% MINERVA (c) IF Computer 1996,97 % http://www.ifcomputer.com/MINERVA mailto:support@ifcomputer.com % standalone application main([Source|_]) :- write('MINERVA Crawl Application started..'),nl, flush_output, urlGet(Source). % open the URL, then read it, then write to standard output urlGet(Source) :- write('Trying to open Url '),write(Source),nl, flush_output, catch( open(Source, read, InputStream, [url,buffered,text]), AnyError, sorry(open(Source),AnyError) ), readAndWrite(InputStream), !. urlGet(_Source). readAndWrite(InputStream) :- write('Url opened..'),nl, flush_output, readLines(InputStream,Lines), write('Reading done..'),nl,flush_output, current_output(OutputStream), writeLines(OutputStream,Lines), write('Writing done.. Done!'),nl, flush_output,!. % if the url does not exist or is not accessible, e,g, network down % ** no catch/3 found for: error(existence_error(source_sink,'http://www.ifcomputer.com/MINERVA'),[]) sorry(Goal,SomeError) :- write('Oooops: '),writeq(Goal),nl, write(' caused: '), write(SomeError),nl, fail. readLines(Stream,Lines) :- get_line(Stream, Line), !, Lines = [Line|Rest], readLines(Stream, Rest). readLines(_, []). writeLines(_Stream,[]). writeLines(Stream,[Line|Lines]) :- write(Stream,Line),nl,flush_output(Stream), writeLines(Stream,Lines).