Hi,

S2ram could also use the usage() function from config.c to display its
message. The only problem is that to replicate its current output we
need to print comments too. To make this possible I made a little
patch. The patch only works for s2disk currently, I didn't feel like
adding the comments for s2ram/s2both if nobody likes the idea...

The `s2both -h' output now looks like:

Usage: s2disk
  [-h|--help]                           This message
  [-f|--config <config>]                Alternative configuration file
  [-s|--image_size <image_size>]        Desired size of the image
  [-o|--resume_offset <resume_offset>]  Offset of swap file in resume device
  [<resume_device>]


Index: config.h
===================================================================
RCS file: /cvsroot/suspend/suspend/config.h,v
retrieving revision 1.5
diff -u -r1.5 config.h
--- config.h    1 Apr 2007 22:03:29 -0000       1.5
+++ config.h    20 Apr 2007 22:04:43 -0000
@@ -10,6 +10,8 @@
  *
  */
 
+#include <getopt.h>
+
 #define MAX_STR_LEN    256
 
 struct config_par {
@@ -19,8 +21,13 @@
        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 options[], const char *short_options);
+void usage(char *my_name, struct option_descr options[], const char 
*short_options);
 
 #define CONFIG_FILE    "/etc/suspend.conf"

Index: suspend.c
===================================================================
RCS file: /cvsroot/suspend/suspend/suspend.c,v
retrieving revision 1.76
diff -u -r1.76 suspend.c
--- suspend.c   3 Apr 2007 19:32:34 -0000       1.76
+++ suspend.c   20 Apr 2007 22:04:44 -0000
@@ -1169,15 +1169,20 @@
 /* Parse the command line and/or configuration file */
 static inline int get_config(int argc, char *argv[])
 {
-       static struct option options[] = {
-               { "help",               no_argument,            NULL, 'h'},
-               { "config",             required_argument,      NULL, 'f'},
-               { "image_size",         required_argument,      NULL, 's'},
-               { "resume_offset",      required_argument,      NULL, 'o'},
+       static struct option_descr options[] = {
+           {   { "help",               no_argument,            NULL, 'h'}, 
+               "\t\t\tThis message"},
+           {   { "config",             required_argument,      NULL, 'f'},
+               "\tAlternative configuration file"},
+           {   { "image_size",         required_argument,      NULL, 's'},
+               "Desired size of the image"},
+           {   { "resume_offset",      required_argument,      NULL, 'o'},
+               "Offset of swap file in resume device"},
 #ifdef CONFIG_BOTH
                HACKS_LONG_OPTS
 #endif
-               { NULL,                 0,                      NULL,  0 }
+           {   { NULL,                 0,                      NULL,  0 },
+               ""}
        };
        int i, error;
        char *conf_name = CONFIG_FILE;
@@ -1187,7 +1192,7 @@
        unsigned long int im_size = 0;
        const char *optstring = "hf:s:o:";
 
-       while ((i = getopt_long(argc, argv, optstring, options, NULL)) != -1) {
+       while ((i = getopt_long(argc, argv, optstring, (struct option *) 
options, NULL)) != -1) {
                switch (i) {
                case 'h':
                        usage(my_name, options, optstring);

Index: config.c
===================================================================
RCS file: /cvsroot/suspend/suspend/config.c,v
retrieving revision 1.8
diff -u -r1.8 config.c
--- config.c    1 Apr 2007 22:03:29 -0000       1.8
+++ config.c    20 Apr 2007 22:04:43 -0000
@@ -104,23 +104,29 @@
        return error;
 }
 
-void usage(char *my_name, struct option *options, const char *short_options)
+void usage(char *my_name, struct option_descr *options, const char 
*short_options)
 {
-       struct option *opt;
+       struct option_descr *opt;
 
-       printf("Usage: %s\t", my_name);
-       for (opt = options; opt->name; opt++) 
+       printf("Usage: %s\n  ", my_name);
+       for (opt = options; opt->o.name; opt++) 
        {
-               if (strchr(short_options,opt->val))
-                       printf("[-%c|--%s", opt->val, opt->name);
+               if (strchr(short_options,opt->o.val))
+                       printf("[-%c|--%s", opt->o.val, opt->o.name);
                else
-                       printf("[--%s", opt->name);
+                       printf("[--%s", opt->o.name);
 
-               if (opt->has_arg)
-                       printf(" <%s>]\n\t\t", opt->name);
+               if (opt->o.has_arg)
+                       printf(" <%s>]", opt->o.name);
                else
-                       printf("]\n\t\t");
+                       printf("]");
+
+               if (strlen(opt->descr))
+                       printf("\t%s",opt->descr);
+
+               printf("\n  ");
        }
 
+
        printf("[<resume_device>]\n");
 }

Attachment: 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

Reply via email to