示例#1
0
文件: conf.c 项目: rvs/libtc
static tcc_entry *
getvalue(conf_section *sec, char *name, tcconf_section_t **ts)
{
    tcconf_section_t *path = NULL;
    char *tmp = strdup(name);
    char *v;
    tcc_entry *te = NULL;

/*     fprintf(stderr, "enter getvalue\n"); */
/*     fprintf(stderr, "getting '%s' in ", name); */
/*     if(ts) */
/* 	tcconf_dumppath(*ts); */
/*     else */
/* 	fprintf(stderr, "%s\n", sec->name); */

    if((v = strrchr(tmp, '/')) != NULL){
	*v++ = 0;
	if(!(sec = getsection(ts, sec, tmp)))
	    goto end;
    } else {
	v = tmp;
    }

    if(tclist_find(sec->entries, v, &te, cmp_str_val)){
	tclist_item_t *li = NULL;
	char *m;
	while((m = tclist_prev(sec->merge, &li))){
	    conf_section *ps, *ms;
	    if(path)
		ps = path->parent? path->parent->sec: path->sec;
	    else
		ps = sec->parent? sec->parent: sec;
	    ms = getsection(NULL, ps, m);
	    if(ms && (te = getvalue(ms, v, NULL)))
		break;
	}
	if(li)
	    tclist_unlock(sec->merge, li);
    }

/*     fprintf(stderr, "leave getvalue\n"); */
end:
    free(tmp);
    return te;
}
示例#2
0
文件: conf.c 项目: rvs/libtc
extern tcconf_section_t *
tcconf_getsection(tcconf_section_t *ts, char *name)
{
    tcref(ts);
    if(!name || getsection(&ts, ts->sec, name))
	return ts;
    tcfree(ts);
    return NULL;
}
示例#3
0
文件: nl.c 项目: rovaughn/distro
static void
nl(const char *fname, FILE *fp)
{
	size_t number = startnum, size = 0, bl = 1;
	int donumber, oldsection, section = 1;
	char *buf = NULL;

	while (getline(&buf, &size, fp) > 0) {
		donumber = 0;
		oldsection = section;

		if (getsection(buf, &section)) {
			if ((section >= oldsection) && !pflag)
				number = startnum;
			continue;
		}

		switch (type[section]) {
		case 't':
			if (buf[0] != '\n')
				donumber = 1;
			break;
		case 'p':
			if (!regexec(preg + section, buf, 0, NULL, 0))
				donumber = 1;
			break;
		case 'a':
			if (buf[0] == '\n' && bl < blines) {
				++bl;
			} else {
				donumber = 1;
				bl = 1;
			}
		}

		if (donumber) {
			printf(format, width, number, sep);
			number += incr;
		}
		fputs(buf, stdout);
	}
	free(buf);
	if (ferror(fp))
		eprintf("getline %s:", fname);
}
示例#4
0
文件: conf.c 项目: rvs/libtc
static conf_section *
getsection(tcconf_section_t **ts, conf_section *sec, char *name)
{
    tcconf_section_t *path = NULL;
    char *tmp = strdup(name);
    char *tn = tmp;
    char *s;

    if(ts)
	path = *ts;

/*     fprintf(stderr, "enter getsection\n"); */
/*     fprintf(stderr, "finding '%s' in ", name); */
/*     if(path) */
/* 	tcconf_dumppath(path); */
/*     else */
/* 	fprintf(stderr, "%s\n", sec->name); */

    while((s = strsep(&tmp, "/")) != NULL){
	if(*s == 0)
	    continue;

	if(!strcmp(s, "..")){
	    if(path && path->parent){
		tcconf_section_t *p = path;
		path = tcref(path->parent);
		sec = path->sec;
		tcfree(p);
	    } else if(sec->parent){
		sec = sec->parent;
	    }
	} else {
	    tcconf_section_t *np;
	    tcc_entry *te;

	    if(tclist_find(sec->entries, s, &te, cmp_str_sec)){
		tclist_t *mlist = sec->merge;
		tclist_item_t *li = NULL;
		char *m;

		sec = NULL;

		while((m = tclist_prev(mlist, &li))){
		    conf_section *ps, *ms;
		    if(path)
			ps = path->parent? path->parent->sec: path->sec;
		    else
			ps = sec->parent? sec->parent: sec;
		    ms = getsection(NULL, ps, m);
		    if(ms && (sec = getsection(NULL, ms, s)))
			break;
		}
		if(li)
		    tclist_unlock(sec->merge, li);
	    } else {
		sec = te->section;
	    }

	    if(!sec)
		break;

	    if(path){
		np = tcallocdz(sizeof(*np), NULL, tcconf_free);
		np->sec = tcref(sec);
		np->parent = path;
		path = np;
	    }
	}
/* 	tcconf_dumppath(path); */
    }

    if(ts)
	*ts = path;
/*     fprintf(stderr, "leave getsection\n"); */
    free(tn);
    return sec;
}