On Thu, 29 Mar 2007 14:30:04 +0200
Stefan Seyfried <[EMAIL PROTECTED]> wrote:

> On Thu, Mar 29, 2007 at 11:04:22AM +0200, Tim Dijkstra wrote:
> > On Thu, 29 Mar 2007 10:32:59 +0200
> > Stefan Seyfried <[EMAIL PROTECTED]> wrote:
> > 
> > > This is ugly and long, but shows the long options (we could leave out
> > > the short options, or go for something like:
> > > Usage: suspend  [-h|--help]
> > >                 [-f|--config <config>]
> > >                 [-s|--image_size <image_size>]
> > >                 [-o|--resume_offset <resume_offset>]
> > >                 [<resume_device>]
> > 
> > I would go for this.
> 
> ok, this is

> Index: config.c
> ===================================================================
> RCS file: /cvsroot/suspend/suspend/config.c,v
> retrieving revision 1.7
> diff -u -p -r1.7 config.c
> --- config.c  10 Nov 2006 00:08:33 -0000      1.7
> +++ config.c  29 Mar 2007 12:29:04 -0000
> @@ -108,12 +108,12 @@ void usage(char *my_name, struct option 
>  {
>       struct option *opt;
>  
> -     printf("Usage: %s ", my_name);
> +     printf("Usage: %s\t", my_name);
>       for (opt = options; opt->name; opt++)
>               if (opt->has_arg)
> -                     printf("[-%c <%s>]", opt->val, opt->name);
> +                     printf("[-%c|--%s <%s>]\n\t\t", opt->val, opt->name, 
> opt->name);
>               else
> -                     printf("[-%c]", opt->val);
> +                     printf("[-%c|--%s]\n\t\t", opt->val, opt->name);
>  
> -     printf(" [<resume_device>]\n");
> +     printf("[<resume_device>]\n");
>  }
> 
> 
> Objections, anyone?

Sorry, to change my mind on this;) But if we want to support only
'--force' and no short option for it this doesn't fit. I can leave out
the short option from the short option string, but the option struct for
`--force' needs an `val', and per code above, it will show in usage().

Is see two ways out. 
1) drop all short options form usage()
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...



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 19:26:47 -0000
@@ -104,16 +104,23 @@
        return error;
 }

-void usage(char *my_name, struct option *options)
+void usage(char *my_name, struct option *options, 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");
 }


Untested...

What do you think?

grts Tim

Attachment: signature.asc
Description: PGP signature

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

Reply via email to