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