home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Tools / Languages / Icon 8.1 / msm-1 / common.sit / alloc.c next >
Encoding:
C/C++ Source or Header  |  1992-09-19  |  996 b   |  54 lines  |  [TEXT/MPS ]

  1. /*
  2.  * alloc.c -- allocation routines for the Icon compiler
  3.  */
  4.  
  5. #include "::h:gsupport.h"
  6.  
  7. #ifdef TypTrc
  8. int typealloc = 0;        /* type allocation switch */
  9. long typespace = 0;        /* type allocation amount */
  10. #endif                    /* TypTrc */
  11. /*
  12.  * salloc - allocate and initialize string 
  13.  */
  14.  
  15. char *salloc(s)
  16. char *s;
  17.    {
  18.    register char *s1;
  19.  
  20.    s1 = (char *)malloc((msize)(strlen(s) + 1));
  21.    if (s1 == NULL) {
  22.       fprintf(stderr, "salloc(%d): out of memory\n",(int)strlen(s) + 1);
  23.       exit(ErrorExit);
  24.       }
  25.    return strcpy(s1, s);
  26.    }
  27.  
  28. /*
  29.  * alloc - allocate n bytes
  30.  */
  31.  
  32. pointer alloc(n)
  33. unsigned int n;
  34.    {
  35.    register pointer a;
  36.  
  37. #ifdef TypTrc
  38.    if (typealloc)
  39.       typespace += (long)n;
  40. #endif                    /* TypTrc */
  41.  
  42. #ifdef AllocTrace
  43.    fprintf(stderr,"alloc(%d)\n", (int)n);
  44.    fflush(stderr);
  45. #endif                    /* AllocTrace */
  46.  
  47.    a = calloc((msize)n,sizeof(char));
  48.    if (a == NULL) {
  49.       fprintf(stderr, "alloc(%d): out of memory\n", (int)n);
  50.       exit(ErrorExit);
  51.       }
  52.    return a;
  53.    }
  54.