wjh+@ANDREW.CMU.EDU (Fred Hansen) (02/07/91)
Several people with Microsoft Word documents have asked if they can be translated into ATK, so I've implemented a translator from RTF to ATK; RTF is one of the formats that can be written by Microsoft Word. This translator doesn't get everything, but does a great job in many cases. To see how well it really works, I need some people to try it out. If you want to translate from RTF to ATK and are willing to send back bug reports, send me a note and I'll send the translator. Incidentally, a recent message asked what Ness is for. One task it excels at is writing translators from one document format to another, especially when one of those formats is ATK. The RTF to ATK translator is written in Ness. Fred Hansen
david@ibmpa.awdpa.ibm.com (02/07/91)
In article <wbg8GvW00VsP04ZG54@andrew.cmu.edu> wjh+@ANDREW.CMU.EDU (Fred Hansen) writes: >If you want to translate from RTF to ATK and are willing to send back >bug reports, send me a note and I'll send the translator. Actually, I'd be real interested in an ATK to RTF translator. Any chance? ------------------------------------------------------------------------------- David Berkowitz uunet!ibmsupt!david (415) 855-4485 | You get shown the light, | in the strangest IBM Personal Systems Programming, Palo Alto | of places, This does not represent an official IBM position. | if you look at it right. -------------------------------------------------------------------------------
wjh+@ANDREW.CMU.EDU (Fred Hansen) (02/16/91)
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