Skip to content
Snippets Groups Projects
confdata.c 23.9 KiB
Newer Older
  • Learn to ignore specific revisions
  • 	if (rename(".tmpconfig", name))
    		return 1;
    
    	return 0;
    }
    
    	if (conf_changed_callback &&
    	    (bool)_sym_change_count != (bool)count)
    		conf_changed_callback();
    
    bool conf_get_changed(void)
    {
    	return sym_change_count;
    }
    
    
    void conf_set_changed_callback(void (*fn)(void))
    {
    	conf_changed_callback = fn;
    }
    
    static void randomize_choice_values(struct symbol *csym)
    {
    	struct property *prop;
    	struct symbol *sym;
    	struct expr *e;
    	int cnt, def;
    
    Arnaud Lacombe's avatar
    Arnaud Lacombe committed
    	 * If choice is mod then we may have more items selected
    
    	 * and if no then no-one.
    	 * In both cases stop.
    	 */
    	if (csym->curr.tri != yes)
    		return;
    
    	prop = sym_get_choice_prop(csym);
    
    	/* count entries in choice block */
    	cnt = 0;
    	expr_list_for_each_sym(prop->expr, e, sym)
    		cnt++;
    
    	/*
    	 * find a random value and set it to yes,
    	 * set the rest to no so we have only one set
    	 */
    	def = (rand() % cnt);
    
    	cnt = 0;
    	expr_list_for_each_sym(prop->expr, e, sym) {
    		if (def == cnt++) {
    			sym->def[S_DEF_USER].tri = yes;
    			csym->def[S_DEF_USER].val = sym;
    		}
    		else {
    			sym->def[S_DEF_USER].tri = no;
    		}
    	}
    	csym->flags |= SYMBOL_DEF_USER;
    	/* clear VALID to get value calculated */
    	csym->flags &= ~(SYMBOL_VALID);
    }
    
    static void set_all_choice_values(struct symbol *csym)
    
    {
    	struct property *prop;
    
    	struct symbol *sym;
    
    	struct expr *e;
    
    
    	prop = sym_get_choice_prop(csym);
    
    	/*
    	 * Set all non-assinged choice values to no
    	 */
    	expr_list_for_each_sym(prop->expr, e, sym) {
    		if (!sym_has_value(sym))
    			sym->def[S_DEF_USER].tri = no;
    	}
    	csym->flags |= SYMBOL_DEF_USER;
    	/* clear VALID to get value calculated */
    	csym->flags &= ~(SYMBOL_VALID);
    }
    
    void conf_set_all_new_symbols(enum conf_def_mode mode)
    {
    	struct symbol *sym, *csym;
    	int i, cnt;
    
    
    	for_all_symbols(i, sym) {
    		if (sym_has_value(sym))
    			continue;
    		switch (sym_get_type(sym)) {
    		case S_BOOLEAN:
    		case S_TRISTATE:
    			switch (mode) {
    			case def_yes:
    				sym->def[S_DEF_USER].tri = yes;
    				break;
    			case def_mod:
    				sym->def[S_DEF_USER].tri = mod;
    				break;
    			case def_no:
    				sym->def[S_DEF_USER].tri = no;
    				break;
    			case def_random:
    
    				cnt = sym_get_type(sym) == S_TRISTATE ? 3 : 2;
    				sym->def[S_DEF_USER].tri = (tristate)(rand() % cnt);
    
    			if (!(sym_is_choice(sym) && mode == def_random))
    
    				sym->flags |= SYMBOL_DEF_USER;
    			break;
    		default:
    			break;
    		}
    
    	}
    
    
    Al Viro's avatar
    Al Viro committed
    	sym_clear_all_valid();
    
    	/*
    	 * We have different type of choice blocks.
    
    Arnaud Lacombe's avatar
    Arnaud Lacombe committed
    	 * If curr.tri equals to mod then we can select several
    
    	 * choice symbols in one block.
    	 * In this case we do nothing.
    
    Arnaud Lacombe's avatar
    Arnaud Lacombe committed
    	 * If curr.tri equals yes then only one symbol can be
    
    	 * selected in a choice block and we set it to yes,
    	 * and the rest to no.
    	 */
    
    	for_all_symbols(i, csym) {
    		if (sym_has_value(csym) || !sym_is_choice(csym))
    			continue;
    
    		sym_calc_value(csym);
    
    		if (mode == def_random)
    			randomize_choice_values(csym);
    		else
    			set_all_choice_values(csym);