cleanups
Remove the custom malloc/free system Remove commit history from comment headers
This commit is contained in:
parent
96e325a259
commit
cb6929f773
181
cpp1.c
181
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
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
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 <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 <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
@ -211,7 +44,7 @@ int PREFIX fppPreProcess(REG(a0) struct fppTag *tags)
|
|||||||
ReturnCode ret; /* cpp return code */
|
ReturnCode ret; /* cpp return code */
|
||||||
struct Global *global;
|
struct Global *global;
|
||||||
|
|
||||||
global=(struct Global *)Malloc(sizeof(struct Global));
|
global=(struct Global *)malloc(sizeof(struct Global));
|
||||||
if(!global)
|
if(!global)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
|
|
||||||
@ -311,8 +144,6 @@ int PREFIX fppPreProcess(REG(a0) struct fppTag *tags)
|
|||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
fclose(stdout);
|
fclose(stdout);
|
||||||
|
|
||||||
FreeAll(); /* free all unfreed memory! */
|
|
||||||
|
|
||||||
if (global->errors > 0 && !global->eflag)
|
if (global->errors > 0 && !global->eflag)
|
||||||
return(IO_ERROR);
|
return(IO_ERROR);
|
||||||
return(IO_NORMAL); /* No errors or -E option set */
|
return(IO_NORMAL); /* No errors or -E option set */
|
||||||
@ -348,17 +179,17 @@ ReturnCode cppmain(struct Global *global)
|
|||||||
|
|
||||||
/* Initialize for reading tokens */
|
/* Initialize for reading tokens */
|
||||||
global->tokenbsize = 50;
|
global->tokenbsize = 50;
|
||||||
global->tokenbuf = Getmem(global, global->tokenbsize + 1);
|
global->tokenbuf = malloc(global->tokenbsize + 1);
|
||||||
if(!global->tokenbuf)
|
if(!global->tokenbuf)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
|
|
||||||
global->functionname = Getmem(global, global->tokenbsize + 1);
|
global->functionname = malloc(global->tokenbsize + 1);
|
||||||
if(!global->functionname)
|
if(!global->functionname)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
global->functionname[0] = '\0';
|
global->functionname[0] = '\0';
|
||||||
|
|
||||||
if(global->showspace) {
|
if(global->showspace) {
|
||||||
global->spacebuf = (char *)Getmem(global, MAX_SPACE_SIZE);
|
global->spacebuf = (char *)malloc(MAX_SPACE_SIZE);
|
||||||
if(!global->spacebuf)
|
if(!global->spacebuf)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
}
|
}
|
||||||
@ -747,7 +578,7 @@ void sharp(struct Global *global)
|
|||||||
if (global->sharpfilename == NULL
|
if (global->sharpfilename == NULL
|
||||||
|| (global->sharpfilename != NULL && !streq(name, global->sharpfilename))) {
|
|| (global->sharpfilename != NULL && !streq(name, global->sharpfilename))) {
|
||||||
if (global->sharpfilename != NULL)
|
if (global->sharpfilename != NULL)
|
||||||
Freemem(global->sharpfilename);
|
free(global->sharpfilename);
|
||||||
global->sharpfilename = savestring(global, name);
|
global->sharpfilename = savestring(global, name);
|
||||||
/* printf(" \"%s\"", name); */
|
/* printf(" \"%s\"", name); */
|
||||||
Putstring(global, " \"");
|
Putstring(global, " \"");
|
||||||
|
56
cpp2.c
56
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "cppdef.h"
|
#include "cppdef.h"
|
||||||
@ -292,7 +238,7 @@ ReturnCode control( struct Global *global,
|
|||||||
|
|
||||||
if( global->infile->progname != NULL )
|
if( global->infile->progname != NULL )
|
||||||
/* Give up the old name if it's allocated. */
|
/* Give up the old name if it's allocated. */
|
||||||
Freemem( global->infile->progname );
|
free( global->infile->progname );
|
||||||
|
|
||||||
global->infile->progname = savestring( global, tp );
|
global->infile->progname = savestring( global, tp );
|
||||||
}
|
}
|
||||||
|
224
cpp3.c
224
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
SOFTWARE.
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
/******************************************************************************
|
#include <stdio.h>
|
||||||
* FREXXWARE
|
#include <ctype.h>
|
||||||
* ----------------------------------------------------------------------------
|
#include <time.h> /*OIS*0.92*/
|
||||||
*
|
#include "cppdef.h"
|
||||||
* Project: Frexx C Preprocessor
|
#include "cpp.h"
|
||||||
* $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 <stdio.h>
|
|
||||||
#include <ctype.h>
|
|
||||||
#include <time.h> /*OIS*0.92*/
|
|
||||||
#include "cppdef.h"
|
|
||||||
#include "cpp.h"
|
|
||||||
|
|
||||||
ReturnCode openfile(struct Global *global, char *filename)
|
ReturnCode openfile(struct Global *global, char *filename)
|
||||||
{
|
{
|
||||||
@ -91,17 +41,17 @@ ReturnCode openfile(struct Global *global, char *filename)
|
|||||||
ret=addfile(global, fp, filename);
|
ret=addfile(global, fp, filename);
|
||||||
|
|
||||||
if(!ret && global->showincluded) {
|
if(!ret && global->showincluded) {
|
||||||
/* no error occured! */
|
/* no error occured! */
|
||||||
Error(global, "cpp: included \"");
|
Error(global, "cpp: included \"");
|
||||||
Error(global, filename);
|
Error(global, filename);
|
||||||
Error(global, "\"\n");
|
Error(global, "\"\n");
|
||||||
}
|
}
|
||||||
return(ret);
|
return(ret);
|
||||||
}
|
}
|
||||||
|
|
||||||
ReturnCode addfile(struct Global *global,
|
ReturnCode addfile(struct Global *global,
|
||||||
FILE *fp, /* Open file pointer */
|
FILE *fp, /* Open file pointer */
|
||||||
char *filename) /* Name of the file */
|
char *filename) /* Name of the file */
|
||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Initialize tables for this open file. This is called from openfile()
|
* Initialize tables for this open file. This is called from openfile()
|
||||||
@ -117,10 +67,10 @@ ReturnCode addfile(struct Global *global,
|
|||||||
ret = getfile(global, NBUFF, filename, &file);
|
ret = getfile(global, NBUFF, filename, &file);
|
||||||
if(ret)
|
if(ret)
|
||||||
return(ret);
|
return(ret);
|
||||||
file->fp = fp; /* Better remember FILE * */
|
file->fp = fp; /* Better remember FILE * */
|
||||||
file->buffer[0] = EOS; /* Initialize for first read */
|
file->buffer[0] = EOS; /* Initialize for first read */
|
||||||
global->line = 1; /* Working on line 1 now */
|
global->line = 1; /* Working on line 1 now */
|
||||||
global->wrongline = TRUE; /* Force out initial #line */
|
global->wrongline = TRUE; /* Force out initial #line */
|
||||||
return(FPP_OK);
|
return(FPP_OK);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -179,8 +129,8 @@ int dooptions(struct Global *global, struct fppTag *tags)
|
|||||||
break;
|
break;
|
||||||
case FPPTAG_KEEPCOMMENTS:
|
case FPPTAG_KEEPCOMMENTS:
|
||||||
if(tags->data) {
|
if(tags->data) {
|
||||||
global->cflag = TRUE;
|
global->cflag = TRUE;
|
||||||
global->keepcomments = TRUE;
|
global->keepcomments = TRUE;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FPPTAG_DEFINE:
|
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
|
* If the option is just "-Dfoo", make it -Dfoo=1
|
||||||
*/
|
*/
|
||||||
{
|
{
|
||||||
char *symbol=(char *)tags->data;
|
char *symbol=(char *)tags->data;
|
||||||
char *text=symbol;
|
char *text=symbol;
|
||||||
while (*text != EOS && *text != '=')
|
while (*text != EOS && *text != '=')
|
||||||
text++;
|
text++;
|
||||||
if (*text == EOS)
|
if (*text == EOS)
|
||||||
text = "1";
|
text = "1";
|
||||||
else
|
else
|
||||||
*text++ = EOS;
|
*text++ = EOS;
|
||||||
/*
|
/*
|
||||||
* Now, save the word and its definition.
|
* Now, save the word and its definition.
|
||||||
*/
|
*/
|
||||||
dp = defendel(global, symbol, FALSE);
|
dp = defendel(global, symbol, FALSE);
|
||||||
if(!dp)
|
if(!dp)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
dp->repl = savestring(global, text);
|
dp->repl = savestring(global, text);
|
||||||
dp->nargs = DEF_NOARGS;
|
dp->nargs = DEF_NOARGS;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FPPTAG_IGNORE_NONFATAL:
|
case FPPTAG_IGNORE_NONFATAL:
|
||||||
@ -211,21 +161,21 @@ int dooptions(struct Global *global, struct fppTag *tags)
|
|||||||
break;
|
break;
|
||||||
case FPPTAG_INCLUDE_DIR:
|
case FPPTAG_INCLUDE_DIR:
|
||||||
if (global->incend >= &global->incdir[NINCLUDE]) {
|
if (global->incend >= &global->incdir[NINCLUDE]) {
|
||||||
cfatal(global, FATAL_TOO_MANY_INCLUDE_DIRS);
|
cfatal(global, FATAL_TOO_MANY_INCLUDE_DIRS);
|
||||||
return(FPP_TOO_MANY_INCLUDE_DIRS);
|
return(FPP_TOO_MANY_INCLUDE_DIRS);
|
||||||
}
|
}
|
||||||
*global->incend++ = (char *)tags->data;
|
*global->incend++ = (char *)tags->data;
|
||||||
break;
|
break;
|
||||||
case FPPTAG_INCLUDE_FILE:
|
case FPPTAG_INCLUDE_FILE:
|
||||||
case FPPTAG_INCLUDE_MACRO_FILE:
|
case FPPTAG_INCLUDE_MACRO_FILE:
|
||||||
if (global->included >= NINCLUDE) {
|
if (global->included >= NINCLUDE) {
|
||||||
cfatal(global, FATAL_TOO_MANY_INCLUDE_FILES);
|
cfatal(global, FATAL_TOO_MANY_INCLUDE_FILES);
|
||||||
return(FPP_TOO_MANY_INCLUDE_FILES);
|
return(FPP_TOO_MANY_INCLUDE_FILES);
|
||||||
}
|
}
|
||||||
global->include[global->included] = (char *)tags->data;
|
global->include[global->included] = (char *)tags->data;
|
||||||
|
|
||||||
global->includeshow[global->included] =
|
global->includeshow[global->included] =
|
||||||
(tags->tag == FPPTAG_INCLUDE_FILE);
|
(tags->tag == FPPTAG_INCLUDE_FILE);
|
||||||
|
|
||||||
global->included++;
|
global->included++;
|
||||||
break;
|
break;
|
||||||
@ -240,45 +190,45 @@ int dooptions(struct Global *global, struct fppTag *tags)
|
|||||||
break;
|
break;
|
||||||
case FPPTAG_SIZEOF_TABLE:
|
case FPPTAG_SIZEOF_TABLE:
|
||||||
{
|
{
|
||||||
SIZES *sizp; /* For -S */
|
SIZES *sizp; /* For -S */
|
||||||
int size; /* For -S */
|
int size; /* For -S */
|
||||||
int isdatum; /* FALSE for -S* */
|
int isdatum; /* FALSE for -S* */
|
||||||
int endtest; /* For -S */
|
int endtest; /* For -S */
|
||||||
|
|
||||||
char *text=(char *)tags->data;
|
char *text=(char *)tags->data;
|
||||||
|
|
||||||
sizp = size_table;
|
sizp = size_table;
|
||||||
if (isdatum = (*text != '*')) /* If it's just -S, */
|
if (isdatum = (*text != '*')) /* If it's just -S, */
|
||||||
endtest = T_FPTR; /* Stop here */
|
endtest = T_FPTR; /* Stop here */
|
||||||
else { /* But if it's -S* */
|
else { /* But if it's -S* */
|
||||||
text++; /* Step over '*' */
|
text++; /* Step over '*' */
|
||||||
endtest = 0; /* Stop at end marker */
|
endtest = 0; /* Stop at end marker */
|
||||||
}
|
}
|
||||||
while (sizp->bits != endtest && *text != EOS) {
|
while (sizp->bits != endtest && *text != EOS) {
|
||||||
if (!isdigit(*text)) { /* Skip to next digit */
|
if (!isdigit(*text)) { /* Skip to next digit */
|
||||||
text++;
|
text++;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
size = 0; /* Compile the value */
|
size = 0; /* Compile the value */
|
||||||
while (isdigit(*text)) {
|
while (isdigit(*text)) {
|
||||||
size *= 10;
|
size *= 10;
|
||||||
size += (*text++ - '0');
|
size += (*text++ - '0');
|
||||||
}
|
}
|
||||||
if (isdatum)
|
if (isdatum)
|
||||||
sizp->size = size; /* Datum size */
|
sizp->size = size; /* Datum size */
|
||||||
else
|
else
|
||||||
sizp->psize = size; /* Pointer size */
|
sizp->psize = size; /* Pointer size */
|
||||||
sizp++;
|
sizp++;
|
||||||
}
|
}
|
||||||
if (sizp->bits != endtest)
|
if (sizp->bits != endtest)
|
||||||
cwarn(global, WARN_TOO_FEW_VALUES_TO_SIZEOF, NULL);
|
cwarn(global, WARN_TOO_FEW_VALUES_TO_SIZEOF, NULL);
|
||||||
else if (*text != EOS)
|
else if (*text != EOS)
|
||||||
cwarn(global, WARN_TOO_MANY_VALUES_TO_SIZEOF, NULL);
|
cwarn(global, WARN_TOO_MANY_VALUES_TO_SIZEOF, NULL);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case FPPTAG_UNDEFINE:
|
case FPPTAG_UNDEFINE:
|
||||||
if (defendel(global, (char *)tags->data, TRUE) == NULL)
|
if (defendel(global, (char *)tags->data, TRUE) == NULL)
|
||||||
cwarn(global, WARN_NOT_DEFINED, tags->data);
|
cwarn(global, WARN_NOT_DEFINED, tags->data);
|
||||||
break;
|
break;
|
||||||
case FPPTAG_OUTPUT_DEFINES:
|
case FPPTAG_OUTPUT_DEFINES:
|
||||||
global->wflag++;
|
global->wflag++;
|
||||||
@ -321,8 +271,8 @@ ReturnCode initdefines(struct Global *global)
|
|||||||
{
|
{
|
||||||
/*
|
/*
|
||||||
* Initialize the built-in #define's. There are two flavors:
|
* Initialize the built-in #define's. There are two flavors:
|
||||||
* #define decus 1 (static definitions)
|
* #define decus 1 (static definitions)
|
||||||
* #define __FILE__ ?? (dynamic, evaluated by magic)
|
* #define __FILE__ ?? (dynamic, evaluated by magic)
|
||||||
* Called only on cpp startup.
|
* Called only on cpp startup.
|
||||||
*
|
*
|
||||||
* Note: the built-in static definitions are supressed by the -N option.
|
* Note: the built-in static definitions are supressed by the -N option.
|
||||||
@ -350,11 +300,11 @@ ReturnCode initdefines(struct Global *global)
|
|||||||
if (!(global->nflag & NFLAG_BUILTIN)) {
|
if (!(global->nflag & NFLAG_BUILTIN)) {
|
||||||
for (pp = global->preset; *pp != NULL; pp++) {
|
for (pp = global->preset; *pp != NULL; pp++) {
|
||||||
if (*pp[0] != EOS) {
|
if (*pp[0] != EOS) {
|
||||||
dp = defendel(global, *pp, FALSE);
|
dp = defendel(global, *pp, FALSE);
|
||||||
if(!dp)
|
if(!dp)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
dp->repl = savestring(global, "1");
|
dp->repl = savestring(global, "1");
|
||||||
dp->nargs = DEF_NOARGS;
|
dp->nargs = DEF_NOARGS;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -368,7 +318,7 @@ ReturnCode initdefines(struct Global *global)
|
|||||||
for (pp = global->magic, i = DEF_NOARGS; *pp != NULL; pp++) {
|
for (pp = global->magic, i = DEF_NOARGS; *pp != NULL; pp++) {
|
||||||
dp = defendel(global, *pp, FALSE);
|
dp = defendel(global, *pp, FALSE);
|
||||||
if(!dp)
|
if(!dp)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
dp->nargs = --i;
|
dp->nargs = --i;
|
||||||
}
|
}
|
||||||
#if OK_DATE
|
#if OK_DATE
|
||||||
@ -376,7 +326,7 @@ ReturnCode initdefines(struct Global *global)
|
|||||||
* Define __DATE__ as today's date.
|
* Define __DATE__ as today's date.
|
||||||
*/
|
*/
|
||||||
dp = defendel(global, "__DATE__", FALSE);
|
dp = defendel(global, "__DATE__", FALSE);
|
||||||
tp = Getmem(global, 14);
|
tp = malloc(14);
|
||||||
if(!tp || !dp)
|
if(!tp || !dp)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
dp->repl = tp;
|
dp->repl = tp;
|
||||||
@ -384,23 +334,23 @@ ReturnCode initdefines(struct Global *global)
|
|||||||
time(&tvec);
|
time(&tvec);
|
||||||
tm = localtime(&tvec);
|
tm = localtime(&tvec);
|
||||||
sprintf(tp, "\"%3s %2d %4d\"", /* "Aug 20 1988" */
|
sprintf(tp, "\"%3s %2d %4d\"", /* "Aug 20 1988" */
|
||||||
months[tm->tm_mon],
|
months[tm->tm_mon],
|
||||||
tm->tm_mday,
|
tm->tm_mday,
|
||||||
tm->tm_year + 1900);
|
tm->tm_year + 1900);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Define __TIME__ as this moment's time.
|
* Define __TIME__ as this moment's time.
|
||||||
*/
|
*/
|
||||||
dp = defendel(global, "__TIME__", FALSE);
|
dp = defendel(global, "__TIME__", FALSE);
|
||||||
tp = Getmem(global, 11);
|
tp = malloc(11);
|
||||||
if(!tp || !dp)
|
if(!tp || !dp)
|
||||||
return(FPP_OUT_OF_MEMORY);
|
return(FPP_OUT_OF_MEMORY);
|
||||||
dp->repl = tp;
|
dp->repl = tp;
|
||||||
dp->nargs = DEF_NOARGS;
|
dp->nargs = DEF_NOARGS;
|
||||||
sprintf(tp, "\"%2d:%02d:%02d\"", /* "20:42:31" */
|
sprintf(tp, "\"%2d:%02d:%02d\"", /* "20:42:31" */
|
||||||
tm->tm_hour,
|
tm->tm_hour,
|
||||||
tm->tm_min,
|
tm->tm_min,
|
||||||
tm->tm_sec);
|
tm->tm_sec);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
return(FPP_OK);
|
return(FPP_OK);
|
||||||
|
49
cpp4.c
49
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "cppdef.h"
|
#include "cppdef.h"
|
||||||
@ -265,7 +218,7 @@ ReturnCode dodefine(struct Global *global)
|
|||||||
cerror(global, ERROR_REDEFINE, dp->name);
|
cerror(global, ERROR_REDEFINE, dp->name);
|
||||||
}
|
}
|
||||||
if (old != NULL) /* We don't need the */
|
if (old != NULL) /* We don't need the */
|
||||||
Freemem(old); /* old definition now. */
|
free(old); /* old definition now. */
|
||||||
}
|
}
|
||||||
return(FPP_OK);
|
return(FPP_OK);
|
||||||
}
|
}
|
||||||
|
44
cpp5.c
44
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
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
SOFTWARE.
|
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 <stdio.h>
|
#include <stdio.h>
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
#include "cppdef.h"
|
#include "cppdef.h"
|
||||||
|
4
makefile
4
makefile
@ -42,8 +42,8 @@ CFLAGS = $(DEBUGFLAG) $(DEFINES)
|
|||||||
AR = ar
|
AR = ar
|
||||||
ARFLAGS = rv
|
ARFLAGS = rv
|
||||||
.SUFFIXES: .o .c .c~ .h .h~ .a .i
|
.SUFFIXES: .o .c .c~ .h .h~ .a .i
|
||||||
OBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o memory.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 memory.o usecpp.o
|
FILEOBJS = cpp1.o cpp2.o cpp3.o cpp4.o cpp5.o cpp6.o usecpp.o
|
||||||
|
|
||||||
# ** compile cpp
|
# ** compile cpp
|
||||||
#
|
#
|
||||||
|
214
memory.c
214
memory.c
@ -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 <string.h>
|
|
||||||
#include <stdlib.h>
|
|
||||||
#if defined(OS9)
|
|
||||||
#include <types.h>
|
|
||||||
#elif defined(UNIX)
|
|
||||||
#include <sys/types.h>
|
|
||||||
#elif defined(AMIGA)
|
|
||||||
#include <exec/types.h>
|
|
||||||
#include <proto/exec.h>
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#include <stdio.h>
|
|
||||||
|
|
||||||
#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;i<MEMORY_COOKIE; i++)
|
|
||||||
if(*((unsigned char *)point+sizeof(struct MemInfo)+i+point->size-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);
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user