roff.c revision 698f87a48e2e945bfe5493ce168e0d0ae1cedd5c
/* $Id: roff.c,v 1.189 2013/12/30 18:44:06 schwarze Exp $ */
/*
* Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2010, 2011, 2012, 2013 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.
*/
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include <assert.h>
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "mandoc.h"
#include "libroff.h"
#include "libmandoc.h"
/* Maximum number of nested if-else conditionals. */
#define RSTACK_MAX 128
/* Maximum number of string expansions per line, to break infinite loops. */
#define EXPAND_LIMIT 1000
enum rofft {
};
enum roffrule {
};
/*
* An incredibly-simple string buffer.
*/
struct roffstr {
char *p; /* nil-terminated buffer */
};
/*
* A key-value roffstr pair as part of a singly-linked list.
*/
struct roffkv {
};
/*
* A single number register as part of a singly-linked list.
*/
struct roffreg {
int val;
};
struct roff {
char control; /* control character */
int rstackpos; /* position in rstack */
const char *current_string; /* value of last called user macro */
};
struct roffnode {
int line; /* parse line */
int col; /* parse col */
char *name; /* node name, e.g. macro name */
char *end; /* end-rules: custom token */
int endspan; /* end-rules: next-line or infty */
};
char **bufp, /* input buffer */ \
int ln, /* parse line */ \
int ppos, /* original pos in buffer */ \
int pos, /* current pos in buffer */ \
int *offs /* reset offset of buffer data */
struct roffmac {
const char *name; /* macro name */
int flags;
};
struct predef {
const char *name; /* predefined input name */
const char *str; /* replacement symbol */
};
static void roffhash_init(void);
static void roffnode_cleanscope(struct roff *);
static void roffnode_pop(struct roff *);
const char *, int, int);
static enum roffrule roff_evalcond(const char *, int *);
static void roff_free1(struct roff *);
static void roff_freereg(struct roffreg *);
static void roff_freestr(struct roffkv *);
static char *roff_getname(struct roff *, char **, int, int);
static int roff_getnum(const char *, int *, int *);
static int roff_getop(const char *, int *, char *);
static int roff_getregn(const struct roff *,
const char *, size_t);
static const char *roff_getstrn(const struct roff *,
const char *, size_t);
static void roff_openeqn(struct roff *, const char *,
int, int, const char *);
char **, size_t *, int, int);
static void roff_setstr(struct roff *,
const char *, const char *, int);
static void roff_setstrn(struct roffkv **, const char *,
/* See roffhash_find() */
#define ASCII_HI 126
#define ASCII_LO 33
};
const char *const __mdoc_reserved[] = {
"Ac", "Ad", "An", "Ao", "Ap", "Aq", "Ar", "At",
"Bc", "Bd", "Bf", "Bk", "Bl", "Bo", "Bq",
"Brc", "Bro", "Brq", "Bsx", "Bt", "Bx",
"Cd", "Cm", "Db", "Dc", "Dd", "Dl", "Do", "Dq",
"Ds", "Dt", "Dv", "Dx", "D1",
"Ec", "Ed", "Ef", "Ek", "El", "Em", "em",
"En", "Eo", "Eq", "Er", "Es", "Ev", "Ex",
"Fa", "Fc", "Fd", "Fl", "Fn", "Fo", "Fr", "Ft", "Fx",
"Hf", "Ic", "In", "It", "Lb", "Li", "Lk", "Lp", "LP",
"Me", "Ms", "Mt", "Nd", "Nm", "No", "Ns", "Nx",
"Oc", "Oo", "Op", "Os", "Ot", "Ox",
"Pa", "Pc", "Pf", "Po", "Pp", "PP", "pp", "Pq",
"Qc", "Ql", "Qo", "Qq", "Or", "Rd", "Re", "Rs", "Rv",
"Sc", "Sf", "Sh", "SH", "Sm", "So", "Sq",
"Ss", "St", "Sx", "Sy",
"Ta", "Tn", "Ud", "Ux", "Va", "Vt", "Xc", "Xo", "Xr",
"%A", "%B", "%D", "%I", "%J", "%N", "%O",
"%P", "%Q", "%R", "%T", "%U", "%V",
};
const char *const __man_reserved[] = {
"AT", "B", "BI", "BR", "BT", "DE", "DS", "DT",
"EE", "EN", "EQ", "EX", "HF", "HP", "I", "IB", "IP", "IR",
"LP", "ME", "MT", "OP", "P", "PD", "PP", "PT",
"R", "RB", "RE", "RI", "RS", "SB", "SH", "SM", "SS", "SY",
"TE", "TH", "TP", "TQ", "TS", "T&", "UC", "UE", "UR", "YS",
};
/* Array of injected predefined strings. */
#define PREDEFS_MAX 38
#include "predefs.in"
};
/* See roffhash_find() */
static int roffit_lines; /* number of lines to delay */
static char *roffit_macro; /* nil-terminated macro line */
static void
roffhash_init(void)
{
struct roffmac *n;
int buc, i;
for (i = 0; i < (int)ROFF_USERDEF; i++) {
/* Do nothing. */ ;
} else
}
}
/*
* Look up a roff token by its name. Returns ROFF_MAX if no macro by
* the nil-terminated string name could be found.
*/
static enum rofft
roffhash_find(const char *p, size_t s)
{
int buc;
struct roffmac *n;
/*
* libroff has an extremely simple hashtable, for the time
* being, which simply keys on the first character, which must
* be printable, then walks a chain. It works well enough until
* optimised.
*/
return(ROFF_MAX);
return(ROFF_MAX);
for ( ; n; n = n->next)
return(ROFF_MAX);
}
/*
* Pop the current node off of the stack of roff instructions currently
* pending.
*/
static void
roffnode_pop(struct roff *r)
{
struct roffnode *p;
p = r->last;
free(p);
}
/*
* Push a roff node onto the instruction stack. This must later be
* removed with roffnode_pop().
*/
static void
{
struct roffnode *p;
if (name)
r->last = p;
}
static void
roff_free1(struct roff *r)
{
struct eqn_node *e;
int i;
}
eqn_free(e);
}
while (r->last)
roffnode_pop(r);
roff_freestr(r->strtab);
roff_freestr(r->xmbtab);
roff_freereg(r->regtab);
if (r->xtab)
for (i = 0; i < 128; i++)
}
void
roff_reset(struct roff *r)
{
int i;
roff_free1(r);
r->control = 0;
for (i = 0; i < PREDEFS_MAX; i++)
}
void
{
roff_free1(r);
free(r);
}
struct roff *
{
struct roff *r;
int i;
r->rstackpos = -1;
for (i = 0; i < PREDEFS_MAX; i++)
return(r);
}
/*
* In the current line, expand user-defined strings ("\*")
* and references to number registers ("\n").
* Also check the syntax of other escape sequences.
*/
static enum rofferr
{
const char *stesc; /* start of an escape sequence ('\\') */
const char *stnam; /* start of the name, after "[(*" */
const char *cp; /* end of the name, e.g. before ']' */
const char *res; /* the string to be substituted */
char *nbuf; /* new buffer to copy bufp to */
int expand_count; /* to avoid infinite loops */
expand_count = 0;
/*
* The second character must be an asterisk or an n.
* If it isn't, skip it anyway: It is escaped,
* so it can't start another escape sequence.
*/
if ('\0' == *cp)
return(ROFF_CONT);
switch (*cp) {
case ('*'):
break;
case ('n'):
break;
default:
continue;
(MANDOCERR_BADESCAPE, r->parse,
return(ROFF_CONT);
}
cp++;
/*
* The third character decides the length
* of the name of the string or register.
* Save a pointer to the name.
*/
switch (*cp) {
case ('\0'):
return(ROFF_CONT);
case ('('):
cp++;
maxl = 2;
break;
case ('['):
cp++;
maxl = 0;
break;
default:
maxl = 1;
break;
}
/* Advance to the end of the name. */
if ('\0' == *cp) {
return(ROFF_CONT);
}
break;
}
/*
* Retrieve the replacement string; if it is
* undefined, resume searching for escapes.
*/
else
(MANDOCERR_BADESCAPE, r->parse,
res = "";
}
/* Replace the escape sequence by the string. */
if (EXPAND_LIMIT >= ++expand_count)
goto again;
/* Just leave the string unexpanded. */
return(ROFF_IGN);
}
return(ROFF_CONT);
}
/*
* Process text streams:
* Convert all breakable hyphens into ASCII_HYPH.
* Decrement and spring input line trap.
*/
static enum rofferr
{
const char *start;
char *p;
int isz;
enum mandoc_esc esc;
while ('\0' != *p) {
p += sz;
if ('\0' == *p)
break;
if ('\\' == *p) {
/* Skip over escapes. */
p++;
if (ESCAPE_ERROR == esc)
break;
continue;
} else if (p == start) {
p++;
continue;
}
if (isalpha((unsigned char)p[-1]) &&
isalpha((unsigned char)p[1]))
*p = ASCII_HYPH;
p++;
}
/* Spring the input line trap. */
if (1 == roffit_lines) {
if (-1 == isz) {
exit((int)MANDOCLEVEL_SYSERR);
}
*bufp = p;
*offs = 0;
roffit_lines = 0;
return(ROFF_REPARSE);
} else if (1 < roffit_lines)
--roffit_lines;
return(ROFF_CONT);
}
enum rofferr
{
enum rofft t;
enum rofferr e;
/*
* Run the reserved-word filter only if we have some reserved
* words to fill in.
*/
if (ROFF_IGN == e)
return(e);
/*
* First, if a scope is open and we're not a macro, pass the
* text through the macro's filter. If a scope isn't open and
* we're not a macro, just let it through.
* Finally, if there's an equation scope open, divert it into it
* no matter our state.
*/
if (ROFF_CONT != e)
return(e);
}
if (r->eqn)
if ( ! ctl) {
if (r->tbl)
}
/*
* If a scope is open, go to the child handler for that macro,
* as it may want to preprocess before doing anything with it.
* Don't do so if an equation is open.
*/
if (r->last) {
}
/*
* Lastly, as we've no scope open, try to look up and execute
* the new macro. If no macro is found, simply return and let
* the compilers handle it.
*/
return(ROFF_CONT);
}
void
roff_endparse(struct roff *r)
{
if (r->last)
if (r->eqn) {
}
if (r->tbl) {
}
}
/*
* Parse a roff node's type from the input buffer. This must be in the
* form of ".foo xxx" in the usual way.
*/
static enum rofft
{
const char *mac;
enum rofft t;
return(ROFF_MAX);
/*
* We stop the macro parse at an escape, tab, space, or nil.
* However, `\}' is also a valid macro, so make sure we don't
* clobber it by seeing the `\' as the end of token.
*/
(*pos)++;
return(t);
}
/* ARGSUSED */
static enum rofferr
{
/*
* A block-close `..' should only be invoked as a child of an
* ignore macro, otherwise raise a warning and just ignore it.
*/
return(ROFF_IGN);
}
case (ROFF_am):
/* FALLTHROUGH */
case (ROFF_ami):
/* FALLTHROUGH */
case (ROFF_am1):
/* FALLTHROUGH */
case (ROFF_de):
/* ROFF_de1 is remapped to ROFF_de in roff_block(). */
/* FALLTHROUGH */
case (ROFF_dei):
/* FALLTHROUGH */
case (ROFF_ig):
break;
default:
return(ROFF_IGN);
}
roffnode_pop(r);
return(ROFF_IGN);
}
static void
roffnode_cleanscope(struct roff *r)
{
while (r->last) {
break;
roffnode_pop(r);
}
}
/* ARGSUSED */
static enum rofferr
{
return(ROFF_IGN);
}
case (ROFF_el):
/* FALLTHROUGH */
case (ROFF_ie):
/* FALLTHROUGH */
case (ROFF_if):
break;
default:
return(ROFF_IGN);
}
return(ROFF_IGN);
}
roffnode_pop(r);
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
int sv;
char *name;
return(ROFF_IGN);
}
/*
* Re-write `de1', since we don't really care about
* groff's strange compatibility mode, into `de'.
*/
else
pos++;
}
/*
* At the beginning of a `de' macro, clear the existing string
* with the same name, if there is one. New content will be
* added from roff_block_text() in multiline mode.
*/
return(ROFF_IGN);
/* If present, process the custom end-of-line marker. */
pos++;
/*
* Note: groff does NOT like escape characters in the input.
* Instead of detecting this, we're just going to let it fly and
* to hell with it.
*/
return(ROFF_IGN);
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
enum rofft t;
int i, j;
/*
* First check whether a custom macro exists at this level. If
* it does, then check against it. This is some of groff's
* stranger behaviours. If we encountered a custom end-scope
* tag and that tag also happens to be a "real" macro, then we
* need to try interpreting it again as a real macro. If it's
* not, then return ignore. Else continue.
*/
break;
('\0' == (*bufp)[i] ||
' ' == (*bufp)[i] ||
'\t' == (*bufp)[i])) {
roffnode_pop(r);
i++;
pos = i;
return(ROFF_RERUN);
return(ROFF_IGN);
}
}
/*
* If we have no custom end-query or lookup failed, then try
* pulling it out of the hashtable.
*/
/*
* Macros other than block-end are only significant
* in `de' blocks; elsewhere, simply throw them away.
*/
if (ROFF_cblock != t) {
return(ROFF_IGN);
}
}
/* ARGSUSED */
static enum rofferr
{
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
enum rofft t;
char *ep;
/*
* Fully handle known macros when they are structurally
* required or when the conditional evaluated to true.
*/
if ((ROFF_MAX != t) &&
}
/* Always check for the closing delimiter `\}'. */
if ('}' != *(++ep))
continue;
/*
* If we're at the end of line, then just chop
* off the \} and resize the buffer.
* If we aren't, then convert it to spaces.
*/
*--ep = '\0';
*szp -= 2;
} else
break;
}
}
/* ARGSUSED */
static enum rofferr
{
char *ep;
ep++;
if ('}' != *ep)
continue;
*ep = '&';
}
}
static int
{
int p, n;
p = *pos;
n = v[p] == '-';
if (n)
p++;
if (p == *pos + n)
return 0;
if (n)
*pos = p;
return 1;
}
static int
{
int e;
switch (*res) {
case '=':
break;
case '>':
if (e)
*res = 'g';
break;
case '<':
if (e)
*res = 'l';
break;
default:
return(0);
}
*pos += 1 + e;
return(*res);
}
static enum roffrule
roff_evalcond(const char *v, int *pos)
{
char op;
switch (v[*pos]) {
case ('n'):
(*pos)++;
return(ROFFRULE_ALLOW);
case ('e'):
/* FALLTHROUGH */
case ('o'):
/* FALLTHROUGH */
case ('t'):
(*pos)++;
return(ROFFRULE_DENY);
case ('!'):
(*pos)++;
not = 1;
break;
default:
not = 0;
break;
}
return ROFFRULE_DENY;
if (lh < 0)
lh = 0;
goto out;
}
return ROFFRULE_DENY;
switch (op) {
case 'g':
break;
case 'l':
break;
case '=':
break;
case '>':
break;
case '<':
break;
default:
return ROFFRULE_DENY;
}
out:
if (not)
}
/* ARGSUSED */
static enum rofferr
{
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
/*
* An `.el' has no conditional body: it will consume the value
* of the current rstack entry set in prior `ie' calls or
* defaults to DENY.
*
* If we're not an `el', however, then evaluate the conditional.
*/
(r->rstackpos < 0 ?
/*
* An if-else will put the NEGATION of the current evaluated
* conditional into the stack of rules.
*/
return(ROFF_ERR);
}
}
/* If the parent has false as its rule, then so do we. */
/*
* Determine scope.
* If there is nothing on the line after the conditional,
* not even whitespace, use next-line scope.
*/
goto out;
}
pos++;
/* An opening brace requests multiline scope. */
pos += 2;
goto out;
}
/*
* Anything else following the conditional causes
* single-line scope. Warn if the scope contains
* nothing but trailing whitespace.
*/
out:
return(ROFF_RERUN);
}
/* ARGSUSED */
static enum rofferr
{
/*
* A symbol is named by the first word following the macro
* invocation up to a space. Its value is anything after the
* name's trailing whitespace and optional double-quote. Thus,
*
* [.ds foo "bar " ]
*
* will have `bar " ' as its value.
*/
if ('\0' == *name)
return(ROFF_IGN);
/* Read past initial double-quote. */
if ('"' == *string)
string++;
/* The rest is the value. */
return(ROFF_IGN);
}
void
{
/* Search for an existing register with the same name. */
/* Create a new register. */
}
if ('+' == sign)
else if ('-' == sign)
else
}
int
{
return(0);
}
static int
{
return(0);
}
static void
{
}
}
/* ARGSUSED */
static enum rofferr
{
const char *key;
char *val;
int iv;
char sign;
val++;
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
const char *name;
char *cp;
while ('\0' != *cp) {
if ('\0' != *name)
}
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
char *cp;
int iv;
/* Parse the number of lines. */
return(ROFF_IGN);
}
/* Arm the input line trap. */
roffit_lines = iv;
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
const char *const *cp;
if (MPARSE_MDOC != r->parsetype)
return(ROFF_CONT);
}
/* ARGSUSED */
static enum rofferr
{
const char *const *cp;
if (MPARSE_MDOC != r->parsetype)
return(ROFF_CONT);
}
/* ARGSUSED */
static enum rofferr
{
else
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
else
return(ROFF_IGN);
}
#if 0
static int
roff_closeeqn(struct roff *r)
{
}
#endif
static void
{
struct eqn_node *e;
int poff;
if (r->last_eqn)
else
if (buf) {
poff = 0;
}
}
/* ARGSUSED */
static enum rofferr
{
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
if (r->tbl) {
}
if (r->last_tbl)
else
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
const char *p;
r->control = 0;
if ('\0' != *p)
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
enum mandoc_esc esc;
if ('\0' == *p) {
return(ROFF_IGN);
}
while ('\0' != *p) {
first = p++;
if ('\\' == *first) {
if (ESCAPE_ERROR == esc) {
(MANDOCERR_BADESCAPE, r->parse,
return(ROFF_IGN);
}
}
second = p++;
if ('\\' == *second) {
if (ESCAPE_ERROR == esc) {
(MANDOCERR_BADESCAPE, r->parse,
return(ROFF_IGN);
}
} else if ('\0' == *second) {
second = " ";
p--;
}
if (fsz > 1) {
continue;
}
r->xtab = mandoc_calloc
(128, sizeof(struct roffstr));
}
return(ROFF_IGN);
}
/* ARGSUSED */
static enum rofferr
{
char *name;
/*
* Handle `so'. Be EXTREMELY careful, as we shouldn't be
* opening anything that's not in our cwd or anything beneath
* it. Thus, explicitly disallow traversing up the file-system
* or using absolute paths.
*/
return(ROFF_ERR);
}
return(ROFF_SO);
}
/* ARGSUSED */
static enum rofferr
{
const char *arg[9];
int i;
/*
* Collect pointers to macro argument strings
* and NUL-terminate them.
*/
for (i = 0; i < 9; i++)
/*
* Expand macro arguments.
*/
*szp = 0;
if (0 > i || 8 < i) {
/* Not an argument invocation. */
cp += 2;
continue;
}
}
/*
* Replace the macro invocation
* by the expanded macro.
*/
if (0 == *szp)
}
static char *
{
if ('\0' == *name)
return(name);
/* Read until end of name. */
if ('\\' != *cp)
continue;
cp++;
if ('\\' == *cp)
continue;
*cp = '\0';
}
/* Nil-terminate name. */
if ('\0' != *cp)
*(cp++) = '\0';
/* Read past spaces. */
while (' ' == *cp)
cp++;
return(name);
}
/*
* Store *string into the user-defined string called *name.
* In multiline mode, append to an existing entry and append '\n';
* else replace the existing entry, if there is one.
* To clear an existing entry, call with (*r, *name, NULL, 0).
*/
static void
int multiline)
{
}
static void
{
struct roffkv *n;
char *c;
int i;
/* Search for an existing string with the same name. */
n = *r;
n = n->next;
if (NULL == n) {
/* Create a new string table entry. */
n = mandoc_malloc(sizeof(struct roffkv));
n->next = *r;
*r = n;
} else if (0 == multiline) {
/* In multiline mode, append; else replace. */
}
return;
/*
* One additional byte for the '\n' in multiline mode,
* and one for the terminating '\0'.
*/
*n->val.p = '\0';
oldch = 0;
} else {
}
/* Skip existing content in the destination buffer. */
/* Append new content to the destination buffer. */
i = 0;
while (i < (int)stringsz) {
/*
* Rudimentary roff copy mode:
* Handle escaped backslashes.
*/
i++;
*c++ = string[i++];
}
/* Append terminating bytes. */
if (multiline)
*c++ = '\n';
*c = '\0';
}
static const char *
{
const struct roffkv *n;
return(n->val.p);
return(NULL);
}
static void
roff_freestr(struct roffkv *r)
{
for (n = r; n; n = nn) {
free(n);
}
}
const struct tbl_span *
{
}
const struct eqn *
{
}
/*
* Duplicate an input string, making the appropriate character
* conversations (as stipulated by `tr') along the way.
* Returns a heap-allocated string with all the replacements made.
*/
char *
roff_strdup(const struct roff *r, const char *p)
{
char *res;
const char *pp;
enum mandoc_esc esc;
return(mandoc_strdup(p));
else if ('\0' == *p)
return(mandoc_strdup(""));
/*
* Step through each character looking for term matches
* (remember that a `tr' can be invoked with an escape, which is
* a glyph but the escape is multi-character).
* We only do this if the character hash has been initialised
* and the string is >0 length.
*/
ssz = 0;
while ('\0' != *p) {
p++;
continue;
} else if ('\\' != *p) {
continue;
}
/* Search for term matches. */
break;
/*
* A match has been found.
* Append the match to the array and move
* forward by its keysize.
*/
continue;
}
/*
* Handle escapes carefully: we need to copy
* over just the escape itself, or else we might
* do replacements within the escape itself.
* Make sure to pass along the bogus string.
*/
pp = p++;
if (ESCAPE_ERROR == esc) {
break;
}
/*
* We bail out on bad escapes.
* No need to warn: we already did so when
* roff_res() was called.
*/
}
return(res);
}
/*
* Find out whether a line is a macro line or not.
* If it is, adjust the current position and return one; if it isn't,
* return zero and don't change the current position.
* If the control character has been set with `.cc', then let that grain
* precedence.
* This is slighly contrary to groff, where using the non-breaking
* control character when `cc' has been invoked will cause the
* non-breaking macro contents to be printed verbatim.
*/
int
{
int pos;
pos++;
else if (0 != r->control)
return(0);
pos += 2;
pos++;
else
return(0);
pos++;
return(1);
}