Main Page | Class Hierarchy | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

tokens.c File Reference

#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "cpp.h"

Include dependency graph for tokens.c:

Include dependency graph

Go to the source code of this file.

Functions

void adjustrow (Tokenrow *trp, int nt)
int comparetokens (Tokenrow *tr1, Tokenrow *tr2)
Tokenrowcopytokenrow (Tokenrow *dtr, Tokenrow *str)
void flushout (void)
Tokengrowtokenrow (Tokenrow *trp)
void insertrow (Tokenrow *dtr, int ntok, Tokenrow *str)
void makespace (Tokenrow *trp)
void maketokenrow (int size, Tokenrow *trp)
void movetokenrow (Tokenrow *dtr, Tokenrow *str)
ucharnewstring (uchar *s, int l, int o)
Tokenrownormtokenrow (Tokenrow *trp)
char * outnum (char *p, int n)
void peektokens (Tokenrow *trp, char *str)
void puttokens (Tokenrow *trp)
void setempty (Tokenrow *trp)

Variables

char * wbp = wbuf
char wbuf [2 *OBS]
const char wstab []


Function Documentation

void adjustrow Tokenrow trp,
int  nt
 

Definition at line 195 of file tokens.c.

References tokenrow::bp, growtokenrow(), tokenrow::lp, tokenrow::max, memmove(), Tokenrow, and tokenrow::tp.

Referenced by gatherargs(), and insertrow().

00196 {
00197     int nby, size;
00198 
00199     if (nt==0)
00200         return;
00201     size = (trp->lp - trp->bp) + nt;
00202     while (size > trp->max)
00203         growtokenrow(trp);
00204     /* nby = sizeof(Token) * (trp->lp - trp->tp); */
00205     nby = (char *)trp->lp - (char *)trp->tp;
00206     if (nby)
00207         memmove(trp->tp+nt, trp->tp, nby);
00208     trp->lp += nt;
00209 }

Here is the call graph for this function:

int comparetokens Tokenrow tr1,
Tokenrow tr2
 

Definition at line 107 of file tokens.c.

References token::len, tokenrow::lp, strncmp(), token::t, Token, Tokenrow, tokenrow::tp, token::type, and token::wslen.

Referenced by dodefine().

00108 {
00109     Token *tp1, *tp2;
00110 
00111     tp1 = tr1->tp;
00112     tp2 = tr2->tp;
00113     if (tr1->lp-tp1 != tr2->lp-tp2)
00114         return 1;
00115     for (; tp1<tr1->lp ; tp1++, tp2++) {
00116         if (tp1->type != tp2->type
00117          || (tp1->wslen==0) != (tp2->wslen==0)
00118          || tp1->len != tp2->len
00119          || strncmp((char*)tp1->t, (char*)tp2->t, tp1->len)!=0)
00120             return 1;
00121     }
00122     return 0;
00123 }

Here is the call graph for this function:

Tokenrow* copytokenrow Tokenrow dtr,
Tokenrow str
 

Definition at line 216 of file tokens.c.

References tokenrow::lp, maketokenrow(), movetokenrow(), rowlen, and Tokenrow.

Referenced by expand(), and substargs().

00217 {
00218     int len = rowlen(str);
00219 
00220     maketokenrow(len, dtr);
00221     movetokenrow(dtr, str);
00222     dtr->lp += len;
00223     return dtr;
00224 }

Here is the call graph for this function:

void flushout void   ) 
 

Definition at line 328 of file tokens.c.

References wbp, wbuf, and write().

Referenced by main(), peektokens(), and puttokens().

00329 {
00330     if (wbp>wbuf) {
00331         write(1, wbuf, wbp-wbuf);
00332         wbp = wbuf;
00333     }
00334 }

Here is the call graph for this function:

Token* growtokenrow Tokenrow trp  ) 
 

Definition at line 89 of file tokens.c.

References tokenrow::bp, error(), FATAL, tokenrow::lp, tokenrow::max, realloc(), Token, Tokenrow, and tokenrow::tp.

Referenced by adjustrow(), dodefine(), and gettokens().

00090 {
00091     int ncur = trp->tp - trp->bp;
00092     int nlast = trp->lp - trp->bp;
00093 
00094     trp->max = 3*trp->max/2 + 1;
00095     trp->bp = (Token *)realloc(trp->bp, trp->max*sizeof(Token));
00096     if (trp->bp == NULL)
00097         error(FATAL, "Out of memory from realloc");
00098     trp->lp = &trp->bp[nlast];
00099     trp->tp = &trp->bp[ncur];
00100     return trp->lp;
00101 }

Here is the call graph for this function:

void insertrow Tokenrow dtr,
int  ntok,
Tokenrow str
 

Definition at line 131 of file tokens.c.

References adjustrow(), makespace(), movetokenrow(), rowlen, Tokenrow, and tokenrow::tp.

Referenced by doconcat(), expand(), and substargs().

00132 {
00133     int nrtok = rowlen(str);
00134 
00135     dtr->tp += ntok;
00136     adjustrow(dtr, nrtok-ntok);
00137     dtr->tp -= ntok;
00138     movetokenrow(dtr, str);
00139     makespace(dtr);
00140     dtr->tp += nrtok;
00141     makespace(dtr);
00142 }

Here is the call graph for this function:

void makespace Tokenrow trp  ) 
 

Definition at line 148 of file tokens.c.

References tokenrow::bp, token::flag, token::len, tokenrow::lp, newstring(), token::t, Token, Tokenrow, tokenrow::tp, token::type, uchar, token::wslen, wstab, and XPWS.

Referenced by doconcat(), gatherargs(), and insertrow().

00149 {
00150     uchar *tt;
00151     Token *tp = trp->tp;
00152 
00153     if (tp >= trp->lp)
00154         return;
00155     if (tp->wslen) {
00156         if (tp->flag&XPWS
00157          && (wstab[tp->type] || trp->tp>trp->bp && wstab[(tp-1)->type])) {
00158             tp->wslen = 0;
00159             return;
00160         }
00161         tp->t[-1] = ' ';
00162         return;
00163     }
00164     if (wstab[tp->type] || trp->tp>trp->bp && wstab[(tp-1)->type])
00165         return;
00166     tt = newstring(tp->t, tp->len, 1);
00167     *tt++ = ' ';
00168     tp->t = tt;
00169     tp->wslen = 1;
00170     tp->flag |= XPWS;
00171 }

Here is the call graph for this function:

void maketokenrow int  size,
Tokenrow trp
 

Definition at line 77 of file tokens.c.

References tokenrow::bp, domalloc(), tokenrow::lp, tokenrow::max, Token, Tokenrow, and tokenrow::tp.

Referenced by copytokenrow(), doconcat(), dodefine(), main(), normtokenrow(), and setup().

00078 {
00079     trp->max = size;
00080     if (size>0)
00081         trp->bp = (Token *)domalloc(size*sizeof(Token));
00082     else
00083         trp->bp = NULL;
00084     trp->tp = trp->bp;
00085     trp->lp = trp->bp;
00086 }

Here is the call graph for this function:

void movetokenrow Tokenrow dtr,
Tokenrow str
 

Definition at line 179 of file tokens.c.

References tokenrow::bp, tokenrow::lp, memmove(), Tokenrow, and tokenrow::tp.

Referenced by copytokenrow(), and insertrow().

00180 {
00181     int nby;
00182 
00183     /* nby = sizeof(Token) * (str->lp - str->bp); */
00184     nby = (char *)str->lp - (char *)str->bp;
00185     memmove(dtr->tp, str->bp, nby);
00186 }

Here is the call graph for this function:

uchar* newstring uchar s,
int  l,
int  o
 

Definition at line 364 of file tokens.c.

References domalloc(), l, s, strncpy(), and uchar.

Referenced by control(), doinclude(), lookup(), makespace(), normtokenrow(), setup(), and stringify().

00365 {
00366     uchar *ns = (uchar *)domalloc(l+o+1);
00367 
00368     ns[l+o] = '\0';
00369     return (uchar*)strncpy((char*)ns+o, (char*)s, l) - o;
00370 }

Here is the call graph for this function:

Tokenrow* normtokenrow Tokenrow trp  ) 
 

Definition at line 232 of file tokens.c.

References tokenrow::bp, token::len, tokenrow::lp, maketokenrow(), newstring(), token::t, Token, Tokenrow, tokenrow::tp, and token::wslen.

Referenced by doadefine(), dodefine(), and gatherargs().

00233 {
00234     Token *tp;
00235     Tokenrow *ntrp = new(Tokenrow);
00236     int len;
00237 
00238     len = trp->lp - trp->tp;
00239     if (len<=0)
00240         len = 1;
00241     maketokenrow(len, ntrp);
00242     for (tp=trp->tp; tp < trp->lp; tp++) {
00243         *ntrp->lp = *tp;
00244         if (tp->len) {
00245             ntrp->lp->t = newstring(tp->t, tp->len, 1);
00246             *ntrp->lp->t++ = ' ';
00247             if (tp->wslen)
00248                 ntrp->lp->wslen = 1;
00249         }
00250         ntrp->lp++;
00251     }
00252     if (ntrp->lp > ntrp->bp)
00253         ntrp->bp->wslen = 0;
00254     return ntrp;
00255 }

Here is the call graph for this function:

char* outnum char *  p,
int  n
 

Definition at line 351 of file tokens.c.

References n, and p.

Referenced by builtin(), and genline().

00352 {
00353     if (n>=10)
00354         p = outnum(p, n/10);
00355     *p++ = n%10 + '0';
00356     return p;
00357 }

void peektokens Tokenrow trp,
char *  str
 

Definition at line 261 of file tokens.c.

References tokenrow::bp, c, fflush(), flushout(), fprintf(), token::hideset, token::len, tokenrow::lp, prhideset(), stderr, token::t, Token, Tokenrow, tokenrow::tp, and token::type.

Referenced by puttokens().

00262 {
00263     Token *tp;
00264 
00265     tp = trp->tp;
00266     flushout();
00267     if (str)
00268         fprintf(stderr, "%s ", str);
00269     if (tp<trp->bp || tp>trp->lp)
00270         fprintf(stderr, "(tp offset %d) ", tp-trp->bp);
00271     for (tp=trp->bp; tp<trp->lp && tp<trp->bp+32; tp++) {
00272         if (tp->type!=NL) {
00273             int c = tp->t[tp->len];
00274             tp->t[tp->len] = 0;
00275             fprintf(stderr, "%s", tp->t);
00276             tp->t[tp->len] = c;
00277         }
00278         if (tp->type==NAME) {
00279             fprintf(stderr, tp==trp->tp?"{*":"{");
00280             prhideset(tp->hideset);
00281             fprintf(stderr, "} ");
00282         } else
00283             fprintf(stderr, tp==trp->tp?"{%x*} ":"{%x} ", tp->type);
00284     }
00285     fprintf(stderr, "\n");
00286     fflush(stderr);
00287 }

Here is the call graph for this function:

void puttokens Tokenrow trp  ) 
 

Definition at line 290 of file tokens.c.

References tokenrow::bp, cursource, source::fd, flushout(), token::len, tokenrow::lp, memcpy(), OBS, p, peektokens(), token::t, Token, Tokenrow, tokenrow::tp, uchar, wbp, wbuf, write(), and token::wslen.

Referenced by genline(), and process().

00291 {
00292     Token *tp;
00293     int len;
00294     uchar *p;
00295 
00296     if (verbose)
00297         peektokens(trp, "");
00298     tp = trp->bp;
00299     for (; tp<trp->lp; tp++) {
00300         len = tp->len+tp->wslen;
00301         p = tp->t-tp->wslen;
00302         while (tp<trp->lp-1 && p+len == (tp+1)->t - (tp+1)->wslen) {
00303             tp++;
00304             len += tp->wslen+tp->len;
00305         }
00306         if (len>OBS/2) {        /* handle giant token */
00307             if (wbp > wbuf)
00308                 write(1, wbuf, wbp-wbuf);
00309             write(1, (char *)p, len);
00310             wbp = wbuf;
00311         } else {    
00312             memcpy(wbp, p, len);
00313             wbp += len;
00314         }
00315         if (wbp >= &wbuf[OBS]) {
00316             write(1, wbuf, OBS);
00317             if (wbp > &wbuf[OBS])
00318                 memcpy(wbuf, wbuf+OBS, wbp - &wbuf[OBS]);
00319             wbp -= OBS;
00320         }
00321     }
00322     trp->tp = tp;
00323     if (cursource->fd==0)
00324         flushout();
00325 }

Here is the call graph for this function:

void setempty Tokenrow trp  ) 
 

Definition at line 340 of file tokens.c.

References tokenrow::bp, tokenrow::lp, Tokenrow, and tokenrow::tp.

Referenced by control(), and process().

00341 {
00342     trp->tp = trp->bp;
00343     trp->lp = trp->bp+1;
00344     *trp->bp = nltoken;
00345 }


Variable Documentation

char* wbp = wbuf [static]
 

Definition at line 7 of file tokens.c.

Referenced by flushout(), and puttokens().

char wbuf[2 *OBS] [static]
 

Definition at line 6 of file tokens.c.

Referenced by flushout(), and puttokens().

const char wstab[] [static]
 

Initial value:

 {
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    1,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    1,  
    1,  
    1,  
    1,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    1,  
    0,  
    1,  
    1,  
    1,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
    0,  
}

Definition at line 13 of file tokens.c.

Referenced by makespace().


Generated on Thu Aug 25 15:47:55 2005 for Quake III Arena by  doxygen 1.3.9.1