Annotation of mandoc/main.c, Revision 1.44
1.44 ! kristaps 1: /* $Id: main.c,v 1.43 2009/09/16 22:17:27 kristaps Exp $ */
1.1 kristaps 2: /*
1.26 kristaps 3: * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
1.1 kristaps 4: *
5: * Permission to use, copy, modify, and distribute this software for any
1.25 kristaps 6: * purpose with or without fee is hereby granted, provided that the above
7: * copyright notice and this permission notice appear in all copies.
1.1 kristaps 8: *
1.25 kristaps 9: * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
10: * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
11: * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
12: * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
13: * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
14: * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
15: * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
1.1 kristaps 16: */
17: #include <sys/stat.h>
18:
19: #include <assert.h>
20: #include <err.h>
21: #include <fcntl.h>
22: #include <stdio.h>
23: #include <stdlib.h>
24: #include <string.h>
25: #include <unistd.h>
26:
27: #include "mdoc.h"
1.10 kristaps 28: #include "man.h"
1.1 kristaps 29:
1.16 kristaps 30: /* Account for FreeBSD and Linux in our declarations. */
31:
1.3 kristaps 32: #ifdef __linux__
33: extern int getsubopt(char **, char * const *, char **);
34: # ifndef __dead
35: # define __dead __attribute__((__noreturn__))
36: # endif
1.13 kristaps 37: #elif defined(__dead2)
1.10 kristaps 38: # ifndef __dead
39: # define __dead __dead2
40: # endif
1.3 kristaps 41: #endif
42:
1.42 kristaps 43: typedef void (*out_mdoc)(void *, const struct mdoc *);
44: typedef void (*out_man)(void *, const struct man *);
1.22 kristaps 45: typedef void (*out_free)(void *);
46:
1.5 kristaps 47: struct buf {
48: char *buf;
49: size_t sz;
50: };
51:
1.19 kristaps 52: enum intt {
53: INTT_AUTO,
54: INTT_MDOC,
55: INTT_MAN
56: };
57:
58: enum outt {
59: OUTT_ASCII = 0,
60: OUTT_TREE,
1.43 kristaps 61: OUTT_HTML,
1.19 kristaps 62: OUTT_LINT
63: };
64:
1.5 kristaps 65: struct curparse {
1.22 kristaps 66: const char *file; /* Current parse. */
67: int fd; /* Current parse. */
1.5 kristaps 68: int wflags;
1.36 kristaps 69: #define WARN_WALL (1 << 0) /* All-warnings mask. */
1.1 kristaps 70: #define WARN_WERR (1 << 2) /* Warnings->errors. */
1.23 kristaps 71: int fflags;
72: #define IGN_SCOPE (1 << 0) /* Ignore scope errors. */
1.24 kristaps 73: #define NO_IGN_ESCAPE (1 << 1) /* Don't ignore bad escapes. */
74: #define NO_IGN_MACRO (1 << 2) /* Don't ignore bad macros. */
75: #define NO_IGN_CHARS (1 << 3) /* Don't ignore bad chars. */
1.39 kristaps 76: #define IGN_ERRORS (1 << 4) /* Ignore failed parse. */
1.29 kristaps 77: enum intt inttype; /* Input parsers... */
1.19 kristaps 78: struct man *man;
1.22 kristaps 79: struct man *lastman;
1.19 kristaps 80: struct mdoc *mdoc;
1.22 kristaps 81: struct mdoc *lastmdoc;
1.29 kristaps 82: enum outt outtype; /* Output devices... */
1.22 kristaps 83: out_mdoc outmdoc;
84: out_man outman;
85: out_free outfree;
86: void *outdata;
1.44 ! kristaps 87: char *outopts;
1.5 kristaps 88: };
1.1 kristaps 89:
1.44 ! kristaps 90: extern void *html_alloc(char *);
1.43 kristaps 91: extern void html_mdoc(void *, const struct mdoc *);
92: extern void html_man(void *, const struct man *);
93: extern void html_free(void *);
1.1 kristaps 94: extern void *ascii_alloc(void);
1.42 kristaps 95: extern void tree_mdoc(void *, const struct mdoc *);
96: extern void tree_man(void *, const struct man *);
97: extern void terminal_mdoc(void *, const struct mdoc *);
98: extern void terminal_man(void *, const struct man *);
1.1 kristaps 99: extern void terminal_free(void *);
100:
101: static int foptions(int *, char *);
102: static int toptions(enum outt *, char *);
1.10 kristaps 103: static int moptions(enum intt *, char *);
1.1 kristaps 104: static int woptions(int *, char *);
105: static int merr(void *, int, int, const char *);
1.37 kristaps 106: static int mwarn(void *, int, int, const char *);
1.19 kristaps 107: static int ffile(struct buf *, struct buf *,
108: const char *, struct curparse *);
1.5 kristaps 109: static int fdesc(struct buf *, struct buf *,
1.19 kristaps 110: struct curparse *);
1.22 kristaps 111: static int pset(const char *, int, struct curparse *,
1.19 kristaps 112: struct man **, struct mdoc **);
113: static struct man *man_init(struct curparse *);
114: static struct mdoc *mdoc_init(struct curparse *);
1.10 kristaps 115: __dead static void version(void);
116: __dead static void usage(void);
1.1 kristaps 117:
1.22 kristaps 118: extern char *__progname;
119:
1.1 kristaps 120:
121: int
122: main(int argc, char *argv[])
123: {
1.19 kristaps 124: int c, rc;
1.5 kristaps 125: struct buf ln, blk;
126: struct curparse curp;
1.1 kristaps 127:
1.5 kristaps 128: bzero(&curp, sizeof(struct curparse));
129:
1.19 kristaps 130: curp.inttype = INTT_AUTO;
1.22 kristaps 131: curp.outtype = OUTT_ASCII;
1.19 kristaps 132:
1.1 kristaps 133: /* LINTED */
1.44 ! kristaps 134: while (-1 != (c = getopt(argc, argv, "f:m:o:T:VW:")))
1.1 kristaps 135: switch (c) {
136: case ('f'):
1.19 kristaps 137: if ( ! foptions(&curp.fflags, optarg))
1.32 kristaps 138: return(EXIT_FAILURE);
1.1 kristaps 139: break;
1.10 kristaps 140: case ('m'):
1.19 kristaps 141: if ( ! moptions(&curp.inttype, optarg))
1.32 kristaps 142: return(EXIT_FAILURE);
1.10 kristaps 143: break;
1.44 ! kristaps 144: case ('o'):
! 145: curp.outopts = optarg;
! 146: break;
1.1 kristaps 147: case ('T'):
1.22 kristaps 148: if ( ! toptions(&curp.outtype, optarg))
1.32 kristaps 149: return(EXIT_FAILURE);
1.1 kristaps 150: break;
151: case ('W'):
1.5 kristaps 152: if ( ! woptions(&curp.wflags, optarg))
1.32 kristaps 153: return(EXIT_FAILURE);
1.1 kristaps 154: break;
155: case ('V'):
156: version();
157: /* NOTREACHED */
158: default:
159: usage();
160: /* NOTREACHED */
161: }
162:
163: argc -= optind;
164: argv += optind;
165:
1.5 kristaps 166: bzero(&ln, sizeof(struct buf));
167: bzero(&blk, sizeof(struct buf));
1.1 kristaps 168:
1.22 kristaps 169: rc = 1;
1.1 kristaps 170:
1.30 kristaps 171: if (NULL == *argv) {
172: curp.file = "<stdin>";
173: curp.fd = STDIN_FILENO;
1.39 kristaps 174:
175: c = fdesc(&blk, &ln, &curp);
176: if ( ! (IGN_ERRORS & curp.fflags))
177: rc = 1 == c ? 1 : 0;
178: else
179: rc = -1 == c ? 0 : 1;
1.30 kristaps 180: }
1.22 kristaps 181:
182: while (rc && *argv) {
1.39 kristaps 183: c = ffile(&blk, &ln, *argv, &curp);
184: if ( ! (IGN_ERRORS & curp.fflags))
185: rc = 1 == c ? 1 : 0;
186: else
187: rc = -1 == c ? 0 : 1;
188:
1.22 kristaps 189: argv++;
190: if (*argv && rc) {
191: if (curp.lastman)
192: if ( ! man_reset(curp.lastman))
193: rc = 0;
194: if (curp.lastmdoc)
195: if ( ! mdoc_reset(curp.lastmdoc))
196: rc = 0;
197: curp.lastman = NULL;
198: curp.lastmdoc = NULL;
1.4 kristaps 199: }
1.1 kristaps 200: }
201:
1.5 kristaps 202: if (blk.buf)
203: free(blk.buf);
204: if (ln.buf)
205: free(ln.buf);
1.22 kristaps 206: if (curp.outfree)
207: (*curp.outfree)(curp.outdata);
1.19 kristaps 208: if (curp.mdoc)
209: mdoc_free(curp.mdoc);
210: if (curp.man)
211: man_free(curp.man);
1.1 kristaps 212:
213: return(rc ? EXIT_SUCCESS : EXIT_FAILURE);
214: }
215:
216:
217: __dead static void
218: version(void)
219: {
220:
221: (void)printf("%s %s\n", __progname, VERSION);
1.18 kristaps 222: exit(EXIT_SUCCESS);
1.1 kristaps 223: }
224:
225:
226: __dead static void
227: usage(void)
228: {
229:
1.12 kristaps 230: (void)fprintf(stderr, "usage: %s [-V] [-foption...] "
231: "[-mformat] [-Toutput] [-Werr...]\n",
232: __progname);
1.18 kristaps 233: exit(EXIT_FAILURE);
1.1 kristaps 234: }
235:
236:
1.19 kristaps 237: static struct man *
238: man_init(struct curparse *curp)
239: {
240: int pflags;
241: struct man *man;
242: struct man_cb mancb;
243:
244: mancb.man_err = merr;
1.37 kristaps 245: mancb.man_warn = mwarn;
1.19 kristaps 246:
1.30 kristaps 247: /* Defaults from mandoc.1. */
1.27 kristaps 248:
1.33 kristaps 249: pflags = MAN_IGN_MACRO | MAN_IGN_ESCAPE | MAN_IGN_CHARS;
1.27 kristaps 250:
1.20 kristaps 251: if (curp->fflags & NO_IGN_MACRO)
252: pflags &= ~MAN_IGN_MACRO;
1.31 kristaps 253: if (curp->fflags & NO_IGN_CHARS)
254: pflags &= ~MAN_IGN_CHARS;
1.33 kristaps 255: if (curp->fflags & NO_IGN_ESCAPE)
256: pflags &= ~MAN_IGN_ESCAPE;
1.19 kristaps 257:
258: if (NULL == (man = man_alloc(curp, pflags, &mancb)))
259: warnx("memory exhausted");
260:
261: return(man);
262: }
263:
264:
265: static struct mdoc *
266: mdoc_init(struct curparse *curp)
267: {
268: int pflags;
269: struct mdoc *mdoc;
270: struct mdoc_cb mdoccb;
271:
272: mdoccb.mdoc_err = merr;
1.37 kristaps 273: mdoccb.mdoc_warn = mwarn;
1.19 kristaps 274:
1.30 kristaps 275: /* Defaults from mandoc.1. */
1.27 kristaps 276:
1.24 kristaps 277: pflags = MDOC_IGN_MACRO | MDOC_IGN_ESCAPE | MDOC_IGN_CHARS;
1.19 kristaps 278:
279: if (curp->fflags & IGN_SCOPE)
280: pflags |= MDOC_IGN_SCOPE;
1.24 kristaps 281: if (curp->fflags & NO_IGN_ESCAPE)
282: pflags &= ~MDOC_IGN_ESCAPE;
283: if (curp->fflags & NO_IGN_MACRO)
284: pflags &= ~MDOC_IGN_MACRO;
285: if (curp->fflags & NO_IGN_CHARS)
286: pflags &= ~MDOC_IGN_CHARS;
1.19 kristaps 287:
288: if (NULL == (mdoc = mdoc_alloc(curp, pflags, &mdoccb)))
1.24 kristaps 289: warnx("memory exhausted");
1.19 kristaps 290:
291: return(mdoc);
292: }
293:
294:
295: static int
296: ffile(struct buf *blk, struct buf *ln,
297: const char *file, struct curparse *curp)
1.1 kristaps 298: {
1.19 kristaps 299: int c;
1.1 kristaps 300:
1.19 kristaps 301: curp->file = file;
302: if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) {
303: warn("%s", curp->file);
1.39 kristaps 304: return(-1);
1.1 kristaps 305: }
306:
1.19 kristaps 307: c = fdesc(blk, ln, curp);
1.1 kristaps 308:
1.19 kristaps 309: if (-1 == close(curp->fd))
310: warn("%s", curp->file);
1.1 kristaps 311:
312: return(c);
313: }
314:
315:
316: static int
1.19 kristaps 317: fdesc(struct buf *blk, struct buf *ln, struct curparse *curp)
1.1 kristaps 318: {
319: size_t sz;
320: ssize_t ssz;
321: struct stat st;
1.29 kristaps 322: int j, i, pos, lnn, comment;
1.19 kristaps 323: struct man *man;
324: struct mdoc *mdoc;
1.10 kristaps 325:
1.19 kristaps 326: sz = BUFSIZ;
327: man = NULL;
328: mdoc = NULL;
1.1 kristaps 329:
330: /*
1.19 kristaps 331: * Two buffers: ln and buf. buf is the input buffer optimised
332: * here for each file's block size. ln is a line buffer. Both
1.1 kristaps 333: * growable, hence passed in by ptr-ptr.
334: */
335:
1.19 kristaps 336: if (-1 == fstat(curp->fd, &st))
1.32 kristaps 337: warn("%s", curp->file);
1.6 kristaps 338: else if ((size_t)st.st_blksize > sz)
339: sz = st.st_blksize;
1.1 kristaps 340:
1.5 kristaps 341: if (sz > blk->sz) {
342: blk->buf = realloc(blk->buf, sz);
1.19 kristaps 343: if (NULL == blk->buf) {
344: warn("realloc");
1.39 kristaps 345: return(-1);
1.19 kristaps 346: }
1.5 kristaps 347: blk->sz = sz;
1.1 kristaps 348: }
349:
1.19 kristaps 350: /* Fill buf with file blocksize. */
1.1 kristaps 351:
1.29 kristaps 352: for (lnn = pos = comment = 0; ; ) {
1.19 kristaps 353: if (-1 == (ssz = read(curp->fd, blk->buf, sz))) {
354: warn("%s", curp->file);
1.39 kristaps 355: return(-1);
1.1 kristaps 356: } else if (0 == ssz)
357: break;
358:
1.19 kristaps 359: /* Parse the read block into partial or full lines. */
360:
1.1 kristaps 361: for (i = 0; i < (int)ssz; i++) {
1.5 kristaps 362: if (pos >= (int)ln->sz) {
363: ln->sz += 256; /* Step-size. */
364: ln->buf = realloc(ln->buf, ln->sz);
1.19 kristaps 365: if (NULL == ln->buf) {
366: warn("realloc");
1.39 kristaps 367: return(-1);
1.19 kristaps 368: }
1.1 kristaps 369: }
370:
1.5 kristaps 371: if ('\n' != blk->buf[i]) {
1.29 kristaps 372: if (comment)
373: continue;
1.5 kristaps 374: ln->buf[pos++] = blk->buf[i];
1.29 kristaps 375:
376: /* Handle in-line `\"' comments. */
377:
378: if (1 == pos || '\"' != ln->buf[pos - 1])
379: continue;
380:
381: for (j = pos - 2; j >= 0; j--)
382: if ('\\' != ln->buf[j])
383: break;
384:
385: if ( ! ((pos - 2 - j) % 2))
386: continue;
387:
388: comment = 1;
389: pos -= 2;
1.1 kristaps 390: continue;
1.29 kristaps 391: }
1.1 kristaps 392:
1.29 kristaps 393: /* Handle escaped `\\n' newlines. */
1.1 kristaps 394:
1.29 kristaps 395: if (pos > 0 && 0 == comment &&
396: '\\' == ln->buf[pos - 1]) {
1.1 kristaps 397: for (j = pos - 1; j >= 0; j--)
1.5 kristaps 398: if ('\\' != ln->buf[j])
1.1 kristaps 399: break;
400: if ( ! ((pos - j) % 2)) {
401: pos--;
402: lnn++;
403: continue;
404: }
405: }
406:
1.5 kristaps 407: ln->buf[pos] = 0;
1.19 kristaps 408: lnn++;
1.29 kristaps 409:
410: /* If unset, assign parser in pset(). */
1.19 kristaps 411:
412: if ( ! (man || mdoc) && ! pset(ln->buf,
413: pos, curp, &man, &mdoc))
1.39 kristaps 414: return(-1);
1.19 kristaps 415:
1.29 kristaps 416: pos = comment = 0;
1.19 kristaps 417:
1.30 kristaps 418: /* Pass down into parsers. */
419:
1.10 kristaps 420: if (man && ! man_parseln(man, lnn, ln->buf))
1.1 kristaps 421: return(0);
1.19 kristaps 422: if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf))
423: return(0);
1.1 kristaps 424: }
425: }
426:
1.29 kristaps 427: /* NOTE a parser may not have been assigned, yet. */
1.19 kristaps 428:
1.22 kristaps 429: if ( ! (man || mdoc)) {
1.41 kristaps 430: (void)fprintf(stderr, "%s: not a manual\n",
431: curp->file);
1.22 kristaps 432: return(0);
433: }
434:
435: if (mdoc && ! mdoc_endparse(mdoc))
436: return(0);
437: if (man && ! man_endparse(man))
438: return(0);
1.19 kristaps 439:
1.29 kristaps 440: /* If unset, allocate output dev now (if applicable). */
1.22 kristaps 441:
442: if ( ! (curp->outman && curp->outmdoc)) {
443: switch (curp->outtype) {
1.43 kristaps 444: case (OUTT_HTML):
1.44 ! kristaps 445: curp->outdata = html_alloc(curp->outopts);
1.43 kristaps 446: curp->outman = html_man;
447: curp->outmdoc = html_mdoc;
448: curp->outfree = html_free;
449: break;
1.22 kristaps 450: case (OUTT_TREE):
451: curp->outman = tree_man;
452: curp->outmdoc = tree_mdoc;
453: break;
454: case (OUTT_LINT):
455: break;
456: default:
457: curp->outdata = ascii_alloc();
458: curp->outman = terminal_man;
459: curp->outmdoc = terminal_mdoc;
460: curp->outfree = terminal_free;
461: break;
462: }
463: }
464:
465: /* Execute the out device, if it exists. */
466:
467: if (man && curp->outman)
1.42 kristaps 468: (*curp->outman)(curp->outdata, man);
1.22 kristaps 469: if (mdoc && curp->outmdoc)
1.42 kristaps 470: (*curp->outmdoc)(curp->outdata, mdoc);
1.22 kristaps 471:
472: return(1);
1.19 kristaps 473: }
474:
475:
476: static int
1.22 kristaps 477: pset(const char *buf, int pos, struct curparse *curp,
1.19 kristaps 478: struct man **man, struct mdoc **mdoc)
479: {
1.29 kristaps 480: int i;
1.19 kristaps 481:
482: /*
483: * Try to intuit which kind of manual parser should be used. If
484: * passed in by command-line (-man, -mdoc), then use that
485: * explicitly. If passed as -mandoc, then try to guess from the
1.30 kristaps 486: * line: either skip dot-lines, use -mdoc when finding `.Dt', or
1.19 kristaps 487: * default to -man, which is more lenient.
488: */
489:
1.29 kristaps 490: if (buf[0] == '.') {
491: for (i = 1; buf[i]; i++)
492: if (' ' != buf[i] && '\t' != buf[i])
493: break;
494: if (0 == buf[i])
495: return(1);
496: }
1.10 kristaps 497:
1.19 kristaps 498: switch (curp->inttype) {
499: case (INTT_MDOC):
500: if (NULL == curp->mdoc)
501: curp->mdoc = mdoc_init(curp);
502: if (NULL == (*mdoc = curp->mdoc))
503: return(0);
1.22 kristaps 504: curp->lastmdoc = *mdoc;
1.19 kristaps 505: return(1);
506: case (INTT_MAN):
507: if (NULL == curp->man)
508: curp->man = man_init(curp);
509: if (NULL == (*man = curp->man))
510: return(0);
1.22 kristaps 511: curp->lastman = *man;
1.19 kristaps 512: return(1);
513: default:
514: break;
515: }
516:
517: if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) {
518: if (NULL == curp->mdoc)
519: curp->mdoc = mdoc_init(curp);
520: if (NULL == (*mdoc = curp->mdoc))
521: return(0);
1.22 kristaps 522: curp->lastmdoc = *mdoc;
1.19 kristaps 523: return(1);
524: }
525:
526: if (NULL == curp->man)
527: curp->man = man_init(curp);
528: if (NULL == (*man = curp->man))
529: return(0);
1.22 kristaps 530: curp->lastman = *man;
1.19 kristaps 531: return(1);
1.10 kristaps 532: }
533:
534:
535: static int
536: moptions(enum intt *tflags, char *arg)
537: {
538:
1.17 kristaps 539: if (0 == strcmp(arg, "doc"))
1.10 kristaps 540: *tflags = INTT_MDOC;
1.19 kristaps 541: else if (0 == strcmp(arg, "andoc"))
542: *tflags = INTT_AUTO;
1.17 kristaps 543: else if (0 == strcmp(arg, "an"))
1.10 kristaps 544: *tflags = INTT_MAN;
545: else {
546: warnx("bad argument: -m%s", arg);
547: return(0);
548: }
549:
550: return(1);
1.1 kristaps 551: }
552:
553:
554: static int
555: toptions(enum outt *tflags, char *arg)
556: {
557:
558: if (0 == strcmp(arg, "ascii"))
559: *tflags = OUTT_ASCII;
560: else if (0 == strcmp(arg, "lint"))
561: *tflags = OUTT_LINT;
562: else if (0 == strcmp(arg, "tree"))
563: *tflags = OUTT_TREE;
1.43 kristaps 564: else if (0 == strcmp(arg, "html"))
565: *tflags = OUTT_HTML;
1.1 kristaps 566: else {
567: warnx("bad argument: -T%s", arg);
568: return(0);
569: }
570:
571: return(1);
572: }
573:
574:
575: static int
576: foptions(int *fflags, char *arg)
577: {
1.34 kristaps 578: char *v, *o;
1.39 kristaps 579: char *toks[7];
1.1 kristaps 580:
581: toks[0] = "ign-scope";
1.24 kristaps 582: toks[1] = "no-ign-escape";
583: toks[2] = "no-ign-macro";
584: toks[3] = "no-ign-chars";
1.39 kristaps 585: toks[4] = "ign-errors";
586: toks[5] = "strict";
587: toks[6] = NULL;
1.1 kristaps 588:
1.34 kristaps 589: while (*arg) {
590: o = arg;
1.1 kristaps 591: switch (getsubopt(&arg, toks, &v)) {
592: case (0):
1.15 kristaps 593: *fflags |= IGN_SCOPE;
1.1 kristaps 594: break;
595: case (1):
1.24 kristaps 596: *fflags |= NO_IGN_ESCAPE;
1.1 kristaps 597: break;
598: case (2):
1.24 kristaps 599: *fflags |= NO_IGN_MACRO;
1.1 kristaps 600: break;
1.20 kristaps 601: case (3):
1.24 kristaps 602: *fflags |= NO_IGN_CHARS;
603: break;
604: case (4):
1.39 kristaps 605: *fflags |= IGN_ERRORS;
606: break;
607: case (5):
1.24 kristaps 608: *fflags |= NO_IGN_ESCAPE |
609: NO_IGN_MACRO | NO_IGN_CHARS;
1.20 kristaps 610: break;
1.1 kristaps 611: default:
1.34 kristaps 612: warnx("bad argument: -f%s", o);
1.1 kristaps 613: return(0);
614: }
1.34 kristaps 615: }
1.1 kristaps 616:
617: return(1);
618: }
619:
620:
621: static int
622: woptions(int *wflags, char *arg)
623: {
1.34 kristaps 624: char *v, *o;
1.36 kristaps 625: char *toks[3];
1.1 kristaps 626:
627: toks[0] = "all";
1.36 kristaps 628: toks[1] = "error";
629: toks[2] = NULL;
1.1 kristaps 630:
1.34 kristaps 631: while (*arg) {
632: o = arg;
1.1 kristaps 633: switch (getsubopt(&arg, toks, &v)) {
634: case (0):
635: *wflags |= WARN_WALL;
636: break;
637: case (1):
638: *wflags |= WARN_WERR;
639: break;
640: default:
1.34 kristaps 641: warnx("bad argument: -W%s", o);
1.1 kristaps 642: return(0);
643: }
1.34 kristaps 644: }
1.1 kristaps 645:
646: return(1);
647: }
648:
649:
1.2 kristaps 650: /* ARGSUSED */
1.1 kristaps 651: static int
652: merr(void *arg, int line, int col, const char *msg)
653: {
1.5 kristaps 654: struct curparse *curp;
655:
656: curp = (struct curparse *)arg;
1.36 kristaps 657:
1.40 kristaps 658: (void)fprintf(stderr, "%s:%d:%d: error: %s\n",
659: curp->file, line, col + 1, msg);
1.27 kristaps 660:
1.1 kristaps 661: return(0);
662: }
663:
664:
665: static int
1.37 kristaps 666: mwarn(void *arg, int line, int col, const char *msg)
1.1 kristaps 667: {
1.5 kristaps 668: struct curparse *curp;
1.1 kristaps 669:
1.5 kristaps 670: curp = (struct curparse *)arg;
1.1 kristaps 671:
1.36 kristaps 672: if ( ! (curp->wflags & WARN_WALL))
673: return(1);
674:
1.40 kristaps 675: (void)fprintf(stderr, "%s:%d:%d: warning: %s\n",
676: curp->file, line, col + 1, msg);
1.1 kristaps 677:
1.5 kristaps 678: if ( ! (curp->wflags & WARN_WERR))
1.1 kristaps 679: return(1);
1.27 kristaps 680:
1.1 kristaps 681: return(0);
682: }
683:
CVSweb