version 1.118, 2019/04/13 15:54:45 |
version 1.119, 2019/04/14 12:38:33 |
|
|
*/ |
*/ |
|
|
static void pnode_print(struct format *, struct pnode *); |
static void pnode_print(struct format *, struct pnode *); |
|
static void pnode_printrefentry(struct format *, struct pnode *); |
|
|
|
|
static void |
static void |
Line 196 pnode_printrefsynopsisdiv(struct format *f, struct pno |
|
Line 197 pnode_printrefsynopsisdiv(struct format *f, struct pno |
|
* Start a hopefully-named `Sh' section. |
* Start a hopefully-named `Sh' section. |
*/ |
*/ |
static void |
static void |
pnode_printrefsect(struct format *f, struct pnode *n) |
pnode_printsection(struct format *f, struct pnode *n) |
{ |
{ |
struct pnode *nc, *ncc; |
struct pnode *nc, *ncc; |
const char *title; |
const char *title; |
int flags, level; |
int flags, level; |
|
|
if (n->parent == NULL) |
if (n->parent == NULL) { |
|
pnode_printrefentry(f, n); |
return; |
return; |
|
} |
|
|
level = ++f->level; |
level = ++f->level; |
flags = ARG_SPACE; |
flags = ARG_SPACE; |
Line 652 pnode_printlink(struct format *f, struct pnode *n) |
|
Line 655 pnode_printlink(struct format *f, struct pnode *n) |
|
static void |
static void |
pnode_printprologue(struct format *f, struct pnode *root) |
pnode_printprologue(struct format *f, struct pnode *root) |
{ |
{ |
struct pnode *date, *refmeta, *name, *vol, *descr, *nc; |
struct pnode *date, *refmeta, *name, *vol, *descr, *nc, *nn; |
const char *sname; |
const char *sname; |
|
|
/* Collect information. */ |
/* Collect information. */ |
Line 661 pnode_printprologue(struct format *f, struct pnode *ro |
|
Line 664 pnode_printprologue(struct format *f, struct pnode *ro |
|
date = pnode_takefirst(root, NODE_DATE); |
date = pnode_takefirst(root, NODE_DATE); |
|
|
name = vol = NULL; |
name = vol = NULL; |
if ((refmeta = pnode_takefirst(root, NODE_REFMETA)) != NULL) { |
if ((refmeta = pnode_findfirst(root, NODE_REFMETA)) != NULL) { |
TAILQ_FOREACH(nc, &refmeta->childq, child) { |
TAILQ_FOREACH_SAFE(nc, &refmeta->childq, child, nn) { |
switch (nc->node) { |
switch (nc->node) { |
case NODE_REFENTRYTITLE: |
case NODE_REFENTRYTITLE: |
name = nc; |
name = nc; |
Line 671 pnode_printprologue(struct format *f, struct pnode *ro |
|
Line 674 pnode_printprologue(struct format *f, struct pnode *ro |
|
vol = nc; |
vol = nc; |
break; |
break; |
default: |
default: |
break; |
continue; |
} |
} |
|
TAILQ_REMOVE(&refmeta->childq, nc, child); |
} |
} |
} |
} |
|
|
Line 715 pnode_printprologue(struct format *f, struct pnode *ro |
|
Line 719 pnode_printprologue(struct format *f, struct pnode *ro |
|
/* Clean up. */ |
/* Clean up. */ |
|
|
pnode_unlink(date); |
pnode_unlink(date); |
pnode_unlink(refmeta); |
pnode_unlink(name); |
|
pnode_unlink(vol); |
pnode_unlink(descr); |
pnode_unlink(descr); |
} |
} |
|
|
|
static void |
|
pnode_printrefentry(struct format *f, struct pnode *n) |
|
{ |
|
struct pnode *info, *meta, *nc, *title; |
|
struct pnode *match, *later; |
|
|
|
/* Collect nodes that remained behind when writing the prologue. */ |
|
|
|
meta = NULL; |
|
info = pnode_takefirst(n, NODE_BOOKINFO); |
|
if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) { |
|
pnode_unlink(info); |
|
info = NULL; |
|
} |
|
if (info == NULL) { |
|
info = pnode_takefirst(n, NODE_REFENTRYINFO); |
|
if (info != NULL && TAILQ_FIRST(&info->childq) == NULL) { |
|
pnode_unlink(info); |
|
info = NULL; |
|
} |
|
meta = pnode_takefirst(n, NODE_REFMETA); |
|
if (meta != NULL && TAILQ_FIRST(&meta->childq) == NULL) { |
|
pnode_unlink(meta); |
|
meta = NULL; |
|
} |
|
} |
|
if (info == NULL && meta == NULL) |
|
return; |
|
|
|
/* |
|
* Find the best place to put this information. |
|
* Use the last existing AUTHORS node, if any. |
|
* Otherwise, put it behind all standard sections that |
|
* conventionally precede AUTHORS, and also behind any |
|
* non-standard sections that follow the last of these, |
|
* but before the next standard section. |
|
*/ |
|
|
|
match = later = NULL; |
|
TAILQ_FOREACH(nc, &n->childq, child) { |
|
switch (nc->node) { |
|
case NODE_REFENTRY: |
|
case NODE_REFNAMEDIV: |
|
case NODE_REFSYNOPSISDIV: |
|
case NODE_PREFACE: |
|
later = NULL; |
|
continue; |
|
case NODE_APPENDIX: |
|
case NODE_INDEX: |
|
if (later == NULL) |
|
later = nc; |
|
continue; |
|
default: |
|
break; |
|
} |
|
if ((title = pnode_findfirst(nc, NODE_TITLE)) == NULL || |
|
(title = TAILQ_FIRST(&title->childq)) == NULL || |
|
title->node != NODE_TEXT) |
|
continue; |
|
if (strcasecmp(title->b, "AUTHORS") == 0 || |
|
strcasecmp(title->b, "AUTHOR") == 0) |
|
match = nc; |
|
else if (strcasecmp(title->b, "NAME") == 0 || |
|
strcasecmp(title->b, "SYNOPSIS") == 0 || |
|
strcasecmp(title->b, "DESCRIPTION") == 0 || |
|
strcasecmp(title->b, "RETURN VALUES") == 0 || |
|
strcasecmp(title->b, "ENVIRONMENT") == 0 || |
|
strcasecmp(title->b, "FILES") == 0 || |
|
strcasecmp(title->b, "EXIT STATUS") == 0 || |
|
strcasecmp(title->b, "EXAMPLES") == 0 || |
|
strcasecmp(title->b, "DIAGNOSTICS") == 0 || |
|
strcasecmp(title->b, "ERRORS") == 0 || |
|
strcasecmp(title->b, "SEE ALSO") == 0 || |
|
strcasecmp(title->b, "STANDARDS") == 0 || |
|
strcasecmp(title->b, "HISTORY") == 0) |
|
later = NULL; |
|
else if ((strcasecmp(title->b, "CAVEATS") == 0 || |
|
strcasecmp(title->b, "BUGS") == 0) && |
|
later == NULL) |
|
later = nc; |
|
} |
|
|
|
/* |
|
* If no AUTHORS section was found, create one from scratch, |
|
* and insert that at the place selected earlier. |
|
*/ |
|
|
|
if (match == NULL) { |
|
if ((match = calloc(1, sizeof(*match))) == NULL) { |
|
perror(NULL); |
|
exit(1); |
|
} |
|
match->node = NODE_SECTION; |
|
match->spc = 1; |
|
match->parent = n; |
|
TAILQ_INIT(&match->childq); |
|
TAILQ_INIT(&match->attrq); |
|
if ((nc = pnode_alloc(match)) == NULL) { |
|
perror(NULL); |
|
exit(1); |
|
} |
|
nc->node = NODE_TITLE; |
|
nc->spc = 1; |
|
if ((nc = pnode_alloc(nc)) == NULL) { |
|
perror(NULL); |
|
exit(1); |
|
} |
|
nc->node = NODE_TEXT; |
|
if ((nc->b = strdup("AUTHORS")) == NULL) { |
|
perror(NULL); |
|
exit(1); |
|
} |
|
nc->spc = 1; |
|
if (later == NULL) |
|
TAILQ_INSERT_TAIL(&n->childq, match, child); |
|
else |
|
TAILQ_INSERT_BEFORE(later, match, child); |
|
} |
|
|
|
/* |
|
* Dump the stuff excised at the beginning |
|
* into this AUTHORS section. |
|
*/ |
|
|
|
if (info != NULL) |
|
TAILQ_INSERT_TAIL(&match->childq, info, child); |
|
if (meta != NULL) |
|
TAILQ_INSERT_TAIL(&match->childq, meta, child); |
|
} |
|
|
/* |
/* |
* We can have multiple <term> elements within a <varlistentry>, which |
* We can have multiple <term> elements within a <varlistentry>, which |
* we should comma-separate as list headers. |
* we should comma-separate as list headers. |
Line 1046 pnode_print(struct format *f, struct pnode *n) |
|
Line 1181 pnode_print(struct format *f, struct pnode *n) |
|
case NODE_SYSTEMITEM: |
case NODE_SYSTEMITEM: |
pnode_printsystemitem(f, n); |
pnode_printsystemitem(f, n); |
break; |
break; |
case NODE_REFENTRYINFO: |
case NODE_REFENTRY: |
/* Suppress. */ |
pnode_printrefentry(f, n); |
pnode_unlinksub(n); |
|
break; |
break; |
case NODE_REFNAME: |
case NODE_REFNAME: |
/* More often, these appear inside NODE_REFNAMEDIV. */ |
/* More often, these appear inside NODE_REFNAMEDIV. */ |
Line 1071 pnode_print(struct format *f, struct pnode *n) |
|
Line 1205 pnode_print(struct format *f, struct pnode *n) |
|
case NODE_TIP: |
case NODE_TIP: |
case NODE_CAUTION: |
case NODE_CAUTION: |
case NODE_WARNING: |
case NODE_WARNING: |
pnode_printrefsect(f, n); |
pnode_printsection(f, n); |
break; |
break; |
case NODE_REPLACEABLE: |
case NODE_REPLACEABLE: |
macro_open(f, "Ar"); |
macro_open(f, "Ar"); |