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

Function print_symbol_for_rustccfg

scripts/config/confdata.c:778–835  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

776}
777
778static void print_symbol_for_rustccfg(FILE *fp, struct symbol *sym)
779{
780 const char *val;
781 const char *val_prefix = "";
782 char *val_prefixed = NULL;
783 size_t val_prefixed_len;
784 char *escaped = NULL;
785
786 if (sym->type == S_UNKNOWN)
787 return;
788
789 val = sym_get_string_value(sym);
790
791 switch (sym->type) {
792 case S_BOOLEAN:
793 case S_TRISTATE:
794 /*
795 * We do not care about disabled ones, i.e. no need for
796 * what otherwise are "comments" in other printers.
797 */
798 if (*val == 'n')
799 return;
800
801 /*
802 * To have similar functionality to the C macro `IS_ENABLED()`
803 * we provide an empty `--cfg CONFIG_X` here in both `y`
804 * and `m` cases.
805 *
806 * Then, the common `fprintf()` below will also give us
807 * a `--cfg CONFIG_X="y"` or `--cfg CONFIG_X="m"`, which can
808 * be used as the equivalent of `IS_BUILTIN()`/`IS_MODULE()`.
809 */
810 fprintf(fp, "--cfg=%s%s\n", CONFIG_, sym->name);
811 break;
812 case S_HEX:
813 if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X'))
814 val_prefix = "0x";
815 break;
816 default:
817 break;
818 }
819
820 if (strlen(val_prefix) > 0) {
821 val_prefixed_len = strlen(val) + strlen(val_prefix) + 1;
822 val_prefixed = xmalloc(val_prefixed_len);
823 snprintf(val_prefixed, val_prefixed_len, "%s%s", val_prefix, val);
824 val = val_prefixed;
825 }
826
827 /* All values get escaped: the `--cfg` option only takes strings */
828 escaped = escape_string_value(val);
829 val = escaped;
830
831 fprintf(fp, "--cfg=%s%s=%s\n", CONFIG_, sym->name, val);
832
833 free(escaped);
834 free(val_prefixed);
835}

Callers

nothing calls this directly

Calls 3

sym_get_string_valueFunction · 0.85
xmallocFunction · 0.85
escape_string_valueFunction · 0.85

Tested by

no test coverage detected