From 8a7dde79de6edee01571d2eb4a333d8256f4c342 Mon Sep 17 00:00:00 2001 From: untir_l <87096069+untir-l@users.noreply.github.com> Date: Sat, 19 Feb 2022 11:10:09 +0530 Subject: Improve docs, don't initialise SDL until arguments are already handled --- cli/hitomezashi_cli.c | 15 ++++++--------- cli/hitomezashi_cli.h | 7 ++++++- 2 files changed, 12 insertions(+), 10 deletions(-) (limited to 'cli') diff --git a/cli/hitomezashi_cli.c b/cli/hitomezashi_cli.c index 762c9e3..70a2812 100644 --- a/cli/hitomezashi_cli.c +++ b/cli/hitomezashi_cli.c @@ -15,12 +15,6 @@ /** Initialise SDL, pass the information from hitomezashi_cli_handle_args() to * libhitomezashi, and save the resulting image. */ int main(int argc, char **argv) { - if (SDL_Init(SDL_INIT_VIDEO) != 0) { - SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "Failed to initialise SDL: %s", - SDL_GetError()); - return Hitomezashi_Cli_Exit_Code_Err_Sdl_Init; - } - char *out_file_path; int x_pattern_len; int y_pattern_len; @@ -32,6 +26,12 @@ int main(int argc, char **argv) { &x_pattern, &y_pattern, &gap, &thickness, argc, argv); + if (SDL_Init(SDL_INIT_VIDEO) != 0) { + SDL_LogCritical(SDL_LOG_CATEGORY_ERROR, "Failed to initialise SDL: %s", + SDL_GetError()); + return Hitomezashi_Cli_Exit_Code_Err_Sdl_Init; + } + struct Hitomezashi_State state; if (hitomezashi_state_init(&state, x_pattern_len, y_pattern_len, x_pattern, y_pattern, gap, thickness) != 0) { @@ -52,7 +52,6 @@ int main(int argc, char **argv) { SDL_Quit(); } -// Attempts to prints help. Exits 0 on success, 2 on failure. void hitomezashi_cli_help(void) { if (puts("hitomezashi_cli - generate hitomezashi patterns\n" "Options:\n" @@ -86,8 +85,6 @@ char *hitomezashi_cli_ascii_binary_str_to_ints(char *ascii_str, size_t n) { return res; } -// Parses arguments with xgetopt, ensures they are valid, initialises various -// variables based on them. Prints and exits if it encounters an error. void hitomezashi_cli_handle_args(char **out_file_path, int *x_pattern_len, int *y_pattern_len, char **x_pattern, char **y_pattern, int *gap, int *thickness, diff --git a/cli/hitomezashi_cli.h b/cli/hitomezashi_cli.h index d83de7b..9f7825c 100644 --- a/cli/hitomezashi_cli.h +++ b/cli/hitomezashi_cli.h @@ -25,12 +25,17 @@ enum Hitomezashi_Cli_Exit_Code { /** Read and parse arguments, ensure they are valid, and give back the * information in usable form to the caller. Also calls hitomezashi_cli_help() * if -h is passed. + * Note that *x_pattern and *y_pattern are dynamically allocated and should be + * freed by the caller when no longer needed. */ void hitomezashi_cli_handle_args(char **out_file_path, int *x_pattern_len, int *y_pattern_len, char **x_pattern, char **y_pattern, int *gap, int *thickness, int argc, char **argv); -/** Print the help text and exit. */ +/** Print the help text and exit. + * Exits with Hitomezashi_Cli_Exit_Code_Success (0) on success, and + * Hitomezashi_Cli_Exit_Code_Print_Help (2) on failure. + */ void hitomezashi_cli_help(void); /** Convert a string composed of ASCII 0 and 1 digits, eg\. "01010", to an array * of numeric 0s and 1s stored as char. */ -- cgit v1.2.3-57-g22cb