home *** CD-ROM | disk | FTP | other *** search
/ Skunkware 5 / Skunkware 5.iso / src / Tools / lynx-2.4 / WWW / Library / Implementation / HTAssoc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-06-28  |  1.7 KB  |  84 lines

  1.  
  2. /* MODULE                            HTAssoc.c
  3. **        ASSOCIATION LIST FOR STORING NAME-VALUE PAIRS.
  4. **        NAMES NOT CASE SENSITIVE, AND ONLY COMMON LENGTH
  5. **        IS CHECKED (allows abbreviations; well, length is
  6. **        taken from lookup-up name, so if table contains
  7. **        a shorter abbrev it is not found).
  8. ** AUTHORS:
  9. **    AL    Ari Luotonen    luotonen@dxcern.cern.ch
  10. **
  11. ** HISTORY:
  12. **
  13. **
  14. ** BUGS:
  15. **
  16. **
  17. */
  18.  
  19.  
  20. #include "HTUtils.h"
  21.  
  22. #include <string.h>
  23.  
  24. #include "HTAAUtil.h"
  25. #include "HTAssoc.h"
  26. #include "HTString.h"
  27.  
  28. #include "LYLeaks.h"
  29.  
  30. PUBLIC HTAssocList *HTAssocList_new NOARGS
  31. {
  32.     return HTList_new();
  33. }
  34.  
  35.  
  36. PUBLIC void HTAssocList_delete ARGS1(HTAssocList *, alist)
  37. {
  38.     if (alist) {
  39.     HTAssocList *cur = alist;
  40.     HTAssoc *assoc;
  41.     while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
  42.         if (assoc->name) free(assoc->name);
  43.         if (assoc->value) free(assoc->value);
  44.         free(assoc);
  45.     }
  46.     HTList_delete(alist);
  47.     }
  48. }
  49.  
  50.  
  51. PUBLIC void HTAssocList_add ARGS3(HTAssocList *,    alist,
  52.                   CONST char *,        name,
  53.                   CONST char *,        value)
  54. {
  55.     HTAssoc *assoc;
  56.  
  57.     if (alist) {
  58.     if (!(assoc = (HTAssoc*)malloc(sizeof(HTAssoc))))
  59.         outofmem(__FILE__, "HTAssoc_add");
  60.     assoc->name = NULL;
  61.     assoc->value = NULL;
  62.  
  63.     if (name) StrAllocCopy(assoc->name, name);
  64.     if (value) StrAllocCopy(assoc->value, value);
  65.     HTList_addObject(alist, (void*)assoc);
  66.     }
  67.     else if (TRACE) fprintf(stderr, "HTAssoc_add: ERROR: assoc list NULL!!\n");
  68. }
  69.  
  70.  
  71. PUBLIC char *HTAssocList_lookup ARGS2(HTAssocList *,    alist,
  72.                       CONST char *,    name)
  73. {
  74.     HTAssocList *cur = alist;
  75.     HTAssoc *assoc;
  76.  
  77.     while (NULL != (assoc = (HTAssoc*)HTList_nextObject(cur))) {
  78.     if (!strncasecomp(assoc->name, name, strlen(name)))
  79.         return assoc->value;
  80.     }
  81.     return NULL;
  82. }
  83.  
  84.