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