int main(int argc, char *argv[])
{
	int result;
    IniContext context;
    const char *szFilename = "test.ini";
    AnnotationEntry annotations[1];

    if (argc > 1) {
        szFilename = argv[1];
    }
	
	log_init();

    memset(annotations, 0, sizeof(annotations));
    annotations[0].func_name = "EXPRESS_CALC";
    annotations[0].func_get = iniAnnotationFuncExpressCalc;

    //printf("sizeof(IniContext): %d\n", (int)sizeof(IniContext));
    result = iniLoadFromFileEx(szFilename, &context,
            FAST_INI_ANNOTATION_WITH_BUILTIN, annotations, 1,
            FAST_INI_FLAGS_SHELL_EXECUTE);
    if (result != 0)
    {
        return result;
    }

    iniPrintItems(&context);
    iniDestroyAnnotationCallBack();
    iniFreeContext(&context);
	return 0;
}
int get_base_path_from_conf_file(const char *filename, char *base_path,
                                 const int path_size)
{
    char *pBasePath;
    IniContext iniContext;
    int result;

    memset(&iniContext, 0, sizeof(IniContext));

    if ((result=iniLoadFromFileEx(filename, &iniContext, true)) != 0)
    {
        logError("file: "__FILE__", line: %d, " \
                 "load conf file \"%s\" fail, ret code: %d", \
                 __LINE__, filename, result);
        return result;
    }

    do
    {
        pBasePath = iniGetStrValue(NULL, "base_path", &iniContext);
        if (pBasePath == NULL)
        {
            logError("file: "__FILE__", line: %d, " \
                     "conf file \"%s\" must have item " \
                     "\"base_path\"!", __LINE__, filename);
            result = ENOENT;
            break;
        }

        snprintf(base_path, path_size, "%s", pBasePath);
        chopPath(base_path);
        if (!fileExists(base_path))
        {
            logError("file: "__FILE__", line: %d, " \
                     "\"%s\" can't be accessed, error info: %s", \
                     __LINE__, base_path, STRERROR(errno));
            result = errno != 0 ? errno : ENOENT;
            break;
        }
        if (!isDir(base_path))
        {
            logError("file: "__FILE__", line: %d, " \
                     "\"%s\" is not a directory!", \
                     __LINE__, base_path);
            result = ENOTDIR;
            break;
        }
    } while (0);

    iniFreeContext(&iniContext);
    return result;
}
Exemple #3
0
int load_log_level_ex(const char *conf_filename)
{
	int result;
	IniContext iniContext;

	if ((result=iniLoadFromFileEx(conf_filename, &iniContext, true)) != 0)
	{
		logError("file: "__FILE__", line: %d, " \
			"load conf file \"%s\" fail, ret code: %d", \
			__LINE__, conf_filename, result);
		return result;
	}

	load_log_level(&iniContext);
	iniFreeContext(&iniContext);
	return 0;
}