TextResource-Compiler

Translates text resource descriptions into C files.

Summary
TextResource-CompilerTranslates text resource descriptions into C files.
CopyrightThis program is free software.
Files
C-kern/main/tools/textresource_compiler.cImplementation file TextResource-Compiler.
Helper
constants
log
print_versionPrints version information
print_usagePrints usage information.
print_errorPrints formatted error string.
xmlattribute_tName and value of an xml attribute.
lifetime
xmlattribute_INITStatic initializer.
outconfig_fctparam_tHolds function parameter for <outconfig_C>.
lifetime
outconfig_fctparam_INITInitializes outconfig_fctparam_t with a name, value and format.
outconfig_eTypes of different outputs the text resource compiler supports.
outconfig_tContains control information how the generated output is to be formatted.
textresource_language_tA language selector for textresource_text_t.
lifetime
textresource_language_INITStatic initializer.
textresource_parameter_tA parameter for textresource_text_t.
lifetime
textresource_parameter_FREEStatic initializer.
textresource_textatom_tAn atomic text element string content referenced by textresource_condition_t.
lifetime
textresource_textatom_INITStatic initializer.
textresource_textatom_INITStatic initializer.
textresource_textatom_INIT_FCTPARAMStatic initializer.
textresource_condition_tA condition which selects or deselects the contained textresource_textatom_t.
conditionThe C99-condition which is checked in the generated source code.
lifetime
add
textresource_langref_tA reference to a language and container for one or more textresource_condition_t.
lifetime
textresource_langref_INITStatic initializer.
add
textresource_text_tA single text resource description.
lifetime
update
textresource_paramtype_t
lifetime
textresource_paramtype_INITStatic initializer.
textresource_tDefines memory representation of parsed text resource description.
languagesContains list of textresource_language_t.
textlistContains list of textresource_text_t.
lifetime
textresource_FREEStatic initializer.
init_textresourceInitializes textresource_t object.
add
textresource_reader_tReads textual representation of text resource.
helper
skip_spaceandcommentSkips comments until next non space character.
parser
parse_version_textresourcereaderSkips comments until “<textresource version=’4’>” is found.
parse_outconfigC_utf8readerParses control information for generated output.
parse_outconfigCtable_utf8readerParses control information for generated output.
parse_header_textresourcereaderParses all header information.
parse_contentversion3_textresourcereaderParses content of “<textresource version=’3’> </textresource>”.
lifetime
textresource_reader_FREEStatic initializer.
free_textresourcereaderCloses file and frees memory of textresource_t.
init_textresourcereaderOpens file and reads header for the version information.
textresource_writer_tWrites programming language representation of text resource.
lifetime
textresource_writer_FREEStatic initializer.
write

Copyright

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 program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more details.

Author

© 2013 Jörg Seebohn

Files

C-kern/main/tools/textresource_compiler.c

Implementation file TextResource-Compiler.

Helper

Summary
constants
log
print_versionPrints version information
print_usagePrints usage information.
print_errorPrints formatted error string.

constants

log

print_version

static void print_version(void)

Prints version information

print_usage

static void print_usage(void)

Prints usage information.

print_error

static void print_error(const char *format,
 ...)

Prints formatted error string.

xmlattribute_t

struct xmlattribute_t

Name and value of an xml attribute.

<entity attr_name="attr_value" ...>.
Summary
lifetime
xmlattribute_INITStatic initializer.

lifetime

xmlattribute_INIT

#define xmlattribute_INIT(name) { (name), string_FREE }

Static initializer.  Sets xmlattribute_t name to parameter value name and its value to undefined.

outconfig_fctparam_t

struct outconfig_fctparam_t

Holds function parameter for <outconfig_C>.  A function parameter is describes as

<fctparam name="ERRSTR" value="(const char*)str_errorcontext(error_maincontext(), err)" format="%s"/>

where name is stgring it referenced with in a text resource description.  The value is used as function call to get the parameter value.  And format is the printf format description used to log the value.

Summary
lifetime
outconfig_fctparam_INITInitializes outconfig_fctparam_t with a name, value and format.
outconfig_eTypes of different outputs the text resource compiler supports.

lifetime

outconfig_fctparam_INIT

#define outconfig_fctparam_INIT(
   name,
   value,
   format
) { arraystf_node_INIT(name.size, name.addr), value, format }

Initializes outconfig_fctparam_t with a name, value and format.  All 3 parameters must be of type string_t.

outconfig_e

Types of different outputs the text resource compiler supports.

outconfig_t

struct outconfig_t

Contains control information how the generated output is to be formatted.

textresource_language_t

struct textresource_language_t

A language selector for textresource_text_t.

Summary

lifetime

textresource_language_INIT

#define textresource_language_INIT(
   name
) { string_INIT(name->size, name->addr), 0 }

Static initializer.

textresource_parameter_t

struct textresource_parameter_t

A parameter for textresource_text_t.

Summary

lifetime

textresource_parameter_FREE

#define textresource_parameter_FREE { arraystf_node_INIT(0,0), 0, 0, typemodifier_PLAIN }

Static initializer.

textresource_textatom_t

struct textresource_textatom_t

An atomic text element string content referenced by textresource_condition_t.  It describes either a parameter reference and its formatting or a simple text string.

Summary

lifetime

textresource_textatom_INIT

#define textresource_textatom_INIT(
   string
) { 0, textresource_textatom_STRING, { string } }

Static initializer.  Initializes textresource_textatom_t as type textresource_textatom_STRING.

textresource_textatom_INIT

#define textresource_textatom_INIT_PARAM(
   parameter
) { 0, textresource_textatom_PARAMETER, { .param = { parameter, 0, 0 } } }

Static initializer.  Initializes textresource_textatom_t as type textresource_textatom_PARAMETER.

textresource_textatom_INIT_FCTPARAM

#define textresource_textatom_INIT_FCTPARAM(
   fctparam
) { 0, textresource_textatom_FCTPARAM, { .fctparam = { fctparam } } }

Static initializer.  Initializes textresource_textatom_t as type textresource_textatom_FCTPARAM.

textresource_condition_t

struct textresource_condition_t

A condition which selects or deselects the contained textresource_textatom_t.  The condition indicates a conditional string if it is not empty.  If condition contains “else” it is the last entry of a switch

((condition1): "str1" (cond2): ... else: "strX")

Every switch ends in an else.  If the user does not supply one an artifical textresource_condition_t is created with condition set to “else” and an empty atomlist.

Summary
conditionThe C99-condition which is checked in the generated source code.
lifetime
add

condition

string_t condition

The C99-condition which is checked in the generated source code.  If the condition is true the text is used and all other conditional texts until after the next encountered “else” are skipped.  A condition set to “else” marks the last entry of a conditional sequence.

lifetime

add

textresource_langref_t

struct textresource_langref_t

A reference to a language and container for one or more textresource_condition_t.

Summary

lifetime

textresource_langref_INIT

#define textresource_langref_INIT(language) { slist_INIT, 0, (language) }

Static initializer.

add

textresource_text_t

struct textresource_text_t

A single text resource description.  The set of all defined text resources is stored in textresource_t.

A textresource_text_t has 0 or more textresource_parameter_t stored in paramlist.  It contains one or more language specific text definitions stored as textresource_langref_t in langlist.  A textresource_langref_t contains one or more textresource_condition_t which define a condition under which a string has to be used or not.

lifetime

update

textresource_paramtype_t

struct textresource_paramtype_t
Summary

lifetime

textresource_paramtype_INIT

#define textresource_paramtype_INIT(
   cstr,
   modifier,
   format
) textresource_paramtype_INIT2(cstr,modifier,format,"")

Static initializer.

Parameter

cstrconst C string.
modifierBit flags from <typemodifier_e> added together.

textresource_t

struct textresource_t

Defines memory representation of parsed text resource description.

Summary

languages

slist_t languages

Contains list of textresource_language_t.

textlist

slist_t textlist

Contains list of textresource_text_t.

lifetime

textresource_FREE

#define textresource_FREE { 0, 0, 0, slist_INIT, slist_INIT, outconfig_FREE }

Static initializer.

init_textresource

static int init_textresource(/*out*/textresource_t *textres,
const char *read_from_filename)

Initializes textresource_t object.

add

textresource_reader_t

struct textresource_reader_t

Reads textual representation of text resource.  The content of the textfile is stored into a structure of type textresource_t.

Summary
helper
skip_spaceandcommentSkips comments until next non space character.
parser
parse_version_textresourcereaderSkips comments until “<textresource version=’4’>” is found.
parse_outconfigC_utf8readerParses control information for generated output.
parse_outconfigCtable_utf8readerParses control information for generated output.
parse_header_textresourcereaderParses all header information.
parse_contentversion3_textresourcereaderParses content of “<textresource version=’3’> </textresource>”.
lifetime
textresource_reader_FREEStatic initializer.
free_textresourcereaderCloses file and frees memory of textresource_t.
init_textresourcereaderOpens file and reads header for the version information.

helper

skip_spaceandcomment

static int skip_spaceandcomment(textresource_reader_t *reader)

Skips comments until next non space character.  The readoffset is moved forward until end of input.

parser

parse_version_textresourcereader

static int parse_version_textresourcereader(textresource_reader_t *reader)

Skips comments until “<textresource version=’4’>” is found.  The whole header tag is consumed.

parse_outconfigC_utf8reader

static int parse_outconfigC_utf8reader(textresource_reader_t *reader)

Parses control information for generated output.

parse_outconfigCtable_utf8reader

static int parse_outconfigCtable_utf8reader(textresource_reader_t *reader)

Parses control information for generated output.

parse_header_textresourcereader

static int parse_header_textresourcereader(textresource_reader_t *reader)

Parses all header information.  First parse_version_textresourcereader is called to find the beginning of the header.  Then all additional xml-header-tags are parsed.

parse_contentversion3_textresourcereader

static int parse_contentversion3_textresourcereader(
   textresource_reader_t *reader
)

Parses content of “<textresource version=’3’> </textresource>”.

lifetime

textresource_reader_FREE

#define textresource_reader_FREE { textresource_FREE, utf8reader_FREE } ;

Static initializer.

free_textresourcereader

static int free_textresourcereader(textresource_reader_t *reader)

Closes file and frees memory of textresource_t.

init_textresourcereader

static int init_textresourcereader(/*out*/textresource_reader_t *reader,
const char *filename)

Opens file and reads header for the version information.  The parameter filename is stored in textresource_reader_t as a reference so do not delete filename as long as reader is alive.

textresource_writer_t

struct textresource_writer_t

Writes programming language representation of text resource.  This writer implements the C language output.

Summary

lifetime

textresource_writer_FREE

#define textresource_writer_FREE { 0, file_FREE }

Static initializer.

write

Translates text resource descriptions into C files.
static void print_version(void)
Prints version information
static void print_usage(void)
Prints usage information.
static void print_error(const char *format,
 ...)
Prints formatted error string.
struct xmlattribute_t
Name and value of an xml attribute.
#define xmlattribute_INIT(name) { (name), string_FREE }
Static initializer.
struct outconfig_fctparam_t
Holds function parameter for outconfig_C.
#define outconfig_fctparam_INIT(
   name,
   value,
   format
) { arraystf_node_INIT(name.size, name.addr), value, format }
Initializes outconfig_fctparam_t with a name, value and format.
struct outconfig_t
Contains control information how the generated output is to be formatted.
struct textresource_language_t
A language selector for textresource_text_t.
struct textresource_text_t
A single text resource description.
#define textresource_language_INIT(
   name
) { string_INIT(name->size, name->addr), 0 }
Static initializer.
struct textresource_parameter_t
A parameter for textresource_text_t.
#define textresource_parameter_FREE { arraystf_node_INIT(0,0), 0, 0, typemodifier_PLAIN }
Static initializer.
struct textresource_textatom_t
An atomic text element string content referenced by textresource_condition_t.
struct textresource_condition_t
A condition which selects or deselects the contained textresource_textatom_t.
#define textresource_textatom_INIT(
   string
) { 0, textresource_textatom_STRING, { string } }
Static initializer.
#define textresource_textatom_INIT_FCTPARAM(
   fctparam
) { 0, textresource_textatom_FCTPARAM, { .fctparam = { fctparam } } }
Static initializer.
string_t condition
The C99-condition which is checked in the generated source code.
struct textresource_langref_t
A reference to a language and container for one or more textresource_condition_t.
#define textresource_langref_INIT(language) { slist_INIT, 0, (language) }
Static initializer.
struct textresource_paramtype_t
#define textresource_paramtype_INIT(
   cstr,
   modifier,
   format
) textresource_paramtype_INIT2(cstr,modifier,format,"")
Static initializer.
struct textresource_t
Defines memory representation of parsed text resource description.
slist_t languages
Contains list of textresource_language_t.
slist_t textlist
Contains list of textresource_text_t.
#define textresource_FREE { 0, 0, 0, slist_INIT, slist_INIT, outconfig_FREE }
Static initializer.
static int init_textresource(/*out*/textresource_t *textres,
const char *read_from_filename)
Initializes textresource_t object.
struct textresource_reader_t
Reads textual representation of text resource.
static int skip_spaceandcomment(textresource_reader_t *reader)
Skips comments until next non space character.
static int parse_version_textresourcereader(textresource_reader_t *reader)
Skips comments until “textresource version=’4’” is found.
static int parse_outconfigC_utf8reader(textresource_reader_t *reader)
Parses control information for generated output.
static int parse_outconfigCtable_utf8reader(textresource_reader_t *reader)
Parses control information for generated output.
static int parse_header_textresourcereader(textresource_reader_t *reader)
Parses all header information.
static int parse_contentversion3_textresourcereader(
   textresource_reader_t *reader
)
Parses content of “textresource version=’3’ /textresource”.
#define textresource_reader_FREE { textresource_FREE, utf8reader_FREE } ;
Static initializer.
static int free_textresourcereader(textresource_reader_t *reader)
Closes file and frees memory of textresource_t.
static int init_textresourcereader(/*out*/textresource_reader_t *reader,
const char *filename)
Opens file and reads header for the version information.
struct textresource_writer_t
Writes programming language representation of text resource.
#define textresource_writer_FREE { 0, file_FREE }
Static initializer.
Close