X-Git-Url: http://gitweb.hugovil.com/?a=blobdiff_plain;f=src%2Fcommon%2Foptions.c;h=59c5d261dfde332cef9c8998cd9f6389bf27523e;hb=fbbb71d6d8aa93bccc87b17408a89432e4b8161c;hp=ededf6d986dab61756c3782e726746d7247c1979;hpb=fa97a074e5240902f051ca883aa7d7c69682c9d5;p=emu8051.git diff --git a/src/common/options.c b/src/common/options.c index ededf6d..59c5d26 100644 --- a/src/common/options.c +++ b/src/common/options.c @@ -3,17 +3,13 @@ * * Copyright (C) 2011 Hugo Villeneuve * - * 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 file is released under the GPLv2 */ #if HAVE_CONFIG_H # include "config.h" #endif -#include #include #include #include @@ -31,15 +27,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,19 +52,13 @@ 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) { char *endptr; int log_level; - log_level = strtol(arg, &endptr, 0); + log_level = (int) strtol(arg, &endptr, 0); if (*endptr != '\0') { log_err("Invalid log level"); @@ -95,13 +86,13 @@ decode_memory_size(char *arg, struct argp_state *state, int memid) else if (memid == EXT_MEM_ID) dest = &options.xram_size; else - exit(1); /* Programming error. */ + exit(EXIT_FAILURE); /* Programming error. */ /* * Sizes versus max memory sizes will be checked when calling * memory_init(). */ - *dest = strtol(arg, &endptr, 0); + *dest = (int) strtol(arg, &endptr, 0); if (*endptr != '\0') { log_err("Invalid memory size"); @@ -114,7 +105,7 @@ decode_address(char *arg, struct argp_state *state, uint16_t *dest) { char *endptr; - *dest = strtol(arg, &endptr, 0); + *dest = (uint16_t) strtol(arg, &endptr, 0); if (*endptr != '\0') { log_err("Invalid address"); @@ -171,8 +162,7 @@ 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()); + error_t rc; /* Setting default values. */ options.filename = NULL; @@ -183,5 +173,7 @@ parse_command_line_options(int argc, char *argv[]) options.stop_address = 0; /* 0 means stop address is disabled. */ /* Parse our arguments. */ - argp_parse(&argp, argc, argv, 0, 0, NULL); + rc = argp_parse(&argp, argc, argv, 0, 0, NULL); + if (rc != 0) + log_fail("Failure to parse command line arguments"); }