diff options
author | Alejandro Colomar <colomar.6.4.3@gmail.com> | 2020-04-17 10:14:37 +0200 |
---|---|---|
committer | Alejandro Colomar <colomar.6.4.3@gmail.com> | 2020-04-17 10:14:37 +0200 |
commit | a86cfb7dd4a4fa761fe0fddcaa2d0c4ea8923a2e (patch) | |
tree | a23d4413652985ec7c2ef55cc3173b126d442c9c | |
parent | 829614e77385dfbbe8ef2b0670ba38c33cba3209 (diff) |
Read image filename from argv instead of environment
-rw-r--r-- | src/main.c | 25 |
1 files changed, 13 insertions, 12 deletions
@@ -38,8 +38,7 @@ ******* static functions (prototypes) **************************************** ******************************************************************************/ static -int init (char fname[static restrict FILENAME_MAX], - img_s **restrict img); +int init (img_s **restrict img); static void deinit (img_s *restrict img); @@ -47,16 +46,20 @@ void deinit (img_s *restrict img); /****************************************************************************** ******* main ***************************************************************** ******************************************************************************/ -int main (void) +int main (int argc, char *argv[]) { - char fname[FILENAME_MAX]; + const char *fname; img_s *img; uint32_t code; int status; status = 1; - if (init(fname, &img)) + if (argc != 2) return 1; + fname = argv[1]; + status++; + if (init(&img)) + goto err0; status++; if (load_templates()) @@ -98,8 +101,9 @@ int main (void) deinit(img); return 0; err: - fprintf(stderr, "Error reading label\n"); deinit(img); +err0: + fprintf(stderr, "Error reading label\n"); return status; } @@ -108,14 +112,11 @@ err: ******* static functions (definitions) *************************************** ******************************************************************************/ static -int init (char fname[static restrict FILENAME_MAX], - img_s **restrict img) +int init (img_s **restrict img) { - if (getenv_s(fname, FILENAME_MAX, ENV_IMG_FNAME)) - return -1; if (alx_cv_init_img(img)) - return -2; + return -1; if (init_symbols()) goto err0; if (init_templates()) @@ -127,7 +128,7 @@ int init (char fname[static restrict FILENAME_MAX], err1: deinit_symbols(); err0: alx_cv_deinit_img(*img); - return -2; + return -1; } static |