slang-users mailing list

[2015 Date Index] [2015 Thread Index] [Other years]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]

[slang-users] Re: cmdopt


John E. Davis <jed@xxxxxxxxxxx> wrote:

> Morten Bo Johansen <mbj@xxxxxxxxxxx> wrote:

> >    cmdopt_add (c, "b", &pp, __argv[2], __argv[3], __argv[4]; type="str");
> 
> In both cases, you are incorrectly using the cmdopt_add function.
> 
> It seems that you are trying to invoke a callback function to handle a
> variable number of command-line arguments.  Like the getopt function,
> this module only supports command line switches that have no optional
> value or those that accept a single value.

No, it wasn't a callback function, actually. The number of
arguments to each function were intended to be finite as in
this

   if (__argv[1] == "-a")
     {
         ifnot (__argc == 4)
           error_msg ();

         func (__argv[2], __argv[3]);
     }

(which I can just use, then).

I can probably also find a way to mix command line arguments
with this method.

But instead of having 10 of these in the script that I am
working on, my - misguided - way of trying to do it with cmdopt
seemed a little leaner. That was all, really. ;-)

> private define print_list (list)
> {
>    () = printf ("%s\n", strcat (__push_list (list)));
> }
> 
> define slsh_main ()
> {
>    variable list = {};
>    variable c = cmdopt_new ();
>    c.add ("a", &p; type="str");
>    c.add ("b", &list; append, type="str");
> 
>    variable i = cmdopt_process (c, __argv, 1);
> 
>    if (length (list))
>      print_list (list);

Did I misunderstand or wasn't the above supposed to print all
the arguments to the "-b" switch? If I do 

  <script> -b a b c
  
then with the above it should print "abc"? However, only the
first argument is pushed onto the list so it prints only "a".

Thanks,
Morten

_______________________________________________
For list information, visit <http://jedsoft.org/slang/mailinglists.html>.


[2015 date index] [2015 thread index]
[Thread Prev] [Thread Next]      [Date Prev] [Date Next]