]> gitweb.factorcode.org Git - factor.git/commitdiff
html-tags imported, file responder shows icons
authorSlava Pestov <slava@factorcode.org>
Thu, 2 Sep 2004 23:38:05 +0000 (23:38 +0000)
committerSlava Pestov <slava@factorcode.org>
Thu, 2 Sep 2004 23:38:05 +0000 (23:38 +0000)
25 files changed:
TODO.FACTOR.txt
factor/FactorLib.java
factor/jedit/FactorPlugin.java
library/httpd/default-responders.factor
library/httpd/file-responder.factor
library/httpd/html-tags.factor [new file with mode: 0644]
library/httpd/html.factor
library/httpd/http-common.factor
library/httpd/resource-responder.factor [new file with mode: 0644]
library/httpd/responder.factor
library/httpd/wiki-responder.factor
library/platform/jvm/boot-sumo.factor
library/platform/jvm/init.factor
library/platform/native/boot-stage2.factor
library/platform/native/init-stage2.factor
library/platform/native/init.factor
library/platform/native/io-internals.factor
library/platform/native/stream.factor
library/strings.factor
library/styles.factor
library/test/httpd/html.factor
library/test/httpd/httpd.factor
library/test/httpd/url-encoding.factor
library/vocabularies.factor
library/vocabulary-style.factor

index 031f4955a6476e69808afee086059b45047f3270..3b2515ca93748a7f1ff38cca6411d3a32a3caf10 100644 (file)
@@ -1,7 +1,6 @@
-- TEST telnetd should use multitasking\r
+- move <resource-stream> from parser\r
 - quit responder breaks with multithreading\r
 - nicer way to combine two paths\r
-- icons for file responder\r
 - -1.1 3 ^ shouldn't give a complex number\r
 - don't show listener on certain commands\r
 - inferior hangs\r
index 4776ca0eac1b781dfcfade796b3c335d794eb7b1..5910650eefce5255c76e8d1d4a6cc1a2f93c917c 100644 (file)
@@ -168,21 +168,26 @@ public class FactorLib
        public static void copy(InputStream in, OutputStream out)
                throws IOException
        {
-               byte[] buf = new byte[4096];
+               try
+               {
+                       byte[] buf = new byte[4096];
 
-               int count;
+                       int count;
 
-               for(;;)
-               {
-                       count = in.read(buf,0,buf.length);
-                       if(count == -1 || count == 0)
-                               break;
+                       for(;;)
+                       {
+                               count = in.read(buf,0,buf.length);
+                               if(count == -1 || count == 0)
+                                       break;
 
-                       out.write(buf,0,count);
+                               out.write(buf,0,count);
+                       }
+               }
+               finally
+               {
+                       in.close();
+                       out.close();
                }
-
-               in.close();
-               out.close();
        } //}}}
 
        //{{{ readLine() method
index 9dd3885d3bc3771957153c15a81de64729629d80..6cf8a886568bb1dae22b5ff99508529cdfca4ac0 100644 (file)
@@ -200,6 +200,9 @@ public class FactorPlugin extends EditPlugin
                int caret = textArea.getCaretPosition()
                        - textArea.getLineStartOffset(
                        textArea.getCaretLine());
+               if(caret == line.length())
+                       caret--;
+
                String noWordSep = textArea.getBuffer().getStringProperty(
                        "noWordSep");
                int wordStart = TextUtilities.findWordStart(line,caret,
index e4f5f442e3f0b71aa7a6c46e456ba6b3749db318..7859b84efb2d01ade77829ac17ea99badd215e06 100644 (file)
@@ -35,42 +35,45 @@ USE: test-responder
 USE: inspect-responder
 USE: quit-responder
 USE: file-responder
+USE: resource-responder
 USE: wiki-responder
 
-: no-such-responder ( -- )
-    "404 No such responder" httpd-error ;
+#! Remove all existing responders, and create a blank
+#! responder table.
+global [ <namespace> "httpd-responders" set ] bind
 
-: default-responders ( -- )
-    #! Remove all existing responders, and create a blank
-    #! responder table.
-    <namespace> [
-        <responder> [
-            "404" "responder" set
-            [ drop no-such-responder ] "get" set
-        ] extend "404" set
+<responder> [
+    "404" "responder" set
+    [ drop no-such-responder ] "get" set
+] extend add-responder
 
-        <responder> [
-            "test" "responder" set
-            [ test-responder ] "get" set
-        ] extend "test" set
+<responder> [
+    "test" "responder" set
+    [ test-responder ] "get" set
+] extend add-responder
 
-        <responder> [
-            "inspect" "responder" set
-            [ inspect-responder ] "get" set
-            "global" "default-argument" set
-        ] extend "inspect" set
+<responder> [
+    "inspect" "responder" set
+    [ inspect-responder ] "get" set
+    "global" "default-argument" set
+] extend add-responder
 
-        <responder> [
-            "quit" "responder" set
-            [ quit-responder ] "get" set
-        ] extend "quit" set
+<responder> [
+    "quit" "responder" set
+    [ quit-responder ] "get" set
+] extend add-responder
 
-        <responder> [
-            "file" "responder" set
-            [ file-responder ] "get" set
-            [ file-responder ] "post" set
-            [ file-responder ] "head" set
-        ] extend "file" set
+<responder> [
+    "file" "responder" set
+    [ file-responder ] "get" set
+    [ file-responder ] "post" set
+    [ file-responder ] "head" set
+] extend add-responder
+
+<responder> [
+    "resource" "responder" set
+    [ resource-responder ] "get" set
+] extend add-responder
 
 !        <responder> [
 !            "wiki" "responder" set
@@ -78,5 +81,4 @@ USE: wiki-responder
 !            [ wiki-post-responder ] "post" set
 !            <namespace> "wiki" set
 !            "WikiHome" "default-argument" set
-!        ] extend "wiki" set
-    ] extend "httpd-responders" set ;
+!        ] extend add-responder
index 9673a9d84652d7584906483ac873f5b7fd22fc24..3c829b60f01a109d95020bc4f31284adbbb16c7d 100644 (file)
@@ -46,20 +46,17 @@ USE: unparser
 : serving-path ( filename -- filename )
     f>"" "doc-root" get swap cat2 ;
 
-: copy-and-close ( from -- )
-    [ dupd "stdio" get fcopy ] [ >r fclose r> rethrow ] catch ;
-
 : file-response ( mime-type length -- )
     [,
         unparse "Content-Length" swons ,
         "Content-Type" swons ,
-    ,] "200 OK" response ;
+    ,] "200 OK" response terpri ;
 
 : serve-static ( filename mime-type -- )
     over file-length file-response  "method" get "head" = [
         drop
     ] [
-        <filebr> "stdio" get copy-and-close
+        <filebr> "stdio" get fcopy
     ] ifte ;
 
 : serve-file ( filename -- )
@@ -69,11 +66,6 @@ USE: unparser
         serve-static
     ] ifte ;
 
-: directory-no/ ( -- )
-    <% "request" get % CHAR: / %
-    "raw-query" get [ CHAR: ? % % ] when*
-    %> redirect ;
-
 : list-directory ( directory -- )
     serving-html
      "method" get "head" = [
@@ -96,13 +88,13 @@ USE: unparser
 : serve-object ( filename -- )
     dup directory? [ serve-directory ] [ serve-file ] ifte ;
 
-: file-responder ( filename method -- )
+: file-responder ( filename -- )
     "doc-root" get [
         serving-path dup exists? [
             serve-object
         ] [
-            2drop "404 not found" httpd-error
+            drop "404 not found" httpd-error
         ] ifte
     ] [
-        2drop "404 doc-root not set" httpd-error
+        drop "404 doc-root not set" httpd-error
     ] ifte ;
diff --git a/library/httpd/html-tags.factor b/library/httpd/html-tags.factor
new file mode 100644 (file)
index 0000000..39ca530
--- /dev/null
@@ -0,0 +1,227 @@
+! cont-html v0.6
+!
+! Copyright (C) 2004 Chris Double.
+! 
+! Redistribution and use in source and binary forms, with or without
+! modification, are permitted provided that the following conditions are met:
+! 
+! 1. Redistributions of source code must retain the above copyright notice,
+!        this list of conditions and the following disclaimer.
+! 
+! 2. Redistributions in binary form must reproduce the above copyright notice,
+!        this list of conditions and the following disclaimer in the documentation
+!        and/or other materials provided with the distribution.
+! 
+! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+IN: html
+USE: strings
+USE: lists
+USE: format
+USE: stack
+USE: combinators
+USE: stdio
+USE: namespaces
+USE: words
+USE: logic
+
+! These words are used to provide a means of writing
+! formatted HTML to standard output with a familiar 'html' look
+! and feel in the code. 
+!
+! HTML tags can be used in a number of different ways. The highest
+! level involves a similar syntax to HTML:
+! 
+! <p> "someoutput" write </p>
+!
+! <p> will outupt the opening tag and </p> will output the closing
+! tag with no attributes.
+!
+! <p class= "red" p> "someoutput" write </p>
+!
+! This time the opening tag does not have the '>'. It pushes
+! a namespace on the stack to hold the attributes and values.
+! Any attribute words used will store the attribute and values
+! in that namespace. After the attribute word should come the
+! value of that attribute. The next attribute word or 
+! finishing word (which is the html word followed by '>') 
+! will actually set the attribute to that value in the namespace.
+! The finishing word will print out the operning tag including
+! attributes. 
+! Any writes after this will appear after the opening tag.
+!
+! Values for attributes can be used directly without any stack
+! operations:
+!
+! (url -- )
+! <a href= a> "Click me" write </a>
+!
+! (url -- )
+! <a href= "http://" swap cat2 a> "click" write </a>
+!
+! (url -- )
+! <a href= <% "http://" % % %> a> "click" write </a>
+!
+! Tags that have no 'closing' equivalent have a trailing tag/> form:
+!
+! <input type= "text" name= "name" size= "20" input/>
+
+: attrs>string ( alist -- string )
+    #! Convert the attrs alist to a string
+    #! suitable for embedding in an html tag.
+    nreverse <% [ dup car % "='" % cdr % "'" % ] each %> ;
+
+: write-attributes ( n: namespace -- )    
+    #! With the attribute namespace on the stack, get the attributes
+    #! and write them to standard output. If no attributes exist, write
+    #! nothing.
+    "attrs" get [ " " write attrs>string write ] when* ;
+
+: store-prev-attribute ( n: tag value -- )     
+    #! Assumes an attribute namespace is on the stack.
+    #! Gets the previous attribute that was used (if any)
+    #! and sets it's value to the current value on the stack.
+    #! If there is no previous attribute, no value is expected
+    #! on the stack.
+    "current-attribute" get [ swons "attrs" cons@ ] when* ;
+
+! HTML tag words
+! 
+! Each closable HTML tag has four words defined. The example below is for
+! <p>:
+!
+! : <p> ( -- )
+!    #! Writes the opening tag to standard output.
+!    "<p>" write ;
+
+! : <p ( -- n: <namespace> )
+!     #! Used for setting inline attributes. Prints out
+!     #! an unclosed opening tag.
+!     "<p" write <namespace> >n ;
+!
+! : p> ( n: <namespace> -- )
+!    #! Used to close off inline attribute version of word.
+!    #! Prints out attributes and closes opening tag.
+!     store-prev-attribute write-attributes n> drop ">" write ;
+!
+! : </p> ( -- )
+!    #! Write out the closing tag.
+!    "</foo>" write ;
+!
+! Each open only HTML tag has only three words:
+!
+! : <input/> ( -- )
+!     #! Used for printing the tag with no attributes.
+!     "<input>" write ;
+!
+! : <input ( -- n: <namespace> )
+!     #! Used for setting inline attributes.
+!     "<input" write <namespace> >n ;
+!
+! : input/> ( n: <namespace> -- )
+!     #! Used to close off inline attribute version of word
+!     #! and print the tag/
+!     store-prev-attribute write-attributes n> drop ">" write ;
+!
+! Each attribute word has the form xxxx= where 'xxxx' is the attribute
+! name. The example below is for href:
+!
+! : href= ( n: <namespace> optional-value -- )
+!    store-prev-attribute "href" "current-attribute" set ;
+
+: create-word ( vocab name def -- )
+    #! Define 'word creating' word to allow
+    #! dynamically creating words.
+    >r swap create r> define-compound ;
+: def-for-html-word-<foo> ( name -- name quot )
+    #! Return the name and code for the <foo> patterned
+    #! word.
+    "<" swap ">" cat3 dup [ write ] cons ;
+
+: def-for-html-word-<foo ( name -- name quot )
+    #! Return the name and code for the <foo patterned
+    #! word.
+    "<" swap cat2 dup [ write <namespace> >n ] cons ;
+
+: def-for-html-word-foo> ( name -- name quot )
+    #! Return the name and code for the foo> patterned
+    #! word.
+    ">" cat2 [
+        store-prev-attribute write-attributes n> drop ">" write
+    ] ;
+
+: def-for-html-word-</foo> ( name -- name quot )
+    #! Return the name and code for the </foo> patterned
+    #! word.    
+    <% "</" % % ">" % %> dup [ write ] cons ;
+
+: def-for-html-word-<foo/> ( name -- name quot )
+    #! Return the name and code for the <foo/> patterned
+    #! word.
+    <% "<" % dup % "/>" % %> swap
+    <% "<" % % ">" % %>
+    [ write ] cons ;
+
+: def-for-html-word-foo/> ( name -- name quot )
+    #! Return the name and code for the foo/> patterned
+    #! word.    
+    "/>" cat2 [
+        store-prev-attribute write-attributes n> drop ">" write
+    ] ;
+
+: define-closed-html-word ( name -- ) 
+    #! Given an HTML tag name, define the words for
+    #! that closable HTML tag.
+    "html" swap
+    2dup def-for-html-word-<foo> create-word
+    2dup def-for-html-word-<foo create-word
+    2dup def-for-html-word-foo> create-word
+    def-for-html-word-</foo> create-word ;
+
+: define-open-html-word ( name -- ) 
+    #! Given an HTML tag name, define the words for
+    #! that open HTML tag.
+    "html" swap
+    2dup def-for-html-word-<foo/> create-word
+    2dup def-for-html-word-<foo create-word
+    def-for-html-word-foo/> create-word ;
+
+: define-attribute-word ( name -- )
+    "html" swap dup "=" cat2 swap 
+    [ store-prev-attribute ] cons reverse
+    [ "current-attribute" set ] append create-word ;
+
+! Define some closed HTML tags
+[
+    "h1" "h2" "h3" "h4" "h5" "h6" "h7" "h8" "h9"    
+    "ol" "li" "form" "a" "p" "html" "head" "body" "title"
+    "b" "i" "ul" "table" "tr" "td" "th" "pre" "textarea"
+    "script" "div" "span" "select" "option"
+] [ define-closed-html-word ] each
+
+! Define some open HTML tags
+[ 
+    "input" 
+    "br" 
+    "link"
+    "img"
+] [ define-open-html-word ] each
+
+! Define some attributes
+[ 
+    "method" "action" "type" "value" "name" 
+    "size" "href" "class" "border" "rows" "cols" 
+    "id" "onclick" "style" "valign" "accesskey"
+    "src" "language" "colspan" "onchange" "rel"
+    "width" "src"
+] [ define-attribute-word ] each 
index 1bb85f1878053b4c223ffea2e56af3a64d7b90b0..0573bc945c299a108d7cace0cbe3bcb87613bf37 100644 (file)
@@ -55,16 +55,6 @@ USE: url-encoding
     #! Convert <, >, &, ' and " to HTML entities.
     [ dup html-entities assoc dup rot ? ] str-map ;
 
-: opening-tag ( tag attrs -- )
-    "<" % swap % [ " " % % ] when* ">" % ;
-
-: closing-tag ( tag -- )
-    "</" % % ">" % ;
-
-: html-tag ( str tag attrs -- str )
-    #! Wrap a string in an HTML tag.
-    <% dupd opening-tag swap % closing-tag %> ;
-
 : >hex-color ( triplet -- hex )
     [ >hex 2 digits ] map "#" swons cat ;
 
@@ -86,21 +76,22 @@ USE: url-encoding
 : font-css% ( font -- )
     "font-family: " % % "; " % ;
 
-: css-style% ( style -- )
-    [
+: css-style ( style -- )
+    <% [
         [ "fg"        fg-css% ]
         [ "bold"      bold-css% ]
         [ "italics"   italics-css% ]
         [ "underline" underline-css% ]
         [ "size"      size-css% ]
         [ "font"      font-css% ]
-    ] assoc-apply ;
+    ] assoc-apply %> ;
 
-: span-tag ( string style -- string )
-    "span" swap <% "style=\"" % css-style% "\"" % %> html-tag ;
-
-: link-tag ( string link -- string )
-    url-encode "a" swap <% "href=" % unparse % %> html-tag ;
+: span-tag ( style quot -- )
+    over css-style dup "" = [
+        drop call
+    ] [
+        <span style= span> call </span>
+    ] ifte ;
 
 : resolve-file-link ( path -- link )
     #! The file responder needs relative links not absolute
@@ -110,20 +101,43 @@ USE: url-encoding
     ] when* "/" ?str-tail drop ;
 
 : file-link-href ( path -- href )
-    <% "/file/" % resolve-file-link % %> ;
+    <% "/file/" % resolve-file-link url-encode % %> ;
 
-: object-link-href ( path -- href )
-    <% "/inspect/" % % %> ;
+: file-link-tag ( style quot -- )
+    over "file-link" swap assoc [
+        <a href= file-link-href a> call </a>
+    ] [
+        call
+    ] ifte* ;
 
-: html-attr-string ( string style -- string )
-    [ span-tag ] keep
-    [
-        [ "file-link"   file-link-href   link-tag ]
-        [ "object-link" object-link-href link-tag ]
-    ] assoc-apply ;
+: object-link-href ( path -- href )
+    "/inspect/" swap cat2 ;
+
+: object-link-tag ( style quot -- )
+    over "object-link" swap assoc [
+        <a href= object-link-href url-encode a> call </a>
+    ] [
+        call
+    ] ifte* ;
+
+: icon-tag ( string style quot -- )
+    over "icon" swap assoc dup [
+        <img src= "/resource/" swap cat2 img/>
+        #! Ignore the quotation, since no further style
+        #! can be applied
+        3drop
+    ] [
+        drop call
+    ] ifte ;
 
 : html-write-attr ( string style -- )
-    swap chars>entities swap html-attr-string write ;
+    [
+        [
+            [
+                [ drop chars>entities write ] span-tag
+            ] file-link-tag
+        ] object-link-tag
+    ] icon-tag ;
 
 : <html-stream> ( stream -- stream )
     #! Wraps the given stream in an HTML stream. An HTML stream
@@ -146,24 +160,19 @@ USE: url-encoding
     ] extend ;
 
 : with-html-stream ( quot -- )
-    [
-        "stdio" get <html-stream> "stdio" set call
-    ] with-scope ;
-
-: html-head ( title -- )
-    "<html><head><title>" write
-    dup write
-    "</title></head><body><h1>" write write "</h1>" write ;
-
-: html-tail ( -- ) "</body></html>" print ;
+    [ "stdio" get <html-stream> "stdio" set call ] with-scope ;
 
 : html-document ( title quot -- )
-    swap chars>entities html-head call html-tail ;
-
-: preformatted-html ( quot -- )
-    "<pre>" print call "</pre>" print ;
+    swap chars>entities dup
+    <html>
+        <head>
+            <title> write </title>
+        </head>
+        <body>
+            <h1> write </h1>
+            call
+        </body>
+    </html> ;
 
 : simple-html-document ( title quot -- )
-    swap [
-        [ with-html-stream ] preformatted-html
-    ] html-document ;
+    swap [ <pre> with-html-stream </pre> ] html-document ;
index 82aaa5afd2cd3061707bf23dbd36c052f38b4f97..1bff2c2866e2d057ce3ee7fabbfc13835a49ecab 100644 (file)
@@ -79,6 +79,11 @@ USE: url-encoding
     "Location" swons unit
     "301 Moved Permanently" response terpri ;
 
+: directory-no/ ( -- )
+    <% "request" get % CHAR: / %
+    "raw-query" get [ CHAR: ? % % ] when*
+    %> redirect ;
+
 : header-line ( alist line -- alist )
     ": " split1 dup [ transp acons ] [ 2drop ] ifte ;
 
diff --git a/library/httpd/resource-responder.factor b/library/httpd/resource-responder.factor
new file mode 100644 (file)
index 0000000..0fb971e
--- /dev/null
@@ -0,0 +1,58 @@
+! :folding=indent:collapseFolds=1:
+
+! $Id$
+!
+! Copyright (C) 2004 Slava Pestov.
+! 
+! Redistribution and use in source and binary forms, with or without
+! modification, are permitted provided that the following conditions are met:
+! 
+! 1. Redistributions of source code must retain the above copyright notice,
+!    this list of conditions and the following disclaimer.
+! 
+! 2. Redistributions in binary form must reproduce the above copyright notice,
+!    this list of conditions and the following disclaimer in the documentation
+!    and/or other materials provided with the distribution.
+! 
+! THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
+! INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
+! FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+! DEVELOPERS AND CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+! SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+! PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+! OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+! WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+! OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+! ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+IN: resource-responder
+USE: combinators
+USE: files
+USE: httpd
+USE: httpd-responder
+USE: kernel
+USE: lists
+USE: logic
+USE: namespaces
+USE: parser
+USE: stack
+USE: stdio
+USE: streams
+USE: strings
+
+: resource-response ( mime-type -- )
+    "Content-Type" swons unit "200 OK" response terpri ;
+
+: serve-resource ( filename mime-type -- )
+    dup mime-type resource-response  "method" get "head" = [
+        drop
+    ] [
+        <resource-stream> "stdio" get fcopy
+    ] ifte ;
+
+: resource-responder ( filename -- )
+    java? "resource-path" get or [
+        serve-resource
+    ] [
+        drop "404 resource-path not set" httpd-error
+    ] ifte ;
index 2d182d572fb8e623edea2ed12fbcb3cfffdf63be..17d7794ab170acd260feecf5d8a776b755f8c47a 100644 (file)
@@ -96,3 +96,10 @@ USE: strings
         ! Just a responder name by itself
         drop "/" swap "/" cat3 redirect drop
     ] ifte ;
+
+: no-such-responder ( -- )
+    "404 No such responder" httpd-error ;
+
+: add-responder ( responder -- )
+    #! Add a responder object to the list.
+    "responder" over get*  "httpd-responders" get set* ;
index 15801115e5c599815ce68548e32ef67aea6bcfda..65e4370bdbac063cd94a07c2ebe62f168fd45ef1 100644 (file)
@@ -54,7 +54,7 @@ USE: httpd-responder
     "wiki" get [ get ] bind ;
 
 : write-wiki-page ( text -- )
-    [ chars>entities wiki-word-links write ] preformatted-html ;
+    [ chars>entities wiki-word-links write ] call ;
 
 : wiki-nodes ( -- alist )
     "wiki" get [ vars-values ] bind ;
index a926b8f48dafff3107de15f7e8d2aed19ec3218f..b986dffe552b3cdb7f1405d9493e954a451f7bb2 100644 (file)
@@ -111,6 +111,7 @@ USE: parser
 
 !!! HTTPD.
 "/library/httpd/url-encoding.factor"       run-resource ! url-encoding
+"/library/httpd/html-tags.factor"          run-resource ! html
 "/library/httpd/html.factor"               run-resource ! html
 "/library/httpd/http-common.factor"        run-resource ! httpd
 "/library/httpd/responder.factor"          run-resource ! httpd-responder
@@ -118,6 +119,7 @@ USE: parser
 "/library/httpd/inspect-responder.factor"  run-resource ! inspect-responder
 "/library/httpd/file-responder.factor"     run-resource ! file-responder
 "/library/httpd/quit-responder.factor"     run-resource ! quit-responder
+"/library/httpd/resource-responder.factor" run-resource ! resource-responder
 "/library/httpd/test-responder.factor"     run-resource ! test-responder
 "/library/httpd/wiki-responder.factor"     run-resource ! wiki-responder
 "/library/httpd/default-responders.factor" run-resource ! default-responders
index 282b73f0874d058446470f45376de242d6338eb2..acd3dc26bfac22433c05ef0a8d491226c2182427 100644 (file)
@@ -71,9 +71,6 @@ USE: words
     init-stdio
     init-environment
     init-search-path
-    init-scratchpad
-    init-styles
-    init-vocab-styles
     "args" get parse-command-line
     run-user-init
 
index 23aab460dd8b487bca89b532f6583868459d0b86..11c3ed665eabebb07cd6d6c1004f08d1497784a7 100644 (file)
@@ -114,6 +114,7 @@ USE: stdio
     "/library/platform/native/cross-compiler.factor"
 
     "/library/httpd/url-encoding.factor"
+    "/library/httpd/html-tags.factor"
     "/library/httpd/html.factor"
     "/library/httpd/http-common.factor"
     "/library/httpd/responder.factor"
@@ -122,6 +123,7 @@ USE: stdio
     "/library/httpd/inspect-responder.factor"
     "/library/httpd/test-responder.factor"
     "/library/httpd/quit-responder.factor"
+    "/library/httpd/resource-responder.factor"
     "/library/httpd/default-responders.factor"
 
     "/library/jedit/jedit-no-local.factor"
@@ -138,9 +140,7 @@ USE: stdio
 ] each
 
 IN: init
-DEFER: finish-cold-boot
 DEFER: warm-boot
-finish-cold-boot
 
 : set-boot ( quot -- ) 8 setenv ;
 [ warm-boot ] set-boot
index c1750ebea9483c5523a651090035e65d79104804..404db6990472ec405bc3b1637233138fec87eb4a 100644 (file)
@@ -68,11 +68,3 @@ USE: words
     "interactive" get [ init-interpreter ] when
 
     0 exit* ;
-
-: finish-cold-boot ( -- )
-    #! After the stage2 bootstrap is done, this word
-    #! completes initialization.
-    init-scratchpad
-    init-styles
-    init-vocab-styles
-    default-responders ;
index 8a560249be1cdf60510a5beb559c7674c4efe797..b5629fd0bceb4e827afe010e42d25455058992b4 100644 (file)
@@ -59,5 +59,4 @@ USE: vectors
     #! An initially-generated image has this as the boot
     #! quotation.
     boot
-    "/library/platform/native/boot-stage2.factor" run-resource
-    "finish-cold-boot" [ "init" ] search execute ;
+    "/library/platform/native/boot-stage2.factor" run-resource ;
index ffd6a26c5634cdf2640b1c55713273d15fc0fd1e..b3ce88c243ce1ec4d5e9843aa0f8bf864610f747 100644 (file)
@@ -73,4 +73,4 @@ USE: threads
     dup wait-to-accept accept-fd ;
 
 : blocking-copy ( in out -- )
-    [ add-copy-io-task (yield) ] callcc0 ;
+    [ add-copy-io-task (yield) ] callcc0 2drop ;
index 97e019626beb941d2a40c323c7e71d0f41c3e6d8..fef1fa3e39922b96aae381f9698ab6a82b7fa0a7 100644 (file)
@@ -80,7 +80,13 @@ USE: namespaces
 : init-stdio ( -- )
     stdin stdout <fd-stream> <stdio-stream> "stdio" set ;
 
+: (fcopy) ( from to -- )
+    #! Copy the contents of the fd-stream 'from' to the
+    #! fd-stream 'to'. Use fcopy; this word does not close
+    #! streams.
+    "out" swap get* >r "in" swap get* r> blocking-copy ;
+
 : fcopy ( from to -- )
     #! Copy the contents of the fd-stream 'from' to the
     #! fd-stream 'to'.
-    "out" swap get* >r "in" swap get* r> blocking-copy ;
+    [ 2dup (fcopy) ] [ -rot fclose fclose rethrow ] catch ;
index 150a35915cf54d1133f134833cb2eff1c9c25b2e..902fcd8afc326779bfc09709f169a68d173909d8 100644 (file)
@@ -169,9 +169,9 @@ USE: stack
     #! In a URL, can this character be used without
     #! URL-encoding?
     [
-        [ letter?             ] [ drop t ]
-        [ LETTER?             ] [ drop t ]
-        [ digit?              ] [ drop t ]
-        [ "/_?" str-contains? ] [ drop t ]
-        [                     ] [ drop f ]
+        [ letter?              ] [ drop t ]
+        [ LETTER?              ] [ drop t ]
+        [ digit?               ] [ drop t ]
+        [ "/_?." str-contains? ] [ drop t ]
+        [                      ] [ drop f ]
     ] cond ;
index 034c2cacbaa8455e46d2120ced9d36d414793ad3..b32a3a504700bdd1a1075ebef51cd6cb913535e9 100644 (file)
@@ -63,19 +63,18 @@ USE: stack
     ! XXX: use object path...
     "styles" get [ set ] bind ;
 
-: init-styles ( -- )
-    <namespace> "styles" set
+<namespace> "styles" set
 
-    [
-        [ "font" | "Monospaced" ]
-    ] "default" set-style
+[
+    [ "font" | "Monospaced" ]
+] "default" set-style
 
-    [
-        [ "bold" | t ]
-    ] default-style append "prompt" set-style
-    
-    [
-        [ "ansi-fg" | "0" ]
-        [ "ansi-bg" | "2" ]
-        [ "fg" | [ 255 0 0 ] ]
-    ] default-style append "comments" set-style ;
+[
+    [ "bold" | t ]
+] default-style append "prompt" set-style
+
+[
+    [ "ansi-fg" | "0" ]
+    [ "ansi-bg" | "2" ]
+    [ "fg" | [ 255 0 0 ] ]
+] default-style append "comments" set-style
index f19d15f71eb523c11ce847be50634ddbdc2e4dcf..cb6303eb68270efed59a421148270dccb5ccbc76 100644 (file)
@@ -5,18 +5,12 @@ USE: stdio
 USE: streams
 USE: strings
 USE: test
+USE: stack
 
 [
     "&lt;html&gt;&amp;&apos;sgml&apos;"
 ] [ "<html>&'sgml'" chars>entities ] unit-test
 
-[ "<span style=\"color: #ff00ff; font-family: Monospaced; \">car</span>" ]
-[
-    "car"
-    [ [ "fg" 255 0 255 ] [ "font" | "Monospaced" ] ]
-    span-tag
-] unit-test
-
 [ "/file/foo/bar" ]
 [
     [
@@ -24,3 +18,58 @@ USE: test
         "/home/slava/doc/foo/bar" file-link-href
     ] with-scope
 ] unit-test
+
+[ "<img src='/resource/library/icons/File.png'>" ]
+[
+    [
+        ""
+        [ [ "icon" | "library/icons/File.png" ] ]
+        [ drop ] icon-tag
+    ] with-string
+] unit-test
+
+[ "" ]
+[
+    [
+        [ ] [ drop ] span-tag
+    ] with-string
+] unit-test
+
+[ "<span style='color: #ff00ff; font-family: Monospaced; '>car</span>" ]
+[
+    [
+        [ [ "fg" 255 0 255 ] [ "font" | "Monospaced" ] ]
+        [ drop "car" write ]
+        span-tag
+    ] with-string
+] unit-test
+
+[ "hello world" ]
+[
+    [ "hello world" [ ] html-write-attr ] with-string
+] unit-test
+
+[ "<span style='color: #ff00ff; font-family: Monospaced; '>car</span>" ]
+[
+    [
+        "car"
+        [ [ "fg" 255 0 255 ] [ "font" | "Monospaced" ] ]
+        html-write-attr
+    ] with-string
+] unit-test
+
+[
+    "<html><head><title>Foo</title></head><body><h1>Foo</h1></body></html>"
+] [
+    [
+        "Foo" [ ] html-document
+    ] with-string
+] unit-test
+
+[
+    "<html><head><title>Foo</title></head><body><h1>Foo</h1><pre>Hi</pre></body></html>"
+] [
+    [
+        "Foo" [ "Hi" write ] simple-html-document
+    ] with-string
+] unit-test
index 5338c4bcc04011b8bacc942d33bc9b426e728b0a..5e1dc4189cdfefc91a6e7bd1a5673702d2b2f6d1 100644 (file)
@@ -19,14 +19,6 @@ USE: lists
 [ 5430 ]
 [ f "Content-Length: 5430" header-line content-length ] unit-test
 
-[ "hello world"   ] [ "hello+world"    url-decode ] unit-test
-[ "hello world"   ] [ "hello%20world"  url-decode ] unit-test
-[ " ! "           ] [ "%20%21%20"      url-decode ] unit-test
-[ "hello world"   ] [ "hello world%"   url-decode ] unit-test
-[ "hello world"   ] [ "hello world%x"  url-decode ] unit-test
-[ "hello%20world" ] [ "hello world"    url-encode ] unit-test
-[ "%20%21%20"     ] [ " ! "            url-encode ] unit-test
-
 [ ] [ "404 not found" ] [ httpd-error ] test-word
 
 [ "arg" ] [
index b8efaec947c41b35bec67cc8846d6ddab6bb4242..300ffb21fa9736f0afa2dab0fd100e0b5272b8bb 100644 (file)
@@ -7,3 +7,11 @@ USE: test
 [ "~hello world" ] [ "%7ehello+world" url-decode ] unit-test
 [ "" ] [ "%XX%XX%XX" url-decode ] unit-test
 [ "" ] [ "%XX%XX%X" url-decode ] unit-test
+
+[ "hello world"   ] [ "hello+world"    url-decode ] unit-test
+[ "hello world"   ] [ "hello%20world"  url-decode ] unit-test
+[ " ! "           ] [ "%20%21%20"      url-decode ] unit-test
+[ "hello world"   ] [ "hello world%"   url-decode ] unit-test
+[ "hello world"   ] [ "hello world%x"  url-decode ] unit-test
+[ "hello%20world" ] [ "hello world"    url-encode ] unit-test
+[ "%20%21%20"     ] [ " ! "            url-encode ] unit-test
index 2bc9f2fc5d864de48ffeae84c0202669f6b75703..49e4bd731c2ba474fa1938f4fb091c24c73e50a7 100644 (file)
@@ -106,8 +106,3 @@ USE: strings
         "words"
         "scratchpad"
     ] "use" set ;
-
-: init-scratchpad ( -- )
-    #! The contents of the scratchpad vocabulary is not saved
-    #! between runs.
-    <namespace> "scratchpad" "vocabularies" get set* ;
index c8a0a62b0aea82511e0e2de11d4135ca893428d0..c118e88c0164519cf5da58f36ba5fe2765c440c0 100644 (file)
@@ -49,74 +49,73 @@ USE: styles
         drop default-style
     ] ifte ;
 
-: init-vocab-styles ( -- )
-    "styles" get [ <namespace> "vocabularies" set ] bind
+"styles" get [ <namespace> "vocabularies" set ] bind
 
-    [
-        [ "ansi-fg" | "1" ]
-        [ "fg" | [ 204 0 0 ] ]
-    ] "arithmetic" set-vocab-style
-    [
-        [ "ansi-fg" | "3" ]
-        [ "fg" | [ 255 132 0 ] ]
-    ] "combinators" set-vocab-style
-    [
-        [ "ansi-fg" | "5" ]
-        [ "fg" | [ 102 0 204 ] ]
-    ] "continuations" set-vocab-style
-    [
-        [ "ansi-fg" | "1" ]
-        [ "fg" | [ 255 0 0 ] ]
-    ] "errors" set-vocab-style
-    [
-        [ "ansi-fg" | "4" ]
-        [ "fg" | [ 153 102 255 ] ]
-    ] "hashtables" set-vocab-style
-    [
-        [ "ansi-fg" | "2" ]
-        [ "fg" | [ 0 102 153 ] ]
-    ] "lists" set-vocab-style
-    [
-        [ "ansi-fg" | "6" ]
-        [ "fg" | [ 0 153 102 ] ]
-    ] "logic" set-vocab-style
-    [
-        [ "ansi-fg" | "1" ]
-        [ "fg" | [ 204 0 0 ] ]
-    ] "math" set-vocab-style
-    [
-        [ "ansi-fg" | "6" ]
-        [ "fg" | [ 0 153 255 ] ]
-    ] "namespaces" set-vocab-style
-    [
-        [ "ansi-fg" | "2" ]
-        [ "fg" | [ 102 204 255 ] ]
-    ] "parser" set-vocab-style
-    [
-        [ "ansi-fg" | "2" ]
-        [ "fg" | [ 102 204 255 ] ]
-    ] "prettyprint" set-vocab-style
-    [
-        [ "ansi-fg" | "2" ]
-        [ "fg" | [ 0 0 0 ] ]
-    ] "stack" set-vocab-style
-    [
-        [ "ansi-fg" | "4" ]
-        [ "fg" | [ 204 0 204 ] ]
-    ] "stdio" set-vocab-style
-    [
-        [ "ansi-fg" | "4" ]
-        [ "fg" | [ 102 0 204 ] ]
-    ] "streams" set-vocab-style
-    [
-        [ "ansi-fg" | "6" ]
-        [ "fg" | [ 255 0 204 ] ]
-    ] "strings" set-vocab-style
-    [
-        [ "ansi-fg" | "4" ]
-        [ "fg" | [ 102 204 255 ] ]
-    ] "unparser" set-vocab-style
-    [
-        [ "ansi-fg" | "3" ]
-        [ "fg" | [ 2 185 2 ] ]
-    ] "vectors" set-vocab-style ;
+[
+    [ "ansi-fg" | "1" ]
+    [ "fg" | [ 204 0 0 ] ]
+] "arithmetic" set-vocab-style
+[
+    [ "ansi-fg" | "3" ]
+    [ "fg" | [ 255 132 0 ] ]
+] "combinators" set-vocab-style
+[
+    [ "ansi-fg" | "5" ]
+    [ "fg" | [ 102 0 204 ] ]
+] "continuations" set-vocab-style
+[
+    [ "ansi-fg" | "1" ]
+    [ "fg" | [ 255 0 0 ] ]
+] "errors" set-vocab-style
+[
+    [ "ansi-fg" | "4" ]
+    [ "fg" | [ 153 102 255 ] ]
+] "hashtables" set-vocab-style
+[
+    [ "ansi-fg" | "2" ]
+    [ "fg" | [ 0 102 153 ] ]
+] "lists" set-vocab-style
+[
+    [ "ansi-fg" | "6" ]
+    [ "fg" | [ 0 153 102 ] ]
+] "logic" set-vocab-style
+[
+    [ "ansi-fg" | "1" ]
+    [ "fg" | [ 204 0 0 ] ]
+] "math" set-vocab-style
+[
+    [ "ansi-fg" | "6" ]
+    [ "fg" | [ 0 153 255 ] ]
+] "namespaces" set-vocab-style
+[
+    [ "ansi-fg" | "2" ]
+    [ "fg" | [ 102 204 255 ] ]
+] "parser" set-vocab-style
+[
+    [ "ansi-fg" | "2" ]
+    [ "fg" | [ 102 204 255 ] ]
+] "prettyprint" set-vocab-style
+[
+    [ "ansi-fg" | "2" ]
+    [ "fg" | [ 0 0 0 ] ]
+] "stack" set-vocab-style
+[
+    [ "ansi-fg" | "4" ]
+    [ "fg" | [ 204 0 204 ] ]
+] "stdio" set-vocab-style
+[
+    [ "ansi-fg" | "4" ]
+    [ "fg" | [ 102 0 204 ] ]
+] "streams" set-vocab-style
+[
+    [ "ansi-fg" | "6" ]
+    [ "fg" | [ 255 0 204 ] ]
+] "strings" set-vocab-style
+[
+    [ "ansi-fg" | "4" ]
+    [ "fg" | [ 102 204 255 ] ]
+] "unparser" set-vocab-style
+[
+    [ "ansi-fg" | "3" ]
+    [ "fg" | [ 2 185 2 ] ]
+] "vectors" set-vocab-style