/*
* Compare a row of tokens, ignoring the content of WS; return !=0 if different
*/
int
comparetokens(Tokenrow *tr1, Tokenrow *tr2)
{
Token *tp1, *tp2;
/*
* replace ntok tokens starting at dtr->tp with the contents of str.
* tp ends up pointing just beyond the replacement.
* Canonical whitespace is assured on each side.
*/
void
insertrow(Tokenrow *dtr, int ntok, Tokenrow *str)
{
int nrtok = rowlen(str);
/*
* Copy an entire tokenrow into another, at tp.
* It is assumed that there is enough space.
* Not strictly conforming.
*/
void
movetokenrow(Tokenrow *dtr, Tokenrow *str)
{
int nby;
/*
* Move the tokens in a row, starting at tr->tp, rightward by nt tokens;
* nt may be negative (left move).
* The row may need to be grown.
* Non-strictly conforming because of the (char *), but easily fixed
*/
void
adjustrow(Tokenrow *trp, int nt)
{
int nby, size;
/*
* Copy a row of tokens into the destination holder, allocating
* the space for the contents. Return the destination.
*/
Tokenrow *
copytokenrow(Tokenrow *dtr, Tokenrow *str)
{
int len = rowlen(str);
/*
* Produce a copy of a row of tokens. Start at trp->tp.
* The value strings are copied as well. The first token
* has WS available.
*/
Tokenrow *
normtokenrow(Tokenrow *trp)
{
Token *tp;
Tokenrow *ntrp = new(Tokenrow);
int len;
len = trp->lp - trp->tp;
if (len<=0)
len = 1;
maketokenrow(len, ntrp);
for (tp=trp->tp; tp < trp->lp; tp++) {
*ntrp->lp = *tp;
if (tp->len) {
ntrp->lp->t = newstring(tp->t, tp->len, 1);
*ntrp->lp->t++ = ' ';
if (tp->wslen)
ntrp->lp->wslen = 1;
}
ntrp->lp++;
}
if (ntrp->lp > ntrp->bp)
ntrp->bp->wslen = 0;
return ntrp;
}
/*
* turn a row into just a newline
*/
void
setempty(Tokenrow *trp)
{
trp->tp = trp->bp;
trp->lp = trp->bp+1;
*trp->bp = nltoken;
}
/*
* generate a number
*/
char *
outnum(char *p, int n)
{
if (n>=10)
p = outnum(p, n/10);
*p++ = n%10 + '0';
return p;
}
/*
* allocate and initialize a new string from s, of length l, at offset o
* Null terminated.
*/
uchar *
newstring(uchar *s, int l, int o)
{
uchar *ns = (uchar *)domalloc(l+o+1);