kwo pushed a commit to branch master.

http://git.enlightenment.org/legacy/imlib2.git/commit/?id=55da63d70080b5ddd13cc3c764d78e5ee7331cc7

commit 55da63d70080b5ddd13cc3c764d78e5ee7331cc7
Author: Kim Woelders <[email protected]>
Date:   Mon Dec 2 20:41:21 2019 +0100

    imlib2_load: Use getopt()
---
 src/bin/imlib2_load.c | 38 +++++++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 17 deletions(-)

diff --git a/src/bin/imlib2_load.c b/src/bin/imlib2_load.c
index 84bbce3..4bc48aa 100644
--- a/src/bin/imlib2_load.c
+++ b/src/bin/imlib2_load.c
@@ -1,6 +1,7 @@
 #include "config.h"
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 
 #ifndef X_DISPLAY_MISSING
 #define X_DISPLAY_MISSING
@@ -12,14 +13,18 @@
 static char         progress_called;
 static FILE        *fout;
 
+#define HELP \
+   "Usage:\n" \
+   "  imlib2_load [OPTIONS] FILE...\n" \
+   "OPTIONS:\n" \
+   "  -e  : Break on error\n" \
+   "  -p  : Check that progress is called\n" \
+   "  -x  : Print to stderr\n"
+
 static void
-usage(int exit_status)
+usage(void)
 {
-   fprintf(exit_status ? stderr : stdout,
-           PROG_NAME ": Load images to test loaders.\n"
-           "Usage: \n  " PROG_NAME " image ...\n");
-
-   exit(exit_status);
+   printf(HELP);
 }
 
 static int
@@ -33,7 +38,7 @@ progress(Imlib_Image im, char percent, int update_x, int 
update_y,
 int
 main(int argc, char **argv)
 {
-   const char         *s;
+   int                 opt;
    Imlib_Image         im;
    Imlib_Load_Error    lerr;
    int                 check_progress;
@@ -43,16 +48,9 @@ main(int argc, char **argv)
    check_progress = 0;
    break_on_error = 0;
 
-   for (;;)
+   while ((opt = getopt(argc, argv, "epx")) != -1)
      {
-        argv++;
-        argc--;
-        if (argc <= 0)
-           break;
-        s = argv[0];
-        if (*s++ != '-')
-           break;
-        switch (*s++)
+        switch (opt)
           {
           case 'e':
              break_on_error += 1;
@@ -66,8 +64,14 @@ main(int argc, char **argv)
           }
      }
 
+   argc -= optind;
+   argv += optind;
+
    if (argc <= 0)
-      usage(0);
+     {
+        usage();
+        return 1;
+     }
 
    if (check_progress)
      {

-- 


Reply via email to