summaryrefslogtreecommitdiffstats
path: root/mdoc.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-04-20 16:46:04 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-04-20 16:46:04 +0000
commitf45f622c8ebfa925e3b5340d31a0b4f9380ff675 (patch)
tree30c393373586e5d6d990ecf3f7c77cb6d9a105d9 /mdoc.c
parentc64d9ad4033a749b71419ced2dc27c0b4a787818 (diff)
downloadmandoc-f45f622c8ebfa925e3b5340d31a0b4f9380ff675.tar.gz
KNF: case (FOO): -> case FOO:, remove /* LINTED */ and /* ARGSUSED */,
remove trailing whitespace and blanks before tabs, improve some indenting; no functional change
Diffstat (limited to 'mdoc.c')
-rw-r--r--mdoc.c155
1 files changed, 66 insertions, 89 deletions
diff --git a/mdoc.c b/mdoc.c
index 58c65508..5a9271b0 100644
--- a/mdoc.c
+++ b/mdoc.c
@@ -35,7 +35,7 @@
#include "libmdoc.h"
#include "libmandoc.h"
-const char *const __mdoc_macronames[MDOC_MAX] = {
+const char *const __mdoc_macronames[MDOC_MAX] = {
"Ap", "Dd", "Dt", "Os",
"Sh", "Ss", "Pp", "D1",
"Dl", "Bd", "Ed", "Bl",
@@ -46,11 +46,8 @@ const char *const __mdoc_macronames[MDOC_MAX] = {
"Ic", "In", "Li", "Nd",
"Nm", "Op", "Ot", "Pa",
"Rv", "St", "Va", "Vt",
- /* LINTED */
"Xr", "%A", "%B", "%D",
- /* LINTED */
"%I", "%J", "%N", "%O",
- /* LINTED */
"%P", "%R", "%T", "%V",
"Ac", "Ao", "Aq", "At",
"Bc", "Bf", "Bo", "Bq",
@@ -67,22 +64,19 @@ const char *const __mdoc_macronames[MDOC_MAX] = {
"Bk", "Ek", "Bt", "Hf",
"Fr", "Ud", "Lb", "Lp",
"Lk", "Mt", "Brq", "Bro",
- /* LINTED */
"Brc", "%C", "Es", "En",
- /* LINTED */
"Dx", "%Q", "br", "sp",
- /* LINTED */
"%U", "Ta", "ll",
};
-const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
+const char *const __mdoc_argnames[MDOC_ARG_MAX] = {
"split", "nosplit", "ragged",
- "unfilled", "literal", "file",
- "offset", "bullet", "dash",
- "hyphen", "item", "enum",
- "tag", "diag", "hang",
- "ohang", "inset", "column",
- "width", "compact", "std",
+ "unfilled", "literal", "file",
+ "offset", "bullet", "dash",
+ "hyphen", "item", "enum",
+ "tag", "diag", "hang",
+ "ohang", "inset", "column",
+ "width", "compact", "std",
"filled", "words", "emphasis",
"symbolic", "nested", "centered"
};
@@ -91,13 +85,13 @@ const char * const *mdoc_macronames = __mdoc_macronames;
const char * const *mdoc_argnames = __mdoc_argnames;
static void mdoc_node_free(struct mdoc_node *);
-static void mdoc_node_unlink(struct mdoc *,
+static void mdoc_node_unlink(struct mdoc *,
struct mdoc_node *);
static void mdoc_free1(struct mdoc *);
static void mdoc_alloc1(struct mdoc *);
-static struct mdoc_node *node_alloc(struct mdoc *, int, int,
+static struct mdoc_node *node_alloc(struct mdoc *, int, int,
enum mdoct, enum mdoc_type);
-static int node_append(struct mdoc *,
+static int node_append(struct mdoc *,
struct mdoc_node *);
#if 0
static int mdoc_preptext(struct mdoc *, int, char *, int);
@@ -105,6 +99,7 @@ static int mdoc_preptext(struct mdoc *, int, char *, int);
static int mdoc_ptext(struct mdoc *, int, char *, int);
static int mdoc_pmacro(struct mdoc *, int, char *, int);
+
const struct mdoc_node *
mdoc_node(const struct mdoc *mdoc)
{
@@ -113,7 +108,6 @@ mdoc_node(const struct mdoc *mdoc)
return(mdoc->first);
}
-
const struct mdoc_meta *
mdoc_meta(const struct mdoc *mdoc)
{
@@ -122,7 +116,6 @@ mdoc_meta(const struct mdoc *mdoc)
return(&mdoc->meta);
}
-
/*
* Frees volatile resources (parse tree, meta-data, fields).
*/
@@ -148,7 +141,6 @@ mdoc_free1(struct mdoc *mdoc)
free(mdoc->meta.date);
}
-
/*
* Allocate all volatile resources (parse tree, meta-data, fields).
*/
@@ -166,7 +158,6 @@ mdoc_alloc1(struct mdoc *mdoc)
mdoc->next = MDOC_NEXT_CHILD;
}
-
/*
* Free up volatile resources (see mdoc_free1()) then re-initialises the
* data with mdoc_alloc1(). After invocation, parse data has been reset
@@ -181,7 +172,6 @@ mdoc_reset(struct mdoc *mdoc)
mdoc_alloc1(mdoc);
}
-
/*
* Completely free up all volatile and non-volatile parse resources.
* After invocation, the pointer is no longer usable.
@@ -194,9 +184,8 @@ mdoc_free(struct mdoc *mdoc)
free(mdoc);
}
-
/*
- * Allocate volatile and non-volatile parse resources.
+ * Allocate volatile and non-volatile parse resources.
*/
struct mdoc *
mdoc_alloc(struct roff *roff, struct mparse *parse,
@@ -216,7 +205,6 @@ mdoc_alloc(struct roff *roff, struct mparse *parse,
return(p);
}
-
/*
* Climb back up the parse tree, validating open scopes. Mostly calls
* through to macro_end() in macro.c.
@@ -280,7 +268,6 @@ mdoc_addspan(struct mdoc *mdoc, const struct tbl_span *sp)
return(1);
}
-
/*
* Main parse routine. Parses a single line -- really just hands off to
* the macro (mdoc_pmacro()) or text parser (mdoc_ptext()).
@@ -305,8 +292,8 @@ mdoc_parseln(struct mdoc *mdoc, int ln, char *buf, int offs)
mdoc->flags &= ~MDOC_SYNOPSIS;
return(roff_getcontrol(mdoc->roff, buf, &offs) ?
- mdoc_pmacro(mdoc, ln, buf, offs) :
- mdoc_ptext(mdoc, ln, buf, offs));
+ mdoc_pmacro(mdoc, ln, buf, offs) :
+ mdoc_ptext(mdoc, ln, buf, offs));
}
int
@@ -316,16 +303,16 @@ mdoc_macro(MACRO_PROT_ARGS)
/* If we're in the body, deny prologue calls. */
- if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
- MDOC_PBODY & mdoc->flags) {
+ if (MDOC_PROLOGUE & mdoc_macros[tok].flags &&
+ MDOC_PBODY & mdoc->flags) {
mdoc_pmsg(mdoc, line, ppos, MANDOCERR_BADBODY);
return(1);
}
/* If we're in the prologue, deny "body" macros. */
- if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
- ! (MDOC_PBODY & mdoc->flags)) {
+ if ( ! (MDOC_PROLOGUE & mdoc_macros[tok].flags) &&
+ ! (MDOC_PBODY & mdoc->flags)) {
mdoc_pmsg(mdoc, line, ppos, MANDOCERR_BADPROLOG);
if (NULL == mdoc->meta.msec)
mdoc->meta.msec = mandoc_strdup("1");
@@ -354,12 +341,12 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
assert(MDOC_ROOT != p->type);
switch (mdoc->next) {
- case (MDOC_NEXT_SIBLING):
+ case MDOC_NEXT_SIBLING:
mdoc->last->next = p;
p->prev = mdoc->last;
p->parent = mdoc->last->parent;
break;
- case (MDOC_NEXT_CHILD):
+ case MDOC_NEXT_CHILD:
mdoc->last->child = p;
p->parent = mdoc->last;
break;
@@ -376,13 +363,13 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
*/
switch (p->type) {
- case (MDOC_BODY):
+ case MDOC_BODY:
if (ENDBODY_NOT != p->end)
break;
/* FALLTHROUGH */
- case (MDOC_TAIL):
+ case MDOC_TAIL:
/* FALLTHROUGH */
- case (MDOC_HEAD):
+ case MDOC_HEAD:
p->norm = p->parent->norm;
break;
default:
@@ -393,15 +380,15 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
return(0);
switch (p->type) {
- case (MDOC_HEAD):
+ case MDOC_HEAD:
assert(MDOC_BLOCK == p->parent->type);
p->parent->head = p;
break;
- case (MDOC_TAIL):
+ case MDOC_TAIL:
assert(MDOC_BLOCK == p->parent->type);
p->parent->tail = p;
break;
- case (MDOC_BODY):
+ case MDOC_BODY:
if (p->end)
break;
assert(MDOC_BLOCK == p->parent->type);
@@ -414,9 +401,9 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
mdoc->last = p;
switch (p->type) {
- case (MDOC_TBL):
+ case MDOC_TBL:
/* FALLTHROUGH */
- case (MDOC_TEXT):
+ case MDOC_TEXT:
if ( ! mdoc_valid_post(mdoc))
return(0);
break;
@@ -427,9 +414,8 @@ node_append(struct mdoc *mdoc, struct mdoc_node *p)
return(1);
}
-
static struct mdoc_node *
-node_alloc(struct mdoc *mdoc, int line, int pos,
+node_alloc(struct mdoc *mdoc, int line, int pos,
enum mdoct tok, enum mdoc_type type)
{
struct mdoc_node *p;
@@ -455,7 +441,6 @@ node_alloc(struct mdoc *mdoc, int line, int pos,
return(p);
}
-
int
mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
{
@@ -468,7 +453,6 @@ mdoc_tail_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
return(1);
}
-
int
mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
{
@@ -484,7 +468,6 @@ mdoc_head_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
return(1);
}
-
int
mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
{
@@ -497,7 +480,6 @@ mdoc_body_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok)
return(1);
}
-
int
mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok,
struct mdoc_node *body, enum mdoc_endbody end)
@@ -514,9 +496,8 @@ mdoc_endbody_alloc(struct mdoc *mdoc, int line, int pos, enum mdoct tok,
return(1);
}
-
int
-mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
+mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
enum mdoct tok, struct mdoc_arg *args)
{
struct mdoc_node *p;
@@ -527,13 +508,13 @@ mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
(args->refcnt)++;
switch (tok) {
- case (MDOC_Bd):
+ case MDOC_Bd:
/* FALLTHROUGH */
- case (MDOC_Bf):
+ case MDOC_Bf:
/* FALLTHROUGH */
- case (MDOC_Bl):
+ case MDOC_Bl:
/* FALLTHROUGH */
- case (MDOC_Rs):
+ case MDOC_Rs:
p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
break;
default:
@@ -546,9 +527,8 @@ mdoc_block_alloc(struct mdoc *mdoc, int line, int pos,
return(1);
}
-
int
-mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos,
+mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos,
enum mdoct tok, struct mdoc_arg *args)
{
struct mdoc_node *p;
@@ -559,7 +539,7 @@ mdoc_elem_alloc(struct mdoc *mdoc, int line, int pos,
(args->refcnt)++;
switch (tok) {
- case (MDOC_An):
+ case MDOC_An:
p->norm = mandoc_calloc(1, sizeof(union mdoc_data));
break;
default:
@@ -615,7 +595,6 @@ mdoc_node_free(struct mdoc_node *p)
free(p);
}
-
static void
mdoc_node_unlink(struct mdoc *mdoc, struct mdoc_node *n)
{
@@ -653,7 +632,6 @@ mdoc_node_unlink(struct mdoc *mdoc, struct mdoc_node *n)
mdoc->first = NULL;
}
-
void
mdoc_node_delete(struct mdoc *mdoc, struct mdoc_node *p)
{
@@ -724,7 +702,7 @@ mdoc_preptext(struct mdoc *mdoc, int line, char *buf, int offs)
if ( ! mdoc_addeqn(mdoc, roff_eqn(mdoc->roff)))
return(0);
offs += (end - (buf + offs));
- }
+ }
return(1);
}
@@ -758,16 +736,16 @@ mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int offs)
*/
if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
- LIST_column == n->norm->Bl.type) {
+ LIST_column == n->norm->Bl.type) {
/* `Bl' is open without any children. */
mdoc->flags |= MDOC_FREECOL;
return(mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf));
}
if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
- NULL != n->parent &&
- MDOC_Bl == n->parent->tok &&
- LIST_column == n->parent->norm->Bl.type) {
+ NULL != n->parent &&
+ MDOC_Bl == n->parent->tok &&
+ LIST_column == n->parent->norm->Bl.type) {
/* `Bl' has block-level `It' children. */
mdoc->flags |= MDOC_FREECOL;
return(mdoc_macro(mdoc, MDOC_It, line, offs, &offs, buf));
@@ -853,7 +831,6 @@ mdoc_ptext(struct mdoc *mdoc, int line, char *buf, int offs)
return(1);
}
-
/*
* Parse a macro line, that is, a line beginning with the control
* character.
@@ -876,14 +853,14 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
sv = offs;
- /*
+ /*
* Copy the first word into a nil-terminated buffer.
* Stop copying when a tab, space, or eoln is encountered.
*/
i = 0;
- while (i < 4 && '\0' != buf[offs] &&
- ' ' != buf[offs] && '\t' != buf[offs])
+ while (i < 4 && '\0' != buf[offs] && ' ' != buf[offs] &&
+ '\t' != buf[offs])
mac[i++] = buf[offs++];
mac[i] = '\0';
@@ -891,8 +868,8 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
tok = (i > 1 || i < 4) ? mdoc_hash_find(mac) : MDOC_MAX;
if (MDOC_MAX == tok) {
- mandoc_vmsg(MANDOCERR_MACRO, mdoc->parse,
- ln, sv, "%s", buf + sv - 1);
+ mandoc_vmsg(MANDOCERR_MACRO, mdoc->parse,
+ ln, sv, "%s", buf + sv - 1);
return(1);
}
@@ -906,7 +883,7 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
while (buf[offs] && ' ' == buf[offs])
offs++;
- /*
+ /*
* Trailing whitespace. Note that tabs are allowed to be passed
* into the parser as "text", so we only warn about spaces here.
*/
@@ -920,7 +897,7 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
*/
if (NULL == mdoc->last || MDOC_It == tok || MDOC_El == tok) {
- if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf))
+ if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf))
goto err;
return(1);
}
@@ -934,7 +911,7 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
*/
if (MDOC_Bl == n->tok && MDOC_BODY == n->type &&
- LIST_column == n->norm->Bl.type) {
+ LIST_column == n->norm->Bl.type) {
mdoc->flags |= MDOC_FREECOL;
if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf))
goto err;
@@ -948,18 +925,18 @@ mdoc_pmacro(struct mdoc *mdoc, int ln, char *buf, int offs)
*/
if (MDOC_It == n->tok && MDOC_BLOCK == n->type &&
- NULL != n->parent &&
- MDOC_Bl == n->parent->tok &&
- LIST_column == n->parent->norm->Bl.type) {
+ NULL != n->parent &&
+ MDOC_Bl == n->parent->tok &&
+ LIST_column == n->parent->norm->Bl.type) {
mdoc->flags |= MDOC_FREECOL;
- if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf))
+ if ( ! mdoc_macro(mdoc, MDOC_It, ln, sv, &sv, buf))
goto err;
return(1);
}
/* Normal processing of a macro. */
- if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf))
+ if ( ! mdoc_macro(mdoc, tok, ln, sv, &offs, buf))
goto err;
/* In quick mode (for mandocdb), abort after the NAME section. */
@@ -985,27 +962,27 @@ mdoc_isdelim(const char *p)
if ('\0' == p[1])
switch (p[0]) {
- case('('):
+ case '(':
/* FALLTHROUGH */
- case('['):
+ case '[':
return(DELIM_OPEN);
- case('|'):
+ case '|':
return(DELIM_MIDDLE);
- case('.'):
+ case '.':
/* FALLTHROUGH */
- case(','):
+ case ',':
/* FALLTHROUGH */
- case(';'):
+ case ';':
/* FALLTHROUGH */
- case(':'):
+ case ':':
/* FALLTHROUGH */
- case('?'):
+ case '?':
/* FALLTHROUGH */
- case('!'):
+ case '!':
/* FALLTHROUGH */
- case(')'):
+ case ')':
/* FALLTHROUGH */
- case(']'):
+ case ']':
return(DELIM_CLOSE);
default:
return(DELIM_NONE);