Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/external/bsd/mdocml/dist Merge mdocml-1.10.0
details: https://anonhg.NetBSD.org/src/rev/70046eadbc8c
branches: trunk
changeset: 755331:70046eadbc8c
user: joerg <joerg%NetBSD.org@localhost>
date: Tue Jun 01 21:27:23 2010 +0000
description:
Merge mdocml-1.10.0
diffstat:
external/bsd/mdocml/dist/mdoc_action.c | 231 ++++++++++++++++++++++++--------
1 files changed, 173 insertions(+), 58 deletions(-)
diffs (truncated from 454 to 300 lines):
diff -r 860523d58dd2 -r 70046eadbc8c external/bsd/mdocml/dist/mdoc_action.c
--- a/external/bsd/mdocml/dist/mdoc_action.c Tue Jun 01 21:17:49 2010 +0000
+++ b/external/bsd/mdocml/dist/mdoc_action.c Tue Jun 01 21:27:23 2010 +0000
@@ -1,4 +1,4 @@
-/* $Vendor-Id: mdoc_action.c,v 1.53 2010/04/06 11:33:00 kristaps Exp $ */
+/* $Vendor-Id: mdoc_action.c,v 1.62 2010/05/29 18:58:52 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps%kth.se@localhost>
*
@@ -28,11 +28,12 @@
#include <string.h>
#include <time.h>
+#include "mandoc.h"
#include "libmdoc.h"
#include "libmandoc.h"
#define POST_ARGS struct mdoc *m, struct mdoc_node *n
-#define PRE_ARGS struct mdoc *m, const struct mdoc_node *n
+#define PRE_ARGS struct mdoc *m, struct mdoc_node *n
#define NUMSIZ 32
#define DATESIZ 32
@@ -44,7 +45,7 @@
static int concat(struct mdoc *, char *,
const struct mdoc_node *, size_t);
-static inline int order_rs(int);
+static inline int order_rs(enum mdoct);
static int post_ar(POST_ARGS);
static int post_at(POST_ARGS);
@@ -56,6 +57,7 @@
static int post_display(POST_ARGS);
static int post_dt(POST_ARGS);
static int post_lb(POST_ARGS);
+static int post_li(POST_ARGS);
static int post_nm(POST_ARGS);
static int post_os(POST_ARGS);
static int post_pa(POST_ARGS);
@@ -101,7 +103,7 @@
{ NULL, NULL }, /* Ft */
{ NULL, NULL }, /* Ic */
{ NULL, NULL }, /* In */
- { NULL, NULL }, /* Li */
+ { NULL, post_li }, /* Li */
{ NULL, NULL }, /* Nd */
{ NULL, post_nm }, /* Nm */
{ NULL, NULL }, /* Op */
@@ -196,7 +198,7 @@
#define RSORD_MAX 14
-static const int rsord[RSORD_MAX] = {
+static const enum mdoct rsord[RSORD_MAX] = {
MDOC__A,
MDOC__T,
MDOC__B,
@@ -215,7 +217,7 @@
int
-mdoc_action_pre(struct mdoc *m, const struct mdoc_node *n)
+mdoc_action_pre(struct mdoc *m, struct mdoc_node *n)
{
switch (n->type) {
@@ -269,12 +271,21 @@
p[0] = '\0';
for ( ; n; n = n->next) {
assert(MDOC_TEXT == n->type);
- if (strlcat(p, n->string, sz) >= sz)
- return(mdoc_nerr(m, n, ETOOLONG));
+ /*
+ * XXX: yes, these can technically be resized, but it's
+ * highly unlikely that we're going to get here, so let
+ * it slip for now.
+ */
+ if (strlcat(p, n->string, sz) >= sz) {
+ mdoc_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
if (NULL == n->next)
continue;
- if (strlcat(p, " ", sz) >= sz)
- return(mdoc_nerr(m, n, ETOOLONG));
+ if (strlcat(p, " ", sz) >= sz) {
+ mdoc_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
}
return(1);
@@ -288,14 +299,16 @@
static int
post_std(POST_ARGS)
{
- struct mdoc_node *nn;
+ struct mdoc_node *nn;
if (n->child)
return(1);
+ if (NULL == m->meta.name)
+ return(1);
nn = n;
m->next = MDOC_NEXT_CHILD;
- assert(m->meta.name);
+
if ( ! mdoc_word_alloc(m, n->line, n->pos, m->meta.name))
return(0);
m->last = nn;
@@ -366,9 +379,10 @@
assert(MDOC_TEXT == n->child->type);
p = mdoc_a2st(n->child->string);
- assert(p);
- free(n->child->string);
- n->child->string = mandoc_strdup(p);
+ if (p != NULL) {
+ free(n->child->string);
+ n->child->string = mandoc_strdup(p);
+ }
return(1);
}
@@ -381,15 +395,27 @@
static int
post_at(POST_ARGS)
{
- struct mdoc_node *nn;
- const char *p;
+ struct mdoc_node *nn;
+ const char *p, *q;
+ char *buf;
+ size_t sz;
if (n->child) {
assert(MDOC_TEXT == n->child->type);
p = mdoc_a2att(n->child->string);
- assert(p);
- free(n->child->string);
- n->child->string = mandoc_strdup(p);
+ if (p) {
+ free(n->child->string);
+ n->child->string = mandoc_strdup(p);
+ } else {
+ p = "AT&T UNIX ";
+ q = n->child->string;
+ sz = strlen(p) + strlen(q) + 1;
+ buf = mandoc_malloc(sz);
+ strlcpy(buf, p, sz);
+ strlcat(buf, q, sz);
+ free(n->child->string);
+ n->child->string = buf;
+ }
return(1);
}
@@ -419,7 +445,7 @@
if ( ! concat(m, buf, n->child, BUFSIZ))
return(0);
- sec = mdoc_atosec(buf);
+ sec = mdoc_str2sec(buf);
/*
* The first section should always make us move into a non-new
* state.
@@ -433,17 +459,14 @@
case (SEC_RETURN_VALUES):
/* FALLTHROUGH */
case (SEC_ERRORS):
- switch (m->meta.msec) {
- case (2):
- /* FALLTHROUGH */
- case (3):
- /* FALLTHROUGH */
- case (9):
+ assert(m->meta.msec);
+ if (*m->meta.msec == '2')
break;
- default:
- return(mdoc_nwarn(m, n, EBADSEC));
- }
- break;
+ if (*m->meta.msec == '3')
+ break;
+ if (*m->meta.msec == '9')
+ break;
+ return(mdoc_nmsg(m, n, MANDOCERR_SECMSEC));
default:
break;
}
@@ -460,8 +483,6 @@
{
struct mdoc_node *nn;
const char *cp;
- char *ep;
- long lval;
if (m->meta.title)
free(m->meta.title);
@@ -471,16 +492,16 @@
free(m->meta.arch);
m->meta.title = m->meta.vol = m->meta.arch = NULL;
- m->meta.msec = 0;
-
/* Handles: `.Dt'
* --> title = unknown, volume = local, msec = 0, arch = NULL
*/
if (NULL == (nn = n->child)) {
/* XXX: make these macro values. */
+ /* FIXME: warn about missing values. */
m->meta.title = mandoc_strdup("unknown");
m->meta.vol = mandoc_strdup("local");
+ m->meta.msec = mandoc_strdup("1");
return(post_prol(m, n));
}
@@ -491,8 +512,10 @@
m->meta.title = mandoc_strdup(nn->string);
if (NULL == (nn = nn->next)) {
+ /* FIXME: warn about missing msec. */
/* XXX: make this a macro value. */
m->meta.vol = mandoc_strdup("local");
+ m->meta.msec = mandoc_strdup("1");
return(post_prol(m, n));
}
@@ -505,13 +528,13 @@
cp = mdoc_a2msec(nn->string);
if (cp) {
- /* FIXME: where is strtonum!? */
m->meta.vol = mandoc_strdup(cp);
- lval = strtol(nn->string, &ep, 10);
- if (nn->string[0] != '\0' && *ep == '\0')
- m->meta.msec = (int)lval;
- } else
+ m->meta.msec = mandoc_strdup(nn->string);
+ } else if (mdoc_nmsg(m, n, MANDOCERR_BADMSEC)) {
m->meta.vol = mandoc_strdup(nn->string);
+ m->meta.msec = mandoc_strdup(nn->string);
+ } else
+ return(0);
if (NULL == (nn = nn->next))
return(post_prol(m, n));
@@ -528,6 +551,7 @@
free(m->meta.vol);
m->meta.vol = mandoc_strdup(cp);
} else {
+ /* FIXME: warn about bad arch. */
cp = mdoc_a2arch(nn->string);
if (NULL == cp) {
free(m->meta.vol);
@@ -563,19 +587,32 @@
if ( ! concat(m, buf, n->child, BUFSIZ))
return(0);
+ /* XXX: yes, these can all be dynamically-adjusted buffers, but
+ * it's really not worth the extra hackery.
+ */
+
if ('\0' == buf[0]) {
#ifdef OSNAME
- if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ)
- return(mdoc_nerr(m, n, EUTSNAME));
+ if (strlcat(buf, OSNAME, BUFSIZ) >= BUFSIZ) {
+ mdoc_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
#else /*!OSNAME */
if (-1 == uname(&utsname))
- return(mdoc_nerr(m, n, EUTSNAME));
- if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ)
- return(mdoc_nerr(m, n, ETOOLONG));
- if (strlcat(buf, " ", 64) >= BUFSIZ)
- return(mdoc_nerr(m, n, ETOOLONG));
- if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ)
- return(mdoc_nerr(m, n, ETOOLONG));
+ return(mdoc_nmsg(m, n, MANDOCERR_UTSNAME));
+
+ if (strlcat(buf, utsname.sysname, BUFSIZ) >= BUFSIZ) {
+ mdoc_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
+ if (strlcat(buf, " ", 64) >= BUFSIZ) {
+ mdoc_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
+ if (strlcat(buf, utsname.release, BUFSIZ) >= BUFSIZ) {
+ mdoc_nmsg(m, n, MANDOCERR_MEM);
+ return(0);
+ }
#endif /*!OSNAME*/
}
Home |
Main Index |
Thread Index |
Old Index