⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cpp1.c

📁 类PASCAL语言的编译器,LINUX环境的,我没试过是否正确.
💻 C
📖 第 1 页 / 共 2 页
字号:
#ifdef RCSstatic char rcsid[]="$Id: cpp1.c,v 1.8 1994/06/02 09:10:34 start Exp $";#endif/****************************************************************************** *                               FREXXWARE * ---------------------------------------------------------------------------- * * Project: Frexx C Preprocessor * $Source: /home/user/start/cpp/RCS/cpp1.c,v $ * $Revision: 1.8 $ * $Date: 1994/06/02 09:10:34 $ * $Author: start $ * $State: Exp $ * $Locker:  $ * * ---------------------------------------------------------------------------- * $Log: cpp1.c,v $ * Revision 1.8  1994/06/02  09:10:34  start * Made the function definition prinout to be more verbose * * Revision 1.7  1994/06/02  08:48:55  start * Made the initial function routine work * Added initial function exclusion list * Added function names output * * Revision 1.6  1994/01/24  09:32:22  start * Fixed the #line-option a bit. * * Revision 1.5  1993/12/06  13:50:39  start * A lot of new stuff (too much to mention) * * Revision 1.5  1993/12/06  13:50:39  start * A lot of new stuff (too much to mention) * * Revision 1.4  1993/12/02  15:10:56  start * Lots of new features. * * Revision 1.3  1993/11/29  14:00:32  start * new * * Revision 1.2  1993/11/11  07:16:39  start * New stuff * * Revision 1.1  1993/11/03  09:13:08  start * Initial revision * * *****************************************************************************//* * CPP main program. * * Edit history * 21-May-84    MM      "Field test" release * 23-May-84    MM      Some minor hacks. * 30-May-84    ARF     Didn't get enough memory for __DATE__ *                      Added code to read stdin if no input *                      files are provided. * 29-Jun-84    MM      Added ARF's suggestions, Unixifying cpp. * 11-Jul-84    MM      "Official" first release (that's what I thought!) * 22-Jul-84    MM/ARF/SCK Fixed line number bugs, added cpp recognition *                      of #line, fixed problems with #include. * 23-Jul-84    MM      More (minor) include hacking, some documentation. *                      Also, redid cpp's #include files * 25-Jul-84    MM      #line filename isn't used for #include searchlist *                      #line format is <number> <optional name> * 25-Jul-84    ARF/MM  Various bugs, mostly serious.  Removed homemade doprint * 01-Aug-84    MM      Fixed recursion bug, remove extra newlines and *                      leading whitespace from cpp output. * 02-Aug-84    MM      Hacked (i.e. optimized) out blank lines and unneeded *                      whitespace in general.  Cleaned up unget()'s. * 03-Aug-84    Keie    Several bug fixes from Ed Keizer, Vrije Universitet. *                      -- corrected arg. count in -D and pre-defined *                      macros.  Also, allow \n inside macro actual parameter *                      lists. * 06-Aug-84    MM      If debugging, dump the preset vector at startup. * 12-Aug-84    MM/SCK  Some small changes from Sam Kendall * 15-Aug-84    Keie/MM cerror, cwarn, etc. take a single string arg. *                      cierror, etc. take a single int. arg. *                      changed LINE_PREFIX slightly so it can be *                      changed in the makefile. * 31-Aug-84    MM      USENET net.sources release. *  7-Sep-84    SCH/ado Lint complaints * 10-Sep-84    Keie    Char's can't be signed in some implementations * 11-Sep-84    ado     Added -C flag, pathological line number fix * 13-Sep-84    ado     Added -E flag (does nothing) and "-" file for stdin. * 14-Sep-84    MM      Allow # 123 as a synonym for #line 123 * 19-Sep-84    MM      scanid always reads to token, make sure #line is *                      written to a new line, even if -C switch given. *                      Also, cpp - - reads stdin, writes stdout. * 03-Oct-84    ado/MM  Several changes to line counting and keepcomments *                      stuff.  Also a rewritten control() hasher -- much *                      simpler and no less "perfect". Note also changes *                      in cpp3.c to fix numeric scanning. * 04-Oct-84    MM      Added recognition of macro formal parameters if *                      they are the only thing in a string, per the *                      draft standard. * 08-Oct-84    MM      One more attack on scannumber * 15-Oct-84    MM/ado  Added -N to disable predefined symbols.  Fixed *                      linecount if COMMENT_INVISIBLE enabled. * 22-Oct-84    MM      Don't evaluate the #if/#ifdef argument if *                      compilation is supressed.  This prevents *                      unnecessary error messages in sequences such as *                          #ifdef FOO          -- undefined *                          #if FOO == 10       -- shouldn't print warning * 25-Oct-84    MM      Fixed bug in false ifdef supression.  On vms, *                      #include <foo> should open foo.h -- this duplicates *                      the behavior of Vax-C * 31-Oct-84    ado/MM  Parametized $ in indentifiers.  Added a better *                      token concatenator and took out the trial *                      concatenation code.  Also improved #ifdef code *                      and cleaned up the macro recursion tester. *  2-Nov-84    MM/ado  Some bug fixes in token concatenation, also *                      a variety of minor (uninteresting) hacks. *  6-Nov-84    MM      Happy Birthday.  Broke into 4 files and added *                      #if sizeof (basic_types) *  9-Nov-84    MM      Added -S* for pointer type sizes * 13-Nov-84    MM      Split cpp1.c, added vms defaulting * 23-Nov-84    MM/ado  -E supresses error exit, added CPP_INCLUDE, *                      fixed strncpy bug. *  3-Dec-84    ado/MM  Added OLD_PREPROCESSOR *  7-Dec-84    MM      Stuff in Nov 12 Draft Standard * 17-Dec-84    george  Fixed problems with recursive macros * 17-Dec-84    MM      Yet another attack on #if's (f/t)level removed. * 07-Jan-85    ado     Init defines before doing command line options *                      so -Uunix works. * 21-Oct-85    RMS     Rename `token' to `tokenbuf'. *                      Allocate it dynamically, with size in `tokenbsize'. * 23-Oct-85    RMS     Do not print message about number of errors. * 14-Mar-85    FNF     Incorporate macro based C debugging package. *                      Port to Commodore AMIGA. * 20-Aug-88    Ois     Changed format of documentation. *    Feb-93    DST Daniel Stenberg. Started enhancing the `cpp' in February 1993: o Allows C++ comments. o Ported to ANSI C and to SAS/C 6.0. o Changed entire indent- and statement- layout previously used! o Changed hash sizing to any-number-hash-size. o Removed every global variable. o Made the cpp startable by creating a taglist and call the cpp. o Made a shared library of it, called FPP: "Frexx PreProcessor" o Changed the amiga version to use realloc(). o Removed all VMS defines. Who wants such? o Changed it from Public Domain to Freeware. o Moved out the include directory assigning to only be a part of   the taglist and _no_ internal at all! o Made `fpp' accept input from a user specified function instead   of always the stdin stream. This makes it possible to preprocess   almost anything. An output routine is also implemented. o I have discovered that this program needs a lot of re-writing   since a amiga shared library can't exit() as this `cpp'   does on a fatal error... I made all necessary changes! Now most functions   leave a return code telling success/failure (*MAJOR* re-writing! :-(). o The original 50-60 gotos in the source codes have been decreased   to only a few. I *HATE* gotos in C programs! o Changed all cwarn(), cerror() cfatal(), ciwarn(), cierror() functions to   the one and all function `cerror()', which will accept a variable number   of arguments to build message from. o Moved all error/warning/fatal texts to domsg(). o All error output can be received in the error function (and have to in the   amiga library version!). o Found out that my test.c caused 53 malloc() but only 25 free()... Inserted   my own Malloc(), Free(), FreeAll() and Realloc() to always remove alloced   memory when finishing the preprocessing (ok, malloc/free does that for us,   but I don't want to use/depend on them). o Compiling into a shared library under AmigaDos still needs some changes.   fopen() and other similar function in SAS/C use symbols I don't want it   to... eg. _ProgramName and _XCEXIT! */#include <stdio.h>#include <ctype.h>#include "cppdef.h"#include "cpp.h"#if defined(AMIGA)#include        <dos.h>#if defined(SHARED)int _OSERR=0;char *_ProgramName="junk";void __stdargs _XCEXIT(long a) { return; }#endif#endifFILE_LOCAL ReturnCode output(struct Global *, int); /* Output one character */FILE_LOCAL void sharp(struct Global *);INLINE FILE_LOCAL ReturnCode cppmain(struct Global *);int PREFIX fppPreProcess(REG(a0) struct fppTag *tags){  int i=0;  ReturnCode ret;       /* cpp return code */  struct Global *global;  global=(struct Global *)Malloc(sizeof(struct Global));  if(!global)    return(FPP_OUT_OF_MEMORY);  memset(global, 0, sizeof(struct Global));  global->infile=NULL;  global->line=0;  global->wrongline=0;  global->errors=0;  global->recursion=0;  global->rec_recover=TRUE;  global->instring=FALSE;  global->inmacro=FALSE;  global->workp=NULL;  global->keepcomments = FALSE;  /* Write out comments flag     */  global->cflag = FALSE;          /* -C option (keep comments)    */  global->eflag = FALSE;          /* -E option (never fail)       */  global->nflag = 0;              /* -N option (no predefines)    */  global->wflag = FALSE;          /* -W option (write #defines)   */  global->ifstack[0]=TRUE;       /* #if information     */  global->ifptr = global->ifstack;  global->incend = global->incdir;  /* names defined at cpp start */  global->preset[0]="frexxcpp"; /* This is the Frexx cpp program */#if defined( amiga )  global->preset[1]="amiga";  global->preset[2]="m68000";  global->preset[3]="amigados";  global->preset[4]= NULL;              /* Must be last         */#elif defined( unix )  global->preset[1]="unix";  global->preset[2]= NULL;#endif  /* Note: order is important   */  global->magic[0] = "__LINE__";  global->magic[1] = "__FILE__";  global->magic[2] = "__FUNCTION__";  global->magic[3] = "__FUNC_LINE__";  global->magic[4] = NULL;                        /* Must be last       */  global->funcline = 0;  global->cplusplus=1;  global->sharpfilename=NULL;  global->parmp=NULL;  global->nargs=0;  global->macro=NULL;  global->evalue=0;  global->input=NULL;  global->output=NULL;  global->error=NULL;  global->first_file=NULL;  global->userdata=NULL;  global->linelines=TRUE;  global->warnillegalcpp = FALSE;  global->outputLINE = TRUE;  global->warnnoinclude = TRUE;  global->showversion = FALSE;  global->showincluded = FALSE;  global->showspace = FALSE;  global->nestcomments = FALSE;  global->warnnestcomments = FALSE;  global->outputfile = TRUE;  global->included = 0;  global->comment = FALSE;  global->rightconcat = FALSE;  global->work[0] = '\0';  global->initialfunc = NULL;  memset(global->symtab, 0, SBSIZE * sizeof(DEFBUF *));  ret=initdefines(global);  /* O.S. specific def's  */  if(ret)    return(ret);  dooptions(global, tags);  /* Command line -flags  */  ret=addfile(global, stdin, global->work); /* "open" main input file       */  global->out = global->outputfile;  if(!ret)    ret=cppmain(global);             /* Process main file            */  if ((i = (global->ifptr - global->ifstack)) != 0) {#if OLD_PREPROCESSOR    cwarn(global, ERROR_IFDEF_DEPTH, i);#else    cerror(global, ERROR_IFDEF_DEPTH, i);#endif  }  fflush(stdout);  fclose(stdout);  FreeAll(); /* free all unfreed memory! */  if (global->errors > 0 && !global->eflag)    return(IO_ERROR);  return(IO_NORMAL);       /* No errors or -E option set   */}INLINE FILE_LOCALReturnCode cppmain(struct Global *global){  /*   * Main process for cpp -- copies tokens from the current input   * stream (main file, include file, or a macro) to the output   * file.   */  int c;        /* Current character    */  int counter;  /* newlines and spaces  */  ReturnCode ret; /* return code variable type */  long bracelevel = 0;  long parenlevel = 0;  long bracketlevel = 0;  int fake = 0;  char tempfunc[50 + 1];  char tempfunc2[50 + 1];  char define = 0; /* probability of a function define phase in the program */  char prev = 0; /* previous type */  char go = 0;  char include = 0;  char initfunc = 0;  /* Initialize for reading tokens */  global->tokenbsize = 50;  global->tokenbuf = Getmem(global, global->tokenbsize + 1);  if(!global->tokenbuf)    return(FPP_OUT_OF_MEMORY);  global->functionname = Getmem(global, global->tokenbsize + 1);  if(!global->functionname)    return(FPP_OUT_OF_MEMORY);  global->functionname[0] = '\0';  if(global->showspace) {    global->spacebuf = (char *)Getmem(global, MAX_SPACE_SIZE);    if(!global->spacebuf)      return(FPP_OUT_OF_MEMORY);  }  if(global->showversion)      Error(global, VERSION_TEXT);  /*   * Explicitly output a #line at the start of cpp output so   * that lint (etc.) knows the name of the original source   * file.  If we don't do this explicitly, we may get   * the name of the first #include file instead.   */  if(global->linelines) /* if #line lines are wanted! */    sharp(global);  /*   * This loop is started "from the top" at the beginning of each line   * wrongline is set TRUE in many places if it is necessary to write   * a #line record.  (But we don't write them when expanding macros.)   *   * The counter variable has two different uses:  at   * the start of a line, it counts the number of blank lines that   * have been skipped over. These are then either output via   * #line records or by outputting explicit blank lines.   * When expanding tokens within a line, the counter remembers   * whether a blank/tab has been output.  These are dropped   * at the end of the line, and replaced by a single blank

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -