Op Thu, 29 Mar 2007 21:58:10 +0200 schreef Stefan Seyfried <[EMAIL PROTECTED]>:
> > 2) Also pass the short option string to usage and check for each > > `val' if it is included in the short option string. At first I > > thought this was a bit overkill, but thinking about it, it is more > > correct... > > ... this is also fine with me (and since you already have done the > work... :-) > > > Untested... > > tested by me. No. It doesn't apply (whitespace damaged) and after i > fixed that up, it did not compile. > > > What do you think? > > It does not work :-) That is because I didn't change the places which call the usage function, it was just a `heh, does this sound reasonable' piece of code... but here is a working patch: Index: config.c =================================================================== RCS file: /cvsroot/suspend/suspend/config.c,v retrieving revision 1.7 diff -u -r1.7 config.c --- config.c 10 Nov 2006 00:08:33 -0000 1.7 +++ config.c 29 Mar 2007 21:11:36 -0000 @@ -104,16 +104,23 @@ return error; } -void usage(char *my_name, struct option *options) +void usage(char *my_name, struct option *options, const char *short_options) { struct option *opt; - printf("Usage: %s ", my_name); - for (opt = options; opt->name; opt++) + printf("Usage: %s\t", my_name); + for (opt = options; opt->name; opt++) + { + if (strchr(short_options,opt->val)) + printf("[-%c|--%s", opt->val, opt->name); + else + printf("[--%s", opt->name); + if (opt->has_arg) - printf("[-%c <%s>]", opt->val, opt->name); + printf(" <%s>]\n\t\t", opt->name); else - printf("[-%c]", opt->val); + printf("]\n\t\t"); + } - printf(" [<resume_device>]\n"); + printf("[<resume_device>]\n"); } Index: config.h =================================================================== RCS file: /cvsroot/suspend/suspend/config.h,v retrieving revision 1.4 diff -u -r1.4 config.h --- config.h 7 Nov 2006 21:13:33 -0000 1.4 +++ config.h 29 Mar 2007 21:11:36 -0000 @@ -21,6 +21,6 @@ int parse(char *my_name, char *file_name, int parc, struct config_par *parv); -void usage(char *my_name, struct option options[]); +void usage(char *my_name, struct option options[], const char *short_options); #define CONFIG_FILE "/etc/suspend.conf" Index: resume.c =================================================================== RCS file: /cvsroot/suspend/suspend/resume.c,v retrieving revision 1.41 diff -u -r1.41 resume.c --- resume.c 16 Mar 2007 16:02:22 -0000 1.41 +++ resume.c 29 Mar 2007 21:11:36 -0000 @@ -746,11 +746,12 @@ char *conf_name = CONFIG_FILE; int set_off = 0; unsigned long long int off = 0; + const char *optstring = "hf:o:"; - while ((i = getopt_long(argc, argv, "hf:o:", options, NULL)) != -1) { + while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { switch (i) { case 'h': - usage("resume", options); + usage("resume", options, optstring); exit(EXIT_SUCCESS); case 'f': conf_name = optarg; @@ -760,7 +761,7 @@ set_off = 1; break; default: - usage("resume", options); + usage("resume", options, optstring); return -EINVAL; } } Index: suspend.c =================================================================== RCS file: /cvsroot/suspend/suspend/suspend.c,v retrieving revision 1.71 diff -u -r1.71 suspend.c --- suspend.c 27 Mar 2007 10:54:19 -0000 1.71 +++ suspend.c 29 Mar 2007 21:11:36 -0000 @@ -1182,11 +1187,12 @@ unsigned long long int off = 0; int set_size = 0; unsigned long int im_size = 0; + const char *optstring="hf:s:o:"; - while ((i = getopt_long(argc, argv, "hf:s:o:", options, NULL)) != -1) { + while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { switch (i) { case 'h': - usage("suspend", options); + usage("suspend", options, optstring); exit(0); case 'f': conf_name = optarg; @@ -1200,7 +1206,7 @@ set_off = 1; break; default: - usage("suspend", options); + usage("suspend", options, optstring); return -EINVAL; } } ------------------------------------------------------------------------- Take Surveys. Earn Cash. Influence the Future of IT Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys-and earn cash http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV _______________________________________________ Suspend-devel mailing list Suspend-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/suspend-devel