;;; Selector type inference
-(define (has-suffix? selector . suffixes)
- (if (null? suffixes)
+(define (true-for-one? predicate values)
+ (if (null? values)
#f
- (if (string-suffix? (car suffixes) selector)
+ (if (predicate (car values))
#t
- (apply has-suffix? selector (cdr suffixes)))))
+ (true-for-one? predicate (cdr values)))))
+
+(define (has-suffix? selector . suffixes)
+ (true-for-one? (lambda (suffix)
+ (string-suffix? suffix selector))
+ suffixes))
+
+(define (has-prefix? selector . prefixes)
+ (true-for-one? (lambda (prefix)
+ (string-prefix? prefix selector))
+ prefixes))
(define (infer-selector-type selector)
(let ((l (string-downcase selector)))
((has-suffix? l ".txt" ".org" ".md") 0)
((has-suffix? l ".png" ".jpg" ".gif" ".bmp" ".tif" ".tga") 'I)
((has-suffix? l "?.scm") 7)
+ ((has-prefix? l "url:" "/url:") 'h)
(else 9))))
((1) (serve-directory selector config))
((0) (serve-text-file selector config))
((7) (serve-query selector arguments config))
+ ((h) (serve-url selector config))
(else (serve-binary-file selector config)))))
(define (serve-directory selector config)
(error "Invalid query." selector arguments))))
+(define (serve-url selector config)
+ (let ((url (substring selector 4)))
+ (print
+ "If you are seeing this page, your gopher browser does not\r\n"
+ "properly support URL directory entries or cannot follow such\r\n"
+ "links. To view the link you requested, use a web browser to\r\n"
+ "open the follwing url:\r\n"
+ "\r\n"
+ url "\r\n")))
+
+
;;; Index rendering
(define (serve-info-records string)