version 1.63, 2010/05/14 13:54:15 |
version 1.65, 2010/05/15 04:46:10 |
Line 78 struct curparse { |
|
Line 78 struct curparse { |
|
#define FL_IGN_ERRORS (1 << 4) /* Ignore failed parse. */ |
#define FL_IGN_ERRORS (1 << 4) /* Ignore failed parse. */ |
enum intt inttype; /* Input parsers... */ |
enum intt inttype; /* Input parsers... */ |
struct man *man; |
struct man *man; |
struct man *lastman; |
|
struct mdoc *mdoc; |
struct mdoc *mdoc; |
struct mdoc *lastmdoc; |
|
enum outt outtype; /* Output devices... */ |
enum outt outtype; /* Output devices... */ |
out_mdoc outmdoc; |
out_mdoc outmdoc; |
out_man outman; |
out_man outman; |
Line 98 static int moptions(enum intt *, char *); |
|
Line 96 static int moptions(enum intt *, char *); |
|
static int woptions(int *, char *); |
static int woptions(int *, char *); |
static int merr(void *, int, int, const char *); |
static int merr(void *, int, int, const char *); |
static int mwarn(void *, int, int, const char *); |
static int mwarn(void *, int, int, const char *); |
static int ffile(struct buf *, struct buf *, |
static void ffile(struct buf *, struct buf *, |
const char *, struct curparse *); |
const char *, struct curparse *); |
static int fdesc(struct buf *, struct buf *, |
static void fdesc(struct buf *, struct buf *, |
struct curparse *); |
struct curparse *); |
static int pset(const char *, int, struct curparse *, |
static int pset(const char *, int, struct curparse *, |
struct man **, struct mdoc **); |
struct man **, struct mdoc **); |
Line 110 static void version(void) __attribute__((noreturn)) |
|
Line 108 static void version(void) __attribute__((noreturn)) |
|
static void usage(void) __attribute__((noreturn)); |
static void usage(void) __attribute__((noreturn)); |
|
|
static const char *progname; |
static const char *progname; |
|
static int with_error, with_warning; |
|
|
|
|
int |
int |
main(int argc, char *argv[]) |
main(int argc, char *argv[]) |
{ |
{ |
int c, rc; |
int c; |
struct buf ln, blk; |
struct buf ln, blk; |
struct curparse curp; |
struct curparse curp; |
|
|
Line 167 main(int argc, char *argv[]) |
|
Line 165 main(int argc, char *argv[]) |
|
memset(&ln, 0, sizeof(struct buf)); |
memset(&ln, 0, sizeof(struct buf)); |
memset(&blk, 0, sizeof(struct buf)); |
memset(&blk, 0, sizeof(struct buf)); |
|
|
rc = 1; |
|
|
|
if (NULL == *argv) { |
if (NULL == *argv) { |
curp.file = "<stdin>"; |
curp.file = "<stdin>"; |
curp.fd = STDIN_FILENO; |
curp.fd = STDIN_FILENO; |
|
|
c = fdesc(&blk, &ln, &curp); |
fdesc(&blk, &ln, &curp); |
if ( ! (FL_IGN_ERRORS & curp.fflags)) |
|
rc = 1 == c ? 1 : 0; |
|
else |
|
rc = -1 == c ? 0 : 1; |
|
} |
} |
|
|
while (rc && *argv) { |
while (*argv) { |
c = ffile(&blk, &ln, *argv, &curp); |
ffile(&blk, &ln, *argv, &curp); |
if ( ! (FL_IGN_ERRORS & curp.fflags)) |
|
rc = 1 == c ? 1 : 0; |
|
else |
|
rc = -1 == c ? 0 : 1; |
|
|
|
argv++; |
if (with_error && !(curp.fflags & FL_IGN_ERRORS)) |
if (*argv && rc) { |
break; |
if (curp.lastman) |
++argv; |
man_reset(curp.lastman); |
|
if (curp.lastmdoc) |
|
mdoc_reset(curp.lastmdoc); |
|
curp.lastman = NULL; |
|
curp.lastmdoc = NULL; |
|
} |
|
} |
} |
|
|
if (blk.buf) |
if (blk.buf) |
Line 204 main(int argc, char *argv[]) |
|
Line 186 main(int argc, char *argv[]) |
|
free(ln.buf); |
free(ln.buf); |
if (curp.outfree) |
if (curp.outfree) |
(*curp.outfree)(curp.outdata); |
(*curp.outfree)(curp.outdata); |
if (curp.mdoc) |
|
mdoc_free(curp.mdoc); |
|
if (curp.man) |
|
man_free(curp.man); |
|
|
|
return(rc ? EXIT_SUCCESS : EXIT_FAILURE); |
return((with_warning || with_error) ? EXIT_FAILURE : EXIT_SUCCESS ); |
} |
} |
|
|
|
|
Line 279 mdoc_init(struct curparse *curp) |
|
Line 257 mdoc_init(struct curparse *curp) |
|
} |
} |
|
|
|
|
static int |
static void |
ffile(struct buf *blk, struct buf *ln, |
ffile(struct buf *blk, struct buf *ln, |
const char *file, struct curparse *curp) |
const char *file, struct curparse *curp) |
{ |
{ |
int c; |
|
|
|
curp->file = file; |
curp->file = file; |
if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) { |
if (-1 == (curp->fd = open(curp->file, O_RDONLY, 0))) { |
perror(curp->file); |
perror(curp->file); |
return(-1); |
with_error = 1; |
|
return; |
} |
} |
|
|
c = fdesc(blk, ln, curp); |
fdesc(blk, ln, curp); |
|
|
if (-1 == close(curp->fd)) |
if (-1 == close(curp->fd)) |
perror(curp->file); |
perror(curp->file); |
|
|
return(c); |
|
} |
} |
|
|
|
|
static int |
static void |
fdesc(struct buf *blk, struct buf *ln, struct curparse *curp) |
fdesc(struct buf *blk, struct buf *ln, struct curparse *curp) |
{ |
{ |
size_t sz; |
size_t sz; |
Line 320 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
Line 296 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
* growable, hence passed in by ptr-ptr. |
* growable, hence passed in by ptr-ptr. |
*/ |
*/ |
|
|
if (-1 == fstat(curp->fd, &st)) |
if (-1 == fstat(curp->fd, &st)) { |
perror(curp->file); |
perror(curp->file); |
else if ((size_t)st.st_blksize > sz) |
with_error = 1; |
|
return; |
|
} |
|
if ((size_t)st.st_blksize > sz) |
sz = st.st_blksize; |
sz = st.st_blksize; |
|
|
if (sz > blk->sz) { |
if (sz > blk->sz) { |
blk->buf = realloc(blk->buf, sz); |
void *buf = realloc(blk->buf, sz); |
if (NULL == blk->buf) { |
|
|
if (NULL == buf) { |
perror(NULL); |
perror(NULL); |
exit(EXIT_FAILURE); |
with_error = 1; |
|
return; |
} |
} |
|
blk->buf = buf; |
blk->sz = sz; |
blk->sz = sz; |
} |
} |
|
|
Line 339 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
Line 321 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
for (lnn = pos = comment = 0; ; ) { |
for (lnn = pos = comment = 0; ; ) { |
if (-1 == (ssz = read(curp->fd, blk->buf, sz))) { |
if (-1 == (ssz = read(curp->fd, blk->buf, sz))) { |
perror(curp->file); |
perror(curp->file); |
return(-1); |
goto bailout; |
} else if (0 == ssz) |
} else if (0 == ssz) |
break; |
break; |
|
|
Line 351 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
Line 333 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
ln->buf = realloc(ln->buf, ln->sz); |
ln->buf = realloc(ln->buf, ln->sz); |
if (NULL == ln->buf) { |
if (NULL == ln->buf) { |
perror(NULL); |
perror(NULL); |
return(EXIT_FAILURE); |
goto bailout; |
} |
} |
} |
} |
|
|
Line 404 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
Line 386 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
|
|
if ( ! (man || mdoc) && ! pset(ln->buf, |
if ( ! (man || mdoc) && ! pset(ln->buf, |
pos, curp, &man, &mdoc)) |
pos, curp, &man, &mdoc)) |
return(-1); |
goto bailout; |
|
|
pos = comment = 0; |
pos = comment = 0; |
|
|
/* Pass down into parsers. */ |
/* Pass down into parsers. */ |
|
|
if (man && ! man_parseln(man, lnn, ln->buf)) |
if (man && ! man_parseln(man, lnn, ln->buf)) |
return(0); |
goto bailout; |
if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf)) |
if (mdoc && ! mdoc_parseln(mdoc, lnn, ln->buf)) |
return(0); |
goto bailout; |
} |
} |
} |
} |
|
|
Line 421 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
Line 403 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
|
|
if ( ! (man || mdoc)) { |
if ( ! (man || mdoc)) { |
fprintf(stderr, "%s: Not a manual\n", curp->file); |
fprintf(stderr, "%s: Not a manual\n", curp->file); |
return(0); |
goto bailout; |
} |
} |
|
|
if (mdoc && ! mdoc_endparse(mdoc)) |
if (mdoc && ! mdoc_endparse(mdoc)) |
return(0); |
goto bailout; |
if (man && ! man_endparse(man)) |
if (man && ! man_endparse(man)) |
return(0); |
goto bailout; |
|
|
/* If unset, allocate output dev now (if applicable). */ |
/* If unset, allocate output dev now (if applicable). */ |
|
|
Line 467 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
Line 449 fdesc(struct buf *blk, struct buf *ln, struct curparse |
|
if (mdoc && curp->outmdoc) |
if (mdoc && curp->outmdoc) |
(*curp->outmdoc)(curp->outdata, mdoc); |
(*curp->outmdoc)(curp->outdata, mdoc); |
|
|
return(1); |
cleanup: |
|
if (curp->mdoc) { |
|
mdoc_free(curp->mdoc); |
|
curp->mdoc = NULL; |
|
} |
|
if (curp->man) { |
|
man_free(curp->man); |
|
curp->man = NULL; |
|
} |
|
return; |
|
|
|
bailout: |
|
with_error = 1; |
|
goto cleanup; |
} |
} |
|
|
|
|
Line 499 pset(const char *buf, int pos, struct curparse *curp, |
|
Line 494 pset(const char *buf, int pos, struct curparse *curp, |
|
curp->mdoc = mdoc_init(curp); |
curp->mdoc = mdoc_init(curp); |
if (NULL == (*mdoc = curp->mdoc)) |
if (NULL == (*mdoc = curp->mdoc)) |
return(0); |
return(0); |
curp->lastmdoc = *mdoc; |
|
return(1); |
return(1); |
case (INTT_MAN): |
case (INTT_MAN): |
if (NULL == curp->man) |
if (NULL == curp->man) |
curp->man = man_init(curp); |
curp->man = man_init(curp); |
if (NULL == (*man = curp->man)) |
if (NULL == (*man = curp->man)) |
return(0); |
return(0); |
curp->lastman = *man; |
|
return(1); |
return(1); |
default: |
default: |
break; |
break; |
Line 517 pset(const char *buf, int pos, struct curparse *curp, |
|
Line 510 pset(const char *buf, int pos, struct curparse *curp, |
|
curp->mdoc = mdoc_init(curp); |
curp->mdoc = mdoc_init(curp); |
if (NULL == (*mdoc = curp->mdoc)) |
if (NULL == (*mdoc = curp->mdoc)) |
return(0); |
return(0); |
curp->lastmdoc = *mdoc; |
|
return(1); |
return(1); |
} |
} |
|
|
Line 525 pset(const char *buf, int pos, struct curparse *curp, |
|
Line 517 pset(const char *buf, int pos, struct curparse *curp, |
|
curp->man = man_init(curp); |
curp->man = man_init(curp); |
if (NULL == (*man = curp->man)) |
if (NULL == (*man = curp->man)) |
return(0); |
return(0); |
curp->lastman = *man; |
|
return(1); |
return(1); |
} |
} |
|
|
Line 660 merr(void *arg, int line, int col, const char *msg) |
|
Line 651 merr(void *arg, int line, int col, const char *msg) |
|
(void)fprintf(stderr, "%s:%d:%d: error: %s\n", |
(void)fprintf(stderr, "%s:%d:%d: error: %s\n", |
curp->file, line, col + 1, msg); |
curp->file, line, col + 1, msg); |
|
|
|
with_error = 1; |
|
|
return(0); |
return(0); |
} |
} |
|
|
Line 677 mwarn(void *arg, int line, int col, const char *msg) |
|
Line 670 mwarn(void *arg, int line, int col, const char *msg) |
|
(void)fprintf(stderr, "%s:%d:%d: warning: %s\n", |
(void)fprintf(stderr, "%s:%d:%d: warning: %s\n", |
curp->file, line, col + 1, msg); |
curp->file, line, col + 1, msg); |
|
|
if ( ! (curp->wflags & WARN_WERR)) |
with_warning = 1; |
return(1); |
if (curp->wflags & WARN_WERR) { |
|
with_error = 1; |
return(0); |
return(0); |
|
} |
|
|
|
return(1); |
} |
} |
|
|