| 804 | } |
| 805 | |
| 806 | static void print_symbol_for_rustccfg(FILE *fp, struct symbol *sym) |
| 807 | { |
| 808 | const char *val; |
| 809 | const char *val_prefix = ""; |
| 810 | char *val_prefixed = NULL; |
| 811 | size_t val_prefixed_len; |
| 812 | char *escaped = NULL; |
| 813 | |
| 814 | if (sym->type == S_UNKNOWN) |
| 815 | return; |
| 816 | |
| 817 | val = sym_get_string_value(sym); |
| 818 | |
| 819 | switch (sym->type) { |
| 820 | case S_BOOLEAN: |
| 821 | case S_TRISTATE: |
| 822 | /* |
| 823 | * We do not care about disabled ones, i.e. no need for |
| 824 | * what otherwise are "comments" in other printers. |
| 825 | */ |
| 826 | if (*val == 'n') |
| 827 | return; |
| 828 | |
| 829 | /* |
| 830 | * To have similar functionality to the C macro `IS_ENABLED()` |
| 831 | * we provide an empty `--cfg CONFIG_X` here in both `y` |
| 832 | * and `m` cases. |
| 833 | * |
| 834 | * Then, the common `fprintf()` below will also give us |
| 835 | * a `--cfg CONFIG_X="y"` or `--cfg CONFIG_X="m"`, which can |
| 836 | * be used as the equivalent of `IS_BUILTIN()`/`IS_MODULE()`. |
| 837 | */ |
| 838 | fprintf(fp, "--cfg=%s%s\n", CONFIG_, sym->name); |
| 839 | break; |
| 840 | case S_HEX: |
| 841 | if (val[0] != '0' || (val[1] != 'x' && val[1] != 'X')) |
| 842 | val_prefix = "0x"; |
| 843 | break; |
| 844 | default: |
| 845 | break; |
| 846 | } |
| 847 | |
| 848 | if (strlen(val_prefix) > 0) { |
| 849 | val_prefixed_len = strlen(val) + strlen(val_prefix) + 1; |
| 850 | val_prefixed = xmalloc(val_prefixed_len); |
| 851 | snprintf(val_prefixed, val_prefixed_len, "%s%s", val_prefix, val); |
| 852 | val = val_prefixed; |
| 853 | } |
| 854 | |
| 855 | /* All values get escaped: the `--cfg` option only takes strings */ |
| 856 | escaped = escape_string_value(val); |
| 857 | val = escaped; |
| 858 | |
| 859 | fprintf(fp, "--cfg=%s%s=%s\n", CONFIG_, sym->name, val); |
| 860 | |
| 861 | free(escaped); |
| 862 | free(val_prefixed); |
| 863 | } |
nothing calls this directly
no test coverage detected