summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKristaps Dzonsons <kristaps@bsd.lv>2008-12-10 13:15:55 +0000
committerKristaps Dzonsons <kristaps@bsd.lv>2008-12-10 13:15:55 +0000
commit4787a4142e096d18cc8d1664421833e0e38bcb83 (patch)
tree92b494fc7c4de80b3c39fb763f81ad7069b7fcf3
parent632958c28b350640c09d493567691b855c78626b (diff)
downloadmandoc-4787a4142e096d18cc8d1664421833e0e38bcb83.tar.gz
Put prelude checking into asec.
-rw-r--r--Makefile19
-rw-r--r--index.72
-rw-r--r--private.h35
-rw-r--r--roff.c107
4 files changed, 80 insertions, 83 deletions
diff --git a/Makefile b/Makefile
index a690a8c2..4494c3c5 100644
--- a/Makefile
+++ b/Makefile
@@ -48,7 +48,7 @@ all: mdocml
lint: llib-lmdocml.ln
-dist: mdocml.tgz
+dist: mdocml.tgz mdocml-port.tgz
www: all $(HTML) $(XML) $(TEXT)
@@ -83,12 +83,27 @@ mdocml.html: mdocml.1 mdocml.css
install-www: www dist
install -m 0644 mdocml.tgz $(PREFIX)/mdocml-$(VERSION).tgz
install -m 0644 mdocml.tgz $(PREFIX)/mdocml.tgz
+ install -m 0644 mdocml-port.tgz $(PREFIX)/mdocml-port-$(VERSION).tgz
+ install -m 0644 mdocml-port.tgz $(PREFIX)/mdocml-port.tgz
install -m 0644 $(HTML) $(XML) $(TEXT) $(PREFIX)/
mdocml.tgz: $(INSTALL)
mkdir -p .dist/mdocml/mdocml-$(VERSION)/
install -m 0644 $(INSTALL) .dist/mdocml/mdocml-$(VERSION)/
- ( cd .dist/mdocml/ && tar zcf ../../mdocml.tgz mdocml-$(VERSION)/ )
+ ( cd .dist/mdocml/ && tar zcf ../../$@ mdocml-$(VERSION)/ )
+ rm -rf .dist/
+
+mdocml-port.tgz: $(INSTALL)
+ mkdir -p .dist/mdocml/pkg
+ sed -e "s!@VERSION@!$(VERSION)!" Makefile.port > .dist/mdocml/Makefile
+ md5 mdocml-$(VERSION).tgz > .dist/mdocml/distinfo
+ rmd160 mdocml-$(VERSION).tgz >> .dist/mdocml/distinfo
+ sha1 mdocml-$(VERSION).tgz >> .dist/mdocml/distinfo
+ install -m 0644 DESCR .dist/mdocml/pkg/DESCR
+ echo @comment $$OpenBSD$$ > .dist/mdocml/pkg/PLIST
+ echo bin/mdocml >> .dist/mdocml/pkg/PLIST
+ echo @man man/man1/mdocml.1 >> .dist/mdocml/pkg/PLIST
+ ( cd .dist/ && tar zcf ../$@ mdocml/ )
rm -rf .dist/
llib-lmdocml.ln: mdocml.ln libmdocml.ln html.ln xml.ln roff.ln ml.ln mlg.ln compat.ln tokens.ln literals.ln tags.ln
diff --git a/index.7 b/index.7
index 48bca38a..62c38261 100644
--- a/index.7
+++ b/index.7
@@ -136,6 +136,8 @@ text and produces HTML output.
and
.Ox
project CGI for producing HTML from nroff source.
+.It Xr roffit Ns : http://daniel.haxx.se/projects/roffit/
+HTML from roff manual source. Dead project?
.El
.\"
.Sh AUTHORS
diff --git a/private.h b/private.h
index 0b09b54f..130a7462 100644
--- a/private.h
+++ b/private.h
@@ -324,22 +324,25 @@ enum roffvol {
#define ROFFSec_NMASK (0x07)
-#define ROFFSec_NAME (1 << 0)
-#define ROFFSec_SYNOP (1 << 1)
-#define ROFFSec_DESC (1 << 2)
-#define ROFFSec_RETVAL (1 << 3)
-#define ROFFSec_ENV (1 << 4)
-#define ROFFSec_FILES (1 << 5)
-#define ROFFSec_EX (1 << 6)
-#define ROFFSec_DIAG (1 << 7)
-#define ROFFSec_ERRS (1 << 8)
-#define ROFFSec_SEEALSO (1 << 9)
-#define ROFFSec_STAND (1 << 10)
-#define ROFFSec_HIST (1 << 11)
-#define ROFFSec_AUTH (1 << 12)
-#define ROFFSec_CAVEATS (1 << 13)
-#define ROFFSec_BUGS (1 << 14)
-#define ROFFSec_OTHER (1 << 15)
+#define ROFFSec_PR_Os (1 << 1)
+#define ROFFSec_PR_Dt (1 << 2)
+#define ROFFSec_PR_Dd (1 << 3)
+#define ROFFSec_NAME (1 << 4)
+#define ROFFSec_SYNOP (1 << 5)
+#define ROFFSec_DESC (1 << 6)
+#define ROFFSec_RETVAL (1 << 7)
+#define ROFFSec_ENV (1 << 8)
+#define ROFFSec_FILES (1 << 9)
+#define ROFFSec_EX (1 << 10)
+#define ROFFSec_DIAG (1 << 11)
+#define ROFFSec_ERRS (1 << 12)
+#define ROFFSec_SEEALSO (1 << 13)
+#define ROFFSec_STAND (1 << 14)
+#define ROFFSec_HIST (1 << 15)
+#define ROFFSec_AUTH (1 << 16)
+#define ROFFSec_CAVEATS (1 << 17)
+#define ROFFSec_BUGS (1 << 18)
+#define ROFFSec_OTHER (1 << 19)
struct roffcb {
int (*roffmsg)(void *, enum roffmsg,
diff --git a/roff.c b/roff.c
index 2ed886e9..8420b597 100644
--- a/roff.c
+++ b/roff.c
@@ -71,12 +71,6 @@ struct rofftree {
char title[64]; /* `Dt' results. */
enum roffmsec section;
enum roffvol volume;
- int state;
-#define ROFF_PRELUDE (1 << 1) /* In roff prelude. */ /* FIXME: put into asec. */
-#define ROFF_PRELUDE_Os (1 << 2) /* `Os' is parsed. */
-#define ROFF_PRELUDE_Dt (1 << 3) /* `Dt' is parsed. */
-#define ROFF_PRELUDE_Dd (1 << 4) /* `Dd' is parsed. */
-#define ROFF_BODY (1 << 5) /* In roff body. */
struct roffcb cb; /* Callbacks. */
void *arg; /* Callbacks' arg. */
int csec; /* Current section. */
@@ -100,7 +94,7 @@ static int rofffindarg(const char *);
static int rofffindcallable(const char *);
static int roffispunct(const char *);
static int roffchecksec(struct rofftree *,
- const char *, int);
+ const char *, int, int);
static int roffargs(const struct rofftree *,
int, char *, char **);
static int roffargok(int, int);
@@ -140,10 +134,7 @@ roff_free(struct rofftree *tree, int flush)
error = 1;
- if (ROFF_PRELUDE & tree->state) {
- (void)roff_err(tree, NULL, "prelude never finished");
- goto end;
- } else if ( ! (ROFFSec_NAME & tree->asec)) {
+ if ( ! (ROFFSec_NAME & tree->asec)) {
(void)roff_err(tree, NULL, "missing `NAME' section");
goto end;
} else if ( ! (ROFFSec_NMASK & tree->asec))
@@ -193,7 +184,6 @@ roff_alloc(const struct roffcb *cb, void *args)
if (NULL == (tree = calloc(1, sizeof(struct rofftree))))
err(1, "calloc");
- tree->state = ROFF_PRELUDE;
tree->arg = args;
tree->section = ROFF_MSEC_MAX;
@@ -226,8 +216,8 @@ textparse(struct rofftree *tree, char *buf)
/* TODO: literal parsing. */
- if ( ! (ROFF_BODY & tree->state))
- return(roff_err(tree, buf, "data not in body"));
+ if ( ! (ROFFSec_NAME & tree->asec))
+ return(roff_err(tree, buf, "data before `NAME' section"));
/* LINTED */
while (*buf) {
@@ -354,13 +344,11 @@ roffparse(struct rofftree *tree, char *buf)
* Prelude macros break some assumptions, so branch now.
*/
- if (ROFF_PRELUDE & tree->state) {
+ if ( ! (ROFFSec_PR_Dd & tree->asec)) {
assert(NULL == tree->last);
return(roffcall(tree, tok, argvp));
}
- assert(ROFF_BODY & tree->state);
-
/*
* First check that our possible parents and parent's possible
* children are satisfied.
@@ -527,10 +515,25 @@ rofffindtok(const char *buf)
static int
-roffchecksec(struct rofftree *tree, const char *start, int sec)
+roffchecksec(struct rofftree *tree,
+ const char *start, int sec, int fail)
{
switch (sec) {
+ case(ROFFSec_PR_Dd):
+ return(1);
+ case(ROFFSec_PR_Dt):
+ if (ROFFSec_PR_Dd & tree->asec)
+ return(1);
+ break;
+ case(ROFFSec_PR_Os):
+ if (ROFFSec_PR_Dt & tree->asec)
+ return(1);
+ break;
+ case(ROFFSec_NAME):
+ if (ROFFSec_PR_Os & tree->asec)
+ return(1);
+ break;
case(ROFFSec_SYNOP):
if (ROFFSec_NAME & tree->asec)
return(1);
@@ -591,11 +594,12 @@ roffchecksec(struct rofftree *tree, const char *start, int sec)
return(1);
}
+ if (fail)
+ return(0);
return(roff_warnp(tree, start, ROFF_Sh, WRN_SECORD));
}
-/* FIXME: move this into literals.c (or similar). */
static int
roffispunct(const char *p)
{
@@ -919,23 +923,16 @@ roff_Dd(ROFFCALL_ARGS)
char *p, buf[32];
size_t sz;
- if (ROFF_BODY & tree->state) {
- assert( ! (ROFF_PRELUDE & tree->state));
- assert(ROFF_PRELUDE_Dd & tree->state);
+ if (ROFFSec_PR_Os & tree->asec)
return(roff_text(tok, tree, argv, type));
- }
-
- assert(ROFF_PRELUDE & tree->state);
- assert( ! (ROFF_BODY & tree->state));
-
- if (ROFF_PRELUDE_Dd & tree->state)
+ if (ROFFSec_PR_Dd & tree->asec)
return(roff_errp(tree, *argv, tok, ERR_PR_REP));
- if (ROFF_PRELUDE_Dt & tree->state)
+ if ( ! roffchecksec(tree, *argv, ROFFSec_PR_Dd, 1))
return(roff_errp(tree, *argv, tok, ERR_PR_OOO));
assert(NULL == tree->last);
-
argv++;
+ tree->asec |= (tree->csec = ROFFSec_PR_Dd);
/*
* This is a bit complex because there are many forms the date
@@ -947,7 +944,6 @@ roff_Dd(ROFFCALL_ARGS)
t = time(NULL);
if (NULL == localtime_r(&t, &tree->tm))
err(1, "localtime_r");
- tree->state |= ROFF_PRELUDE_Dd;
return(1);
}
@@ -961,10 +957,8 @@ roff_Dd(ROFFCALL_ARGS)
continue;
return(roff_errp(tree, p, tok, ERR_BADARG));
}
- if (strptime(buf, "%b%d,%Y", &tree->tm)) {
- tree->state |= ROFF_PRELUDE_Dd;
+ if (strptime(buf, "%b%d,%Y", &tree->tm))
return(1);
- }
return(roff_errp(tree, p, tok, ERR_BADARG));
}
@@ -982,7 +976,6 @@ roff_Dd(ROFFCALL_ARGS)
if (NULL == strptime(buf, "%b %d %Y", &tree->tm))
return(roff_errp(tree, p, tok, ERR_BADARG));
- tree->state |= ROFF_PRELUDE_Dd;
return(1);
}
@@ -993,21 +986,15 @@ roff_Dt(ROFFCALL_ARGS)
{
size_t sz;
- if (ROFF_BODY & tree->state) {
- assert( ! (ROFF_PRELUDE & tree->state));
- assert(ROFF_PRELUDE_Dt & tree->state);
+ if (ROFFSec_PR_Os & tree->asec)
return(roff_text(tok, tree, argv, type));
- }
-
- assert(ROFF_PRELUDE & tree->state);
- assert( ! (ROFF_BODY & tree->state));
-
- if ( ! (ROFF_PRELUDE_Dd & tree->state))
- return(roff_errp(tree, *argv, tok, ERR_PR_OOO));
- if (ROFF_PRELUDE_Dt & tree->state)
+ if (ROFFSec_PR_Dt & tree->asec)
return(roff_errp(tree, *argv, tok, ERR_PR_REP));
+ if ( ! roffchecksec(tree, *argv, ROFFSec_PR_Dt, 1))
+ return(roff_errp(tree, *argv, tok, ERR_PR_OOO));
argv++;
+ tree->asec |= (tree->csec = ROFFSec_PR_Dt);
sz = sizeof(tree->title);
if (NULL == *argv)
@@ -1065,7 +1052,6 @@ roff_Dt(ROFFCALL_ARGS)
return(roff_errp(tree, *argv, tok, ERR_BADARG));
assert(NULL == tree->last);
- tree->state |= ROFF_PRELUDE_Dt;
return(1);
}
@@ -1144,21 +1130,16 @@ roff_Os(ROFFCALL_ARGS)
char *p;
size_t sz;
- if (ROFF_BODY & tree->state) {
- assert( ! (ROFF_PRELUDE & tree->state));
- assert(ROFF_PRELUDE_Os & tree->state);
+ if (ROFFSec_PR_Os & tree->asec)
return(roff_text(tok, tree, argv, type));
- }
-
- assert(ROFF_PRELUDE & tree->state);
- if ( ! (ROFF_PRELUDE_Dt & tree->state) ||
- ! (ROFF_PRELUDE_Dd & tree->state))
+ if ( ! roffchecksec(tree, *argv, ROFFSec_PR_Os, 1))
return(roff_errp(tree, *argv, tok, ERR_PR_OOO));
- tree->os[0] = 0;
-
p = *++argv;
sz = sizeof(tree->os);
+ tree->asec |= (tree->csec = ROFFSec_PR_Os);
+
+ tree->os[0] = 0;
while (*argv)
if (strlcat(tree->os, *argv++, sz) >= sz)
@@ -1168,10 +1149,6 @@ roff_Os(ROFFCALL_ARGS)
if (strlcpy(tree->os, "LOCAL", sz) >= sz)
return(roff_errp(tree, p, tok, ERR_ARGLEN));
- tree->state |= ROFF_PRELUDE_Os;
- tree->state &= ~ROFF_PRELUDE;
- tree->state |= ROFF_BODY;
-
assert(ROFF_MSEC_MAX != tree->section);
assert(0 != tree->title[0]);
assert(0 != tree->os[0]);
@@ -1205,7 +1182,7 @@ roff_layout(ROFFCALL_ARGS)
assert( ! (ROFF_CALLABLE & tokens[tok].flags));
- if (ROFF_PRELUDE & tree->state)
+ if ( ! ROFFSec_NAME & tree->asec)
return(roff_errp(tree, *argv, tok, ERR_NOT_PR));
if (ROFF_EXIT == type) {
@@ -1268,7 +1245,7 @@ roff_layout(ROFFCALL_ARGS)
if (0 == tree->asec && ! (ROFFSec_NAME & tree->csec))
return(roff_err(tree, *argv, "`NAME' section "
"must be first"));
- if ( ! roffchecksec(tree, *argv, tree->csec))
+ if ( ! roffchecksec(tree, *argv, tree->csec, 0))
return(0);
tree->asec |= tree->csec;
@@ -1369,7 +1346,7 @@ roff_ordered(ROFFCALL_ARGS)
* .Xr arg1 arg2 punctuation
*/
- if (ROFF_PRELUDE & tree->state)
+ if ( ! ROFFSec_NAME & tree->asec)
return(roff_errp(tree, *argv, tok, ERR_NOT_PR));
first = (*argv == tree->cur);
@@ -1441,7 +1418,7 @@ roff_text(ROFFCALL_ARGS)
* <fl> v W f </fl> ;
*/
- if (ROFF_PRELUDE & tree->state)
+ if ( ! ROFFSec_NAME & tree->asec)
return(roff_errp(tree, *argv, tok, ERR_NOT_PR));
first = (*argv == tree->cur);