-/* $Id: main.c,v 1.55 2009/11/02 08:08:23 kristaps Exp $ */
+/* $Id: main.c,v 1.60 2010/03/22 20:43:00 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <sys/stat.h>
#include <assert.h>
/* FIXME: Intel's compiler? LLVM? pcc? */
#if !defined(__GNUC__) || (__GNUC__ < 2)
-# define __attribute__(x)
+# if !defined(lint)
+# define __attribute__(x)
+# endif
#endif /* !defined(__GNUC__) || (__GNUC__ < 2) */
-#ifdef __linux__
-extern int getsubopt(char **, char * const *, char **);
-extern size_t strlcat(char *, const char *, size_t);
-#endif
-
typedef void (*out_mdoc)(void *, const struct mdoc *);
typedef void (*out_man)(void *, const struct man *);
typedef void (*out_free)(void *);
OUTT_ASCII = 0,
OUTT_TREE,
OUTT_HTML,
+ OUTT_XHTML,
OUTT_LINT
};
#define WARN_WALL (1 << 0) /* All-warnings mask. */
#define WARN_WERR (1 << 2) /* Warnings->errors. */
int fflags;
-#define IGN_SCOPE (1 << 0) /* Ignore scope errors. */
-#define NO_IGN_ESCAPE (1 << 1) /* Don't ignore bad escapes. */
-#define NO_IGN_MACRO (1 << 2) /* Don't ignore bad macros. */
-#define NO_IGN_CHARS (1 << 3) /* Don't ignore bad chars. */
-#define IGN_ERRORS (1 << 4) /* Ignore failed parse. */
+#define FL_IGN_SCOPE (1 << 0) /* Ignore scope errors. */
+#define FL_NIGN_ESCAPE (1 << 1) /* Don't ignore bad escapes. */
+#define FL_NIGN_MACRO (1 << 2) /* Don't ignore bad macros. */
+#define FL_NIGN_CHARS (1 << 3) /* Don't ignore bad chars. */
+#define FL_IGN_ERRORS (1 << 4) /* Ignore failed parse. */
enum intt inttype; /* Input parsers... */
struct man *man;
struct man *lastman;
char outopts[BUFSIZ];
};
+#define FL_STRICT FL_NIGN_ESCAPE | \
+ FL_NIGN_MACRO | \
+ FL_NIGN_CHARS
+
static int foptions(int *, char *);
-static int toptions(enum outt *, char *);
+static int toptions(struct curparse *, char *);
static int moptions(enum intt *, char *);
static int woptions(int *, char *);
static int merr(void *, int, int, const char *);
(void)strlcat(curp.outopts, ",", BUFSIZ);
break;
case ('T'):
- if ( ! toptions(&curp.outtype, optarg))
+ if ( ! toptions(&curp, optarg))
return(EXIT_FAILURE);
break;
case ('W'):
curp.fd = STDIN_FILENO;
c = fdesc(&blk, &ln, &curp);
- if ( ! (IGN_ERRORS & curp.fflags))
+ if ( ! (FL_IGN_ERRORS & curp.fflags))
rc = 1 == c ? 1 : 0;
else
rc = -1 == c ? 0 : 1;
while (rc && *argv) {
c = ffile(&blk, &ln, *argv, &curp);
- if ( ! (IGN_ERRORS & curp.fflags))
+ if ( ! (FL_IGN_ERRORS & curp.fflags))
rc = 1 == c ? 1 : 0;
else
rc = -1 == c ? 0 : 1;
pflags = MAN_IGN_MACRO | MAN_IGN_ESCAPE | MAN_IGN_CHARS;
- if (curp->fflags & NO_IGN_MACRO)
+ if (curp->fflags & FL_NIGN_MACRO)
pflags &= ~MAN_IGN_MACRO;
- if (curp->fflags & NO_IGN_CHARS)
+ if (curp->fflags & FL_NIGN_CHARS)
pflags &= ~MAN_IGN_CHARS;
- if (curp->fflags & NO_IGN_ESCAPE)
+ if (curp->fflags & FL_NIGN_ESCAPE)
pflags &= ~MAN_IGN_ESCAPE;
return(man_alloc(curp, pflags, &mancb));
pflags = MDOC_IGN_MACRO | MDOC_IGN_ESCAPE | MDOC_IGN_CHARS;
- if (curp->fflags & IGN_SCOPE)
+ if (curp->fflags & FL_IGN_SCOPE)
pflags |= MDOC_IGN_SCOPE;
- if (curp->fflags & NO_IGN_ESCAPE)
+ if (curp->fflags & FL_NIGN_ESCAPE)
pflags &= ~MDOC_IGN_ESCAPE;
- if (curp->fflags & NO_IGN_MACRO)
+ if (curp->fflags & FL_NIGN_MACRO)
pflags &= ~MDOC_IGN_MACRO;
- if (curp->fflags & NO_IGN_CHARS)
+ if (curp->fflags & FL_NIGN_CHARS)
pflags &= ~MDOC_IGN_CHARS;
return(mdoc_alloc(curp, pflags, &mdoccb));
if ( ! (curp->outman && curp->outmdoc)) {
switch (curp->outtype) {
+ case (OUTT_XHTML):
+ curp->outdata = xhtml_alloc(curp->outopts);
+ curp->outman = html_man;
+ curp->outmdoc = html_mdoc;
+ curp->outfree = html_free;
+ break;
case (OUTT_HTML):
curp->outdata = html_alloc(curp->outopts);
curp->outman = html_man;
else if (0 == strcmp(arg, "an"))
*tflags = INTT_MAN;
else {
- fprintf(stderr, "%s: Bad argument", arg);
+ fprintf(stderr, "%s: Bad argument\n", arg);
return(0);
}
static int
-toptions(enum outt *tflags, char *arg)
+toptions(struct curparse *curp, char *arg)
{
if (0 == strcmp(arg, "ascii"))
- *tflags = OUTT_ASCII;
- else if (0 == strcmp(arg, "lint"))
- *tflags = OUTT_LINT;
+ curp->outtype = OUTT_ASCII;
+ else if (0 == strcmp(arg, "lint")) {
+ curp->outtype = OUTT_LINT;
+ curp->wflags |= WARN_WALL;
+ curp->fflags |= FL_STRICT;
+ }
else if (0 == strcmp(arg, "tree"))
- *tflags = OUTT_TREE;
+ curp->outtype = OUTT_TREE;
else if (0 == strcmp(arg, "html"))
- *tflags = OUTT_HTML;
+ curp->outtype = OUTT_HTML;
+ else if (0 == strcmp(arg, "xhtml"))
+ curp->outtype = OUTT_XHTML;
else {
- fprintf(stderr, "%s: Bad argument", arg);
+ fprintf(stderr, "%s: Bad argument\n", arg);
return(0);
}
o = arg;
switch (getsubopt(&arg, UNCONST(toks), &v)) {
case (0):
- *fflags |= IGN_SCOPE;
+ *fflags |= FL_IGN_SCOPE;
break;
case (1):
- *fflags |= NO_IGN_ESCAPE;
+ *fflags |= FL_NIGN_ESCAPE;
break;
case (2):
- *fflags |= NO_IGN_MACRO;
+ *fflags |= FL_NIGN_MACRO;
break;
case (3):
- *fflags |= NO_IGN_CHARS;
+ *fflags |= FL_NIGN_CHARS;
break;
case (4):
- *fflags |= IGN_ERRORS;
+ *fflags |= FL_IGN_ERRORS;
break;
case (5):
- *fflags |= NO_IGN_ESCAPE |
- NO_IGN_MACRO | NO_IGN_CHARS;
+ *fflags |= FL_STRICT;
break;
case (6):
- *fflags &= ~NO_IGN_ESCAPE;
+ *fflags &= ~FL_NIGN_ESCAPE;
break;
default:
- fprintf(stderr, "%s: Bad argument", o);
+ fprintf(stderr, "%s: Bad argument\n", o);
return(0);
}
}
*wflags |= WARN_WERR;
break;
default:
- fprintf(stderr, "%s: Bad argument", o);
+ fprintf(stderr, "%s: Bad argument\n", o);
return(0);
}
}