2017-10-20 05:05:43 +02:00
|
|
|
# RETRO
|
|
|
|
|
|
|
|
This is a set of extensions for RRE.
|
|
|
|
|
|
|
|
# Console Input
|
|
|
|
|
|
|
|
~~~
|
2018-11-22 05:32:11 +01:00
|
|
|
:c:get (-c) as{ 'liii.... i #1 d }as ;
|
2017-10-20 05:05:43 +02:00
|
|
|
~~~
|
|
|
|
|
|
|
|
---------------------------------------------------------------
|
|
|
|
|
2018-11-18 22:27:40 +01:00
|
|
|
---------------------------------------------------------------
|
|
|
|
|
2017-10-20 05:05:43 +02:00
|
|
|
# Scripting: Command Line Arguments
|
|
|
|
|
2017-10-20 03:16:46 +02:00
|
|
|
~~~
|
|
|
|
:sys:argc (-n) `-6100 ;
|
|
|
|
:sys:argv (n-s) s:empty swap `-6101 ;
|
|
|
|
~~~
|
|
|
|
|
2017-11-04 15:23:49 +01:00
|
|
|
# System Interaction
|
|
|
|
|
2017-11-04 22:22:36 +01:00
|
|
|
The `unix:` namespace contains words for interacting with the
|
|
|
|
host operating system.
|
|
|
|
|
2017-11-05 03:46:38 +01:00
|
|
|
`unix:system` runs another application using the system shell
|
|
|
|
and returns after execution is completed.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:system (s-) #-8000 `-6300 ;
|
2017-11-05 03:46:38 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
`unix:fork` forks the current process and returns a process
|
|
|
|
identifier.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:fork (-n) #-8001 `-6300 ;
|
2017-11-05 03:46:38 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
`unix:exit` takes a return code and exits RRE, returning the
|
|
|
|
specified code.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:exit (n-) #-8002 `-6300 ;
|
2017-11-05 03:46:38 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
`unix:getpid` returns the current process identifier.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:getpid (-n) #-8003 `-6300 ;
|
2017-11-05 03:46:38 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
This group is used to execute a new process in place of the
|
|
|
|
current one. These take a program and optionally 1-3 arguments.
|
|
|
|
They map to the execl() system call.
|
|
|
|
|
|
|
|
Example:
|
|
|
|
|
|
|
|
'/usr/bin/cal '2 '2019 unix:exec2
|
|
|
|
|
2017-11-04 15:23:49 +01:00
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:exec0 (s-) #-8004 `-6300 ;
|
|
|
|
:unix:exec1 (ss-) #-8005 `-6300 ;
|
|
|
|
:unix:exec2 (sss-) #-8006 `-6300 ;
|
|
|
|
:unix:exec3 (ssss-) #-8007 `-6300 ;
|
2017-11-04 15:23:49 +01:00
|
|
|
~~~
|
|
|
|
|
2017-11-05 03:46:38 +01:00
|
|
|
`unix:wait` waits for a child process to complete. This maps to
|
|
|
|
the wait() system call.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:wait (-n) #-8008 `-6300 ;
|
2017-11-05 03:46:38 +01:00
|
|
|
~~~
|
|
|
|
|
2017-11-05 03:51:13 +01:00
|
|
|
`unix:kill` terminates a process. Takes a process and a signal
|
|
|
|
to send.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:kill (nn-) #-8009 `-6300 ;
|
2017-11-05 03:51:13 +01:00
|
|
|
~~~
|
|
|
|
|
2017-11-19 16:08:58 +01:00
|
|
|
The next two words allow opening and closing pipes. The first,
|
|
|
|
`unix:popen` takes the name of a program and a file mode and
|
|
|
|
returns a file handle usable with words in the `file:` namespace.
|
|
|
|
The second, `unix:pclose` closes the pipe.
|
|
|
|
|
2017-11-05 22:52:49 +01:00
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:popen (sn-n) #-8010 `-6300 ;
|
|
|
|
:unix:pclose (n-) #-8011 `-6300 ;
|
2017-11-05 22:52:49 +01:00
|
|
|
~~~
|
|
|
|
|
2017-11-09 18:59:04 +01:00
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:write (sh-) [ dup s:length ] dip #-8012 `-6300 ;
|
2017-11-19 16:08:58 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
`unix:chdir` changes the current working directory to the
|
|
|
|
specified one.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:chdir (s-) #-8013 `-6300 ;
|
2017-11-19 16:08:58 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:getenv (sa-) #-8014 `-6300 ;
|
|
|
|
:unix:putenv (s-) #-8015 `-6300 ;
|
2017-11-19 16:08:58 +01:00
|
|
|
~~~
|
|
|
|
|
|
|
|
`unix:sleep` pauses execution for the specified number of
|
|
|
|
seconds.
|
|
|
|
|
|
|
|
~~~
|
2018-01-09 15:47:13 +01:00
|
|
|
:unix:sleep (n-) #-8016 `-6300 ;
|
2017-11-09 18:59:04 +01:00
|
|
|
~~~
|
|
|
|
|
2017-10-20 05:05:43 +02:00
|
|
|
---------------------------------------------------------------
|
|
|
|
|
2018-02-16 21:26:13 +01:00
|
|
|
~~~
|
2018-05-07 18:24:36 +02:00
|
|
|
:unix:io:n:put (n-) #-8100 `-6300 ;
|
|
|
|
:unix:io:s:put (s-) #-8101 `-6300 ;
|
2018-02-16 21:26:13 +01:00
|
|
|
~~~
|
|
|
|
|
2017-11-15 20:57:17 +01:00
|
|
|
# Interactive Listener
|
|
|
|
|
|
|
|
~~~
|
2018-11-14 14:52:30 +01:00
|
|
|
'NoEcho var
|
2017-11-15 20:57:17 +01:00
|
|
|
|
|
|
|
{{
|
2018-05-07 18:24:36 +02:00
|
|
|
:version (-) @Version #100 /mod n:put $. c:put n:put ;
|
2017-11-15 20:57:17 +01:00
|
|
|
:eol? (c-f) [ ASCII:CR eq? ] [ ASCII:LF eq? ] [ ASCII:SPACE eq? ] tri or or ;
|
|
|
|
:valid? (s-sf) dup s:length n:-zero? ;
|
2018-11-14 14:52:30 +01:00
|
|
|
:ok (-) @NoEcho not 0; drop compiling? [ nl 'Ok_ s:put ] -if ;
|
2017-11-26 16:20:56 +01:00
|
|
|
:check-eof (c-c) dup [ #-1 eq? ] [ #4 eq? ] bi or [ 'bye d:lookup d:xt fetch call ] if ;
|
2018-04-03 22:45:55 +02:00
|
|
|
:check-bs (c-c) dup [ #8 eq? ] [ #127 eq? ] bi or [ buffer:get buffer:get drop-pair ] if ;
|
2018-05-07 18:24:36 +02:00
|
|
|
:s:get (-s) [ #1025 buffer:set
|
|
|
|
[ c:get dup buffer:add check-eof check-bs eol? ] until
|
|
|
|
buffer:start s:chop ] buffer:preserve ;
|
2017-11-15 20:57:17 +01:00
|
|
|
---reveal---
|
2018-11-14 14:52:30 +01:00
|
|
|
:banner (-) @NoEcho not 0; drop
|
|
|
|
'RETRO_12_(rx- s:put version $) c:put nl
|
2018-05-07 18:24:36 +02:00
|
|
|
EOM n:put '_MAX,_TIB_@_1025,_Heap_@_ s:put here n:put nl ;
|
2018-04-04 18:11:44 +02:00
|
|
|
:bye (-) #0 unix:exit ;
|
2017-11-15 20:57:17 +01:00
|
|
|
:listen (-)
|
2018-05-07 18:24:36 +02:00
|
|
|
ok repeat s:get valid? [ interpret ok ] [ drop ] choose again ;
|
2017-11-15 20:57:17 +01:00
|
|
|
}}
|
|
|
|
~~~
|
2017-11-27 22:53:51 +01:00
|
|
|
|
|
|
|
~~~
|
|
|
|
:include (s-) `-9999 ;
|
|
|
|
~~~
|
2017-12-01 03:17:11 +01:00
|
|
|
|
|
|
|
~~~
|
|
|
|
{{
|
2017-12-01 03:23:12 +01:00
|
|
|
:gather (c-)
|
|
|
|
dup [ #8 eq? ] [ #127 eq? ] bi or [ drop ] [ buffer:add ] choose ;
|
2018-05-07 18:24:36 +02:00
|
|
|
:cycle (q-qc) repeat c:get dup-pair swap call not 0; drop gather again ;
|
2017-12-01 03:17:11 +01:00
|
|
|
---reveal---
|
|
|
|
:parse-until (q-s)
|
|
|
|
[ s:empty buffer:set cycle drop-pair buffer:start ] buffer:preserve ;
|
|
|
|
}}
|
|
|
|
|
2018-05-07 18:24:36 +02:00
|
|
|
:s:get (-s) [ [ ASCII:LF eq? ] [ ASCII:CR eq? ] bi or ] parse-until ;
|
2017-12-01 03:17:11 +01:00
|
|
|
~~~
|
|
|
|
|