summaryrefslogtreecommitdiff
path: root/Master/tlpkg/archive/lib/C/tlp-config.c
blob: 5633db611dd97861edf6170030e402ac7a7783c6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* tlp-config.c - module exporting configuration stuff
 *
 * Copyright 2007 Jjgod Jiang
 * Derived from the Perl implementation by Norbert Preining
 *
 * 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, 
};

const char *_tlp_normal_categories[] = {
    TLP_NORMAL_CATEGORIES,
};

const char *_tlp_categories[] = {
    TLP_META_CATEGORIES, 
    TLP_NORMAL_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);
}