From c525bc266f29f990b1844706f5b0a5c7b197997c Mon Sep 17 00:00:00 2001 From: John Zaitseff Date: Thu, 14 Jan 2021 12:04:03 +1100 Subject: [PATCH] Refactor preliminary initialisation code into init_program_prelim() --- src/trader.c | 47 +++++++++++++++++++++++++++++++++++------------ 1 file changed, 35 insertions(+), 12 deletions(-) diff --git a/src/trader.c b/src/trader.c index ed0bb80..f22661a 100644 --- a/src/trader.c +++ b/src/trader.c @@ -117,6 +117,19 @@ static void show_version (void) __attribute__((noreturn)); static void show_usage (int status) __attribute__((noreturn)); +/* + Function: init_program_prelim - Initialise program preliminaries + Parameters: argc - Same as passed to main() + argv - Same as passed to main() + Returns: (nothing) + + This function initialises the program name, locale and message + catalogs. It must be called before command line arguments are + processed. +*/ +static void init_program_prelim (int argc, char *argv[]); + + /* Function: init_program - Initialise program-wide functions Parameters: (none) @@ -146,18 +159,8 @@ static void end_program (void); int main (int argc, char *argv[]) { - // Strip off leading pathname components from program name - init_program_name(argv[0]); - - // Initialise the locale - if (setlocale(LC_ALL, "") == NULL) { - err_exit("could not set locale " - "(check LANG, LC_ALL and LANGUAGE in environment)"); - } - - // Use correct message catalogs for the locale - bindtextdomain(PACKAGE, LOCALEDIR); - textdomain(PACKAGE); + // Initialise program name, locale and message catalogs + init_program_prelim(argc, argv); // Process command line arguments process_cmdline(argc, argv); @@ -361,6 +364,26 @@ playing that game. If GAME is not specified, start a new game.\n\n\ // These functions are documented at the start of this file +/***********************************************************************/ +// init_program_prelim: Initialise program preliminaries + +void init_program_prelim (int argc, char *argv[]) +{ + // Strip off leading pathname components from program name + init_program_name(argv[0]); + + // Initialise the locale and message catalogs + if (setlocale(LC_ALL, "") == NULL) { + err_exit("could not set locale " + "(check LANG, LC_ALL and LANGUAGE in environment)"); + } + + // Use correct message catalogs for the locale + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); +} + + /***********************************************************************/ // init_program: Initialise program-wide functions