home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume10 / lemming / part01 / lemalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-08-05  |  1.2 KB  |  85 lines

  1. /*
  2.  * lemalloc.c -- allocation routines useful to the whole lemming family
  3.  *
  4.  * copyright (c) by Alan W. Paeth, 1987. All rights reserved.
  5.  */
  6.  
  7. #include "lem.h"
  8.  
  9. char *salloc(s)
  10.     char *s;
  11.     {
  12.     char *out;
  13.     out = (char*)(calloc(strlen(s)+1, sizeof(char)));
  14.     strcpy(out, s);
  15.     return(out);
  16.     }
  17.     
  18. objfree(i)
  19.     {
  20.     if (Otext)
  21.     {
  22.     free(Otext);
  23.     Otext = 0;
  24.     }
  25.     free(o);
  26.     o = 0;
  27.     }
  28.  
  29. objalloc(t)
  30.     {
  31.     int i;
  32.     if (lastobj == MAXOBJS)
  33.     {
  34.     forobjects
  35.         {
  36.         if (Odel) break;
  37.         }
  38.     if (i == lastobj) err("out of object space");
  39.     objfree(i);
  40.     }
  41.     else
  42.     {
  43.     i = lastobj++;
  44.     o = (pel)(calloc(1, sizeof(el)));
  45.     }
  46.     Otext = 0;
  47.     Otype = t;
  48.     Otype = t;
  49.     Oalign= galign;
  50.     Oemph = gemph;
  51.     Osize = gsize;
  52.     return(i);
  53.     }
  54.  
  55. objcompress()
  56.     {
  57.     int i, j;
  58.     forobjects
  59.     {
  60.     if (Onotdel) continue;    /* look for a hole */
  61.     for(j=i+1; j<lastobj; j++)
  62.         {
  63.         pel tmp;
  64.         if (objs[j]->stat == DEL) continue;    /* look for non-hole */
  65.         tmp = objs[j];
  66.         objs[j] = objs[i];
  67.         objs[i] = tmp;
  68.         break;
  69.         }
  70.     }
  71.     forobjsrev
  72.     {
  73.     if (Odel) objfree(i);
  74.     else break;
  75.     }
  76.     lastobj = i+1;
  77.     }
  78.  
  79. objnew(i)
  80.     {
  81.     Ostat = DEL;
  82.     Ogroup = 0;
  83.     objectop(i, DEL, UNDEL);
  84.     }
  85.