Hi, OK, it turns out that my last patch for adding comments to usage had a horrible bug. Although (struct option_descr) would yield a (struct option), as anticipated, the increment of the pointers of these structs ofcourse wouldn't...
Anyway the patch below fixes this, although also in a bit hackish way. usage() expects an \0 in the option.name string, and after that a comment. Like this: "help\0this text" grts Tim Index: config.c =================================================================== RCS file: /cvsroot/suspend/suspend/config.c,v retrieving revision 1.9 diff -u -r1.9 config.c --- config.c 2 May 2007 20:55:43 -0000 1.9 +++ config.c 12 May 2007 20:10:37 -0000 @@ -104,23 +104,27 @@ return error; } -void usage(char *my_name, struct option_descr *options, const char *short_options) +/* We're abusing struct option a bit. usage() expects an \0 in the + * name string, and after that a comment. + */ +void usage(char *my_name, struct option *options, const char *short_options) { - struct option_descr *opt; + struct option *opt; printf("Usage: %s [options]", my_name); - for (opt = options; opt->o.name; opt++) + for (opt = options; opt->name; opt++) { - if (strchr(short_options,opt->o.val)) - printf("\n -%c, --%s", opt->o.val, opt->o.name); + const char *descr = opt->name + strlen(opt->name) + 1; + if (strchr(short_options,opt->val)) + printf("\n -%c, --%s", opt->val, opt->name); else - printf("\n --%s", opt->o.name); + printf("\n --%s", opt->name); - if (opt->o.has_arg) - printf(" <%s>", opt->o.name); + if (opt->has_arg) + printf(" <%s>", opt->name); - if (strlen(opt->descr)) - printf("\t%s",opt->descr); + if (strlen(descr)) + printf("\t%s",descr); } printf("\n"); Index: config.h =================================================================== RCS file: /cvsroot/suspend/suspend/config.h,v retrieving revision 1.6 diff -u -r1.6 config.h --- config.h 2 May 2007 20:55:43 -0000 1.6 +++ config.h 12 May 2007 20:10:37 -0000 @@ -21,13 +21,8 @@ unsigned int len; }; -struct option_descr { - struct option o; - const char *descr; -}; - int parse(char *my_name, char *file_name, int parc, struct config_par *parv); -void usage(char *my_name, struct option_descr options[], const char *short_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.43 diff -u -r1.43 resume.c --- resume.c 2 May 2007 20:55:43 -0000 1.43 +++ resume.c 12 May 2007 20:10:37 -0000 @@ -735,16 +735,24 @@ /* Parse the command line and/or configuration file */ static inline int get_config(int argc, char *argv[]) { - static struct option_descr options[] = { - { { "help", no_argument, NULL, 'h'}, - "\t\t\tthis text." }, - { { "config", required_argument, NULL, 'f'}, - "\t\talternative configuration file." }, - { { "resume_device", required_argument, NULL, 'r'}, - "device that contains swap area"}, - { { "resume_offset", required_argument, NULL, 'o'}, - "offset of swap file in resume device."}, - { { NULL, 0, NULL, 0 }, ""} + static struct option options[] = { + { + "help\0\t\t\tthis text", + no_argument, NULL, 'h' + }, + { + "config\0\t\talternative configuration file.", + required_argument, NULL, 'f' + }, + { + "resume_device\0device that contains swap area", + required_argument, NULL, 'r' + }, + { + "resume_offset\0offset of swap file in resume device.", + required_argument, NULL, 'o' + }, + { NULL, 0, NULL, 0 } }; int i, error; char *conf_name = CONFIG_FILE; @@ -754,7 +762,7 @@ char *rdev = NULL; const char *optstring = "hf:o:r:"; - while ((i = getopt_long(argc, argv, optstring, (struct option *)options, NULL)) != -1) { + while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { switch (i) { case 'h': usage("resume", options, optstring); Index: s2ram.c =================================================================== RCS file: /cvsroot/suspend/suspend/s2ram.c,v retrieving revision 1.53 diff -u -r1.53 s2ram.c --- s2ram.c 2 May 2007 20:55:43 -0000 1.53 +++ s2ram.c 12 May 2007 20:10:37 -0000 @@ -345,20 +345,25 @@ { int i, id = -1, ret = 0, test_mode = 0; int active_console = -1; - struct option_descr options[] = { - { { "help", no_argument, NULL, 'h'}, - "\tthis text." }, - { { "test", no_argument, NULL, 'n'}, - "\ttest if the machine is in the database." }, - { { "identify", no_argument, NULL, 'i'}, - "prints a string that identifies the machine." }, - HACKS_LONG_OPTS, - { { NULL, 0, NULL, 0 }, - "" } + struct option options[] = { + { + "help\0\tthis text.", + no_argument, NULL, 'h' + }, + { + "test\0\ttest if the machine is in the database.", + no_argument, NULL, 'n' + }, + { + "identify\0prints a string that identifies the machine.", + no_argument, NULL, 'i' + }, + HACKS_LONG_OPTS, + { NULL, 0, NULL, 0 } }; const char *optstring = "hni" "fspmrva:"; - while ((i = getopt_long(argc, argv, optstring, (struct option *)options, NULL)) != -1) { + while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { switch (i) { case 'h': usage("s2ram", options, optstring); Index: s2ram.h =================================================================== RCS file: /cvsroot/suspend/suspend/s2ram.h,v retrieving revision 1.6 diff -u -r1.6 s2ram.h --- s2ram.h 2 May 2007 20:55:43 -0000 1.6 +++ s2ram.h 12 May 2007 20:10:37 -0000 @@ -21,18 +21,31 @@ void s2ram_add_flag(int opt, const char *arg); #define HACKS_LONG_OPTS \ - { { "force", no_argument, NULL, 1}, \ - "\tforce suspending, even on unknown machines.\n\nThe following options are only available with --force:" }, \ - { { "vbe_save", no_argument, NULL, 2}, \ - "\tsave VBE state before suspending and restore after resume."}, \ - { { "vbe_post", no_argument, NULL, 3}, \ - "\tVBE POST the graphics card after resume."}, \ - { { "vbe_mode", no_argument, NULL, 4}, \ - "\tget VBE mode before suspend and set it after resume."}, \ - { { "radeontool", no_argument, NULL, 5}, \ - "\tturn off the backlight on radeons before suspending."}, \ - { { "pci_save", no_argument, NULL, 6}, \ - "\tsave the PCI config space for the VGA card."}, \ - { { "acpi_sleep", required_argument, NULL, 7}, \ - "set the acpi_sleep parameter before suspend\n\t\t\t1=s3_bios, 2=s3_mode, 3=both" } - + {\ + "force\0\tforce suspending, even on unknown machines.\n\nThe following options are only available with --force:",\ + no_argument, NULL, 1 \ + },\ + {\ + "vbe_save\0\tsave VBE state before suspending and restore after resume.",\ + no_argument, NULL, 2 \ + },\ + {\ + "vbe_post\0\tVBE POST the graphics card after resume.",\ + no_argument, NULL, 3 \ + },\ + {\ + "vbe_mode\0\tget VBE mode before suspend and set it after resume.",\ + no_argument, NULL, 4 \ + },\ + {\ + "radeontool\0\tturn off the backlight on radeons before suspending.",\ + no_argument, NULL, 5 \ + },\ + {\ + "pci_save\0\tsave the PCI config space for the VGA card.",\ + no_argument, NULL, 6 \ + },\ + {\ + "acpi_sleep\0set the acpi_sleep parameter before suspend\n\t\t\t1=s3_bios, 2=s3_mode, 3=both",\ + required_argument, NULL, 7 \ + } Index: suspend.c =================================================================== RCS file: /cvsroot/suspend/suspend/suspend.c,v retrieving revision 1.77 diff -u -r1.77 suspend.c --- suspend.c 2 May 2007 20:55:43 -0000 1.77 +++ suspend.c 12 May 2007 20:10:37 -0000 @@ -1168,22 +1168,31 @@ /* Parse the command line and/or configuration file */ static inline int get_config(int argc, char *argv[]) { - static struct option_descr options[] = { - { { "help", no_argument, NULL, 'h'}, - "\t\t\tthis message."}, - { { "config", required_argument, NULL, 'f'}, - "\t\talternative configuration file."}, - { { "image_size", required_argument, NULL, 's'}, - "\tdesired size of the image."}, - { { "resume_device", required_argument, NULL, 'r'}, - "device that contains swap area."}, - { { "resume_offset", required_argument, NULL, 'o'}, - "offset of swap file in resume device."}, + static struct option options[] = { + { + "help\0\t\t\tthis text", + no_argument, NULL, 'h' + }, + { + "config\0\t\talternative configuration file.", + required_argument, NULL, 'f' + }, + { + "resume_device\0device that contains swap area", + required_argument, NULL, 'r' + }, + { + "resume_offset\0offset of swap file in resume device.", + required_argument, NULL, 'o' + }, + { + "image_size\0\tdesired size of the image.", + required_argument, NULL, 's' + }, #ifdef CONFIG_BOTH - HACKS_LONG_OPTS, + HACKS_LONG_OPTS, #endif - { { NULL, 0, NULL, 0 }, - ""} + { NULL, 0, NULL, 0 } }; int i, error; char *conf_name = CONFIG_FILE; @@ -1195,7 +1204,7 @@ int set_rdev = 0; const char *optstring = "hf:s:o:r:"; - while ((i = getopt_long(argc, argv, optstring, (struct option *) options, NULL)) != -1) { + while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) { switch (i) { case 'h': usage(my_name, options, optstring);
signature.asc
Description: PGP signature
------------------------------------------------------------------------- This SF.net email is sponsored by DB2 Express Download DB2 Express C - the FREE version of DB2 express and take control of your XML. No limits. Just data. Click to get it now. http://sourceforge.net/powerbar/db2/
_______________________________________________ Suspend-devel mailing list Suspend-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/suspend-devel