* src/pic/main.c (_asmCmd): include debug arguments (-g as $3)
[fw/sdcc] / as / mcs51 / asstore.c
1 /* strstore.c */
2
3 #include <stdio.h>
4 #include <setjmp.h>
5 #include <string.h>
6 #include "asm.h"
7
8 /*
9  * Allocate space for "str", copy str into new space
10  * Return a pointer to the allocated name, or NULL if out of memory
11  */
12 char *StoreString( char *str )
13 {
14    /* To avoid wasting memory headers on small allocations, we
15    /  allocate a big chunk and parcel it out as required.
16    /  These static variables remember our hunk
17    */
18    #define STR_STORE_HUNK 2000
19    static char *pNextFree = NULL;
20    static int  bytesLeft = 0;
21    
22    int  length;
23    char *pStoredString;
24    
25    length = strlen( str ) + 1;  /* what we need, including null */
26
27    if (length > bytesLeft)
28    {
29       /* no space.  Allocate a new hunk.  We lose the pointer to any
30       /  old hunk.  We don't care, as the names are never deleted.
31       */
32       pNextFree = (char*)new( STR_STORE_HUNK );
33       bytesLeft = STR_STORE_HUNK;
34    }
35
36    /* Copy the name and terminating null into the name store */
37    pStoredString = pNextFree;
38    memcpy( pStoredString, str, length );
39
40    pNextFree += length;
41    bytesLeft -= length;
42
43    return pStoredString;
44 }