-/* $Id: hash.c,v 1.1 2008/12/15 01:54:58 kristaps Exp $ */
+/* $Id: hash.c,v 1.2 2008/12/15 02:23:12 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
void *
mdoc_hash_alloc(void)
{
- int i, major, minor, index;
+ int i, major, minor, ind;
const void **htab;
htab = calloc(27 * 26, sizeof(struct mdoc_macro *));
assert(major >= 0 && major < 27);
assert(minor >= 0 && minor < 26);
- index = (major * 27) + minor;
+ ind = (major * 27) + minor;
- assert(NULL == htab[index]);
- htab[index] = &mdoc_macros[i];
+ assert(NULL == htab[ind]);
+ htab[ind] = &mdoc_macros[i];
}
return((void *)htab);
int
mdoc_hash_find(const void *arg, const char *tmp)
{
- int major, minor, index, slot;
+ int major, minor, ind, slot;
const void **htab;
- htab = (const void **)arg;
+ htab = /* LINTED */
+ (const void **)arg;
if (0 == tmp[0] || 0 == tmp[1])
return(MDOC_MAX);
else
minor = tmp[1] - 97;
- index = (major * 27) + minor;
+ ind = (major * 27) + minor;
- if (NULL == htab[index])
+ if (NULL == htab[ind])
return(MDOC_MAX);
- slot = htab[index] - (void *)mdoc_macros;
- assert(0 == slot % sizeof(struct mdoc_macro));
+ slot = htab[ind] - /* LINTED */
+ (void *)mdoc_macros;
+ assert(0 == (size_t)slot % sizeof(struct mdoc_macro));
slot /= sizeof(struct mdoc_macro);
if (0 != strcmp(mdoc_macronames[slot], tmp))
-/* $Id: macro.c,v 1.2 2008/12/15 01:54:58 kristaps Exp $ */
+/* $Id: macro.c,v 1.3 2008/12/15 02:23:12 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
#include "private.h"
-#define _C(p) ((const char **)p)
+#define _CC(p) ((const char **)p)
+static int append_text(struct mdoc *, int,
+ int, int, char *[]);
+static int append_scoped(struct mdoc *, int,
+ int, int, char *[]);
static int isdelim(const char *);
-static int args_next(struct mdoc *, int, int *, char *, char **);
-static int append_text(struct mdoc *, int, int, int, char *[]);
-static int append_scoped(struct mdoc *, int, int, int, char *[]);
+static int args_next(struct mdoc *, int,
+ int *, char *, char **);
static int
static int
-append_scoped(struct mdoc *mdoc, int tok, int pos, int sz, char *args[])
+append_scoped(struct mdoc *mdoc, int tok,
+ int pos, int sz, char *args[])
{
+ assert(sz >= 0);
args[sz] = NULL;
mdoc_block_alloc(mdoc, pos, tok, 0, NULL);
- mdoc_head_alloc(mdoc, pos, tok, sz, _C(args));
+ mdoc_head_alloc(mdoc, pos, tok, (size_t)sz, _CC(args));
mdoc_body_alloc(mdoc, pos, tok);
return(1);
}
static int
-append_text(struct mdoc *mdoc, int tok, int pos, int sz, char *args[])
+append_text(struct mdoc *mdoc, int tok,
+ int pos, int sz, char *args[])
{
+ assert(sz >= 0);
args[sz] = NULL;
switch (tok) {
case (MDOC_Tn):
if (0 == sz && ! mdoc_warn(mdoc, tok, pos, WARN_ARGS_GE1))
return(0);
- mdoc_elem_alloc(mdoc, pos, tok, 0, NULL, sz, _C(args));
+ mdoc_elem_alloc(mdoc, pos, tok, 0,
+ NULL, (size_t)sz, _CC(args));
return(1);
case (MDOC_Ar):
case (MDOC_Cm):
/* FALLTHROUGH */
case (MDOC_Fl):
- mdoc_elem_alloc(mdoc, pos, tok, 0, NULL, sz, _C(args));
+ mdoc_elem_alloc(mdoc, pos, tok, 0,
+ NULL, (size_t)sz, _CC(args));
return(1);
case (MDOC_Ad):
case (MDOC_Vt):
if (0 == sz)
return(mdoc_err(mdoc, tok, pos, ERR_ARGS_GE1));
- mdoc_elem_alloc(mdoc, pos, tok, 0, NULL, sz, _C(args));
+ mdoc_elem_alloc(mdoc, pos, tok, 0,
+ NULL, (size_t)sz, _CC(args));
return(1);
/* ======= ADD MORE MACRO ARGUMENT-LIMITS ABOVE. ======= */
int
macro_text(struct mdoc *mdoc, int tok, int ppos, int *pos, char *buf)
{
- int lastarg, j, c, lasttok, lastpunct;
+ int lastarg, c, lasttok, lastpunct, j;
char *args[MDOC_LINEARG_MAX], *p;
lasttok = ppos;
macro_scoped_implicit(struct mdoc *mdoc,
int tok, int ppos, int *pos, char *buf)
{
- int j, c, lastarg, t;
+ int t, c, lastarg, j;
char *args[MDOC_LINEARG_MAX];
struct mdoc_node *n;
assert( ! (MDOC_EXPLICIT & mdoc_macros[tok].flags));
+ /* LINTED */
for (n = mdoc->last; n; n = n->parent) {
if (MDOC_BLOCK != n->type)
continue;
/* Command found. */
if (MDOC_MAX != (c = mdoc_find(mdoc, args[j])))
- if ( ! mdoc_warn(mdoc, tok, *pos, WARN_SYNTAX_MACLIKE))
+ if ( ! mdoc_warn(mdoc, tok, lastarg, WARN_SYNTAX_MACLIKE))
return(0);
/* Word found. */
-/* $Id: mdoc.c,v 1.1 2008/12/15 01:54:58 kristaps Exp $ */
+/* $Id: mdoc.c,v 1.2 2008/12/15 02:23:12 kristaps Exp $ */
/*
* Copyright (c) 2008 Kristaps Dzonsons <kristaps@kth.se>
*
i--;
- (void)memcpy(tmp, buf + 1, i);
+ (void)memcpy(tmp, buf + 1, (size_t)i);
tmp[i++] = 0;
if (MDOC_MAX == (c = mdoc_find(mdoc, tmp)))
nn = mdoc_macronames[p->data.block.tok];
nt = "block";
break;
+ default:
+ abort();
+ /* NOTREACHED */
}
if (NULL == mdoc->first) {
on = mdoc_macronames[mdoc->last->data.block.tok];
ot = "block";
break;
+ default:
+ abort();
+ /* NOTREACHED */
}
switch (p->type) {
static void
argfree(size_t sz, struct mdoc_arg *p)
{
- size_t i, j;
+ int i, j;
if (0 == sz)
return;
assert(p);
- for (i = 0; i < sz; i++)
+ /* LINTED */
+ for (i = 0; i < (int)sz; i++)
if (p[i].sz > 0) {
assert(p[i].value);
- for (j = 0; j < p[i].sz; j++)
+ /* LINTED */
+ for (j = 0; j < (int)p[i].sz; j++)
free(p[i].value[j]);
}
free(p);
static void
argcpy(struct mdoc_arg *dst, const struct mdoc_arg *src)
{
- size_t i;
+ int i;
dst->arg = src->arg;
if (0 == (dst->sz = src->sz))
return;
dst->value = xcalloc(dst->sz, sizeof(char *));
- for (i = 0; i < dst->sz; i++)
+ for (i = 0; i < (int)dst->sz; i++)
dst->value[i] = xstrdup(src->value[i]);
}
argdup(size_t argsz, const struct mdoc_arg *args)
{
struct mdoc_arg *pp;
- size_t i;
+ int i;
if (0 == argsz)
return(NULL);
pp = xcalloc((size_t)argsz, sizeof(struct mdoc_arg));
- for (i = 0; i < argsz; i++)
+ for (i = 0; i < (int)argsz; i++)
argcpy(&pp[i], &args[i]);
return(pp);
static void
paramfree(size_t sz, char **p)
{
- size_t i;
+ int i;
if (0 == sz)
return;
assert(p);
- for (i = 0; i < sz; i++)
+ /* LINTED */
+ for (i = 0; i < (int)sz; i++)
free(p[i]);
free(p);
}
paramdup(size_t sz, const char **p)
{
char **pp;
- size_t i;
+ int i;
if (0 == sz)
return(NULL);
pp = xcalloc(sz, sizeof(char *));
- for (i = 0; i < sz; i++)
+ for (i = 0; i < (int)sz; i++)
pp[i] = xstrdup(p[i]);
return(pp);