home *** CD-ROM | disk | FTP | other *** search
/ Network CD 2 / Network CD - Volume 2.iso / programs / internet / tcp / ftp / archie132.lha / archie-1.3.2 / src / atalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-10  |  1.9 KB  |  98 lines

  1. /*
  2.  * Copyright (c) 1989, 1990 by the University of Washington
  3.  *
  4.  * For copying and distribution information, please see the file
  5.  * <copyright.h>.
  6.  */
  7.  
  8. #include <copyright.h>
  9. #include <stdio.h>
  10. #include <stdlib.h>
  11. #include <string.h>
  12. #include <time.h>
  13. #include <string.h>
  14.  
  15. #include <pfs.h>
  16. #include <pmachine.h> /* for correct definition of ZERO */
  17.  
  18. static PATTRIB    lfree = NULL;
  19. int        pattrib_count = 0;
  20. int        pattrib_max = 0;
  21.  
  22. /*
  23.  * atalloc - allocate and initialize vlink structure
  24.  *
  25.  *    ATALLOC returns a pointer to an initialized structure of type
  26.  *    PATTRIB.  If it is unable to allocate such a structure, it
  27.  *    returns NULL.
  28.  */
  29. PATTRIB
  30. atalloc()
  31.     {
  32.     PATTRIB    at;
  33.     if(lfree) {
  34.         at = lfree;
  35.         lfree = lfree->next;
  36.     }
  37.     else {
  38.         at = (PATTRIB) malloc(sizeof(PATTRIB_ST));
  39.         if (!at) return(NULL);
  40.         pattrib_max++;
  41.     }
  42.  
  43.     pattrib_count++;
  44.  
  45.     ZERO(at);
  46.     /* Initialize and fill in default values; all items are
  47.        0 [or NULL] save precedence */
  48.     at->precedence = ATR_PREC_OBJECT;
  49.  
  50.     return(at);
  51.     }
  52.  
  53. /*
  54.  * atfree - free a PATTRIB structure
  55.  *
  56.  *    ATFREE takes a pointer to a PATTRRIB structure and adds it to
  57.  *    the free list for later reuse.
  58.  */
  59. void
  60. atfree(at)
  61.     PATTRIB    at;
  62.     {
  63.     if(at->aname) stfree(at->aname);
  64.  
  65.     if((strcmp(at->avtype,"ASCII") == 0) && at->value.ascii) 
  66.         stfree(at->value.ascii);
  67.     if((strcmp(at->avtype,"LINK") == 0) && at->value.link) 
  68.         vlfree(at->value.link);
  69.     
  70.     if(at->avtype) stfree(at->avtype);
  71.  
  72.     at->next = lfree;
  73.     at->previous = NULL;
  74.     lfree = at;
  75.     pattrib_count--;
  76.     }
  77.  
  78. /*
  79.  * atlfree - free a PATTRIB structure
  80.  *
  81.  *    ATLFREE takes a pointer to a PATTRIB structure frees it and any linked
  82.  *    PATTRIB structures.  It is used to free an entrie list of PATTRIB
  83.  *    structures.
  84.  */
  85. void
  86. atlfree(at)
  87.     PATTRIB    at;
  88.     {
  89.     PATTRIB    nxt;
  90.  
  91.     while(at != NULL) {
  92.         nxt = at->next;
  93.         atfree(at);
  94.         at = nxt;
  95.     }
  96.     }
  97.  
  98.