home *** CD-ROM | disk | FTP | other *** search
/ Resource Library: Multimedia / Resource Library: Multimedia.iso / sgml / unix / sgmlc / sgmlmem.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-07-03  |  2.4 KB  |  60 lines

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