]> git.sur5r.net Git - cc65/commitdiff
More common subroutines
authorcuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 14 Jun 2000 09:32:22 +0000 (09:32 +0000)
committercuz <cuz@b7a2c559-68d2-44c3-8de9-860c34a00d81>
Wed, 14 Jun 2000 09:32:22 +0000 (09:32 +0000)
git-svn-id: svn://svn.cc65.org/cc65/trunk@69 b7a2c559-68d2-44c3-8de9-860c34a00d81

30 files changed:
src/ca65/expr.c
src/ca65/fname.c [deleted file]
src/ca65/global.c
src/ca65/global.h
src/ca65/incpath.c
src/ca65/istack.c
src/ca65/listing.c
src/ca65/macro.c
src/ca65/main.c
src/ca65/make/gcc.mak
src/ca65/make/watcom.mak
src/ca65/mem.c [deleted file]
src/ca65/mem.h [deleted file]
src/ca65/objcode.c
src/ca65/objfile.c
src/ca65/options.c
src/ca65/scanner.c
src/ca65/symtab.c
src/ca65/toklist.c
src/ca65/ulabel.c
src/common/abend.c [new file with mode: 0644]
src/common/abend.h [new file with mode: 0644]
src/common/cmdline.c
src/common/cmdline.h
src/common/fname.c [new file with mode: 0644]
src/common/fname.h [new file with mode: 0644]
src/common/make/gcc.mak
src/common/make/watcom.mak
src/common/xmalloc.c [new file with mode: 0644]
src/common/xmalloc.h [new file with mode: 0644]

index 509dc6ebacea6f4d060cc7de37e8889ffeded0ef..44c7524d138e02b6fc3b60c7f147fcbf7bd4295a 100644 (file)
 
 
 #include "../common/exprdefs.h"
+#include "../common/xmalloc.h"
 
 #include "error.h"
 #include "global.h"
 #include "instr.h"
-#include "mem.h"
 #include "nexttok.h"
 #include "objcode.h"
 #include "objfile.h"
@@ -85,7 +85,7 @@ static ExprNode* NewExprNode (void)
        FreeExprNodes = N->Left;
     } else {
        /* Allocate fresh memory */
-        N = Xmalloc (sizeof (ExprNode));
+        N = xmalloc (sizeof (ExprNode));
     }
     N->Op = EXPR_NULL;
     N->Left = N->Right = 0;
@@ -106,7 +106,7 @@ static void FreeExprNode (ExprNode* E)
            FreeExprNodes = E;
        } else {
            /* Free the memory */
-           Xfree (E);
+           xfree (E);
        }
     }
 }
@@ -114,10 +114,10 @@ static void FreeExprNode (ExprNode* E)
 
 
 /*****************************************************************************/
-/*             Dump an expression tree on stdout for debugging              */
+/*             Dump an expression tree on stdout for debugging              */
 /*****************************************************************************/
 
-
+            
 
 static void InternalDumpExpr (ExprNode* Expr)
 /* Dump an expression in UPN */
diff --git a/src/ca65/fname.c b/src/ca65/fname.c
deleted file mode 100644 (file)
index e764d52..0000000
+++ /dev/null
@@ -1,74 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                 fname.c                                  */
-/*                                                                           */
-/*                      File name handling utilities                        */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 2000      Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
-/*                                                                           */
-/*                                                                           */
-/* This software is provided 'as-is', without any expressed or implied       */
-/* warranty.  In no event will the authors be held liable for any damages    */
-/* arising from the use of this software.                                    */
-/*                                                                           */
-/* Permission is granted to anyone to use this software for any purpose,     */
-/* including commercial applications, and to alter it and redistribute it    */
-/* freely, subject to the following restrictions:                            */
-/*                                                                           */
-/* 1. The origin of this software must not be misrepresented; you must not   */
-/*    claim that you wrote the original software. If you use this software   */
-/*    in a product, an acknowledgment in the product documentation would be  */
-/*    appreciated but is not required.                                       */
-/* 2. Altered source versions must be plainly marked as such, and must not   */
-/*    be misrepresented as being the original software.                      */
-/* 3. This notice may not be removed or altered from any source              */
-/*    distribution.                                                          */
-/*                                                                           */
-/*****************************************************************************/
-
-
-
-#include <string.h>
-
-#include "mem.h"
-#include "fname.h"
-
-
-
-/*****************************************************************************/
-/*                                          Code                                    */
-/*****************************************************************************/
-
-
-
-char* MakeFilename (const char* Origin, const char* Ext)
-/* Make a new file name from Origin and Ext. If Origin has an extension, it
- * is removed and Ext is appended. If Origin has no extension, Ext is simply
- * appended. The result is placed in a malloc'ed buffer and returned.
- * The function may be used to create "foo.o" from "foo.s".
- */
-{
-    /* Construct the name */
-    char* Result;
-    const char* P = strrchr (Origin, '.');
-    if (P == 0) {
-       /* No dot, add the extension */
-       Result = Xmalloc (strlen (Origin) + strlen (Ext) + 1);
-       strcpy (Result, Origin);
-       strcat (Result, Ext);
-    } else {
-       Result = Xmalloc (P - Origin + strlen (Ext) + 1);
-       memcpy (Result, Origin, P - Origin);
-       strcpy (Result + (P - Origin), Ext);
-    }
-    return Result;
-}
-
-
-
-
index 24fb34f280140a6120d880959de93c5df98c4352..574654edc2a85cfc84b2885ae2ebffd447e8eabd 100644 (file)
@@ -43,8 +43,6 @@
 
 
 
-const char* ProgName                 = "ca65"; /* Program name */
-
 /* File names */
 const char* InFile                   = 0;      /* Name of input file */
 const char* OutFile                  = 0;      /* Name of output file */
@@ -70,7 +68,7 @@ unsigned char NoColonLabels   = 0;            /* Allow labels without a colon */
 unsigned char LooseStringTerm = 0;     /* Allow ' as string terminator */
 unsigned char AtInIdents      = 0;     /* Allow '@' in identifiers */
 unsigned char DollarInIdents  = 0;     /* Allow '$' in identifiers */
-                                                                         
+
 
 
 
index 4bd7f9af0e802ddaa261d7e2aae06104d3a24c87..bcca6eca2d2f448c3994e1176b1258117b9f936f 100644 (file)
@@ -44,8 +44,6 @@
 
 
 
-extern const char*     ProgName;       /* Program name */
-
 /* File names */
 extern const char*     InFile;         /* Name of input file */
 extern const char*     OutFile;        /* Name of output file */
index 28736716950fdfbd42c7cd2928af5109be0f1132..9021f44a63c3da06d90b5f27efbe41d3b417ccf8 100644 (file)
@@ -44,7 +44,8 @@
 #  include <unistd.h>
 #endif
 
-#include "mem.h"
+#include "../common/xmalloc.h"
+
 #include "incpath.h"
 
 
@@ -83,7 +84,7 @@ static char* Add (char* Orig, const char* New)
     }
 
     /* Allocate memory for the new string */
-    NewPath = Xmalloc (OrigLen + NewLen + 2);
+    NewPath = xmalloc (OrigLen + NewLen + 2);
 
     /* Copy the strings */
     memcpy (NewPath, Orig, OrigLen);
@@ -92,7 +93,7 @@ static char* Add (char* Orig, const char* New)
     NewPath [OrigLen+NewLen+1] = '\0';
 
     /* Delete the original path */
-    Xfree (Orig);
+    xfree (Orig);
 
     /* Return the new path */
     return NewPath;
@@ -138,8 +139,8 @@ static char* Find (const char* Path, const char* File)
        /* Check if this file exists */
        if (access (PathName, R_OK) == 0) {
            /* The file exists */
-           return StrDup (PathName);
-       }
+           return xstrdup (PathName);
+       }                  
 
        /* Skip a list separator if we have one */
        if (*P == ';') {
index 6e2f9e241240df70f7970df216046da52f384677..5ba35a9069fa1fb137bca8bc729934731df6143f 100644 (file)
@@ -33,8 +33,9 @@
 
 
 
+#include "../common/xmalloc.h"
+
 #include "error.h"
-#include "mem.h"
 #include "istack.h"
 
 
@@ -80,7 +81,7 @@ void PushInput (int (*Func) (void*), void* Data, const char* Desc)
     }
 
     /* Create a new stack element */
-    E = Xmalloc (sizeof (*E));
+    E = xmalloc (sizeof (*E));
 
     /* Initialize it */
     E->Func = Func;
@@ -109,7 +110,7 @@ void PopInput (void)
     IStack = IStack->Next;
 
     /* And delete it */
-    Xfree (E);
+    xfree (E);
 }
 
 
index 8177c6e15779fbd71e97194b1fdc048367df0939..05dc6c4ecb0aead31acfaf5fb7202a363ffa314c 100644 (file)
 #include <string.h>
 #include <errno.h>
 
+#include "../common/fname.h"
 #include "../common/segdefs.h"
 #include "../common/version.h"
+#include "../common/xmalloc.h"
 
 #include "error.h"
-#include "fname.h"
 #include "global.h"
-#include "mem.h"
 #include "objcode.h"
 #include "listing.h"
 
@@ -94,7 +94,7 @@ void NewListingLine (const char* Line, unsigned char File, unsigned char Depth)
        }
 
        /* Allocate memory */
-       L = Xmalloc (sizeof (ListLine) + Len);
+       L = xmalloc (sizeof (ListLine) + Len);
 
        /* Initialize the fields. */
        L->Next         = 0;
@@ -201,7 +201,7 @@ static void PrintPageHeader (FILE* F, const ListLine* L)
  */
 {
     /* Print the header on the new page */
-    fprintf (F, 
+    fprintf (F,
             "ca65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n"
             "Main file   : %s\n"
             "Current file: %s\n"
@@ -328,7 +328,7 @@ void CreateListing (void)
        }
 
        /* Allocate memory for the given number of bytes */
-       Buf = Xmalloc (Count*2+1);
+       Buf = xmalloc (Count*2+1);
 
        /* Copy an ASCII representation of the bytes into the buffer */
        B = Buf;
@@ -422,7 +422,7 @@ void CreateListing (void)
        }
 
        /* Delete the temporary buffer */
-       Xfree (Buf);
+       xfree (Buf);
 
        /* Next line */
        L = L->Next;
index a5eb78262b24c79874c85ea82ddd819e05e9691a..67c6b7b9b934485dfa452169fed07d204b929243 100644 (file)
 #include <string.h>
 
 #include "../common/hashstr.h"
+#include "../common/xmalloc.h"
 
 #include "condasm.h"
 #include "error.h"
 #include "istack.h"
-#include "mem.h"
 #include "nexttok.h"
 #include "pseudo.h"
 #include "toklist.h"
@@ -123,7 +123,7 @@ static IdDesc* NewIdDesc (const char* Id)
 {
     /* Allocate memory */
     unsigned Len = strlen (Id);
-    IdDesc* I = Xmalloc (sizeof (IdDesc) + Len);
+    IdDesc* I = xmalloc (sizeof (IdDesc) + Len);
 
     /* Initialize the struct */
     I->Next = 0;
@@ -141,7 +141,7 @@ static Macro* NewMacro (const char* Name, unsigned HashVal, unsigned char Style)
 {
     /* Allocate memory */
     unsigned Len = strlen (Name);
-    Macro* M = Xmalloc (sizeof (Macro) + Len);
+    Macro* M = xmalloc (sizeof (Macro) + Len);
 
     /* Initialize the macro struct */
     M->LocalCount = 0;
@@ -174,7 +174,7 @@ static MacExp* NewMacExp (Macro* M)
     unsigned I;
 
     /* Allocate memory */
-    MacExp* E = Xmalloc (sizeof (MacExp));
+    MacExp* E = xmalloc (sizeof (MacExp));
 
     /* Initialize the data */
     E->M                 = M;
@@ -184,7 +184,7 @@ static MacExp* NewMacExp (Macro* M)
     E->LocalStart = LocalName;
     LocalName    += M->LocalCount;
     E->ParamCount = 0;
-    E->Params     = Xmalloc (M->ParamCount * sizeof (TokNode*));
+    E->Params     = xmalloc (M->ParamCount * sizeof (TokNode*));
     E->ParamExp          = 0;
     for (I = 0; I < M->ParamCount; ++I) {
        E->Params [I] = 0;
@@ -209,9 +209,9 @@ static void FreeMacExp (MacExp* E)
 
     /* Free the parameter list */
     for (I = 0; I < E->ParamCount; ++I) {
-       Xfree (E->Params [I]);
+       xfree (E->Params [I]);
     }
-    Xfree (E->Params);
+    xfree (E->Params);
 
     /* Free the final token if we have one */
     if (E->Final) {
@@ -219,7 +219,7 @@ static void FreeMacExp (MacExp* E)
     }
 
     /* Free the structure itself */
-    Xfree (E);
+    xfree (E);
 }
 
 
index 5d30bcc0c4b2bff2a8eb3f3e09f277abb3b829bd..f224bd4294ba9f464e814592ae0d0586bc5fe269 100644 (file)
@@ -49,7 +49,7 @@
 #include "instr.h"
 #include "listing.h"
 #include "macro.h"
-#include "mem.h"
+/*#include "mem.h"*/
 #include "nexttok.h"
 #include "objcode.h"
 #include "objfile.h"
@@ -89,7 +89,7 @@ static void Usage (void)
                     "  --auto-import\t\tMark unresolved symbols as import\n"
                     "  --cpu type\t\tSet cpu type\n"
                     "  --debug-info\t\tAdd debug info to object file\n"
-            "  --help\t\tPrint this text\n"
+            "  --help\t\tHelp (this text)\n"
             "  --ignore-case\t\tIgnore case of symbols\n"
                     "  --include-dir dir\tSet an include directory search path\n"
                     "  --listing\t\tCreate a listing if assembly was ok\n"
@@ -98,7 +98,6 @@ static void Usage (void)
                     "  --verbose\t\tIncrease verbosity\n"
                     "  --version\t\tPrint the assembler version\n",
             ProgName);
-    exit (EXIT_FAILURE);
 }
 
 
@@ -128,7 +127,7 @@ static void DefineSymbol (const char* Def)
 
     /* The symbol must start with a character or underline */
     if (Def [0] != '_' && !isalpha (Def [0])) {
-       InvSym (Def);
+       InvDef (Def);
     }
     P = Def;
 
@@ -145,7 +144,7 @@ static void DefineSymbol (const char* Def)
     /* Do we have a value given? */
     if (*P != '=') {
        if (*P != '\0') {
-           InvSym (Def);
+           InvDef (Def);
        }
        Val = 0;
     } else {
@@ -154,11 +153,11 @@ static void DefineSymbol (const char* Def)
        if (*P == '$') {
            ++P;
            if (sscanf (P, "%lx", &Val) != 1) {
-               InvSym (Def);
+               InvDef (Def);
            }
        } else {
            if (sscanf (P, "%li", &Val) != 1) {
-               InvSym (Def);
+               InvDef (Def);
            }
                }
     }
@@ -219,6 +218,7 @@ static void OptHelp (const char* Opt, const char* Arg)
 /* Print usage information and exit */
 {
     Usage ();
+    exit (EXIT_SUCCESS);
 }
 
 
@@ -450,15 +450,7 @@ int main (int argc, char* argv [])
     int I;
 
     /* Initialize the cmdline module */
-    InitCmdLine (argc, argv);
-
-    /* Set the program name */
-    ProgName = argv [0];
-
-    /* We must have a file name */
-    if (argc < 2) {
-       Usage ();
-    }
+    InitCmdLine (argc, argv, "ca65");
 
     /* Enter the base lexical level. We must do that here, since we may
      * define symbols using -D.
@@ -532,8 +524,9 @@ int main (int argc, char* argv [])
                } else {
            /* Filename. Check if we already had one */
            if (InFile) {
-               fprintf (stderr, "Don't know what to do with `%s'\n", Arg);
-               Usage ();
+               fprintf (stderr, "%s: Don't know what to do with `%s'\n",
+                        ProgName, Arg);
+               exit (EXIT_FAILURE);
            } else {
                InFile = Arg;
            }
@@ -545,7 +538,7 @@ int main (int argc, char* argv [])
 
     /* Do we have an input file? */
     if (InFile == 0) {
-       fprintf (stderr, "No input file\n");
+       fprintf (stderr, "%s: No input files\n", ProgName);
        exit (EXIT_FAILURE);
     }
 
index 7476985a00a54b7baa7e21e625e9db8f6f41499f..6013fca2da9f4af97acce4c84fae10243c2101da 100644 (file)
@@ -10,7 +10,6 @@ OBJS =  condasm.o     \
        ea.o            \
         error.o                \
         expr.o         \
-       fname.o         \
        fragment.o      \
         global.o               \
        incpath.o       \
@@ -20,7 +19,6 @@ OBJS =  condasm.o     \
        macpack.o       \
                macro.o         \
         main.o                 \
-        mem.o                  \
        nexttok.o       \
         objcode.o      \
         objfile.o      \
index 92e34ce435370b0fa42e09873b5ba058458ba4d3..8b4eba838519586d6bd9d591e18340d248625114 100644 (file)
@@ -67,7 +67,6 @@ OBJS =        condasm.obj     \
        ea.obj          \
        error.obj       \
        expr.obj        \
-       fname.obj       \
        fragment.obj    \
        global.obj      \
        incpath.obj     \
@@ -77,7 +76,6 @@ OBJS =        condasm.obj     \
        macpack.obj     \
        macro.obj       \
        main.obj        \
-       mem.obj         \
        nexttok.obj     \
        objcode.obj     \
        objfile.obj     \
@@ -113,7 +111,6 @@ FILE condasm.obj
 FILE ea.obj
 FILE error.obj
 FILE expr.obj
-FILE fname.obj
 FILE fragment.obj
 FILE global.obj
 FILE incpath.obj
@@ -123,7 +120,6 @@ FILE listing.obj
 FILE macpack.obj
 FILE macro.obj
 FILE main.obj
-FILE mem.obj
 FILE nexttok.obj
 FILE objcode.obj
 FILE objfile.obj
diff --git a/src/ca65/mem.c b/src/ca65/mem.c
deleted file mode 100644 (file)
index 7f10aa8..0000000
+++ /dev/null
@@ -1,84 +0,0 @@
-/*****************************************************************************/
-/*                                                                          */
-/*                                  mem.c                                   */
-/*                                                                          */
-/*              Memory allocation for the ca65 macroassembler               */
-/*                                                                          */
-/*                                                                          */
-/*                                                                          */
-/* (C) 1998    Ullrich von Bassewitz                                        */
-/*             Wacholderweg 14                                              */
-/*             D-70597 Stuttgart                                            */
-/* EMail:      uz@musoftware.de                                             */
-/*                                                                          */
-/*                                                                          */
-/* This software is provided 'as-is', without any expressed or implied      */
-/* warranty.  In no event will the authors be held liable for any damages    */
-/* arising from the use of this software.                                   */
-/*                                                                          */
-/* Permission is granted to anyone to use this software for any purpose,     */
-/* including commercial applications, and to alter it and redistribute it    */
-/* freely, subject to the following restrictions:                           */
-/*                                                                          */
-/* 1. The origin of this software must not be misrepresented; you must not   */
-/*    claim that you wrote the original software. If you use this software   */
-/*    in a product, an acknowledgment in the product documentation would be  */
-/*    appreciated but is not required.                                      */
-/* 2. Altered source versions must be plainly marked as such, and must not   */
-/*    be misrepresented as being the original software.                             */
-/* 3. This notice may not be removed or altered from any source                     */
-/*    distribution.                                                         */
-/*                                                                          */
-/*****************************************************************************/
-
-
-
-#include <stdlib.h>
-#include <string.h>
-
-#include "error.h"
-#include "mem.h"
-
-
-
-/*****************************************************************************/
-/*                                  code                                    */
-/*****************************************************************************/
-
-
-
-void* Xmalloc (size_t size)
-/* Allocate memory, check for out of memory condition. Do some debugging */
-{
-    void* p;
-
-    p = malloc (size);
-    if (p == 0 && size != 0) {
-       Fatal (FAT_OUT_OF_MEMORY);
-    }
-
-    /* Return a pointer to the block */
-    return p;
-}
-
-
-
-void Xfree (const void* block)
-/* Free the block, do some debugging */
-{
-    free ((void*) block);
-}
-
-
-
-char* StrDup (const char* s)
-/* Duplicate a string on the heap. The function checks for out of memory */
-{
-    unsigned len;
-
-    len = strlen (s) + 1;
-    return memcpy (Xmalloc (len), s, len);
-}
-
-
-
diff --git a/src/ca65/mem.h b/src/ca65/mem.h
deleted file mode 100644 (file)
index 4a6871c..0000000
+++ /dev/null
@@ -1,67 +0,0 @@
-/*****************************************************************************/
-/*                                                                           */
-/*                                  mem.h                                   */
-/*                                                                           */
-/*              Memory allocation for the ca65 macroassembler               */
-/*                                                                           */
-/*                                                                           */
-/*                                                                           */
-/* (C) 1998     Ullrich von Bassewitz                                        */
-/*              Wacholderweg 14                                              */
-/*              D-70597 Stuttgart                                            */
-/* EMail:       uz@musoftware.de                                             */
-/*                                                                           */
-/*                                                                           */
-/* This software is provided 'as-is', without any expressed or implied       */
-/* warranty.  In no event will the authors be held liable for any damages    */
-/* arising from the use of this software.                                    */
-/*                                                                           */
-/* Permission is granted to anyone to use this software for any purpose,     */
-/* including commercial applications, and to alter it and redistribute it    */
-/* freely, subject to the following restrictions:                            */
-/*                                                                           */
-/* 1. The origin of this software must not be misrepresented; you must not   */
-/*    claim that you wrote the original software. If you use this software   */
-/*    in a product, an acknowledgment in the product documentation would be  */
-/*    appreciated but is not required.                                       */
-/* 2. Altered source versions must be plainly marked as such, and must not   */
-/*    be misrepresented as being the original software.                      */
-/* 3. This notice may not be removed or altered from any source              */
-/*    distribution.                                                          */
-/*                                                                           */
-/*****************************************************************************/
-
-
-
-#ifndef MEM_H
-#define MEM_H
-
-
-
-#include <stddef.h>
-
-
-
-/*****************************************************************************/
-/*                                          Code                                    */
-/*****************************************************************************/
-
-
-
-void* Xmalloc (size_t size);
-/* Allocate memory, check for out of memory condition. Do some debugging */
-
-void Xfree (const void* block);
-/* Free the block, do some debugging */
-
-char* StrDup (const char* s);
-/* Duplicate a string on the heap. The function checks for out of memory */
-
-
-
-/* End of mem.h */
-
-#endif
-
-
-
index 029e01e3c24d208dc7a1c2eae8eeed3a42297250..31d9a896baa4f1c7b9383375a9609372ca176322 100644 (file)
 #include <ctype.h>
 
 #include "../common/segdefs.h"
+#include "../common/xmalloc.h"
 
 #include "error.h"
 #include "fragment.h"
 #include "global.h"
 #include "listing.h"
-#include "mem.h"
 #include "objfile.h"
 #include "scanner.h"
 #include "symtab.h"
@@ -140,7 +140,7 @@ static Segment* NewSegment (const char* Name, unsigned SegType)
     } while (*N);
 
     /* Create a new segment */
-    S = Xmalloc (sizeof (*S));
+    S = xmalloc (sizeof (*S));
 
     /* Initialize it */
     S->List    = 0;
@@ -150,7 +150,7 @@ static Segment* NewSegment (const char* Name, unsigned SegType)
     S->SegType = SegType;
     S->PC      = 0;
     S->Num     = SegmentCount++;
-    S->Name    = StrDup (Name);
+    S->Name    = xstrdup (Name);
 
     /* Insert it into the segment list */
     SegmentLast->List = S;
@@ -599,7 +599,7 @@ static Fragment* NewFragment (unsigned char Type, unsigned short Len)
     Fragment* F;
 
     /* Create a new fragment */
-    F = Xmalloc (sizeof (*F));
+    F = xmalloc (sizeof (*F));
 
     /* Initialize it */
     F->List    = 0;
@@ -631,7 +631,7 @@ static Fragment* NewFragment (unsigned char Type, unsigned short Len)
            LineCur->FragList = F;
            /* First fragment - set the PC
            LineCur->PC    = GetPC ();
-           LineCur->Reloc = RelocMode;    
+           LineCur->Reloc = RelocMode;
 */
        } else {
                    LineCur->FragLast->LineList = F;
index b79ff097047477067d23f3fd870cceb66692507e..ca2e872ad5f891430d7c3ea727a773889e3b7842 100644 (file)
 #include <string.h>
 #include <errno.h>
 
+#include "../common/fname.h"
 #include "../common/objdefs.h"
 
 #include "global.h"
 #include "error.h"
-#include "fname.h"
-#include "mem.h"
 #include "objfile.h"
 
 
index ca05f0b4826cc0df1040412afa66b84aaf11230b..0af381818b0a76c734cd2efcc7584956fa804019 100644 (file)
@@ -34,8 +34,8 @@
 
 
 #include "../common/optdefs.h"
+#include "../common/xmalloc.h"
 
-#include "mem.h"
 #include "error.h"
 #include "objfile.h"
 #include "options.h"
@@ -67,7 +67,7 @@ static Option* NewOption (unsigned char Type)
     Option* Opt;
 
     /* Allocate memory */
-    Opt = Xmalloc (sizeof (*Opt));
+    Opt = xmalloc (sizeof (*Opt));
 
     /* Initialize fields */
     Opt->Next  = 0;
@@ -101,7 +101,7 @@ void OptStr (unsigned char Type, const char* Text)
        Fatal (FAT_STRING_TOO_LONG);
     }
     O        = NewOption (Type);
-    O->V.Str = StrDup (Text);
+    O->V.Str = xstrdup (Text);
 }
 
 
index 30ba6db7c914d5850b2b0987d7254bae7396afe2..7b0718b4dfdd35c54084549dbe14097242788f78 100644 (file)
 #include <errno.h>
 #include <sys/stat.h>
 
+#include "../common/fname.h"
+#include "../common/xmalloc.h"
+
 #include "condasm.h"
 #include "error.h"
-#include "fname.h"
 #include "global.h"
 #include "incpath.h"
 #include "instr.h"
 #include "istack.h"
 #include "listing.h"
 #include "macro.h"
-#include "mem.h"
 #include "objfile.h"
 #include "toklist.h"
 #include "scanner.h"
@@ -353,7 +354,7 @@ void NewInputFile (const char* Name)
        }
 
        /* Free the allocated memory */
-       Xfree (PathName);
+       xfree (PathName);
 
     }
 
@@ -367,11 +368,11 @@ void NewInputFile (const char* Name)
        }
        Files [FileCount].MTime = Buf.st_mtime;
        Files [FileCount].Size  = Buf.st_size;
-       Files [FileCount].Name  = StrDup (Name);
+       Files [FileCount].Name  = xstrdup (Name);
        ++FileCount;
 
        /* Create a new state variable and initialize it */
-       I           = Xmalloc (sizeof (*I));
+       I           = xmalloc (sizeof (*I));
        I->F        = F;
        I->Pos.Line = 0;
        I->Pos.Col  = 0;
@@ -407,7 +408,7 @@ void DoneInputFile (void)
 
     /* Cleanup the current stuff */
     fclose (I->F);
-    Xfree (I);
+    xfree (I);
     --ICount;
 }
 
@@ -419,7 +420,7 @@ void NewInputData (const char* Data, int Malloced)
     InputData* I;
 
     /* Create a new state variable and initialize it */
-    I                  = Xmalloc (sizeof (*I));
+    I                  = xmalloc (sizeof (*I));
     I->Data    = Data;
     I->Pos     = Data;
     I->Malloced = Malloced;
@@ -451,9 +452,9 @@ static void DoneInputData (void)
 
     /* Cleanup the current stuff */
     if (I->Malloced) {
-       Xfree (I->Data);
+       xfree (I->Data);
     }
-    Xfree (I);
+    xfree (I);
 }
 
 
index 53843eb1c39a919229e9804d3298bc77daeb542a..d1f7ce1012191bc4abdf14601a0fcbf451222879 100644 (file)
 
 #include "../common/symdefs.h"
 #include "../common/hashstr.h"
+#include "../common/xmalloc.h"
 
 #include "global.h"
 #include "error.h"
-#include "mem.h"
 #include "expr.h"
 #include "objfile.h"
 #include "symtab.h"
@@ -146,7 +146,7 @@ static SymEntry* NewSymEntry (const char* Name)
     Len = strlen (Name);
 
     /* Allocate memory */
-    S = Xmalloc (sizeof (SymEntry) + Len);
+    S = xmalloc (sizeof (SymEntry) + Len);
 
     /* Initialize the entry */
     S->Left   = 0;
@@ -174,7 +174,7 @@ static SymTable* NewSymTable (unsigned Size)
     SymTable* S;
 
     /* Allocate memory */
-    S = Xmalloc (sizeof (SymTable) + (Size-1) * sizeof (SymEntry*));
+    S = xmalloc (sizeof (SymTable) + (Size-1) * sizeof (SymEntry*));
 
     /* Set variables and clear hash table entries */
     S->TableSlots   = Size;
index dc2712d391c5c67a512c26b5373d51a29fccf21b..a45d8f0a9c737e6bd51ec4207dbd52a070f46f0d 100644 (file)
@@ -35,7 +35,8 @@
 
 #include <string.h>
 
-#include "mem.h"
+#include "../common/xmalloc.h"
+
 #include "scanner.h"
 #include "toklist.h"
 
@@ -54,7 +55,7 @@ TokNode* NewTokNode (void)
 
     /* Allocate memory */
     unsigned Len = TokHasSVal (Tok)? strlen (SVal) : 0;
-    T = Xmalloc (sizeof (TokNode) + Len);
+    T = xmalloc (sizeof (TokNode) + Len);
 
     /* Initialize the token contents */
     T->Next    = 0;
@@ -73,7 +74,7 @@ TokNode* NewTokNode (void)
 void FreeTokNode (TokNode* T)
 /* Free the given token node */
 {
-    Xfree (T);
+    xfree (T);
 }
 
 
@@ -132,7 +133,7 @@ TokList* NewTokList (void)
 /* Create a new, empty token list */
 {
     /* Allocate memory for the list structure */
-    TokList* T = Xmalloc (sizeof (TokList));
+    TokList* T = xmalloc (sizeof (TokList));
 
     /* Initialize the fields */
     InitTokList (T);
@@ -155,7 +156,7 @@ void FreeTokList (TokList* List)
     }
 
     /* Free the list structure itself */
-    Xfree (List);
+    xfree (List);
 }
 
 
@@ -168,9 +169,9 @@ void AddCurTok (TokList* List)
 
     /* Insert the node into the list */
     if (List->Root == 0) {
-       List->Root = T;
+       List->Root = T;
     } else {
-       List->Last->Next = T;
+       List->Last->Next = T;
     }
     List->Last = T;
 
@@ -180,6 +181,3 @@ void AddCurTok (TokList* List)
 
 
 
-
-
-
index adfe2e5f177299cadbc6e4a61c5a8580eeecd65e..1618afb73f39ee2d8111b61246e44fc6050bd3f4 100644 (file)
 
 
 #include "../common/filepos.h"
+#include "../common/xmalloc.h"
 
 #include "error.h"
 #include "expr.h"
-#include "mem.h"
 #include "scanner.h"
 #include "ulabel.h"
 
@@ -80,7 +80,7 @@ static ULabel* NewULabel (ExprNode* Val)
  */
 {
     /* Allocate memory for the ULabel structure */
-    ULabel* L = Xmalloc (sizeof (ULabel));
+    ULabel* L = xmalloc (sizeof (ULabel));
 
     /* Initialize the fields */
     L->Pos = CurPos;
@@ -227,7 +227,7 @@ void ULabCheck (void)
      */
     if (ULabCount) {
        unsigned I = 0;
-       ULabList = Xmalloc (ULabCount * sizeof (ULabel*));
+       ULabList = xmalloc (ULabCount * sizeof (ULabel*));
        L = ULabRoot;
        while (L) {
            ULabList[I] = L;
diff --git a/src/common/abend.c b/src/common/abend.c
new file mode 100644 (file)
index 0000000..741badd
--- /dev/null
@@ -0,0 +1,74 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 abend.c                                  */
+/*                                                                           */
+/*                          Abnormal program end                            */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#include <stdarg.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+#include "cmdline.h"
+#include "abend.h"
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+void AbEnd (const char* Format, ...)
+/* Print a message preceeded by the program name and terminate the program
+ * with an error exit code.
+ */
+{
+    va_list ap;
+
+    /* Print the program name */
+    fprintf (stderr, "%s: ", ProgName);
+
+    /* Format the given message and print it */
+    va_start (ap, Format);
+    vfprintf (stderr, Format, ap);
+    va_end (ap);
+
+    /* Add a newline */
+    fprintf (stderr, "\n");
+
+    /* Terminate the program */
+    exit (EXIT_FAILURE);
+}
+
+
+
diff --git a/src/common/abend.h b/src/common/abend.h
new file mode 100644 (file)
index 0000000..ef6f9cc
--- /dev/null
@@ -0,0 +1,59 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 abend.h                                  */
+/*                                                                           */
+/*                          Abnormal program end                            */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000     Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef ABEND_H
+#define ABEND_H
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+void AbEnd (const char* Format, ...);
+/* Print a message preceeded by the program name and terminate the program 
+ * with an error exit code.
+ */
+
+
+
+/* End of abend.h */
+
+#endif
+
+
+
index 564a4203a6c2867c055fcb0c2e89289408a45222..3403cdd7cb2980edebe961b40e187913891fce7f 100644 (file)
@@ -33,9 +33,9 @@
 
 
 
-#include <stdio.h>
-#include <stdlib.h>
+#include <string.h>
 
+#include "abend.h"
 #include "cmdline.h"
 
 
 
 
 
+/* Program name - is set after call to InitCmdLine */
+const char* ProgName;
+
+/* The program argument vector */
 static char** ArgVec     = 0;
 static unsigned ArgCount = 0;
 
 
 
 /*****************************************************************************/
-/*                                          Code                                    */
+/*                                          Code                                    */
 /*****************************************************************************/
 
 
 
-void InitCmdLine (unsigned aArgCount, char* aArgVec[])
+void InitCmdLine (unsigned aArgCount, char* aArgVec[], const char* aProgName)
 /* Initialize command line parsing. aArgVec is the argument array terminated by
  * a NULL pointer (as usual), ArgCount is the number of valid arguments in the
  * array. Both arguments are remembered in static storage.
  */
 {
+    /* Remember the argument vector */
     ArgCount = aArgCount;
     ArgVec   = aArgVec;
+
+    /* Get the program name from argv[0] but strip a path */
+    if (ArgVec[0] == 0) {
+       /* Use the default name given */
+       ProgName = aProgName;
+    } else {
+       /* Strip a path */
+       ProgName = strchr (ArgVec[0], '\0');
+       while (ProgName > ArgVec[0]) {
+           --ProgName;
+                   if (*ProgName == '/' || *ProgName == '\\') {
+               ++ProgName;
+               break;
+           }
+       }
+       if (ProgName[0] == '\0') {
+           /* Use the default */
+           ProgName = aProgName;
+       }
+    }
 }
 
 
@@ -72,8 +97,7 @@ void InitCmdLine (unsigned aArgCount, char* aArgVec[])
 void UnknownOption (const char* Opt)
 /* Print an error about an unknown option. */
 {
-    fprintf (stderr, "Unknown option: %s\n", Opt);
-    exit (EXIT_FAILURE);
+    AbEnd ("Unknown option: %s\n", Opt);
 }
 
 
@@ -81,8 +105,7 @@ void UnknownOption (const char* Opt)
 void NeedArg (const char* Opt)
 /* Print an error about a missing option argument and exit. */
 {
-    fprintf (stderr, "Option requires an argument: %s\n", Opt);
-    exit (EXIT_FAILURE);
+    AbEnd ("Option requires an argument: %s\n", Opt);
 }
 
 
@@ -90,8 +113,7 @@ void NeedArg (const char* Opt)
 void InvDef (const char* Def)
 /* Print an error about an invalid definition and die */
 {
-    fprintf (stderr, "Invalid definition: `%s'\n", Def);
-    exit (EXIT_FAILURE);
+    AbEnd ("Invalid definition: `%s'\n", Def);
 }
 
 
@@ -130,9 +152,9 @@ void LongOption (int* ArgNum, const LongOpt* OptTab, unsigned OptCount)
        if (strcmp (Opt, OptTab->Option) == 0) {
            /* Found, call the function */
            if (OptTab->ArgCount > 0) {
-               OptTab->Func (Opt, ArgVec[++(*ArgNum)]);
+               OptTab->Func (Opt, ArgVec[++(*ArgNum)]);
            } else {
-               OptTab->Func (Opt, 0);
+               OptTab->Func (Opt, 0);
            }
            /* Done */
            return;
index da620ac44378547c114ff58d18a4aa9a1c3df8cc..1173e10b654b95e17c0439498da1d03fa435eaf5 100644 (file)
@@ -44,6 +44,9 @@
 
 
 
+/* Program name - is set after call to InitCmdLine */
+extern const char* ProgName;
+
 /* Structure defining a long option */
 typedef struct LongOpt LongOpt;
 struct LongOpt {
@@ -60,7 +63,7 @@ struct LongOpt {
 
 
 
-void InitCmdLine (unsigned aArgCount, char* aArgVec[]);
+void InitCmdLine (unsigned aArgCount, char* aArgVec[], const char* aProgName);
 /* Initialize command line parsing. aArgVec is the argument array terminated by
  * a NULL pointer (as usual), ArgCount is the number of valid arguments in the
  * array. Both arguments are remembered in static storage.
diff --git a/src/common/fname.c b/src/common/fname.c
new file mode 100644 (file)
index 0000000..fd907e8
--- /dev/null
@@ -0,0 +1,73 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 fname.c                                  */
+/*                                                                           */
+/*                      File name handling utilities                        */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000      Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@musoftware.de                                            */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#include <string.h>
+
+#include "xmalloc.h"
+#include "fname.h"
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+char* MakeFilename (const char* Origin, const char* Ext)
+/* Make a new file name from Origin and Ext. If Origin has an extension, it
+ * is removed and Ext is appended. If Origin has no extension, Ext is simply
+ * appended. The result is placed in a malloc'ed buffer and returned.
+ * The function may be used to create "foo.o" from "foo.s".
+ */
+{
+    /* Construct the name */
+    char* Result;
+    const char* P = strrchr (Origin, '.');
+    if (P == 0) {
+       /* No dot, add the extension */
+       Result = xmalloc (strlen (Origin) + strlen (Ext) + 1);
+       strcpy (Result, Origin);
+       strcat (Result, Ext);
+    } else {
+       Result = xmalloc (P - Origin + strlen (Ext) + 1);
+       memcpy (Result, Origin, P - Origin);
+       strcpy (Result + (P - Origin), Ext);
+    }
+    return Result;
+}
+
+
+
diff --git a/src/common/fname.h b/src/common/fname.h
new file mode 100644 (file)
index 0000000..671bf80
--- /dev/null
@@ -0,0 +1,61 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                 fname.h                                  */
+/*                                                                           */
+/*                      File name handling utilities                        */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000      Ullrich von Bassewitz                                       */
+/*               Wacholderweg 14                                             */
+/*               D-70597 Stuttgart                                           */
+/* EMail:        uz@musoftware.de                                            */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef FNAME_H
+#define FNAME_H
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+char* MakeFilename (const char* Origin, const char* Ext);
+/* Make a new file name from Origin and Ext. If Origin has an extension, it
+ * is removed and Ext is appended. If Origin has no extension, Ext is simply
+ * appended. The result is placed in a malloc'ed buffer and returned.
+ * The function may be used to create "foo.o" from "foo.s".
+ */
+
+
+
+/* End of fname.h */
+
+#endif
+
+
+
index f50e1f18d35642099a7530cda1bcda86fefaac3b..9b49c46bf2cf2ee1360e9bc36d3ad613f0ac3678 100644 (file)
@@ -9,9 +9,12 @@ LIB    = common.a
 
 
 
-OBJS = bitops.o        \
+OBJS = abend.o         \
+       bitops.o        \
        cmdline.o       \
+       fname.o         \
        hashstr.o       \
+       xmalloc.o       \
        xsprintf.o
 
 
index 949680695eda1108e6efe88569ce01965af74302..909f44a80906275fb9081339916c526e340e2693 100644 (file)
@@ -65,10 +65,13 @@ CCCFG  = -bt=$(TARGET) -d1 -onatx -zp4 -5 -zq -w2
 # ------------------------------------------------------------------------------
 # All library OBJ files
 
-OBJS = bitops.obj      \
+OBJS = abend.obj       \
+       bitops.obj      \
        cmdline.obj     \
+       fname.obj       \
        hashstr.obj     \
        wildargv.obj    \
+       xmalloc.obj     \
        xsprintf.obj
 
 
@@ -92,3 +95,5 @@ clean:
 
 
 
+
+
diff --git a/src/common/xmalloc.c b/src/common/xmalloc.c
new file mode 100644 (file)
index 0000000..bce7598
--- /dev/null
@@ -0,0 +1,87 @@
+/*****************************************************************************/
+/*                                                                          */
+/*                                xmalloc.c                                 */
+/*                                                                           */
+/*                      Memory allocation subroutines                       */
+/*                                                                          */
+/*                                                                          */
+/*                                                                          */
+/* (C) 2000    Ullrich von Bassewitz                                        */
+/*             Wacholderweg 14                                              */
+/*             D-70597 Stuttgart                                            */
+/* EMail:      uz@musoftware.de                                             */
+/*                                                                          */
+/*                                                                          */
+/* This software is provided 'as-is', without any expressed or implied      */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                   */
+/*                                                                          */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                           */
+/*                                                                          */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                      */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                             */
+/* 3. This notice may not be removed or altered from any source                     */
+/*    distribution.                                                         */
+/*                                                                          */
+/*****************************************************************************/
+
+
+
+#include <stdlib.h>
+#include <string.h>
+
+#include "abend.h"
+#include "xmalloc.h"
+
+
+
+/*****************************************************************************/
+/*                                  code                                    */
+/*****************************************************************************/
+
+
+
+void* xmalloc (size_t Size)
+/* Allocate memory, check for out of memory condition. Do some debugging */
+{
+    /* Allocate memory */
+    void* P = malloc (Size);
+
+    /* Check for errors */
+    if (P == 0 && Size != 0) {
+       AbEnd ("Out of memory - requested block size = %lu", (unsigned long) Size);
+    }
+
+    /* Return a pointer to the block */
+    return P;
+}
+
+
+
+void xfree (const void* Block)
+/* Free the block, do some debugging */
+{
+    free ((void*) Block);
+}
+
+
+
+char* xstrdup (const char* S)
+/* Duplicate a string on the heap. The function checks for out of memory */
+{
+    /* Get the length of the string */
+    unsigned Len = strlen (S) + 1;
+
+    /* Allocate memory and return a copy */
+    return memcpy (xmalloc (Len), S, Len);
+}
+
+
+
+
diff --git a/src/common/xmalloc.h b/src/common/xmalloc.h
new file mode 100644 (file)
index 0000000..d90a5c9
--- /dev/null
@@ -0,0 +1,67 @@
+/*****************************************************************************/
+/*                                                                           */
+/*                                xmalloc.h                                 */
+/*                                                                           */
+/*                      Memory allocation subroutines                       */
+/*                                                                           */
+/*                                                                           */
+/*                                                                           */
+/* (C) 2000    Ullrich von Bassewitz                                        */
+/*              Wacholderweg 14                                              */
+/*              D-70597 Stuttgart                                            */
+/* EMail:       uz@musoftware.de                                             */
+/*                                                                           */
+/*                                                                           */
+/* This software is provided 'as-is', without any expressed or implied       */
+/* warranty.  In no event will the authors be held liable for any damages    */
+/* arising from the use of this software.                                    */
+/*                                                                           */
+/* Permission is granted to anyone to use this software for any purpose,     */
+/* including commercial applications, and to alter it and redistribute it    */
+/* freely, subject to the following restrictions:                            */
+/*                                                                           */
+/* 1. The origin of this software must not be misrepresented; you must not   */
+/*    claim that you wrote the original software. If you use this software   */
+/*    in a product, an acknowledgment in the product documentation would be  */
+/*    appreciated but is not required.                                       */
+/* 2. Altered source versions must be plainly marked as such, and must not   */
+/*    be misrepresented as being the original software.                      */
+/* 3. This notice may not be removed or altered from any source              */
+/*    distribution.                                                          */
+/*                                                                           */
+/*****************************************************************************/
+
+
+
+#ifndef XMALLOC_H
+#define XMALLOC_H
+
+
+
+#include <stddef.h>
+
+
+
+/*****************************************************************************/
+/*                                          Code                                    */
+/*****************************************************************************/
+
+
+
+void* xmalloc (size_t Size);
+/* Allocate memory, check for out of memory condition. Do some debugging */
+
+void xfree (const void* Block);
+/* Free the block, do some debugging */
+
+char* xstrdup (const char* S);
+/* Duplicate a string on the heap. The function checks for out of memory */
+
+
+
+/* End of xmalloc.h */
+
+#endif
+
+
+