home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / compsci / arcsgm.cpt / ARC SGML 1.0 / sgmlc / sgmlmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-17  |  2.4 KB  |  63 lines

  1. #ifdef applec
  2. #pragma segment SegC
  3. #endif
  4. /******************************************************************************/
  5. #include "vmincl.h"           /* Include files for VM. */
  6. #include "vmxtrn.h"           /* Declarations for VM public variables. */
  7. /******************************************************************************/
  8. /* SGMLMEM: Support environment memory services for SGML.
  9.             TO DO: Add subpool allocation to support SUBDOC
  10.                    and the use of a variant concrete syntax
  11.                    in document instances together with the
  12.                    reference concrete syntax in the prologs.
  13. */
  14. void sgmlmem(im)
  15. struct ipbmem *im;            /* IPB: memory services. */
  16. {
  17.      switch (im->memtype) {
  18.      case MEMGET:             /* Get memory area of specified size. */
  19.           im->memarea = calloc((size_t)im->memsize, (size_t)1);
  20.           return;
  21.      case MEMFREE:            /* Free designated memory area. */
  22.           free(im->memarea);
  23.           return;
  24.      }
  25. }
  26. /******************************************************************************/
  27. /* Memory functions for the interface and text processor.  If desired, these
  28.    can be modified to call SGMLMEM so that all memory will be allocated by
  29.    the same routine.
  30. */
  31. /******************************************************************************/
  32. /* SAVESTR: Save a string whose length is in its first byte.
  33.             The string is saved with the length byte.
  34. */
  35. UNCH *savestr(s)
  36. UNCH *s;
  37. {
  38.      UNCH *rp;
  39.  
  40.      rp = vmalloc((UNS)*s);        /* Allocate storage for string. */
  41.      memcpy(rp, s, (size_t)*s);            /* Copy string into new storage. */
  42.      return rp;                    /* Return pointer to stored string. */
  43. }
  44. /******************************************************************************/
  45. /* VMALLOC: Interface to memory allocation with error handling.
  46.             If storage is not available, fatal error message is issued.
  47.             Storage is initialized to zeros.
  48. */
  49. UNCH *vmalloc(size)
  50. unsigned size;                /* Number of bytes of initialized storage. */
  51. {
  52.     UNCH *ptr;
  53.  
  54.     if ((ptr = calloc((size_t)size, (size_t)1))!=NULL) return ptr;
  55.     printf(
  56. "\nVM201-> ***** Out of memory; processing ended. *****"
  57.     );
  58.     exit(201);
  59.     /*lint -unreachable         There is no implied return at this point. */
  60.     return 0;                /* Avoid Borland C++ warning. */
  61. }
  62. /******************************************************************************/
  63.