slang-users mailing list

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

[slang-users] cmdopt


Hi,

I just looked at cmdopt.sl, wanting to use it in a script but
apparently I don't understand how it works. I am attaching a
little test script, "psl". The problem is that I cannot seem to
call the two different functions in the script with a different
number of arguments.

                  -------- psl begin ----------
                  
#!/usr/bin/env slsh

_debug_info=1;_traceback=1;_slangtrace=1;

require ("cmdopt");

private define p (a)
{
   () = printf ("%s\n", a);
}

private define pp (a, b, c)
{
   () = printf ("%s%s%s\n", a, b, c);
}

define slsh_main ()
{
   variable c = cmdopt_new ();
   cmdopt_add (c, "a", &p, __argv[2]; type="str");
   cmdopt_add (c, "b", &pp, __argv[2], __argv[3], __argv[4]; type="str");
   variable i = cmdopt_process (c, __argv, 1);

   if (i >= __argc)
     exit (1);
}  

                  -------- psl end ----------


Now, if I call the script as

   ./psl -b a b c
   
it prints "abc" as I want

but if I call the script as

   ./psl -a a
   
It doesn't print "a", rather it returns:

   Invalid Index
   Unable to access array element
   ./psl:21:slsh_main:Invalid Index
     Local variables for slsh_main:
           Struct_Type c = Struct_Type with 4 fields
           Undefined_Type i = Undefined_Type
   Error encountered while executing slsh_main
   
Line 21 refers to the "pp" function called with the "-b"
option and not the "p" function I just called with the "-a"
option..

If I comment out this line, then it works. In other words, the one
command line option works if the other is commented out and vice
versa. I can't have them both.

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]