Example #1
0
std::shared_ptr<Tool>
TransformSet::findToolByTag( const std::string &tag,
							 const std::string &ext ) const
{
	for ( auto &t: myTools )
		if ( t->getTag() == tag && t->handlesExtension( ext ) )
			return t;

	DEBUG( "Tool Tag '" + tag + "' not found that handles extension '" + ext + "', falling back to normal tool search" );

	return findTool( ext );
}
Example #2
0
// load options file
void LoadOptions(char *filename)
{
    FILE *f;
    char section[64], line[1024], group[64], key[64],  *val;
    TexCodec *codec;
    TexTool *tool;
    int linenum, l;

    // parse file
    sprintf(line, "%s%s", progpath, filename);
    f = fopen(line, "r");
    if (!f)
    {
        Warning("LoadOptions: failed to open '%s' - %s!", filename, strerror(errno));
        return;
    }
    linenum = 0;
    strcpy(section, "GENERAL");
    while (fgets(line, sizeof(line), f) != NULL)
    {
        linenum++;

        // parse comment
        if (line[0] == ';' || line[0] == '#' || line[0] == '\n')
            continue;

        // parse group
        if (line[0] == '[')
        {
            val = strstr(line, "]");
            if (!val)
                Warning("%s:%i: bad group %s", filename, linenum, line);
            else
            {
                l = min(val - line - 1, sizeof(group) - 1);
                strncpy(group, line + 1, l);
                group[l] = 0;
                if (group[0] == '!')
                {
                    strncpy(section, group + 1, sizeof(section));
                    if (!strnicmp(section, "CODEC:", 6))
                    {
                        codec = findCodec(section + 6, true);
                        if (!codec)
                            Error("LoadOptions: unknown codec section [%s], please fix your config file\n", section);
                    }
                    if (!strnicmp(section, "TOOL:", 5))
                    {
                        tool = findTool(section + 5, true);
                        if (!tool)
                            Error("LoadOptions: unknown tool section [%s], please fix your config file\n", tool);
                    }
                    strcpy(group, "options");
                }
            }
            continue;
        }

        // key=value pair
        while(val = strstr(line, "\n")) val[0] = 0;
        val = strstr(line, "=");
        if (!val)
        {
            Warning("%s:%i: bad key pair '%s'", filename, linenum, line);
            continue;
        }
        l = min(val - line, sizeof(key) - 1);
        strncpy(key, line, l);
        key[l] = 0;
        val++;

        // parse
        if (!strcmp(section, "GENERAL"))
        {
            if (!stricmp(key, "waitforkey"))
                waitforkey = OptionBoolean(val, waitforkey);
            continue;
        }
        if (!strcmp(section, "TEXCOMPRESS"))
        {
            TexCompress_Option(section, group, key, val, filename, linenum);
            continue;
        }
        if (!strnicmp(section, "CODEC:", 6))
        {
            TexCompress_CodecOption(codec, group, key, val, filename, linenum);

            continue;
        }
        if (!strnicmp(section, "TOOL:", 5))
        {
            if (tool)
                TexCompress_ToolOption(tool, group, key, val, filename, linenum);
            continue;
        }
        Warning("%s:%i: unknown section '%s'", filename, linenum, section);
    }
    fclose(f);
}