summaryrefslogtreecommitdiffstats
path: root/utils/themeeditor/skin_parser.h
blob: 7b3ab13ad0b69967e04830e6e7c834aa21469628 (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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2010 Robert Bieber
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/

#ifndef GENERIC_PARSER_H
#define GENERIC_PARSER_H

#define SKIN_MAX_MEMORY 1048576

/********************************************************************
 ******  A global buffer will be used to store the parse tree *******
 *******************************************************************/
extern char skin_parse_tree[];

/********************************************************************
 ****** Data Structures *********************************************
 *******************************************************************/

/* Possible types of element in a WPS file */
enum skin_element_type
{
    LINE,
    SUBLINES,
    CONDITIONAL,
    TAG,
    NEWLINE,
    TEXT,
    COMMENT,
};

enum skin_errorcode
{
    MEMORY_LIMIT_EXCEEDED,
    NEWLINE_EXPECTED,
    ILLEGAL_TAG,
    ARGLIST_EXPECTED,
    TOO_MANY_ARGS,
    DEFAULT_NOT_ALLOWED,
    UNEXPECTED_NEWLINE,
    INSUFFICIENT_ARGS,
    INT_EXPECTED,
    SEPERATOR_EXPECTED,
    CLOSE_EXPECTED,
    MULTILINE_EXPECTED
};

/* Holds a tag parameter, either numeric or text */
struct skin_tag_parameter
{
    enum
    {
        NUMERIC,
        STRING,
        CODE,
        DEFAULT
    } type;

    union
    {
        int numeric;
        char* text;
        struct skin_element* code;
    } data;
            
};

/* Defines an element of a SKIN file */
struct skin_element
{
    /* Defines what type of element it is */
    enum skin_element_type type;

    /* The line on which it's defined in the source file */
    int line;

    /* Text for comments and plaintext */
    char* text;

    /* The tag or conditional name */
    char name[3];

    /* Pointer to and size of an array of parameters */
    int params_count;
    struct skin_tag_parameter* params;

    /* Pointer to and size of an array of children */
    int children_count;
    struct skin_element** children;

    /* Link to the next element */
    struct skin_element* next;
};

/***********************************************************************
 ***** Functions *******************************************************
 **********************************************************************/

/* Parses a WPS document and returns a list of skin_element
   structures. */
struct skin_element* skin_parse(char* document);

/* Memory management functions */
struct skin_element* skin_alloc_element();
struct skin_element** skin_alloc_children(int count);
struct skin_tag_parameter* skin_alloc_params(int count);
char* skin_alloc_string(int length);

void skin_free_tree(struct skin_element* root);

#endif /* GENERIC_PARSER_H */