Example #1
0
/*
 * Include files within dirname.  Only files with names ending in ".conf", or
 * consisting entirely of alphanumeric characters, dashes, and underscores are
 * included.  This restriction avoids including editor backup files, .rpmsave
 * files, and the like.  Files are processed in alphanumeric order.
 */
static errcode_t parse_include_dir(const char *dirname,
                                   struct profile_node *root_section)
{
    errcode_t retval = 0;
    char **fnames, *pathname;
    int i;

    if (k5_dir_filenames(dirname, &fnames) != 0)
        return PROF_FAIL_INCLUDE_DIR;

    for (i = 0; fnames != NULL && fnames[i] != NULL; i++) {
        if (!valid_name(fnames[i]))
            continue;
        if (asprintf(&pathname, "%s/%s", dirname, fnames[i]) < 0) {
            retval = ENOMEM;
            break;
        }
        retval = parse_include_file(pathname, root_section);
        free(pathname);
        if (retval)
            break;
    }
    k5_free_filenames(fnames);
    return retval;
}
Example #2
0
static errcode_t parse_line(char *line, struct parse_state *state,
                            char **ret_modspec)
{
    char    *cp;

    if (strncmp(line, "include", 7) == 0 && isspace(line[7])) {
        cp = skip_over_blanks(line + 7);
        strip_line(cp);
        return parse_include_file(cp, state->root_section);
    }
    if (strncmp(line, "includedir", 10) == 0 && isspace(line[10])) {
        cp = skip_over_blanks(line + 10);
        strip_line(cp);
        return parse_include_dir(cp, state->root_section);
    }
    switch (state->state) {
    case STATE_INIT_COMMENT:
        if (strncmp(line, "module", 6) == 0 && isspace(line[6])) {
            /*
             * If we are expecting a module declaration, fill in *ret_modspec
             * and return PROF_MODULE, which will cause parsing to abort and
             * the module to be loaded instead.  If we aren't expecting a
             * module declaration, return PROF_MODULE without filling in
             * *ret_modspec, which will be treated as an ordinary error.
             */
            if (ret_modspec) {
                cp = skip_over_blanks(line + 6);
                strip_line(cp);
                *ret_modspec = strdup(cp);
                if (!*ret_modspec)
                    return ENOMEM;
            }
            return PROF_MODULE;
        }
        if (line[0] != '[')
            return 0;
        state->state = STATE_STD_LINE;
    case STATE_STD_LINE:
        return parse_std_line(line, state);
    case STATE_GET_OBRACE:
        cp = skip_over_blanks(line);
        if (*cp != '{')
            return PROF_MISSING_OBRACE;
        state->state = STATE_STD_LINE;
    }
    return 0;
}
Example #3
0
static void on_macro_include(ParseEnv* env, MLStr* filename, gboolean is_system_header, gint line) {
	CppFile* incfile = 0;
	gchar* str;
	CppElem* elem;

	//if( stopsign_is_set() )
	//	return;

	elem = cpp_elem_new();
	elem->type = CPP_ET_INCLUDE;
	elem->file = env->file;
	elem->name = tiny_str_new("_include_", 9);
	elem->sline = line;
	elem->eline = line;
	elem->v_include.filename = tiny_str_new(filename->buf, filename->len);
	elem->v_include.sys_header = is_system_header;

	str = g_strdup_printf("#include %c%s%c", is_system_header?'<':'\"', elem->v_include.filename->buf, is_system_header?'<':'\"');
	elem->decl = tiny_str_new(str, (gsize)strlen(str));
	g_free(str);

	cpp_scope_insert( &(env->file->root_scope), elem );

	/*
	line = filename->buf[filename->len];
	filename->buf[filename->len] = 0;
		g_print("%s : %d\n", filename->buf, memcmp(filename, "glib/gmem.h", 11));
	filename->buf[filename->len] = line;
	*/
	incfile = parse_include_file(env, filename, is_system_header);

	if( incfile ) {
		elem->v_include.include_file = g_strdup(incfile->filename->buf);
		insert_rmacros_into_env(env, incfile);
		cpp_file_unref(incfile);
	}
}
Example #4
0
/*
 * Include files within dirname.  Only files with names ending in ".conf", or
 * consisting entirely of alphanumeric characters, dashes, and underscores are
 * included.  This restriction avoids including editor backup files, .rpmsave
 * files, and the like.
 */
static errcode_t parse_include_dir(const char *dirname,
                                   struct profile_node *root_section)
{
#ifdef _WIN32
    char *wildcard = NULL, *pathname;
    WIN32_FIND_DATA ffd;
    HANDLE handle;
    errcode_t retval = 0;

    if (asprintf(&wildcard, "%s\\*", dirname) < 0)
        return ENOMEM;

    handle = FindFirstFile(wildcard, &ffd);
    if (handle == INVALID_HANDLE_VALUE) {
        retval = PROF_FAIL_INCLUDE_DIR;
        goto cleanup;
    }

    do {
        if (!valid_name(ffd.cFileName))
            continue;
        if (asprintf(&pathname, "%s\\%s", dirname, ffd.cFileName) < 0) {
            retval = ENOMEM;
            break;
        }
        retval = parse_include_file(pathname, root_section);
        free(pathname);
        if (retval)
            break;
    } while (FindNextFile(handle, &ffd) != 0);

    FindClose(handle);

cleanup:
    free(wildcard);
    return retval;

#else /* not _WIN32 */

    DIR     *dir;
    char    *pathname;
    errcode_t retval = 0;
    struct dirent *ent;

    dir = opendir(dirname);
    if (dir == NULL)
        return PROF_FAIL_INCLUDE_DIR;
    while ((ent = readdir(dir)) != NULL) {
        if (!valid_name(ent->d_name))
            continue;
        if (asprintf(&pathname, "%s/%s", dirname, ent->d_name) < 0) {
            retval = ENOMEM;
            break;
        }
        retval = parse_include_file(pathname, root_section);
        free(pathname);
        if (retval)
            break;
    }
    closedir(dir);
    return retval;
#endif /* not _WIN32 */
}