From 6b58ebd22d7161e749382e3c7834908ba98ffa18 Mon Sep 17 00:00:00 2001 From: erana Date: Wed, 1 Feb 2012 17:28:01 +0900 Subject: [PATCH] spider function --- s48/cavespider/load.scm | 27 ++++++++++++++------------- s48/cavespider/string-util.scm | 8 ++++---- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/s48/cavespider/load.scm b/s48/cavespider/load.scm index a16d560..8eee273 100644 --- a/s48/cavespider/load.scm +++ b/s48/cavespider/load.scm @@ -29,20 +29,22 @@ (load "client.scm") (define (spider-f) - (spider-rec (list hostname) 0)) - -(define (spider-rec hostname-list index) - (let ((file-contents (file->string (string-append dir-filename "/" "index.html")))) - (let ((url-list (file-contents->url file-contents 0))) - (let ((dir-filename (ask-server (string-append "GET / HTTP/1.0" (string #\return #\newline #\return #\newline)) "index.html" hostname port))) - (let ((hostname-list (append hostname-list (url->hostname url-list '()))) - (keyword-list (file-contents->keyword file-contents keyword))) - - (hash-set! table (string-append keyword (number->string index)) file-contents);;NOTE keys are variable due to append above - (spider-rec (cdr hostname-list) (+ index 1)) - ))))) + (spider-rec "" (list hostname) 0)) +(define (spider-rec dir-file-name hostname-list index) + (cond ((or (null? hostname-list) + (string=? (car hostname-list) "")) + (newline)("spidering ended.")(newline)) + (else + (let ((dir-file-name-after (ask-server (string-append "GET / HTTP/1.0" (string #\return #\newline #\return #\newline)) "index.html" (car hostname-list) port))) + (let ((file-contents (file->string (string-append dir-file-name-after "/" "index.html")))) + (let ((url-list (file-contents->url file-contents 0))) + (let ((hostname-list (append hostname-list (url->hostname url-list '()))) + (keyword-list (file-contents->keyword file-contents keyword))) + (hash-set! table (string-append keyword (number->string index)) file-contents);;NOTE keys are variable due to append above + (spider-rec dir-file-name-after (cdr hostname-list) (+ index 1)) + ))))))) (display "give hostname name : ") @@ -53,7 +55,6 @@ (display "give port : ") (define port (number->string (read))) (newline) -;;(define dir-filename (ask-server (string-append "GET / HTTP/1.0" (string #\return #\newline #\return #\newline)) "index.html" hostname port)) (display "give string to search for (no spaces): ") (define keyword (symbol->string (read))) diff --git a/s48/cavespider/string-util.scm b/s48/cavespider/string-util.scm index 60d1382..15c8af7 100644 --- a/s48/cavespider/string-util.scm +++ b/s48/cavespider/string-util.scm @@ -74,12 +74,12 @@ (set! hostname-list (append (list rets) (url->hostname (cdr url-list) hostname-list))) ) - rets) - rets) + hostname-list) + hostname-list) (begin ;;(display s) - rets)) - rets)) + hostname-list)) + hostname-list)) ;;test