/* $Id: mdoc_argv.c,v 1.107 2015/10/17 00:21:07 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
* 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 AUTHORS DISCLAIM ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* 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
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "mandoc_aux.h"
#include "mandoc.h"
#include "roff.h"
#include "mdoc.h"
#include "libmandoc.h"
#include "libmdoc.h"
enum argsflag {
ARGSFL_NONE = 0,
};
enum argvflag {
};
struct mdocarg {
};
char *, enum argsflag, char **);
static int args_checkpunct(const char *, int);
static void argv_multi(struct roff_man *, int,
struct mdoc_argv *, int *, char *);
static void argv_single(struct roff_man *, int,
struct mdoc_argv *, int *, char *);
ARGV_NONE, /* MDOC_Split */
ARGV_NONE, /* MDOC_Nosplit */
ARGV_NONE, /* MDOC_Ragged */
ARGV_NONE, /* MDOC_Unfilled */
ARGV_NONE, /* MDOC_Literal */
ARGV_SINGLE, /* MDOC_File */
ARGV_SINGLE, /* MDOC_Offset */
ARGV_NONE, /* MDOC_Bullet */
ARGV_NONE, /* MDOC_Dash */
ARGV_NONE, /* MDOC_Hyphen */
ARGV_NONE, /* MDOC_Item */
ARGV_NONE, /* MDOC_Enum */
ARGV_NONE, /* MDOC_Tag */
ARGV_NONE, /* MDOC_Diag */
ARGV_NONE, /* MDOC_Hang */
ARGV_NONE, /* MDOC_Ohang */
ARGV_NONE, /* MDOC_Inset */
ARGV_MULTI, /* MDOC_Column */
ARGV_SINGLE, /* MDOC_Width */
ARGV_NONE, /* MDOC_Compact */
ARGV_NONE, /* MDOC_Std */
ARGV_NONE, /* MDOC_Filled */
ARGV_NONE, /* MDOC_Words */
ARGV_NONE, /* MDOC_Emphasis */
ARGV_NONE, /* MDOC_Symbolic */
ARGV_NONE /* MDOC_Symbolic */
};
};
};
};
};
};
};
};
/*
* Parse flags and their arguments from the input line.
* These come in the form -flag [argument ...].
* Some flags take no argument, some one, some multiple.
*/
void
{
char *argname;
char savechar;
/* Which flags does this macro support? */
return;
/* Loop over the flags on the input line. */
/* Seek to the first unescaped space. */
break;
/*
* We want to nil-terminate the word to look it up.
* But we may not have a flag, in which case we need
* to restore the line as-is. So keep around the
* stray byte, which we'll reset upon exiting.
*/
/*
* Now look up the word as a flag. Use temporary
* storage that we'll copy into the node's flags.
*/
break;
/* If it isn't a flag, restore the saved byte. */
if (savechar != '\0')
break;
}
/* Read to the next word (the first argument). */
ipos++;
/* Parse the arguments of the flag. */
case ARGV_SINGLE:
break;
case ARGV_MULTI:
break;
case ARGV_NONE:
break;
}
/* Append to the return values. */
/* Prepare for parsing the next flag. */
}
}
void
{
int i;
if (NULL == p)
return;
if (p->refcnt) {
--(p->refcnt);
if (p->refcnt)
return;
}
for (i = (int)p->argc - 1; i >= 0; i--)
argn_free(p, i);
free(p);
}
static void
{
int j;
}
}
enum margserr
{
struct roff_node *n;
char *v_local;
if (v == NULL)
v = &v_local;
/*
* We know that we're in an `It', so it's reasonable to expect
* us to be sitting in a `Bl'. Someday this may not be the case
* (if we allow random `It's sitting out there), so provide a
* safe fall-back into the default behaviour.
*/
fl = ARGSFL_TABSEP;
break;
}
}
static enum margserr
{
char *p;
int pairs;
}
return ARGS_EOLN;
}
return ARGS_PUNCT;
/*
* Tabs in `It' lines in `Bl -column' can't be escaped.
* Phrases are reparsed for `Ta' and other macros later.
*/
if (fl == ARGSFL_TABSEP) {
/*
* Words right before and right after
* tab characters are not parsed,
* unless there is a blank in between.
*/
if (p[-1] != ' ')
if (p[1] != ' ')
/*
* One or more blanks after a tab cause
* one leading blank in the next column.
* So skip all but one of them.
*/
*pos += (int)(p - *v) + 1;
(*pos)++;
/*
* A tab at the end of an input line
* switches to the next column.
*/
} else {
p = strchr(*v, '\0');
if (p[-1] == ' ')
*pos += (int)(p - *v);
}
/* Skip any trailing blank characters. */
while (p > *v && p[-1] == ' ' &&
(p - 1 == *v || p[-2] != '\\'))
p--;
*p = '\0';
return ARGS_PHRASE;
}
/*
* Process a quoted literal. A quote begins with a double-quote
* and ends with a double-quote NOT preceded by a double-quote.
* NUL-terminate the literal in place.
* Collapse pairs of quotes inside quoted literals.
* Whitespace is NOT involved in literal termination.
*/
pairs = 0;
/* Move following text left after quoted quotes. */
if (pairs)
continue;
/* Unquoted quotes end quoted args. */
break;
/* Quoted quotes collapse. */
pairs++;
(*pos)++;
}
if (pairs)
return ARGS_QWORD;
}
return ARGS_QWORD;
(*pos)++;
return ARGS_QWORD;
}
/*
* After parsing the last word in this phrase,
* tell lookup() whether or not to interpret it.
*/
}
return ARGS_WORD;
}
/*
* Check if the string consists only of space-separated closing
* delimiters. This is a bit of a dance: the first must be a close
* delimiter, but it may be followed by middle delimiters. Arbitrary
* whitespace may separate these tokens.
*/
static int
{
int j;
enum mdelim d;
/* First token must be a close-delimiter. */
if (DELIMSZ == j)
return 0;
dbuf[j] = '\0';
return 0;
while (' ' == buf[i])
i++;
while (buf[i]) {
j = 0;
if (DELIMSZ == j)
return 0;
dbuf[j] = '\0';
d = mdoc_isdelim(dbuf);
if (DELIM_NONE == d || DELIM_OPEN == d)
return 0;
while (' ' == buf[i])
i++;
}
return '\0' == buf[i];
}
static void
{
char *p;
break;
break;
if (v->sz % MULTI_STEP == 0)
v->sz + MULTI_STEP, sizeof(char *));
}
}
static void
{
char *p;
return;
v->sz = 1;
v->value = mandoc_malloc(sizeof(char *));
v->value[0] = mandoc_strdup(p);
}