home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / propage4.0 / arexx / autoimporttext.pprx < prev    next >
Encoding:
Text File  |  1996-02-07  |  8.5 KB  |  255 lines

  1. /*
  2. AutoImportText
  3.  
  4. This Genie will import text and create as many pages (copies of the current page, if any) as necessary to fit the text. "Essays" have indented paragraphs with a half-line gap between them.
  5. "Scripts" set margins as follows: paragraphs without codes are left unchanged; paragraphs beginning with a " are set as dialogue. Paragraphs beginning with : or ; are set as names of speakers. Character actions/manners of speaking are coded with a ( .
  6. In all cases type is 14 point.
  7.  
  8.  
  9. Written by Don Cox, Feb. 94, based on a Gold Disk original. Debug, June 94. Script format added Oct 94, Nov 94. Bug fixes Dec 94. Modified Feb 95. Bug fix, April 95. Bug fix, Sept. 95.
  10. */
  11. /* $VER: AutoImportText Sept 95 */
  12.  
  13. /*call open("STDERR","ram:traceAIT","W")
  14. trace r */ 
  15.  
  16. call SafeEndEdit.rexx()
  17. call ppm_AutoUpdate(0)
  18. currentunits = ppm_GetUnits()
  19. call ppm_SetUnits(2)
  20. address command
  21.  
  22. typesize = 14.000 /* You could change this */
  23. bigtypesize = 24.000
  24. currentpage = ppm_CurrentPage()
  25.  
  26. if currentpage ~= 0 then do /*  Page exists, select box */
  27.     filename = ppm_GetFileName("Open Text File:", "", "")
  28.     if filename = '' then call exit_msg()
  29.     box = ppm_ClickOnBox("Click on box in which to import text")
  30.     end
  31.  
  32. else do   /*  No page exists, make from default */
  33.     filename = ppm_GetFileName("Open Text File:", "", "")
  34.     if filename = '' then call exit_msg()
  35.     currentpage = ppm_CreatePage(1,1,1,1,0)
  36.     box = ppm_PageFirstBox(currentpage)
  37.     if box = '' then call exit_msg("No box on default page, cannot import text.")
  38.     end
  39.  
  40. startpage = currentpage
  41.  
  42. if box = 0 then exit_msg("No box selected")
  43. info    = ppm_GetBoxInfo(box)
  44. fword   = upper(word(info, 1))
  45. lword   = word(info, words(info))
  46.  
  47. if (fword ~= "EMPTY" & lword ~= "0") then exit_msg("You must select an empty text box to use this Genie")
  48. if word(info, 3) = 1 | word(info, 1) = word(info, 3) then leave
  49.  
  50. doparas = ppm_Inform(3, "Set paragraph indent?", "Essays", "Scripts", "No change")
  51. donumbers = 1
  52. if doparas = 2 then donumbers = ppm_Inform(2, "Number the pages?",,)
  53.  
  54. cpage = ppm_CurrentPage()
  55. pagebox = 0 /* Is there a page number box already? */
  56. testbox = ppm_PageFirstBox(cpage)
  57. do until testbox=0
  58.     info    = ppm_GetBoxInfo(box)
  59.     fword   = upper(word(info, 1))
  60.     lword   = word(info, words(info))
  61.     if upper(fword)="TEXT" then do
  62.         boxtxt = ppm_GetBoxText(testbox,1)
  63.         if (words(boxtxt)=2 & pos("Page \#<Pc0>",boxtxt)~=0) then pagebox = 1
  64.         end
  65.     if pagebox = 1 then numberbox = testbox
  66.     if pagebox = 1 then break
  67.     testbox = ppm_PageNextBox(testbox)
  68.     end
  69. if (donumbers = 0 & pagebox = 1) then do
  70.     DeleteIt = ppm_Inform(2, "Delete existing Page number box?",,)
  71.     if DeleteIt = 1 then call ppm_DeleteBox(numberbox)
  72.     end
  73.  
  74. /* make page number box */
  75. if donumbers = 1 then do
  76.     psize = ppm_GetPageSize(cpage)
  77.     startpage = cpage
  78.     pagewidth = word(psize,1)
  79.     pageheight = word(psize,2)
  80.     numberleft = pagewidth-6
  81.     numbertop = pageheight-2
  82.     numberbox = 0
  83.  
  84.     if pagebox = 0 then do
  85.         numberbox = ppm_CreateBox(numberleft, numbertop,3,1,0,)
  86.         call ppm_SetSize(12)
  87.         overflow = ppm_TextIntoBox(numberbox,"\jl\fs<12.000>Page \#<Pc0>")
  88.         end
  89.  
  90.     end
  91.  
  92. /* Go to first box of chain */
  93. prevbox = box
  94. outbox = 0
  95.  
  96. do forever
  97.     prevbox = ppm_ArtNextBox(prevbox)
  98.     if prevbox = 0 | ppm_BoxPage(prevbox) ~= currentpage then leave
  99.     outbox = prevbox
  100. end
  101.  
  102.  
  103. if doparas = 1 then do
  104.     call scriptimport /* pre-process script files */
  105.     success = ppm_DefineParaTag("<mainpara{UcMl<0.0>Mr<0.0>PnPs<150>}>")
  106.     success = ppm_DefineParaTag("<character{UcMl<0.0>Mr<0.0>PnPs<100>}>")
  107.     success = ppm_DefineParaTag("<characterLive{UcMl<190.0>Mr<0.0>PnPs<100>}>")
  108.     success = ppm_DefineParaTag("<dialogue{UcMl<100.0>Mr<100.0>PnPs<150>}>")
  109.     success = ppm_DefineParaTag("<manner{UcMl<125.0>Mr<125.0>PnPs<100>}>")
  110.     success = ppm_DefineParaTag("<mannerLive{UcMl<0.0>Mr<125.0>PnPs<100>}>")
  111.     success = ppm_DefineStyleTag("<character{\dP<character>\fs<"typesize">\jc}>")
  112.     success = ppm_DefineStyleTag("<dialogue{\dP<dialogue>\fs<"typesize">\jf}>")
  113.     success = ppm_DefineStyleTag("<manner{\dP<manner>\fs<"typesize">\jf}>")
  114.     success = ppm_DefineStyleTag("<characterLive{\dP<characterLive>\lr<180>\fs<"typesize">\jl}>")
  115.     success = ppm_DefineStyleTag("<dialogueLive{\dP<dialogue>\lr<180>\fs<"typesize">\jl}>")
  116.     success = ppm_DefineStyleTag("<mannerLive{\dP<mannerLive>\lr<180>\fs<"typesize">\jl}>")
  117.     success = ppm_DefineStyleTag("<mainstyleLive{\dP<mainpara>\lr<180>\fs<"typesize">\jf}>")    
  118. end
  119.  
  120. else if doparas = 0 then do
  121.     success = ppm_DefineParaTag("<mainpara{Pi<0.5>Ps<150>}>")
  122.     end
  123.  
  124. success = ppm_DefineParaTag("<quotes{Ml<80.0>Mr<80.0>PnPs<120>}>")
  125. success = ppm_DefineParaTag("<address{UcMl<200>Mr<0.000>PnPs<110>SW<0>SC<0>Tb}>")
  126. success = ppm_DefineParaTag("<solid{UcMbPnPs<100>SW<0>SC<0>Tb}>")
  127.  
  128. success = ppm_DefineStyleTag("<mainstyle{\dP<mainpara>\fs<"typesize">\jf}>")
  129. success = ppm_DefineStyleTag("<quotes{\dP<quotes>\fs<"typesize">\I\jf}>")
  130. success = ppm_DefineStyleTag("<heading{\dp\B\fs<"bigtypesize">\jl\lr<120>\c<Grey 15%>}>")
  131. success = ppm_DefineStyleTag("<address{\dP<address>\fs<"typesize">\jr\lr<120>\c<Black>}>")
  132. success = ppm_DefineStyleTag("<solid text{\dP<solid>\ff<(CG)Times>\fs<"typesize">\jl\K\H\lr<120>\c<Black>}>")
  133. call ppm_SetStyleTag("mainstyle")
  134.  
  135.  
  136. if ~ppm_ImportText(box, filename) then call exit_msg("Could not import "filename" - box not empty?") /* Box must be empty for flowing text */
  137.  
  138. call ppm_SetMagMode(100)
  139. moretodo = ppm_TextOverFlow( box )
  140.  
  141. if ~moretodo then exit_msg("Done")
  142. boxoff = boxoffset(box, currentpage)
  143. if outbox = 0 then do
  144.     outbox = box
  145.     outboxoff = boxoff
  146.     end
  147. else
  148.     outboxoff = boxoffset(outbox, currentpage)
  149.  
  150. do while moretodo
  151.     call ppm_CopyPage(currentpage, currentpage, 1)
  152.     call ppm_MovePage(currentpage, currentpage + 1)
  153.     currentpage = currentpage + 1
  154.     box = ppm_PageFirstBox(currentpage)
  155.     fbox = box
  156.     do boxoff
  157.         box = ppm_PageNextBox(box)
  158.         end
  159.     call ppm_DeleteContents(box)
  160.     call ppm_LinkBox(outbox, box)
  161.     outbox = fbox
  162.     do outboxoff
  163.         outbox = ppm_PageNextBox(outbox)
  164.         end
  165.     moretodo = ppm_TextOverFlow(outbox)
  166.  
  167.     if moretodo then do
  168.         info    = ppm_GetBoxInfo(box)
  169.         b_width = word(info,5)
  170.         if (b_width = 0) then exit_msg("Word too wide for box.")
  171.         end
  172.     end
  173.  
  174. newpage = ppm_GoToPage(startpage)
  175. numpages = currentpage-startpage+1
  176. if numpages = 1 then call ppm_DeleteBox(numberbox) /* Don't number 1 page */
  177.  
  178. call exit_msg("Made "numpages" pages")
  179.  
  180. /* +++++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++++  */
  181.  
  182. /* Box Offset Procedure */
  183. boxoffset: procedure
  184. do
  185.     arg box, page
  186.     cbox = ppm_PageFirstBox(page)
  187.     bcount = 0
  188.     do while cbox ~= 0
  189.         if cbox = box then return(bcount)
  190.         cbox = ppm_PageNextBox(cbox)
  191.         bcount = bcount + 1
  192.     end
  193.     exit_msg("An internal error has occurred. Please try again")
  194. end
  195.  
  196. /* ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++ */
  197.  
  198. /* Exit Msg Procedure */
  199. exit_msg: 
  200. do
  201.     parse arg message
  202.     if message ~= '' then call ppm_Inform(1, message,)
  203.     call ppm_AutoUpdate(1)
  204.     call ppm_SetUnits(currentunits)
  205.     exit
  206. end
  207.  
  208. /* ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++ */
  209.  
  210. scriptimport:
  211.  
  212. stype = ppm_Inform(3, "Type of Script?", "Abort", "Live Tape", "Film")
  213. if stype = 0 then exit_msg("Aborted by User")
  214.  
  215.  
  216. temptext="ram:temp.text"
  217. call open("input",filename)
  218. call open("temp",temptext,"W")
  219. do until eof("input")
  220.     instring = readln("input")
  221.     outstring = ""
  222.     if instring~="" then do
  223.         stringlength = length(instring)
  224.         instring = strip(instring,"B")
  225.         
  226.         firstchar = left(instring,1)
  227.         parastring = ""
  228.         select /* begin paras with a code character */
  229.             when firstchar ="(" then parastring = "\dS<manner>"
  230.             when firstchar ='"' then do
  231.                 parastring = "\dS<dialogue>"
  232.                 instring = strip(instring,"L",'"')
  233.                 end
  234.             when firstchar =":" then do
  235.                 parastring = "\dS<character>"
  236.                 instring = strip(instring,"L",":")
  237.                 end
  238.             when firstchar =";" then do
  239.                 parastring = "\dS<character>"
  240.                 instring = strip(instring,"L",";")
  241.                 end
  242.             otherwise parastring = "\dS<mainstyle>"
  243.             end
  244.         if stype = 1 then do
  245.             if parastring~= "" then parastring = compress(parastring,">")||"Live>"
  246.             end
  247.         outstring = parastring||instring
  248.         end
  249.  
  250.     call writeln("temp",outstring)
  251.     end
  252. call close("temp")
  253.  
  254. filename = temptext
  255. return