From 32545c99a2b88b04f8981ae6fa950aeac2155979 Mon Sep 17 00:00:00 2001 From: marschap Date: Sat, 2 Jul 2005 12:29:42 +0000 Subject: [PATCH] replace macros by static inline functions; reorder functions to not require forward declarations --- server/parse.c | 65 ++++++++++++++++++++++++++++++++------------------ 1 file changed, 42 insertions(+), 23 deletions(-) diff --git a/server/parse.c b/server/parse.c index e8b9b5c..03e0073 100644 --- a/server/parse.c +++ b/server/parse.c @@ -31,33 +31,22 @@ #define MAX_ARGUMENTS 40 +static inline int is_whitespace(char x) { + return ((x == ' ') || (x == '\t') || (x == '\r')); +} -static int parse_message (const char *str, Client *c); +static inline int is_final(char x) { + return ((x == '\n') || (x == '\0')); +} -int -parse_all_client_messages () -{ - Client * c; +static inline int is_opening_quote(char x, char q) { + return ((q == '\0') && ((x == '\"') || (x == '{'))); +} - debug( RPT_DEBUG, "%s()", __FUNCTION__ ); - - for (c = clients_getfirst(); c != NULL; c = clients_getnext()) { - char * str; - - /* And parse all its messages...*/ - /*debug(RPT_DEBUG, "parse: Getting messages...");*/ - for (str = client_get_message (c); str != NULL; str = client_get_message (c)) { - parse_message (str, c); - free (str); - } - } - return 0; +static inline int is_closing_quote(char x, char q) { + return (((q == '{') && (x == '}')) || ((q == '\"') && (x == '\"'))); } -#define is_whitespace(x) (((x) == ' ') || ((x) == '\t') || ((x) == '\r')) -#define is_final(x) (((x) == '\n') || ((x) == '\0')) -#define is_opening_quote(x,q) (((q) == '\0') && (((x) == '\"') || ((x) == '{'))) -#define is_closing_quote(x,q) ((((q) == '{') && ((x) == '}')) || (((q) == '\"') && ((x) == '\"'))) static int parse_message (const char *str, Client *c) { @@ -72,6 +61,7 @@ static int parse_message (const char *str, Client *c) int argc = 0; char *argv[MAX_ARGUMENTS]; int argpos = 0; + CommandFunc function = NULL; void close_arg() { if (argc >= MAX_ARGUMENTS-1) { @@ -180,8 +170,15 @@ static int parse_message (const char *str, Client *c) return 0; } +#if 0 /* show what we have parsed */ + int i; + for (i = 0; i < argc; i++) { + printf("%s%c", argv[i], (i == argc-1) ? '\n' : ' '); + } +#endif + /* Now find and call the appropriate function...*/ - CommandFunc function = get_command_function(argv[0]); + function = get_command_function(argv[0]); if (function != NULL) { error = function (c, argc, argv); @@ -201,3 +198,25 @@ static int parse_message (const char *str, Client *c) return 0; } + +int +parse_all_client_messages () +{ + Client * c; + + debug( RPT_DEBUG, "%s()", __FUNCTION__ ); + + for (c = clients_getfirst(); c != NULL; c = clients_getnext()) { + char * str; + + /* And parse all its messages...*/ + /*debug(RPT_DEBUG, "parse: Getting messages...");*/ + for (str = client_get_message (c); str != NULL; str = client_get_message (c)) { + parse_message (str, c); + free (str); + } + } + return 0; +} + +