(load "html2list.scm")
(load "getlinks.scm")
(define scm-c-dir "/mit/jrising/webtree/scm-c/")
(define (main)
(let ((search (to-search-url (prompt-for-expression "Enter search")))
(output (open-output-file (string-append scm-c-dir "search.toc"))))
(write-string "lynx -source \"http://www.google.com/search?q=" output)
(write-string search output)
(write-string (string-append "\" > " scm-c-dir "htmldata.html\n") output)
(close-port output)
(let ((htmltext (get-htmldata (wait-for-files))))
(display "Interpretting html text...")
(let ((htmlist (interpret-page htmltext)))
(newline)
(display "Finding links...")
(let ((links (getlinks hlst
(lambda (link)
(not (my-substring link "google.com"))))))
(newline)
(display "Done!"))))))
(define (wait-for-files)
(let ((newfiles
(filter (lambda (pathname)
(and (pathname-type pathname)
(not (string=? (pathname-type pathname) "toc"))))
(directory-read scm-c-dir))))
(if (not (null? newfiles))
(begin
(display "Recieved: ")
(display (->namestring (car newfiles)))
(newline)
(->namestring (car newfiles)))
(wait-for-files))))
(define (to-search-url expr)
(if (list? expr)
(accumulate (lambda (word str)
(if (string-null? str)
(to-search-url word)
(string-append (to-search-url word) "+" str)))
""
expr)
(symbol->string expr)))
(define (accumulate proc init lst)
(if (null? lst)
init
(proc (car lst) (accumulate proc init (cdr lst)))))
(define (filter test lst)
(if (null? lst)
nil
(if (test (car lst))
(cons (car lst) (filter test (cdr lst)))
(filter test (cdr lst)))))
(define nil '())