BRIGHT@DALAC.BITNET (BOB BRIGHT) (01/17/88)
Following is a small gift for Word Perfect users: an Icon program which converts .DOC files created by that miserable-excuse-for-a-word-processor- which-came-bundled-with-our-machines into WP files. To run it you'll need the ICONT translator and ICONX run-time programs (available at listserv@canada01, atarinet, and any number of other places, I imagine). To translate the program, double-click on ICONT.TTP and enter 1STWD2WP.ICN on the command line. When the translator is finished, you can throw away the .U1 and .U2 files; 1STWD2WP.ICX is all you'll need. To run the program, double-click on ICONX.TTP and enter 1STWD2WP.ICX on the command line (or "Install" ICONX.TTP with an ICX extension, and then double-click on 1STWD2WP.ICX itself). The program will prompt for the name of the input and output files (defaults to .DOC and .WP extensions, respectively). It will search the current directory and root directories of A: and D:, but you can specify a full pathname if you wish. (You could also edit the .ICN file before you translate it, if you want different default paths and extensions.) The program reads and converts each line of the input file, writing to output as it goes. Putting everything in a ramdisk will speed things up quite a bit. It will preserve all of the underlining, italics, bold, super- and subscripting in your .DOC file (but *not* 1st Word's light-faced type), and look after such things as hard and soft CR's. You'll have to fix up your block-indented quotes and whatnot a bit, but that's relatively easy to do once you've got the converted file into Word Perfect. Also, if you convert a .DOC file that was saved double-spaced, you'll get an extra space before each soft CR, so resave it single-spaced first. This hasn't been tested much, since my main concern was to translate some of the papers I'd been working on into WP format. (This is the kind of "quick-and-dirty" application that Icon excels at, BTW.) The program worked fine for me, but use it at your own risk (and, it goes without saying, keep backups of your .DOC files until you're *certain* the .WP file is OK). BBB Bob Bright <BRIGHT@DALAC.BITNET> Philosophy Dept. Dalhousie University Halifax, NS B3H 3J5 ---------------- cut here for 1STWD2WP.ICN ---------------- global name, io procedure main() write(" *****************************_ \n * FILE CONVERSION UTILITY *_ \n * 1st_Word .DOC *_ \n * to *_ \n * Word Perfect *_ \n * *_ \n * v1.0 *_ \n * 2 December 1987 *_ \n * (c) BBB *_ \n *****************************\n\n") #================================================================== # open files for input and output #================================================================== # get name of .DOC file to convert, call fileopen procedure writes("Please specify name of 1st_Word file to convert: ") name := read() || ".DOC" fileopen("1st_Word file to convert") infile := io line := read(infile) if line[1] c== "\x1F" then { writes(name," is not a 1st Word .DOC file. _ Do you wish to proceed? (y/n): ") if read() c== "y" then stop("Execution terminated.") } # replace original extension of filename with ".WP", call fileopen again name := name[1:find(".",name)] name := name||".WP" writes("Please specify output name for Word Perfect file [",name,"]: ") i := read() if i c== "" then name := i fileopen("output file","wu") #"wu" so \x0A is not translated to \x0D\x0A outfile := io writes(outfile,"\x80\x80") #at the start of every WP file #================================================================== # initialize variables #================================================================== bold := 0 und := 0 ital := 0 sup := 0 sub := 0 codes := "\x80\x81\x82\x83\x84\x85\x86\x87\x88\x89\x8A\x8B\x8C\x8D\x8E\x8F_ \x90\x91\x92\x93\x94\x95\x96\x97\x98\x99\x9A\x9B\x9C\x9D\x9E\x9F_ \xA0\xA1\xA2\xA3\xA4\xA5\xA6\xA7\xA8\xA9\xAA\xAB\xAC\xAD\xAE\xAF" #=================================================================== # read infile a line at a time, and # (i) delete all stretch spaces (\x1C) # (ii) convert variable spaces (\x1E) to " " # (iii) convert tab spaces to \x09 # (iv) convert "-" to \xA9 # (v) add super & subscripts up to the first escape character # (vi) search for changes in 1st word styling parameters, convert # to word perfect format # (vii) write line to outfile, with soft or hard returns as required #==================================================================== while line := read(infile) do { #first check to see if it's a 1st word format line if line[1] == "\x1F" then next #delete stretch spaces while i := find("\x1C",line) do line[i] := "" #convert varspaces to " " while i := find("\x1E",line) do line[i] := " " #convert tab spaces to \x09 while i := find("\x1D",line) do line[i] := "\x09" #convert "-" to A9 while i := find("-",line) do line[i] := "\xA9" #add super & subscripts up 1st escape char. if sub=1 then { c := 1 while line[c] c== "\e" do { if line[c] >> "\x1F" then if line [c] << "\x7F" then { line[c] := "\xBD"||line[c] c +:= 1 } c +:= 1 } } if sup=1 then { c := 1 while line[c] c== "\e" do { if line[c] >> "\x1F" then if line [c] << "\x7F" then { line[c] := "\xBC"||line[c] c +:= 1 } c +:= 1 } } #now find 1st_word styling codes and convert to WP styling while i := find("\e",line) do { num := find(line[i+1],codes)-1 #init. num to integer value of # styling code following \e rep := "" #initialize replacement string # test for subscript on if num >= 32 then { num -:= 32 sub := 1 c := i+1 while line[c] c== "\e" do { if line[c] >> "\x1F" then if line [c] << "\x7F" then { line[c] := "\xBD"||line[c] c +:= 1 } c +:= 1 } } else sub := 0 #test for superscript on if num >= 16 then { num -:= 16 sup := 1 c := i+1 while line[c] c== "\e" do { if line[c] >> "\x1F" then if line [c] << "\x7F" then { line[c] := "\xBC"||line[c] c +:= 1 } c +:= 1 } } else sup := 0 #test for underline on if num >= 8 then { num -:= 8 if und=0 then { rep := rep||"\x94" und := 1 } } else if und=1 then { rep := rep||"\x95" und := 0 } #test for italics on if num >= 4 then { num -:= 4 if ital=0 then { rep := rep||"\xB2" ital := 1 } } else if ital=1 then { rep := rep||"\xB3" ital := 0 } #cut out light-faced type if num >= 2 then num -:= 2 #test for bold on if num >= 1 then { if bold=0 then { rep := rep||"\x9D" bold := 1 } } else if bold=1 then { rep := rep||"\x9C" bold := 0 } #replace the 1st_word styling codes with rep line := line[1:i]||rep||line[i+2:0] } #write line to outfile with hard or soft return as needed if line[-1] == " " then writes(outfile,line[1:-1]||"\x0D") else if line[-1] == "\xA9" then writes(outfile,line||"\x0D") else if line[-1] == "\x09" then writes(outfile,line[1:-1]||"\x0D") else writes(outfile,line||"\x0A") writes(".") } write("\x0D\x0ACompleted conversion.") end ############################################### procedure fileopen(s1,s2) ucase := "ABCDEFGHIJKLMNOPQRSTUVWXYZ" lcase := "abcdefghijklmnopqrstuvwxyz" repeat { c := 1 #convert while name[c] do { #name to if i := find(name[c],lcase) then name[c] := ucase[i] #upper c +:= 1 #case. } if io := open(name,s2) then break #check current directory name2 := name name := "D:\\" || name2 #check root directory of D: if io := open(name,s2) then break name := "A:\\" || name2 #check root directory of A: if io := open(name,s2) then break writes("Cannot open ",name2,". Please re-specify ",s1,": ") name := read() #get name } end -------------------- end of 1STWD2WP.ICN -----------------------