#!/usr/bin/env icon # # palval.icn -- validate palindrome pages. # 26-Nov-2018 / gmt # # Prints those lines of palinwrd.htm and palinsen.htm that are not # palindromic. Should only print headers if the files are correct. link html procedure main() dofile("palinwrd.htm") dofile("palinsen.htm") end procedure dofile(fname) #: process one input file local f, s f := open(fname) | stop("cannot open ", fname) write("\n", fname, ":") while s := htchunks(f) do if *s > 0 & s[1] ~== '<' then { s := clean(s) if not ispal(s) then write(s) } close(f) end procedure clean(s) #: remove HTML entities like & and " local t t := "" s ? { while t ||:= tab(upto('&')) do tab(upto(';')+1) t ||:= tab(0) } return t end procedure ispal(s) #: succeed if s is a palindrome local t s := map(s, &ucase, &lcase) t := "" s ? while tab(upto(&lcase)) do t ||:= tab(many(&lcase)) return t == reverse(t) end