/* GPL(C) Mohsin Ahmed, http://www.cs.albany.edu/~mosh * SYNOPSIS: translate chars while doing i/o, don't ask why. * * translate( Infile:in, Outfile:in ): * read chars from Infile and * write translated chars to outfile. * translate: process the Infile to Outfile. * ie. convert to upcase alphabet, and compress spaces. * end_of_file = 26, * ascii A = 65 * ascii Z = 65+26-1=90 * ascii a = 97 * ascii z = 122+26-1=122 * ascii SPACE = 32 * ascii RETURN= 10 */ translate( Infile, Outfile ):- see( Infile ), tell( Outfile ), translate, seen, told. translate:- repeat, get0( C ), skipspaces( C, 0 ), C == 26. skipspaces( 32, 0 ):-!, put( 32 ), get0( C ), skipspaces( C, 1 ). skipspaces( 32, 1 ):-!, get0( C ), skipspaces( C, 1 ). skipspaces( C, _ ):- process( C ). process( C ):- 97 =< C, C =< 122, !, D is 65 + (C - 97), put(D). process( C ):- put(C). /* EOF */