-/* $Id: action.c,v 1.33 2009/03/08 11:41:22 kristaps Exp $ */
+/* $Id: action.c,v 1.34 2009/03/08 12:40:27 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
size_t width;
int i, tok;
char buf[32];
- char **p;
+ char *p;
if (NULL == m->last->args)
return(merr(m, ENOWIDTH));
if (i == (int)m->last->args->argc)
return(merr(m, ENOWIDTH));
- p = &m->last->args->argv[i].value[0];
+ p = m->last->args->argv[i].value[0];
/*
* If the value to -width is a macro, then we re-write it to be
* the macro's width as set in share/tmac/mdoc/doc-common.
*/
- if (xstrcmp(*p, "Ds"))
+ if (xstrcmp(p, "Ds"))
width = 8;
- else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, *p)))
+ else if (MDOC_MAX == (tok = mdoc_tokhash_find(m->htab, p)))
return(1);
else if (0 == (width = mdoc_macro2len(tok)))
return(mwarn(m, WNOWIDTH));
mdoc_msg(m, "re-writing %s argument: %s -> %zun",
- mdoc_argnames[MDOC_Width], *p, width);
+ mdoc_argnames[MDOC_Width], p, width);
/* The value already exists: free and reallocate it. */
(void)snprintf(buf, sizeof(buf), "%zun", width);
- free(*p);
- *p = xstrdup(buf);
+ free(m->last->args->argv[i].value[0]);
+ m->last->args->argv[i].value[0] = xstrdup(buf);
return(1);
}
-/* $Id: argv.c,v 1.39 2009/03/08 11:41:22 kristaps Exp $ */
+/* $Id: argv.c,v 1.40 2009/03/08 12:40:27 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
return(ARGV_ERROR);
if (NULL == (arg = *v)) {
- v = xcalloc(1, sizeof(struct mdoc_arg));
+ *v = xcalloc(1, sizeof(struct mdoc_arg));
arg = *v;
- }
+ }
arg->argc++;
arg->argv = xrealloc(arg->argv, arg->argc *
- sizeof(struct mdoc_arg));
+ sizeof(struct mdoc_argv));
(void)memcpy(&arg->argv[(int)arg->argc - 1],
&tmp, sizeof(struct mdoc_argv));
{
int i, j;
- if (p->refcnt && --(p->refcnt) > 0)
- return;
+ if (p->refcnt) {
+ --(p->refcnt);
+ if (p->refcnt)
+ return;
+ }
+
+ assert(p->argc);
/* LINTED */
for (i = 0; i < (int)p->argc; i++) {
/* LINTED */
for (j = 0; j < (int)p->argv[i].sz; j++)
free(p->argv[i].value[j]);
+
free(p->argv[i].value);
}
- if (p->argc)
- free(p->argv);
+ free(p->argv);
free(p);
}
v->value = xrealloc(v->value,
(v->sz + 5) * sizeof(char *));
- v->value[(int)v->sz] = p;
+ v->value[(int)v->sz] = xstrdup(p);
}
if (v->sz)
v->sz = 1;
v->value = xcalloc(1, sizeof(char *));
- v->value[0] = p;
+ v->value[0] = xstrdup(p);
return(1);
}
v->sz = 1;
v->value = xcalloc(1, sizeof(char *));
- v->value[0] = p;
+ v->value[0] = xstrdup(p);
return(1);
}
-/* $Id: mdoc.c,v 1.53 2009/03/08 11:41:22 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.54 2009/03/08 12:40:27 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
break;
}
+ /* FIXME: be able to skip unknown macro lines! */
+
mac[i - 1] = 0;
if (i == 5 || i <= 2) {
-/* $Id: validate.c,v 1.72 2009/03/08 11:48:44 kristaps Exp $ */
+/* $Id: validate.c,v 1.73 2009/03/08 12:40:27 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
if (NULL == n->args)
return(1);
+ assert(n->args->argc);
for (i = 0; i < (int)n->args->argc; i++)
if ( ! check_argv(m, n, &n->args->argv[i]))
return(0);
p += (int)c - 1;
continue;
}
- return(mdoc_perr(mdoc, line, pos,
- "invalid escape sequence: %s", p));
+ return(mdoc_perr(mdoc, line, pos, "invalid escape"));
}
return(1);
pre_an(PRE_ARGS)
{
- if (n->args && 1 >= n->args->argc)
+ if (NULL == n->args || 1 == n->args->argc)
return(1);
return(mdoc_nerr(mdoc, n, "only one argument allowed"));
}