Annotation of mandoc/main.c, Revision 1.34
1.34 ! kristaps 1: /* $Id: main.c,v 1.33 2009/07/04 09:01:55 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.33 kristaps 235: pflags = MAN_IGN_MACRO | MAN_IGN_ESCAPE | 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.33 kristaps 241: if (curp->fflags & NO_IGN_ESCAPE)
242: pflags &= ~MAN_IGN_ESCAPE;
1.19 kristaps 243:
244: if (NULL == (man = man_alloc(curp, pflags, &mancb)))
245: warnx("memory exhausted");
246:
247: return(man);
248: }
249:
250:
251: static struct mdoc *
252: mdoc_init(struct curparse *curp)
253: {
254: int pflags;
255: struct mdoc *mdoc;
256: struct mdoc_cb mdoccb;
257:
258: mdoccb.mdoc_err = merr;
259: mdoccb.mdoc_warn = mdocwarn;
260:
1.30 kristaps 261: /* Defaults from mandoc.1. */
1.27 kristaps 262:
1.24 kristaps 263: pflags = MDOC_IGN_MACRO | MDOC_IGN_ESCAPE | MDOC_IGN_CHARS;
1.19 kristaps 264:
265: if (curp->fflags & IGN_SCOPE)
266: pflags |= MDOC_IGN_SCOPE;
1.24 kristaps 267: if (curp->fflags & NO_IGN_ESCAPE)
268: pflags &= ~MDOC_IGN_ESCAPE;
269: if (curp->fflags & NO_IGN_MACRO)
270: pflags &= ~MDOC_IGN_MACRO;
271: if (curp->fflags & NO_IGN_CHARS)
272: pflags &= ~MDOC_IGN_CHARS;
1.19 kristaps 273:
274: if (NULL == (mdoc = mdoc_alloc(curp, pflags, &mdoccb)))
1.24 kristaps 275: warnx("memory exhausted");
1.19 kristaps 276:
277: return(mdoc);
278: }
279:
280:
281: static int
282: ffile(struct buf *blk, struct buf *ln,
283: const char *file, struct curparse *curp)
1.1 kristaps 284: {
1.19 kristaps 285: int c;
1.1 kristaps 286:
1.19 kristaps 287: curp->file = file;
288: if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) {
289: warn("%s", curp->file);
1.1 kristaps 290: return(0);
291: }
292:
1.19 kristaps 293: c = fdesc(blk, ln, curp);
1.1 kristaps 294:
1.19 kristaps 295: if (-1 == close(curp->fd))
296: warn("%s", curp->file);
1.1 kristaps 297:
298: return(c);
299: }
300:
301:
302: static int
1.19 kristaps 303: fdesc(struct buf *blk, struct buf *ln, struct curparse *curp)
1.1 kristaps 304: {
305: size_t sz;
306: ssize_t ssz;
307: struct stat st;
1.29 kristaps 308: int j, i, pos, lnn, comment;
1.19 kristaps 309: struct man *man;
310: struct mdoc *mdoc;
1.10 kristaps 311:
1.19 kristaps 312: sz = BUFSIZ;
313: man = NULL;
314: mdoc = NULL;
1.1 kristaps 315:
316: /*
1.19 kristaps 317: * Two buffers: ln and buf. buf is the input buffer optimised
318: * here for each file's block size. ln is a line buffer. Both
1.1 kristaps 319: * growable, hence passed in by ptr-ptr.
320: */
321:
1.19 kristaps 322: if (-1 == fstat(curp->fd, &st))
1.32 kristaps 323: warn("%s", curp->file);
1.6 kristaps 324: else if ((size_t)st.st_blksize > sz)
325: sz = st.st_blksize;
1.1 kristaps 326:
1.5 kristaps 327: if (sz > blk->sz) {
328: blk->buf = realloc(blk->buf, sz);
1.19 kristaps 329: if (NULL == blk->buf) {
330: warn("realloc");
331: return(0);
332: }
1.5 kristaps 333: blk->sz = sz;
1.1 kristaps 334: }
335:
1.19 kristaps 336: /* Fill buf with file blocksize. */
1.1 kristaps 337:
1.29 kristaps 338: for (lnn = pos = comment = 0; ; ) {
1.19 kristaps 339: if (-1 == (ssz = read(curp->fd, blk->buf, sz))) {
340: warn("%s", curp->file);
1.1 kristaps 341: return(0);
342: } else if (0 == ssz)
343: break;
344:
1.19 kristaps 345: /* Parse the read block into partial or full lines. */
346:
1.1 kristaps 347: for (i = 0; i < (int)ssz; i++) {
1.5 kristaps 348: if (pos >= (int)ln->sz) {
349: ln->sz += 256; /* Step-size. */
350: ln->buf = realloc(ln->buf, ln->sz);
1.19 kristaps 351: if (NULL == ln->buf) {
352: warn("realloc");
353: return(0);
354: }
1.1 kristaps 355: }
356:
1.5 kristaps 357: if ('\n' != blk->buf[i]) {
1.29 kristaps 358: if (comment)
359: continue;
1.5 kristaps 360: ln->buf[pos++] = blk->buf[i];
1.29 kristaps 361:
362: /* Handle in-line `\"' comments. */
363:
364: if (1 == pos || '\"' != ln->buf[pos - 1])
365: continue;
366:
367: for (j = pos - 2; j >= 0; j--)
368: if ('\\' != ln->buf[j])
369: break;
370:
371: if ( ! ((pos - 2 - j) % 2))
372: continue;
373:
374: comment = 1;
375: pos -= 2;
1.1 kristaps 376: continue;
1.29 kristaps 377: }
1.1 kristaps 378:
1.29 kristaps 379: /* Handle escaped `\\n' newlines. */
1.1 kristaps 380:
1.29 kristaps 381: if (pos > 0 && 0 == comment &&
382: '\\' == ln->buf[pos - 1]) {
1.1 kristaps 383: for (j = pos - 1; j >= 0; j--)
1.5 kristaps 384: if ('\\' != ln->buf[j])
1.1 kristaps 385: break;
386: if ( ! ((pos - j) % 2)) {
387: pos--;
388: lnn++;
389: continue;
390: }
391: }
392:
1.5 kristaps 393: ln->buf[pos] = 0;
1.19 kristaps 394: lnn++;
1.29 kristaps 395:
396: /* If unset, assign parser in pset(). */
1.19 kristaps 397:
398: if ( ! (man || mdoc) && ! pset(ln->buf,
399: pos, curp, &man, &mdoc))
1.10 kristaps 400: return(0);
1.19 kristaps 401:
1.29 kristaps 402: pos = comment = 0;
1.19 kristaps 403:
1.30 kristaps 404: /* Pass down into parsers. */
405:
1.10 kristaps 406: if (man && ! man_parseln(man, lnn, ln->buf))
1.1 kristaps 407: return(0);
1.19 kristaps 408: if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf))
409: return(0);
1.1 kristaps 410: }
411: }
412:
1.29 kristaps 413: /* NOTE a parser may not have been assigned, yet. */
1.19 kristaps 414:
1.22 kristaps 415: if ( ! (man || mdoc)) {
416: warnx("%s: not a manual", curp->file);
417: return(0);
418: }
419:
420: if (mdoc && ! mdoc_endparse(mdoc))
421: return(0);
422: if (man && ! man_endparse(man))
423: return(0);
1.19 kristaps 424:
1.29 kristaps 425: /* If unset, allocate output dev now (if applicable). */
1.22 kristaps 426:
427: if ( ! (curp->outman && curp->outmdoc)) {
428: switch (curp->outtype) {
429: case (OUTT_TREE):
430: curp->outman = tree_man;
431: curp->outmdoc = tree_mdoc;
432: break;
433: case (OUTT_LINT):
434: break;
435: default:
436: curp->outdata = ascii_alloc();
437: curp->outman = terminal_man;
438: curp->outmdoc = terminal_mdoc;
439: curp->outfree = terminal_free;
440: break;
441: }
442: }
443:
444: /* Execute the out device, if it exists. */
445:
446: if (man && curp->outman)
447: if ( ! (*curp->outman)(curp->outdata, man))
448: return(0);
449: if (mdoc && curp->outmdoc)
450: if ( ! (*curp->outmdoc)(curp->outdata, mdoc))
451: return(0);
452:
453: return(1);
1.19 kristaps 454: }
455:
456:
457: static int
1.22 kristaps 458: pset(const char *buf, int pos, struct curparse *curp,
1.19 kristaps 459: struct man **man, struct mdoc **mdoc)
460: {
1.29 kristaps 461: int i;
1.19 kristaps 462:
463: /*
464: * Try to intuit which kind of manual parser should be used. If
465: * passed in by command-line (-man, -mdoc), then use that
466: * explicitly. If passed as -mandoc, then try to guess from the
1.30 kristaps 467: * line: either skip dot-lines, use -mdoc when finding `.Dt', or
1.19 kristaps 468: * default to -man, which is more lenient.
469: */
470:
1.29 kristaps 471: if (buf[0] == '.') {
472: for (i = 1; buf[i]; i++)
473: if (' ' != buf[i] && '\t' != buf[i])
474: break;
475: if (0 == buf[i])
476: return(1);
477: }
1.10 kristaps 478:
1.19 kristaps 479: switch (curp->inttype) {
480: case (INTT_MDOC):
481: if (NULL == curp->mdoc)
482: curp->mdoc = mdoc_init(curp);
483: if (NULL == (*mdoc = curp->mdoc))
484: return(0);
1.22 kristaps 485: curp->lastmdoc = *mdoc;
1.19 kristaps 486: return(1);
487: case (INTT_MAN):
488: if (NULL == curp->man)
489: curp->man = man_init(curp);
490: if (NULL == (*man = curp->man))
491: return(0);
1.22 kristaps 492: curp->lastman = *man;
1.19 kristaps 493: return(1);
494: default:
495: break;
496: }
497:
498: if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) {
499: if (NULL == curp->mdoc)
500: curp->mdoc = mdoc_init(curp);
501: if (NULL == (*mdoc = curp->mdoc))
502: return(0);
1.22 kristaps 503: curp->lastmdoc = *mdoc;
1.19 kristaps 504: return(1);
505: }
506:
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);
1.10 kristaps 513: }
514:
515:
516: static int
517: moptions(enum intt *tflags, char *arg)
518: {
519:
1.17 kristaps 520: if (0 == strcmp(arg, "doc"))
1.10 kristaps 521: *tflags = INTT_MDOC;
1.19 kristaps 522: else if (0 == strcmp(arg, "andoc"))
523: *tflags = INTT_AUTO;
1.17 kristaps 524: else if (0 == strcmp(arg, "an"))
1.10 kristaps 525: *tflags = INTT_MAN;
526: else {
527: warnx("bad argument: -m%s", arg);
528: return(0);
529: }
530:
531: return(1);
1.1 kristaps 532: }
533:
534:
535: static int
536: toptions(enum outt *tflags, char *arg)
537: {
538:
539: if (0 == strcmp(arg, "ascii"))
540: *tflags = OUTT_ASCII;
541: else if (0 == strcmp(arg, "lint"))
542: *tflags = OUTT_LINT;
543: else if (0 == strcmp(arg, "tree"))
544: *tflags = OUTT_TREE;
545: else {
546: warnx("bad argument: -T%s", arg);
547: return(0);
548: }
549:
550: return(1);
551: }
552:
553:
554: static int
555: foptions(int *fflags, char *arg)
556: {
1.34 ! kristaps 557: char *v, *o;
1.24 kristaps 558: char *toks[6];
1.1 kristaps 559:
560: toks[0] = "ign-scope";
1.24 kristaps 561: toks[1] = "no-ign-escape";
562: toks[2] = "no-ign-macro";
563: toks[3] = "no-ign-chars";
564: toks[4] = "strict";
565: toks[5] = NULL;
1.1 kristaps 566:
1.34 ! kristaps 567: while (*arg) {
! 568: o = arg;
1.1 kristaps 569: switch (getsubopt(&arg, toks, &v)) {
570: case (0):
1.15 kristaps 571: *fflags |= IGN_SCOPE;
1.1 kristaps 572: break;
573: case (1):
1.24 kristaps 574: *fflags |= NO_IGN_ESCAPE;
1.1 kristaps 575: break;
576: case (2):
1.24 kristaps 577: *fflags |= NO_IGN_MACRO;
1.1 kristaps 578: break;
1.20 kristaps 579: case (3):
1.24 kristaps 580: *fflags |= NO_IGN_CHARS;
581: break;
582: case (4):
583: *fflags |= NO_IGN_ESCAPE |
584: NO_IGN_MACRO | NO_IGN_CHARS;
1.20 kristaps 585: break;
1.1 kristaps 586: default:
1.34 ! kristaps 587: warnx("bad argument: -f%s", o);
1.1 kristaps 588: return(0);
589: }
1.34 ! kristaps 590: }
1.1 kristaps 591:
592: return(1);
593: }
594:
595:
596: static int
597: woptions(int *wflags, char *arg)
598: {
1.34 ! kristaps 599: char *v, *o;
1.1 kristaps 600: char *toks[5];
601:
602: toks[0] = "all";
603: toks[1] = "compat";
604: toks[2] = "syntax";
605: toks[3] = "error";
606: toks[4] = NULL;
607:
1.34 ! kristaps 608: while (*arg) {
! 609: o = arg;
1.1 kristaps 610: switch (getsubopt(&arg, toks, &v)) {
611: case (0):
612: *wflags |= WARN_WALL;
613: break;
614: case (1):
615: *wflags |= WARN_WCOMPAT;
616: break;
617: case (2):
618: *wflags |= WARN_WSYNTAX;
619: break;
620: case (3):
621: *wflags |= WARN_WERR;
622: break;
623: default:
1.34 ! kristaps 624: warnx("bad argument: -W%s", o);
1.1 kristaps 625: return(0);
626: }
1.34 ! kristaps 627: }
1.1 kristaps 628:
629: return(1);
630: }
631:
632:
1.2 kristaps 633: /* ARGSUSED */
1.1 kristaps 634: static int
635: merr(void *arg, int line, int col, const char *msg)
636: {
1.5 kristaps 637: struct curparse *curp;
638:
639: curp = (struct curparse *)arg;
640: warnx("%s:%d: error: %s (column %d)",
641: curp->file, line, msg, col);
1.27 kristaps 642:
1.1 kristaps 643: return(0);
644: }
645:
646:
647: static int
1.14 kristaps 648: mdocwarn(void *arg, int line, int col,
1.1 kristaps 649: enum mdoc_warn type, const char *msg)
650: {
1.5 kristaps 651: struct curparse *curp;
1.1 kristaps 652: char *wtype;
653:
1.5 kristaps 654: curp = (struct curparse *)arg;
1.1 kristaps 655: wtype = NULL;
656:
657: switch (type) {
658: case (WARN_COMPAT):
659: wtype = "compat";
1.5 kristaps 660: if (curp->wflags & WARN_WCOMPAT)
1.1 kristaps 661: break;
662: return(1);
663: case (WARN_SYNTAX):
664: wtype = "syntax";
1.5 kristaps 665: if (curp->wflags & WARN_WSYNTAX)
1.1 kristaps 666: break;
667: return(1);
668: }
669:
670: assert(wtype);
1.5 kristaps 671: warnx("%s:%d: %s warning: %s (column %d)",
672: curp->file, line, wtype, msg, col);
1.1 kristaps 673:
1.5 kristaps 674: if ( ! (curp->wflags & WARN_WERR))
1.1 kristaps 675: return(1);
1.27 kristaps 676:
1.30 kristaps 677: warnx("considering warnings as errors");
1.1 kristaps 678: return(0);
679: }
680:
681:
1.14 kristaps 682: static int
683: manwarn(void *arg, int line, int col, const char *msg)
684: {
685: struct curparse *curp;
686:
687: curp = (struct curparse *)arg;
688:
689: if ( ! (curp->wflags & WARN_WSYNTAX))
690: return(1);
691:
692: warnx("%s:%d: syntax warning: %s (column %d)",
693: curp->file, line, msg, col);
694:
695: if ( ! (curp->wflags & WARN_WERR))
696: return(1);
697:
1.30 kristaps 698: warnx("considering warnings as errors");
1.14 kristaps 699: return(0);
700: }
CVSweb