Browse code

shared/options.c: handle obsolete options in cmdline parser (bb#1213)

git-svn: trunk@4236

Tomasz Kojm authored on 2008/10/08 05:18:21
Showing 9 changed files
... ...
@@ -1,3 +1,7 @@
1
+Tue Oct  7 22:35:22 CEST 2008 (tk)
2
+----------------------------------
3
+  * shared/options.c: handle obsolete options in cmdline parser (bb#1213)
4
+
1 5
 Tue Oct  7 23:21:35 EEST 2008 (edwin)
2 6
 -------------------------------------
3 7
 
... ...
@@ -124,7 +124,7 @@ int main(int argc, char **argv)
124 124
     }
125 125
 #endif
126 126
 
127
-    opt = opt_parse(argc, argv, short_options, long_options, NULL);
127
+    opt = opt_parse(argc, argv, short_options, long_options, NULL, NULL);
128 128
     if(!opt) {
129 129
 	mprintf("!Can't parse the command line\n");
130 130
 	return 1;
... ...
@@ -74,7 +74,7 @@ int main(int argc, char **argv)
74 74
 				  NULL };
75 75
 
76 76
 
77
-    opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, clamdscan_accepted);
77
+    opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, clamdscan_accepted, NULL);
78 78
     if(!opt) {
79 79
 	mprintf("!Can't parse the command line\n");
80 80
 	return 2;
... ...
@@ -84,7 +84,7 @@ int main(int argc, char **argv)
84 84
     sigprocmask(SIG_SETMASK, &sigset, NULL);
85 85
 #endif
86 86
 
87
-    opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL);
87
+    opt = opt_parse(argc, argv, clamscan_shortopt, clamscan_longopt, NULL, clamscan_deprecated);
88 88
     if(!opt) {
89 89
 	mprintf("!Can't parse the command line\n");
90 90
 	return 40;
... ...
@@ -88,7 +88,40 @@ static struct option clamscan_longopt[] = {
88 88
     {"dev-ac-only", 0, 0, 0},
89 89
     {"dev-ac-depth", 1, 0, 0},
90 90
     {"fdpass", 0, 0, 0},
91
+
92
+    /* deprecated (please also add to clamscan_deprecated[]) */
93
+    {"no-phishing-restrictedscan", 0, 0, 0},
94
+    {"max-ratio", 1, 0, 0},
95
+    {"max-space", 1, 0, 0},
96
+    {"block-max", 0, 0, 0},
97
+    {"unzip", 2, 0, 0},
98
+    {"unrar", 2, 0, 0},
99
+    {"arj", 2, 0, 0},
100
+    {"unzoo", 2, 0, 0},
101
+    {"lha", 2, 0, 0},
102
+    {"jar", 2, 0, 0},
103
+    {"tar", 2, 0, 0},
104
+    {"tgz", 2, 0, 0},
105
+    {"deb", 2, 0, 0},
106
+
91 107
     {0, 0, 0, 0}
92 108
 };
93 109
 
110
+const char *clamscan_deprecated[] = {
111
+    "no-phishing-restrictedscan",
112
+    "max-ratio",
113
+    "max-space",
114
+    "block-max",
115
+    "unzip",
116
+    "unrar",
117
+    "arj",
118
+    "unzoo",
119
+    "lha",
120
+    "jar",
121
+    "tar",
122
+    "tgz",
123
+    "deb",
124
+    NULL
125
+};
126
+
94 127
 #endif
... ...
@@ -237,7 +237,7 @@ int main(int argc, char **argv)
237 237
     	};
238 238
 
239 239
 
240
-    opt = opt_parse(argc, argv, short_options, long_options, NULL);
240
+    opt = opt_parse(argc, argv, short_options, long_options, NULL, NULL);
241 241
     if(!opt) {
242 242
 	mprintf("!Can't parse the command line\n");
243 243
 	return 40;
... ...
@@ -31,10 +31,10 @@
31 31
 #include "output.h"
32 32
 
33 33
 
34
-static int register_option(struct optstruct *opt, const char *optlong, char optshort, const struct option *options_long, const char * const *accepted_long)
34
+static int register_option(struct optstruct *opt, const char *optlong, char optshort, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long)
35 35
 {
36 36
 	struct optnode *newnode;
37
-	int i, found = 0;
37
+	int i, found;
38 38
 	const char *longname = NULL;
39 39
 
40 40
 
... ...
@@ -54,9 +54,12 @@ static int register_option(struct optstruct *opt, const char *optlong, char opts
54 54
     }
55 55
 
56 56
     if(accepted_long) {
57
+	found = 0;
57 58
 	for(i = 0; accepted_long[i]; i++)
58
-	    if(!strcmp(accepted_long[i], longname))
59
+	    if(!strcmp(accepted_long[i], longname)) {
59 60
 		found = 1;
61
+		break;
62
+	    }
60 63
 
61 64
 	if(!found) {
62 65
 	    if(optshort)
... ...
@@ -68,6 +71,25 @@ static int register_option(struct optstruct *opt, const char *optlong, char opts
68 68
 	}
69 69
     }
70 70
 
71
+    if(deprecated_long) {
72
+	found = 0;
73
+	for(i = 0; deprecated_long[i]; i++) {
74
+	    if(!strcmp(deprecated_long[i], longname)) {
75
+		found = 1;
76
+		break;
77
+	    }
78
+	}
79
+
80
+	if(found) {
81
+	    if(optshort)
82
+		mprintf("WARNING: Ignoring deprecated option --%s (-%c)\n", longname, optshort);
83
+	    else
84
+		mprintf("WARNING: Ignoring deprecated option --%s\n", longname);
85
+
86
+	    return 0;
87
+	}
88
+    }
89
+
71 90
     newnode = (struct optnode *) malloc(sizeof(struct optnode));
72 91
     if(!newnode) {
73 92
 	mprintf("!register_long_option: malloc failed\n");
... ...
@@ -125,7 +147,7 @@ void opt_free(struct optstruct *opt)
125 125
     free(opt);
126 126
 }
127 127
 
128
-struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long)
128
+struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long)
129 129
 {
130 130
 	int ret, opt_index, i, len;
131 131
 	struct optstruct *opt;
... ...
@@ -147,7 +169,7 @@ struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_sho
147 147
 
148 148
 	switch(ret) {
149 149
 	    case 0:
150
-		if(register_option(opt, options_long[opt_index].name, 0, options_long, accepted_long) == -1) {
150
+		if(register_option(opt, options_long[opt_index].name, 0, options_long, accepted_long, deprecated_long) == -1) {
151 151
 		    opt_free(opt);
152 152
 		    return NULL;
153 153
 		}
... ...
@@ -160,7 +182,7 @@ struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_sho
160 160
 		    else
161 161
 			longname = NULL;
162 162
 
163
-		    if(register_option(opt, longname, ret, options_long, accepted_long) == -1) {
163
+		    if(register_option(opt, longname, ret, options_long, accepted_long, deprecated_long) == -1) {
164 164
 			opt_free(opt);
165 165
 			return NULL;
166 166
 		    }
... ...
@@ -36,7 +36,7 @@ struct optstruct {
36 36
 
37 37
 void opt_free(struct optstruct *opt);
38 38
 
39
-struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long);
39
+struct optstruct *opt_parse(int argc, char * const *argv, const char *getopt_short, const struct option *options_long, const char * const *accepted_long, const char * const *deprecated_long);
40 40
 
41 41
 int opt_check(const struct optstruct *opt, const char *optlong);
42 42
 
... ...
@@ -1760,7 +1760,7 @@ int main(int argc, char **argv)
1760 1760
 	    {0, 0, 0, 0}
1761 1761
     	};
1762 1762
 
1763
-    opt = opt_parse(argc, argv, short_options, long_options, NULL);
1763
+    opt = opt_parse(argc, argv, short_options, long_options, NULL, NULL);
1764 1764
     if(!opt) {
1765 1765
 	mprintf("!Can't parse the command line\n");
1766 1766
 	return 1;