MCPcopy Create free account
hub / github.com/Entware/Entware / sym_set_string_value

Function sym_set_string_value

scripts/config/symbol.c:620–667  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

618}
619
620bool sym_set_string_value(struct symbol *sym, const char *newval)
621{
622 const char *oldval;
623 char *val;
624 int size;
625
626 switch (sym->type) {
627 case S_BOOLEAN:
628 case S_TRISTATE:
629 switch (newval[0]) {
630 case 'y': case 'Y':
631 return sym_set_tristate_value(sym, yes);
632 case 'm': case 'M':
633 return sym_set_tristate_value(sym, mod);
634 case 'n': case 'N':
635 return sym_set_tristate_value(sym, no);
636 }
637 return false;
638 default:
639 ;
640 }
641
642 if (!sym_string_within_range(sym, newval))
643 return false;
644
645 if (!(sym->flags & SYMBOL_DEF_USER)) {
646 sym->flags |= SYMBOL_DEF_USER;
647 sym_set_changed(sym);
648 }
649
650 oldval = sym->def[S_DEF_USER].val;
651 size = strlen(newval) + 1;
652 if (sym->type == S_HEX && (newval[0] != '0' || (newval[1] != 'x' && newval[1] != 'X'))) {
653 size += 2;
654 sym->def[S_DEF_USER].val = val = xmalloc(size);
655 *val++ = '0';
656 *val++ = 'x';
657 } else if (!oldval || strcmp(oldval, newval))
658 sym->def[S_DEF_USER].val = val = xmalloc(size);
659 else
660 return true;
661
662 strcpy(val, newval);
663 free((void *)oldval);
664 sym_clear_all_valid();
665
666 return true;
667}
668
669/*
670 * Find the default value associated to a symbol.

Callers 4

setModelDataMethod · 0.85
conf_stringFunction · 0.85
conf_stringFunction · 0.85
conf_stringFunction · 0.85

Calls 5

sym_set_tristate_valueFunction · 0.85
sym_string_within_rangeFunction · 0.85
sym_set_changedFunction · 0.85
xmallocFunction · 0.85
sym_clear_all_validFunction · 0.85

Tested by

no test coverage detected