-/* $Id: mandoc.c,v 1.38 2011/03/15 03:03:54 schwarze Exp $ */
+/* $Id: mandoc.c,v 1.44 2011/03/28 23:52:13 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
* 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;
}
/* 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)
while (' ' == *cp)
cp++;
}
- *pos += (cp - start) + (quoted ? 1 : 0);
+ *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);
}
-
static int
a2time(time_t *t, const char *fmt, const char *p)
{
return(0);
}
-
static char *
time2a(time_t t)
{
return(NULL);
}
-
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;
return(out ? out : mandoc_strdup(in));
}
-
int
mandoc_eos(const char *p, size_t sz, int enclosed)
{
return(found && !enclosed);
}
-
int
mandoc_hyph(const char *start, const char *c)
{
return(1);
}
+
+/*
+ * 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.
+ */
+int
+mandoc_getcontrol(const char *cp, int *ppos)
+{
+ int pos;
+
+ pos = *ppos;
+
+ if ('\\' == cp[pos] && '.' == cp[pos + 1])
+ pos += 2;
+ else if ('.' == cp[pos] || '\'' == cp[pos])
+ pos++;
+ else
+ return(0);
+
+ while (' ' == cp[pos] || '\t' == cp[pos])
+ pos++;
+
+ *ppos = pos;
+ return(1);
+}