]> gitweb.factorcode.org Git - factor.git/commitdiff
gopher: some aesthetics.
authorJohn Benediktsson <mrjbq7@gmail.com>
Thu, 27 Oct 2016 02:50:00 +0000 (19:50 -0700)
committerJohn Benediktsson <mrjbq7@gmail.com>
Thu, 27 Oct 2016 02:50:00 +0000 (19:50 -0700)
extra/gopher/gopher.factor
extra/gopher/server/server.factor

index b2b65f86b6f0ed9ce71f7e64afe23689fa4527bb..18d7a65b96d67ec3029145256e48d578f9d6ff99 100644 (file)
@@ -49,8 +49,7 @@ PRIVATE>
 ERROR: not-a-gopher-url url ;
 
 : gopher ( url -- item-type byte-array )
-    dup url? [ >url ] unless
-    dup protocol>> "gopher" = [ not-a-gopher-url ] unless {
+    >url dup protocol>> "gopher" = [ not-a-gopher-url ] unless {
         [ host>> ]
         [ port>> 70 or <inet> binary ]
         [ path>> rest [ "1/" ] when-empty ]
@@ -108,8 +107,7 @@ M: gopher-link >url
 PRIVATE>
 
 : gopher. ( url -- )
-    dup url? [ >url ] unless
-    [ path>> ] [ gopher swap ] bi {
+    >url [ path>> ] [ gopher swap ] bi {
         { A_TEXT [ gopher-text. ] }
         { A_MENU [ gopher-menu. ] }
         { A_INDEX [ gopher-menu. ] }
index 850ad3bce6eda4c6c7e244aadf5c6de45beee78d..a600fbd35ac6fc8f3a07f94192363c3149c39596 100644 (file)
@@ -48,6 +48,7 @@ TUPLE: gopher-server < threaded-server
 
 :: list-directory ( server path -- )
     path server serving-directory>> ?head drop [
+        [ "/" ] when-empty
         "i[%s]\t\terror.host\t1\r\n\r\n" sprintf
         utf8 encode write
     ] [
@@ -70,8 +71,8 @@ TUPLE: gopher-server < threaded-server
                 "%-40s %s %10s" sprintf
             ] [
                 path prepend-path
+                server serving-directory>> ?head drop
             ] bi
-            server serving-directory>> ?head drop
             server serving-hostname>>
             server insecure>>
             "%s%s\t%s\t%s\t%d\r\n" sprintf