]> gitweb.factorcode.org Git - factor.git/commitdiff
gopher.server: adding a main.
authorJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 Mar 2021 22:26:27 +0000 (15:26 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Mon, 15 Mar 2021 22:26:27 +0000 (15:26 -0700)
extra/gopher/server/server.factor

index 1042fa3648d18530ea337071476287313f1d0fc4..b6f28aeb641339bdbaada0c4a6374c67e9f23222 100644 (file)
@@ -2,10 +2,10 @@
 ! See http://factorcode.org/license.txt for BSD license
 
 USING: accessors calendar combinators combinators.short-circuit
-formatting fry io io.directories io.encodings.binary
+command-line formatting io io.directories io.encodings.binary
 io.encodings.string io.encodings.utf8 io.files io.files.info
-io.files.types io.pathnames io.servers kernel locals math
-mime.types sequences splitting strings urls.encoding ;
+io.files.types io.pathnames io.servers kernel math mime.types
+namespaces sequences sorting splitting strings urls.encoding ;
 
 IN: gopher.server
 
@@ -64,8 +64,9 @@ TUPLE: gopher-server < threaded-server
     path [
         [ name>> "." head? ] reject
         [ { [ directory? ] [ regular-file? ] } 1|| ] filter
+        [ name>> ] sort-with
         [
-            [ gopher-type ] [ name>> ] bi
+            [ gopher-type ] [ name>> ] [ directory? [ "/" append ] when ] tri
             [
                 dup file-info [ file-modified ] [ file-size ] bi
                 "%-40s %s %10s" sprintf
@@ -115,3 +116,9 @@ PRIVATE>
 
 : start-gopher-server ( directory port -- server )
     <gopher-server> start-server ;
+
+: gopher-server-main ( -- )
+    command-line get ?first "." or
+    70 <gopher-server> start-server wait-for-server ;
+
+MAIN: gopher-server-main