home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / UNIX / ARCHIE / CLIENTS / XARCHIE2.TAR / atalloc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1991-10-21  |  1.8 KB  |  94 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. void
  56. atfree(at)
  57.     PATTRIB    at;
  58.     {
  59.     if(at->aname) stfree(at->aname);
  60.  
  61.     if((strcmp(at->avtype,"ASCII") == 0) && at->value.ascii) 
  62.         stfree(at->value.ascii);
  63.     if((strcmp(at->avtype,"LINK") == 0) && at->value.link) 
  64.         vlfree(at->value.link);
  65.     
  66.     if(at->avtype) stfree(at->avtype);
  67.  
  68.     at->next = lfree;
  69.     at->previous = NULL;
  70.     lfree = at;
  71.     pattrib_count--;
  72.     }
  73.  
  74. /*
  75.  * atlfree - free a PATTRIB structure
  76.  *
  77.  *    ATLFREE takes a pointer to a PATTRIB structure frees it and any linked
  78.  *    PATTRIB structures.  It is used to free an entrie list of PATTRIB
  79.  *    structures.
  80.  */
  81. void
  82. atlfree(at)
  83.     PATTRIB    at;
  84.     {
  85.     PATTRIB    nxt;
  86.  
  87.     while(at != NULL) {
  88.         nxt = at->next;
  89.         atfree(at);
  90.         at = nxt;
  91.     }
  92.     }
  93.  
  94.