\ usage: generate commands and pipe them into "gforth-0.7.0 dumbsh.fs" \ the commands are of the form s" echo\0a\0\0echo\0b", i.e., each \ argument is 0-terminated, and the whole command is terminated with \ an empty zero-terminated string. Yes, that means you cannot pass \ empty aruments. Hmm. require cstr.fs c-library dumbsh \c #include \c #include \c #include \c #include c-function execvp execvp a a -- n c-function fork fork -- n c-function wait wait a -- n \c #define IOR(flag) ((flag)? -512-errno : 0) c-function f>ior IOR n -- n ( f -- ior ) end-c-library variable wait-status 1 [if] \ debugging : ztype ( c-addr -- ) dup 1000 0 scan drop over - type ; : printcommand ( addr -- ) begin dup @ dup while ztype space cell+ repeat 2drop cr ; [endif] : mysystem ( addr -- ) \ dup printcommand fork dup -1 = if f>ior throw endif if \ parent drop 0 wait drop else \ child dup @ swap execvp f>ior throw endif ; : advance ( c-addr1 u1 -- c-addr2 u2 ) \ skip one char if present dup if 1 /string endif ; : get-command1 ( c-addr1 u1 -- c-addr2 u2 addr ) \ the blocks are the rest of the input before and after getting \ the command, addr is the array containing the command strings align here >r begin dup while over c@ 0<> while over , 0 scan advance repeat then 0 , \ terminating pointer advance \ past empty string r> dup dp ! ; : get-command ( c-addr1 u1 -- c-addr2 u2 addr ) \ catch some boundary conditions of get-command1 begin get-command1 dup @ if exit endif drop dup 0= if \ end of file 0 exit endif again ; : main ( -- ) stdin slurp-fid begin get-command dup while mysystem repeat drop 2drop ; main bye