2010-05-28 05:25:48 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id: tag_table.c 26346 2010-05-28 02:30:27Z jdgordon $
|
|
|
|
*
|
|
|
|
* Copyright (C) 2010 Jonathan Gordon
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-05-27 15:35:22 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <string.h>
|
change the %Cl tag to be cleaner. it it now %Cl(x, y, width, height [, xalign][, yalign])
d,i,s modifiers are no longer supported (were there for origional compatability) and +,- modifiers are not supported anymore either.
Legal values for xalign are: l,c,r (left, center, right)
Legal values for xalign are: t,c,b (top, center, bottom)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26475 a1c6a512-1295-4272-9138-f99709370657
2010-06-02 09:51:03 +00:00
|
|
|
#include <ctype.h>
|
2010-05-27 15:35:22 +00:00
|
|
|
#include "tag_table.h"
|
|
|
|
|
|
|
|
#define PUTCH(out, c) fprintf(out, "%c", c)
|
|
|
|
extern struct tag_info legal_tags[];
|
2010-05-28 02:30:27 +00:00
|
|
|
|
2010-05-29 09:35:05 +00:00
|
|
|
char images_with_subimages[100];
|
|
|
|
int image_count = 0;
|
2010-05-28 02:30:27 +00:00
|
|
|
|
|
|
|
/** Command line setting **/
|
|
|
|
bool is_mono_display = false;
|
2010-05-30 11:54:52 +00:00
|
|
|
bool use_new_vp_tags = true;
|
2010-05-28 02:30:27 +00:00
|
|
|
|
|
|
|
|
2010-05-27 15:35:22 +00:00
|
|
|
/* dump "count" args to output replacing '|' with ',' except after the last count.
|
|
|
|
* return the amount of chars read. (start+return will be after the last | )
|
|
|
|
*/
|
|
|
|
int dump_arg(FILE* out, const char* start, int count, bool close)
|
|
|
|
{
|
|
|
|
int l = 0;
|
|
|
|
while (count)
|
|
|
|
{
|
|
|
|
if (start[l] == '|')
|
|
|
|
{
|
|
|
|
if (count > 1)
|
|
|
|
{
|
2010-05-27 15:55:39 +00:00
|
|
|
PUTCH(out, ',');
|
2010-05-27 15:35:22 +00:00
|
|
|
} else if (close) {
|
2010-05-27 15:55:39 +00:00
|
|
|
PUTCH(out, ')');
|
2010-05-27 15:35:22 +00:00
|
|
|
}
|
|
|
|
count--;
|
|
|
|
} else {
|
2010-06-02 08:18:47 +00:00
|
|
|
if (find_escape_character(start[l]))
|
|
|
|
{
|
|
|
|
PUTCH(out, '%');
|
|
|
|
}
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, start[l]);
|
|
|
|
}
|
|
|
|
l++;
|
|
|
|
}
|
|
|
|
return l;
|
|
|
|
}
|
2010-05-28 02:30:27 +00:00
|
|
|
|
2010-05-30 11:54:52 +00:00
|
|
|
int dump_viewport_tags(FILE* out, const char* start)
|
|
|
|
{
|
|
|
|
int len = 0;
|
|
|
|
if (is_mono_display)
|
|
|
|
{
|
|
|
|
return dump_arg(out, start, 5, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
int arg_count = use_new_vp_tags?5:7;
|
|
|
|
len += dump_arg(out, start, arg_count, true);
|
|
|
|
if (!use_new_vp_tags)
|
|
|
|
return len;
|
|
|
|
if (start[len] != '-')
|
|
|
|
{
|
|
|
|
fprintf(out, "%%Vf(");
|
|
|
|
len += dump_arg(out, start+len, 1, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (start[len++] != '|');
|
|
|
|
}
|
|
|
|
if (start[len] != '-')
|
|
|
|
{
|
|
|
|
fprintf(out, "%%Vb(");
|
|
|
|
len += dump_arg(out, start+len, 1, true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
while (start[len++] != '|');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
2010-05-27 15:35:22 +00:00
|
|
|
#define MATCH(s) (!strcmp(tag->name, s))
|
2010-05-28 02:30:27 +00:00
|
|
|
int parse_tag(FILE* out, const char* start, bool in_conditional)
|
2010-05-27 15:35:22 +00:00
|
|
|
{
|
|
|
|
struct tag_info *tag;
|
|
|
|
int len = 0;
|
|
|
|
for(tag = legal_tags;
|
|
|
|
tag->name[0] && strncmp(start, tag->name, strlen(tag->name)) != 0;
|
|
|
|
tag++) ;
|
|
|
|
if (!tag->name[0])
|
|
|
|
return -1;
|
|
|
|
if (tag->params[0] == '\0')
|
|
|
|
{
|
|
|
|
fprintf(out, "%s", tag->name);
|
|
|
|
return strlen(tag->name);
|
|
|
|
}
|
|
|
|
fprintf(out, "%s", tag->name);
|
|
|
|
len += strlen(tag->name);
|
|
|
|
start += len;
|
|
|
|
/* handle individual tags which accept params */
|
2010-05-28 02:30:27 +00:00
|
|
|
if ((MATCH("bl") || MATCH("pb") || MATCH("pv")) && !in_conditional)
|
2010-05-27 15:35:22 +00:00
|
|
|
{
|
|
|
|
if (*start == '|')
|
|
|
|
{
|
2010-05-28 02:30:27 +00:00
|
|
|
len++; start++;
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, '(');
|
|
|
|
/* TODO: need to verify that we are actually using the long form... */
|
|
|
|
len += dump_arg(out, start, 5, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (MATCH("d") || MATCH("D") || MATCH("mv") || MATCH("pS") || MATCH("pE") || MATCH("t") || MATCH("Tl"))
|
|
|
|
{
|
|
|
|
char temp[8] = {'\0'};
|
|
|
|
int i = 0;
|
|
|
|
/* tags which maybe have a number after them */
|
|
|
|
while ((*start >= '0' && *start <= '9') || *start == '.')
|
|
|
|
{
|
|
|
|
temp[i++] = *start++;
|
|
|
|
}
|
|
|
|
if (i!= 0)
|
|
|
|
{
|
|
|
|
fprintf(out, "(%s)", temp);
|
|
|
|
len += i;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (MATCH("xl"))
|
|
|
|
{
|
2010-05-29 09:35:05 +00:00
|
|
|
char label = start[1];
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, '(');
|
2010-05-28 03:06:51 +00:00
|
|
|
int read = 1+dump_arg(out, start+1, 4, false);
|
|
|
|
len += read;
|
|
|
|
start += read;
|
2010-05-28 02:30:27 +00:00
|
|
|
if (*start>= '0' && *start <= '9')
|
|
|
|
{
|
2010-05-29 09:35:05 +00:00
|
|
|
images_with_subimages[image_count++] = label;
|
2010-05-28 02:30:27 +00:00
|
|
|
PUTCH(out, ',');
|
|
|
|
len += dump_arg(out, start, 1, false);
|
|
|
|
}
|
|
|
|
PUTCH(out, ')');
|
2010-05-27 15:35:22 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("xd"))
|
|
|
|
{
|
2010-05-29 09:35:05 +00:00
|
|
|
char label = start[0];
|
|
|
|
int i=0;
|
|
|
|
while (i<image_count)
|
|
|
|
{
|
|
|
|
if (images_with_subimages[i] == label)
|
|
|
|
break;
|
|
|
|
i++;
|
|
|
|
}
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, '(');
|
|
|
|
PUTCH(out, *start++); len++;
|
2010-05-29 09:35:05 +00:00
|
|
|
if (i<image_count &&
|
|
|
|
((*start >= 'a' && *start <= 'z') ||
|
|
|
|
(*start >= 'A' && *start <= 'Z')))
|
2010-05-28 02:30:27 +00:00
|
|
|
{
|
|
|
|
PUTCH(out, *start); len++;
|
|
|
|
}
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, ')');
|
|
|
|
}
|
|
|
|
else if (MATCH("x"))
|
|
|
|
{
|
|
|
|
PUTCH(out, '(');
|
|
|
|
len += 1+dump_arg(out, start+1, 4, true);
|
|
|
|
}
|
|
|
|
else if (MATCH("Fl"))
|
|
|
|
{
|
|
|
|
PUTCH(out, '(');
|
|
|
|
len += 1+dump_arg(out, start+1, 2, true);
|
|
|
|
}
|
|
|
|
else if (MATCH("Cl"))
|
|
|
|
{
|
change the %Cl tag to be cleaner. it it now %Cl(x, y, width, height [, xalign][, yalign])
d,i,s modifiers are no longer supported (were there for origional compatability) and +,- modifiers are not supported anymore either.
Legal values for xalign are: l,c,r (left, center, right)
Legal values for xalign are: t,c,b (top, center, bottom)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26475 a1c6a512-1295-4272-9138-f99709370657
2010-06-02 09:51:03 +00:00
|
|
|
int read;
|
|
|
|
char xalign = '\0', yalign = '\0';
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, '(');
|
change the %Cl tag to be cleaner. it it now %Cl(x, y, width, height [, xalign][, yalign])
d,i,s modifiers are no longer supported (were there for origional compatability) and +,- modifiers are not supported anymore either.
Legal values for xalign are: l,c,r (left, center, right)
Legal values for xalign are: t,c,b (top, center, bottom)
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26475 a1c6a512-1295-4272-9138-f99709370657
2010-06-02 09:51:03 +00:00
|
|
|
read = 1+dump_arg(out, start+1, 2, false);
|
|
|
|
len += read;
|
|
|
|
start += read;
|
|
|
|
switch (tolower(*start))
|
|
|
|
{
|
|
|
|
case 'l':
|
|
|
|
case 'c':
|
|
|
|
case 'r':
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
xalign = *start;
|
|
|
|
len++;
|
|
|
|
start++;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
case 'i':
|
|
|
|
case 'I':
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
len++;
|
|
|
|
start++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PUTCH(out,',');
|
|
|
|
read = dump_arg(out, start, 1, false);
|
|
|
|
len += read;
|
|
|
|
start += read;
|
|
|
|
switch (tolower(*start))
|
|
|
|
{
|
|
|
|
case 't':
|
|
|
|
case 'c':
|
|
|
|
case 'b':
|
|
|
|
case '+':
|
|
|
|
case '-':
|
|
|
|
yalign = *start;
|
|
|
|
len++;
|
|
|
|
start++;
|
|
|
|
break;
|
|
|
|
case 'd':
|
|
|
|
case 'D':
|
|
|
|
case 'i':
|
|
|
|
case 'I':
|
|
|
|
case 's':
|
|
|
|
case 'S':
|
|
|
|
len++;
|
|
|
|
start++;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
PUTCH(out,',');
|
|
|
|
read = dump_arg(out, start, 1, false);
|
|
|
|
if (xalign)
|
|
|
|
{
|
|
|
|
if (xalign == '-')
|
|
|
|
xalign = 'l';
|
|
|
|
if (xalign == '+')
|
|
|
|
xalign = 'r';
|
|
|
|
fprintf(out, ",%c", xalign);
|
|
|
|
}
|
|
|
|
if (yalign)
|
|
|
|
{
|
|
|
|
if (yalign == '-')
|
|
|
|
yalign = 't';
|
|
|
|
if (yalign == '+')
|
|
|
|
yalign = 'b';
|
|
|
|
fprintf(out, ",%s%c", xalign?"":"-,", yalign);
|
|
|
|
}
|
|
|
|
PUTCH(out, ')');
|
|
|
|
len += read;
|
2010-05-27 15:35:22 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("Vd") || MATCH("VI"))
|
|
|
|
{
|
|
|
|
PUTCH(out, '(');
|
|
|
|
PUTCH(out, *start); len++;
|
|
|
|
PUTCH(out, ')');
|
|
|
|
}
|
|
|
|
else if (MATCH("Vp"))
|
|
|
|
{
|
|
|
|
/* NOTE: almost certainly needs work */
|
|
|
|
PUTCH(out, '(');
|
|
|
|
len += 1+dump_arg(out, start+1, 3, true);
|
|
|
|
}
|
|
|
|
else if (MATCH("Vl") || MATCH("Vi"))
|
|
|
|
{
|
2010-05-30 11:54:52 +00:00
|
|
|
int read;
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, '(');
|
2010-05-30 11:54:52 +00:00
|
|
|
read = 1+dump_arg(out, start+1, 1, false);
|
|
|
|
PUTCH(out, ',');
|
|
|
|
len += read + dump_viewport_tags(out, start+read);
|
2010-05-27 15:35:22 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("V"))
|
|
|
|
{
|
|
|
|
PUTCH(out, '(');
|
2010-05-30 11:54:52 +00:00
|
|
|
len += 1+dump_viewport_tags(out, start+1);
|
2010-05-27 15:35:22 +00:00
|
|
|
}
|
|
|
|
else if (MATCH("X"))
|
|
|
|
{
|
|
|
|
if (*start+1 == 'd')
|
|
|
|
{
|
|
|
|
fprintf(out, "(d)");
|
|
|
|
len ++;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
PUTCH(out, '(');
|
|
|
|
len += 1+dump_arg(out, start+1, 1, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (MATCH("St") || MATCH("Sx"))
|
|
|
|
{
|
|
|
|
PUTCH(out, '(');
|
|
|
|
len += 1+dump_arg(out, start+1, 1, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
else if (MATCH("T"))
|
|
|
|
{
|
|
|
|
PUTCH(out, '(');
|
|
|
|
len += 1+dump_arg(out, start+1, 5, true);
|
|
|
|
}
|
|
|
|
return len;
|
|
|
|
}
|
|
|
|
|
|
|
|
void parse_text(const char* in, FILE* out)
|
|
|
|
{
|
|
|
|
const char* end = in+strlen(in);
|
2010-05-28 02:30:27 +00:00
|
|
|
int level = 0;
|
|
|
|
int len;
|
2010-05-27 15:35:22 +00:00
|
|
|
top:
|
|
|
|
while (in < end && *in)
|
|
|
|
{
|
|
|
|
if (*in == '%')
|
|
|
|
{
|
|
|
|
PUTCH(out, *in++);
|
|
|
|
switch(*in)
|
|
|
|
{
|
|
|
|
|
|
|
|
case '%':
|
|
|
|
case '<':
|
|
|
|
case '|':
|
|
|
|
case '>':
|
|
|
|
case ';':
|
|
|
|
case '#':
|
2010-06-02 08:18:47 +00:00
|
|
|
case ')':
|
|
|
|
case '(':
|
|
|
|
case ',':
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, *in++);
|
|
|
|
goto top;
|
|
|
|
break;
|
|
|
|
case '?':
|
|
|
|
PUTCH(out, *in++);
|
|
|
|
break;
|
|
|
|
}
|
2010-05-28 02:30:27 +00:00
|
|
|
len = parse_tag(out, in, level>0);
|
|
|
|
if (len < 0)
|
|
|
|
{
|
|
|
|
PUTCH(out, *in++);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
in += len;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else if (*in == '<')
|
|
|
|
{
|
|
|
|
level++;
|
|
|
|
PUTCH(out, *in++);
|
|
|
|
}
|
|
|
|
else if (*in == '>')
|
|
|
|
{
|
|
|
|
level--;
|
|
|
|
PUTCH(out, *in++);
|
2010-05-27 15:35:22 +00:00
|
|
|
}
|
2010-06-02 08:18:47 +00:00
|
|
|
else if (*in == '|')
|
|
|
|
{
|
|
|
|
if (level == 0)
|
|
|
|
{
|
|
|
|
PUTCH(out, '%');
|
|
|
|
}
|
|
|
|
PUTCH(out, *in++);
|
|
|
|
}
|
2010-05-27 15:55:39 +00:00
|
|
|
else if (*in == '#')
|
|
|
|
{
|
2010-05-29 09:09:45 +00:00
|
|
|
while (*in && *in != '\n')
|
2010-05-27 15:55:39 +00:00
|
|
|
{
|
|
|
|
PUTCH(out, *in++);
|
|
|
|
}
|
|
|
|
}
|
2010-05-27 15:35:22 +00:00
|
|
|
else
|
|
|
|
{
|
2010-06-02 08:18:47 +00:00
|
|
|
if (find_escape_character(*in))
|
|
|
|
{
|
|
|
|
PUTCH(out, '%');
|
|
|
|
}
|
2010-05-27 15:35:22 +00:00
|
|
|
PUTCH(out, *in++);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char* argv[])
|
|
|
|
{
|
2010-05-27 15:47:32 +00:00
|
|
|
char buffer[10*1024], temp[512];
|
|
|
|
FILE *in, *out = stdout;
|
2010-05-28 02:30:27 +00:00
|
|
|
int filearg = 1, i=0;
|
2010-05-27 15:47:32 +00:00
|
|
|
if( (argc < 2) ||
|
|
|
|
strcmp(argv[1],"-h") == 0 ||
|
|
|
|
strcmp(argv[1],"--help") == 0 )
|
|
|
|
{
|
2010-05-28 02:30:27 +00:00
|
|
|
printf("Usage: %s [OPTIONS] infile [outfile]\n", argv[0]);
|
|
|
|
printf("\nOPTIONS:\n");
|
2010-05-30 11:54:52 +00:00
|
|
|
printf("\t-c\tDon't use new viewport colour tags (non-mono displays only)\n");
|
2010-05-28 02:30:27 +00:00
|
|
|
printf("\t-m\tSkin is for a mono display (different viewport tags)\n");
|
2010-05-27 15:47:32 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2010-05-28 02:30:27 +00:00
|
|
|
|
|
|
|
while ((argc > filearg) && argv[filearg][0] == '-')
|
|
|
|
{
|
|
|
|
i=1;
|
|
|
|
while (argv[filearg][i])
|
|
|
|
{
|
|
|
|
switch(argv[filearg][i])
|
|
|
|
{
|
2010-05-30 11:54:52 +00:00
|
|
|
case 'c': /* disable new colour tags */
|
|
|
|
use_new_vp_tags = false;
|
|
|
|
break;
|
2010-05-28 02:30:27 +00:00
|
|
|
case 'm': /* skin is for a mono display */
|
|
|
|
is_mono_display = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
filearg++;
|
|
|
|
}
|
|
|
|
if (argc == filearg)
|
|
|
|
{
|
|
|
|
printf("Missing input filename\n");
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
in = fopen(argv[filearg], "r");
|
2010-05-27 15:47:32 +00:00
|
|
|
if (!in)
|
|
|
|
return 1;
|
|
|
|
while (fgets(temp, 512, in))
|
|
|
|
strcat(buffer, temp);
|
2010-05-28 02:30:27 +00:00
|
|
|
fclose(in);
|
|
|
|
filearg++;
|
2010-05-27 15:47:32 +00:00
|
|
|
|
2010-05-28 02:30:27 +00:00
|
|
|
if (argc > filearg)
|
2010-05-27 15:47:32 +00:00
|
|
|
{
|
2010-05-28 02:30:27 +00:00
|
|
|
out = fopen(argv[filearg], "w");
|
2010-05-27 15:47:32 +00:00
|
|
|
if (!out)
|
2010-05-28 02:30:27 +00:00
|
|
|
{
|
|
|
|
printf("Couldn't open %s\n", argv[filearg]);
|
2010-05-27 15:47:32 +00:00
|
|
|
return 1;
|
2010-05-28 02:30:27 +00:00
|
|
|
}
|
2010-05-27 15:47:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
parse_text(buffer, out);
|
|
|
|
if (out != stdout)
|
|
|
|
fclose(out);
|
2010-05-27 15:35:22 +00:00
|
|
|
return 0;
|
|
|
|
}
|