I've been beating myself crazy exploring command line arguments and return
values in Harbour. I'm used to this in C:
=====================================
#include <stdio.h>
int main(int argc, char *argv[]){
int i;
for (i=0; i < argc; i++)
printf("%s\n", argv[i]);
return(17);
}
=====================================
I wasn't so successful in Clipper. No matter what I put as the args to main, I
had to predeclare at least the maximum number of args expected, and later
convert that to an array. And for the life of me, I can't find a way to return
a non-zero such that Bash's $? variable shows anything but 0. Here's the code
I wrote:
===================================
function Main(arg1, arg2, arg3, arg4, arg5)
LOCAL arg
LOCAL argc := 0
LOCAL argv := {arg1, arg2, arg3, arg4, arg5}
? "Arguments follow ..."
FOR EACH arg IN argv
if arg = Nil
EXIT
ENDIF
argc++
? "Argument ", argc, "=", arg
NEXT
? "No more arguments."
? "There were ", argc, " arguments total."
RETURN 17 //Doesnt work, always 0
===================================
Here's the result:
=====================================
slitt@mydesk:~/hb_ex$ hbrun args.prg one two three
Arguments follow ...
Argument 1 = one
Argument 2 = two
Argument 3 = three
No more arguments.
There were 3 arguments total.
slitt@mydesk:~/hb_ex$ echo $?
0
slitt@mydesk:~/hb_ex$
=====================================
Kludge city! There's got to be a better way, and the return statement doesn't
influence the executable's $?. What am I missing?
Thanks
SteveT
Steve Litt
Recession Relief Package
http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt
Hi all,
I've been beating myself crazy exploring command line arguments and return
values in Harbour. I'm used to this in C:
=====================================
#include
http://www.recession-relief.US">http://www.recession-relief.US
Twitter: http://www.twitter.com/stevelitt">http://www.twitter.com/stevelitt