2010-05-25 15:19:52 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* 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 GENERIC_PARSER_H
|
|
|
|
#define GENERIC_PARSER_H
|
|
|
|
|
2010-05-31 17:39:58 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C"
|
|
|
|
{
|
|
|
|
#endif
|
2010-06-10 21:02:44 +00:00
|
|
|
#include <stdlib.h>
|
2010-08-03 12:14:50 +00:00
|
|
|
#include <stdbool.h>
|
2010-05-25 15:19:52 +00:00
|
|
|
|
2011-11-15 14:11:08 +00:00
|
|
|
#if defined(ROCKBOX) && !defined(__PCTOOL__)
|
|
|
|
/* Use this type and macro to convert a pointer from the
|
|
|
|
* skin buffer to a useable pointer */
|
|
|
|
typedef long skinoffset_t;
|
|
|
|
#define SKINOFFSETTOPTR(base, offset) ((offset) < 0 ? NULL : ((void*)&base[offset]))
|
|
|
|
#define PTRTOSKINOFFSET(base, pointer) ((pointer) ? ((void*)pointer-(void*)base) : -1)
|
|
|
|
/* Use this macro when declaring a variable to self-document the code.
|
|
|
|
* type is the actual type being pointed to (i.e OFFSETTYPE(char*) foo )
|
|
|
|
*
|
|
|
|
* WARNING: Don't use the PTRTOSKINOFFSET() around a function call as it wont
|
|
|
|
* do what you expect.
|
|
|
|
*/
|
|
|
|
#define OFFSETTYPE(type) skinoffset_t
|
|
|
|
#else
|
|
|
|
#define SKINOFFSETTOPTR(base, offset) offset
|
|
|
|
#define PTRTOSKINOFFSET(base, pointer) pointer
|
|
|
|
#define OFFSETTYPE(type) type
|
|
|
|
#endif
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
/********************************************************************
|
|
|
|
****** Data Structures *********************************************
|
|
|
|
*******************************************************************/
|
|
|
|
|
|
|
|
/* Possible types of element in a WPS file */
|
|
|
|
enum skin_element_type
|
|
|
|
{
|
2010-06-13 03:13:01 +00:00
|
|
|
UNKNOWN = -1,
|
2010-06-01 07:11:23 +00:00
|
|
|
VIEWPORT,
|
2010-07-04 02:04:14 +00:00
|
|
|
LINE_ALTERNATOR,
|
2010-07-04 02:05:42 +00:00
|
|
|
LINE,
|
2010-05-29 00:04:04 +00:00
|
|
|
CONDITIONAL,
|
|
|
|
TAG,
|
|
|
|
TEXT,
|
2010-05-25 15:19:52 +00:00
|
|
|
COMMENT,
|
|
|
|
};
|
|
|
|
|
|
|
|
enum skin_errorcode
|
|
|
|
{
|
|
|
|
MEMORY_LIMIT_EXCEEDED,
|
|
|
|
NEWLINE_EXPECTED,
|
|
|
|
ILLEGAL_TAG,
|
|
|
|
ARGLIST_EXPECTED,
|
|
|
|
TOO_MANY_ARGS,
|
|
|
|
DEFAULT_NOT_ALLOWED,
|
|
|
|
UNEXPECTED_NEWLINE,
|
|
|
|
INSUFFICIENT_ARGS,
|
|
|
|
INT_EXPECTED,
|
2010-07-15 06:24:11 +00:00
|
|
|
DECIMAL_EXPECTED,
|
2010-11-05 09:51:19 +00:00
|
|
|
SEPARATOR_EXPECTED,
|
2010-05-25 15:19:52 +00:00
|
|
|
CLOSE_EXPECTED,
|
|
|
|
MULTILINE_EXPECTED
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Holds a tag parameter, either numeric or text */
|
|
|
|
struct skin_tag_parameter
|
|
|
|
{
|
|
|
|
enum
|
|
|
|
{
|
2010-07-15 06:24:11 +00:00
|
|
|
INTEGER,
|
|
|
|
DECIMAL, /* stored in data.number as (whole*10)+part */
|
2010-05-25 15:19:52 +00:00
|
|
|
STRING,
|
|
|
|
CODE,
|
|
|
|
DEFAULT
|
|
|
|
} type;
|
|
|
|
|
|
|
|
union
|
|
|
|
{
|
2010-07-15 06:24:11 +00:00
|
|
|
int number;
|
2011-11-15 14:11:08 +00:00
|
|
|
OFFSETTYPE(char*) text;
|
|
|
|
OFFSETTYPE(struct skin_element*) code;
|
2010-05-25 15:19:52 +00:00
|
|
|
} data;
|
2010-06-01 19:55:20 +00:00
|
|
|
|
|
|
|
char type_code;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
};
|
|
|
|
|
2011-10-16 15:55:12 +00:00
|
|
|
/* Defines an element of a SKIN file,
|
|
|
|
*
|
|
|
|
* This is allocated a lot, so it's optimized for size */
|
2010-05-25 15:19:52 +00:00
|
|
|
struct skin_element
|
|
|
|
{
|
2011-10-16 15:55:12 +00:00
|
|
|
/* Link to the next element */
|
2011-11-15 14:11:08 +00:00
|
|
|
OFFSETTYPE(struct skin_element*) next;
|
2011-10-16 15:55:12 +00:00
|
|
|
/* Pointer to an array of children */
|
2011-11-15 14:11:08 +00:00
|
|
|
OFFSETTYPE(struct skin_element**) children;
|
2010-06-10 21:02:44 +00:00
|
|
|
/* Placeholder for element data
|
|
|
|
* TEXT and COMMENT uses it for the text string
|
|
|
|
* TAG, VIEWPORT, LINE, etc may use it for post parse extra storage
|
|
|
|
*/
|
2011-11-15 14:11:08 +00:00
|
|
|
OFFSETTYPE(void*) data;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
|
|
|
/* The tag or conditional name */
|
2010-07-31 11:28:37 +00:00
|
|
|
const struct tag_info *tag;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
2011-10-16 15:55:12 +00:00
|
|
|
/* Pointer to an array of parameters */
|
2011-11-15 14:11:08 +00:00
|
|
|
OFFSETTYPE(struct skin_tag_parameter*) params;
|
2010-05-25 15:19:52 +00:00
|
|
|
|
2011-10-16 15:55:12 +00:00
|
|
|
/* Number of elements in the children array */
|
|
|
|
short children_count;
|
|
|
|
/* The line on which it's defined in the source file */
|
|
|
|
short line;
|
|
|
|
/* Defines what type of element it is */
|
|
|
|
enum skin_element_type type;
|
|
|
|
/* Number of elements in the params array */
|
|
|
|
char params_count;
|
2010-05-25 15:19:52 +00:00
|
|
|
};
|
|
|
|
|
2010-07-29 12:37:48 +00:00
|
|
|
enum skin_cb_returnvalue
|
|
|
|
{
|
|
|
|
CALLBACK_ERROR = -666,
|
|
|
|
FEATURE_NOT_AVAILABLE,
|
|
|
|
CALLBACK_OK = 0,
|
|
|
|
/* > 0 reserved for future use */
|
|
|
|
};
|
|
|
|
typedef int (*skin_callback)(struct skin_element* element, void* data);
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
/***********************************************************************
|
|
|
|
***** Functions *******************************************************
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
/* Parses a WPS document and returns a list of skin_element
|
|
|
|
structures. */
|
2010-07-29 12:37:48 +00:00
|
|
|
#ifdef ROCKBOX
|
|
|
|
struct skin_element* skin_parse(const char* document,
|
|
|
|
skin_callback callback, void* callback_data);
|
|
|
|
#else
|
2010-06-01 21:25:02 +00:00
|
|
|
struct skin_element* skin_parse(const char* document);
|
2010-07-29 12:37:48 +00:00
|
|
|
#endif
|
2010-05-25 15:19:52 +00:00
|
|
|
/* Memory management functions */
|
2010-06-17 11:04:32 +00:00
|
|
|
struct skin_element* skin_alloc_element(void);
|
2011-11-15 14:11:08 +00:00
|
|
|
OFFSETTYPE(struct skin_element*)* skin_alloc_children(int count);
|
|
|
|
struct skin_tag_parameter* skin_alloc_params(int count);
|
2010-05-25 15:19:52 +00:00
|
|
|
char* skin_alloc_string(int length);
|
|
|
|
|
2010-05-25 22:24:08 +00:00
|
|
|
void skin_free_tree(struct skin_element* root);
|
|
|
|
|
2010-06-10 21:02:44 +00:00
|
|
|
|
2010-05-31 17:39:58 +00:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2010-05-25 15:19:52 +00:00
|
|
|
#endif /* GENERIC_PARSER_H */
|