Annotation of mandoc/main.c, Revision 1.42
1.42 ! kristaps 1: /* $Id: main.c,v 1.41 2009/07/28 10:15:12 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,
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.42 ! kristaps 89: extern void tree_mdoc(void *, const struct mdoc *);
! 90: extern void tree_man(void *, const struct man *);
! 91: extern void terminal_mdoc(void *, const struct mdoc *);
! 92: extern void 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)) {
1.41 kristaps 421: (void)fprintf(stderr, "%s: not a manual\n",
422: curp->file);
1.22 kristaps 423: return(0);
424: }
425:
426: if (mdoc && ! mdoc_endparse(mdoc))
427: return(0);
428: if (man && ! man_endparse(man))
429: return(0);
1.19 kristaps 430:
1.29 kristaps 431: /* If unset, allocate output dev now (if applicable). */
1.22 kristaps 432:
433: if ( ! (curp->outman && curp->outmdoc)) {
434: switch (curp->outtype) {
435: case (OUTT_TREE):
436: curp->outman = tree_man;
437: curp->outmdoc = tree_mdoc;
438: break;
439: case (OUTT_LINT):
440: break;
441: default:
442: curp->outdata = ascii_alloc();
443: curp->outman = terminal_man;
444: curp->outmdoc = terminal_mdoc;
445: curp->outfree = terminal_free;
446: break;
447: }
448: }
449:
450: /* Execute the out device, if it exists. */
451:
452: if (man && curp->outman)
1.42 ! kristaps 453: (*curp->outman)(curp->outdata, man);
1.22 kristaps 454: if (mdoc && curp->outmdoc)
1.42 ! kristaps 455: (*curp->outmdoc)(curp->outdata, mdoc);
1.22 kristaps 456:
457: return(1);
1.19 kristaps 458: }
459:
460:
461: static int
1.22 kristaps 462: pset(const char *buf, int pos, struct curparse *curp,
1.19 kristaps 463: struct man **man, struct mdoc **mdoc)
464: {
1.29 kristaps 465: int i;
1.19 kristaps 466:
467: /*
468: * Try to intuit which kind of manual parser should be used. If
469: * passed in by command-line (-man, -mdoc), then use that
470: * explicitly. If passed as -mandoc, then try to guess from the
1.30 kristaps 471: * line: either skip dot-lines, use -mdoc when finding `.Dt', or
1.19 kristaps 472: * default to -man, which is more lenient.
473: */
474:
1.29 kristaps 475: if (buf[0] == '.') {
476: for (i = 1; buf[i]; i++)
477: if (' ' != buf[i] && '\t' != buf[i])
478: break;
479: if (0 == buf[i])
480: return(1);
481: }
1.10 kristaps 482:
1.19 kristaps 483: switch (curp->inttype) {
484: case (INTT_MDOC):
485: if (NULL == curp->mdoc)
486: curp->mdoc = mdoc_init(curp);
487: if (NULL == (*mdoc = curp->mdoc))
488: return(0);
1.22 kristaps 489: curp->lastmdoc = *mdoc;
1.19 kristaps 490: return(1);
491: case (INTT_MAN):
492: if (NULL == curp->man)
493: curp->man = man_init(curp);
494: if (NULL == (*man = curp->man))
495: return(0);
1.22 kristaps 496: curp->lastman = *man;
1.19 kristaps 497: return(1);
498: default:
499: break;
500: }
501:
502: if (pos >= 3 && 0 == memcmp(buf, ".Dd", 3)) {
503: if (NULL == curp->mdoc)
504: curp->mdoc = mdoc_init(curp);
505: if (NULL == (*mdoc = curp->mdoc))
506: return(0);
1.22 kristaps 507: curp->lastmdoc = *mdoc;
1.19 kristaps 508: return(1);
509: }
510:
511: if (NULL == curp->man)
512: curp->man = man_init(curp);
513: if (NULL == (*man = curp->man))
514: return(0);
1.22 kristaps 515: curp->lastman = *man;
1.19 kristaps 516: return(1);
1.10 kristaps 517: }
518:
519:
520: static int
521: moptions(enum intt *tflags, char *arg)
522: {
523:
1.17 kristaps 524: if (0 == strcmp(arg, "doc"))
1.10 kristaps 525: *tflags = INTT_MDOC;
1.19 kristaps 526: else if (0 == strcmp(arg, "andoc"))
527: *tflags = INTT_AUTO;
1.17 kristaps 528: else if (0 == strcmp(arg, "an"))
1.10 kristaps 529: *tflags = INTT_MAN;
530: else {
531: warnx("bad argument: -m%s", arg);
532: return(0);
533: }
534:
535: return(1);
1.1 kristaps 536: }
537:
538:
539: static int
540: toptions(enum outt *tflags, char *arg)
541: {
542:
543: if (0 == strcmp(arg, "ascii"))
544: *tflags = OUTT_ASCII;
545: else if (0 == strcmp(arg, "lint"))
546: *tflags = OUTT_LINT;
547: else if (0 == strcmp(arg, "tree"))
548: *tflags = OUTT_TREE;
549: else {
550: warnx("bad argument: -T%s", arg);
551: return(0);
552: }
553:
554: return(1);
555: }
556:
557:
558: static int
559: foptions(int *fflags, char *arg)
560: {
1.34 kristaps 561: char *v, *o;
1.39 kristaps 562: char *toks[7];
1.1 kristaps 563:
564: toks[0] = "ign-scope";
1.24 kristaps 565: toks[1] = "no-ign-escape";
566: toks[2] = "no-ign-macro";
567: toks[3] = "no-ign-chars";
1.39 kristaps 568: toks[4] = "ign-errors";
569: toks[5] = "strict";
570: toks[6] = NULL;
1.1 kristaps 571:
1.34 kristaps 572: while (*arg) {
573: o = arg;
1.1 kristaps 574: switch (getsubopt(&arg, toks, &v)) {
575: case (0):
1.15 kristaps 576: *fflags |= IGN_SCOPE;
1.1 kristaps 577: break;
578: case (1):
1.24 kristaps 579: *fflags |= NO_IGN_ESCAPE;
1.1 kristaps 580: break;
581: case (2):
1.24 kristaps 582: *fflags |= NO_IGN_MACRO;
1.1 kristaps 583: break;
1.20 kristaps 584: case (3):
1.24 kristaps 585: *fflags |= NO_IGN_CHARS;
586: break;
587: case (4):
1.39 kristaps 588: *fflags |= IGN_ERRORS;
589: break;
590: case (5):
1.24 kristaps 591: *fflags |= NO_IGN_ESCAPE |
592: NO_IGN_MACRO | NO_IGN_CHARS;
1.20 kristaps 593: break;
1.1 kristaps 594: default:
1.34 kristaps 595: warnx("bad argument: -f%s", o);
1.1 kristaps 596: return(0);
597: }
1.34 kristaps 598: }
1.1 kristaps 599:
600: return(1);
601: }
602:
603:
604: static int
605: woptions(int *wflags, char *arg)
606: {
1.34 kristaps 607: char *v, *o;
1.36 kristaps 608: char *toks[3];
1.1 kristaps 609:
610: toks[0] = "all";
1.36 kristaps 611: toks[1] = "error";
612: toks[2] = NULL;
1.1 kristaps 613:
1.34 kristaps 614: while (*arg) {
615: o = arg;
1.1 kristaps 616: switch (getsubopt(&arg, toks, &v)) {
617: case (0):
618: *wflags |= WARN_WALL;
619: break;
620: case (1):
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;
1.36 kristaps 640:
1.40 kristaps 641: (void)fprintf(stderr, "%s:%d:%d: error: %s\n",
642: curp->file, line, col + 1, msg);
1.27 kristaps 643:
1.1 kristaps 644: return(0);
645: }
646:
647:
648: static int
1.37 kristaps 649: mwarn(void *arg, int line, int col, const char *msg)
1.1 kristaps 650: {
1.5 kristaps 651: struct curparse *curp;
1.1 kristaps 652:
1.5 kristaps 653: curp = (struct curparse *)arg;
1.1 kristaps 654:
1.36 kristaps 655: if ( ! (curp->wflags & WARN_WALL))
656: return(1);
657:
1.40 kristaps 658: (void)fprintf(stderr, "%s:%d:%d: warning: %s\n",
659: curp->file, line, col + 1, msg);
1.1 kristaps 660:
1.5 kristaps 661: if ( ! (curp->wflags & WARN_WERR))
1.1 kristaps 662: return(1);
1.27 kristaps 663:
1.1 kristaps 664: return(0);
665: }
666:
CVSweb