-/* $Id: man_macro.c,v 1.56 2011/03/17 11:56:17 kristaps Exp $ */
+/* $Id: man_macro.c,v 1.62 2011/04/19 16:38:48 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
*
#include <stdlib.h>
#include <string.h>
+#include "man.h"
#include "mandoc.h"
+#include "libmandoc.h"
#include "libman.h"
enum rew {
static int blk_exp(MACRO_PROT_ARGS);
static int blk_imp(MACRO_PROT_ARGS);
static int in_line_eoln(MACRO_PROT_ARGS);
+static int man_args(struct man *, int,
+ int *, char *, char **);
static int rew_scope(enum man_type,
struct man *, enum mant);
int
blk_exp(MACRO_PROT_ARGS)
{
- int w, la;
+ int la;
char *p;
/*
for (;;) {
la = *pos;
- w = man_args(m, line, pos, buf, &p);
-
- if (-1 == w)
- return(0);
- if (0 == w)
+ if ( ! man_args(m, line, pos, buf, &p))
break;
-
if ( ! man_word_alloc(m, line, la, p))
return(0);
}
int
blk_imp(MACRO_PROT_ARGS)
{
- int w, la;
+ int la;
char *p;
struct man_node *n;
for (;;) {
la = *pos;
- w = man_args(m, line, pos, buf, &p);
-
- if (-1 == w)
- return(0);
- if (0 == w)
+ if ( ! man_args(m, line, pos, buf, &p))
break;
-
if ( ! man_word_alloc(m, line, la, p))
return(0);
}
int
in_line_eoln(MACRO_PROT_ARGS)
{
- int w, la;
+ int la;
char *p;
struct man_node *n;
for (;;) {
la = *pos;
- w = man_args(m, line, pos, buf, &p);
-
- if (-1 == w)
- return(0);
- if (0 == w)
+ if ( ! man_args(m, line, pos, buf, &p))
break;
if ( ! man_word_alloc(m, line, la, p))
return(0);
return(man_unscope(m, m->first, MANDOCERR_SCOPEEXIT));
}
+static int
+man_args(struct man *m, int line, int *pos, char *buf, char **v)
+{
+ char *start;
+
+ assert(*pos);
+ *v = start = buf + *pos;
+ assert(' ' != *start);
+
+ if ('\0' == *start)
+ return(0);
+
+ *v = mandoc_getarg(m->parse, v, line, pos);
+ return(1);
+}