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