home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE0.TAR / atalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-08-27  |  1.8 KB  |  92 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.  
  11. #include <pfs.h>
  12. #include <pmachine.h> /* for correct definition of ZERO */
  13.  
  14. static PATTRIB    lfree = NULL;
  15. int        pattrib_count = 0;
  16. int        pattrib_max = 0;
  17.  
  18. /*
  19.  * atalloc - allocate and initialize vlink structure
  20.  *
  21.  *    ATALLOC returns a pointer to an initialized structure of type
  22.  *    PATTRIB.  If it is unable to allocate such a structure, it
  23.  *    returns NULL.
  24.  */
  25. PATTRIB
  26. atalloc()
  27.     {
  28.     PATTRIB    at;
  29.     if(lfree) {
  30.         at = lfree;
  31.         lfree = lfree->next;
  32.     }
  33.     else {
  34.         at = (PATTRIB) malloc(sizeof(PATTRIB_ST));
  35.         if (!at) return(NULL);
  36.         pattrib_max++;
  37.     }
  38.  
  39.     pattrib_count++;
  40.  
  41.     ZERO(at);
  42.     /* Initialize and fill in default values; all items are
  43.        0 [or NULL] save precedence */
  44.     at->precedence = ATR_PREC_OBJECT;
  45.  
  46.     return(at);
  47.     }
  48.  
  49. /*
  50.  * atfree - free a PATTRIB structure
  51.  *
  52.  *    ATFREE takes a pointer to a PATTRRIB structure and adds it to
  53.  *    the free list for later reuse.
  54.  */
  55. atfree(at)
  56.     PATTRIB    at;
  57.     {
  58.     if(at->aname) stfree(at->aname);
  59.  
  60.     if((strcmp(at->avtype,"ASCII") == 0) && at->value.ascii) 
  61.         stfree(at->value.ascii);
  62.     if((strcmp(at->avtype,"LINK") == 0) && at->value.link) 
  63.         vlfree(at->value.link);
  64.     
  65.     if(at->avtype) stfree(at->avtype);
  66.  
  67.     at->next = lfree;
  68.     at->previous = NULL;
  69.     lfree = at;
  70.     pattrib_count--;
  71.     }
  72.  
  73. /*
  74.  * atlfree - free a PATTRIB structure
  75.  *
  76.  *    ATLFREE takes a pointer to a PATTRIB structure frees it and any linked
  77.  *    PATTRIB structures.  It is used to free an entrie list of PATTRIB
  78.  *    structures.
  79.  */
  80. atlfree(at)
  81.     PATTRIB    at;
  82.     {
  83.     PATTRIB    nxt;
  84.  
  85.     while(at != NULL) {
  86.         nxt = at->next;
  87.         atfree(at);
  88.         at = nxt;
  89.     }
  90.     }
  91.  
  92.