From d230e5df59cfca29c61723b339a61d8d3316a073 Mon Sep 17 00:00:00 2001 From: Hugo Villeneuve Date: Thu, 23 Jan 2014 19:15:39 -0500 Subject: [PATCH] Simplify options parsing code --- src/common/options.c | 22 +++++++--------------- src/common/options.h | 7 ++++--- src/gtk/helpmenu.c | 4 +--- 3 files changed, 12 insertions(+), 21 deletions(-) diff --git a/src/common/options.c b/src/common/options.c index ededf6d..ba0a9fa 100644 --- a/src/common/options.c +++ b/src/common/options.c @@ -31,15 +31,16 @@ const char *argp_program_version = PACKAGE_VERSION; const char *argp_program_bug_address = PACKAGE_BUGREPORT; -#define PACKAGE_DOC_LENGTH 128 - -/* Program documentation. */ -static char str_doc[PACKAGE_DOC_LENGTH]; +/* + * Program documentation. + * Adjacent string constants are concatenated as one string constant. + */ +static const char str_doc[] = PACKAGE_NAME " -- " PACKAGE_DESCRIPTION; -/* How many arguments we accept. */ +/* How many non-option arguments we accept. */ #define ARGS_COUNT 1 -/* A description of the arguments we accept. */ +/* A description of the non-option arguments we accept. */ static const char args_doc[] = "[FILENAME]"; /* The options we understand. */ @@ -55,12 +56,6 @@ static struct argp_option argp_options[] = { struct options_t options; -const char * -get_package_description(void) -{ - return "Emulator for 8051 family microcontrollers"; -} - static void decode_debug_option(char *arg, struct argp_state *state) { @@ -171,9 +166,6 @@ static struct argp argp = {argp_options, parse_opt, args_doc, str_doc, void parse_command_line_options(int argc, char *argv[]) { - snprintf(str_doc, PACKAGE_DOC_LENGTH, "%s -- %s", PACKAGE_NAME, - get_package_description()); - /* Setting default values. */ options.filename = NULL; options.pram_size = PGM_MEM_DEFAULT_SIZE; diff --git a/src/common/options.h b/src/common/options.h index 589c2d5..731689d 100644 --- a/src/common/options.h +++ b/src/common/options.h @@ -21,6 +21,10 @@ #ifndef OPTIONS_H #define OPTIONS_H 1 +#define PACKAGE_COPYRIGHT "(c) Hugo Villeneuve" + +#define PACKAGE_DESCRIPTION "Emulator for 8051 family microcontrollers" + #define COMMAND_LINE_OPTIONS \ "Usage: " PACKAGE " [OPTION]... [FILENAME]\n" \ "Simulator/emulator for 8051 family microcontrollers.\n\n" \ @@ -39,7 +43,4 @@ struct options_t { void parse_command_line_options(int argc, char *argv[]); -const char * -get_package_description(void); - #endif /* OPTIONS_H */ diff --git a/src/gtk/helpmenu.c b/src/gtk/helpmenu.c index 6d3f9e0..50ddd4a 100644 --- a/src/gtk/helpmenu.c +++ b/src/gtk/helpmenu.c @@ -39,8 +39,6 @@ #include "messagebox.h" #include "helpmenu.h" -#define PACKAGE_COPYRIGHT "(c) Hugo Villeneuve" - static void HelpCommandsEvent(gchar *string) { @@ -87,7 +85,7 @@ HelpAboutEvent(GtkWidget *widget, gpointer data) "title", "About Dialog", "version", PACKAGE_VERSION, "logo-icon-name", PACKAGE_TARNAME, - "comments", get_package_description(), + "comments", PACKAGE_DESCRIPTION, "authors", authors, "website", PACKAGE_URL, "copyright", PACKAGE_COPYRIGHT, -- 2.20.1