wjh+@ANDREW.CMU.EDU (Fred Hansen) (01/10/90)
Yes, we can convert table objects to ASCII comma separated tables. Here is the input: \begindata{table,269544420} \rows 0 11 0 0 \cols 113 99 99 57 62 =[r,c-1]+[r,c-2] =[r-1,c+1]-3 12 22 63 'ab =+[r-1,c-1]+[r-2,c-1]+[r-3,c-1] 91 \enddata{table,269544420} and here is the resulting output 57,62,=[r,c-1]+[r,c-2] =[r-1,c+1]-3,12,22 63, , 'ab,=+[r-1,c-1]+[r-2,c-1]+[r-3,c-1],91 The rules I used were to remove lines beginning with backslashes and change all tabs to commas. (If you've more information about the required ACSII format, the program can be revised.) FredH PS. Here is the program: ---- Enclosure ---- -- tbl2ascii.n -- ThisNess program converts an ATK table to ASCII with comma separated fields. -- The ends of rows are indicated with newlines. -- formulas begin with = -- quoted strings begin with ' " or ^ for left, right, and center justification -- To run this program, store the table in a file, say /tmp/t.table and execute -- nessrun tbl2ascii.n /tmp/t.table -- the output will be a file with the same base name and the extension .ascii: /tmp/t.ascii -- (if the destination file existed, its name is changed by adding the extension .old) --- stripline(m) -- remove everything from start(m) to after the next newline -- function stripline(m) marker s s := search(m, "\n") if s = "" then s := base(m) end if replace (extent(m, s), "") end function --stripbackslashlines(text) -- strips from the text all lines which begin with backslash -- function stripbackslashlines(t) -- throughout, t is an empty marker just before the start of a line t := start(t) while next(t) = "\\" do stripline(t) end while while TRUE do t := search(t, "\n\\") if t = "" then exit while end if t := finish(first(t)) stripline(t) end while end function --tabstocommas(text) -- convert all tabs to commas -- function tabstocommas(t) while true do t := search(t, "\t") if t = "" then exit while end if replace(t, ",") t := finish(t) end while end function function main(args) marker filename, outname, text -- determine input and output names from the command line argument filename := token(args, "qwertyuiopasdfghjklzxcvbnm" ~ "QWERTYUIOPASDFGHJKLZXCVBNM" ~ "~./0123456789") outname := search(filename, ".") text := search(finish(outname), ".") while text /= "" do outname := text text := search(finish(outname), ".") end while if outname = "" or search(outname, "/") /= "" or extent(next(outname), filename) = "d" then outname := filename ~ ".ascii" else outname := extent(filename, outname) ~ "ascii" end if -- tell user what's happening printline("tbl2ascii: " ~ filename ~ " -> " ~ outname) -- move the destination out of the way -- (this generates a spurious error if the destination does NOT exist) system("mv " ~ outname ~ " " ~ outname ~ ".old") -- read the text -- prepend a backslash to text to prevent trying to read it as an -- ATK object and to have the first line stripped system ("echo -n \\\\ | cat - " ~ filename ~ " > " ~ outname) text := readfile(outname) printline(text) -- process the text stripbackslashlines(text) tabstocommas(text) writefile(outname, text) end function ---- Enclosure ----