I just need the code
Bash emulator
Root / Programming Questions / [.]
funcooldudes101Created:
Im making a sb bash emulator and i want to replicate DIRECT mode... How do i do that so i can use all of the sb commands in a bash emulator?
This is too broad of a question, and not a trivial problem. If you are really wanting to emulate bash, you'll need to write a compiler, and even a simple compiler will require a parser, lexer, and a way to validate syntax. Not simple at all. If you just want to allow a user to type out commands, and then execute them, and you aren't worried about supporting all of bash's built in's. You could do something like the following (all though, if you are just starting out with SB this might be a bit too ambitious):
In PRG slot 0:
VAR CODE$="" @INPUT_START INPUT "BASH: ",CODE$ PRGEDIT 1, 2 PRGSET CODE$ USE 1 EXEC_CODE GOTO @INPUT_STARTIn PRG slot 1:
COMMON DEF EXEC_CODE ENDThe way this works is that, the input you capture from the user is stored in a variable called CODE$, we then write that string into the PRG 1 slot at line 2 (the one to the right of the EDIT button on your keyboard). If you typed the second code snippet into the PRG 1 slot, exactly, you will have a common function, EXEC_CODE, that can be called from slot 0 that contains your input. Finally we call that function, which should execute the string. Try sorting this out first, and then if you have questions let me know.
This is too broad of a question, and not a trivial problem. If you are really wanting to emulate bash, you'll need to write a compiler, and even a simple compiler will require a parser, lexer, and a way to validate syntax. Not simple at all. If you just want to allow a user to type out commands, and then execute them, and you aren't worried about supporting all of bash's built in's. You could do something like the following (all though, if you are just starting out with SB this might be a bit too ambitious): In PRG slot 0:Ok thanks!VAR CODE$="" @INPUT_START INPUT "BASH: ",CODE$ PRGEDIT 1, 2 PRGSET CODE$ USE 1 EXEC_CODE GOTO @INPUT_STARTIn PRG slot 1:COMMON DEF EXEC_CODE ENDThe way this works is that, the input you capture from the user is stored in a variable called CODE$, we then write that string into the PRG 1 slot at line 2 (the one to the right of the EDIT button on your keyboard). If you typed the second code snippet into the PRG 1 slot, exactly, you will have a common function, EXEC_CODE, that can be called from slot 0 that contains your input. Finally we call that function, which should execute the string. Try sorting this out first, and then if you have questions let me know.