FUNCTION somefunction$(VAR bla$ SIZE size) (SOLVED)
Oct 8, 2023 9:49:49 GMT 1
Post by rikky on Oct 8, 2023 9:49:49 GMT 1
Hello,
I'm totally confused.
Following did work for ages and suddenly doesn't anymore.
I'm working with the stable:
BaCon version 4.7 on Linux armv7l - (c) Peter van Eerten - MIT License.
And I thought the following did work with this stable also, but I have no way to be certain.
What I do is having a square bracket array ARGS$[] with everything that there is on the command line,
and I put it into a round bracket array ARG$()
And then I feed them to various functions in my programs in the form of:
FUNCTION somefunction$(VAR bla$ SIZE size)
I've made a TESTARGS$() FUNCTION for clarification.
It prints instead of returns, but it is for demonstration only.
I can feed anything into this function and it prints the right size
Except if I feed it with ARG$("1") and ARG$("2"), when there are zeo or only one arguments on the commandline.
My program is called '/home/rik/bug.bac'
So
But:
my program:
FUNCTION TESTARGS$(VAR bla$ SIZE size)
OPTION BASE 1
LOCAL abc
'PRINT
PRINT "size : ",size
FOR abc = 1 TO size
PRINT "ARG[" & STR$(abc) & "] : " & bla$[abc]
NEXT abc
RETURN ""
END FUNCTION
DECLARE ARG$ ASSOC STRING
ALIAS argv TO ARGS$
ALIAS argc TO ARGLEN
DEF FN ARGC() = argc
LOCAL abc
FOR abc = 0 TO ARGLEN-1
ARG$(STR$(abc)) = ARGS$[abc]
NEXT abc
PRINT
PRINT "ARGLEN : ",ARGLEN
FOR abc = 0 TO ARGLEN -1
PRINT "ARGS$[" ,abc, "] : " , ARGS$[abc]
NEXT abc
PRINT
PRINT "NRKEYS(ARG$) : " , NRKEYS(ARG$)
FOR abc = 0 TO NRKEYS(ARG$)-1
PRINT "ARG$(" ,abc, ") : " , ARG$(STR$(abc))
NEXT abc
PRINT
PRINT "TESTARGS$(" & TOKEN$(ARGUMENT$,1) & "," & TOKEN$(ARGUMENT$,2) & ")"
TESTARGS$(TOKEN$(ARGUMENT$,1),TOKEN$(ARGUMENT$,2))
PRINT
PRINT "TESTARGS$('" & ARG$("1") & "','" & ARG$("2") & "')"
IF ARGLEN = 1 OR ARGLEN = 2 THEN PRINT "size should be 2, but it is 0."
TESTARGS$(ARG$("1") , ARG$("2"))
PRINT
PRINT "TESTARGS$('','')"
TESTARGS$("","")
PRINT
Response from:
Rik.
EDIT: shortened the program a little.
EDIT2: bacon 4.6.1 does not have this bug.
I'm totally confused.
Following did work for ages and suddenly doesn't anymore.
I'm working with the stable:
BaCon version 4.7 on Linux armv7l - (c) Peter van Eerten - MIT License.
And I thought the following did work with this stable also, but I have no way to be certain.
What I do is having a square bracket array ARGS$[] with everything that there is on the command line,
and I put it into a round bracket array ARG$()
And then I feed them to various functions in my programs in the form of:
FUNCTION somefunction$(VAR bla$ SIZE size)
I've made a TESTARGS$() FUNCTION for clarification.
It prints instead of returns, but it is for demonstration only.
I can feed anything into this function and it prints the right size
Except if I feed it with ARG$("1") and ARG$("2"), when there are zeo or only one arguments on the commandline.
My program is called '/home/rik/bug.bac'
So
/home/rik/bug een twee drie vier
works.But:
/home/rik/bug een
does NOT.my program:
OPTION BASE 1FUNCTION TESTARGS$(VAR bla$ SIZE size)
OPTION BASE 1
LOCAL abc
PRINT "size : ",size
FOR abc = 1 TO size
PRINT "ARG[" & STR$(abc) & "] : " & bla$[abc]
NEXT abc
RETURN ""
END FUNCTION
DECLARE ARG$ ASSOC STRING
ALIAS argv TO ARGS$
ALIAS argc TO ARGLEN
DEF FN ARGC() = argc
LOCAL abc
FOR abc = 0 TO ARGLEN-1
ARG$(STR$(abc)) = ARGS$[abc]
NEXT abc
PRINT "ARGLEN : ",ARGLEN
FOR abc = 0 TO ARGLEN -1
PRINT "ARGS$[" ,abc, "] : " , ARGS$[abc]
NEXT abc
PRINT "NRKEYS(ARG$) : " , NRKEYS(ARG$)
FOR abc = 0 TO NRKEYS(ARG$)-1
PRINT "ARG$(" ,abc, ") : " , ARG$(STR$(abc))
NEXT abc
PRINT "TESTARGS$(" & TOKEN$(ARGUMENT$,1) & "," & TOKEN$(ARGUMENT$,2) & ")"
TESTARGS$(TOKEN$(ARGUMENT$,1),TOKEN$(ARGUMENT$,2))
PRINT "TESTARGS$('" & ARG$("1") & "','" & ARG$("2") & "')"
IF ARGLEN = 1 OR ARGLEN = 2 THEN PRINT "size should be 2, but it is 0."
TESTARGS$(ARG$("1") , ARG$("2"))
PRINT "TESTARGS$('','')"
TESTARGS$("","")
Response from:
/home/rik/bug een
ARGLEN : 2
ARGS$[0] : /home/rik/bug
ARGS$[1] : een
NRKEYS(ARG$) : 2
ARG$(0) : /home/rik/bug
ARG$(1) : een
TESTARGS$(/home/rik/bug,een)
size : 2
ARG[1] : /home/rik/bug
ARG[2] : een
TESTARGS$('een','')
size should be 2, but it is 0.
size : 0
TESTARGS$('','')
size : 2
ARG[1] :
ARG[2] :
Rik.
EDIT: shortened the program a little.
EDIT2: bacon 4.6.1 does not have this bug.