From e4a03762c83065142a21c681f115e3405fd81a31 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sat, 29 Apr 2017 12:43:56 +0000 Subject: Parser unification: use nice ohashes for all three request and macro tables; no functional change, minus two source files, minus 200 lines of code. --- usr.bin/mandoc/man.c | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) (limited to 'usr.bin/mandoc/man.c') diff --git a/usr.bin/mandoc/man.c b/usr.bin/mandoc/man.c index 8246784d40e..1db9e879202 100644 --- a/usr.bin/mandoc/man.c +++ b/usr.bin/mandoc/man.c @@ -1,4 +1,4 @@ -/* $OpenBSD: man.c,v 1.117 2017/04/24 23:06:09 schwarze Exp $ */ +/* $OpenBSD: man.c,v 1.118 2017/04/29 12:43:55 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014, 2015 Ingo Schwarze @@ -143,26 +143,19 @@ man_pmacro(struct roff_man *man, int ln, char *buf, int offs) { struct roff_node *n; const char *cp; - int tok; - int i, ppos; + size_t sz; + enum roff_tok tok; + int ppos; int bline; - char mac[5]; - ppos = offs; - - /* - * Copy the first word into a nil-terminated buffer. - * Stop when a space, tab, escape, or eoln is encountered. - */ - - i = 0; - while (i < 4 && strchr(" \t\\", buf[offs]) == NULL) - mac[i++] = buf[offs++]; - - mac[i] = '\0'; - - tok = (i > 0 && i < 4) ? man_hash_find(mac) : TOKEN_NONE; + /* Determine the line macro. */ + ppos = offs; + tok = TOKEN_NONE; + for (sz = 0; sz < 4 && strchr(" \t\\", buf[offs]) == NULL; sz++) + offs++; + if (sz > 0 && sz < 4) + tok = roffhash_find(man->manmac, buf + ppos, sz); if (tok == TOKEN_NONE) { mandoc_msg(MANDOCERR_MACRO, man->parse, ln, ppos, buf + ppos - 1); -- cgit v1.2.3