3 * Traakan, Inc., Los Altos, CA
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice unmodified, this list of conditions, and the following
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 * Stanza files look about like this:
38 * These are used for config files.
46 ndmstz_getline (FILE *fp, char *buf, int n_buf)
64 while ((c = getc(fp)) != EOF && c != '\n')
71 while ((c = getc(fp)) != EOF && c != '\n') {
72 if (p < &buf[n_buf-1])
80 ndmstz_getstanza (FILE *fp, char *buf, int n_buf)
91 goto again; /* blank line */
94 /* not a stanza header, eat line */
95 while ((c = getc(fp)) != EOF && c != '\n')
101 while ((c = getc(fp)) != EOF && c != '\n' && c != ']') {
102 if (p < &buf[n_buf-1])
108 /* eat rest of line */
109 while ((c = getc(fp)) != EOF && c != '\n')
113 /* fp is left pointing to begining of first line */
119 ndmstz_parse (char *buf, char *argv[], int max_argv)
128 while ((c = *p++) != 0) {
147 if (argc > max_argv-1)
153 if (c == '"' || c == '\'') {
172 main (int ac, char *av[])
180 printf ("bad usage\n");
184 fp = fopen (av[1], "r");
191 while (ndmstz_getstanza (fp, buf, sizeof buf) >= 0)
192 printf ("%s\n", buf);
194 for (i = 2; i < ac; i++) {
197 while (ndmstz_getstanza (fp, buf, sizeof buf) >= 0) {
198 if (strcmp (av[i], buf) == 0) {
204 printf ("Search for '%s' failed\n", av[i]);
207 printf ("'%s'\n", buf);
208 printf ("========================================\n");
209 while (ndmstz_getline (fp, buf, sizeof buf) >= 0) {
210 printf ("= %s", buf);
211 argc = ndmstz_parse (buf, argv, 100);
212 printf (" [%d]\n", argc);
214 printf ("========================================\n");
223 #endif /* SELF_TEST */