Package: jpegjudge / 0.0.2-4

10-judge.c--change-name=11-long-opt.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
From 1d81fa815fc29de41dc41daec0bc3a67970641f3 Mon Sep 17 00:00:00 2001
From: Jari Aalto <jari.aalto@cante.net>
Date: Tue, 5 Jan 2010 15:55:36 +0200
Subject: [PATCH] judge.c: Add GNU --long options

Signed-off-by: Jari Aalto <jari.aalto@cante.net>
---
 judge.c |   46 +++++++++++++++++++++++++++++++++++++++-------
 1 files changed, 39 insertions(+), 7 deletions(-)

diff --git a/judge.c b/judge.c
index 7724f82..db4b2ee 100644
--- a/judge.c
+++ b/judge.c
@@ -24,6 +24,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <unistd.h>
+#include <string.h>
 
 #include <jpeglib.h>
 
@@ -111,27 +112,58 @@ judge_quality (char *filename)
 static void
 usage (char *prog, int ec)
 {
-  fprintf (stderr, "Usage: %s [ -vb ] file ...\n", prog);
+  fprintf (stderr, "Usage: %s [ -Vb ] file ...\n", prog);
   exit (ec);
 }
 
+void
+version (void)
+{
+  printf ("%s %s\n", VERSION, PACKAGE);
+  exit (0);
+}
+
+const char *
+is_in_list (int size, char **const list, const char *string)
+{
+  int i = 0;
+
+  while (i < size)
+    {
+	if ( !strcmp( list[i], string) )
+	  return list[i];
+
+	i++;
+    }
+
+  return (const char *)NULL;
+}
+
 int
 main (int argc, char **argv)
 {
   int display_filenames = 1;
   int retcode = 0;
-  
+
+  /* Handle long options */
+
+  if ( is_in_list (argc, argv, "--help"))
+    usage (argv[0], 0);
+
+  if ( is_in_list (argc, argv, "--version"))
+    version();
+
   for (;;)
     {
-      switch (getopt (argc, argv, "hvb"))
+      switch (getopt (argc, argv, "hVb"))
 	{
 	case 'h':
 	  usage (argv[0], 0);
 	  
-	case 'v':
-	  printf ("%s version %s\n", PACKAGE, VERSION);
-	  exit (0);
-	
+	case 'V':
+	  version();
+	  break;
+
 	case 'b':
 	  display_filenames = 0;
 	  break;
-- 
1.7.0