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

Function parse_conf_buf

src/cfgfiles.c:1692–1807  ·  view source on GitHub ↗

* Parse config buffer, handling comments, empty lines, config sections, * CHOOSE, and line continuation, calling proc for every valid line. * * Continued lines are merged together with one space in between. */

Source from the content-addressed store, hash-verified

1690 * Continued lines are merged together with one space in between.
1691 */
1692staticfn void
1693parse_conf_buf(struct _cnf_parser_state *p, boolean (*proc)(char *arg))
1694{
1695 p->cont = FALSE;
1696 p->pbreak = FALSE;
1697 p->ep = strchr(p->inbuf, '\n');
1698 if (p->skip) { /* in case previous line was too long */
1699 if (p->ep)
1700 p->skip = FALSE; /* found newline; next line is normal */
1701 } else {
1702 if (!p->ep) { /* newline missing */
1703 if (strlen(p->inbuf) < (p->inbufsz - 2)) {
1704 /* likely the last line of file is just
1705 missing a newline; process it anyway */
1706 p->ep = eos(p->inbuf);
1707 } else {
1708 config_error_add("Line too long, skipping");
1709 p->skip = TRUE; /* discard next fgets */
1710 }
1711 } else {
1712 *p->ep = '\0'; /* remove newline */
1713 }
1714 if (p->ep) {
1715 char *tmpbuf = (char *) 0;
1716 int len;
1717 boolean ignoreline = FALSE;
1718 boolean oldline = FALSE;
1719
1720 /* line continuation (trailing '\') */
1721 p->morelines = (--p->ep >= p->inbuf && *p->ep == '\\');
1722 if (p->morelines)
1723 *p->ep = '\0';
1724
1725 /* trim off spaces at end of line */
1726 while (p->ep >= p->inbuf
1727 && (*p->ep == ' ' || *p->ep == '\t' || *p->ep == '\r'))
1728 *p->ep-- = '\0';
1729
1730 if (!config_error_nextline(p->inbuf)) {
1731 p->rv = FALSE;
1732 if (p->buf)
1733 free(p->buf), p->buf = (char *) 0;
1734 p->pbreak = TRUE;
1735 return;
1736 }
1737
1738 p->ep = p->inbuf;
1739 while (*p->ep == ' ' || *p->ep == '\t')
1740 ++p->ep;
1741
1742 /* ignore empty lines and full-line comment lines */
1743 if (!*p->ep || *p->ep == '#')
1744 ignoreline = TRUE;
1745
1746 if (p->buf)
1747 oldline = TRUE;
1748
1749 /* merge now read line with previous ones, if necessary */

Callers 2

parse_conf_strFunction · 0.85
parse_conf_fileFunction · 0.85

Calls 8

eosFunction · 0.85
config_error_addFunction · 0.85
config_error_nextlineFunction · 0.85
handle_config_sectionFunction · 0.85
find_optparamFunction · 0.85
choose_random_partFunction · 0.85
dupstrFunction · 0.85
allocFunction · 0.70

Tested by

no test coverage detected