summaryrefslogtreecommitdiff
path: root/utils/themeeditor
diff options
context:
space:
mode:
Diffstat (limited to 'utils/themeeditor')
-rw-r--r--utils/themeeditor/main.cpp6
-rw-r--r--utils/themeeditor/parsetreenode.cpp9
-rw-r--r--utils/themeeditor/skin_debug.c10
-rw-r--r--utils/themeeditor/skin_parser.c80
-rw-r--r--utils/themeeditor/skin_parser.h1
-rw-r--r--utils/themeeditor/skin_scan.c20
-rw-r--r--utils/themeeditor/skin_scan.h1
7 files changed, 114 insertions, 13 deletions
diff --git a/utils/themeeditor/main.cpp b/utils/themeeditor/main.cpp
index a3a5daaa6c..87d38b861d 100644
--- a/utils/themeeditor/main.cpp
+++ b/utils/themeeditor/main.cpp
@@ -35,7 +35,11 @@ int main(int argc, char* argv[])
35{ 35{
36 QApplication app(argc, argv); 36 QApplication app(argc, argv);
37 37
38 char doc[] = "#Comment\n%Vd(U);Hey\n%?bl(test,3,5,2,1)<param2|param3>"; 38 char doc[] = "#Comment\n"
39 "%Vd(U);Hey\n"
40 "%?bl(test,3,5,2,1)<param2|param3>\n"
41 "%V(1,2,3,4,5)%pS(5)\n"
42 "Some more stuff here";
39 43
40 ParseTreeModel tree(doc); 44 ParseTreeModel tree(doc);
41 45
diff --git a/utils/themeeditor/parsetreenode.cpp b/utils/themeeditor/parsetreenode.cpp
index caafff5f43..7b77b62ecc 100644
--- a/utils/themeeditor/parsetreenode.cpp
+++ b/utils/themeeditor/parsetreenode.cpp
@@ -64,6 +64,7 @@ ParseTreeNode::ParseTreeNode(struct skin_element* data, ParseTreeNode* parent)
64 } 64 }
65 break; 65 break;
66 66
67 case VIEWPORT:
67 case LINE: 68 case LINE:
68 for(struct skin_element* current = data->children[0]; current; 69 for(struct skin_element* current = data->children[0]; current;
69 current = current->next) 70 current = current->next)
@@ -92,6 +93,10 @@ QString ParseTreeNode::genCode() const
92 { 93 {
93 switch(element->type) 94 switch(element->type)
94 { 95 {
96
97 case VIEWPORT:
98 buffer.append(children[0]->genCode());
99
95 case LINE: 100 case LINE:
96 for(int i = 0; i < children.count(); i++) 101 for(int i = 0; i < children.count(); i++)
97 { 102 {
@@ -220,6 +225,9 @@ QVariant ParseTreeNode::data(int column) const
220 { 225 {
221 switch(element->type) 226 switch(element->type)
222 { 227 {
228 case VIEWPORT:
229 return QObject::tr("Viewport");
230
223 case LINE: 231 case LINE:
224 return QObject::tr("Logical Line"); 232 return QObject::tr("Logical Line");
225 233
@@ -272,6 +280,7 @@ QVariant ParseTreeNode::data(int column) const
272 { 280 {
273 switch(element->type) 281 switch(element->type)
274 { 282 {
283 case VIEWPORT:
275 case LINE: 284 case LINE:
276 case SUBLINES: 285 case SUBLINES:
277 case CONDITIONAL: 286 case CONDITIONAL:
diff --git a/utils/themeeditor/skin_debug.c b/utils/themeeditor/skin_debug.c
index 5d37f64a11..06764f9053 100644
--- a/utils/themeeditor/skin_debug.c
+++ b/utils/themeeditor/skin_debug.c
@@ -91,6 +91,16 @@ void skin_debug_tree(struct skin_element* root)
91 switch(current->type) 91 switch(current->type)
92 { 92 {
93 93
94 case VIEWPORT:
95 printf("[ Viewport \n");
96
97 debug_indent_level++;
98 skin_debug_tree(current->children[0]);
99 debug_indent_level--;
100
101 printf("]");
102 break;
103
94 case TEXT: 104 case TEXT:
95 printf("[ Plain text on line %d : %s ]\n", current->line, 105 printf("[ Plain text on line %d : %s ]\n", current->line,
96 current->text); 106 current->text);
diff --git a/utils/themeeditor/skin_parser.c b/utils/themeeditor/skin_parser.c
index 655c3d18a5..74ba7bd71d 100644
--- a/utils/themeeditor/skin_parser.c
+++ b/utils/themeeditor/skin_parser.c
@@ -38,6 +38,7 @@ int skin_current_block = 0;
38int skin_line = 0; 38int skin_line = 0;
39 39
40/* Auxiliary parsing functions (not visible at global scope) */ 40/* Auxiliary parsing functions (not visible at global scope) */
41struct skin_element* skin_parse_viewport(char** document);
41struct skin_element* skin_parse_line(char** document); 42struct skin_element* skin_parse_line(char** document);
42struct skin_element* skin_parse_line_optional(char** document, int conditional); 43struct skin_element* skin_parse_line_optional(char** document, int conditional);
43struct skin_element* skin_parse_sublines(char** document); 44struct skin_element* skin_parse_sublines(char** document);
@@ -54,26 +55,68 @@ struct skin_element* skin_parse_code_as_arg(char** document);
54 55
55struct skin_element* skin_parse(char* document) 56struct skin_element* skin_parse(char* document)
56{ 57{
57 58
58 struct skin_element* root = NULL; 59 struct skin_element* root = NULL;
59 struct skin_element* last = NULL; 60 struct skin_element* last = NULL;
60 61
61 struct skin_element** to_write = 0; 62 struct skin_element** to_write = 0;
62
63 char* cursor = document; /* Keeps track of location in the document */
64 char* bookmark; /* Used when we need to look ahead */
65 63
66 int sublines = 0; /* Flag for parsing sublines */ 64 char* cursor = document; /* Keeps track of location in the document */
67 65
68 skin_line = 1; 66 skin_line = 1;
69 67
70 while(*cursor != '\0') 68 while(*cursor != '\0')
71 { 69 {
72 70
71 if(!root)
72 to_write = &root;
73 else
74 to_write = &(last->next);
75
76
77 *to_write = skin_parse_viewport(&cursor);
78 last = *to_write;
79 if(!last)
80 return NULL;
81
82 /* Making sure last is at the end */
83 while(last->next)
84 last = last->next;
85
86 }
87
88 return root;
89
90}
91
92struct skin_element* skin_parse_viewport(char** document)
93{
94
95 struct skin_element* root = NULL;
96 struct skin_element* last = NULL;
97 struct skin_element* retval = NULL;
98
99 retval = skin_alloc_element();
100 retval->type = VIEWPORT;
101 retval->children = skin_alloc_children(1);
102 retval->children_count = 1;
103 retval->line = skin_line;
104
105 struct skin_element** to_write = 0;
106
107 char* cursor = *document; /* Keeps track of location in the document */
108 char* bookmark; /* Used when we need to look ahead */
109
110 int sublines = 0; /* Flag for parsing sublines */
111
112 while(*cursor != '\0' && !(check_viewport(cursor) && cursor != *document))
113 {
114
73 /* First, we check to see if this line will contain sublines */ 115 /* First, we check to see if this line will contain sublines */
74 bookmark = cursor; 116 bookmark = cursor;
75 sublines = 0; 117 sublines = 0;
76 while(*cursor != '\n' && *cursor != '\0') 118 while(*cursor != '\n' && *cursor != '\0'
119 && !(check_viewport(cursor) && cursor != *document))
77 { 120 {
78 if(*cursor == MULTILINESYM) 121 if(*cursor == MULTILINESYM)
79 { 122 {
@@ -135,10 +178,13 @@ struct skin_element* skin_parse(char* document)
135 while(last->next) 178 while(last->next)
136 last = last->next; 179 last = last->next;
137 180
138 } 181 }
182
183 *document = cursor;
184
185 retval->children[0] = root;
186 return retval;
139 187
140 return root;
141
142} 188}
143 189
144/* Auxiliary Parsing Functions */ 190/* Auxiliary Parsing Functions */
@@ -176,7 +222,8 @@ struct skin_element* skin_parse_line_optional(char** document, int conditional)
176 || *cursor == ARGLISTCLOSESYM 222 || *cursor == ARGLISTCLOSESYM
177 || *cursor == ENUMLISTSEPERATESYM 223 || *cursor == ENUMLISTSEPERATESYM
178 || *cursor == ENUMLISTCLOSESYM) 224 || *cursor == ENUMLISTCLOSESYM)
179 && conditional)) 225 && conditional)
226 && !(check_viewport(cursor) && cursor != *document))
180 { 227 {
181 /* Allocating memory if necessary */ 228 /* Allocating memory if necessary */
182 if(root) 229 if(root)
@@ -244,7 +291,8 @@ struct skin_element* skin_parse_sublines_optional(char** document,
244 || *cursor == ARGLISTCLOSESYM 291 || *cursor == ARGLISTCLOSESYM
245 || *cursor == ENUMLISTSEPERATESYM 292 || *cursor == ENUMLISTSEPERATESYM
246 || *cursor == ENUMLISTCLOSESYM) 293 || *cursor == ENUMLISTCLOSESYM)
247 && conditional)) 294 && conditional)
295 && !(check_viewport(cursor) && cursor != *document))
248 { 296 {
249 if(*cursor == COMMENTSYM) 297 if(*cursor == COMMENTSYM)
250 skip_comment(&cursor); 298 skip_comment(&cursor);
@@ -405,7 +453,7 @@ int skin_parse_tag(struct skin_element* element, char** document)
405 if(*tag_args == '|') 453 if(*tag_args == '|')
406 { 454 {
407 optional = 1; 455 optional = 1;
408 req_args = i - 1; 456 req_args = i;
409 tag_args++; 457 tag_args++;
410 } 458 }
411 459
@@ -478,6 +526,14 @@ int skin_parse_tag(struct skin_element* element, char** document)
478 526
479 tag_args++; 527 tag_args++;
480 528
529 /* Checking for the optional bar */
530 if(*tag_args == '|')
531 {
532 optional = 1;
533 req_args = i + 1;
534 tag_args++;
535 }
536
481 } 537 }
482 538
483 /* Checking for a premature end */ 539 /* Checking for a premature end */
diff --git a/utils/themeeditor/skin_parser.h b/utils/themeeditor/skin_parser.h
index 201e06c257..77b4ed1158 100644
--- a/utils/themeeditor/skin_parser.h
+++ b/utils/themeeditor/skin_parser.h
@@ -42,6 +42,7 @@ extern char skin_parse_tree[];
42/* Possible types of element in a WPS file */ 42/* Possible types of element in a WPS file */
43enum skin_element_type 43enum skin_element_type
44{ 44{
45 VIEWPORT,
45 LINE, 46 LINE,
46 SUBLINES, 47 SUBLINES,
47 CONDITIONAL, 48 CONDITIONAL,
diff --git a/utils/themeeditor/skin_scan.c b/utils/themeeditor/skin_scan.c
index dfe5d008e5..37c948fb3c 100644
--- a/utils/themeeditor/skin_scan.c
+++ b/utils/themeeditor/skin_scan.c
@@ -22,6 +22,7 @@
22#include <stdio.h> 22#include <stdio.h>
23#include <ctype.h> 23#include <ctype.h>
24#include <stdlib.h> 24#include <stdlib.h>
25#include <string.h>
25 26
26#include "skin_scan.h" 27#include "skin_scan.h"
27#include "skin_debug.h" 28#include "skin_debug.h"
@@ -136,3 +137,22 @@ int scan_int(char** document)
136 *document = cursor; 137 *document = cursor;
137 return retval; 138 return retval;
138} 139}
140
141int check_viewport(char* document)
142{
143 if(strlen(document) < 3)
144 return 0;
145
146 if(document[0] != TAGSYM)
147 return 0;
148
149 if(document[1] != 'V')
150 return 0;
151
152 if(document[2] != ARGLISTOPENSYM
153 && document[2] != 'l'
154 && document[2] != 'i')
155 return 0;
156
157 return 1;
158}
diff --git a/utils/themeeditor/skin_scan.h b/utils/themeeditor/skin_scan.h
index 682e32b3af..6aea92c8a9 100644
--- a/utils/themeeditor/skin_scan.h
+++ b/utils/themeeditor/skin_scan.h
@@ -33,6 +33,7 @@ void skip_comment(char** document);
33void skip_whitespace(char** document); 33void skip_whitespace(char** document);
34char* scan_string(char** document); 34char* scan_string(char** document);
35int scan_int(char** document); 35int scan_int(char** document);
36int check_viewport(char* document); /* Checks for a viewport declaration */
36 37
37#ifdef __cplusplus 38#ifdef __cplusplus
38} 39}