| 1 | #cxx . . $ `<file>/conf.c`/include <ctype.h> |
| 2 | #include <string.h> |
| 3 | #include <stdlib.h> |
| 4 | #include <stdio.h> |
| 5 | #include <stdarg.h> |
| 6 | #include "conf.h"cxx . . $ `<file>/conf.h`/ |
| 7 | |
| 8 | static int count_chcxx . . $ count_ch(cb7559238bb26814).(const char *str, int ch) { |
| 9 | int count = 0; |
| 10 | |
| 11 | for (; str && *str; ++str) |
| 12 | if (*str == ch) |
| 13 | ++count; |
| 14 | return count; |
| 15 | } |
| 16 | |
| 17 | struct odpath_tcxx . . $ odpath_t# *load_confcxx . . $ load_conf(24e337d2fbce6db6).(const char *file, struct odpath_tcxx . . $ odpath_t# *root) { |
| 18 | char *buffer = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(2048), *section = malloccxx . . $ malloc(bfcfa4d6b7f7ef64).(16384); |
| 19 | struct odpath_tcxx . . $ odpath_t# *path = root, *current = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!; |
| 20 | FILEcxx . . $ FILE# *fp; |
| 21 | int line = 0, sec_size = 0; |
| 22 | |
| 23 | if (path) while (path->nextcxx . . $ odpath_t#next.) path = path->nextcxx . . $ odpath_t#next.; |
| 24 | |
| 25 | if (!(fp = fopencxx . . $ fopen(82ec0787cd37e0a3).(file, "r"))) { |
| 26 | freecxx . . $ free(5d22bdacc48458e8).(buffer); |
| 27 | freecxx . . $ free(5d22bdacc48458e8).(section); |
| 28 | return root; |
| 29 | } |
| 30 | |
| 31 | while (fgetscxx . . $ fgets(efb0aaba7ac866ae).(buffer, 2048, fp)) { |
| 32 | int line_size = strlencxx . . $ strlen(751346f8406fd082).(buffer); |
| 33 | |
| 34 | ++line; |
| 35 | /* empty lines and comments are ignored */ |
| 36 | if (!strchrcxx . . $ strchr(2050848944e00d54).("#\n\r", buffer[0]) && line_size) { |
| 37 | /* continuation... */ |
| 38 | if (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(buffer[0])) { |
| 39 | char *sol = buffer; |
| 40 | |
| 41 | if (!current) { |
| 42 | errorcxx . . $ error(326aeb464d16410c).("%s:%i: data outside section", file, line); |
| 43 | continue; |
| 44 | } |
| 45 | if (sec_size + line_size >= MAX_SECTION_SIZEcxx . . $ `conf.h:9:9`!) |
| 46 | fatalcxx . . $ fatal(326aeb464d16410c).("section is greater than MAX_SECTION_SIZE (%i)", MAX_SECTION_SIZEcxx . . $ `conf.h:9:9`!); |
| 47 | /* strip leading spaces */ |
| 48 | while (isspacecxx . . $ `<external>/17904084882347303253/ctype.h:197:10`!(*sol)) ++sol; |
| 49 | strcatcxx . . $ strcat(b7b3a83273496486).(section, sol); |
| 50 | } else { |
| 51 | const char *home = getenvcxx . . $ getenv(a8b8e32347182212).("HOME"); |
| 52 | char *tok; |
| 53 | char **paths; |
| 54 | int npaths, pathi; |
| 55 | |
| 56 | /* new section... */ |
| 57 | if (current) { |
| 58 | current->contentcxx . . $ odpath_t#content. = strdupcxx . . $ strdup(a8b8e32347182212).(section); |
| 59 | if (path) { |
| 60 | path->nextcxx . . $ odpath_t#next. = current; |
| 61 | path = current; |
| 62 | } else { |
| 63 | path = current; |
| 64 | if (!root) root = path; |
| 65 | } |
| 66 | } |
| 67 | if (!(current = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, sizeof(struct odpath_tcxx . . $ odpath_t#)))) |
| 68 | fatalcxx . . $ fatal(326aeb464d16410c).("malloc failed"); |
| 69 | |
| 70 | memsetcxx . . $ memset(d1de1e4fb215f1c6).(section, 0, MAX_SECTION_SIZEcxx . . $ `conf.h:9:9`!); |
| 71 | |
| 72 | /* read stuff */ |
| 73 | tok = strtokcxx . . $ strtok(b7b3a83273496486).(buffer, " \t"); |
| 74 | if (!tok) |
| 75 | fatalcxx . . $ fatal(326aeb464d16410c).("%s:%i: unexpected end of line", file, line); |
| 76 | |
| 77 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tok, "final")) { |
| 78 | current->finalcxx . . $ odpath_t#final. = 1; |
| 79 | tok = strtokcxx . . $ strtok(b7b3a83273496486).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, " \t"); |
| 80 | } |
| 81 | |
| 82 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tok, "enter") && strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tok, "leave")) |
| 83 | fatalcxx . . $ fatal(326aeb464d16410c).("%s:%i: line should start with final, enter or leave", file, line); |
| 84 | |
| 85 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tok, "enter")) |
| 86 | current->typecxx . . $ odpath_t#type. = PT_ENTERcxx . . $ PT_ENTER.; |
| 87 | else |
| 88 | if (!strcmpcxx . . $ strcmp(5ae29d726ae57f88).(tok, "leave")) |
| 89 | current->typecxx . . $ odpath_t#type. = PT_LEAVEcxx . . $ PT_LEAVE.; |
| 90 | |
| 91 | /* count :'s */ |
| 92 | tok = strtokcxx . . $ strtok(b7b3a83273496486).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, "\n"); |
| 93 | npaths = count_chcxx . . $ count_ch(cb7559238bb26814).(tok, ':') + 1; |
| 94 | |
| 95 | paths = calloccxx . . $ calloc(63a7bf2941bfcd7a).(npaths, sizeof(char*)); |
| 96 | |
| 97 | for (pathi = 0, tok = strtokcxx . . $ strtok(b7b3a83273496486).(tok, ":"); pathi < npaths; ++pathi, tok = strtokcxx . . $ strtok(b7b3a83273496486).(NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:419:9`!, ":")) { |
| 98 | if (home && tok[0] == '~') { |
| 99 | char tmppath[strlencxx . . $ strlen(751346f8406fd082).(tok) + strlencxx . . $ strlen(751346f8406fd082).(home) + 1]; |
| 100 | |
| 101 | strcpycxx . . $ strcpy(b7b3a83273496486).(tmppath, home); |
| 102 | strcatcxx . . $ strcat(b7b3a83273496486).(tmppath, tok + 1); |
| 103 | paths[pathi] = expand_envarscxx . . $ expand_envars(a8b8e32347182212).(tmppath); |
| 104 | } else |
| 105 | paths[pathi] = expand_envarscxx . . $ expand_envars(a8b8e32347182212).(tok); |
| 106 | } |
| 107 | current->pathscxx . . $ odpath_t#paths. = (const char**)paths; |
| 108 | current->npathscxx . . $ odpath_t#npaths. = npaths; |
| 109 | } |
| 110 | } |
| 111 | } |
| 112 | if (current) { |
| 113 | current->contentcxx . . $ odpath_t#content. = strdupcxx . . $ strdup(a8b8e32347182212).(section); |
| 114 | if (path) { |
| 115 | path->nextcxx . . $ odpath_t#next. = current; |
| 116 | path = current; |
| 117 | } else { |
| 118 | path = current; |
| 119 | if (!root) root = path; |
| 120 | } |
| 121 | } |
| 122 | fclosecxx . . $ fclose(89bc1efcdac0ca22).(fp); |
| 123 | freecxx . . $ free(5d22bdacc48458e8).(section); |
| 124 | freecxx . . $ free(5d22bdacc48458e8).(buffer); |
| 125 | return root; |
| 126 | } |
| 127 | |
| 128 | void fatalcxx . . $ fatal(326aeb464d16410c).(const char *fmt, ...) { |
| 129 | va_listcxx . . $ va_list# args; |
| 130 | |
| 131 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "fatal: "); |
| 132 | va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, fmt); |
| 133 | vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, fmt, args); |
| 134 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 135 | va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args); |
| 136 | exitcxx . . $ exit(3ca292c338df9bb3).(1); |
| 137 | } |
| 138 | |
| 139 | void errorcxx . . $ error(326aeb464d16410c).(const char *fmt, ...) { |
| 140 | va_listcxx . . $ va_list# args; |
| 141 | |
| 142 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "error: "); |
| 143 | va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, fmt); |
| 144 | vfprintfcxx . . $ vfprintf(bded311e54d67f9c).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, fmt, args); |
| 145 | fprintfcxx . . $ fprintf(bc216f8e5b1ebeac).(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!, "\n"); |
| 146 | va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args); |
| 147 | } |
| 148 | |
| 149 | void warningcxx . . $ warning(326aeb464d16410c).(const char *fmt, ...) { |
| 150 | va_listcxx . . $ va_list# args; |
| 151 | |
| 152 | printfcxx . . $ printf(581fddd72a8db8fc).("warning: "); |
| 153 | va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, fmt); |
| 154 | vprintfcxx . . $ vprintf(5c80dbd47e6ebfbb).(fmt, args); |
| 155 | va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args); |
| 156 | } |
| 157 | |
| 158 | void infocxx . . $ info(326aeb464d16410c).(const char *fmt, ...) { |
| 159 | va_listcxx . . $ va_list# args; |
| 160 | |
| 161 | printfcxx . . $ printf(581fddd72a8db8fc).("ondir: "); |
| 162 | va_startcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:50:9`!(args, fmt); |
| 163 | vprintfcxx . . $ vprintf(5c80dbd47e6ebfbb).(fmt, args); |
| 164 | va_endcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stdarg.h:52:9`!(args); |
| 165 | } |
| 166 | |
| 167 | /* Expand internal ONDIR environment variables */ |
| 168 | char *expand_envarscxx . . $ expand_envars(a8b8e32347182212).(const char *in) { |
| 169 | int inlen = strlencxx . . $ strlen(751346f8406fd082).(in), outmax = inlen * 2, outlen = 0; |
| 170 | char *out = calloccxx . . $ calloc(63a7bf2941bfcd7a).(1, outmax); |
| 171 | |
| 172 | while (*in) { |
| 173 | const char *mark = in; |
| 174 | |
| 175 | if (*in == '$') { |
| 176 | int bracketed = 0, varlen = 0; |
| 177 | const char *varstart; |
| 178 | |
| 179 | ++in; |
| 180 | if (*in == '{') { ++in; bracketed = 1; } |
| 181 | varstart = in; |
| 182 | while (in[varlen] && (isalnumcxx . . $ `<external>/17904084882347303253/ctype.h:189:10`!(in[varlen]) || in[varlen] == '_')) |
| 183 | ++varlen; |
| 184 | if (bracketed && in[varlen] != '}') |
| 185 | in = mark; |
| 186 | else { |
| 187 | char var[varlen + 1]; |
| 188 | const char *val; |
| 189 | |
| 190 | strncpycxx . . $ strncpy(255158a415b673b0).(var, varstart, varlen); |
| 191 | var[varlen] = 0; |
| 192 | |
| 193 | if (strcmpcxx . . $ strcmp(5ae29d726ae57f88).(var, "ONDIRWD") && (var[0] < '0' || var[0] > '9')) { |
| 194 | in = mark; |
| 195 | } else { |
| 196 | val = getenvcxx . . $ getenv(a8b8e32347182212).(var); |
| 197 | if (val) { |
| 198 | int vallen = strlencxx . . $ strlen(751346f8406fd082).(val); |
| 199 | |
| 200 | if (outlen + vallen >= outmax) { |
| 201 | outmax = outmax * 2 + vallen; |
| 202 | out = realloccxx . . $ realloc(417ab160f6baadc6).(out, outmax); |
| 203 | } |
| 204 | strcatcxx . . $ strcat(b7b3a83273496486).(out, val); |
| 205 | outlen += vallen; |
| 206 | in = mark + varlen + bracketed * 2 + 1; |
| 207 | continue; |
| 208 | } else { |
| 209 | in = mark; |
| 210 | out[outlen] = 0; |
| 211 | } |
| 212 | } |
| 213 | } |
| 214 | } |
| 215 | |
| 216 | /* Add another character */ |
| 217 | if (outlen + 1 >= outmax) { |
| 218 | outmax *= 2; |
| 219 | out = realloccxx . . $ realloc(417ab160f6baadc6).(out, outmax); |
| 220 | } |
| 221 | |
| 222 | out[outlen++] = *in++; |
| 223 | out[outlen] = 0; |
| 224 | } |
| 225 | out[outlen] = 0; |
| 226 | return out; |
| 227 | } |