Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!emory!att!ucbvax!ANDREW.CMU.EDU!wjh+ From: wjh+@ANDREW.CMU.EDU (Fred Hansen) Newsgroups: comp.soft-sys.andrew Subject: Re: RTF to ATK translator ready for beta tests Message-ID: <0bj0sla00VsPQ4JYwQ@andrew.cmu.edu> Date: 15 Feb 91 16:37:05 GMT References: <1991Feb7.060949.16153@ibmpa.awdpa.ibm.com> Sender: daemon@ucbvax.BERKELEY.EDU Organization: The Internet Lines: 86 Excerpts from internet.info-andrew: 7-Feb-91 Re: RTF to ATK translator r.. david@uunet.uu.net (752) > I'd be real interested in an ATK to RTF translator. This shouldn't be too hard, but I've already overstepped my quota on ATK work for this month. The skeleton program (function main) would be like fromrtf.n. Function convert() would essentially have a loop over the text applying nextstylesegment() to get each segment. Each segment would be output as a group with appropriate style codes at its beginning; this is generated by an enormous if-sequence testing for each style with hasstyles(). I would plan to deal only with the styles in default.tpl; if others were common, they could be handled by modifying the code. In particular, it could be extended to cover all the special styles utilized in fromrtf.n. The code below is for illustrative purposes only; it has not been compiled, let alone tested. If anyone does try this out, I'd sure like to know what happens. Fred Hansen - - - - - - marker lineEnd := "\n" -- could be \r function rtfPrefix() -- maybe add a fonttbl and a stylesheet return "\\rtf1\\ansi" end function -- stick in a newline every so often function breakup(text) marker outtext := newbase() marker m while text /= "" do m := nextn(start(text), 78) if extent (finish(text), m) /= "" then m := text else m := extent(text, m) end if outtext ~:= m ~ lineEnd text := extent(finish(m), text) end while return outtext end function -- determine rtf styles for ATK styles -- NOTE: the style names in quotations are merely suggestive. -- The important fact is that the first character of the quoted string -- has the given style name. function stylesfor(text) marker styles := newbase() if hasstyles(text, "italic") then styles ~:= "\\i "end if if hasstyles(text, "bold") then styles ~:= "\\b "end if if hasstyles(text, "formatnote") then -- ought to extract header, footer, or page number information styles ~:= "\\v " -- make it hidden for now end if if hasstyles(text, "hidden") then styles ~:= "\\v " end if if hasstyles(text, "description") then styles ~:= "\\li720\\fi720 " end if -- and so on for all the styles in default.tpl end function function convert(text) marker outtext := "{" ~ rtfPrefix() marker m := start(text) while True do m := nextstylesegment(m) if extent(finish(text), m) /= "" then -- extends off the end of text m := extent(m, text) end if if m = "" then return outtext ~ "}" ~ lineEnd end if outtext ~:= "{" ~ stylesfor(m) ~ breakup(m) ~ "}" ~ lineEnd end while end function