From 916061ed728b162eb71037e2bfb56d6497d21361 Mon Sep 17 00:00:00 2001 From: Kristaps Dzonsons Date: Mon, 28 Mar 2011 23:52:13 +0000 Subject: Have libman and libmdoc use mandoc_getcontrol() to determine whether a macro has been invoked. libroff is next. --- mandoc.c | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'mandoc.c') diff --git a/mandoc.c b/mandoc.c index 17e94d37..da4a1606 100644 --- a/mandoc.c +++ b/mandoc.c @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.43 2011/03/22 14:05:45 kristaps Exp $ */ +/* $Id: mandoc.c,v 1.44 2011/03/28 23:52:13 kristaps Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -506,3 +506,28 @@ 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); +} -- cgit v1.2.3