>From 3a6ac85a3d54999ea1f11c549c79ae114dcc06cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?"Rodolfo=20Garc=C3=ADa=20Pe=C3=B1as=20(kix)"?= <[email protected]>
Date: Fri, 20 Jul 2012 18:18:50 +0200
Subject: [PATCH 3/3] shorter name for menu_parser_* functions
The functions menu_parser_* are now mp_* to have shorter names
and shorter lines.
---
WINGs/menuparser.c | 72 ++++++++++++++++++++++-----------------------
WINGs/menuparser.h | 28 ++++++++----------
WINGs/menuparser_macros.c | 49 +++++++++++++++---------------
3 files changed, 71 insertions(+), 78 deletions(-)
diff --git a/WINGs/menuparser.c b/WINGs/menuparser.c
index 98c4448..50b37f9 100644
--- a/WINGs/menuparser.c
+++ b/WINGs/menuparser.c
@@ -28,15 +28,14 @@
#include "menuparser.h"
-static WMenuParser menu_parser_create_new(const char *file_name, void *file,
- const char *include_default_paths);
-static char *menu_parser_isolate_token(WMenuParser parser,
- WParserMacro *list_macros);
-static void menu_parser_get_directive(WMenuParser parser);
-static Bool menu_parser_include_file(WMenuParser parser);
-static void menu_parser_condition_ifmacro(WMenuParser parser, Bool
check_exists);
-static void menu_parser_condition_else(WMenuParser parser);
-static void menu_parser_condition_end(WMenuParser parser);
+static WMenuParser mp_create_new(const char *file_name, void *file,
+ const char *include_default_paths);
+static char *mp_isolate_token(WMenuParser parser, WParserMacro *list_macros);
+static void mp_get_directive(WMenuParser parser);
+static Bool mp_include_file(WMenuParser parser);
+static void mp_condition_ifmacro(WMenuParser parser, Bool check_exists);
+static void mp_condition_else(WMenuParser parser);
+static void mp_condition_end(WMenuParser parser);
/* Constructor and Destructor for the Menu Parser object */
@@ -45,8 +44,9 @@ WMenuParser WMenuParserCreate(const char *file_name, void
*file,
{
WMenuParser parser;
- parser = menu_parser_create_new(file_name, file, include_default_paths);
- menu_parser_register_preset_macros(parser);
+ parser = mp_create_new(file_name, file, include_default_paths);
+ mp_register_preset_macros(parser);
+
return parser;
}
@@ -66,12 +66,12 @@ void WMenuParserDelete(WMenuParser parser)
}
if (parser->macros)
- menu_parser_free_macros(parser);
+ mp_free_macros(parser);
wfree(parser);
}
-static WMenuParser menu_parser_create_new(const char *file_name, void *file,
+static WMenuParser mp_create_new(const char *file_name, void *file,
const char *include_default_paths)
{
WMenuParser parser = wmalloc(sizeof(*parser));
@@ -160,7 +160,7 @@ read_next_line:
cur_parser->rd = cur_parser->line_buffer;
for (;;) {
- if (!menu_parser_skip_spaces_and_comments(cur_parser)) {
+ if (!mp_skip_spaces_and_comments(cur_parser)) {
/* We reached the end of line */
if (scanmode == GET_TITLE)
goto read_next_line; /* Empty line -> skip */
@@ -170,7 +170,7 @@ read_next_line:
if ((scanmode == GET_TITLE) && (*cur_parser->rd == '#')) {
cur_parser->rd++;
- menu_parser_get_directive(cur_parser);
+ mp_get_directive(cur_parser);
goto read_next_line_with_filechange;
}
@@ -178,7 +178,7 @@ read_next_line:
goto read_next_line;
/* Found a word */
- token = menu_parser_isolate_token(cur_parser,
top_parser->macros);
+ token = mp_isolate_token(cur_parser, top_parser->macros);
switch (scanmode) {
case GET_TITLE:
*title = token;
@@ -255,7 +255,7 @@ read_next_line:
/* Return False when there's nothing left on the line,
otherwise increment parser's pointer to next token */
-Bool menu_parser_skip_spaces_and_comments(WMenuParser parser)
+Bool mp_skip_spaces_and_comments(WMenuParser parser)
{
for (;;) {
while (isspace(*parser->rd))
@@ -316,7 +316,7 @@ found_end_of_comment:
/* read a token (non-spaces suite of characters)
* the result os wmalloc's, so it needs to be free'd */
-static char *menu_parser_isolate_token(WMenuParser parser, WParserMacro
*list_macros)
+static char *mp_isolate_token(WMenuParser parser, WParserMacro *list_macros)
{
char *start, *token;
int limit = MAX_NESTED_MACROS;
@@ -354,7 +354,7 @@ found_end_quote:
while (isnamechr(*parser->rd))
parser->rd++;
- macro = menu_parser_find_macro(parser, start_macro);
+ macro = mp_find_macro(parser, start_macro);
if (macro != NULL) {
char *expand_there;
@@ -369,7 +369,7 @@ found_end_quote:
/* Macro expansion will take care to keep the
rest of the line after
* the macro to the end of the line for future
token extraction */
- menu_parser_expand_macro(parser, macro,
expand_there,
+ mp_expand_macro(parser, macro, expand_there,
sizeof(parser->line_buffer) - (start - parser->line_buffer) );
/* Restart parsing to allow expansion of sub
macro calls */
@@ -397,7 +397,7 @@ found_end_quote:
}
/* Processing of special # directives */
-static void menu_parser_get_directive(WMenuParser parser)
+static void mp_get_directive(WMenuParser parser)
{
char *command;
@@ -415,30 +415,30 @@ static void menu_parser_get_directive(WMenuParser parser)
}
if (strcmp(command, "include") == 0) {
- if (!menu_parser_include_file(parser))
+ if (!mp_include_file(parser))
return;
} else if (strcmp(command, "define") == 0) {
- menu_parser_define_macro(parser);
+ mp_define_macro(parser);
} else if (strcmp(command, "ifdef") == 0) {
- menu_parser_condition_ifmacro(parser, 1);
+ mp_condition_ifmacro(parser, 1);
} else if (strcmp(command, "ifndef") == 0) {
- menu_parser_condition_ifmacro(parser, 0);
+ mp_condition_ifmacro(parser, 0);
} else if (strcmp(command, "else") == 0) {
- menu_parser_condition_else(parser);
+ mp_condition_else(parser);
} else if (strcmp(command, "endif") == 0) {
- menu_parser_condition_end(parser);
+ mp_condition_end(parser);
} else {
WMenuParserError(parser, _("unknow directive '#%s'"), command);
return;
}
- if (menu_parser_skip_spaces_and_comments(parser))
+ if (mp_skip_spaces_and_comments(parser))
WMenuParserError(parser, _("extra text after '#' command is
ignored: \"%.16s...\""),
parser->rd);
}
@@ -446,14 +446,14 @@ static void menu_parser_get_directive(WMenuParser parser)
/* Extract the file name, search for it in known directories
* and create a sub-parser to handle it.
* Returns False if the file could not be found */
-static Bool menu_parser_include_file(WMenuParser parser)
+static Bool mp_include_file(WMenuParser parser)
{
char buffer[MAXLINE];
char *req_filename, *fullfilename, *p;
char eot;
FILE *fh;
- if (!menu_parser_skip_spaces_and_comments(parser)) {
+ if (!mp_skip_spaces_and_comments(parser)) {
WMenuParserError(parser, _("no file name found for #include") );
return False;
}
@@ -569,21 +569,21 @@ found_end_define_fname:
/* Found the file, make it our new source */
found_valid_file:
- parser->include_file = menu_parser_create_new(wstrdup(req_filename),
fh, parser->include_default_paths);
+ parser->include_file = mp_create_new(wstrdup(req_filename), fh,
parser->include_default_paths);
parser->include_file->parent_file = parser;
return True;
}
/* Check wether a macro exists or not, and marks the parser to ignore the
* following data accordingly */
-static void menu_parser_condition_ifmacro(WMenuParser parser, Bool
check_exists)
+static void mp_condition_ifmacro(WMenuParser parser, Bool check_exists)
{
WParserMacro *macro;
int idx;
const char *cmd_name, *macro_name;
cmd_name = check_exists?"ifdef":"ifndef";
- if (!menu_parser_skip_spaces_and_comments(parser)) {
+ if (!mp_skip_spaces_and_comments(parser)) {
WMenuParserError(parser, _("missing macro name argument to
#%s"), cmd_name);
return;
}
@@ -607,7 +607,7 @@ static void menu_parser_condition_ifmacro(WMenuParser
parser, Bool check_exists)
if (parser->cond.stack[1].skip) {
parser->cond.stack[0].skip = True;
} else {
- macro = menu_parser_find_macro(parser, macro_name);
+ macro = mp_find_macro(parser, macro_name);
parser->cond.stack[0].skip =
((check_exists) && (macro == NULL)) ||
((!check_exists) && (macro != NULL)) ;
@@ -618,7 +618,7 @@ static void menu_parser_condition_ifmacro(WMenuParser
parser, Bool check_exists)
}
/* Swap the 'data ignore' flag because a #else condition was found */
-static void menu_parser_condition_else(WMenuParser parser)
+static void mp_condition_else(WMenuParser parser)
{
if (parser->cond.depth <= 0) {
WMenuParserError(parser, _("found #%s but have no matching
#if"), "else" );
@@ -633,7 +633,7 @@ static void menu_parser_condition_else(WMenuParser parser)
}
/* Closes the current conditional, removing it from the stack */
-static void menu_parser_condition_end(WMenuParser parser)
+static void mp_condition_end(WMenuParser parser)
{
int idx;
diff --git a/WINGs/menuparser.h b/WINGs/menuparser.h
index 692ef69..4ff6a91 100644
--- a/WINGs/menuparser.h
+++ b/WINGs/menuparser.h
@@ -28,9 +28,9 @@
*/
#define MAXLINE 1024
-#define MAX_NESTED_INCLUDES 16 // To avoid infinite includes case
-#define MAX_NESTED_MACROS 24 // To avoid infinite loop inside macro
expansions
-#define MAX_MACRO_ARG_COUNT 32 // Limited by design
+#define MAX_NESTED_INCLUDES 16 /* To avoid infinite includes case */
+#define MAX_NESTED_MACROS 24 /* To avoid infinite loop inside macro
expansions */
+#define MAX_MACRO_ARG_COUNT 32 /* Limited by design */
typedef struct w_parser_macro WParserMacro;
@@ -46,7 +46,7 @@ struct w_menu_parser {
WParserMacro *macros;
struct {
/* Conditional text parsing is implemented using a stack of the
- skip states for each nested #if */
+ * skip states for each nested #if */
int depth;
struct {
Bool skip;
@@ -69,19 +69,15 @@ struct w_parser_macro {
unsigned char value[MAXLINE * 4];
};
-Bool menu_parser_skip_spaces_and_comments(WMenuParser parser);
+Bool mp_skip_spaces_and_comments(WMenuParser parser);
-void menu_parser_register_preset_macros(WMenuParser parser);
+void mp_register_preset_macros(WMenuParser parser);
+void mp_define_macro(WMenuParser parser);
+void mp_free_macros(WMenuParser parser);
+void mp_expand_macro(WMenuParser parser, WParserMacro *macro,
+ char *write_buf, int write_buf_size);
-void menu_parser_define_macro(WMenuParser parser);
-
-void menu_parser_free_macros(WMenuParser parser);
-
-WParserMacro *menu_parser_find_macro(WMenuParser parser, const char *name);
-
-void menu_parser_expand_macro(WMenuParser parser, WParserMacro *macro,
-
char *write_buf, int write_buf_size);
-
-int isnamechr(char ch); // Check if char is valid character for a macro name
+WParserMacro *mp_find_macro(WMenuParser parser, const char *name);
+int isnamechr(char ch); /* Check if char is valid character for a macro name */
#endif /* _MENUPARSER_H_INCLUDED */
diff --git a/WINGs/menuparser_macros.c b/WINGs/menuparser_macros.c
index b18c2ab..98c6b9f 100644
--- a/WINGs/menuparser_macros.c
+++ b/WINGs/menuparser_macros.c
@@ -76,25 +76,22 @@
call-back function would not have the possibility to fail.
*/
-static Bool menu_parser_read_macro_def(WMenuParser parser, WParserMacro
*macro, char **argname);
-
-static Bool menu_parser_read_macro_args(WMenuParser parser, WParserMacro
*macro,
+static Bool mp_read_macro_def(WMenuParser parser, WParserMacro *macro, char
**argname);
+static Bool mp_read_macro_args(WMenuParser parser, WParserMacro *macro,
char *array[], char *buffer, ssize_t
buffer_size);
/* Free all used memory associated with parser's macros */
-void menu_parser_free_macros(WMenuParser parser)
+void mp_free_macros(WMenuParser parser)
{
WParserMacro *macro, *mnext;
#ifdef DEBUG
unsigned char *rd;
- unsigned int size;
- unsigned int count;
+ unsigned int size, count = 0;
/* if we were compiled with debugging, we take the opportunity that we
- parse the list of macros, for memory release, to print all the
- definitions */
+ * parse the list of macros, for memory release, to print all the
+ * definitions */
printf(__FILE__ ": Macros defined while parsing \"%s\"\n",
parser->file_name);
- count = 0;
#endif
for (macro = parser->macros; macro != NULL; macro = mnext) {
#ifdef DEBUG
@@ -158,14 +155,14 @@ int isnamechr(char ch)
}
/* Parse the definition of the macro and add it to the top-most parser's list
*/
-void menu_parser_define_macro(WMenuParser parser)
+void mp_define_macro(WMenuParser parser)
{
WParserMacro *macro;
int idx;
char arg_names_buf[MAXLINE];
char *arg_name[MAX_MACRO_ARG_COUNT];
- if (!menu_parser_skip_spaces_and_comments(parser)) {
+ if (!mp_skip_spaces_and_comments(parser)) {
WMenuParserError(parser, _("no macro name found for #define") );
return;
}
@@ -187,7 +184,7 @@ void menu_parser_define_macro(WMenuParser parser)
parser->rd++;
idx = 0;
for (;;) {
- if (!menu_parser_skip_spaces_and_comments(parser)) {
+ if (!mp_skip_spaces_and_comments(parser)) {
arglist_error_premature_eol:
WMenuParserError(parser, _("premature end of
file while reading arg-list for macro \"%s\""), macro->name);
wfree(macro);
@@ -224,7 +221,7 @@ arglist_error_premature_eol:
return;
}
- if (!menu_parser_skip_spaces_and_comments(parser))
+ if (!mp_skip_spaces_and_comments(parser))
goto arglist_error_premature_eol;
if (*parser->rd == ')')
@@ -253,8 +250,8 @@ arglist_error_premature_eol:
}
/* Get the macro's definition */
- menu_parser_skip_spaces_and_comments(parser);
- if (!menu_parser_read_macro_def(parser, macro, arg_name)) {
+ mp_skip_spaces_and_comments(parser);
+ if (!mp_read_macro_def(parser, macro, arg_name)) {
wfree(macro);
return;
}
@@ -264,7 +261,7 @@ arglist_error_premature_eol:
parser = parser->parent_file;
/* Check that the macro was not already defined */
- if (menu_parser_find_macro(parser, macro->name) != NULL) {
+ if (mp_find_macro(parser, macro->name) != NULL) {
WMenuParserError(parser, _("macro \"%s\" already defined,
ignoring redefinition"),
macro->name);
wfree(macro);
@@ -277,7 +274,7 @@ arglist_error_premature_eol:
}
/* Check if the current word in the parser matches a macro */
-WParserMacro *menu_parser_find_macro(WMenuParser parser, const char *name)
+WParserMacro *mp_find_macro(WMenuParser parser, const char *name)
{
const char *ref, *cmp;
WParserMacro *macro;
@@ -323,7 +320,7 @@ static inline char *mp_is_parameter(char *parse, const char
*param)
*
* There is no need to keep track of the names of the parameters, so they are
stored in
* a temporary storage for the time of the macro parsing. */
-static Bool menu_parser_read_macro_def(WMenuParser parser, WParserMacro
*macro, char **arg)
+static Bool mp_read_macro_def(WMenuParser parser, WParserMacro *macro, char
**arg)
{
unsigned char *wr_size, *wr;
unsigned int size_data, size_max;
@@ -333,7 +330,7 @@ static Bool menu_parser_read_macro_def(WMenuParser parser,
WParserMacro *macro,
size_data = 0;
wr = wr_size + 2;
size_max = sizeof(macro->value) - (wr - macro->value) - 3;
- while (menu_parser_skip_spaces_and_comments(parser)) {
+ while (mp_skip_spaces_and_comments(parser)) {
if (isnamechr(*parser->rd)) {
char *next_rd;
@@ -406,7 +403,7 @@ next_loop:
/* When a macro is being used in the file, this function will generate the
* expanded value for the macro in the parser's work line.
* It blindly supposes that the data generated in macro->value is valid */
-void menu_parser_expand_macro(WMenuParser parser, WParserMacro *macro,
+void mp_expand_macro(WMenuParser parser, WParserMacro *macro,
char *write_buf, int write_buf_size)
{
char save_buf[sizeof(parser->line_buffer)];
@@ -418,8 +415,8 @@ void menu_parser_expand_macro(WMenuParser parser,
WParserMacro *macro,
int space_left;
if (macro->arg_count >= 0) {
- menu_parser_skip_spaces_and_comments(parser);
- if (!menu_parser_read_macro_args(parser, macro, arg_value,
arg_values_buf, sizeof(arg_values_buf)))
+ mp_skip_spaces_and_comments(parser);
+ if (!mp_read_macro_args(parser, macro, arg_value,
arg_values_buf, sizeof(arg_values_buf)))
return;
}
@@ -486,7 +483,7 @@ void menu_parser_expand_macro(WMenuParser parser,
WParserMacro *macro,
/* When reading a macro to be expanded (not being defined), that takes
arguments,
* this function parses the arguments being provided */
-static Bool menu_parser_read_macro_args(WMenuParser parser, WParserMacro
*macro,
+static Bool mp_read_macro_args(WMenuParser parser, WParserMacro *macro,
char *array[], char *buffer, ssize_t
buffer_size)
{
int arg;
@@ -499,7 +496,7 @@ static Bool menu_parser_read_macro_args(WMenuParser parser,
WParserMacro *macro,
parser->rd++;
buffer_size--; /* Room for final '\0' */
- menu_parser_skip_spaces_and_comments(parser);
+ mp_skip_spaces_and_comments(parser);
arg = 0;
for (;;) {
int paren_count;
@@ -538,7 +535,7 @@ found_end_of_string:
if (buffer_size-- > 0)
*buffer++ = ' ';
- menu_parser_skip_spaces_and_comments(parser);
+ mp_skip_spaces_and_comments(parser);
continue;
}
@@ -756,7 +753,7 @@ static void w_create_macro(WMenuParser parser, const char
*name, WParserMacroFun
}
/* Register all the pre-defined macros in the parser */
-void menu_parser_register_preset_macros(WMenuParser parser)
+void mp_register_preset_macros(WMenuParser parser)
{
/* Defined by CPP: common predefined macros (GNU C extension) */
w_create_macro(parser, "__BASE_FILE__", mpm_base_file);
--
1.7.10.4
--
To unsubscribe, send mail to [email protected].