diff options
author | Jjgod Jiang <gzjjgod@gmail.com> | 2007-11-23 18:42:18 +0000 |
---|---|---|
committer | Jjgod Jiang <gzjjgod@gmail.com> | 2007-11-23 18:42:18 +0000 |
commit | fb0a76e55e2bbb6ff31506cdb4fd9e3f63b9f665 (patch) | |
tree | 59f0b90e0520dcfae509c1325dd60b8927b23aac /Master/tlpkg/lib/C/tlp-utils.c | |
parent | 77f76c0f54c796d4ca72a4b9bcd878b385c6950a (diff) |
Support config.
git-svn-id: svn://tug.org/texlive/trunk@5569 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/tlpkg/lib/C/tlp-utils.c')
-rw-r--r-- | Master/tlpkg/lib/C/tlp-utils.c | 69 |
1 files changed, 68 insertions, 1 deletions
diff --git a/Master/tlpkg/lib/C/tlp-utils.c b/Master/tlpkg/lib/C/tlp-utils.c index eda65103584..864b7a0597c 100644 --- a/Master/tlpkg/lib/C/tlp-utils.c +++ b/Master/tlpkg/lib/C/tlp-utils.c @@ -29,9 +29,72 @@ void tlp_str_free(tlp_str str) free(str); } +tlp_str_list *tlp_str_list_new() +{ + tlp_str_list *list = tlp_new(tlp_str_list); + if (list == NULL) + return NULL; + + list->head = list->tail = NULL; + return list; +} + +tlp_str_list *tlp_str_list_from_array(const char *array[]) +{ + tlp_str_list *list = tlp_str_list_new(); + int i, size; + + if (list == NULL) + return NULL; + + size = sizeof(array) / sizeof(array[0]); + for (i = 0; i < size; i++) + if (tlp_str_list_append_bytes(list, array[i]) != TLP_OK) + { + tlp_str_list_free(list); + return NULL; + } + + return list; +} + +tlp_result tlp_str_list_append(tlp_str_list *list, tlp_str str) +{ + tlp_str_list_node *node = tlp_new(tlp_str_list_node); + + if (node == NULL) + return TLP_FAILED; + + node->str = str; + node->next = NULL; + + if (list->head == NULL) + list->head = node; + + if (list->tail == NULL) + list->tail = node; + + else + { + list->tail->next = node; + list->tail = node; + } + + return TLP_OK; +} + +tlp_result tlp_str_list_append_bytes(tlp_str_list *list, const char *bytes) +{ + tlp_str str = tlp_str_from_bytes(bytes); + if (str == NULL) + return TLP_FAILED; + + return tlp_str_list_append(list, str); +} + void tlp_str_list_free(tlp_str_list *list) { - tlp_str_list *node = list, *temp; + tlp_str_list_node *node = list->head, *temp; while (node != NULL) { @@ -43,6 +106,7 @@ void tlp_str_list_free(tlp_str_list *list) node = temp; } + free(list); list = NULL; } @@ -78,6 +142,9 @@ int tlp_str_start_with_bytes(tlp_str str, const char *prefix) int ret; prefix_str = tlp_str_from_bytes(prefix); + if (prefix_str == NULL) + return 0; + ret = tlp_str_start_with(str, prefix_str); tlp_str_free(prefix_str); |