[READ-ONLY] Mirror of https://github.com/VibeDevelopers/atheme. Modified fork of atheme IRC Services www.vibetalk.net/
0

Configure Feed

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

libathemecore/commandhelp.c: handle indented conditions in help files

I had intended while rewriting this functionality a while back to allow
for help files to have indented conditions to aid readability for help
file maintainers.

However, I only added such a file very recently, which resulted in
garbage output because I neglected to modify the function that actually
processes the file's lines (rather than evaluates the conditions on
them).

Fixes: atheme/atheme@2a9d68b63285ce77d157
Reported-By: KindOne (Libera.Chat)

Aaron Jones (Mar 25, 2024, 8:49 AM UTC) 10b376b9 67483239

+31 -18
+31 -18
libathemecore/commandhelp.c
··· 169 169 170 170 unsigned int ifnest_false = 0; 171 171 unsigned int ifnest = 0; 172 + unsigned int line = 0; 172 173 char buf[BUFSIZE]; 173 174 174 175 while (fgets(buf, sizeof buf, fh)) 175 176 { 177 + line++; 178 + 176 179 (void) strip(buf); 177 180 (void) replace(buf, sizeof buf, "&nick&", service_name); 178 181 179 - if (strncasecmp(buf, "#if", 3) == 0) 182 + char *str = buf; 183 + 184 + if (*str == '#') 180 185 { 181 - if (ifnest_false || ! help_evaluate_condition(si, buf + 3)) 182 - ifnest_false++; 186 + str++; 183 187 184 - ifnest++; 185 - continue; 186 - } 188 + while (*str == ' ' || *str == '\t') 189 + str++; 187 190 188 - if (strncasecmp(buf, "#endif", 6) == 0) 189 - { 190 - if (ifnest_false) 191 - ifnest_false--; 191 + if (strncasecmp(str, "if ", 3) == 0 || strncasecmp(str, "if\t", 3) == 0) 192 + { 193 + str += 3; 192 194 193 - if (ifnest) 194 - ifnest--; 195 + if (ifnest_false || ! help_evaluate_condition(si, str)) 196 + ifnest_false++; 195 197 196 - continue; 197 - } 198 + ifnest++; 199 + } 200 + else if (strncasecmp(str, "endif", 5) == 0) 201 + { 202 + if (ifnest_false) 203 + ifnest_false--; 198 204 199 - if (strncasecmp(buf, "#else", 5) == 0) 200 - { 201 - if (ifnest && ifnest_false < 2) 202 - ifnest_false ^= 1; 205 + if (ifnest) 206 + ifnest--; 207 + } 208 + else if (strncasecmp(str, "else", 4) == 0) 209 + { 210 + if (ifnest && ifnest_false < 2) 211 + ifnest_false ^= 1; 212 + } 213 + else 214 + (void) slog(LG_ERROR, "%s: unrecognised directive '%s' in help file '%s' line %u", 215 + MOWGLI_FUNC_NAME, str, path, line); 203 216 204 217 continue; 205 218 }