Пример #1
0
int main (void)
{
	bool equalStrings (const char s1[], const char s2[]);
	const char stra[] = "String compare test";
	const char strb[] = "String";

	printf ("%i\n", equalStrings (stra, strb));
	printf ("%i\n", equalStrings (strb, stra));	
	printf ("%i\n", equalStrings (strb,"String"));	

	return 0;
}
Пример #2
0
int main (void)
{
    // prototyping
    bool equalStrings(const char str1[], const char str2[]);
    const char stra[] = "string compare test";
    const char strb[] = "string";
    printf ("%i\n", equalStrings (stra, strb));
    printf ("%i\n", equalStrings (stra, stra));
    printf ("%i\n", equalStrings (strb, "string"));

    return 0;
}
Пример #3
0
struct RBNode *insertRBNodeBinary(struct RBTree *tree, char *key, RBDATATYPE *data)
{
    if (!tree->root) {
        tree->root = createRBNode(key, data, NULL, NULL, NULL);
        return;
    }

    struct RBNode *node = tree->root, *parent = NULL;

    int height;
    for (height = 0; node; ++height) {
        if (equalStrings(key, node->key, MAXKEYSIZE)) {
            return;
        } else {
            parent = node;
            node = compare(key, node->key) ? node->left : node->right;
        }
    }

    if (height > tree->height)
        tree->height++;

    struct RBNode *n = createRBNode(key, data, NULL, NULL, NULL);
    if (!n)
        return;
    
    if (compare(key, parent->key))
        parent->left = n;
    else
        parent->right = n;

    tree->size++;

    return n;
}
Пример #4
0
bool endsWith(const char* str, const char* substr)
{
	int len = stringLength(str);
	int len2 = stringLength(substr);
	if (len2 > len) return false;
	return equalStrings(str + len - len2, substr);
}
Пример #5
0
static void alpha_blending(lua_State* L, const char* mode)
{
	Shader* shader = getShader(L);
	if (!shader) return;
	if (equalStrings(mode, "add"))
	{
		shader->m_render_states |= BGFX_STATE_BLEND_ADD;
	}
	else if (equalStrings(mode, "alpha"))
	{
		shader->m_render_states |= BGFX_STATE_BLEND_ALPHA;
	}
	else
	{
		g_log_error.log("Renderer") << "Uknown blend mode " << mode << " in " << shader->getPath().c_str();
	}
}
Пример #6
0
bool Model::parseVertexDecl(FS::IFile& file, bgfx::VertexDecl* vertex_decl)
{
	vertex_decl->begin();

	u32 attribute_count;
	file.read(&attribute_count, sizeof(attribute_count));

	for (u32 i = 0; i < attribute_count; ++i)
	{
		char tmp[50];
		u32 len;
		file.read(&len, sizeof(len));
		if (len > sizeof(tmp) - 1)
		{
			return false;
		}
		file.read(tmp, len);
		tmp[len] = '\0';

		if (equalStrings(tmp, "in_position"))
		{
			vertex_decl->add(bgfx::Attrib::Position, 3, bgfx::AttribType::Float);
		}
		else if (equalStrings(tmp, "in_colors"))
		{
			vertex_decl->add(bgfx::Attrib::Color0, 4, bgfx::AttribType::Uint8, true, false);
		}
		else if (equalStrings(tmp, "in_tex_coords"))
		{
			vertex_decl->add(bgfx::Attrib::TexCoord0, 2, bgfx::AttribType::Float);
		}
		else if (equalStrings(tmp, "in_normal"))
		{
			vertex_decl->add(bgfx::Attrib::Normal, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (equalStrings(tmp, "in_tangents"))
		{
			vertex_decl->add(bgfx::Attrib::Tangent, 4, bgfx::AttribType::Uint8, true, true);
		}
		else if (equalStrings(tmp, "in_weights"))
		{
			vertex_decl->add(bgfx::Attrib::Weight, 4, bgfx::AttribType::Float);
		}
		else if (equalStrings(tmp, "in_indices"))
		{
			vertex_decl->add(bgfx::Attrib::Indices, 4, bgfx::AttribType::Int16, false, true);
		}
		else
		{
			ASSERT(false);
			return false;
		}

		u32 type;
		file.read(&type, sizeof(type));
	}

	vertex_decl->end();
	return true;
}
Пример #7
0
	IFileDevice* getDevice(const char* device)
	{
		for (int i = 0; i < m_devices.size(); ++i)
		{
			if (equalStrings(m_devices[i]->name(), device)) return m_devices[i];
		}

		return nullptr;
	}
Пример #8
0
		IPlugin* getPlugin(const char* name) override
		{
			for (int i = 0; i < m_plugins.size(); ++i)
			{
				if (equalStrings(m_plugins[i]->getName(), name))
				{
					return m_plugins[i];
				}
			}
			return nullptr;
		}
int lookup(const struct entry dictionary[], const char search[],
			const int entries)
{
	bool equalStrings(const char s1[], const char s2[]);

	int i;

	for (i = 0; i < entries; ++i)
		if (equalStrings(search, dictionary[i].word))
			return i;

	return -1;
}
Пример #10
0
uint32_t handleMultiply(Assembler *assembler, char **tokens) {
    uint32_t Rd = getValue(tokens[1]);
    uint32_t Rm = getValue(tokens[2]);
    uint32_t Rs = getValue(tokens[3]);
    uint32_t Rn;
    if (equalStrings(tokens[0], "mla")) {
        Rn = getValue(tokens[4]);
        return genMul(true, Rd, Rn, Rs, Rm);
    } else {
        Rn = 0;
    }

    return genMul(false, Rd, 0, Rs, Rm);
}
Пример #11
0
	bool mount(IFileDevice* device) override
	{
		for (int i = 0; i < m_devices.size(); i++)
		{
			if (m_devices[i] == device)
			{
				return false;
			}
		}

		if (equalStrings(device->name(), "memory"))
		{
			m_memory_device.m_devices[0] = device;
			m_memory_device.m_devices[1] = nullptr;
		}
		else if (equalStrings(device->name(), "disk"))
		{
			m_disk_device.m_devices[0] = device;
			m_disk_device.m_devices[1] = nullptr;
		}

		m_devices.push(device);
		return true;
	}
Пример #12
0
//take a mnemonic string and return the DP opcode associated with it
//ugly function but most elegant/simplest way around this problem
DPOpcodes mnemToOpcode(char *mnem) {
    char* dpMnems[NUMDPINSTRS] = {"and", "eor", "sub", "rsb", "add", "tst",
                                  "teq", "cmp", "orr", "mov"};
    DPOpcodes opcodes[NUMDPINSTRS] = {AND, EOR, SUB, RSB, ADD, TST, TEQ, CMP,
                                      ORR, MOV};

    for (int i = 0; i < NUMDPINSTRS; ++i) {
        if (equalStrings(dpMnems[i], mnem)) {
            return opcodes[i];
        }
    }
    //if we reached here, we did not match any mnemonic
    fprintf(stderr, "invalid DP mnemonic: %s mnem", mnem);
    exit(EXIT_FAILURE);
}
Пример #13
0
uint32_t handleSDT(Assembler *assembler, char **tokens) {
    //set fields to default.
    bool load = equalStrings(tokens[0], "ldr");
    int Rd = getValue(tokens[1]);
    bool immediate = false;
    bool preIndexing = true;
    bool up = true;
    int Rn = 0xF;
    int offset = 0;

    if (tokens[2][0] == '=') {  //numeric constant
        immediate = false;
        uint32_t constant = getValue(tokens[2]);
        if (constant <= MAX_MOV_CONSTANT) {
            tokens[0] = "mov";
            tokens[2][0] = '#';
            return handleDataProcessing(assembler, tokens);
        } else {
            assembler->binaryProgram[(assembler->firstEmptyAddr) / INSTR_LENGTH]
                    = constant;
            offset = calcOffset(assembler,
                                (unsigned int) assembler->firstEmptyAddr, false);
            assembler->firstEmptyAddr += INSTR_LENGTH;
        }

    } else {
        preIndexing = (tokens[2][3] != ']' && tokens[2][4] != ']')
                        || tokens[3] == NULL;
        Rn = getValue(&tokens[2][1]);
        if (tokens[3] != NULL) {
            if (tokens[3][1] == '-') {
                up = false;

                //change negative at start of Rm to #
                tokens[3][1] = '#';

                //make token 3 start at last #
                tokens[3] = &tokens[3][1];
            }
            // offset is handled similarly to operand2, but with immediate
            // negated after
            offset = handleOperand2(&tokens[3], &immediate);
            immediate = !immediate;
        }
    }

    return genSDT(immediate, preIndexing, up, load, Rn, Rd, offset);
}
Пример #14
0
// function to look up a word
// takes the entry struct and looks up an instance of that struct, also takes a search word, and the current amount of entries in the dictionary
// ie : lookup(dictionary, wordInput, entries)
int lookup(const struct entry1 dictionaryx[], const char search[], const int entries){
    
    int i;
    // function prototype
    bool equalStrings(const char s1[], const char s2[]);
    
    // loops through the current amount of entries
    for(i = 0; i < entries; ++i){
        // compares the search word to member of the current instance of the entry struct
        
        if(equalStrings(search, dictionaryx[i].word))
            // if the words match return the current position of the word in the dictionary struct
            return i;
    }
    
    return -1;
}
Пример #15
0
static void uniform(lua_State* L, const char* name, const char* type)
{
    auto* shader = getShader(L);
    if (!shader) return;
    auto& u = shader->m_uniforms.emplace();
    copyString(u.name, name);
    u.name_hash = crc32(name);
    if (equalStrings(type, "float"))
    {
        u.type = Shader::Uniform::FLOAT;
        u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
    }
    else if (equalStrings(type, "color"))
    {
        u.type = Shader::Uniform::COLOR;
        u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
    }
    else if (equalStrings(type, "int"))
    {
        u.type = Shader::Uniform::INT;
        u.handle = bgfx::createUniform(name, bgfx::UniformType::Int1);
    }
    else if (equalStrings(type, "matrix4"))
    {
        u.type = Shader::Uniform::MATRIX4;
        u.handle = bgfx::createUniform(name, bgfx::UniformType::Mat4);
    }
    else if (equalStrings(type, "time"))
    {
        u.type = Shader::Uniform::TIME;
        u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
    }
    else if (equalStrings(type, "vec3"))
    {
        u.type = Shader::Uniform::VEC3;
        u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
    }
    else if (equalStrings(type, "vec2"))
    {
        u.type = Shader::Uniform::VEC2;
        u.handle = bgfx::createUniform(name, bgfx::UniformType::Vec4);
    }
    else
    {
        g_log_error.log("Renderer") << "Unknown uniform type " << type << " in " << shader->getPath().c_str();
    }
}
Пример #16
0
bool hasNoRn(char *mnem) {
    return equalStrings(mnem, "mov");
}
Пример #17
0
bool hasNoRd(char *mnem) {
    return equalStrings(mnem, "tst") ||
           equalStrings(mnem, "teq") ||
           equalStrings(mnem, "cmp");
}