-/* $Id: mandoc.c,v 1.42 2011/03/20 16:02:05 kristaps 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>
}
/*
- * 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);
}