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 | |
parent | 77f76c0f54c796d4ca72a4b9bcd878b385c6950a (diff) |
Support config.
git-svn-id: svn://tug.org/texlive/trunk@5569 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/tlpkg/lib/C/Makefile | 2 | ||||
-rw-r--r-- | Master/tlpkg/lib/C/tlp-config.c | 54 | ||||
-rw-r--r-- | Master/tlpkg/lib/C/tlp-config.h | 17 | ||||
-rw-r--r-- | Master/tlpkg/lib/C/tlp-src.c | 4 | ||||
-rw-r--r-- | Master/tlpkg/lib/C/tlp-utils.c | 69 | ||||
-rw-r--r-- | Master/tlpkg/lib/C/tlp-utils.h | 18 |
6 files changed, 148 insertions, 16 deletions
diff --git a/Master/tlpkg/lib/C/Makefile b/Master/tlpkg/lib/C/Makefile index 39b165212fe..396b9744290 100644 --- a/Master/tlpkg/lib/C/Makefile +++ b/Master/tlpkg/lib/C/Makefile @@ -3,5 +3,5 @@ SO = dylib all: libtlp.$(SO) -libtlp.$(SO): tlp-src.o tlp-utils.o +libtlp.$(SO): tlp-src.o tlp-config.o tlp-utils.o $(CC) $^ -dynamiclib -o $@ diff --git a/Master/tlpkg/lib/C/tlp-config.c b/Master/tlpkg/lib/C/tlp-config.c index aa164dfd6d2..5633db611dd 100644 --- a/Master/tlpkg/lib/C/tlp-config.c +++ b/Master/tlpkg/lib/C/tlp-config.c @@ -6,28 +6,70 @@ * This file is licensed under the GNU General Public License version 2 * or any later version. */ +#include <tlp-utils.h> #include <stdlib.h> #define TLP_META_CATEGORIES "Collection", "Scheme" #define TLP_NORMAL_CATEGORIES "Package", "TLCore", "Documentation" +#define TLP_DEFAULT_CATEGORY "Package" const char *_tlp_meta_categories[] = { TLP_META_CATEGORIES, - NULL }; const char *_tlp_normal_categories[] = { TLP_NORMAL_CATEGORIES, - NULL }; const char *_tlp_categories[] = { TLP_META_CATEGORIES, TLP_NORMAL_CATEGORIES, - NULL }; -const char **tlp_meta_categories = _tlp_meta_categories; -const char **tlp_normal_categories = _tlp_normal_categories; -const char **tlp_categories = _tlp_categories; +tlp_str_list *tlp_meta_categories; +tlp_str_list *tlp_normal_categories; +tlp_str_list *tlp_categories; +tlp_str tlp_default_category; + +#define ARR_SIZE(arr) (sizeof(arr) / sizeof(arr[0])) + +/* TODO: we might have more complicated implementation later. */ +tlp_result tlp_config_init() +{ + tlp_meta_categories = tlp_str_list_from_array(_tlp_meta_categories); + if (tlp_meta_categories == NULL) + goto failed1; + + tlp_normal_categories = tlp_str_list_from_array(_tlp_normal_categories); + if (tlp_normal_categories == NULL) + goto failed2; + + tlp_categories = tlp_str_list_from_array(_tlp_categories); + if (tlp_categories == NULL) + goto failed3; + + tlp_default_category = tlp_str_from_bytes(TLP_DEFAULT_CATEGORY); + if (tlp_default_category == NULL) + goto failed4; + + return TLP_OK; + +failed4: + tlp_str_list_free(tlp_categories); +failed3: + tlp_str_list_free(tlp_normal_categories); +failed2: + tlp_str_list_free(tlp_meta_categories); +failed1: + return TLP_FAILED; +} + +void tlp_config_free() +{ + tlp_str_list_free(tlp_meta_categories); + tlp_str_list_free(tlp_normal_categories); + tlp_str_list_free(tlp_categories); + + tlp_str_free(tlp_default_category); +} diff --git a/Master/tlpkg/lib/C/tlp-config.h b/Master/tlpkg/lib/C/tlp-config.h index 6b02f88bf33..c00e2143c84 100644 --- a/Master/tlpkg/lib/C/tlp-config.h +++ b/Master/tlpkg/lib/C/tlp-config.h @@ -6,7 +6,18 @@ * This file is licensed under the GNU General Public License version 2 * or any later version. */ -extern const char **tlp_meta_categories; -extern const char **tlp_normal_categories; -extern const char **tlp_categories; +#ifndef __TLP_CONFIG__ +#define __TLP_CONFIG__ + +/* We use the following pointers to encapsulate the real config module + * implementation: we could use static allocated arrays, or we could + * use dynamic allocated ones, as long as we follow the rule (put a + * NULL pointer at the end of it), internal implementation does not + * matter. */ + +extern tlp_str_list tlp_meta_categories; +extern tlp_str_list tlp_normal_categories; +extern tlp_str_list tlp_categories; + +#endif diff --git a/Master/tlpkg/lib/C/tlp-src.c b/Master/tlpkg/lib/C/tlp-src.c index 457709c0076..a67aacbb74f 100644 --- a/Master/tlpkg/lib/C/tlp-src.c +++ b/Master/tlpkg/lib/C/tlp-src.c @@ -194,7 +194,9 @@ tlp_result tlp_src_process_line(tlp_src *src, tlp_str line, if (tlp_str_start_with_bytes(line, tlp_src_fields[i].key)) return tlp_src_fields[i].func(line, src, started, file); - return TLP_FAILED; + tlp_error_msg("%s: unknown tlpsrc directive, please fix: %s", + file, line); + return TLP_OK; } tlp_result tlp_src_get_name(tlp_str line, 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); diff --git a/Master/tlpkg/lib/C/tlp-utils.h b/Master/tlpkg/lib/C/tlp-utils.h index 60e74848fc5..a2332bf8d4f 100644 --- a/Master/tlpkg/lib/C/tlp-utils.h +++ b/Master/tlpkg/lib/C/tlp-utils.h @@ -17,16 +17,20 @@ typedef char tlp_char; typedef tlp_char *tlp_str; #define TLP_CHAR(x) ((tlp_char) x) -#define TLP_STR(x) ((tlp_str) x) enum tlp_special_chars { TLP_CHAR_COMMENT = TLP_CHAR('#'), TLP_CHAR_END = TLP_CHAR('\0'), }; -typedef struct tlp_str_list { +typedef struct tlp_str_list_node { tlp_str str; - struct tlp_str_list *next; + struct tlp_str_list_node *next; +} tlp_str_list_node; + +typedef struct tlp_str_list { + struct tlp_str_list_node *head; + struct tlp_str_list_node *tail; } tlp_str_list; typedef tlp_str_list tlp_execute; @@ -44,7 +48,13 @@ typedef enum tlp_result { tlp_str tlp_str_from_bytes(const char *bytes); tlp_str tlp_str_copy(tlp_str str); void tlp_str_free(tlp_str str); -void tlp_str_list_free(tlp_str_list *list); + + +tlp_str_list *tlp_str_list_new(); +tlp_str_list *tlp_str_list_from_array(const char *array[]); +tlp_result tlp_str_list_append(tlp_str_list *list, tlp_str str); +tlp_result tlp_str_list_append_bytes(tlp_str_list *list, const char *bytes); +void tlp_str_list_free(tlp_str_list *list); tlp_str tlp_fgets(tlp_str s, int n, FILE *fp); size_t tlp_str_len(tlp_str str); |