示例#1
0
int conf_read(const char *name)
{
	FILE *in = NULL;
	char line[1024];
	char *p, *p2;
	int lineno = 0;
	struct symbol *sym;
	struct property *prop;
	struct expr *e;
	int i;

	if (name) {
		in = fopen(name, "r");
	} else {
		const char **names = conf_confnames;
		while ((name = *names++)) {
			name = conf_expand_value(name);
			in = fopen(name, "r");
			if (in) {
				printf("#\n"
				       "# using defaults found in %s\n"
				       "#\n", name);
				break;
			}
		}
	}

	if (!in)
		return 1;

	for_all_symbols(i, sym) {
		sym->flags |= SYMBOL_NEW | SYMBOL_CHANGED;
		sym->flags &= ~SYMBOL_VALID;
		switch (sym->type) {
		case S_INT:
		case S_HEX:
		case S_STRING:
			if (S_VAL(sym->def))
				free(S_VAL(sym->def));
		default:
			S_VAL(sym->def) = NULL;
			S_TRI(sym->def) = no;
			;
		}
	}
示例#2
0
tristate
expr_calc_value(struct expr * e)
{
    tristate val1, val2;
    const char *str1, *str2;

    if (!e)
	return yes;

    switch (e->type) {
    case E_SYMBOL:
	sym_calc_value(e->left.sym);
	return S_TRI(e->left.sym->curr);
    case E_AND:
	val1 = expr_calc_value(e->left.expr);
	val2 = expr_calc_value(e->right.expr);
	return E_AND(val1, val2);
    case E_OR:
	val1 = expr_calc_value(e->left.expr);
	val2 = expr_calc_value(e->right.expr);
	return E_OR(val1, val2);
    case E_NOT:
	val1 = expr_calc_value(e->left.expr);
	return E_NOT(val1);
    case E_EQUAL:
	sym_calc_value(e->left.sym);
	sym_calc_value(e->right.sym);
	str1 = sym_get_string_value(e->left.sym);
	str2 = sym_get_string_value(e->right.sym);
	return !strcmp(str1, str2) ? yes : no;
    case E_UNEQUAL:
	sym_calc_value(e->left.sym);
	sym_calc_value(e->right.sym);
	str1 = sym_get_string_value(e->left.sym);
	str2 = sym_get_string_value(e->right.sym);
	return !strcmp(str1, str2) ? no : yes;
    default:
	printf("expr_calc_value: %d?\n", e->type);
	return no;
    }
}
示例#3
0
文件: conf.c 项目: mmikulicic/acaros
static void conf(struct menu *menu)
{
	struct symbol *sym;
	struct property *prop;
	struct menu *child;

	if (!menu_is_visible(menu))
		return;

	sym = menu->sym;
	prop = menu->prompt;
	if (prop) {
		const char *prompt;

		switch (prop->type) {
		case P_MENU:
			if (input_mode == ask_silent && rootEntry != menu) {
				check_conf(menu);
				return;
			}
		case P_COMMENT:
			prompt = menu_get_prompt(menu);
			if (prompt)
				printf("%*c\n%*c %s\n%*c\n",
					indent, '*',
					indent, '*', prompt,
					indent, '*');
		default:
			;
		}
	}

	if (!sym)
		goto conf_childs;

	if (sym_is_choice(sym)) {
		conf_choice(menu);
		if (S_TRI(sym->curr) != mod)
			return;
		goto conf_childs;
	}

	switch (sym->type) {
	case S_INT:
	case S_HEX:
	case S_STRING:
		conf_string(menu);
		break;
	default:
		conf_sym(menu);
		break;
	}

conf_childs:
	if (sym)
		indent += 2;
	for (child = menu->list; child; child = child->next)
		conf(child);
	if (sym)
		indent -= 2;
}
示例#4
0
文件: conf.c 项目: mmikulicic/acaros
static int conf_choice(struct menu *menu)
{
	struct symbol *sym, *def_sym;
	struct menu *cmenu, *def_menu;
	const char *help;
	int type, len;
	bool is_new;

	sym = menu->sym;
	type = sym_get_type(sym);
	is_new = !sym_has_value(sym);
	if (sym_is_changable(sym)) {
		conf_sym(menu);
		sym_calc_value(sym);
		switch (sym_get_tristate_value(sym)) {
		case no:
			return 1;
		case mod:
			return 0;
		case yes:
			break;
		}
	} else {
		sym->def = sym->curr;
		if (S_TRI(sym->curr) == mod) {
			printf("%*s%s\n", indent - 1, "", menu_get_prompt(menu));
			return 0;
		}
	}

	while (1) {
		printf("%*s%s ", indent - 1, "", menu_get_prompt(menu));
		def_sym = sym_get_choice_value(sym);
		def_menu = NULL;
		for (cmenu = menu->list; cmenu; cmenu = cmenu->next) {
			if (!menu_is_visible(cmenu))
				continue;
			printo(menu_get_prompt(cmenu));
			if (cmenu->sym == def_sym)
				def_menu = cmenu;
		}
		printo(NULL);
		if (def_menu)
			printf("[%s] ", menu_get_prompt(def_menu));
		else {
			printf("\n");
			return 1;
		}
		switch (input_mode) {
		case ask_new:
		case ask_silent:
		case ask_all:
			if (is_new)
				sym->flags |= SYMBOL_NEW;
			conf_askvalue(sym, menu_get_prompt(def_menu));
			strip(line);
			break;
		default:
			line[0] = 0;
			printf("\n");
		}
		if (line[0] == '?' && !line[1]) {
			help = nohelp_text;
			if (menu->sym->help)
				help = menu->sym->help;
			printf("\n%s\n", help);
			continue;
		}
		if (line[0]) {
			len = strlen(line);
			line[len] = 0;

			def_menu = NULL;
			for (cmenu = menu->list; cmenu; cmenu = cmenu->next) {
				if (!cmenu->sym || !menu_is_visible(cmenu))
					continue;
				if (!strncasecmp(line, menu_get_prompt(cmenu), len)) {
					def_menu = cmenu;
					break;
				}
			}
		}
		if (def_menu) {
			sym_set_choice_value(sym, def_menu->sym);
			if (def_menu->list) {
				indent += 2;
				conf(def_menu->list);
				indent -= 2;
			}
			return 1;
		}
	}
}