Fran�ois Van Emelen writes:
> 100 rem macro_bas
> 110 REMark example of substitution /VAL
> 120 res1$="res1$=" :res2$="res2$=" :REMark res1$ string res2$ num
> 130 L1$='(' :R1$=")": f1$='upper$': string1$="'qdos'"
> 140 num1$="20":num2$="5":f2$="*"
> 150 OPEN_OVER#3,ram1_mac_do
> 160 PRINT#3,res1$&f1$&l1$&string1$&r1$
> 170 PRINT#3,res2$&num1$&f2$&num2$
> 180 CLOSE#3
> 190 DO 'ram1_mac_do'
> 200 PRINT res1$,res2$
> 210 rem lines 200 ... are not executed
> 220 rem because ram1_mac_do doesn't return to mac_bas but to job
> 225 rem 0/command line
> 230 rem type 'print res1$,res2$ on the command line
> 235 rem and 'QDOS', '200' will be displayed
This was the sort devious stuff one was expected to do in Archive. In
SuperBasic it is easiest just to MERGE or MRUN the code. Why go to all this
trouble?
SBasic has other possibilities in that you can run separate SBasics as a
slaves to a master program (SBasic or other). Heres an example program (this
is just a more general version of Marcel's program), just so you can test
the principle. Much more advanced things can be achieved with a little
effort:
100 REMark Get an SBASIC job to work as
110 REMark a slave of another SBASIC.
120 REMark Full programmable interpreter
130 REMark via PRINT statements!
140 REMark By pjwitte January 23rd 2001
150 :
160 REMark Init
170 ch = 1: cu = 0: CLS#ch: CLS#cu
180 pip$ = 'pipe_p' & HEX$(DATE,32)
190 :
200 REMark Plumb in SBAS slave
210 co = FOPEN(pip$ & 'o_2048')
220 ERT co
230 REMark lrun our command stream
240 cm$ = 'lrun "' & pip$ & 'o_1024"'
250 REMark Start SBAS with command
260 EXEP 'SBASIC'; cm$
270 REMark We control command channel
280 PRINT#co; 'ch = fopen(#0;"' & pip$ & 'i_64")'
290 REMark Messages come out here
300 ci = FOP_IN(pip$ & 'i'): IF ci < 0: CLOSE
310 ERT ci
320 :
330 REMark Add some tools (abbreviated here)
340 LIST#co; 1000 TO
350 :
360 REMark Test
370 PRINT#co; 'echo "Hello": beep 2000, 2'
380 IF Answer < 0: CLOSE: STOP
390 :
400 REMark Torment!
410 REPeat sb
420 INPUT#cu; '>'! cm$
430 IF cm$ = '' OR cm$ == 'quit': EXIT sb
440 PRINT#co; cm$
450 IF Answer < 0: EXIT sb
460 END REPeat sb
470 PRINT#co; 'beep 2000, 2: quit'
480 CLOSE
490 :
500 DEFine FuNction Answer
510 ans% = 0
520 REPeat il
530 k$ = INKEY$(#ci; 20)
540 IF LEN(k$) = 0: EXIT il
550 INPUT#ci; l$: echo k$ & l$
560 ans% = 1
570 END REPeat il
580 IF EOF(#ci): ans% = -10
590 IF ans% = 0: echo 'no answer'
600 IF ans% < 0: echo 'Slave died'
610 RETurn ans%
620 END DEFine
630 :
1000 DEFine PROCedure echo(t$)
1010 PRINT#ch; t$
1020 END DEFine
1030 :
Once this program runs you can type your commands in at the > prompt, eg
> print 3 + 2
answer: 5
or
> a=3
> b=3
> echo a+b
answer as expected. The problem is that it is too easy to crash the slave
job in which case it just dies and you have to set up a new one:
> ert -3
answer: insufficient memory. Slave died
The error could be as simple as a syntax error, eg
> prt 5
At least you get an error message which can be passed on to the master
program.
This technique could be used to add SBasic scripting to our (future) web
browser ;)
Per