version 1.79, 2010/05/17 22:11:42 |
version 1.90, 2010/06/26 15:22:19 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> |
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@bsd.lv> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
* purpose with or without fee is hereby granted, provided that the above |
* purpose with or without fee is hereby granted, provided that the above |
|
|
#include <unistd.h> |
#include <unistd.h> |
|
|
#include "mandoc.h" |
#include "mandoc.h" |
|
#include "regs.h" |
|
#include "main.h" |
#include "mdoc.h" |
#include "mdoc.h" |
#include "man.h" |
#include "man.h" |
#include "roff.h" |
#include "roff.h" |
#include "main.h" |
|
|
|
#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) |
#define UNCONST(a) ((void *)(uintptr_t)(const void *)(a)) |
|
|
|
|
OUTT_TREE, |
OUTT_TREE, |
OUTT_HTML, |
OUTT_HTML, |
OUTT_XHTML, |
OUTT_XHTML, |
OUTT_LINT |
OUTT_LINT, |
|
OUTT_PS |
}; |
}; |
|
|
struct curparse { |
struct curparse { |
Line 97 struct curparse { |
|
Line 99 struct curparse { |
|
static const char * const mandocerrs[MANDOCERR_MAX] = { |
static const char * const mandocerrs[MANDOCERR_MAX] = { |
"ok", |
"ok", |
"text should be uppercase", |
"text should be uppercase", |
"sections out of conentional order", |
"sections out of conventional order", |
"section name repeats", |
"section name repeats", |
"out of order prologue", |
"out of order prologue", |
"repeated prologue entry", |
"repeated prologue entry", |
"list type must come first", |
"list type must come first", |
"column syntax is inconsistent", |
|
"bad standard", |
"bad standard", |
"bad library", |
"bad library", |
"bad escape sequence", |
"bad escape sequence", |
"unterminated quoted string", |
"unterminated quoted string", |
"argument requires the width argument", |
"argument requires the width argument", |
"superfluous width argument", |
"superfluous width argument", |
|
"ignoring argument", |
"bad date argument", |
"bad date argument", |
"bad width argument", |
"bad width argument", |
"unknown manual sction", |
"unknown manual section", |
"section not in conventional manual section", |
"section not in conventional manual section", |
"end of line whitespace", |
"end of line whitespace", |
"scope open on exit", |
"scope open on exit", |
Line 142 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 144 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"macro requires body argument(s)", |
"macro requires body argument(s)", |
"macro requires argument(s)", |
"macro requires argument(s)", |
"no title in document", |
"no title in document", |
|
"missing list type", |
|
"missing display type", |
"line argument(s) will be lost", |
"line argument(s) will be lost", |
"body argument(s) will be lost", |
"body argument(s) will be lost", |
|
"column syntax is inconsistent", |
"missing font type", |
"missing font type", |
"missing display type", |
|
"missing list type", |
|
"displays may not be nested", |
"displays may not be nested", |
|
"unsupported display type", |
"no scope to rewind: syntax violated", |
"no scope to rewind: syntax violated", |
"scope broken, syntax violated", |
"scope broken, syntax violated", |
"line scope broken, syntax violated", |
"line scope broken, syntax violated", |
Line 395 read_whole_file(struct curparse *curp, struct buf *fb, |
|
Line 399 read_whole_file(struct curparse *curp, struct buf *fb, |
|
*with_mmap = 1; |
*with_mmap = 1; |
fb->sz = (size_t)st.st_size; |
fb->sz = (size_t)st.st_size; |
fb->buf = mmap(NULL, fb->sz, PROT_READ, |
fb->buf = mmap(NULL, fb->sz, PROT_READ, |
MAP_FILE, curp->fd, 0); |
MAP_FILE|MAP_SHARED, curp->fd, 0); |
if (fb->buf != MAP_FAILED) |
if (fb->buf != MAP_FAILED) |
return(1); |
return(1); |
} |
} |
Line 447 fdesc(struct curparse *curp) |
|
Line 451 fdesc(struct curparse *curp) |
|
struct man *man; |
struct man *man; |
struct mdoc *mdoc; |
struct mdoc *mdoc; |
struct roff *roff; |
struct roff *roff; |
|
struct regset regs; |
|
|
man = NULL; |
man = NULL; |
mdoc = NULL; |
mdoc = NULL; |
roff = NULL; |
roff = NULL; |
memset(&ln, 0, sizeof(struct buf)); |
memset(&ln, 0, sizeof(struct buf)); |
|
memset(®s, 0, sizeof(struct regset)); |
|
|
/* |
/* |
* Two buffers: ln and buf. buf is the input file and may be |
* Two buffers: ln and buf. buf is the input file and may be |
Line 534 fdesc(struct curparse *curp) |
|
Line 540 fdesc(struct curparse *curp) |
|
|
|
of = 0; |
of = 0; |
do { |
do { |
re = roff_parseln(roff, lnn_start, |
re = roff_parseln(roff, ®s, lnn_start, |
&ln.buf, &ln.sz, of, &of); |
&ln.buf, &ln.sz, of, &of); |
} while (ROFF_RERUN == re); |
} while (ROFF_RERUN == re); |
|
|
Line 584 fdesc(struct curparse *curp) |
|
Line 590 fdesc(struct curparse *curp) |
|
switch (curp->outtype) { |
switch (curp->outtype) { |
case (OUTT_XHTML): |
case (OUTT_XHTML): |
curp->outdata = xhtml_alloc(curp->outopts); |
curp->outdata = xhtml_alloc(curp->outopts); |
curp->outman = html_man; |
|
curp->outmdoc = html_mdoc; |
|
curp->outfree = html_free; |
|
break; |
break; |
case (OUTT_HTML): |
case (OUTT_HTML): |
curp->outdata = html_alloc(curp->outopts); |
curp->outdata = html_alloc(curp->outopts); |
|
break; |
|
case (OUTT_ASCII): |
|
curp->outdata = ascii_alloc(curp->outopts); |
|
curp->outfree = ascii_free; |
|
break; |
|
case (OUTT_PS): |
|
curp->outdata = ps_alloc(); |
|
curp->outfree = ps_free; |
|
break; |
|
default: |
|
break; |
|
} |
|
|
|
switch (curp->outtype) { |
|
case (OUTT_HTML): |
|
/* FALLTHROUGH */ |
|
case (OUTT_XHTML): |
curp->outman = html_man; |
curp->outman = html_man; |
curp->outmdoc = html_mdoc; |
curp->outmdoc = html_mdoc; |
curp->outfree = html_free; |
curp->outfree = html_free; |
Line 598 fdesc(struct curparse *curp) |
|
Line 618 fdesc(struct curparse *curp) |
|
curp->outman = tree_man; |
curp->outman = tree_man; |
curp->outmdoc = tree_mdoc; |
curp->outmdoc = tree_mdoc; |
break; |
break; |
case (OUTT_LINT): |
case (OUTT_ASCII): |
break; |
/* FALLTHROUGH */ |
default: |
case (OUTT_PS): |
curp->outdata = ascii_alloc(80); |
|
curp->outman = terminal_man; |
curp->outman = terminal_man; |
curp->outmdoc = terminal_mdoc; |
curp->outmdoc = terminal_mdoc; |
curp->outfree = terminal_free; |
|
break; |
break; |
|
default: |
|
break; |
} |
} |
} |
} |
|
|
Line 729 toptions(struct curparse *curp, char *arg) |
|
Line 749 toptions(struct curparse *curp, char *arg) |
|
curp->outtype = OUTT_HTML; |
curp->outtype = OUTT_HTML; |
else if (0 == strcmp(arg, "xhtml")) |
else if (0 == strcmp(arg, "xhtml")) |
curp->outtype = OUTT_XHTML; |
curp->outtype = OUTT_XHTML; |
|
else if (0 == strcmp(arg, "ps")) |
|
curp->outtype = OUTT_PS; |
else { |
else { |
fprintf(stderr, "%s: Bad argument\n", arg); |
fprintf(stderr, "%s: Bad argument\n", arg); |
return(0); |
return(0); |