version 1.15, 2009/03/25 21:03:13 |
version 1.17, 2009/03/26 16:23:22 |
|
|
#include "mdoc.h" |
#include "mdoc.h" |
#include "man.h" |
#include "man.h" |
|
|
|
/* Account for FreeBSD and Linux in our declarations. */ |
|
|
#ifdef __linux__ |
#ifdef __linux__ |
extern int getsubopt(char **, char * const *, char **); |
extern int getsubopt(char **, char * const *, char **); |
# ifndef __dead |
# ifndef __dead |
Line 54 struct curparse { |
|
Line 56 struct curparse { |
|
#define WARN_WERR (1 << 2) /* Warnings->errors. */ |
#define WARN_WERR (1 << 2) /* Warnings->errors. */ |
}; |
}; |
|
|
#define IGN_SCOPE (1 << 0) /* Flag to ignore scope. */ |
#define IGN_SCOPE (1 << 0) /* Ignore scope errors. */ |
#define IGN_ESCAPE (1 << 1) /* Flag to ignore bad escapes. */ |
#define IGN_ESCAPE (1 << 1) /* Ignore bad escapes. */ |
#define IGN_MACRO (1 << 2) /* Flag to ignore unknown macros. */ |
#define IGN_MACRO (1 << 2) /* Ignore unknown macros. */ |
|
|
enum intt { |
enum intt { |
INTT_MDOC = 0, |
INTT_MDOC = 0, |
|
|
|
|
enum outt { |
enum outt { |
OUTT_ASCII = 0, |
OUTT_ASCII = 0, |
OUTT_LATIN1, |
|
OUTT_UTF8, |
|
OUTT_TREE, |
OUTT_TREE, |
OUTT_LINT |
OUTT_LINT |
}; |
}; |
Line 78 typedef void (*out_free)(void *); |
|
Line 78 typedef void (*out_free)(void *); |
|
extern char *__progname; |
extern char *__progname; |
|
|
extern void *ascii_alloc(void); |
extern void *ascii_alloc(void); |
extern void *latin1_alloc(void); |
|
extern void *utf8_alloc(void); |
|
extern int terminal_run(void *, const struct man *, |
extern int terminal_run(void *, const struct man *, |
const struct mdoc *); |
const struct mdoc *); |
extern int tree_run(void *, const struct man *, |
extern int tree_run(void *, const struct man *, |
Line 100 static int file(struct buf *, struct buf *, |
|
Line 98 static int file(struct buf *, struct buf *, |
|
static int fdesc(struct buf *, struct buf *, |
static int fdesc(struct buf *, struct buf *, |
const char *, int, |
const char *, int, |
struct man *, struct mdoc *); |
struct man *, struct mdoc *); |
|
|
__dead static void version(void); |
__dead static void version(void); |
__dead static void usage(void); |
__dead static void usage(void); |
|
|
Line 158 main(int argc, char *argv[]) |
|
Line 155 main(int argc, char *argv[]) |
|
argv += optind; |
argv += optind; |
|
|
/* |
/* |
* Allocate the appropriate front-end. Note that utf8, ascii |
* Allocate the appropriate front-end. Note that utf8, latin1 |
* and latin1 all resolve to the terminal front-end with |
* (both not yet implemented) and ascii all resolve to the |
* different encodings (see terminal.c). Not all frontends have |
* terminal front-end with different encodings (see terminal.c). |
* cleanup or alloc routines. |
* Not all frontends have cleanup or alloc routines. |
*/ |
*/ |
|
|
switch (outtype) { |
switch (outtype) { |
case (OUTT_LATIN1): |
|
outdata = latin1_alloc(); |
|
outrun = terminal_run; |
|
outfree = terminal_free; |
|
break; |
|
case (OUTT_UTF8): |
|
outdata = utf8_alloc(); |
|
outrun = terminal_run; |
|
outfree = terminal_free; |
|
break; |
|
case (OUTT_TREE): |
case (OUTT_TREE): |
outdata = NULL; |
outdata = NULL; |
outrun = tree_run; |
outrun = tree_run; |
Line 204 main(int argc, char *argv[]) |
|
Line 191 main(int argc, char *argv[]) |
|
mancb.man_err = merr; |
mancb.man_err = merr; |
mancb.man_warn = manwarn; |
mancb.man_warn = manwarn; |
|
|
|
/* Configure buffers. */ |
|
|
bzero(&ln, sizeof(struct buf)); |
bzero(&ln, sizeof(struct buf)); |
bzero(&blk, sizeof(struct buf)); |
bzero(&blk, sizeof(struct buf)); |
|
|
Line 211 main(int argc, char *argv[]) |
|
Line 200 main(int argc, char *argv[]) |
|
mdoc = NULL; |
mdoc = NULL; |
pflags = 0; |
pflags = 0; |
|
|
|
/* |
|
* Allocate the parser. There are two kinds of parser: libman |
|
* and libmdoc. We must separately copy over the flags that |
|
* we'll use internally. |
|
*/ |
|
|
switch (inttype) { |
switch (inttype) { |
case (INTT_MAN): |
case (INTT_MAN): |
if (fflags & IGN_MACRO) |
if (fflags & IGN_MACRO) |
pflags |= MAN_IGN_MACRO; |
pflags |= MAN_IGN_MACRO; |
|
|
man = man_alloc(&curp, pflags, &mancb); |
man = man_alloc(&curp, pflags, &mancb); |
break; |
break; |
default: |
default: |
Line 225 main(int argc, char *argv[]) |
|
Line 219 main(int argc, char *argv[]) |
|
pflags |= MDOC_IGN_ESCAPE; |
pflags |= MDOC_IGN_ESCAPE; |
if (fflags & IGN_MACRO) |
if (fflags & IGN_MACRO) |
pflags |= MDOC_IGN_MACRO; |
pflags |= MDOC_IGN_MACRO; |
|
|
mdoc = mdoc_alloc(&curp, pflags, &mdoccb); |
mdoc = mdoc_alloc(&curp, pflags, &mdoccb); |
break; |
break; |
} |
} |
|
|
/* |
/* |
* Loop around available files. |
* Main loop around available files. |
*/ |
*/ |
|
|
if (NULL == *argv) { |
if (NULL == *argv) { |
curp.file = "<stdin>"; |
curp.file = "<stdin>"; |
rc = 0; |
rc = 0; |
c = fdesc(&blk, &ln, "stdin", |
c = fdesc(&blk, &ln, "stdin", STDIN_FILENO, man, mdoc); |
STDIN_FILENO, man, mdoc); |
|
|
|
if (c && NULL == outrun) |
if (c && NULL == outrun) |
rc = 1; |
rc = 1; |
Line 256 main(int argc, char *argv[]) |
|
Line 248 main(int argc, char *argv[]) |
|
man_reset(man); |
man_reset(man); |
if (mdoc) |
if (mdoc) |
mdoc_reset(mdoc); |
mdoc_reset(mdoc); |
|
|
argv++; |
argv++; |
} |
} |
rc = NULL == *argv; |
rc = NULL == *argv; |
|
|
moptions(enum intt *tflags, char *arg) |
moptions(enum intt *tflags, char *arg) |
{ |
{ |
|
|
if (0 == strcmp(arg, "mdoc")) |
if (0 == strcmp(arg, "doc")) |
*tflags = INTT_MDOC; |
*tflags = INTT_MDOC; |
else if (0 == strcmp(arg, "man")) |
else if (0 == strcmp(arg, "an")) |
*tflags = INTT_MAN; |
*tflags = INTT_MAN; |
else { |
else { |
warnx("bad argument: -m%s", arg); |
warnx("bad argument: -m%s", arg); |
Line 429 toptions(enum outt *tflags, char *arg) |
|
Line 420 toptions(enum outt *tflags, char *arg) |
|
|
|
if (0 == strcmp(arg, "ascii")) |
if (0 == strcmp(arg, "ascii")) |
*tflags = OUTT_ASCII; |
*tflags = OUTT_ASCII; |
else if (0 == strcmp(arg, "latin1")) |
|
*tflags = OUTT_LATIN1; |
|
else if (0 == strcmp(arg, "utf8")) |
|
*tflags = OUTT_UTF8; |
|
else if (0 == strcmp(arg, "lint")) |
else if (0 == strcmp(arg, "lint")) |
*tflags = OUTT_LINT; |
*tflags = OUTT_LINT; |
else if (0 == strcmp(arg, "tree")) |
else if (0 == strcmp(arg, "tree")) |