]> gitweb.factorcode.org Git - factor.git/commitdiff
Fix merge conflicts
authorSlava Pestov <slava@factorcode.org>
Thu, 6 Mar 2008 19:54:15 +0000 (13:54 -0600)
committerSlava Pestov <slava@factorcode.org>
Thu, 6 Mar 2008 19:54:15 +0000 (13:54 -0600)
1  2 
core/io/files/files.factor
extra/http/server/server.factor
extra/http/server/templating/fhtml/fhtml-tests.factor
extra/http/server/templating/fhtml/fhtml.factor
extra/io/unix/files/files.factor
unmaintained/sniffer/io/bsd/bsd.factor

Simple merge
index 990c77f71ee5a288b71282327dc8ce70e3225cdd,a003f1c422d9bbd2be33198fcd63d38127b74f33..858ccd10097124773b2505bbab75abd6e15bb353
@@@ -165,7 -160,7 +165,7 @@@ LOG: httpd-hit NOTIC
  
  : httpd ( port -- )
      internet-server "http.server"
-     [ handle-client ] with-server ;
 -    latin1 [ handle-client ] with-server ;
++    binary [ handle-client ] with-server ;
  
  : httpd-main ( -- ) 8888 httpd ;
  
index 0ae3b41454af304705473b883fa331a1ae1d13b4,0000000000000000000000000000000000000000..40654734fadc94d340c14773b802ea595b937436
mode 100644,000000..100755
--- /dev/null
@@@ -1,17 -1,0 +1,17 @@@
- USING: io io.files io.streams.string
++USING: io io.files io.streams.string io.encodings.utf8
 +http.server.templating.fhtml kernel tools.test sequences ;
 +IN: http.server.templating.fhtml.tests
 +
 +: test-template ( path -- ? )
 +    "extra/http/server/templating/fhtml/test/" swap append
 +    [
 +        ".fhtml" append resource-path
 +        [ run-template-file ] with-string-writer
 +    ] keep
-     ".html" append resource-path file-contents = ;
++    ".html" append resource-path utf8 file-contents = ;
 +
 +[ t ] [ "example" test-template ] unit-test
 +[ t ] [ "bug" test-template ] unit-test
 +[ t ] [ "stack" test-template ] unit-test
 +
 +[ ] [ "<%\n%>" parse-template drop ] unit-test
index e5770affc52f35a1f8b0b1956c99497f86fc35b5,0000000000000000000000000000000000000000..3dcd23b99fa64fd8dbd25202cea421b4f27fad2c
mode 100755,000000..100755
--- /dev/null
@@@ -1,106 -1,0 +1,106 @@@
- io.files io.streams.lines io.streams.string html html.elements
 +! Copyright (C) 2005 Alex Chapman
 +! Copyright (C) 2006, 2007 Slava Pestov
 +! See http://factorcode.org/license.txt for BSD license.
 +USING: continuations sequences kernel parser namespaces io
- assocs ;
++io.files io.streams.string html html.elements
 +source-files debugger combinators math quotations generic
 +strings splitting accessors http.server.static http.server
-             ?resource-path file-contents
++assocs io.encodings.utf8 ;
 +
 +IN: http.server.templating.fhtml
 +
 +: templating-vocab ( -- vocab-name ) "http.server.templating.fhtml" ;
 +
 +! See apps/http-server/test/ or libs/furnace/ for template usage
 +! examples
 +
 +! We use a custom lexer so that %> ends a token even if not
 +! followed by whitespace
 +TUPLE: template-lexer ;
 +
 +: <template-lexer> ( lines -- lexer )
 +    <lexer> template-lexer construct-delegate ;
 +
 +M: template-lexer skip-word
 +    [
 +        {
 +            { [ 2dup nth CHAR: " = ] [ drop 1+ ] }
 +            { [ 2dup swap tail-slice "%>" head? ] [ drop 2 + ] }
 +            { [ t ] [ f skip ] }
 +        } cond
 +    ] change-column ;
 +
 +DEFER: <% delimiter
 +
 +: check-<% ( lexer -- col )
 +    "<%" over lexer-line-text rot lexer-column start* ;
 +
 +: found-<% ( accum lexer col -- accum )
 +    [
 +        over lexer-line-text
 +        >r >r lexer-column r> r> subseq parsed
 +        \ write-html parsed
 +    ] 2keep 2 + swap set-lexer-column ;
 +
 +: still-looking ( accum lexer -- accum )
 +    [
 +        dup lexer-line-text swap lexer-column tail
 +        parsed \ print-html parsed
 +    ] keep next-line ;
 +
 +: parse-%> ( accum lexer -- accum )
 +    dup still-parsing? [
 +        dup check-<%
 +        [ found-<% ] [ [ still-looking ] keep parse-%> ] if*
 +    ] [
 +        drop
 +    ] if ;
 +
 +: %> lexer get parse-%> ; parsing
 +
 +: parse-template-lines ( lines -- quot )
 +    <template-lexer> [
 +        V{ } clone lexer get parse-%> f (parse-until)
 +    ] with-parser ;
 +
 +: parse-template ( string -- quot )
 +    [
 +        use [ clone ] change
 +        templating-vocab use+
 +        string-lines parse-template-lines
 +    ] with-scope ;
 +
 +: eval-template ( string -- ) parse-template call ;
 +
 +: html-error. ( error -- )
 +    <pre> error. </pre> ;
 +
 +: run-template-file ( filename -- )
 +    [
 +        [
 +            "quiet" on
 +            parser-notes off
 +            templating-vocab use+
 +            ! so that reload works properly
 +            dup source-file file set
-     [ run-template-file ] with-file-writer ;
++            ?resource-path utf8 file-contents
 +            [ eval-template ] [ html-error. drop ] recover
 +        ] with-file-vocabs
 +    ] curry assert-depth ;
 +
 +: run-relative-template-file ( filename -- )
 +    file get source-file-path parent-directory
 +    swap path+ run-template-file ;
 +
 +: template-convert ( infile outfile -- )
++    utf8 [ run-template-file ] with-file-writer ;
 +
 +! file responder integration
 +: serve-fhtml ( filename -- response )
 +    "text/html" <content>
 +    swap [ run-template-file ] curry >>body ;
 +
 +: enable-fhtml ( responder -- responder )
 +    [ serve-fhtml ]
 +    "application/x-factor-server-page"
 +    pick special>> set-at ;
Simple merge
index 0000000000000000000000000000000000000000,e89bb0064500baaa28ad04fc2dbde221805e632f..5f82b21069ef3784be7f008c0b7f07428b81c069
mode 000000,100644..100644
--- /dev/null
@@@ -1,0 -1,89 +1,89 @@@
 -M: unix-io destruct-handle ( obj -- ) unix:close drop ;
+ ! Copyright (C) 2007 Elie Chaftari, Doug Coleman.
+ ! See http://factorcode.org/license.txt for BSD license.
+ USING: alien.c-types alien.syntax destructors hexdump io
+ io.buffers io.nonblocking io.sockets
+ io.unix.backend io.unix.files kernel libc locals math qualified
+ sequences io.sniffer.backend ;
+ QUALIFIED: unix
+ IN: io.sniffer.bsd
++M: unix-io destruct-handle ( obj -- ) unix:close ;
+ C-UNION: ifreq_props "sockaddr-in" "short" "int" "caddr_t" ;
+ C-STRUCT: ifreq { { "char" 16 } "name" } { "ifreq_props" "props" } ;
+ TUPLE: sniffer-spec path ifname ;
+ C: <sniffer-spec> sniffer-spec
+ : IOCPARM_MASK   HEX: 1fff ; inline
+ : IOCPARM_MAX    IOCPARM_MASK 1+ ; inline
+ : IOC_VOID       HEX: 20000000 ; inline
+ : IOC_OUT        HEX: 40000000 ; inline
+ : IOC_IN         HEX: 80000000 ; inline
+ : IOC_INOUT      IOC_IN IOC_OUT bitor ; inline
+ : IOC_DIRMASK    HEX: e0000000 ; inline
+ :: ioc ( inout group num len -- n )
+     group first 8 shift num bitor
+     len IOCPARM_MASK bitand 16 shift bitor
+     inout bitor ;
+ : io-len ( type -- n )
+     dup zero? [ heap-size ] unless ;
+ : io ( group num -- n )
+     IOC_VOID -rot 0 io-len ioc ;
+ : ior ( group num type -- n )
+     IOC_OUT -roll io-len ioc ;
+ : iow ( group num type -- n )
+     IOC_IN -roll io-len ioc ;
+ : iowr ( group num type -- n )
+     IOC_INOUT -roll io-len ioc ;
+ : BIOCGBLEN ( -- n ) "B" 102 "uint" ior ; inline
+ : BIOCSETIF ( -- n ) "B" 108 "ifreq" iow ; inline
+ : BIOCPROMISC ( -- n ) "B" 105 io ; inline 
+ : BIOCIMMEDIATE ( -- n ) "B" 112 "uint" iow ; inline
+ : make-ifreq-props ( ifname -- ifreq )
+     "ifreq" <c-object>
+     12 <short> 16 0 pad-right over set-ifreq-props
+     swap malloc-char-string dup free-always
+     over set-ifreq-name ;
+ : make-ioctl-buffer ( fd -- buffer )
+     BIOCGBLEN "char*" <c-object>
+     [ unix:ioctl io-error ] keep
+     *int <buffer> ;
+ : ioctl-BIOSETIF ( fd ifreq -- )
+     >r BIOCSETIF r> unix:ioctl io-error ;
+ : ioctl-BIOPROMISC ( fd -- )
+     BIOCPROMISC f unix:ioctl io-error ;
+ : ioctl-BIOCIMMEDIATE
+     BIOCIMMEDIATE 1 <int> unix:ioctl io-error ;
+ : ioctl-sniffer-fd ( fd ifname -- )
+     dupd make-ifreq-props ioctl-BIOSETIF
+     dup ioctl-BIOPROMISC
+     ioctl-BIOCIMMEDIATE ;
+ M: unix-io <sniffer> ( obj -- sniffer )
+     [
+         [
+             sniffer-spec-path
+             open-read
+             dup close-later
+         ] keep
+         dupd sniffer-spec-ifname ioctl-sniffer-fd
+         dup make-ioctl-buffer
+         input-port <port> <line-reader>
+         \ sniffer construct-delegate
+     ] with-destructors ;