fork of PCE focusing on macplus, supporting DaynaPort SCSI network emulation
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

ini: Skip conditional blocks if the condition is not met

Conditional blocks whose condition is not met are now completely skipped.
This means in particular that these blocks no longer need to contain
syntactically correct configuration information. All that is required is
that the curly braces match.

Hampa Hug 7a1c596e 4493932d

+38 -37
+38 -37
src/libini/read.c
··· 5 5 /***************************************************************************** 6 6 * File name: src/libini/read.c * 7 7 * Created: 2001-08-24 by Hampa Hug <hampa@hampa.ch> * 8 - * Copyright: (C) 2001-2010 Hampa Hug <hampa@hampa.ch> * 8 + * Copyright: (C) 2001-2013 Hampa Hug <hampa@hampa.ch> * 9 9 *****************************************************************************/ 10 10 11 11 /***************************************************************************** ··· 80 80 } 81 81 82 82 static 83 - int parse_block (scanner_t *scn, ini_sct_t *sct, ini_sct_t *sub, char *buf) 83 + int skip_block (scanner_t *scn) 84 84 { 85 - int r, s; 85 + int c; 86 + unsigned cnt; 86 87 87 - if (scn_match (scn, "{") == 0) { 88 - return (1); 89 - } 88 + cnt = 1; 90 89 91 - if (sub == NULL) { 92 - sub = ini_sct_new (NULL); 90 + while ((c = scn_get_chr (scn, 0)) != 0) { 91 + scn_rmv_chr (scn, 1); 93 92 94 - if (sub == NULL) { 95 - return (1); 93 + if (c == '{') { 94 + cnt += 1; 96 95 } 97 - 98 - sub->parent = sct; 96 + else if (c == '}') { 97 + cnt -= 1; 99 98 100 - s = 1; 101 - } 102 - else { 103 - s = 0; 99 + if (cnt == 0) { 100 + return (0); 101 + } 102 + } 104 103 } 105 104 105 + return (1); 106 + } 106 107 107 - r = parse_section (scn, sub, buf); 108 + static 109 + int parse_block (scanner_t *scn, ini_sct_t *sct, char *buf, int skip) 110 + { 111 + if (scn_match (scn, "{") == 0) { 112 + return (1); 113 + } 108 114 109 - if (s) { 110 - ini_sct_del (sub); 115 + if (skip) { 116 + return (skip_block (scn)); 111 117 } 112 118 113 - if (r) { 119 + if (parse_section (scn, sct, buf)) { 114 120 return (1); 115 121 } 116 122 ··· 154 160 static 155 161 int parse_if (scanner_t *scn, ini_sct_t *sct, char *buf) 156 162 { 157 - int done; 158 - ini_sct_t *sub; 163 + int done, skip; 159 164 ini_val_t val; 160 165 161 166 ini_val_init (&val, NULL); ··· 166 171 } 167 172 168 173 if ((val.type == INI_VAL_INT) && (val.val.u32 != 0)) { 169 - sub = sct; 174 + skip = 0; 170 175 done = 1; 171 176 } 172 177 else { 173 - sub = NULL; 178 + skip = 1; 174 179 done = 0; 175 180 } 176 181 177 182 ini_val_free (&val); 178 183 179 - if (parse_block (scn, sct, sub, buf)) { 184 + if (parse_block (scn, sct, buf, skip)) { 180 185 return (1); 181 186 } 182 187 ··· 189 194 return (1); 190 195 } 191 196 192 - if ((val.type == INI_VAL_INT) && (val.val.u32 != 0)) { 193 - sub = done ? NULL : sct; 194 - } 195 - else { 196 - sub = NULL; 197 - } 197 + skip = 1; 198 198 199 - if (sub != NULL) { 200 - done = 1; 199 + if (done == 0) { 200 + if ((val.type == INI_VAL_INT) && (val.val.u32 != 0)) { 201 + skip = 0; 202 + done = 1; 203 + } 201 204 } 202 205 203 206 ini_val_free (&val); 204 207 205 - if (parse_block (scn, sct, sub, buf)) { 208 + if (parse_block (scn, sct, buf, skip)) { 206 209 return (1); 207 210 } 208 211 } 209 212 else { 210 - sub = done ? NULL : sct; 211 - 212 - if (parse_block (scn, sct, sub, buf)) { 213 + if (parse_block (scn, sct, buf, done)) { 213 214 return (1); 214 215 } 215 216