From cb6929f773fdf9466318ab1bd38b92dde846462a Mon Sep 17 00:00:00 2001 From: Daniel Stenberg Date: Mon, 9 May 2011 10:41:40 +0200 Subject: [PATCH] cleanups Remove the custom malloc/free system Remove commit history from comment headers --- cpp1.c | 181 +------------ cpp2.c | 56 +--- cpp3.c | 244 +++++++----------- cpp4.c | 49 +--- cpp5.c | 44 ---- cpp6.c | 761 ++++++++++++++++++++++++------------------------------- makefile | 4 +- memory.c | 214 ---------------- 8 files changed, 438 insertions(+), 1115 deletions(-) delete mode 100644 memory.c diff --git a/cpp1.c b/cpp1.c index e98fed6..77556b0 100644 --- a/cpp1.c +++ b/cpp1.c @@ -1,5 +1,5 @@ /****************************************************************************** -Copyright (c) 1999 Daniel Stenberg +Copyright (c) 1993 - 2011 Daniel Stenberg Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -19,173 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -/****************************************************************************** - * 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 - * 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 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 #include @@ -211,7 +44,7 @@ int PREFIX fppPreProcess(REG(a0) struct fppTag *tags) ReturnCode ret; /* cpp return code */ struct Global *global; - global=(struct Global *)Malloc(sizeof(struct Global)); + global=(struct Global *)malloc(sizeof(struct Global)); if(!global) return(FPP_OUT_OF_MEMORY); @@ -311,8 +144,6 @@ int PREFIX fppPreProcess(REG(a0) struct fppTag *tags) 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 */ @@ -348,17 +179,17 @@ ReturnCode cppmain(struct Global *global) /* Initialize for reading tokens */ global->tokenbsize = 50; - global->tokenbuf = Getmem(global, global->tokenbsize + 1); + global->tokenbuf = malloc(global->tokenbsize + 1); if(!global->tokenbuf) return(FPP_OUT_OF_MEMORY); - global->functionname = Getmem(global, global->tokenbsize + 1); + global->functionname = malloc(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); + global->spacebuf = (char *)malloc(MAX_SPACE_SIZE); if(!global->spacebuf) return(FPP_OUT_OF_MEMORY); } @@ -747,7 +578,7 @@ void sharp(struct Global *global) if (global->sharpfilename == NULL || (global->sharpfilename != NULL && !streq(name, global->sharpfilename))) { if (global->sharpfilename != NULL) - Freemem(global->sharpfilename); + free(global->sharpfilename); global->sharpfilename = savestring(global, name); /* printf(" \"%s\"", name); */ Putstring(global, " \""); diff --git a/cpp2.c b/cpp2.c index 7e987ee..4310f4d 100644 --- a/cpp2.c +++ b/cpp2.c @@ -19,60 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -/****************************************************************************** - * FREXXWARE - * ---------------------------------------------------------------------------- - * - * Project: Frexx C Preprocessor - * $Source: /home/user/start/cpp/RCS/cpp2.c,v $ - * $Revision: 1.5 $ - * $Date: 1994/01/24 09:32:54 $ - * $Author: start $ - * $State: Exp $ - * $Locker: start $ - * - * ---------------------------------------------------------------------------- - * $Log: cpp2.c,v $ - * Revision 1.5 1994/01/24 09:32:54 start - * Fixed AmigaDOS include file routine. - * - * Revision 1.4 1993/12/06 13:50:39 start - * A lot of new stuff (too much to mention) - * - * Revision 1.4 1993/12/06 13:50:39 start - * A lot of new stuff (too much to mention) - * - * 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 - * - * - *****************************************************************************/ -/* - * C P P 2 . C - * - * Process #control lines - * - * Edit history - * 13-Nov-84 MM Split from cpp1.c - * 21-Oct-85 RMS Do not turn on `instring' while reading #include arg. - * Rename `token' to `tokenbuf'. - * Flush tabs at end of #include line, like spaces. - * 14-Mar-86 FNF Incorporate macro based C debugging package. - * Port to Commodore AMIGA. - * 25-May-86 FNF Change handling of fully qualified include file - * pathnames (like "/usr/include/stdio.h" for unix, - * or "df0:include/stdio.h" for the Amiga) to be - * used verbatum in the first open attempt. - * 20-Aug-88 Ois Added #error. Passed unrecognized # commands. - * Added \n when those lines are passed. - */ - #include #include #include "cppdef.h" @@ -292,7 +238,7 @@ ReturnCode control( struct Global *global, if( global->infile->progname != NULL ) /* Give up the old name if it's allocated. */ - Freemem( global->infile->progname ); + free( global->infile->progname ); global->infile->progname = savestring( global, tp ); } diff --git a/cpp3.c b/cpp3.c index 314ef83..2f77fbc 100644 --- a/cpp3.c +++ b/cpp3.c @@ -19,61 +19,11 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -/****************************************************************************** - * FREXXWARE - * ---------------------------------------------------------------------------- - * - * Project: Frexx C Preprocessor - * $Source: /home/user/start/cpp/RCS/cpp3.c,v $ - * $Revision: 1.6 $ - * $Date: 1994/06/02 08:50:08 $ - * $Author: start $ - * $State: Exp $ - * $Locker: $ - * - * ---------------------------------------------------------------------------- - * $Log: cpp3.c,v $ - * Revision 1.6 1994/06/02 08:50:08 start - * Added the new command line options - * - * Revision 1.5 1994/01/24 09:33:15 start - * Added the FPPTAG_RIGHTCONCAT tag. - * - * Revision 1.4 1993/12/06 13:50:39 start - * A lot of new stuff (too much to mention) - * - * Revision 1.4 1993/12/06 13:50:39 start - * A lot of new stuff (too much to mention) - * - * 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 - * - * - *****************************************************************************/ -/* - * C P P 3 . C - * - * File open and command line options - * - * Edit history - * 13-Nov-84 MM Split from cpp1.c - * 21-Oct-85 rms Make -g command arg not cause an error. - * 14-Mar-86 FNF Incorporate macro based C debugging package. - * Port to the Commodore AMIGA. - * 20-Aug-88 Ois Added __TIME__, and changed __DATE__ to standard. - */ - -#include -#include -#include /*OIS*0.92*/ -#include "cppdef.h" -#include "cpp.h" +#include +#include +#include /*OIS*0.92*/ +#include "cppdef.h" +#include "cpp.h" ReturnCode openfile(struct Global *global, char *filename) { @@ -84,24 +34,24 @@ ReturnCode openfile(struct Global *global, char *filename) FILE *fp; ReturnCode ret; - + if ((fp = fopen(filename, "r")) == NULL) ret=FPP_OPEN_ERROR; else ret=addfile(global, fp, filename); if(!ret && global->showincluded) { - /* no error occured! */ - Error(global, "cpp: included \""); - Error(global, filename); - Error(global, "\"\n"); + /* no error occured! */ + Error(global, "cpp: included \""); + Error(global, filename); + Error(global, "\"\n"); } return(ret); } ReturnCode addfile(struct Global *global, - FILE *fp, /* Open file pointer */ - char *filename) /* Name of the file */ + FILE *fp, /* Open file pointer */ + char *filename) /* Name of the file */ { /* * Initialize tables for this open file. This is called from openfile() @@ -113,14 +63,14 @@ ReturnCode addfile(struct Global *global, FILEINFO *file; ReturnCode ret; - + ret = getfile(global, NBUFF, filename, &file); if(ret) return(ret); - file->fp = fp; /* Better remember FILE * */ - file->buffer[0] = EOS; /* Initialize for first read */ - global->line = 1; /* Working on line 1 now */ - global->wrongline = TRUE; /* Force out initial #line */ + file->fp = fp; /* Better remember FILE * */ + file->buffer[0] = EOS; /* Initialize for first read */ + global->line = 1; /* Working on line 1 now */ + global->wrongline = TRUE; /* Force out initial #line */ return(FPP_OK); } @@ -179,8 +129,8 @@ int dooptions(struct Global *global, struct fppTag *tags) break; case FPPTAG_KEEPCOMMENTS: if(tags->data) { - global->cflag = TRUE; - global->keepcomments = TRUE; + global->cflag = TRUE; + global->keepcomments = TRUE; } break; case FPPTAG_DEFINE: @@ -188,22 +138,22 @@ int dooptions(struct Global *global, struct fppTag *tags) * If the option is just "-Dfoo", make it -Dfoo=1 */ { - char *symbol=(char *)tags->data; - char *text=symbol; - while (*text != EOS && *text != '=') - text++; - if (*text == EOS) - text = "1"; - else - *text++ = EOS; - /* - * Now, save the word and its definition. - */ - dp = defendel(global, symbol, FALSE); - if(!dp) - return(FPP_OUT_OF_MEMORY); - dp->repl = savestring(global, text); - dp->nargs = DEF_NOARGS; + char *symbol=(char *)tags->data; + char *text=symbol; + while (*text != EOS && *text != '=') + text++; + if (*text == EOS) + text = "1"; + else + *text++ = EOS; + /* + * Now, save the word and its definition. + */ + dp = defendel(global, symbol, FALSE); + if(!dp) + return(FPP_OUT_OF_MEMORY); + dp->repl = savestring(global, text); + dp->nargs = DEF_NOARGS; } break; case FPPTAG_IGNORE_NONFATAL: @@ -211,21 +161,21 @@ int dooptions(struct Global *global, struct fppTag *tags) break; case FPPTAG_INCLUDE_DIR: if (global->incend >= &global->incdir[NINCLUDE]) { - cfatal(global, FATAL_TOO_MANY_INCLUDE_DIRS); - return(FPP_TOO_MANY_INCLUDE_DIRS); + cfatal(global, FATAL_TOO_MANY_INCLUDE_DIRS); + return(FPP_TOO_MANY_INCLUDE_DIRS); } *global->incend++ = (char *)tags->data; break; case FPPTAG_INCLUDE_FILE: case FPPTAG_INCLUDE_MACRO_FILE: if (global->included >= NINCLUDE) { - cfatal(global, FATAL_TOO_MANY_INCLUDE_FILES); - return(FPP_TOO_MANY_INCLUDE_FILES); + cfatal(global, FATAL_TOO_MANY_INCLUDE_FILES); + return(FPP_TOO_MANY_INCLUDE_FILES); } global->include[global->included] = (char *)tags->data; global->includeshow[global->included] = - (tags->tag == FPPTAG_INCLUDE_FILE); + (tags->tag == FPPTAG_INCLUDE_FILE); global->included++; break; @@ -240,45 +190,45 @@ int dooptions(struct Global *global, struct fppTag *tags) break; case FPPTAG_SIZEOF_TABLE: { - SIZES *sizp; /* For -S */ - int size; /* For -S */ - int isdatum; /* FALSE for -S* */ - int endtest; /* For -S */ + SIZES *sizp; /* For -S */ + int size; /* For -S */ + int isdatum; /* FALSE for -S* */ + int endtest; /* For -S */ - char *text=(char *)tags->data; + char *text=(char *)tags->data; - sizp = size_table; - if (isdatum = (*text != '*')) /* If it's just -S, */ - endtest = T_FPTR; /* Stop here */ - else { /* But if it's -S* */ - text++; /* Step over '*' */ - endtest = 0; /* Stop at end marker */ - } - while (sizp->bits != endtest && *text != EOS) { - if (!isdigit(*text)) { /* Skip to next digit */ - text++; - continue; - } - size = 0; /* Compile the value */ - while (isdigit(*text)) { - size *= 10; - size += (*text++ - '0'); - } - if (isdatum) - sizp->size = size; /* Datum size */ - else - sizp->psize = size; /* Pointer size */ - sizp++; - } - if (sizp->bits != endtest) - cwarn(global, WARN_TOO_FEW_VALUES_TO_SIZEOF, NULL); - else if (*text != EOS) - cwarn(global, WARN_TOO_MANY_VALUES_TO_SIZEOF, NULL); + sizp = size_table; + if (isdatum = (*text != '*')) /* If it's just -S, */ + endtest = T_FPTR; /* Stop here */ + else { /* But if it's -S* */ + text++; /* Step over '*' */ + endtest = 0; /* Stop at end marker */ + } + while (sizp->bits != endtest && *text != EOS) { + if (!isdigit(*text)) { /* Skip to next digit */ + text++; + continue; + } + size = 0; /* Compile the value */ + while (isdigit(*text)) { + size *= 10; + size += (*text++ - '0'); + } + if (isdatum) + sizp->size = size; /* Datum size */ + else + sizp->psize = size; /* Pointer size */ + sizp++; + } + if (sizp->bits != endtest) + cwarn(global, WARN_TOO_FEW_VALUES_TO_SIZEOF, NULL); + else if (*text != EOS) + cwarn(global, WARN_TOO_MANY_VALUES_TO_SIZEOF, NULL); } break; case FPPTAG_UNDEFINE: if (defendel(global, (char *)tags->data, TRUE) == NULL) - cwarn(global, WARN_NOT_DEFINED, tags->data); + cwarn(global, WARN_NOT_DEFINED, tags->data); break; case FPPTAG_OUTPUT_DEFINES: global->wflag++; @@ -292,7 +242,7 @@ int dooptions(struct Global *global, struct fppTag *tags) break; case FPPTAG_OUTPUT: global->output=(void (*)(int, void *))tags->data; - break; + break; case FPPTAG_ERROR: global->error=(void (*)(void *, char *, va_list))tags->data; break; @@ -321,8 +271,8 @@ ReturnCode initdefines(struct Global *global) { /* * Initialize the built-in #define's. There are two flavors: - * #define decus 1 (static definitions) - * #define __FILE__ ?? (dynamic, evaluated by magic) + * #define decus 1 (static definitions) + * #define __FILE__ ?? (dynamic, evaluated by magic) * Called only on cpp startup. * * Note: the built-in static definitions are supressed by the -N option. @@ -333,15 +283,15 @@ ReturnCode initdefines(struct Global *global) char *tp; DEFBUF *dp; struct tm *tm; - + int i; time_t tvec; - + static char months[12][4] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; - + /* * Predefine the built-in symbols. Allow the * implementor to pre-define a symbol as "" to @@ -350,11 +300,11 @@ ReturnCode initdefines(struct Global *global) if (!(global->nflag & NFLAG_BUILTIN)) { for (pp = global->preset; *pp != NULL; pp++) { if (*pp[0] != EOS) { - dp = defendel(global, *pp, FALSE); - if(!dp) - return(FPP_OUT_OF_MEMORY); - dp->repl = savestring(global, "1"); - dp->nargs = DEF_NOARGS; + dp = defendel(global, *pp, FALSE); + if(!dp) + return(FPP_OUT_OF_MEMORY); + dp->repl = savestring(global, "1"); + dp->nargs = DEF_NOARGS; } } } @@ -368,7 +318,7 @@ ReturnCode initdefines(struct Global *global) for (pp = global->magic, i = DEF_NOARGS; *pp != NULL; pp++) { dp = defendel(global, *pp, FALSE); if(!dp) - return(FPP_OUT_OF_MEMORY); + return(FPP_OUT_OF_MEMORY); dp->nargs = --i; } #if OK_DATE @@ -376,7 +326,7 @@ ReturnCode initdefines(struct Global *global) * Define __DATE__ as today's date. */ dp = defendel(global, "__DATE__", FALSE); - tp = Getmem(global, 14); + tp = malloc(14); if(!tp || !dp) return(FPP_OUT_OF_MEMORY); dp->repl = tp; @@ -384,23 +334,23 @@ ReturnCode initdefines(struct Global *global) time(&tvec); tm = localtime(&tvec); sprintf(tp, "\"%3s %2d %4d\"", /* "Aug 20 1988" */ - months[tm->tm_mon], - tm->tm_mday, - tm->tm_year + 1900); - + months[tm->tm_mon], + tm->tm_mday, + tm->tm_year + 1900); + /* * Define __TIME__ as this moment's time. */ dp = defendel(global, "__TIME__", FALSE); - tp = Getmem(global, 11); + tp = malloc(11); if(!tp || !dp) return(FPP_OUT_OF_MEMORY); dp->repl = tp; dp->nargs = DEF_NOARGS; sprintf(tp, "\"%2d:%02d:%02d\"", /* "20:42:31" */ - tm->tm_hour, - tm->tm_min, - tm->tm_sec); + tm->tm_hour, + tm->tm_min, + tm->tm_sec); #endif } return(FPP_OK); @@ -413,8 +363,8 @@ void deldefines(struct Global *global) */ char **pp; int i; - - + + /* * Delete the built-in symbols, unless -WW. */ @@ -434,7 +384,7 @@ void deldefines(struct Global *global) * Undefine __DATE__. */ defendel(global, "__DATE__", TRUE); - + /* * Undefine __TIME__. */ diff --git a/cpp4.c b/cpp4.c index d695c13..2c64af2 100644 --- a/cpp4.c +++ b/cpp4.c @@ -19,53 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -/****************************************************************************** - * FREXXWARE - * ---------------------------------------------------------------------------- - * - * Project: Frexx C Preprocessor - * $Source: /home/user/start/cpp/RCS/cpp4.c,v $ - * $Revision: 1.3 $ - * $Date: 1994/06/02 08:50:52 $ - * $Author: start $ - * $State: Exp $ - * $Locker: $ - * - * ---------------------------------------------------------------------------- - * $Log: cpp4.c,v $ - * Revision 1.3 1994/06/02 08:50:52 start - * Changed a few things to make the initial function routine to run - * - * Revision 1.2 1994/01/24 09:34:03 start - * Made a bunch of functions FILE_LOCAL and INLINE. - * - * Revision 1.1 1993/11/03 09:13:08 start - * Initial revision - * - * - *****************************************************************************/ -/* - * C P P 4 . C - * M a c r o D e f i n i t i o n s - * - * Edit History - * 31-Aug-84 MM USENET net.sources release - * 04-Oct-84 MM __LINE__ and __FILE__ must call ungetstring() - * so they work correctly with token concatenation. - * Added string formal recognition. - * 25-Oct-84 MM "Short-circuit" evaluate #if's so that we - * don't print unnecessary error messages for - * #if !defined(FOO) && FOO != 0 && 10 / FOO ... - * 31-Oct-84 ado/MM Added token concatenation - * 6-Nov-84 MM Split off eval stuff - * 21-Oct-85 RMS Rename `token' to `tokenbuf'. - * In doundef, don't complain if arg already not defined. - * 14-Mar-86 FNF Incorporate macro based C debugging package. - * Port to Commodore AMIGA. - * 21-Aug-88 Ois Changed concatenation operator to ##. Changed hand- - * ling of tokens following ##. Added new meaning of #. - */ - #include #include #include "cppdef.h" @@ -265,7 +218,7 @@ ReturnCode dodefine(struct Global *global) cerror(global, ERROR_REDEFINE, dp->name); } if (old != NULL) /* We don't need the */ - Freemem(old); /* old definition now. */ + free(old); /* old definition now. */ } return(FPP_OK); } diff --git a/cpp5.c b/cpp5.c index 174b7d4..c1aa8f4 100644 --- a/cpp5.c +++ b/cpp5.c @@ -19,50 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -/****************************************************************************** - * FREXXWARE - * ---------------------------------------------------------------------------- - * - * Project: Frexx C Preprocessor - * $Source: /home/user/start/cpp/RCS/cpp5.c,v $ - * $Revision: 1.2 $ - * $Date: 1994/01/24 09:35:02 $ - * $Author: start $ - * $State: Exp $ - * $Locker: $ - * - * ---------------------------------------------------------------------------- - * $Log: cpp5.c,v $ - * Revision 1.2 1994/01/24 09:35:02 start - * Made a bunch of functions FILE_LOCAL and INLINE. - * - * Revision 1.1 1993/11/03 09:13:08 start - * Initial revision - * - * - *****************************************************************************/ -/* - * C P P 5 . C - * E x p r e s s i o n E v a l u a t i o n - * - * Edit History - * 31-Aug-84 MM USENET net.sources release - * 04-Oct-84 MM __LINE__ and __FILE__ must call ungetstring() - * so they work correctly with token concatenation. - * Added string formal recognition. - * 25-Oct-84 MM "Short-circuit" evaluate #if's so that we - * don't print unnecessary error messages for - * #if !defined(FOO) && FOO != 0 && 10 / FOO ... - * 31-Oct-84 ado/MM Added token concatenation - * 6-Nov-84 MM Split from #define stuff, added sizeof stuff - * 19-Nov-84 ado #if error returns TRUE for (sigh) compatibility - * 21-Oct-85 RMS Rename `token' to `tokenbuf' - * 23-Oct-85 RMS Treat undefined symbols as having value zero. - * 14-Mar-86 FNF Incorporate macro based C debugging package. - * Port to Commodore Amiga. - * 20-Aug-88 Ois Conditionally compile sizeof stuff. - */ - #include #include #include "cppdef.h" diff --git a/cpp6.c b/cpp6.c index c4b7a77..d817c1d 100644 --- a/cpp6.c +++ b/cpp6.c @@ -19,69 +19,6 @@ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. ******************************************************************************/ -/****************************************************************************** - * FREXXWARE - * ---------------------------------------------------------------------------- - * - * Project: Frexx C Preprocessor - * $Source: /home/user/start/cpp/RCS/cpp6.c,v $ - * $Revision: 1.5 $ - * $Date: 1994/01/24 09:35:17 $ - * $Author: start $ - * $State: Exp $ - * $Locker: $ - * - * ---------------------------------------------------------------------------- - * $Log: cpp6.c,v $ - * Revision 1.5 1994/01/24 09:35:17 start - * Made the FPPTAG_RIGHTCONCAT work. - * - * Revision 1.4 1993/12/06 13:50:39 start - * A lot of new stuff (too much to mention) - * - * Revision 1.4 1993/12/06 13:50:39 start - * A lot of new stuff (too much to mention) - * - * 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 - * - * - *****************************************************************************/ -/* - * C P P 6 . C - * S u p p o r t R o u t i n e s - * - * Edit History - * 25-May-84 MM Added 8-bit support to type table. - * 30-May-84 ARF sharp() should output filename in quotes - * 02-Aug-84 MM Newline and #line hacking. sharp() now in cpp1.c - * 31-Aug-84 MM USENET net.sources release - * 11-Sep-84 ado/MM Keepcomments, also line number pathological - * 12-Sep-84 ado/MM bug if comment changes to space and we unget later. - * 03-Oct-84 gkr/MM Fixed scannumber bug for '.e' (as in struct.element). - * 04-Oct-84 MM Added ungetstring() for token concatenation - * 08-Oct-84 MM Yet another attack on number scanning - * 31-Oct-84 ado Parameterized $ in identifiers - * 2-Nov-84 MM Token concatenation is messier than I thought - * 6-Dec-84 MM \ is everywhere invisible. - * 21-Oct-85 RMS Rename `token' to `tokenbuf'. - * Dynamically allocate it, and make it as big as needed. - * 23-Oct-85 RMS Fix bugs storing into tokenbuf as it gets bigger. - * Change error msg to cpp: "FILE", line LINE: MSG - * 24-Oct-85 RMS Turn off warnings about / then * inside a comment. - * 16-Mar-86 FNF Incorporate macro based C debugging package. - * Port to Commodore Amiga. - * 20-Aug-88 Ois Added time routines (or actually deleted stubs). - * 20-Aug-88 Ois Changed handling of token following ## to match Cpp4. - * 16-Feb-93 DSt Changed case of getmem() to Getmem(). - */ - #include #include #include "cppdef.h" @@ -94,46 +31,46 @@ FILE_LOCAL char *incmem(struct Global *, char *, int); /* * skipnl() skips over input text to the end of the line. * skipws() skips over "whitespace" (spaces or tabs), but - * not skip over the end of the line. It skips over - * TOK_SEP, however (though that shouldn't happen). + * not skip over the end of the line. It skips over + * TOK_SEP, however (though that shouldn't happen). * scanid() reads the next token (C identifier) into tokenbuf. - * The caller has already read the first character of - * the identifier. Unlike macroid(), the token is - * never expanded. + * The caller has already read the first character of + * the identifier. Unlike macroid(), the token is + * never expanded. * macroid() reads the next token (C identifier) into tokenbuf. - * If it is a #defined macro, it is expanded, and - * macroid() returns TRUE, otherwise, FALSE. + * If it is a #defined macro, it is expanded, and + * macroid() returns TRUE, otherwise, FALSE. * catenate() Does the dirty work of token concatenation, TRUE if it did. * scanstring() Reads a string from the input stream, calling - * a user-supplied function for each character. - * This function may be output() to write the - * string to the output file, or save() to save - * the string in the work buffer. + * a user-supplied function for each character. + * This function may be output() to write the + * string to the output file, or save() to save + * the string in the work buffer. * scannumber() Reads a C numeric constant from the input stream, - * calling the user-supplied function for each - * character. (output() or save() as noted above.) + * calling the user-supplied function for each + * character. (output() or save() as noted above.) * save() Save one character in the work[] buffer. * savestring() Saves a string in malloc() memory. * getfile() Initialize a new FILEINFO structure, called when - * #include opens a new file, or a macro is to be - * expanded. + * #include opens a new file, or a macro is to be + * expanded. * Getmem() Get a specified number of bytes from malloc memory. * output() Write one character to stdout (calling Putchar) -- - * implemented as a function so its address may be - * passed to scanstring() and scannumber(). + * implemented as a function so its address may be + * passed to scanstring() and scannumber(). * lookid() Scans the next token (identifier) from the input - * stream. Looks for it in the #defined symbol table. - * Returns a pointer to the definition, if found, or NULL - * if not present. The identifier is stored in tokenbuf. + * stream. Looks for it in the #defined symbol table. + * Returns a pointer to the definition, if found, or NULL + * if not present. The identifier is stored in tokenbuf. * defnedel() Define enter/delete subroutine. Updates the - * symbol table. + * symbol table. * get() Read the next byte from the current input stream, - * handling end of (macro/file) input and embedded - * comments appropriately. Note that the global - * instring is -- essentially -- a parameter to get(). + * handling end of (macro/file) input and embedded + * comments appropriately. Note that the global + * instring is -- essentially -- a parameter to get(). * cget() Like get(), but skip over TOK_SEP. * unget() Push last gotten character back on the input stream. - * cerror() This routine format an print messages to the user. + * cerror() This routine format an print messages to the user. */ /* @@ -153,36 +90,36 @@ FILE_LOCAL char *incmem(struct Global *, char *, int); #endif #if OK_DOLLAR -#define DOL LET +#define DOL LET #else -#define DOL 000 +#define DOL 000 #endif -char type[256] = { /* Character type codes Hex */ - END, 000, 000, 000, 000, 000, 000, 000, /* 00 */ - 000, SPA, 000, 000, 000, 000, 000, 000, /* 08 */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 10 */ - 000, 000, 000, 000, 000, LET, 000, SPA, /* 18 */ - SPA, OP_NOT, QUO, 000, DOL, OP_MOD,OP_AND,QUO, /* 20 !"#$%&' */ +char type[256] = { /* Character type codes Hex */ + END, 000, 000, 000, 000, 000, 000, 000, /* 00 */ + 000, SPA, 000, 000, 000, 000, 000, 000, /* 08 */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 10 */ + 000, 000, 000, 000, 000, LET, 000, SPA, /* 18 */ + SPA, OP_NOT, QUO, 000, DOL, OP_MOD,OP_AND,QUO, /* 20 !"#$%&' */ OP_LPA,OP_RPA,OP_MUL,OP_ADD, 000,OP_SUB, DOT,OP_DIV, /* 28 ()*+,-./ */ - DIG, DIG, DIG, DIG, DIG, DIG, DIG, DIG, /* 30 01234567 */ - DIG, DIG,OP_COL, 000, OP_LT, OP_EQ, OP_GT,OP_QUE, /* 38 89:;<=>? */ - 000, LET, LET, LET, LET, LET, LET, LET, /* 40 @ABCDEFG */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 48 HIJKLMNO */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 50 PQRSTUVW */ - LET, LET, LET, 000, BSH, 000,OP_XOR, LET, /* 58 XYZ[\]^_ */ - 000, LET, LET, LET, LET, LET, LET, LET, /* 60 `abcdefg */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 68 hijklmno */ - LET, LET, LET, LET, LET, LET, LET, LET, /* 70 pqrstuvw */ - LET, LET, LET, 000, OP_OR, 000,OP_NOT, 000, /* 78 xyz{|}~ */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ - 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + DIG, DIG, DIG, DIG, DIG, DIG, DIG, DIG, /* 30 01234567 */ + DIG, DIG,OP_COL, 000, OP_LT, OP_EQ, OP_GT,OP_QUE, /* 38 89:;<=>? */ + 000, LET, LET, LET, LET, LET, LET, LET, /* 40 @ABCDEFG */ + LET, LET, LET, LET, LET, LET, LET, LET, /* 48 HIJKLMNO */ + LET, LET, LET, LET, LET, LET, LET, LET, /* 50 PQRSTUVW */ + LET, LET, LET, 000, BSH, 000,OP_XOR, LET, /* 58 XYZ[\]^_ */ + 000, LET, LET, LET, LET, LET, LET, LET, /* 60 `abcdefg */ + LET, LET, LET, LET, LET, LET, LET, LET, /* 68 hijklmno */ + LET, LET, LET, LET, LET, LET, LET, LET, /* 70 pqrstuvw */ + LET, LET, LET, 000, OP_OR, 000,OP_NOT, 000, /* 78 xyz{|}~ */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ + 000, 000, 000, 000, 000, 000, 000, 000, /* 80 .. FF */ }; void skipnl(struct Global *global) @@ -191,8 +128,8 @@ void skipnl(struct Global *global) * Skip to the end of the current input line. */ int c; - - do { /* Skip to newline */ + + do { /* Skip to newline */ c = get(global); } while (c != '\n' && c != EOF_CHAR); return; @@ -204,8 +141,8 @@ int skipws(struct Global *global) * Skip over whitespace */ int c; - - do { /* Skip whitespace */ + + do { /* Skip whitespace */ c = get(global); #if COMMENT_INVISIBLE } while (type[c] == SPA || c == COM_SEP); @@ -216,7 +153,7 @@ int skipws(struct Global *global) } void scanid(struct Global *global, - int c) /* First char of id */ + int c) /* First char of id */ { /* * Get the next token (an id) into the token buffer. @@ -225,15 +162,15 @@ void scanid(struct Global *global, */ int ct; - + if (c == DEF_MAGIC) /* Eat the magic token */ c = get(global); /* undefiner. */ ct = 0; do { if (ct == global->tokenbsize) - global->tokenbuf = incmem (global, global->tokenbuf, 1 + - (global->tokenbsize *= 2)); + global->tokenbuf = realloc(global->tokenbuf, 1 + + (global->tokenbsize *= 2)); global->tokenbuf[ct++] = c; c = get(global); } @@ -252,7 +189,7 @@ ReturnCode macroid(struct Global *global, int *c) */ DEFBUF *dp; ReturnCode ret=FPP_OK; - + if (global->infile != NULL && global->infile->fp != NULL) global->recursion = 0; while (type[*c] == LET && (dp = lookid(global, *c)) != NULL) { @@ -277,7 +214,7 @@ int catenate(struct Global *global, ReturnCode *ret) int c; char *token1; #endif - + #if OK_CONCAT if (get(global) != TOK_SEP) { /* Token concatenation */ unget(global); @@ -289,34 +226,34 @@ int catenate(struct Global *global, ReturnCode *ret) if(global->rightconcat) { *ret=macroid(global, &c); /* Scan next token */ if(*ret) - return(FALSE); + return(FALSE); } else lookid(global, c); switch(type[c]) { /* What was it? */ - case LET: /* An identifier, ... */ + case LET: /* An identifier, ... */ if ((int)strlen(token1) + (int)strlen(global->tokenbuf) >= NWORK) { - cfatal(global, FATAL_WORK_AREA_OVERFLOW, token1); - *ret=FPP_WORK_AREA_OVERFLOW; - return(FALSE); + cfatal(global, FATAL_WORK_AREA_OVERFLOW, token1); + *ret=FPP_WORK_AREA_OVERFLOW; + return(FALSE); } sprintf(global->work, "%s%s", token1, global->tokenbuf); break; - case DIG: /* A number */ - case DOT: /* Or maybe a float */ + case DIG: /* A number */ + case DOT: /* Or maybe a float */ strcpy(global->work, token1); global->workp = global->work + strlen(global->work); *ret=scannumber(global, c, save); if(*ret) - return(FALSE); + return(FALSE); *ret=save(global, EOS); if(*ret) - return(FALSE); + return(FALSE); break; - default: /* An error, ... */ + default: /* An error, ... */ if (isprint(c)) - cerror(global, ERROR_STRANG_CHARACTER, c); + cerror(global, ERROR_STRANG_CHARACTER, c); else - cerror(global, ERROR_STRANG_CHARACTER2, c); + cerror(global, ERROR_STRANG_CHARACTER2, c); strcpy(global->work, token1); unget(global); break; @@ -327,7 +264,7 @@ int catenate(struct Global *global, ReturnCode *ret) * new (concatenated) token after freeing token1. * Finally, setup to read the new token. */ - Freemem(token1); /* Free up memory */ + free(token1); /* Free up memory */ *ret=ungetstring(global, global->work); /* Unget the new thing, */ if(*ret) return(FALSE); @@ -339,9 +276,9 @@ int catenate(struct Global *global, ReturnCode *ret) } ReturnCode scanstring(struct Global *global, - int delim, /* ' or " */ - /* Output function: */ - ReturnCode (*outfun)(struct Global *, int)) + int delim, /* ' or " */ + /* Output function: */ + ReturnCode (*outfun)(struct Global *, int)) { /* * Scan off a string. Warning if terminated by newline or EOF. @@ -351,21 +288,21 @@ ReturnCode scanstring(struct Global *global, int c; ReturnCode ret; - - global->instring = TRUE; /* Don't strip comments */ + + global->instring = TRUE; /* Don't strip comments */ ret=(*outfun)(global, delim); if(ret) return(ret); while ((c = get(global)) != delim - && c != '\n' - && c != EOF_CHAR) { + && c != '\n' + && c != EOF_CHAR) { ret=(*outfun)(global, c); if(ret) return(ret); if (c == '\\') { ret=(*outfun)(global, get(global)); if(ret) - return(ret); + return(ret); } } global->instring = FALSE; @@ -380,47 +317,47 @@ ReturnCode scanstring(struct Global *global, } ReturnCode scannumber(struct Global *global, - int c, /* First char of number */ - /* Output/store func: */ - ReturnCode (*outfun)(struct Global *, int)) + int c, /* First char of number */ + /* Output/store func: */ + ReturnCode (*outfun)(struct Global *, int)) { /* * Process a number. We know that c is from 0 to 9 or dot. * Algorithm from Dave Conroy's Decus C. */ - - int radix; /* 8, 10, or 16 */ - int expseen; /* 'e' seen in floater */ - int signseen; /* '+' or '-' seen */ - int octal89; /* For bad octal test */ - int dotflag; /* TRUE if '.' was seen */ + + int radix; /* 8, 10, or 16 */ + int expseen; /* 'e' seen in floater */ + int signseen; /* '+' or '-' seen */ + int octal89; /* For bad octal test */ + int dotflag; /* TRUE if '.' was seen */ ReturnCode ret; char done=FALSE; - - expseen = FALSE; /* No exponent seen yet */ - signseen = TRUE; /* No +/- allowed yet */ - octal89 = FALSE; /* No bad octal yet */ - radix = 10; /* Assume decimal */ + + expseen = FALSE; /* No exponent seen yet */ + signseen = TRUE; /* No +/- allowed yet */ + octal89 = FALSE; /* No bad octal yet */ + radix = 10; /* Assume decimal */ if ((dotflag = (c == '.')) != FALSE) {/* . something? */ ret=(*outfun)(global, '.'); /* Always out the dot */ if(ret) return(ret); if (type[(c = get(global))] != DIG) { /* If not a float numb, */ unget(global); /* Rescan strange char */ - return(FPP_OK); /* All done for now */ + return(FPP_OK); /* All done for now */ } - } /* End of float test */ + } /* End of float test */ else if (c == '0') { /* Octal or hex? */ ret=(*outfun)(global, c); /* Stuff initial zero */ if(ret) return(ret); - radix = 8; /* Assume it's octal */ + radix = 8; /* Assume it's octal */ c = get(global); /* Look for an 'x' */ if (c == 'x' || c == 'X') { /* Did we get one? */ - radix = 16; /* Remember new radix */ + radix = 16; /* Remember new radix */ ret=(*outfun)(global, c); /* Stuff the 'x' */ if(ret) - return(ret); + return(ret); c = get(global); /* Get next character */ } } @@ -430,45 +367,45 @@ ReturnCode scannumber(struct Global *global, * as legitimate floating-point numbers. */ if (radix != 16 && (c == 'e' || c == 'E')) { - if (expseen) /* Already saw 'E'? */ - break; /* Exit loop, bad nbr. */ - expseen = TRUE; /* Set exponent seen */ - signseen = FALSE; /* We can read '+' now */ - radix = 10; /* Decimal exponent */ + if (expseen) /* Already saw 'E'? */ + break; /* Exit loop, bad nbr. */ + expseen = TRUE; /* Set exponent seen */ + signseen = FALSE; /* We can read '+' now */ + radix = 10; /* Decimal exponent */ } else if (radix != 16 && c == '.') { - if (dotflag) /* Saw dot already? */ - break; /* Exit loop, two dots */ - dotflag = TRUE; /* Remember the dot */ - radix = 10; /* Decimal fraction */ + if (dotflag) /* Saw dot already? */ + break; /* Exit loop, two dots */ + dotflag = TRUE; /* Remember the dot */ + radix = 10; /* Decimal fraction */ } else if (c == '+' || c == '-') { /* 1.0e+10 */ - if (signseen) /* Sign in wrong place? */ - break; /* Exit loop, not nbr. */ - /* signseen = TRUE; */ /* Remember we saw it */ - } else { /* Check the digit */ + if (signseen) /* Sign in wrong place? */ + break; /* Exit loop, not nbr. */ + /* signseen = TRUE; */ /* Remember we saw it */ + } else { /* Check the digit */ switch (c) { - case '8': case '9': /* Sometimes wrong */ - octal89 = TRUE; /* Do check later */ + case '8': case '9': /* Sometimes wrong */ + octal89 = TRUE; /* Do check later */ case '0': case '1': case '2': case '3': case '4': case '5': case '6': case '7': - break; /* Always ok */ - + break; /* Always ok */ + case 'a': case 'b': case 'c': case 'd': case 'e': case 'f': case 'A': case 'B': case 'C': case 'D': case 'E': case 'F': - if (radix == 16) /* Alpha's are ok only */ - break; /* if reading hex. */ - default: /* At number end */ - done=TRUE; /* Break from for loop */ - continue; - } /* End of switch */ - } /* End general case */ + if (radix == 16) /* Alpha's are ok only */ + break; /* if reading hex. */ + default: /* At number end */ + done=TRUE; /* Break from for loop */ + continue; + } /* End of switch */ + } /* End general case */ ret=(*outfun)(global, c); /* Accept the character */ if(ret) return(ret); - signseen = TRUE; /* Don't read sign now */ + signseen = TRUE; /* Don't read sign now */ c = get(global); /* Read another char */ - } /* End of scan loop */ + } /* End of scan loop */ /* * When we break out of the scan loop, c contains the first * character (maybe) not in the number. If the number is an @@ -482,10 +419,10 @@ ReturnCode scannumber(struct Global *global, if (c == 'l' || c == 'L') { ret=(*outfun)(global, c); if(ret) - return(ret); + return(ret); c = get(global); /* Ungotten later */ } - } else { /* Else it's an integer */ + } else { /* Else it's an integer */ /* * We know that dotflag and expseen are both zero, now: * dotflag signals "saw 'L'", and @@ -496,27 +433,27 @@ ReturnCode scannumber(struct Global *global, switch (c) { case 'l': case 'L': - if (dotflag) { - done=FALSE; - continue; - } - dotflag = TRUE; - break; + if (dotflag) { + done=FALSE; + continue; + } + dotflag = TRUE; + break; case 'u': case 'U': - if (expseen) { - done=FALSE; - continue; - } - expseen = TRUE; - break; + if (expseen) { + done=FALSE; + continue; + } + expseen = TRUE; + break; default: - done=FALSE; - continue; + done=FALSE; + continue; } ret=(*outfun)(global, c); /* Got 'L' or 'U'. */ if(ret) - return(ret); + return(ret); c = get(global); /* Look at next, too. */ } } @@ -545,89 +482,53 @@ char *savestring(struct Global *global, char *text) */ char *result; - - result = Getmem(global, strlen(text) + 1); + result = malloc(strlen(text) + 1); strcpy(result, text); return (result); } ReturnCode getfile(struct Global *global, - int bufsize, /* Line or define buffer size */ - char *name, - FILEINFO **file) /* File or macro name string */ + int bufsize, /* Line or define buffer size */ + char *name, + FILEINFO **file) /* File or macro name string */ { /* * Common FILEINFO buffer initialization for a new file or macro. */ int size; - - size = strlen(name); /* File/macro name */ + + size = strlen(name); /* File/macro name */ if(!size) { name = "[stdin]"; size = strlen(name); } - *file = (FILEINFO *) Getmem(global, (int)(sizeof (FILEINFO) + bufsize + size)); + *file = (FILEINFO *) malloc((int)(sizeof (FILEINFO) + bufsize + size)); if(!*file) return(FPP_OUT_OF_MEMORY); - (*file)->parent = global->infile; /* Chain files together */ - (*file)->fp = NULL; /* No file yet */ + (*file)->parent = global->infile; /* Chain files together */ + (*file)->fp = NULL; /* No file yet */ (*file)->filename = savestring(global, name); /* Save file/macro name */ - (*file)->progname = NULL; /* No #line seen yet */ - (*file)->unrecur = 0; /* No macro fixup */ - (*file)->bptr = (*file)->buffer; /* Initialize line ptr */ - (*file)->buffer[0] = EOS; /* Force first read */ - (*file)->line = 0; /* (Not used just yet) */ - if (global->infile != NULL) /* If #include file */ - global->infile->line = global->line; /* Save current line */ - global->infile = (*file); /* New current file */ - global->line = 1; /* Note first line */ - return(FPP_OK); /* All done. */ -} - -void Freemem(void *ptr) -{ - /* - * Free a block of memory! - */ - - Free(ptr); -} - - -char *Getmem(struct Global *global, int size) -{ - /* - * Get a block of free memory. - */ - - char *result; - if ((result = (char *)Malloc((unsigned) size)) == NULL) - cfatal(global, FATAL_OUT_OF_MEMORY); - return(result); -} - -FILE_LOCAL -char *incmem(struct Global *global, char *obj, int size) -{ - /* - * Get a block of free memory. - */ - - char *result; - if ((result = Realloc(obj, (unsigned) size)) == NULL) - cfatal(global, FATAL_OUT_OF_MEMORY); - return(result); + (*file)->progname = NULL; /* No #line seen yet */ + (*file)->unrecur = 0; /* No macro fixup */ + (*file)->bptr = (*file)->buffer; /* Initialize line ptr */ + (*file)->buffer[0] = EOS; /* Force first read */ + (*file)->line = 0; /* (Not used just yet) */ + if (global->infile != NULL) /* If #include file */ + global->infile->line = global->line; /* Save current line */ + global->infile = (*file); /* New current file */ + global->line = 1; /* Note first line */ + return(FPP_OK); /* All done. */ } /* - * C P P S y m b o l T a b l e s + * C P P S y m b o l T a b l e s */ - + DEFBUF *lookid(struct Global *global, - int c) /* First character of token */ + int c) /* First character of token */ { /* * Look for the next token in the symbol table. Returns token in tokenbuf. @@ -638,37 +539,37 @@ DEFBUF *lookid(struct Global *global, DEFBUF *dp; int ct; int temp; - int isrecurse; /* For #define foo foo */ - + int isrecurse; /* For #define foo foo */ + nhash = 0; if ((isrecurse = (c == DEF_MAGIC))) /* If recursive macro */ c = get(global); /* hack, skip DEF_MAGIC */ ct = 0; do { if (ct == global->tokenbsize) - global->tokenbuf = incmem(global, global->tokenbuf, 1 + (global->tokenbsize *= 2)); - global->tokenbuf[ct++] = c; /* Store token byte */ - nhash += c; /* Update hash value */ + global->tokenbuf = realloc(global->tokenbuf, 1 + (global->tokenbsize *= 2)); + global->tokenbuf[ct++] = c; /* Store token byte */ + nhash += c; /* Update hash value */ c = get(global); } while (type[c] == LET || type[c] == DIG); unget(global); /* Rescan terminator */ - global->tokenbuf[ct] = EOS; /* Terminate token */ + global->tokenbuf[ct] = EOS; /* Terminate token */ if (isrecurse) /* Recursive definition */ return(NULL); /* undefined just now */ - nhash += ct; /* Fix hash value */ - dp = global->symtab[nhash % SBSIZE]; /* Starting bucket */ + nhash += ct; /* Fix hash value */ + dp = global->symtab[nhash % SBSIZE]; /* Starting bucket */ while (dp != (DEFBUF *) NULL) { /* Search symbol table */ if (dp->hash == nhash /* Fast precheck */ - && (temp = strcmp(dp->name, global->tokenbuf)) >= 0) + && (temp = strcmp(dp->name, global->tokenbuf)) >= 0) break; - dp = dp->link; /* Nope, try next one */ + dp = dp->link; /* Nope, try next one */ } return((temp == 0) ? dp : NULL); } DEFBUF *defendel(struct Global *global, - char *name, - int delete) /* TRUE to delete a symbol */ + char *name, + int delete) /* TRUE to delete a symbol */ { /* * Enter this name in the lookup table (delete = FALSE) @@ -683,7 +584,7 @@ DEFBUF *defendel(struct Global *global, int nhash; int temp; int size; - + for (nhash = 0, np = name; *np != EOS;) nhash += *np++; size = (np - name); @@ -691,21 +592,21 @@ DEFBUF *defendel(struct Global *global, prevp = &global->symtab[nhash % SBSIZE]; while ((dp = *prevp) != (DEFBUF *) NULL) { if (dp->hash == nhash - && (temp = strcmp(dp->name, name)) >= 0) { + && (temp = strcmp(dp->name, name)) >= 0) { if (temp > 0) - dp = NULL; /* Not found */ + dp = NULL; /* Not found */ else { - *prevp = dp->link; /* Found, unlink and */ - if (dp->repl != NULL) /* Free the replacement */ - Freemem(dp->repl); /* if any, and then */ - Freemem((char *) dp); /* Free the symbol */ + *prevp = dp->link; /* Found, unlink and */ + if (dp->repl != NULL) /* Free the replacement */ + free(dp->repl); /* if any, and then */ + free((char *) dp); /* Free the symbol */ } break; } prevp = &dp->link; } if (!delete) { - dp = (DEFBUF *) Getmem(global, (int) (sizeof (DEFBUF) + size)); + dp = (DEFBUF *) malloc((int) (sizeof (DEFBUF) + size)); dp->link = *prevp; *prevp = dp; dp->hash = nhash; @@ -721,12 +622,12 @@ void outdefines(struct Global *global) { DEFBUF *dp; DEFBUF **syp; - + deldefines(global); /* Delete built-in #defines */ for (syp = global->symtab; syp < &global->symtab[SBSIZE]; syp++) { if ((dp = *syp) != (DEFBUF *) NULL) { do { - outadefine(global, dp); + outadefine(global, dp); } while ((dp = dp->link) != (DEFBUF *) NULL); } } @@ -737,7 +638,7 @@ void outadefine(struct Global *global, DEFBUF *dp) { char *cp; int c; - + /* printf("#define %s", dp->name); */ Putstring(global, "#define "); Putstring(global, dp->name); @@ -763,35 +664,35 @@ void outadefine(struct Global *global, DEFBUF *dp) Putchar(global, '\t'); for (cp = dp->repl; (c = *cp++ & 0xFF) != EOS;) { if (c >= MAC_PARM && c < (MAC_PARM + PAR_MAC)) { - /* printf("__%d", c - MAC_PARM + 1); */ - Putstring(global, "__"); - Putint(global, c - MAC_PARM + 1); + /* printf("__%d", c - MAC_PARM + 1); */ + Putstring(global, "__"); + Putint(global, c - MAC_PARM + 1); } else if (isprint(c) || c == '\t' || c == '\n') - Putchar(global, c); + Putchar(global, c); else switch (c) { case QUOTE_PARM: - Putchar(global, '#'); - break; - case DEF_MAGIC: /* Special anti-recursion */ + Putchar(global, '#'); + break; + case DEF_MAGIC: /* Special anti-recursion */ case MAC_PARM + PAR_MAC: /* Special "arg" marker */ - break; + break; case COM_SEP: #if COMMENT_INVISIBLE - Putstring(global, "/**/"); + Putstring(global, "/**/"); #else - Putchar(global, ' '); + Putchar(global, ' '); #endif - break; + break; case TOK_SEP: - Putstring(global, "##"); - break; + Putstring(global, "##"); + break; default: - { - /* Octal output! */ - char buffer[32]; - sprintf(buffer, "\\0%o", c); - Putstring(global, buffer); - } + { + /* Octal output! */ + char buffer[32]; + sprintf(buffer, "\\0%o", c); + Putstring(global, buffer); + } } } } @@ -799,7 +700,7 @@ void outadefine(struct Global *global, DEFBUF *dp) } /* - * G E T + * G E T */ int get(struct Global *global) @@ -811,9 +712,9 @@ int get(struct Global *global) int c; FILEINFO *file; - int popped; /* Recursion fixup */ + int popped; /* Recursion fixup */ long comments=0; - + popped = 0; get_from_file: if ((file = global->infile) == NULL) @@ -836,9 +737,9 @@ int get(struct Global *global) popped++; global->recursion -= file->unrecur; if (global->recursion < 0) - global->recursion = 0; - global->infile = file->parent; /* Unwind file chain */ - } else { /* Else get from a file */ + global->recursion = 0; + global->infile = file->parent; /* Unwind file chain */ + } else { /* Else get from a file */ /* * If a input routine has been specified in the initial taglist, * we should get the next line from that function IF we're reading @@ -846,70 +747,70 @@ int get(struct Global *global) */ if(global->input && global->first_file && !strcmp(global->first_file, file->filename)) - file->bptr = global->input(file->buffer, NBUFF, global->userdata); - else - file->bptr = fgets(file->buffer, NBUFF, file->fp); + file->bptr = global->input(file->buffer, NBUFF, global->userdata); + else + file->bptr = fgets(file->buffer, NBUFF, file->fp); if(file->bptr != NULL) { - goto newline; /* process the line */ + goto newline; /* process the line */ } else { - if(!(global->input && global->first_file && !strcmp(global->first_file, file->filename))) - /* If the input function isn't user supplied, close the file! */ - fclose(file->fp); /* Close finished file */ - if ((global->infile = file->parent) != NULL) { - /* - * There is an "ungotten" newline in the current - * infile buffer (set there by doinclude() in - * cpp1.c). Thus, we know that the mainline code - * is skipping over blank lines and will do a - * #line at its convenience. - */ - global->wrongline = TRUE; /* Need a #line now */ - } + if(!(global->input && global->first_file && !strcmp(global->first_file, file->filename))) + /* If the input function isn't user supplied, close the file! */ + fclose(file->fp); /* Close finished file */ + if ((global->infile = file->parent) != NULL) { + /* + * There is an "ungotten" newline in the current + * infile buffer (set there by doinclude() in + * cpp1.c). Thus, we know that the mainline code + * is skipping over blank lines and will do a + * #line at its convenience. + */ + global->wrongline = TRUE; /* Need a #line now */ + } } } /* * Free up space used by the (finished) file or macro and * restart input from the parent file/macro, if any. */ - Freemem(file->filename); /* Free name and */ + free(file->filename); /* Free name and */ if (file->progname != NULL) /* if a #line was seen, */ - Freemem(file->progname); /* free it, too. */ - Freemem(file); /* Free file space */ + free(file->progname); /* free it, too. */ + free(file); /* Free file space */ if (global->infile == NULL) /* If at end of file */ return (EOF_CHAR); /* Return end of file */ - global->line = global->infile->line; /* Reset line number */ - goto get_from_file; /* Get from the top. */ + global->line = global->infile->line; /* Reset line number */ + goto get_from_file; /* Get from the top. */ } /* * Common processing for the new character. */ if (c == DEF_MAGIC && file->fp != NULL) /* Don't allow delete */ - goto newline; /* from a file */ + goto newline; /* from a file */ if (file->parent != NULL) { /* Macro or #include */ if (popped != 0) file->parent->unrecur += popped; else { global->recursion -= file->parent->unrecur; if (global->recursion < 0) - global->recursion = 0; + global->recursion = 0; file->parent->unrecur = 0; } } if (c == '\n') /* Maintain current */ - ++global->line; /* line counter */ + ++global->line; /* line counter */ if (global->instring) /* Strings just return */ return (c); /* the character. */ else if (c == '/') { /* Comment? */ - global->instring = TRUE; /* So get() won't loop */ + global->instring = TRUE; /* So get() won't loop */ /* Check next byte for '*' and if(cplusplus) also '/' */ if ( (c = get(global)) != '*' ) if(!global->cplusplus || (global->cplusplus && c!='/')) { - global->instring = FALSE; /* Nope, no comment */ - unget(global); /* Push the char. back */ - return ('/'); /* Return the slash */ + global->instring = FALSE; /* Nope, no comment */ + unget(global); /* Push the char. back */ + return ('/'); /* Return the slash */ } - + comments = 1; if (global->keepcomments) { /* If writing comments */ @@ -922,100 +823,100 @@ int get(struct Global *global) } if(c=='*') { - Putchar(global, '/'); /* Write out the */ - Putchar(global, '*'); /* initializer */ + Putchar(global, '/'); /* Write out the */ + Putchar(global, '*'); /* initializer */ } else { - /* C++ style comment */ - Putchar(global, '/'); /* Write out the */ - Putchar(global, '/'); /* initializer */ + /* C++ style comment */ + Putchar(global, '/'); /* Write out the */ + Putchar(global, '/'); /* initializer */ } } if(global->cplusplus && c=='/') { /* Eat C++ comment! */ do { - c=get(global); - if(global->keepcomments) - Putchar(global, c); + c=get(global); + if(global->keepcomments) + Putchar(global, c); } while(c!='\n' && c!=EOF_CHAR); /* eat all to EOL or EOF */ - global->instring = FALSE; /* End of comment */ - return(c); /* Return the end char */ + global->instring = FALSE; /* End of comment */ + return(c); /* Return the end char */ } for (;;) { /* Eat a comment */ c = get(global); test: if (global->keepcomments && c != EOF_CHAR) - Putchar(global, c); + Putchar(global, c); switch (c) { case EOF_CHAR: - cerror(global, ERROR_EOF_IN_COMMENT); - return (EOF_CHAR); + cerror(global, ERROR_EOF_IN_COMMENT); + return (EOF_CHAR); case '/': - if(global->nestcomments || global->warnnestcomments) { - if((c = get(global)) != '*') - goto test; - if(global->warnnestcomments) { - cwarn(global, WARN_NESTED_COMMENT); - } - if(global->nestcomments) - comments++; - } - break; - - case '*': - if ((c = get(global)) != '/') /* If comment doesn't */ - goto test; /* end, look at next */ - if (global->keepcomments) { /* Put out the comment */ - Putchar(global, c); /* terminator, too */ - } - if(--comments) - /* nested comment, continue! */ - break; + if(global->nestcomments || global->warnnestcomments) { + if((c = get(global)) != '*') + goto test; + if(global->warnnestcomments) { + cwarn(global, WARN_NESTED_COMMENT); + } + if(global->nestcomments) + comments++; + } + break; - global->instring = FALSE; /* End of comment, */ - /* - * A comment is syntactically "whitespace" -- - * however, there are certain strange sequences - * such as - * #define foo(x) (something) - * foo|* comment *|(123) - * these are '/' ^ ^ - * where just returning space (or COM_SEP) will cause - * problems. This can be "fixed" by overwriting the - * '/' in the input line buffer with ' ' (or COM_SEP) - * but that may mess up an error message. - * So, we peek ahead -- if the next character is - * "whitespace" we just get another character, if not, - * we modify the buffer. All in the name of purity. - */ - if (*file->bptr == '\n' - || type[*file->bptr & 0xFF] == SPA) - goto newline; + case '*': + if ((c = get(global)) != '/') /* If comment doesn't */ + goto test; /* end, look at next */ + if (global->keepcomments) { /* Put out the comment */ + Putchar(global, c); /* terminator, too */ + } + if(--comments) + /* nested comment, continue! */ + break; + + global->instring = FALSE; /* End of comment, */ + /* + * A comment is syntactically "whitespace" -- + * however, there are certain strange sequences + * such as + * #define foo(x) (something) + * foo|* comment *|(123) + * these are '/' ^ ^ + * where just returning space (or COM_SEP) will cause + * problems. This can be "fixed" by overwriting the + * '/' in the input line buffer with ' ' (or COM_SEP) + * but that may mess up an error message. + * So, we peek ahead -- if the next character is + * "whitespace" we just get another character, if not, + * we modify the buffer. All in the name of purity. + */ + if (*file->bptr == '\n' + || type[*file->bptr & 0xFF] == SPA) + goto newline; #if COMMENT_INVISIBLE - /* - * Return magic (old-fashioned) syntactic space. - */ - return ((file->bptr[-1] = COM_SEP)); + /* + * Return magic (old-fashioned) syntactic space. + */ + return ((file->bptr[-1] = COM_SEP)); #else - return ((file->bptr[-1] = ' ')); + return ((file->bptr[-1] = ' ')); #endif - - case '\n': /* we'll need a #line */ - if (!global->keepcomments) - global->wrongline = TRUE; /* later... */ - default: /* Anything else is */ - break; /* Just a character */ - } /* End switch */ - } /* End comment loop */ - } /* End if in comment */ + + case '\n': /* we'll need a #line */ + if (!global->keepcomments) + global->wrongline = TRUE; /* later... */ + default: /* Anything else is */ + break; /* Just a character */ + } /* End switch */ + } /* End comment loop */ + } /* End if in comment */ else if (!global->inmacro && c == '\\') { /* If backslash, peek */ if ((c = get(global)) == '\n') { /* for a . If so, */ global->wrongline = TRUE; goto newline; - } else { /* Backslash anything */ - unget(global); /* Get it later */ - return ('\\'); /* Return the backslash */ + } else { /* Backslash anything */ + unget(global); /* Get it later */ + return ('\\'); /* Return the backslash */ } } else if (c == '\f' || c == VT) /* Form Feed, Vertical */ c = ' '; /* Tab are whitespace */ @@ -1030,17 +931,17 @@ void unget(struct Global *global) * without problems, at end of file. Only one character may * be ungotten. If you need to unget more, call ungetstring(). */ - + FILEINFO *file; if ((file = global->infile) == NULL) - return; /* Unget after EOF */ + return; /* Unget after EOF */ if (--file->bptr < file->buffer) { cfatal(global, FATAL_TOO_MUCH_PUSHBACK); /* This happens only if used the wrong way! */ return; } - if (*file->bptr == '\n') /* Ungetting a newline? */ - --global->line; /* Unget the line number, too */ + if (*file->bptr == '\n') /* Ungetting a newline? */ + --global->line; /* Unget the line number, too */ } ReturnCode ungetstring(struct Global *global, char *text) @@ -1052,7 +953,7 @@ ReturnCode ungetstring(struct Global *global, char *text) FILEINFO *file; ReturnCode ret; - + ret = getfile(global, strlen(text) + 1, "", &file); if(!ret) strcpy(file->buffer, text); @@ -1066,7 +967,7 @@ int cget(struct Global *global) * token concatenation */ - int c; + int c; do { c = get(global); #if COMMENT_INVISIBLE @@ -1089,7 +990,7 @@ void domsg(struct Global *global, /* * Print filenames, macro names, and line numbers for error messages. */ - + static char *ErrorMessage[]={ /* * ERRORS: @@ -1171,18 +1072,18 @@ void domsg(struct Global *global, "Out of memory", "Too much pushback", /* internal */ }; - + char *tp; FILEINFO *file; char *severity=errorinfile; file && !file->fp; file = file->parent) ; tp = file ? file->filename : 0; Error(global, "%s\"%s\", line %d: %s: ", - MSG_PREFIX, tp, global->infile->fp?global->line:file->line, severity); + MSG_PREFIX, tp, global->infile->fp?global->line:file->line, severity); if(global->error) global->error(global->userdata, ErrorMessage[error], arg); #if defined(UNIX) @@ -1193,26 +1094,26 @@ void domsg(struct Global *global, return; #endif Error(global, "\n"); - + if (file) /*OIS*0.92*/ while ((file = file->parent) != NULL) { /* Print #includes, too */ tp = file->parent ? "," : "."; if (file->fp == NULL) - Error(global, " from macro %s%s\n", file->filename, tp); + Error(global, " from macro %s%s\n", file->filename, tp); else - Error(global, " from file %s, line %d%s\n", - (file->progname != NULL) ? file->progname : file->filename, - file->line, tp); + Error(global, " from file %s, line %d%s\n", + (file->progname != NULL) ? file->progname : file->filename, + file->line, tp); } - + if(errorerrors++; } void cerror(struct Global *global, - ErrorCode message, - ...) /* arguments */ + ErrorCode message, + ...) /* arguments */ { /* * Print a normal error message, string argument. diff --git a/makefile b/makefile index 7b0c7e3..ec75d60 100644 --- a/makefile +++ b/makefile @@ -42,8 +42,8 @@ CFLAGS = $(DEBUGFLAG) $(DEFINES) AR = ar ARFLAGS = rv .SUFFIXES: .o .c .c~ .h .h~ .a .i -OBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o memory.o -FILEOBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o memory.o usecpp.o +OBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o +FILEOBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o usecpp.o # ** compile cpp # diff --git a/memory.c b/memory.c deleted file mode 100644 index 9e0a2b3..0000000 --- a/memory.c +++ /dev/null @@ -1,214 +0,0 @@ -/****************************************************************************** -Copyright (c) 1999 Daniel Stenberg - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -******************************************************************************/ -/****************************************************************************** - * FREXXWARE - * ---------------------------------------------------------------------------- - * - * Project: Frexx C Preprocessor - * $Source: /home/user/start/cpp/RCS/memory.c,v $ - * $Revision: 1.2 $ - * $Date: 1994/01/24 09:36:46 $ - * $Author: start $ - * $State: Exp $ - * $Locker: $ - * - * ---------------------------------------------------------------------------- - * $Log: memory.c,v $ - * Revision 1.2 1994/01/24 09:36:46 start - * Made it run with OS9 properly. - * - * Revision 1.1 1993/11/03 09:13:08 start - * Initial revision - * - * - *****************************************************************************/ - -#include -#include -#if defined(OS9) -#include -#elif defined(UNIX) -#include -#elif defined(AMIGA) -#include -#include -#endif - -#include - -#include "memory.h" -#ifdef DEBUG -int mem; -int maxmem; -int malloc_count=0; -#endif - -/* - * We have two mallockey pointers because we have two different kinds of - * Malloc()s! One for each execution and one for each fplInit(). - */ -static struct MemInfo *MallocKey=NULL; - -void *Realloc(void *ptr, int size) -{ - struct MemInfo *point; - void *new; - /* `point' points to the MemInfo structure: */ - point=(struct MemInfo *)((char *)ptr-sizeof(struct MemInfo)); - - if(size<=point->size) - /* - * To increase performance, don't care about reallocing - * to smaller sizes! - */ - return(ptr); - new=Malloc(size); /* allocate new storage */ - if(!new) - return(NULL); /* fail! */ - - memcpy(new, ptr, point->size); /* copy contents */ - - Free(ptr); /* free old area */ - - return(new); /* return new pointer */ -} - - -void *Malloc(int size) -{ - char *alloc; - struct MemInfo *point; - -#ifdef DEBUG - size+=MEMORY_COOKIE; /* add extra bytes after the block! */ -#endif - -#ifdef AMIGA - alloc=(char *)AllocMem(size+sizeof(struct MemInfo), 0L); -#elif defined(UNIX) - alloc=(char *)malloc(size+sizeof(struct MemInfo)); -#endif - - if(!alloc) - return(NULL); - - point=(struct MemInfo *)alloc; - point->prev=MallocKey; /* previous */ - point->next=NULL; /* next */ - point->size=size; /* size */ -#ifdef DEBUG - malloc_count++; - mem+=size+sizeof(struct MemInfo); - if(mem>maxmem) - maxmem=mem; - - memset((void *)((char *)point+sizeof(struct MemInfo)), 0xbb, size); -#endif - if(MallocKey) - point->prev->next=point; - - MallocKey = (void *)point; - - alloc = ((char *)point+sizeof(struct MemInfo)); - return ((void *)alloc); -} - -void Free(void *ptr) -{ - struct MemInfo *point; - /* `point' points to the MemInfo structure: */ - point=(struct MemInfo *)((char *)ptr-sizeof(struct MemInfo)); - - if(MallocKey==point) { - /* if this is the last Malloc, set `last' to `prev' */ - MallocKey=point->prev; - if(MallocKey) - MallocKey->next=NULL; - } else { - /* point the previous' `next' to our `next', and our next `previous' - to our `previous'. Unlink us from the chain */ - if(point->prev) - /* only if we aren't the _first_ Malloc() ! */ - point->prev->next=point->next; - if(point->next) - /* only if there is a next! */ - point->next->prev=point->prev; - } -#ifdef DEBUG - mem-=point->size+sizeof(struct MemInfo); - - CheckMem(ptr); -#endif - -#ifdef AMIGA - FreeMem(point, point->size+sizeof(struct MemInfo)); -#elif UNIX - free(point); -#endif -} - -#ifdef DEBUG -void CheckMem(void *ptr) -{ - int i; - int b=0; - struct MemInfo *point; - /* `point' points to the MemInfo structure: */ - point=(struct MemInfo *)((char *)ptr-sizeof(struct MemInfo)); - for(i=0;isize-MEMORY_COOKIE)!= 0xbb) - b++; - - if(b) { -#if defined(UNIX) - fprintf(stderr, "Memory violation: malloc(%d) was abused %d bytes!\n", - point->size-MEMORY_COOKIE-sizeof(struct MemInfo), b); -#elif defined(AMIGA) - /* ERROR */; -#endif - } -} -#endif - -void FreeAll(void) -{ - struct MemInfo *point; - void *prev; - - if(!MallocKey) - return; - do { - point=MallocKey; - /* `point' points to the MemInfo structure! */ - - prev=(void *)point->prev; - -#ifdef DEBUG - mem-=point->size+sizeof(struct MemInfo); -#endif -#ifdef AMIGA - FreeMem(MallocKey, point->size+sizeof(struct MemInfo)); -#elif UNIX - free((char *)MallocKey); -#endif - } while(MallocKey=prev); -}