aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDavid M. Syzdek <syzdek@bindlebinaries.com>2017-07-08 17:57:44 -0800
committerDavid M. Syzdek <syzdek@bindlebinaries.com>2017-07-08 17:57:44 -0800
commit83a5fe5cfd48bf46896a29a15669021945e126f4 (patch)
treed90a5e11c28755b336de8acd6250cd6c911dd10c
parent38225654ec5ce3554a9080c825b7dffb4a115ffd (diff)
downloadsecurecoreutils-83a5fe5cfd48bf46896a29a15669021945e126f4.tar.gz
securecoreutils-83a5fe5cfd48bf46896a29a15669021945e126f4.tar.bz2
securecoreutils-83a5fe5cfd48bf46896a29a15669021945e126f4.tar.xz
securecoreutils-83a5fe5cfd48bf46896a29a15669021945e126f4.zip
Updating how common options are processed.
-rw-r--r--src/securecoreutils.c41
-rw-r--r--src/securecoreutils.h5
-rw-r--r--src/widget-cat.c3
-rw-r--r--src/widget-pathcheck.c3
-rw-r--r--src/widget-rm.c3
-rw-r--r--src/widget-rmdir.c3
-rw-r--r--src/widget-tail.c3
-rw-r--r--src/widget-zcat.c3
8 files changed, 48 insertions, 16 deletions
diff --git a/src/securecoreutils.c b/src/securecoreutils.c
index ee50c7b..03a3d81 100644
--- a/src/securecoreutils.c
+++ b/src/securecoreutils.c
@@ -193,7 +193,7 @@ int main(int argc, char * argv[])
193 break; 193 break;
194 194
195 case 'h': 195 case 'h':
196 scu_usage(); 196 scu_usage(&cnf);
197 return(0); 197 return(0);
198 198
199 case 's': 199 case 's':
@@ -328,7 +328,7 @@ int scu_pathcheck(const char * path, int isdir)
328} 328}
329 329
330 330
331void scu_usage(void) 331void scu_usage(scu_config * cnf)
332{ 332{
333 int x; 333 int x;
334 int y; 334 int y;
@@ -337,7 +337,7 @@ void scu_usage(void)
337 printf(" widget [OPTIONS]\n"); 337 printf(" widget [OPTIONS]\n");
338 printf("\n"); 338 printf("\n");
339 339
340 scu_usage_options(); 340 scu_usage_options(cnf);
341 printf("\n"); 341 printf("\n");
342 342
343 printf("WIDGETS:\n"); 343 printf("WIDGETS:\n");
@@ -369,13 +369,38 @@ void scu_usage(void)
369} 369}
370 370
371 371
372void scu_usage_options(void) 372void scu_usage_options(scu_config * cnf)
373{ 373{
374 int i;
375
376 cnf->short_opt = (cnf->short_opt == NULL) ? "hqVv" : cnf->short_opt;
374 printf("OPTIONS:\n"); 377 printf("OPTIONS:\n");
375 printf(" -h, --help print this help and exit\n"); 378
376 printf(" -q, --quiet, --silent do not print messages\n"); 379 for (i = 0; ((cnf->short_opt[i])); i++)
377 printf(" -V, --version print version number and exit\n"); 380 {
378 printf(" -v, --verbose print verbose messages\n"); 381 switch (cnf->short_opt[i])
382 {
383 case 'h':
384 printf(" -h, --help print this help and exit\n");
385 break;
386
387 case 'q':
388 printf(" -q, --quiet, --silent do not print messages\n");
389 break;
390
391 case 'V':
392 printf(" -V, --version print version number and exit\n");
393 break;
394
395 case 'v':
396 printf(" -v, --verbose print verbose messages\n");
397 break;
398
399 default:
400 break;
401 };
402 };
403
379 return; 404 return;
380} 405}
381 406
diff --git a/src/securecoreutils.h b/src/securecoreutils.h
index daa21d7..694d911 100644
--- a/src/securecoreutils.h
+++ b/src/securecoreutils.h
@@ -133,6 +133,7 @@ struct scu_config
133 int argc; 133 int argc;
134 const char * prog_name; 134 const char * prog_name;
135 char ** argv; 135 char ** argv;
136 const char * short_opt;
136 const scu_widget * widget; 137 const scu_widget * widget;
137}; 138};
138 139
@@ -159,8 +160,8 @@ struct scu_widget
159int scu_pathcheck(const char * path, int isdir); 160int scu_pathcheck(const char * path, int isdir);
160 161
161/// Displays secure core utils wrapper usage 162/// Displays secure core utils wrapper usage
162void scu_usage(void); 163void scu_usage(scu_config * cnf);
163void scu_usage_options(void); 164void scu_usage_options(scu_config * cnf);
164void scu_usage_restrictions(void); 165void scu_usage_restrictions(void);
165void scu_usage_summary(scu_config * cnf, const char * suffix); 166void scu_usage_summary(scu_config * cnf, const char * suffix);
166 167
diff --git a/src/widget-cat.c b/src/widget-cat.c
index f62314e..f92784f 100644
--- a/src/widget-cat.c
+++ b/src/widget-cat.c
@@ -95,6 +95,7 @@ int scu_widget_cat(scu_config * cnf)
95 }; 95 };
96 96
97 assert(cnf != NULL); 97 assert(cnf != NULL);
98 cnf->short_opt = short_opt;
98 99
99 while((c = getopt_long(cnf->argc, cnf->argv, short_opt, long_opt, &opt_index)) != -1) 100 while((c = getopt_long(cnf->argc, cnf->argv, short_opt, long_opt, &opt_index)) != -1)
100 { 101 {
@@ -217,7 +218,7 @@ void scu_widget_cat_usage(scu_config * cnf)
217{ 218{
218 scu_usage_summary(cnf, " [OPTIONS] file"); 219 scu_usage_summary(cnf, " [OPTIONS] file");
219 printf("\n"); 220 printf("\n");
220 scu_usage_options(); 221 scu_usage_options(cnf);
221 printf("\n"); 222 printf("\n");
222 scu_usage_restrictions(); 223 scu_usage_restrictions();
223 printf("\n"); 224 printf("\n");
diff --git a/src/widget-pathcheck.c b/src/widget-pathcheck.c
index 1018a77..77d670f 100644
--- a/src/widget-pathcheck.c
+++ b/src/widget-pathcheck.c
@@ -88,6 +88,7 @@ int scu_widget_pathcheck(scu_config * cnf)
88 }; 88 };
89 89
90 assert(cnf != NULL); 90 assert(cnf != NULL);
91 cnf->short_opt = short_opt;
91 92
92 isdir = 0; 93 isdir = 0;
93 94
@@ -171,7 +172,7 @@ void scu_widget_pathcheck_usage(scu_config * cnf)
171{ 172{
172 scu_usage_summary(cnf, " [OPTIONS] file"); 173 scu_usage_summary(cnf, " [OPTIONS] file");
173 printf("\n"); 174 printf("\n");
174 scu_usage_options(); 175 scu_usage_options(cnf);
175 printf(" -d, --directory check path for directory instead of file\n"); 176 printf(" -d, --directory check path for directory instead of file\n");
176 printf("\n"); 177 printf("\n");
177 scu_usage_restrictions(); 178 scu_usage_restrictions();
diff --git a/src/widget-rm.c b/src/widget-rm.c
index 85beb4a..573f13f 100644
--- a/src/widget-rm.c
+++ b/src/widget-rm.c
@@ -100,6 +100,7 @@ int scu_widget_rm(scu_config * cnf)
100 }; 100 };
101 101
102 assert(cnf != NULL); 102 assert(cnf != NULL);
103 cnf->short_opt = short_opt;
103 104
104 force = 0; 105 force = 0;
105 prompt = 0; 106 prompt = 0;
@@ -240,7 +241,7 @@ void scu_widget_rm_usage(scu_config * cnf)
240{ 241{
241 scu_usage_summary(cnf, " [OPTIONS] file"); 242 scu_usage_summary(cnf, " [OPTIONS] file");
242 printf("\n"); 243 printf("\n");
243 scu_usage_options(); 244 scu_usage_options(cnf);
244 printf(" -i prompt for confirmation\n"); 245 printf(" -i prompt for confirmation\n");
245 printf(" -f, --force ignore nonexistent files\n"); 246 printf(" -f, --force ignore nonexistent files\n");
246 printf("\n"); 247 printf("\n");
diff --git a/src/widget-rmdir.c b/src/widget-rmdir.c
index 6018eee..962e16b 100644
--- a/src/widget-rmdir.c
+++ b/src/widget-rmdir.c
@@ -93,6 +93,7 @@ int scu_widget_rmdir(scu_config * cnf)
93 }; 93 };
94 94
95 assert(cnf != NULL); 95 assert(cnf != NULL);
96 cnf->short_opt = short_opt;
96 97
97 while((c = getopt_long(cnf->argc, cnf->argv, short_opt, long_opt, &opt_index)) != -1) 98 while((c = getopt_long(cnf->argc, cnf->argv, short_opt, long_opt, &opt_index)) != -1)
98 { 99 {
@@ -192,7 +193,7 @@ void scu_widget_rmdir_usage(scu_config * cnf)
192{ 193{
193 scu_usage_summary(cnf, " [OPTIONS] file");; 194 scu_usage_summary(cnf, " [OPTIONS] file");;
194 printf("\n"); 195 printf("\n");
195 scu_usage_options(); 196 scu_usage_options(cnf);
196 printf(" -i prompt for confirmation\n"); 197 printf(" -i prompt for confirmation\n");
197 printf(" -f, --force ignore nonexistent files\n"); 198 printf(" -f, --force ignore nonexistent files\n");
198 printf("\n"); 199 printf("\n");
diff --git a/src/widget-tail.c b/src/widget-tail.c
index a33abc7..1abc5e3 100644
--- a/src/widget-tail.c
+++ b/src/widget-tail.c
@@ -137,6 +137,7 @@ int scu_widget_tail(scu_config * cnf)
137 }; 137 };
138 138
139 assert(cnf != NULL); 139 assert(cnf != NULL);
140 cnf->short_opt = short_opt;
140 141
141 opts = 0; 142 opts = 0;
142 optnum = 10; 143 optnum = 10;
@@ -515,7 +516,7 @@ void scu_widget_tail_usage(scu_config * cnf)
515{ 516{
516 scu_usage_summary(cnf, " [OPTIONS] file"); 517 scu_usage_summary(cnf, " [OPTIONS] file");
517 printf("\n"); 518 printf("\n");
518 scu_usage_options(); 519 scu_usage_options(cnf);
519 printf(" -c, --bytes=X output the last X bytes\n"); 520 printf(" -c, --bytes=X output the last X bytes\n");
520 printf(" -f, --follow output appended data as the file grows\n"); 521 printf(" -f, --follow output appended data as the file grows\n");
521 printf(" -n, --lines=X output the last X lines\n"); 522 printf(" -n, --lines=X output the last X lines\n");
diff --git a/src/widget-zcat.c b/src/widget-zcat.c
index bb122e6..720e254 100644
--- a/src/widget-zcat.c
+++ b/src/widget-zcat.c
@@ -137,6 +137,7 @@ int scu_widget_zcat(scu_config * cnf)
137 }; 137 };
138 138
139 assert(cnf != NULL); 139 assert(cnf != NULL);
140 cnf->short_opt = short_opt;
140 141
141 bzero(magic, sizeof(magic)); 142 bzero(magic, sizeof(magic));
142 143
@@ -381,7 +382,7 @@ void scu_widget_zcat_usage(scu_config * cnf)
381{ 382{
382 scu_usage_summary(cnf, " [OPTIONS] file"); 383 scu_usage_summary(cnf, " [OPTIONS] file");
383 printf("\n"); 384 printf("\n");
384 scu_usage_options(); 385 scu_usage_options(cnf);
385 printf("\n"); 386 printf("\n");
386 scu_usage_restrictions(); 387 scu_usage_restrictions();
387 printf("\n"); 388 printf("\n");