MCPcopy Create free account
hub / github.com/NetHack/NetHack / is_config_section

Function is_config_section

src/cfgfiles.c:522–549  ·  view source on GitHub ↗

check for " [ anything-except-bracket-or-empty ] # arbitrary-comment" with spaces optional; returns pointer to "anything-except..." (with trailing " ] #..." stripped) if ok, otherwise Null */

Source from the content-addressed store, hash-verified

520 with spaces optional; returns pointer to "anything-except..." (with
521 trailing " ] #..." stripped) if ok, otherwise Null */
522staticfn char *
523is_config_section(
524 char *str) /* trailing spaces are stripped, ']' too iff result is good */
525{
526 char *a, *c, *z;
527
528 /* remove any spaces at start and end; won't significantly interfere
529 with echoing the string in a config error message, if warranted */
530 a = trimspaces(str);
531 /* first character should be open square bracket; set pointer past it */
532 if (*a++ != '[')
533 return (char *) 0;
534 /* last character should be close bracket, ignoring any comment */
535 z = strchr(a, ']');
536 if (!z)
537 return (char *) 0;
538 /* comment, if present, can be preceded by spaces */
539 for (c = z + 1; *c == ' '; ++c)
540 continue;
541 if (*c && *c != '#')
542 return (char *) 0;
543 /* we now know that result is good; there won't be a config error
544 message so we can modify the input string */
545 *z = '\0';
546 /* 'a' points past '[' and the string ends where ']' was; remove any
547 spaces between '[' and choice-start and between choice-end and ']' */
548 return trimspaces(a);
549}
550
551staticfn boolean
552handle_config_section(char *buf)

Callers 1

handle_config_sectionFunction · 0.85

Calls 1

trimspacesFunction · 0.85

Tested by

no test coverage detected