home *** CD-ROM | disk | FTP | other *** search
/ minnie.tuhs.org / unixen.tar / unixen / PDP-11 / Distributions / ucb / spencer_2bsd.tar.gz / 2bsd.tar / src / Mail / strings.c < prev    next >
C/C++ Source or Header  |  1980-02-17  |  2KB  |  76 lines

  1. /* Copyright (c) 1979 Regents of the University of California */
  2. #
  3.  
  4. /*
  5.  * Mail -- a mail program
  6.  *
  7.  * String allocation routines.
  8.  * Strings handed out here are reclaimed at the top of the command
  9.  * loop each time, so they need not be freed.
  10.  */
  11.  
  12. #include "rcv.h"
  13.  
  14. /*
  15.  * Allocate size more bytes of space and return the address of the
  16.  * first byte to the caller.  An even number of bytes are always
  17.  * allocated so that the space will always be on a word boundary.
  18.  * The string spaces are of exponentially increasing size, to satisfy
  19.  * the occasional user with enormous string size requests.
  20.  */
  21.  
  22. char *
  23. salloc(size)
  24. {
  25.     register char *t;
  26.     register int s;
  27.     register struct strings *sp;
  28.     int index;
  29.  
  30.     s = size;
  31.     s++;
  32.     s &= ~01;
  33.     index = 0;
  34.     for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
  35.         if (sp->s_topFree == NOSTR && (STRINGSIZE << index) >= s)
  36.             break;
  37.         if (sp->s_nleft >= s)
  38.             break;
  39.         index++;
  40.     }
  41.     if (sp >= &stringdope[NSPACE])
  42.         panic("Ran out of memory!");
  43.     if (sp->s_topFree == NOSTR) {
  44.         index = sp - &stringdope[0];
  45.         sp->s_topFree = (char *) calloc(STRINGSIZE << index,
  46.             (unsigned) 1);
  47.         sp->s_nextFree = sp->s_topFree;
  48.         sp->s_nleft = STRINGSIZE << index;
  49.     }
  50.     sp->s_nleft -= s;
  51.     t = sp->s_nextFree;
  52.     sp->s_nextFree += s;
  53.     return(t);
  54. }
  55.  
  56. /*
  57.  * Reset the string area to be empty.
  58.  * Called to free all strings allocated
  59.  * since last reset.
  60.  */
  61.  
  62. sreset()
  63. {
  64.     register struct strings *sp;
  65.     register int index;
  66.  
  67.     index = 0;
  68.     for (sp = &stringdope[0]; sp < &stringdope[NSPACE]; sp++) {
  69.         if (sp->s_topFree == NOSTR)
  70.             continue;
  71.         sp->s_nextFree = sp->s_topFree;
  72.         sp->s_nleft = STRINGSIZE << index;
  73.         index++;
  74.     }
  75. }
  76.