1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
8 * $Id: tag_table.c 26346 2010-05-28 02:30:27Z jdgordon $
10 * Copyright (C) 2010 Jonathan Gordon
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
26 #include "tag_table.h"
28 #define PUTCH(out, c) fprintf(out, "%c", c)
29 extern struct tag_info legal_tags
[];
32 /** Command line setting **/
33 bool is_mono_display
= false;
38 /* dump "count" args to output replacing '|' with ',' except after the last count.
39 * return the amount of chars read. (start+return will be after the last | )
41 int dump_arg(FILE* out
, const char* start
, int count
, bool close
)
63 #define MATCH(s) (!strcmp(tag->name, s))
64 int parse_tag(FILE* out
, const char* start
, bool in_conditional
)
69 tag
->name
[0] && strncmp(start
, tag
->name
, strlen(tag
->name
)) != 0;
73 if (tag
->params
[0] == '\0')
75 fprintf(out
, "%s", tag
->name
);
76 return strlen(tag
->name
);
78 fprintf(out
, "%s", tag
->name
);
79 len
+= strlen(tag
->name
);
81 /* handle individual tags which accept params */
82 if ((MATCH("bl") || MATCH("pb") || MATCH("pv")) && !in_conditional
)
88 /* TODO: need to verify that we are actually using the long form... */
89 len
+= dump_arg(out
, start
, 5, true);
92 else if (MATCH("d") || MATCH("D") || MATCH("mv") || MATCH("pS") || MATCH("pE") || MATCH("t") || MATCH("Tl"))
94 char temp
[8] = {'\0'};
96 /* tags which maybe have a number after them */
97 while ((*start
>= '0' && *start
<= '9') || *start
== '.')
103 fprintf(out
, "(%s)", temp
);
107 else if (MATCH("xl"))
110 int read
= 1+dump_arg(out
, start
+1, 4, false);
113 if (*start
>= '0' && *start
<= '9')
116 len
+= dump_arg(out
, start
, 1, false);
120 else if (MATCH("xd"))
122 /* NOTE: almost certainly needs work */
124 PUTCH(out
, *start
++); len
++;
125 if ((*start
>= 'a' && *start
<= 'z') ||
126 (*start
>= 'A' && *start
<= 'Z'))
128 PUTCH(out
, *start
); len
++;
135 len
+= 1+dump_arg(out
, start
+1, 4, true);
137 else if (MATCH("Fl"))
140 len
+= 1+dump_arg(out
, start
+1, 2, true);
142 else if (MATCH("Cl"))
145 len
+= 1+dump_arg(out
, start
+1, 4, true);
147 else if (MATCH("Vd") || MATCH("VI"))
150 PUTCH(out
, *start
); len
++;
153 else if (MATCH("Vp"))
155 /* NOTE: almost certainly needs work */
157 len
+= 1+dump_arg(out
, start
+1, 3, true);
159 else if (MATCH("Vl") || MATCH("Vi"))
162 len
+= 1+dump_arg(out
, start
+1, is_mono_display
?6:8, true);
167 len
+= 1+dump_arg(out
, start
+1, is_mono_display
?5:7, true);
179 len
+= 1+dump_arg(out
, start
+1, 1, true);
182 else if (MATCH("St") || MATCH("Sx"))
185 len
+= 1+dump_arg(out
, start
+1, 1, true);
191 len
+= 1+dump_arg(out
, start
+1, 5, true);
196 void parse_text(const char* in
, FILE* out
)
198 const char* end
= in
+strlen(in
);
202 while (in
< end
&& *in
)
223 len
= parse_tag(out
, in
, level
>0);
245 while (*in
&& *in
!= '\n')
257 int main(int argc
, char* argv
[])
259 char buffer
[10*1024], temp
[512];
260 FILE *in
, *out
= stdout
;
261 int filearg
= 1, i
=0;
263 strcmp(argv
[1],"-h") == 0 ||
264 strcmp(argv
[1],"--help") == 0 )
266 printf("Usage: %s [OPTIONS] infile [outfile]\n", argv
[0]);
267 printf("\nOPTIONS:\n");
268 printf("\t-m\tSkin is for a mono display (different viewport tags)\n");
272 while ((argc
> filearg
) && argv
[filearg
][0] == '-')
275 while (argv
[filearg
][i
])
277 switch(argv
[filearg
][i
])
279 case 'm': /* skin is for a mono display */
280 is_mono_display
= true;
289 printf("Missing input filename\n");
293 in
= fopen(argv
[filearg
], "r");
296 while (fgets(temp
, 512, in
))
297 strcat(buffer
, temp
);
303 out
= fopen(argv
[filearg
], "w");
306 printf("Couldn't open %s\n", argv
[filearg
]);
311 parse_text(buffer
, out
);