atua-www: use new style code blocks

FossilOrigin-Name: f99ab6924d76816143676d58239db96bd3f743384ac21d7832bb7ef162298f65
This commit is contained in:
crc 2018-03-24 13:58:13 +00:00
parent d786dd0704
commit cba750a54d

View file

@ -34,12 +34,12 @@ Atua needs to know:
- The maximum length of a selector
- The maximum file size
````
~~~
'/home/crc/atua 'PATH s:const
'/gophermap 'DEFAULT-INDEX s:const
#1024 'MAX-SELECTOR-LENGTH const
#65535 #8 * 'MAX-FILE-SIZE const
````
~~~
# I/O Words
@ -52,9 +52,9 @@ and provide some other helpers.
The Gopher protocol uses tabs and cr/lf for signficant things. To aid
in this, I define output words for tabs and end of line.
````
~~~
:eol (-) ASCII:CR putc ASCII:LF putc ;
````
~~~
*Console Input*
@ -62,72 +62,72 @@ Input lines end with a cr, lf, or tab. The `eol?` checks for this.
The `gets` word could easily be made more generic in terms of what
it checks for. This suffices for a Gopher server though.
````
~~~
:eol? (c-f)
[ ASCII:CR eq? ] [ ASCII:LF eq? ] [ ASCII:SPACE eq? ] tri or or ;
:gets (a-)
buffer:set
[ getc dup buffer:add eol? not ] while ;
````
~~~
# An HTML Namespace
````
~~~
:html:tt (q-) '<tt> puts call '</tt> puts ;
:html:br (-) '<br> puts ;
````
~~~
# Gopher Namespace
Atua uses a `gopher:` namespace to group the server related words.
````
~~~
{{
````
~~~
First up are buffers for the selector string and the file buffer. The
variables and buffers are kept private.
````
~~~
'Selector d:create
MAX-SELECTOR-LENGTH n:inc allot
:buffer here ;
````
~~~
Next up, variables to track information related to the requested
selector. Atua will construct filenames based on these.
````
~~~
'Requested-File var
'Requested-Index var
````
~~~
`FID`, the file id, tracks the open file handle that Atua uses
when reading in a file. The `Size` variable will hold the size of
the file (in bytes).
````
~~~
'FID var
'Size var
'Mode var
````
~~~
I use a `Server-Info` variable to decide whether or not to display
the index footer. This will become a configurable option in the
future.
````
~~~
'Server-Info var
````
~~~
These are just simple accessor words to aid in overall readability.
````
~~~
:requested-file (-s) @Requested-File ;
:requested-index (-s) @Requested-Index ;
````
~~~
````
~~~
:get-mime-type (s-s)
[ $. s:index-of ] sip +
(textual_files)
@ -185,16 +185,16 @@ These are just simple accessor words to aid in overall readability.
'.js [ 'application/x-javascript ] s:case
'.xml [ 'application/xml ] s:case
drop 'text/plain ;
````
~~~
````
~~~
:with-path (-s)
PATH &Selector s:chop s:append ;
:construct-filenames (-)
with-path s:keep !Requested-File
with-path '/gophermap s:append s:keep !Requested-Index
;
````
~~~
A *gophermap* is a file that makes it easier to handle Gopher menus.
Atua's gophermap support covers:
@ -209,7 +209,7 @@ Atua's gophermap support covers:
Any line with a tab is treated as a selector line and is transferred
without changing.
````
~~~
'Tab var
:eol? [ ASCII:LF eq? ] [ ASCII:CR eq? ] bi or ;
:tab? @Tab ;
@ -221,14 +221,14 @@ Atua's gophermap support covers:
[ @FID file:read dup buffer:add check-tab eol? not ] while
buffer:get drop
;
````
~~~
The internal helpers are now defined, so switch to the part of the
namespace that'll be left exposed to the world.
````
~~~
---reveal---
````
~~~
An information line gets a format like:
@ -237,14 +237,14 @@ An information line gets a format like:
The `gopher:i` displays a string in this format. It's used later for
the index footer.
````
~~~
:gopher:i (s-)
[ puts ] html:tt html:br eol ;
````
~~~
The `gopher:icon` displays an indicator for menu items.
````
~~~
:gopher:icon
$0 [ '&nbsp;TXT&nbsp;&nbsp; puts ] case
$1 [ '[DIR]_ puts ] case
@ -262,9 +262,9 @@ The `gopher:icon` displays an indicator for menu items.
$h [ '&nbsp;HTM&nbsp;&nbsp; puts ] case
drop '&nbsp;???&nbsp;&nbsp; puts
;
````
~~~
````
~~~
:gopher:get-selector (-)
&Selector gets &Selector gets ;
(Rewrite_This:_It's_too_big)
@ -291,9 +291,9 @@ The `gopher:icon` displays an indicator for menu items.
@FID file:close
buffer
;
````
~~~
````
~~~
:link
dup fetch $h eq? push
dup fetch gopher:icon n:inc
@ -320,48 +320,41 @@ The `gopher:icon` displays an indicator for menu items.
'forthworks.com:80_/_atua-www_/_running_on_retro gopher:i
'</p></body></html> puts
;
````
~~~
In a prior version of this I used `puts` to send the content. That
stopped at the first zero value, which kept it from working with
binary data. I added `gopher:send` to send the `Size` number of
bytes to stdout, fixing this issue.
````
~~~
:gopher:send (p-)
requested-file get-mime-type 'Content-type:_ puts puts eol eol
@Size [ fetch-next putc ] times drop ;
````
~~~
The only thing left is the top level server.
````
~~~
:gopher:server
gopher:get-selector
'HTTP/1.0_200_OK puts eol
gopher:file-for-request
@Server-Info
[ gopher:generate-index
````
'<tt> puts
'<a_href="http://forthworks.com:8888 puts &Selector s:chop puts '">Light_on_Dark</a>_or_ puts
'<a_href="http://forthworks.com:80 puts &Selector s:chop puts '">Dark_on_Light</a> puts
'</tt> puts
````
]
[ gopher:generate-index ]
[ gopher:read-file gopher:send ] choose
;
````
~~~
Close off the helper portion of the namespace.
````
~~~
}}
````
~~~
And run the `gopher:server`.
````
~~~
gopher:server
reset
````
~~~