fun isSpace c = case c of #" " => true | #"\n" => true | #"\t" => true | _ => false fun skipSpaces inStream = case TextIO.lookahead inStream of SOME c => if isSpace c then (TextIO.input1 inStream; skipSpaces inStream) else () | _ => () fun readString inStream = let fun readRest s = case TextIO.lookahead inStream of SOME c => if isSpace c then s else (TextIO.input1 inStream; readRest (s ^ String.str c)) | _ => s in (skipSpaces inStream; readRest "") end fun readAndPrintLoop inStream = if TextIO.endOfStream inStream then () else ( print (readString inStream ^ "\n"); readAndPrintLoop inStream ) fun processFile processor file = let val inStream = TextIO.openIn file in ( processor inStream; TextIO.closeIn inStream ) end fun analyzeFile file = processFile readAndPrintLoop file ; fun copyChar inStream = case TextIO.input1 inStream of SOME c => print (String.str c) | NONE => () fun copyFile inStream = if TextIO.endOfStream inStream then () else ( copyChar inStream; copyFile inStream ) fun printFile file = processFile copyFile file ;