;support for multiple-file streams 11/6/04 ;"string" MSSCAN - searches for "string" in MS input stream, ;up until ascii 128 character. If found, pushes a 1 and leaves ;MS positioned to next character after target, otherwise pushes 0. "Loading MSSCAN" $PRINT CRLF OCTAL DEFINE MSSCAN #0 ;success/fail flag #0 ;mode - 0=looking for 1st occ, 1=matching subsequent $DUP ;match string, when empty match is made $HEAD ;start by looking for first char DO ;until done MSBIN ;get one byte from MS input DUP 200 SUB IFZ ;if ascii 128 then DROP ;the ms in char DROP ;the char being matched DROP ;the mode ;leave 0 on stack #1 ;we're done ELSE ;not an ascii 128, try to match... OVER SUB IFNZ ;(drop char) if no match then OVER IFZ ;if mode 0 #0 ;just keep going ELSE ;if partial match gone bad DROP DROP ;match char and mode #0 ;back to mode 0 $DROP $DUP $HEAD ;start it again #0 ;keep going ENDIF ELSE ;finally a match! DROP DROP ;the match char and mode $LEN ;of emptying match string IFZ ;if successful match DROP #1 ;change to success #1 ;and exit ELSE #1 ;mode 1, match successive chars $HEAD ;next char to match #0 ;keep going ENDIF ENDIF ENDIF UNTIL ;done $DROP $DROP ;strings END ; ;RUN&DEL - execute word in string on X stack then delete it "Loading RUN&DEL" $PRINT CRLF DEFINE RUN&DEL $DEFADR DUP IFZ "Word not found" $PRINT DROP ELSE DUP EXECUTE ;run it 4 SUB #0 PUT ;delete it CRLF ;to make it look neat ENDIF END ; ;The main show.. "file" LIBLOAD searches for the specified ;file then loads it, the file itself determines how it behaves. "Loading LIBLOAD" $PRINT CRLF DEFINE LIBLOAD ";;;FILE:" $SWAP $CAT ":" $CAT MSSCAN IFZ "Not found" $PRINT ELSE LOAD ENDIF END ; ;now test it... "TESTRUN" LIBLOAD ;should print It worked! ;at this point you should be able to "TESTLOAD" LIBLOAD ;to define the word TEST CONSOLE ; ;;;FILE:TESTRUN: "TESTWORD" ;immediate string-push name DEFINE TESTWORD "It worked!" $PRINT END RUN&DEL ;run and delete "TESTWORD" CONSOLE ; ;;;FILE:TESTLOAD: ;conventional file DEFINE TEST "Blablabla" $PRINT END CONSOLE ۂ