summaryrefslogtreecommitdiff
path: root/usr.bin/mandoc/mandoc.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2011-04-24 16:22:03 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2011-04-24 16:22:03 +0000
commit8f4d5715119f71fe84fabe1ac036212fb9cd6dd4 (patch)
tree4595e6b302aaf0ccfc79216f87c3cccdca69b3b5 /usr.bin/mandoc/mandoc.c
parent1752cec47372d4848aa06c33133bac2b1f479dba (diff)
Merge version 1.11.1:
Again lots of cleanup and maintenance work by kristaps@. - simplify error reporting: less function pointers, more mandoc_[v]msg - main: split document parsing out of main.c into read.c - roff, mdoc, man: improved recognition of control characters - roff: better handling of if/else stack overflows - roff: add some predefined strings for backward compatibility - mdoc, man: empty sections are not errors - mdoc: move delimiter handling to libmdoc - some header restructuring and some minor features and fixes This merge causes two minor regressions that i will fix in separate commits right afterwards.
Diffstat (limited to 'usr.bin/mandoc/mandoc.c')
-rw-r--r--usr.bin/mandoc/mandoc.c77
1 files changed, 26 insertions, 51 deletions
diff --git a/usr.bin/mandoc/mandoc.c b/usr.bin/mandoc/mandoc.c
index d694cb56107..931ce863017 100644
--- a/usr.bin/mandoc/mandoc.c
+++ b/usr.bin/mandoc/mandoc.c
@@ -1,4 +1,4 @@
-/* $Id: mandoc.c,v 1.24 2011/04/21 22:59:54 schwarze Exp $ */
+/* $Id: mandoc.c,v 1.25 2011/04/24 16:22:02 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
@@ -292,7 +292,7 @@ mandoc_strdup(const char *ptr)
* or to the null byte terminating the argument line.
*/
char *
-mandoc_getarg(char **cpp, mandocmsg msg, void *data, int ln, int *pos)
+mandoc_getarg(struct mparse *parse, char **cpp, int ln, int *pos)
{
char *start, *cp;
int quoted, pairs, white;
@@ -339,8 +339,8 @@ mandoc_getarg(char **cpp, mandocmsg msg, void *data, int ln, int *pos)
}
/* Quoted argument without a closing quote. */
- if (1 == quoted && msg)
- (*msg)(MANDOCERR_BADQUOTE, data, ln, *pos, NULL);
+ if (1 == quoted)
+ mandoc_msg(MANDOCERR_BADQUOTE, parse, ln, *pos, NULL);
/* Null-terminate this argument and move to the next one. */
if (pairs)
@@ -353,8 +353,8 @@ mandoc_getarg(char **cpp, mandocmsg msg, void *data, int ln, int *pos)
*pos += (int)(cp - start) + (quoted ? 1 : 0);
*cpp = cp;
- if ('\0' == *cp && msg && (white || ' ' == cp[-1]))
- (*msg)(MANDOCERR_EOLNSPACE, data, ln, *pos, NULL);
+ if ('\0' == *cp && (white || ' ' == cp[-1]))
+ mandoc_msg(MANDOCERR_EOLNSPACE, parse, ln, *pos, NULL);
return(start);
}
@@ -412,20 +412,20 @@ fail:
}
char *
-mandoc_normdate(char *in, mandocmsg msg, void *data, int ln, int pos)
+mandoc_normdate(struct mparse *parse, char *in, int ln, int pos)
{
char *out;
time_t t;
if (NULL == in || '\0' == *in ||
0 == strcmp(in, "$" "Mdocdate$")) {
- (*msg)(MANDOCERR_NODATE, data, ln, pos, NULL);
+ mandoc_msg(MANDOCERR_NODATE, parse, ln, pos, NULL);
time(&t);
}
else if (!a2time(&t, "$" "Mdocdate: %b %d %Y $", in) &&
!a2time(&t, "%b %d, %Y", in) &&
!a2time(&t, "%Y-%m-%d", in)) {
- (*msg)(MANDOCERR_BADDATE, data, ln, pos, NULL);
+ mandoc_msg(MANDOCERR_BADDATE, parse, ln, pos, NULL);
t = 0;
}
out = t ? time2a(t) : NULL;
@@ -503,52 +503,27 @@ mandoc_hyph(const char *start, const char *c)
}
/*
- * Check if a string is a punctuation delimiter. This only applies to
- * mdoc(7) documents, but as it's used in both front-ends and back-ends,
- * it needs to go here (instead of, say, in libmdoc.h).
+ * Find out whether a line is a macro line or not. If it is, adjust the
+ * current position and return one; if it isn't, return zero and don't
+ * change the current position.
*/
-enum mdelim
-mandoc_isdelim(const char *p)
+int
+mandoc_getcontrol(const char *cp, int *ppos)
{
+ int pos;
- if ('\0' == p[0])
- return(DELIM_NONE);
-
- if ('\0' == p[1])
- switch (p[0]) {
- case('('):
- /* FALLTHROUGH */
- case('['):
- return(DELIM_OPEN);
- case('|'):
- return(DELIM_MIDDLE);
- case('.'):
- /* FALLTHROUGH */
- case(','):
- /* FALLTHROUGH */
- case(';'):
- /* FALLTHROUGH */
- case(':'):
- /* FALLTHROUGH */
- case('?'):
- /* FALLTHROUGH */
- case('!'):
- /* FALLTHROUGH */
- case(')'):
- /* FALLTHROUGH */
- case(']'):
- return(DELIM_CLOSE);
- default:
- return(DELIM_NONE);
- }
+ pos = *ppos;
- if ('\\' != p[0])
- return(DELIM_NONE);
+ if ('\\' == cp[pos] && '.' == cp[pos + 1])
+ pos += 2;
+ else if ('.' == cp[pos] || '\'' == cp[pos])
+ pos++;
+ else
+ return(0);
- if (0 == strcmp(p + 1, "."))
- return(DELIM_CLOSE);
- if (0 == strcmp(p + 1, "*(Ba"))
- return(DELIM_MIDDLE);
+ while (' ' == cp[pos] || '\t' == cp[pos])
+ pos++;
- return(DELIM_NONE);
+ *ppos = pos;
+ return(1);
}