?? preamble.c
字號:
/* PRECC library * *This file contains functions which precc requires to build ITSELF and *cannot be generated from the precc code in precc*.y (except as drop *through inclusions). * *These routines should not be required for other compilations *(the cc.c routines in the kernel suffice). * */# include "preamble.h"# undef UNSETNAME/* startup functions */void usage(int n){ switch (n){ case 1: fprintf(stderr,"mixed swiches and files\n"); break; case 2: fprintf(stderr,"error opening %s for writing\n",p_outfile); break; case 3: fprintf(stderr,"unknown option\n"); break; case 4: fprintf(stderr,"bad numerical option\n"); break; case 5: fprintf(stderr,"error opening %s for reading\n",p_infile); break; } fprintf(stderr,"usage %s [options] [infile [outfile]]\n",p_argv[0]); fprintf(stderr,"options : -r<read buffer size in kb> (%d)\n", (int)(precc_data.readbuffersize*(sizeof (TOKEN) + sizeof (VALUE))/1024)); fprintf(stderr," -p<program buffer size in kb> (%d)\n", (int)(precc_data.maxprogramsize*sizeof(VALUE)/1024)); fprintf(stderr," -v<attribute buffer size in kb> (%d)\n", (int)(precc_data.stacksize*sizeof(STACKVALUE)/1024)); fprintf(stderr," -f<context buffer size in kb> (%d)\n", (int)(precc_data.contextstacksize*sizeof(FRAME)/1024)); fprintf(stderr," -old (not set)\n"); p_exit (n);}int getkintarg(char *s,int *t,size_t n)/* read a number in kbytes and translate it to calloc units */{ if (1 != sscanf(s,"%u",t)) usage(4); *t *= 1000; /* kbytes */ *t /= n; /* the unit size */ return 0;}/* agents are buffers, safe places to put characters to be able to refer back to them later. One can Concatenate a word to a buffer and close off the slot: nputagent(A,word);getagent(A,&place) Concatenate a char to a buffer and close off the slot: putagent(A,char);getagent(A,&place) Initialize the buffer: initagent(A,buffer) Reset the buffer, old data is now unsafe: resetagent(A)*/CHAR cbuff[CBUFFSIZE]; /* read buffer*/AGENT chars = {cbuff,cbuff,cbuff}; /* read agent */CHAR nbuff[NBUFFSIZE]; /* name buffer*/AGENT namE = {nbuff,nbuff,nbuff}; /* name agent */static CHAR abuff[NBUFFSIZE]; /* args buffer*/AGENT args = {abuff,abuff,abuff}; /* args agent */static CHAR kbuff[NBUFFSIZE]; /* keys buffer*/AGENT keys = {kbuff,kbuff,kbuff}; /* keys agent */static CHAR mbuff[NBUFFSIZE]; /* keys buffer*/AGENT meta = {mbuff,mbuff,mbuff}; /* meta agent */void resetall (){ CHARS resetagent(); resetagent(&chars); resetagent(&namE); resetagent(&args); resetagent(&meta); resetagent(&keys);}/* methods on agents */VOID initagent(AGENT *x,CHARS y){x->buffer=y;x->in=y;x->out=y;*y=0;}CHARS putagent(AGENT *x,char y){*x->in++=y; /* move the in pointer on one place */*x->in=0;return(x->in-1);}CHARS nputagent(AGENT *x,CHARS y){*(x->in= p_scpy(x->in,y))=0;return(x->out); /* the current out-pointer is returned */} /* which points to the start of the current word */CHARS getagent(AGENT *x,CHARS *y){*x->in++=0; /* finish the current in word */*y=x->out; /* report the out pointer */*x->in=0; /* zero next word */return(x->out=x->in); /* set the out pointer to next incoming word */}CHARS resetagent(AGENT *x){*x->buffer=0; /* zero first word */return(x->out=x->in=x->buffer);}/* in particular */CHARS myputchar(char c){return(putagent(&chars,c));}CHARS getname(CHARS *x){return(getagent(&chars,x));}CHARS putname(CHARS x){return(nputagent(&chars,(x)));}CHARS putint(int x){static char shortbuf[32];sprintf(shortbuf,"%d",x);return(putname(shortbuf));}CHARS putargs(CHARS x){return(nputagent(&args,x));}CHARS getargs(CHARS *x){return(getagent(&args,x));}CHARS putmeta(CHARS x){return(nputagent(&meta,x));}CHARS getmeta(CHARS *x){return(getagent(&meta,x));}CHARS putkeys(CHARS x){return(nputagent(&keys,x));}CHARS getkeys(CHARS *x){return(getagent(&keys,x));}/* end of methods on agents */# include <ctype.h> /* these are here to do char-int argument conversions */BOOLEAN p_isalpha(c)char c;{ return(isalpha((int)c) || (c=='_'));} BOOLEAN p_isdigit(c)char c;{ return(isdigit((int)c));}BOOLEAN p_isspace(c)char c;{ return((c==' ') || (c== *"\t"));}BOOLEAN p_isalnum(c)char c;{ return(isalnum((int)c) || (c=='_'));} /* this returns the address of the LAST char copied */ char *p_scpy(char *x,char *y){ while((*x++ = *y++) != 0); return(&x[-1]);}int yytchar;int yylen;CHARS yylloc; /* this is the address of the LAST token * I returned from the readahead buffer, if it's not NULL, * which means the buffer is empty. */int yylineno;/* I need to supply this for precc */VALUE yylval; /* ditto */ int yylex()/* * Read ahead lines into yybuffer until EOL, * but ignore escaped End-Of-Lines (either escaped by * trailing `\' or by `@' at beginning of next line after this line began * with one. * * Dole out characters one at a time. * * Return 0!=TOKEN for a good read and 0=FAILURE when an EOF is encountered. */{ int n; CHARS buff = yybuffer; static int atsignalled, linecount; static char c; extern int yytchar; extern int yylen; static int nbuff; /* gets returns nonzero EITHER if given ^^Z OR on the next call after a ^foo^Z - which is all OK for nonzero=EOF */ if(NULL!=yylloc) { if (nbuff>0) {/* we can use a token we read ahead for */ yylen=1; nbuff--; return(yytchar=(int)(yylval=(VALUE)(int) *++yylloc)); } /* otherwise we ask for more TOKENS next time and return the EOL (0) now and it'll be used to terminate a string. */ yylloc=NULL; yylen=0; nbuff=0; return (yytchar=(int)(yylval=(VALUE)0)); } /*if(NULL==yylloc){*/ /* we have to load the readahead buff */ yylloc=buff-1; /* we will return a token at *buff ... */ *buff=yytchar=0; /* ... but we start clean */ nbuff=0; /* length of readahead buffer */ atsignalled=0; /* we're not in an @ sequence yet */ linecount=0; /* we've read no sequence of lines yet */ /* and carry on */ /* we're here because the readahead buffer was empty and so the initialization conditions hold: yylloc=buff-1, etc. */ while (gets((char*)buff)!=NULL) { yylineno++; linecount++; n = (int)strlen((char*)buff); /* count the booty */ nbuff+=n; /* keep count of the buffer contents */ if (n==0) { /* we got a linefeed only and it's time to start * feeding out stuff from the buffer */ if (nbuff>0){ yylen=1; nbuff--; return(yytchar=(int)(yylval=(VALUE)(int) *++yylloc)); } /* here we've got no tokens, now or before */ yylen=0; yylloc=NULL; /* signal to read ahead again next time round */ return (yytchar=(int)(yylval=(VALUE)0)); /* return the 0 string * terminator */ } /* we're here with nbuff>0 already, and with n>0 */ /* check to see if this is an @ seq start */ if ((linecount==1) && (*buff=='@'))
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -