The BAsic CONverter Forum
« Feature requests »

Welcome Guest. Please Login or Register.
May 25, 2013, 1:56pm




The BAsic CONverter Forum :: General :: Bugs, features :: Feature requests
   [Search This Thread] [Share Topic] [Print]
 AuthorTopic: Feature requests (Read 698 times)
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Feature requests
« Thread Started on Nov 14, 2010, 10:54am »

I am new to BaCon. These are some thoughts on extra features that would be nice...

BREAK [number]
Just like in Bash, an optional integer number to break up any level when in nested loops.

CONTINUE [number]
Some BASICs have this, Bash has it, well, lots of languages have it. Goes to the start of the current loop. Again, I suggest an optional integer argument.

Note, I just looked at freeBASIC, they have gone their own way on the above, for example, this is the equivalent of 'BREAK 2':

For i = 1 To 10
For j = 1 To 10
Exit For, For
Next j
Print "I will never be shown"
Next i

...not as simple.

COMMAND
To get the commandline parameters passed to the application.

EXEC on steroids
It would be very useful if you could extend one of these with extra keywords to support stdin and stdout and the return-value.
For example, here is some C code that executes a shell to find out how many instances of application 'pupmem' are running:

fpipe=(FILE*)popen("pidof pupmem | tr ' ' '\n' | wc -l","r");
fgets(pidcnt,sizeof pidcnt,fpipe);
pclose(fpipe);

...and similarly a pipe can be coded for stdin.

stdout is what I guess is what EXEC already does, for example:

files$=EXEC$("ls -l")

But what about stdin? Return value?

Um, would this be do-able, or even is it a sensible syntax?:

files$=EXEC$("ls -l") STDIN=param1$ RETVAL=num1

Regards,
Barry Kauler
Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Re: Feature requests
« Reply #1 on Nov 14, 2010, 11:30am »

Oops, I should have read the docs a bit more, BaCon already has ARGUMENT$, so ignore my post above about COMMAND.
Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

Joined: Apr 2010
Gender: Male
Posts: 938
Location: The Hague, The Netherlands
Karma: 9
 Re: Feature requests
« Reply #2 on Nov 14, 2010, 12:27pm »

Hi Barry,

The BREAK and CONTINUE requests will be quite hard to implement but I'll look at it. Currently there is no CONTINUE at all so that one can be added anyway.

For EXEC, what do you mean with 'returnvalue'? Probably the returnvalue of the actual command, right? (In BASH shell scripting this is denoted with $? - I guess you refer to this?)

If you mean this returnvalue, what would be the returnvalue of a string like: EXEC("ls -l; cd /tmp; rm *.*") ? Would we see the returnvalue of the 'rm' as this one is executed last?

EXEC it is a function so the syntax will be something like this: EXEC("command", [stdin [, returnvalue]]). So the last two will be optional.

Regards
Peter
Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Re: Feature requests
« Reply #3 on Nov 15, 2010, 12:32am »

Peter,
Yes, this would be great:

EXEC("command", [stdin [, returnvalue]])

Yes, by return value I mean the integer numeric return status when an application exits, which in Bash you get with $?.

But you are mostly likely to need returnvalue, so this would perhaps be better:

EXEC("command" [,returnvalue [,stdin]])

Adding both of these to EXEC would make it so powerful.

The stdin gives us a mechanism to feed some value into the shell from the BaCon application.

Another thing that would be nice, but this is probably asking too much, is if the "command" string could be made to recognise BaCon variables. For example:

EXEC("demoapp ${variable1}")

where variable1 is an actual variable in BaCon.

...maybe that is too hard though, as it might require run-time evaluation of the command string. Well, I suppose BaCon could be made to recognise the special syntax "${variable1}" and perform a runtime substitution.

The reason that I request all of these enhancements to EXEC is that I am so familiar with Bash/Ash and when coding in a high-level language I can often see how to solve a particular task very quickly in one line of Bash, whereas it is not so easy for me in that high-level language.

So, all the enhancements requested above would make the insertion of shell code into the BaCon program very powerful.

Regards,
Barry Kauler
Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Re: Feature requests
« Reply #4 on Nov 15, 2010, 12:38am »

If you mean this returnvalue, what would be the returnvalue of a string like: EXEC("ls -l; cd /tmp; rm *.*") ? Would we see the returnvalue of the 'rm' as this one is executed last?

Yes, exactly as if you did it in Bash:

ls -l; cd /tmp; rm *.*
echo $?

...whatever return-value the command string finishes with.
Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

Joined: Apr 2010
Gender: Male
Posts: 938
Location: The Hague, The Netherlands
Karma: 9
 Re: Feature requests
« Reply #5 on Nov 15, 2010, 1:38am »

Thanks Barry, understood it all now.

Currently I have a prototype running for the BREAK [x] request, but I want to do more testing before uploading it to the BETA directory.

If this works then CONTINUE [x] will be easy.

(BTW I only know these commands with argument from Shell scripting, none of the BASIC's I have worked with in the past supports them, as far as I remember. But they are handy for sure!)

The EXEC$ argument order can of course change to first STDIN and then returnvalue.

I'll post here when I have your requests ready.

Regards
Peter
Link to Post - Back to Top  IP: Logged
vovchik
Senior Member
****
member is offline





Joined: Apr 2010
Gender: Male
Posts: 360
Karma: 6
 Re: Feature requests
« Reply #6 on Nov 15, 2010, 10:27am »

Dear Barry,

To use a BaCon var with the the EXEC$ command, you can always do it the "long" way:

mydir$ = "/tmp"
mycmd$ = CONCAT$("ls -l", $mydir)
myresult$ = EXEC$(mycmd$)

Not as convenient as you are suggesting, but I use it all the time and it works nicely.

The BREAK/CONTINUE and stdin/returncode business for EXEC$ do appear to be useful. Peter has knack for being able to implement the seemingly impossible! :)

With kind regards,
vovchik
« Last Edit: Nov 15, 2010, 10:30am by vovchik »Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Re: Feature requests
« Reply #7 on Nov 16, 2010, 8:47am »

(BTW I only know these commands with argument from Shell scripting, none of the BASIC's I have worked with in the past supports them, as far as I remember. But they are handy for sure!)

...I mentioned freeBASIC, but they do it with their own unusual syntax.

There is one other I know of that does it exactly as in Bash: PureBasic:

http://www.purebasic.com/documentation/reference/break_continue.html

...but notice, they only do it for BREAK, not for CONTINUE.

Link to Post - Back to Top  IP: Logged
barryk
Junior Member
**
member is offline





Joined: May 2010
Gender: Male
Posts: 79
Karma: 0
 Re: Feature requests
« Reply #8 on Nov 16, 2010, 9:21am »

Gambas has an interesting implementation of EXEC, that does stdin and stdout:

http://gambasdoc.org/help/lang/exec

...looks pretty good.

RealBasic also allows exiting from nested loops, but the implementation is even more complicated than freeBASIC:

http://docs.realsoftware.com/index.php/Exit

Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

Joined: Apr 2010
Gender: Male
Posts: 938
Location: The Hague, The Netherlands
Karma: 9
 Re: Feature requests
« Reply #9 on Nov 16, 2010, 11:56am »

Thanks Barry, now I see why I never encountered these commands before, as indeed I never used PureBasic. Nor Gambas or RealBasic :)

Anyway, I have BREAK [x] and CONTINUE [x] ready now.

If you have time, can you check the latest BETA and let me know if this is what you have in mind?

I'll look into EXEC now.

Regards
Peter
Link to Post - Back to Top  IP: Logged
Pjot
Administrator
*****
member is offline

[avatar]

[icq]
[homepage]

Joined: Apr 2010
Gender: Male
Posts: 938
Location: The Hague, The Netherlands
Karma: 9
 Re: Feature requests
« Reply #10 on Nov 18, 2010, 7:58am »

So EXEC$ is on its way - the STDIN part is ready, it took a little bit more time than I expected.

The returnvalue of a child process is still not there because one simply cannot pass a variablename as argument to a function, as C does not do runtime conversion of memory buffers.

Therefore, I was thinking of assigning a reserved variable for the returnvalue of the last command which was executed (both by SYSTEM or EXEC$), similarly to BASH. For example, simply the variable RV, or something like that.

Anyway, now EXEC$ has an optional second argument which can be the feed to STDIN of the command executed in the shell. So for now the syntax is:

a$ = EXEC$("command" [, "stdin"])

I have tested this with the 'bc' calculator language, as follows:

Code:
result$ = EXEC$("bc", "12+4\nquit")
PRINT result$

' Or as follows:

result$ = EXEC$("bc", CONCAT$("12+4", NL$, "quit"))
PRINT result$


This should calculate 12 added with 4 and will show 16. As usual the latest can be found in the BETA directory.

Regards
Peter
« Last Edit: Nov 18, 2010, 7:59am by Pjot »Link to Post - Back to Top  IP: Logged
   [Search This Thread] [Share Topic] [Print]

Click Here To Make This Board Ad-Free


This Board Hosted For FREE By ProBoards
Get Your Own Free Message Boards & Free Forums!
Terms of Service | Privacy Policy | Notice | FTC Disclosure | Report Abuse | Mobile