%!ps % fixamp01.psl % Changes single ampersands to "&" in an xhtml document % ========================================================== % by Don Lancaster % Copyright c 2009 and earlier by Don Lancaster and Synergetics, Box 809, % Thatcher Arizona, 5552 (928) 428-4073 don@tinaja.com support % via http://www.tinaja.com All commercial rights and all electronic % media rights **FULLY** reserved. Reposting is expressly forbidden. % IMPORTANT NOTE: Don Lancaster's file gonzo.ps is optional for this program. % After obvious location mods, uncomment ONE of the following two lines: % (C:\\gonzo2\\gonzo.ps)run % use internal gonzo % use internal gonzo % (A:\\gonzo.ps) run % use external gonzo % NOTE THAT ALL PS FILENAME STRINGS !!!DEMAND!!! DOUBLE REVERSE SLASHES. % Gonzo is available as http://www.tinaja.com/post01.asp#gonzo with a % tutorial at http://www.tinaja.com/glib/gonzotut.pdf %%%%%%%%%%%%% % Newer versions of XHTML demand that all text ampersands are in a "&" % format. This PostScript program attempts to take a mix of uncorrected % and corrected ampersands and replace them with all correctly formatted. % Note that a bug in Dreamweaver will sometimes trash any internally % attempted corrections. And that eBay, government sites, and many % search documents may include dozens of ampersands per link. % The following algorithm is used: An iccoming file is character by % character copied to an output file. IF there is not a semicolon % within the next SEVEN characters and IF less than seven characters % from the end of the file, a "amp;" character sequence is inserted. % Note that other xhtml sequences (such as > or   might % have a variable number of characters between the ampersand % and the semicolon. And that the algorithm might rarely fail % on a non xhtml sequence that has both ampersands and semicolons % in it. % Also, ampersands inside JavaScript, Visual Basic, or other scripts may % need hand repatched. % To use, edit as a standard ASCII text file and send to Acrobat % Distiller. Distiller versions newer than 8.1 default to prohibiting % file writes and must be activated by a "run acrodist -F from the % Windows command line. % At present, input, output, and program files must be in the same folder. % Note that an "Empty Job - No File Produced" is normal and expected. % An excerpt from the Gonzo Utilities.... % mergestr merges the two top stack strings into one top stack string /mergestr {2 copy length exch length add string dup dup 4 3 roll 4 index length exch putinterval 3 1 roll exch 0 exch putinterval} def % /testforampersand does the insertion when needed /testforampersand { curchar (&) eq { readfile bytesavailable 8 gt { /curposn readfile fileposition store readfile (x) readstring pop (;) eq readfile (x) readstring pop (;) eq or readfile (x) readstring pop (;) eq or readfile (x) readstring pop (;) eq or readfile (x) readstring pop (;) eq or readfile (x) readstring pop (;) eq or readfile (x) readstring pop (;) eq or not {writefile (amp;) writestring } if readfile curposn setfileposition % restore to original next character } if % stop near end of file } if % only if an ampersand } store % /correctampersnds is the high level routine to do the actual corrections. % Presently limited to 10 Meg or smaller files. /correctampersands { /readfilename fileheader infilename mergestr store /readfile readfilename (r) file store /writefilename fileheader outfilename mergestr store /writefile writefilename (w+) file store 0 1 10000000 { readfile (x) readstring not {exit} if /curchar exch store writefile curchar writestring testforampersand } repeat % till end of input file readfile closefile writefile closefile } store %%%%%%%%%%%%%%%%%% demo - remove or alter before reuse %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % /fileheader (C:\\Documents and Settings\\don\\Desktop\\validate\\fixamps\\)def /infilename (mscalc01.asp) def /outfilename (mc01.asp) def % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% correctampersands % this does it % EOF