home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / program / c / c68k_src / preproc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-12-10  |  2.5 KB  |  86 lines

  1. #include        <stdio.h>
  2. #include        "c.h"
  3. #include        "expr.h"
  4. #include        "gen.h"
  5. #include        "cglbdec.h"
  6.  
  7. /*
  8.  *    68000 C compiler
  9.  *
  10.  *    Copyright 1984, 1985, 1986 Matthew Brandt.
  11.  *  all commercial rights reserved.
  12.  *
  13.  *    This compiler is intended as an instructive tool for personal use. Any
  14.  *    use for profit without the written consent of the author is prohibited.
  15.  *
  16.  *    This compiler may be distributed freely for non-commercial use as long
  17.  *    as this notice stays intact. Please forward any enhancements or question
  18. s
  19.  *    to:
  20.  *
  21.  *        Matthew Brandt
  22.  *        Box 920337
  23.  *        Norcross, Ga 30092
  24.  */
  25.  
  26. FILE            *inclfile[10];
  27. int             incldepth = 0;
  28. int             inclline[10];
  29. char            *lptr;
  30.  
  31. preprocess()
  32. {       ++lptr;
  33.         lastch = ' ';
  34.         getsym();               /* get first word on line */
  35.         if( lastst != id ) {
  36.                 error(ERR_PREPROC);
  37.                 return getline(incldepth == 0);
  38.                 }
  39.         if( strcmp(lastid,"include") == 0 )
  40.                 return doinclude();
  41.         else if( strcmp(lastid,"define") == 0 )
  42.                 return dodefine();
  43.         else    {
  44.                 error(ERR_PREPROC);
  45.                 return getline(incldepth == 0);
  46.                 }
  47. }
  48.  
  49. doinclude()
  50. {       int     rv;
  51.         getsym();               /* get file to include */
  52.         if( lastst != sconst ) {
  53.                 error(ERR_INCLFILE);
  54.                 return getline(incldepth == 0);
  55.                 }
  56.         inclline[incldepth] = lineno;
  57.         inclfile[incldepth++] = input;  /* push current input file */
  58.         input = fopen(laststr,"r");
  59.         if( input == 0 ) {
  60.                 input = inclfile[--incldepth];
  61.                 error(ERR_CANTOPEN);
  62.                 rv = getline(incldepth == 0);
  63.                 }
  64.         else    {
  65.                 rv = getline(incldepth == 1);
  66.                 lineno = -32768;        /* dont list include files */
  67.                 }
  68.         return rv;
  69. }
  70.  
  71. dodefine()
  72. {       SYM     *sp;
  73.         getsym();               /* get past #define */
  74.         if( lastst != id ) {
  75.                 error(ERR_DEFINE);
  76.                 return getline(incldepth == 0);
  77.                 }
  78.         ++global_flag;          /* always do #define as globals */
  79.         sp = xalloc(sizeof(SYM));
  80.         sp->name = litlate(lastid);
  81.         sp->value.s = litlate(lptr);
  82.         insert(sp,&defsyms);
  83.         --global_flag;
  84.         return getline(incldepth == 0);
  85. }
  86.