From 59461acd7755f810cfd60f8eb481174d2017f895 Mon Sep 17 00:00:00 2001 From: jdgordon Date: Thu, 27 May 2010 15:35:22 +0000 Subject: [PATCH] first go at a general skin updater program. not very useful yet git-svn-id: svn://svn.rockbox.org/rockbox/trunk@26332 a1c6a512-1295-4272-9138-f99709370657 --- utils/skinupdater/skinupdater.c | 199 +++++++++++++++++++++++++++++++ utils/skinupdater/tag_table.c | 252 ++++++++++++++++++++++++++++++++++++++++ utils/skinupdater/tag_table.h | 82 +++++++++++++ 3 files changed, 533 insertions(+) create mode 100644 utils/skinupdater/skinupdater.c create mode 100644 utils/skinupdater/tag_table.c create mode 100644 utils/skinupdater/tag_table.h diff --git a/utils/skinupdater/skinupdater.c b/utils/skinupdater/skinupdater.c new file mode 100644 index 000000000..060d4dda4 --- /dev/null +++ b/utils/skinupdater/skinupdater.c @@ -0,0 +1,199 @@ +#include +#include +#include +#include +#include "tag_table.h" + +#define PUTCH(out, c) fprintf(out, "%c", c) +extern struct tag_info legal_tags[]; +/* 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) + { + printf(","); + } else if (close) { + printf(")"); + } + count--; + } else { + PUTCH(out, start[l]); + } + l++; + } + return l; +} +#define MATCH(s) (!strcmp(tag->name, s)) +int parse_tag(FILE* out, const char* start) +{ + 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 */ + if (MATCH("bl") || MATCH("pb") || MATCH("pv")) + { + start++; len++; + if (*start == '|') + { + 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")) + { + PUTCH(out, '('); + len += 1+dump_arg(out, start+1, 5, true); + } + else if (MATCH("xd")) + { + /* NOTE: almost certainly needs work */ + PUTCH(out, '('); + PUTCH(out, *start++); len++; + if ((*start >= 'a' && *start <= 'z') || + (*start >= 'A' && *start <= 'Z')) + PUTCH(out, *start); len++; + 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")) + { + PUTCH(out, '('); + len += 1+dump_arg(out, start+1, 4, true); + } + 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")) + { + PUTCH(out, '('); + len += 1+dump_arg(out, start+1, 8, true); + } + else if (MATCH("V")) + { + PUTCH(out, '('); + len += 1+dump_arg(out, start+1, 7, true); + } + 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); +top: + while (in < end && *in) + { + if (*in == '%') + { + PUTCH(out, *in++); + switch(*in) + { + + case '%': + case '<': + case '|': + case '>': + case ';': + case '#': + PUTCH(out, *in++); + goto top; + break; + case '?': + PUTCH(out, *in++); + break; + } + in += parse_tag(out, in); + } + else + { + PUTCH(out, *in++); + } + } +} + +int main(int argc, char* argv[]) +{ + parse_text("%s%?it<%?in<%in. |>%it|%fn>\n" + "%s%?ia<%ia|%?d2<%d2|(root)>>\n" + "%s%?id<%id|%?d1<%d1|(root)>> %?iy<(%iy)|>\n\n" + "%al%pc/%pt%ar[%pp:%pe]\n" + "%fbkBit %?fv %?iv<(id3v%iv)|(no id3)>\n" + "%pb\n%pm\n", stdout); + return 0; +} diff --git a/utils/skinupdater/tag_table.c b/utils/skinupdater/tag_table.c new file mode 100644 index 000000000..1f5015fea --- /dev/null +++ b/utils/skinupdater/tag_table.c @@ -0,0 +1,252 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: tag_table.c 26297 2010-05-26 03:53:06Z jdgordon $ + * + * 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. + * + ****************************************************************************/ + +#include "tag_table.h" + +#include + +/* The tag definition table */ +struct tag_info legal_tags[] = +{ + { "ac", "" }, + { "al", "" }, + { "aL", "" }, + { "ar", "" }, + { "aR", "" }, + { "aX", "" }, + + { "bl" , "*fIIII" }, + { "bv", "" }, + { "bt", "" }, + { "bs", "" }, + { "bc", "" }, + { "bp", "" }, + { "bu", "" }, + + + { "cc", "" }, + { "cd", "" }, + { "ce", "" }, + { "cf", "" }, + { "cH", "" }, + { "ck", "" }, + { "cI", "" }, + { "cl", "" }, + { "cm", "" }, + { "cM", "" }, + { "cS", "" }, + { "cy", "" }, + { "cY", "" }, + { "cP", "" }, + { "cp", "" }, + { "ca", "" }, + { "cb", "" }, + { "cu", "" }, + { "cw", "" }, + + { "fb", "" }, + { "fc", "" }, + { "ff", "" }, + { "fk", "" }, + { "fm", "" }, + { "fn", "" }, + { "fp", "" }, + { "fs", "" }, + { "fv", "" }, + { "d" , "I" }, + + { "Fb", "" }, + { "Fc", "" }, + { "Ff", "" }, + { "Fk", "" }, + { "Fm", "" }, + { "Fn", "" }, + { "Fp", "" }, + { "Fs", "" }, + { "Fv", "" }, + { "D" , "I" }, + + + { "ia", "" }, + { "ic", "" }, + { "id", "" }, + { "iA", "" }, + { "iG", "" }, + { "ig", "" }, + { "ik", "" }, + { "in", "" }, + { "it", "" }, + { "iv", "" }, + { "iy", "" }, + { "iC", "" }, + + { "Ia", "" }, + { "Ic", "" }, + { "Id", "" }, + { "IA", "" }, + { "IG", "" }, + { "Ig", "" }, + { "Ik", "" }, + { "In", "" }, + { "It", "" }, + { "Iv", "" }, + { "Iy", "" }, + { "IC", "" }, + + { "Sp", "" }, + { "Ss", "" }, + + { "lh", "" }, + + { "mh", "" }, + { "mr", "" }, + { "mm", "" }, + { "mp", "" }, + { "mv", "|I" }, + + { "pm", "" }, + { "pf", "" }, + { "pb" , "*fIIII" }, + { "pv" , "*fIIII" }, + + { "px", "" }, + { "pc", "" }, + { "pr", "" }, + { "pt", "" }, + { "pS" , "|I"}, + { "pE" , "|I"}, + { "pp", "" }, + { "pe", "" }, + { "pn", "" }, + { "ps", "" }, + + { "rp", "" }, + { "rr", "" }, + { "ra", "" }, + + { "rg", "" }, + { "xf", "" }, + + { "tp", "" }, + { "tt", "" }, + { "tm", "" }, + { "ts", "" }, + { "ta", "" }, + { "tb", "" }, + { "tf", "" }, + { "Ti", "" }, + { "Tn", "" }, + { "Tf", "" }, + { "Tc", "" }, + { "tx", "" }, + { "ty", "" }, + { "tz", "" }, + + { "s", "" }, + { "t" , "I" }, + + { "we", "" }, + { "wd", "" }, + { "wi", "" }, + + { "xl", "SFIIi" }, + { "xd", "S" }, + { "x", "SFII" }, + + { "Fl" , "IF"}, + { "Cl" , "IISS"}, + { "C" , ""}, + + { "Vd" , "S"}, + { "VI" , "S"}, + + { "Vp" , "ICC"}, + { "Lt" , ""}, + { "Li" , ""}, + + { "Vl" , "SIIiii|ii"}, + { "Vi" , "sIIiii|ii"}, + { "V" , "IIiii|ii"}, + + { "X" , "f"}, + + { "St" , "S"}, + { "Sx" , "S"}, + { "Sr" , ""}, + + { "Tl" , "|I"}, + { "cs", "" }, + { "T" , "IIiiI"}, + + { "Rp" , ""}, + { "Rr" , ""}, + { "Rf" , ""}, + { "Re" , ""}, + { "Rb" , ""}, + { "Rm" , ""}, + { "Rs" , ""}, + { "Rn" , ""}, + { "Rh" , ""}, + { "s",""}, + + { "" , ""} /* Keep this here to mark the end of the table */ +}; + +/* A table of legal escapable characters */ +char legal_escape_characters[] = "%(,);#<|>"; + +/* + * Just does a straight search through the tag table to find one by + * the given name + */ +char* find_tag(char* name) +{ + + struct tag_info* current = legal_tags; + + /* + * Continue searching so long as we have a non-empty name string + * and the name of the current element doesn't match the name + * we're searching for + */ + + while(strcmp(current->name, name) && current->name[0] != '\0') + current++; + + if(current->name[0] == '\0') + return NULL; + else + return current->params; + +} + +/* Searches through the legal escape characters string */ +int find_escape_character(char lookup) +{ + char* current = legal_escape_characters; + while(*current != lookup && *current != '\0') + current++; + + if(*current == lookup) + return 1; + else + return 0; +} diff --git a/utils/skinupdater/tag_table.h b/utils/skinupdater/tag_table.h new file mode 100644 index 000000000..7cbabfe76 --- /dev/null +++ b/utils/skinupdater/tag_table.h @@ -0,0 +1,82 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id: tag_table.h 26292 2010-05-25 22:24:08Z bieber $ + * + * 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 TAG_TABLE_H +#define TAG_TABLE_H + +#ifdef __cplusplus +extern "C" +{ +namespace wps +{ +#endif + + +/* + * Struct for tag parsing information + * name - The name of the tag, i.e. V for %V + * params - A string specifying all of the tags parameters, each + * character representing a single parameter. Valid + * characters for parameters are: + * I - Required integer + * i - Nullable integer + * S - Required string + * s - Nullable string + * F - Required file name + * f - Nullable file name + * C - Required WPS code + * Any nullable parameter may be replaced in the WPS file + * with a '-'. To specify that parameters may be left off + * altogether, place a '|' in the parameter string. For + * instance, with the parameter string... + * Ii|Ss + * one integer must be specified, one integer can be + * specified or set to default with '-', and the user can + * stop providing parameters at any time after that. + * To specify multiple instances of the same type, put a + * number before the character. For instance, the string... + * 2s + * will specify two strings. An asterisk (*) at the beginning of the + * string will specify that either all or none of the optional + * + */ +struct tag_info +{ + + char* name; + char* params; + +}; + +/* + * Finds a tag by name and returns its parameter list, or an empty + * string if the tag is not found in the table + */ +char* find_tag(char* name); + +/* + * Determines whether a character is legal to escape or not. If + * lookup is not found in the legal escape characters string, returns + * false, otherwise returns true + */ +int find_escape_character(char lookup); + +#endif /* TAG_TABLE_H */ -- 2.11.4.GIT