| 9297 | } |
| 9298 | |
| 9299 | int |
| 9300 | add_autopickup_exception(const char *mapping) |
| 9301 | { |
| 9302 | static const char |
| 9303 | APE_regex_error[] = "regex error in AUTOPICKUP_EXCEPTION", |
| 9304 | APE_syntax_error[] = "syntax error in AUTOPICKUP_EXCEPTION"; |
| 9305 | |
| 9306 | struct autopickup_exception *ape; |
| 9307 | char text[256], end; |
| 9308 | int n; |
| 9309 | boolean grab = FALSE; |
| 9310 | |
| 9311 | /* scan length limit used to be 255, but smaller size allows the |
| 9312 | quoted value to fit within BUFSZ, simplifying formatting elsewhere; |
| 9313 | this used to ignore the possibility of trailing junk but now checks |
| 9314 | for it, accepting whitespace but rejecting anything else unless it |
| 9315 | starts with '#" for a comment */ |
| 9316 | end = '\0'; |
| 9317 | if ((n = sscanf(mapping, "\"<%253[^\"]\" %c", text, &end)) == 1 |
| 9318 | || (n == 2 && end == '#')) { |
| 9319 | grab = TRUE; |
| 9320 | } else if ((n = sscanf(mapping, "\">%253[^\"]\" %c", text, &end)) == 1 |
| 9321 | || (n = sscanf(mapping, "\"%253[^\"]\" %c", text, &end)) == 1 |
| 9322 | || (n == 2 && end == '#')) { |
| 9323 | grab = FALSE; |
| 9324 | } else { |
| 9325 | config_error_add("%s", APE_syntax_error); |
| 9326 | return 0; |
| 9327 | } |
| 9328 | |
| 9329 | ape = (struct autopickup_exception *) alloc(sizeof *ape); |
| 9330 | ape->regex = regex_init(); |
| 9331 | if (!regex_compile(text, ape->regex)) { |
| 9332 | char errbuf[BUFSZ]; |
| 9333 | char *re_error_desc = regex_error_desc(ape->regex, errbuf); |
| 9334 | |
| 9335 | /* free first in case reason for failure was insufficient memory */ |
| 9336 | regex_free(ape->regex); |
| 9337 | free((genericptr_t) ape); |
| 9338 | config_error_add("%s: %s", APE_regex_error, re_error_desc); |
| 9339 | return 0; |
| 9340 | } |
| 9341 | ape->pattern = dupstr(text); |
| 9342 | ape->grab = grab; |
| 9343 | ape->next = ga.apelist; |
| 9344 | ga.apelist = ape; |
| 9345 | return 1; |
| 9346 | } |
| 9347 | |
| 9348 | staticfn void |
| 9349 | remove_autopickup_exception(struct autopickup_exception *whichape) |
no test coverage detected