retroforth/example/gopher.forth
crc 7b9d31e65f add gopher:get as an example (using curl)
FossilOrigin-Name: 6253025375089084436e290e6f6727fd379b6b7517d01f0dbc257a283e924e64
2019-05-10 19:56:13 +00:00

37 lines
909 B
Forth

gopher:get
Data: asns-n
Addr: -
Float: -
Takes an address, a server, a port, and a selector. Fetch the
resource and store it at address. Return the number of bytes
received.
Class: class:word | Namespace: gopher | Interface Layer: ios
Example #1:
here 'forthworks.com #70 '/ gopher:get
here s:put
~~~
:set (asns-sns) 'abcd 'bcda reorder buffer:set ;
:url (sns-s) 'abc 'cba reorder 'gopher://%s:%n/0%s s:format ;
:command (s-s) 'curl_-s_%s s:format ;
:connect (s-p) file:R unix:popen ;
:read (p-p) [ dup file:read dup buffer:add n:zero? ] until ;
:complete (p-n) unix:pclose buffer:end buffer:start - ;
---reveal---
:gopher:get (asns-n)
[ set url command connect read complete ] buffer:preserve ;
~~~
## Test Case
~~~
'Data d:create #256001 allot
&Data 'forthworks.com #70 '/retro gopher:get
'%n_bytes_read\n s:format s:put
~~~