-/* $OpenBSD$ */
+/* $Id: mdoc_argv.c,v 1.105 2015/10/06 18:32:19 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2012, 2014 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2012, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
#include <stdio.h>
#include <string.h>
-#include "mdoc.h"
-#include "mandoc.h"
#include "mandoc_aux.h"
-#include "libmdoc.h"
+#include "mandoc.h"
+#include "roff.h"
+#include "mdoc.h"
#include "libmandoc.h"
+#include "libmdoc.h"
#define MULTI_STEP 5 /* pre-allocate argument values */
#define DELIMSZ 6 /* max possible size of a delimiter */
};
static void argn_free(struct mdoc_arg *, int);
-static enum margserr args(struct mdoc *, int, int *,
+static enum margserr args(struct roff_man *, int, int *,
char *, enum argsflag, char **);
static int args_checkpunct(const char *, int);
-static void argv_multi(struct mdoc *, int,
+static void argv_multi(struct roff_man *, int,
struct mdoc_argv *, int *, char *);
-static void argv_single(struct mdoc *, int,
+static void argv_single(struct roff_man *, int,
struct mdoc_argv *, int *, char *);
static const enum argvflag argvflags[MDOC_ARG_MAX] = {
* Some flags take no argument, some one, some multiple.
*/
void
-mdoc_argv(struct mdoc *mdoc, int line, enum mdoct tok,
+mdoc_argv(struct roff_man *mdoc, int line, int tok,
struct mdoc_arg **reta, int *pos, char *buf)
{
struct mdoc_argv tmpv;
/* Parse the arguments of the flag. */
tmpv.line = line;
- tmpv.pos = ipos;
+ tmpv.pos = *pos;
tmpv.sz = 0;
tmpv.value = NULL;
}
enum margserr
-mdoc_zargs(struct mdoc *mdoc, int line, int *pos, char *buf, char **v)
-{
-
- return(args(mdoc, line, pos, buf, ARGSFL_NONE, v));
-}
-
-enum margserr
-mdoc_args(struct mdoc *mdoc, int line, int *pos,
- char *buf, enum mdoct tok, char **v)
+mdoc_args(struct roff_man *mdoc, int line, int *pos,
+ char *buf, int tok, char **v)
{
+ struct roff_node *n;
+ char *v_local;
enum argsflag fl;
- struct mdoc_node *n;
-
- fl = mdocargs[tok].flags;
- if (MDOC_It != tok)
- return(args(mdoc, line, pos, buf, fl, v));
+ if (v == NULL)
+ v = &v_local;
+ fl = tok == TOKEN_NONE ? ARGSFL_NONE : mdocargs[tok].flags;
+ if (tok != MDOC_It)
+ return args(mdoc, line, pos, buf, fl, v);
/*
* We know that we're in an `It', so it's reasonable to expect
break;
}
- return(args(mdoc, line, pos, buf, fl, v));
+ return args(mdoc, line, pos, buf, fl, v);
}
static enum margserr
-args(struct mdoc *mdoc, int line, int *pos,
+args(struct roff_man *mdoc, int line, int *pos,
char *buf, enum argsflag fl, char **v)
{
char *p, *pp;
if ('\0' == buf[*pos]) {
if (MDOC_PPHRASE & mdoc->flags)
- return(ARGS_EOLN);
+ return ARGS_EOLN;
/*
* If we're not in a partial phrase and the flag for
* being a phrase literal is still set, the punctuation
mdoc->parse, line, *pos, NULL);
mdoc->flags &= ~MDOC_PHRASELIT;
- return(ARGS_EOLN);
+ return ARGS_EOLN;
}
*v = &buf[*pos];
if (ARGSFL_DELIM == fl)
if (args_checkpunct(buf, *pos))
- return(ARGS_PUNCT);
+ return ARGS_PUNCT;
/*
* First handle TABSEP items, restricted to `Bl -column'. This
for (pp = &buf[*pos]; ' ' == *pp; pp++, (*pos)++)
/* Skip ahead. */ ;
- return(rc);
+ return rc;
}
/*
if ('\0' == buf[*pos]) {
if (MDOC_PPHRASE & mdoc->flags)
- return(ARGS_QWORD);
+ return ARGS_QWORD;
mandoc_msg(MANDOCERR_ARG_QUOTE,
mdoc->parse, line, *pos, NULL);
- return(ARGS_QWORD);
+ return ARGS_QWORD;
}
mdoc->flags &= ~MDOC_PHRASELIT;
buf[(*pos)++] = '\0';
if ('\0' == buf[*pos])
- return(ARGS_QWORD);
+ return ARGS_QWORD;
while (' ' == buf[*pos])
(*pos)++;
mandoc_msg(MANDOCERR_SPACE_EOL, mdoc->parse,
line, *pos, NULL);
- return(ARGS_QWORD);
+ return ARGS_QWORD;
}
p = &buf[*pos];
*v = mandoc_getarg(mdoc->parse, &p, line, pos);
- return(ARGS_WORD);
+ return ARGS_WORD;
}
/*
dbuf[j] = buf[i];
if (DELIMSZ == j)
- return(0);
+ return 0;
dbuf[j] = '\0';
if (DELIM_CLOSE != mdoc_isdelim(dbuf))
- return(0);
+ return 0;
while (' ' == buf[i])
i++;
dbuf[j++] = buf[i++];
if (DELIMSZ == j)
- return(0);
+ return 0;
dbuf[j] = '\0';
d = mdoc_isdelim(dbuf);
if (DELIM_NONE == d || DELIM_OPEN == d)
- return(0);
+ return 0;
while (' ' == buf[i])
i++;
}
- return('\0' == buf[i]);
+ return '\0' == buf[i];
}
static void
-argv_multi(struct mdoc *mdoc, int line,
+argv_multi(struct roff_man *mdoc, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
enum margserr ac;
}
static void
-argv_single(struct mdoc *mdoc, int line,
+argv_single(struct roff_man *mdoc, int line,
struct mdoc_argv *v, int *pos, char *buf)
{
enum margserr ac;