2
0

nv_pair_list.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. /* nv_pair_list.c - the opkg package management system
  2. Carl D. Worth
  3. Copyright (C) 2001 University of Southern California
  4. This program is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU General Public License as
  6. published by the Free Software Foundation; either version 2, or (at
  7. your option) any later version.
  8. This program is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. */
  13. #include "nv_pair.h"
  14. #include "void_list.h"
  15. #include "nv_pair_list.h"
  16. #include "libbb/libbb.h"
  17. void nv_pair_list_init(nv_pair_list_t * list)
  18. {
  19. void_list_init((void_list_t *) list);
  20. }
  21. void nv_pair_list_deinit(nv_pair_list_t * list)
  22. {
  23. nv_pair_list_elt_t *pos;
  24. nv_pair_t *nv_pair;
  25. while (!void_list_empty(list)) {
  26. pos = nv_pair_list_pop(list);
  27. if (!pos)
  28. break;
  29. nv_pair = (nv_pair_t *) pos->data;
  30. nv_pair_deinit(nv_pair);
  31. /* malloced in nv_pair_list_append */
  32. free(nv_pair);
  33. pos->data = NULL;
  34. free(pos);
  35. }
  36. void_list_deinit((void_list_t *) list);
  37. }
  38. nv_pair_t *nv_pair_list_append(nv_pair_list_t * list, const char *name,
  39. const char *value)
  40. {
  41. /* freed in nv_pair_list_deinit */
  42. nv_pair_t *nv_pair = xcalloc(1, sizeof(nv_pair_t));
  43. nv_pair_init(nv_pair, name, value);
  44. void_list_append((void_list_t *) list, nv_pair);
  45. return nv_pair;
  46. }
  47. void nv_pair_list_push(nv_pair_list_t * list, nv_pair_t * data)
  48. {
  49. void_list_push((void_list_t *) list, data);
  50. }
  51. nv_pair_list_elt_t *nv_pair_list_pop(nv_pair_list_t * list)
  52. {
  53. return (nv_pair_list_elt_t *) void_list_pop((void_list_t *) list);
  54. }
  55. char *nv_pair_list_find(nv_pair_list_t * list, char *name)
  56. {
  57. nv_pair_list_elt_t *iter;
  58. nv_pair_t *nv_pair;
  59. list_for_each_entry(iter, &list->head, node) {
  60. nv_pair = (nv_pair_t *) iter->data;
  61. if (strcmp(nv_pair->name, name) == 0) {
  62. return nv_pair->value;
  63. }
  64. }
  65. return NULL;
  66. }
  67. nv_pair_list_elt_t *nv_pair_list_first(nv_pair_list_t * list)
  68. {
  69. return (nv_pair_list_elt_t *) void_list_first((void_list_t *) list);
  70. }
  71. nv_pair_list_elt_t *nv_pair_list_prev(nv_pair_list_t * list,
  72. nv_pair_list_elt_t * node)
  73. {
  74. return (nv_pair_list_elt_t *) void_list_prev((void_list_t *) list,
  75. (void_list_elt_t *) node);
  76. }
  77. nv_pair_list_elt_t *nv_pair_list_next(nv_pair_list_t * list,
  78. nv_pair_list_elt_t * node)
  79. {
  80. return (nv_pair_list_elt_t *) void_list_next((void_list_t *) list,
  81. (void_list_elt_t *) node);
  82. }
  83. nv_pair_list_elt_t *nv_pair_list_last(nv_pair_list_t * list)
  84. {
  85. return (nv_pair_list_elt_t *) void_list_last((void_list_t *) list);
  86. }