summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNils Wallménius <nils@rockbox.org>2010-07-31 16:25:41 +0000
committerNils Wallménius <nils@rockbox.org>2010-07-31 16:25:41 +0000
commit597ccddb39c625812157db7ab4bda4b4209021ac (patch)
tree43318923ef7d81f0a6de0d2cc119b0e8d6b54d51
parent1aaaa9e75702448704f95c156437e019bde2cb08 (diff)
downloadrockbox-597ccddb39c625812157db7ab4bda4b4209021ac.tar.gz
rockbox-597ccddb39c625812157db7ab4bda4b4209021ac.zip
skinparser lib: more const correctness
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27641 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--lib/skin_parser/skin_parser.c80
-rw-r--r--lib/skin_parser/skin_scan.c16
-rw-r--r--lib/skin_parser/skin_scan.h12
3 files changed, 48 insertions, 60 deletions
diff --git a/lib/skin_parser/skin_parser.c b/lib/skin_parser/skin_parser.c
index 7f648cf0ae..3554629608 100644
--- a/lib/skin_parser/skin_parser.c
+++ b/lib/skin_parser/skin_parser.c
@@ -44,24 +44,24 @@ static void* callback_data;
44#endif 44#endif
45 45
46/* Auxiliary parsing functions (not visible at global scope) */ 46/* Auxiliary parsing functions (not visible at global scope) */
47static struct skin_element* skin_parse_viewport(char** document); 47static struct skin_element* skin_parse_viewport(const char** document);
48static struct skin_element* skin_parse_line(char** document); 48static struct skin_element* skin_parse_line(const char** document);
49static struct skin_element* skin_parse_line_optional(char** document, 49static struct skin_element* skin_parse_line_optional(const char** document,
50 int conditional); 50 int conditional);
51static struct skin_element* skin_parse_sublines(char** document); 51static struct skin_element* skin_parse_sublines(const char** document);
52static struct skin_element* skin_parse_sublines_optional(char** document, 52static struct skin_element* skin_parse_sublines_optional(const char** document,
53 int conditional); 53 int conditional);
54 54
55static int skin_parse_tag(struct skin_element* element, char** document); 55static int skin_parse_tag(struct skin_element* element, const char** document);
56static int skin_parse_text(struct skin_element* element, char** document, 56static int skin_parse_text(struct skin_element* element, const char** document,
57 int conditional); 57 int conditional);
58static int skin_parse_conditional(struct skin_element* element, 58static int skin_parse_conditional(struct skin_element* element,
59 char** document); 59 const char** document);
60static int skin_parse_comment(struct skin_element* element, char** document); 60static int skin_parse_comment(struct skin_element* element, const char** document);
61static struct skin_element* skin_parse_code_as_arg(char** document); 61static struct skin_element* skin_parse_code_as_arg(const char** document);
62 62
63 63
64static void skip_whitespace(char** document) 64static void skip_whitespace(const char** document)
65{ 65{
66 while(**document == ' ' || **document == '\t') 66 while(**document == ' ' || **document == '\t')
67 (*document)++; 67 (*document)++;
@@ -70,7 +70,6 @@ static void skip_whitespace(char** document)
70#ifdef ROCKBOX 70#ifdef ROCKBOX
71struct skin_element* skin_parse(const char* document, 71struct skin_element* skin_parse(const char* document,
72 skin_callback cb, void* cb_data) 72 skin_callback cb, void* cb_data)
73
74{ 73{
75 callback = cb; 74 callback = cb;
76 callback_data = cb_data; 75 callback_data = cb_data;
@@ -83,7 +82,7 @@ struct skin_element* skin_parse(const char* document)
83 82
84 struct skin_element** to_write = 0; 83 struct skin_element** to_write = 0;
85 84
86 char* cursor = (char*)document; /*Keeps track of location in the document*/ 85 const char* cursor = document; /*Keeps track of location in the document*/
87 86
88 skin_line = 1; 87 skin_line = 1;
89 skin_start = (char*)document; 88 skin_start = (char*)document;
@@ -117,9 +116,8 @@ struct skin_element* skin_parse(const char* document)
117 116
118} 117}
119 118
120static struct skin_element* skin_parse_viewport(char** document) 119static struct skin_element* skin_parse_viewport(const char** document)
121{ 120{
122
123 struct skin_element* root = NULL; 121 struct skin_element* root = NULL;
124 struct skin_element* last = NULL; 122 struct skin_element* last = NULL;
125 struct skin_element* retval = NULL; 123 struct skin_element* retval = NULL;
@@ -134,8 +132,8 @@ static struct skin_element* skin_parse_viewport(char** document)
134 132
135 struct skin_element** to_write = 0; 133 struct skin_element** to_write = 0;
136 134
137 char* cursor = *document; /* Keeps track of location in the document */ 135 const char* cursor = *document; /* Keeps track of location in the document */
138 char* bookmark; /* Used when we need to look ahead */ 136 const char* bookmark; /* Used when we need to look ahead */
139 137
140 int sublines = 0; /* Flag for parsing sublines */ 138 int sublines = 0; /* Flag for parsing sublines */
141 139
@@ -242,28 +240,24 @@ static struct skin_element* skin_parse_viewport(char** document)
242 240
243 retval->children[0] = root; 241 retval->children[0] = root;
244 return retval; 242 return retval;
245
246} 243}
247 244
248/* Auxiliary Parsing Functions */ 245/* Auxiliary Parsing Functions */
249 246
250static struct skin_element* skin_parse_line(char**document) 247static struct skin_element* skin_parse_line(const char**document)
251{ 248{
252
253 return skin_parse_line_optional(document, 0); 249 return skin_parse_line_optional(document, 0);
254
255} 250}
256 251
257
258/* 252/*
259 * If conditional is set to true, then this will break upon encountering 253 * If conditional is set to true, then this will break upon encountering
260 * SEPERATESYM. This should only be used when parsing a line inside a 254 * SEPERATESYM. This should only be used when parsing a line inside a
261 * conditional, otherwise just use the wrapper function skin_parse_line() 255 * conditional, otherwise just use the wrapper function skin_parse_line()
262 */ 256 */
263static struct skin_element* skin_parse_line_optional(char** document, 257static struct skin_element* skin_parse_line_optional(const char** document,
264 int conditional) 258 int conditional)
265{ 259{
266 char* cursor = *document; 260 const char* cursor = *document;
267 261
268 struct skin_element* root = NULL; 262 struct skin_element* root = NULL;
269 struct skin_element* current = NULL; 263 struct skin_element* current = NULL;
@@ -364,16 +358,16 @@ static struct skin_element* skin_parse_line_optional(char** document,
364 return retval; 358 return retval;
365} 359}
366 360
367static struct skin_element* skin_parse_sublines(char** document) 361static struct skin_element* skin_parse_sublines(const char** document)
368{ 362{
369 return skin_parse_sublines_optional(document, 0); 363 return skin_parse_sublines_optional(document, 0);
370} 364}
371 365
372static struct skin_element* skin_parse_sublines_optional(char** document, 366static struct skin_element* skin_parse_sublines_optional(const char** document,
373 int conditional) 367 int conditional)
374{ 368{
375 struct skin_element* retval; 369 struct skin_element* retval;
376 char* cursor = *document; 370 const char* cursor = *document;
377 int sublines = 1; 371 int sublines = 1;
378 int i; 372 int i;
379 373
@@ -458,11 +452,10 @@ static struct skin_element* skin_parse_sublines_optional(char** document,
458 return retval; 452 return retval;
459} 453}
460 454
461static int skin_parse_tag(struct skin_element* element, char** document) 455static int skin_parse_tag(struct skin_element* element, const char** document)
462{ 456{
463 457 const char* cursor = *document + 1;
464 char* cursor = *document + 1; 458 const char* bookmark;
465 char* bookmark;
466 459
467 char tag_name[3]; 460 char tag_name[3];
468 char* tag_args; 461 char* tag_args;
@@ -531,7 +524,6 @@ static int skin_parse_tag(struct skin_element* element, char** document)
531 return 1; 524 return 1;
532 } 525 }
533 526
534
535 /* Checking the number of arguments and allocating args */ 527 /* Checking the number of arguments and allocating args */
536 if(*cursor != ARGLISTOPENSYM && tag_args[0] != '|') 528 if(*cursor != ARGLISTOPENSYM && tag_args[0] != '|')
537 { 529 {
@@ -600,7 +592,6 @@ static int skin_parse_tag(struct skin_element* element, char** document)
600 /* Scanning the arguments */ 592 /* Scanning the arguments */
601 skip_whitespace(&cursor); 593 skip_whitespace(&cursor);
602 594
603
604 /* Checking for comments */ 595 /* Checking for comments */
605 if(*cursor == COMMENTSYM) 596 if(*cursor == COMMENTSYM)
606 skip_comment(&cursor); 597 skip_comment(&cursor);
@@ -705,7 +696,6 @@ static int skin_parse_tag(struct skin_element* element, char** document)
705 req_args = i + 1; 696 req_args = i + 1;
706 tag_args++; 697 tag_args++;
707 } 698 }
708
709 } 699 }
710 700
711 /* Checking for a premature end */ 701 /* Checking for a premature end */
@@ -730,10 +720,10 @@ static int skin_parse_tag(struct skin_element* element, char** document)
730 * If the conditional flag is set true, then parsing text will stop at an 720 * If the conditional flag is set true, then parsing text will stop at an
731 * ARGLISTSEPERATESYM. Only set that flag when parsing within a conditional 721 * ARGLISTSEPERATESYM. Only set that flag when parsing within a conditional
732 */ 722 */
733static int skin_parse_text(struct skin_element* element, char** document, 723static int skin_parse_text(struct skin_element* element, const char** document,
734 int conditional) 724 int conditional)
735{ 725{
736 char* cursor = *document; 726 const char* cursor = *document;
737 int length = 0; 727 int length = 0;
738 int dest; 728 int dest;
739 char *text = NULL; 729 char *text = NULL;
@@ -794,17 +784,16 @@ static int skin_parse_text(struct skin_element* element, char** document,
794 return 1; 784 return 1;
795} 785}
796 786
797static int skin_parse_conditional(struct skin_element* element, char** document) 787static int skin_parse_conditional(struct skin_element* element, const char** document)
798{ 788{
799 789 const char* cursor = *document + 1; /* Starting past the "%" */
800 char* cursor = *document + 1; /* Starting past the "%" */ 790 const char* bookmark;
801 char* bookmark;
802 int children = 1; 791 int children = 1;
803 int i; 792 int i;
804 793
805#ifdef ROCKBOX 794#ifdef ROCKBOX
806 bool feature_available = true; 795 bool feature_available = true;
807 char *false_branch = NULL; 796 const char *false_branch = NULL;
808#endif 797#endif
809 798
810 /* Some conditional tags allow for target feature checking, 799 /* Some conditional tags allow for target feature checking,
@@ -920,9 +909,9 @@ static int skin_parse_conditional(struct skin_element* element, char** document)
920 return 1; 909 return 1;
921} 910}
922 911
923static int skin_parse_comment(struct skin_element* element, char** document) 912static int skin_parse_comment(struct skin_element* element, const char** document)
924{ 913{
925 char* cursor = *document; 914 const char* cursor = *document;
926#ifndef ROCKBOX 915#ifndef ROCKBOX
927 char* text = NULL; 916 char* text = NULL;
928#endif 917#endif
@@ -957,11 +946,10 @@ static int skin_parse_comment(struct skin_element* element, char** document)
957 return 1; 946 return 1;
958} 947}
959 948
960static struct skin_element* skin_parse_code_as_arg(char** document) 949static struct skin_element* skin_parse_code_as_arg(const char** document)
961{ 950{
962
963 int sublines = 0; 951 int sublines = 0;
964 char* cursor = *document; 952 const char* cursor = *document;
965 953
966 /* Checking for sublines */ 954 /* Checking for sublines */
967 while(*cursor != '\n' && *cursor != '\0' 955 while(*cursor != '\n' && *cursor != '\0'
diff --git a/lib/skin_parser/skin_scan.c b/lib/skin_parser/skin_scan.c
index d18f2224b3..de9c423f04 100644
--- a/lib/skin_parser/skin_scan.c
+++ b/lib/skin_parser/skin_scan.c
@@ -32,7 +32,7 @@
32/* Scanning Functions */ 32/* Scanning Functions */
33 33
34/* Simple function to advance a char* past a comment */ 34/* Simple function to advance a char* past a comment */
35void skip_comment(char** document) 35void skip_comment(const char** document)
36{ 36{
37 while(**document != '\n' && **document != '\0') 37 while(**document != '\n' && **document != '\0')
38 (*document)++; 38 (*document)++;
@@ -40,7 +40,7 @@ void skip_comment(char** document)
40 (*document)++; 40 (*document)++;
41} 41}
42 42
43void skip_arglist(char** document) 43void skip_arglist(const char** document)
44{ 44{
45 if(**document == ARGLISTOPENSYM) 45 if(**document == ARGLISTOPENSYM)
46 (*document)++; 46 (*document)++;
@@ -66,7 +66,7 @@ void skip_arglist(char** document)
66 (*document)++; 66 (*document)++;
67} 67}
68 68
69void skip_enumlist(char** document) 69void skip_enumlist(const char** document)
70{ 70{
71 if(**document == ENUMLISTOPENSYM) 71 if(**document == ENUMLISTOPENSYM)
72 (*document)++; 72 (*document)++;
@@ -93,10 +93,10 @@ void skip_enumlist(char** document)
93 (*document)++; 93 (*document)++;
94} 94}
95 95
96char* scan_string(char** document) 96char* scan_string(const char** document)
97{ 97{
98 98
99 char* cursor = *document; 99 const char* cursor = *document;
100 int length = 0; 100 int length = 0;
101 char* buffer = NULL; 101 char* buffer = NULL;
102 int i; 102 int i;
@@ -149,10 +149,10 @@ char* scan_string(char** document)
149 return buffer; 149 return buffer;
150} 150}
151 151
152int scan_int(char** document) 152int scan_int(const char** document)
153{ 153{
154 154
155 char* cursor = *document, *end; 155 const char *cursor = *document, *end;
156 int length = 0; 156 int length = 0;
157 char buffer[16]; 157 char buffer[16];
158 int retval; 158 int retval;
@@ -194,7 +194,7 @@ int scan_int(char** document)
194 return retval; 194 return retval;
195} 195}
196 196
197int check_viewport(char* document) 197int check_viewport(const char* document)
198{ 198{
199 if(strlen(document) < 3) 199 if(strlen(document) < 3)
200 return 0; 200 return 0;
diff --git a/lib/skin_parser/skin_scan.h b/lib/skin_parser/skin_scan.h
index 72d4475767..47d8289f98 100644
--- a/lib/skin_parser/skin_scan.h
+++ b/lib/skin_parser/skin_scan.h
@@ -29,12 +29,12 @@ extern "C"
29 29
30 30
31/* Scanning functions */ 31/* Scanning functions */
32void skip_comment(char** document); 32void skip_comment(const char** document);
33void skip_arglist(char** document); 33void skip_arglist(const char** document);
34void skip_enumlist(char** document); 34void skip_enumlist(const char** document);
35char* scan_string(char** document); 35char* scan_string(const char** document);
36int scan_int(char** document); 36int scan_int(const char** document);
37int check_viewport(char* document); /* Checks for a viewport declaration */ 37int check_viewport(const char* document); /* Checks for a viewport declaration */
38 38
39#ifdef __cplusplus 39#ifdef __cplusplus
40} 40}