pkg/ubasic: add support for BASIC's "shell" statement. #11349
pkg/ubasic: add support for BASIC's "shell" statement. #11349jcarrano wants to merge 15 commits intoRIOT-OS:masterfrom
Conversation
Make procedure more reusable
Add ubasic_tests module
This is a quick and dirty solution to have something to test the system() standard function.
The system() function is standard in C99. It should invoke a system command. BUGS: this implementation ignores the return value.
"shell" invokes C's system() function wich in riot (if shell_commands is enabled) invokes a shell command.
Can you give a ref for that? "basic shell statement" is a bit frustrating to google... |
Well, to be honest, I'm not very sure of what I did. There are many BASIC dialects (uBASIC being one of them), but several seem to have a shell command that takes a single string as an argument and executes it in a sub-process using the system shell. |
|
I updated the description with reference to other dialects' |
|
I updated the description with reference to other dialects' shell.
Thank you!
|
miri64
left a comment
There was a problem hiding this comment.
There are some dependency issues in this PR, which we should rather discuss seperately.
| return 0; | ||
| } | ||
|
|
||
| int _echo_handler(int argc, char **argv) |
There was a problem hiding this comment.
Also, I noticed today, that this somewhat clashes with a task in our tutorials
|
|
||
| #ifdef MODULE_SHELL_COMMANDS | ||
| /* Provide standard system() function */ | ||
| int system(const char *command) |
There was a problem hiding this comment.
This as well.
Also I think this rather belongs into the POSIX module and shell_commands shouldn't be a dependency.
There was a problem hiding this comment.
This should have its own PR. I would not put it under POSIX, since system() is C99/C89 and placing it is the easiest way to make sure system() is tied to shell_commands.
There was a problem hiding this comment.
since system() is C99/C89 and placing it is the easiest way to make sure system() is tied to shell_commands.
You can have shell commands without having the module shell_commands (which provides a number of default shell commands), so I don't understand the requirement for shell_commands.
There was a problem hiding this comment.
I you don't have shell_commands, then you don't have access to any command from within system(), Because you have no way for your application to communicate a custom command list:
Lines 54 to 62 in 200c465
Nothing will break, but no commands will be available.
In 2038, when we finally get XFAs, this won't be an issue (if we survive the UNIX timestamp overflow)
There was a problem hiding this comment.
I you don't have shell_commands, then you don't have access to any command from within
system()
Well, that seems to be more of an issue of the current implementation. So I see it as premature to establish a dependency that in reality should not be there (I would expect e.g. system("udp …") to work if I call it with gnrc_networking.
In 2038, when we finally get XFAs, this won't be an issue (if we survive the UNIX timestamp overflow)
ztimer will handle the latter. ;-)
|
|
||
| strncpy(tmpstring, command, len+1); | ||
|
|
||
| handle_input_line(_shell_command_list, tmpstring); |
There was a problem hiding this comment.
I should have used NULL here, since the _shell_command_list is going to be searched anyways.
| handle_input_line(_shell_command_list, tmpstring); | |
| handle_input_line(NULL, tmpstring); |
|
|
||
| #ifdef MODULE_SHELL_COMMANDS | ||
| /* Provide standard system() function */ | ||
| int system(const char *command) |
There was a problem hiding this comment.
I you don't have shell_commands, then you don't have access to any command from within system(), Because you have no way for your application to communicate a custom command list:
Lines 54 to 62 in 200c465
Nothing will break, but no commands will be available.
In 2038, when we finally get XFAs, this won't be an issue (if we survive the UNIX timestamp overflow)
|
Needs rebase and split-up. |
|
@miri64 Maybe we can leave the echo commit out (i.e. not even PR it). The only reason I put it there was to be able to have at least one command to test (otherwise the only command available by default is "reboot"). The thing is, because of the way the shell works it not easy or practical to make the application specific commands available to The result of all this is that it makes testing this feature harder. |
|
Couldn't the |
|
@miri64 yes, that goes along the lines of what I was proposing in #9258, which is to allow choosing which system functionality (I will try to avoid calling them "system calls" because in RIOT they are not) are provided and to allow choosing an implementation. The first question, then, is: do we want 'system()'. I think yes because it is in the standard and because it is useful. |
I'm not against it. |
Then I'll make a PR just for that. |
|
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. If you want me to ignore this issue, please mark it with the "State: don't stale" label. Thank you for your contributions. |
Contribution description
A joke can go wrong when people don't understand it, and it can wronger if they take it seriously...
This commit is based on #11319 and adds support for the "shell" statement. In BASIC, this is supposed to call a system command:
I used "system()" to implement it. For more information regarding
shellin other BASIC dialects, see:Testing procedure
Run the test. Test case no.3 takes ages in a board (I tested samr21) so you can use the following patch to disable it (place it under
pkg/ubasic/patches).0006-remove-me-relax-test-2.patchSide notes.
The modifications to ubasic were unexpectedly easy. I spent most of the time figuring out how to get system() running in RIOT. One of the biggest issues I had was that at some point I added a main.c to the test application and afterwards remove it, bit the main.o was still there messing up the symbols!!!
Issues/PRs references
Depends (and extends) #11319 .