home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / utilities / propage_pdraw / donsgenies / propagegenies.lha / ImportAmigaGuide.pprx < prev    next >
Encoding:
Text File  |  1995-07-11  |  7.8 KB  |  252 lines

  1. /*
  2. Import AmigaGuide
  3.  
  4. This Genie will import AmigaGuide format text and create as many pages (copies of the current page, if any) as necessary to fit the text. 
  5.  
  6. Written by Don Cox, Jul. 95, based on AutoImportText.
  7. */
  8. /* $VER: ImportAmigaGuide Jul 95 */
  9.  
  10. /*call open("STDERR","ram:traceIA","W")
  11. trace r */ 
  12.  
  13. call SafeEndEdit.rexx()
  14. call ppm_AutoUpdate(0)
  15. currentunits = ppm_GetUnits()
  16. call ppm_SetUnits(2)
  17. address command
  18.  
  19. temptext="PPage:temp.text" /* temp. file - you could change this */
  20. typesize = 9.000 /* You could change this */
  21. bigtypesize = 24.000
  22. currentpage = ppm_CurrentPage()
  23.  
  24. if currentpage ~= 0 then do /*  Page exists, select box */
  25.     filename = ppm_GetFileName("Open AmigaGuide File:", "", "")
  26.     if filename = '' then call exit_msg()
  27.     box = ppm_ClickOnBox("Click on box in which to import text")
  28.     end
  29.  
  30. else do   /*  No page exists, make from default */
  31.     filename = ppm_GetFileName("Open AmigaGuide File:", "", "")
  32.     if filename = '' then call exit_msg()
  33.     currentpage = ppm_CreatePage(1,1,1,1,0)
  34.     box = ppm_PageFirstBox(currentpage)
  35.     if box = '' then call exit_msg("No box on default page, cannot import text.")
  36.     end
  37.  
  38. startpage = currentpage
  39.  
  40. if box = 0 then exit_msg("No box selected")
  41. info    = ppm_GetBoxInfo(box)
  42. fword   = upper(word(info, 1))
  43. lword   = word(info, words(info))
  44.  
  45. if fword ~= "EMPTY" & lword ~= "0" then exit_msg("You must select an empty text box to use this Genie")
  46. if word(info, 3) = 1 | word(info, 1) = word(info, 3) then leave
  47.  
  48. donumbers = ppm_Inform(2, "Number the pages?",,)
  49.  
  50. cpage = ppm_CurrentPage()
  51. pagebox = 0 /* Is there a page number box already? */
  52. testbox = ppm_PageFirstBox(cpage)
  53. do until testbox=0
  54.     boxtxt = ppm_GetBoxText(testbox,1)
  55.     if (words(boxtxt)=2 & pos("Page \#<Pc0>",boxtxt)~=0) then pagebox = 1
  56.     if pagebox = 1 then numberbox = testbox
  57.     if pagebox = 1 then break
  58.     testbox = ppm_PageNextBox(testbox)
  59.     end
  60. if (donumbers = 0 & pagebox = 1) then do
  61.     DeleteIt = ppm_Inform(2, "Delete existing Page number box?",,)
  62.     if DeleteIt = 1 then call ppm_DeleteBox(numberbox)
  63.     end
  64.  
  65. /* make page number box */
  66. if donumbers = 1 then do
  67.     psize = ppm_GetPageSize(cpage)
  68.     startpage = cpage
  69.     pagewidth = word(psize,1)
  70.     pageheight = word(psize,2)
  71.     numberleft = pagewidth-6
  72.     numbertop = pageheight-2
  73.     numberbox = 0
  74.  
  75.     if pagebox = 0 then do
  76.         numberbox = ppm_CreateBox(numberleft, numbertop,3,1,0,)
  77.         call ppm_SetSize(12)
  78.         overflow = ppm_TextIntoBox(numberbox,"\jl\fs<12.000>Page \#<Pc0>")
  79.         call ppm_SetSize(typesize)
  80.         end
  81.  
  82.     end
  83.  
  84. /* Go to first box of chain */
  85. prevbox = box
  86. outbox = 0
  87.  
  88. do forever
  89.     prevbox = ppm_ArtNextBox(prevbox)
  90.     if prevbox = 0 | ppm_BoxPage(prevbox) ~= currentpage then leave
  91.     outbox = prevbox
  92. end
  93.  
  94.  
  95.  
  96. call guideproc /* pre-process file */
  97.  
  98.  
  99. if ~ppm_ImportText(box, filename) then call exit_msg("Could not import "filename" - box not empty?") /* Box must be empty for flowing text */
  100.  
  101. call ppm_ShowStatus("  Importing AmigaGuide file into Pro Page ...")
  102.  
  103. call ppm_SetMagMode(100)
  104. moretodo = ppm_TextOverFlow( box )
  105.  
  106. if ~moretodo then exit_msg("Done")
  107. boxoff = boxoffset(box, currentpage)
  108. if outbox = 0 then do
  109.     outbox = box
  110.     outboxoff = boxoff
  111.     end
  112. else
  113.     outboxoff = boxoffset(outbox, currentpage)
  114.  
  115. do while moretodo
  116.     call ppm_CopyPage(currentpage, currentpage, 1)
  117.     call ppm_MovePage(currentpage, currentpage + 1)
  118.     currentpage = currentpage + 1
  119.     box = ppm_PageFirstBox(currentpage)
  120.     fbox = box
  121.     do boxoff
  122.         box = ppm_PageNextBox(box)
  123.         end
  124.     call ppm_DeleteContents(box)
  125.     call ppm_LinkBox(outbox, box)
  126.     outbox = fbox
  127.     do outboxoff
  128.         outbox = ppm_PageNextBox(outbox)
  129.         end
  130.     moretodo = ppm_TextOverFlow(outbox)
  131.  
  132.     if moretodo then do
  133.         info    = ppm_GetBoxInfo(box)
  134.         b_width = word(info,5)
  135.         if (b_width = 0) then exit_msg("Word too wide for box.")
  136.         end
  137.     end
  138.  
  139. newpage = ppm_GoToPage(startpage)
  140. numpages = currentpage-startpage+1
  141. if numpages = 1 then call ppm_DeleteBox(numberbox) /* Don't number 1 page */
  142.  
  143. call exit_msg("Made "numpages" pages")
  144.  
  145. /* +++++++++++++++++++++++++++++++  ++++++++++++++++++++++++++++++++  */
  146.  
  147. /* Box Offset Procedure */
  148. boxoffset: procedure
  149. do
  150.     arg box, page
  151.     cbox = ppm_PageFirstBox(page)
  152.     bcount = 0
  153.     do while cbox ~= 0
  154.         if cbox = box then return(bcount)
  155.         cbox = ppm_PageNextBox(cbox)
  156.         bcount = bcount + 1
  157.     end
  158.     exit_msg("An internal error has occurred. Please try again")
  159. end
  160.  
  161. /* ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++ */
  162.  
  163. /* Exit Msg Procedure */
  164. exit_msg: 
  165. do
  166.     parse arg message
  167.     if message ~= '' then call ppm_Inform(1, message,)
  168.     call ppm_AutoUpdate(1)
  169.     call ppm_ClearStatus()
  170.     call ppm_SetUnits(currentunits)
  171.     exit
  172. end
  173.  
  174. /* ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++ */
  175.  
  176. guideproc:  /* convert AmigaGuide codes */
  177.  
  178. call ppm_ShowStatus("  Processing AmigaGuide file...")
  179.  
  180. call open("input",filename)
  181. call open("temp",temptext,"W")
  182. linecount = 0
  183. do until eof("input")
  184.     instring = readln("input")
  185.     linecount = linecount+1
  186.     if linecount//25=0 then do
  187.         call ppm_ShowStatus("  Processing AmigaGuide file, line "linecount) 
  188.         end
  189.     posn1 = 1
  190.     posn2 = 2
  191.     outstring = ""
  192.     if instring~="" then do
  193.         stringlength = length(instring)
  194.         if left(instring,1) = " " then do
  195.             instring = substr(instring,2) /* remove leading space */
  196.             instring = "\N"||instring /* replace with N space */
  197.             end
  198.         do until posn1=0
  199.             upstring = upper(instring)
  200.             if pos("@REMARK",upstring)~=0 then instring = " "
  201.             if pos("@ENDNODE",upstring)~=0 then instring = " "
  202.             if pos("@DNODE",upstring)~=0 then instring = " "
  203.             if pos("@MASTER",upstring)~=0 then instring = " "
  204.             if pos("@NEXT",upstring)~=0 then instring = " "
  205.             if pos("@PREV",upstring)~=0 then instring = " "
  206.             if pos("@TOC",upstring)~=0 then instring = " "
  207.             if pos("@INDEX",upstring)~=0 then instring = " "
  208.             if pos("@DATABASE",upstring)~=0 then instring = substr(instring,10)
  209.             if pos("@$VER:",upstring)~=0 then instring = substr(instring,2)
  210.             if pos("@AUTHOR",upstring)~=0 then instring = substr(instring,2)
  211.             if pos("@TITLE",upstring)~=0 then instring = substr(instring,8)
  212.             if pos("@(C)",upstring)~=0 then instring=substr(instring,2)
  213.             if pos("@NODE", upstring)~=0 then instring = "\P"
  214.             posn1 = pos("@{",instring,posn1)
  215.             if posn1 = 0 then break
  216.             posn2 = pos("}",instring,posn1)
  217.             if posn2 = 0 then break
  218.  
  219.             newcode = ""
  220.             codelength = posn2-posn1+1
  221.             codestring = substr(instring,posn1,codelength)
  222.             instring = delstr(instring,posn1,codelength)
  223.             select
  224.                 when upper(codestring) = "@{U}" then newcode = "\U"
  225.                 when upper(codestring) = "@{UU}" then newcode = "\u"
  226.                 when upper(codestring) = "@{FG HIGHLIGHT}" then newcode="\B"
  227.                 when upper(codestring) = "@{FG TEXT}" then newcode = "\b"
  228.                 when upper(codestring) = "@{B}" then newcode = "\B"
  229.                 when upper(codestring) = "@{UB}" then newcode = "\b"
  230.                 otherwise newcode = ""
  231.                 end
  232.             linkpos = pos(" LINK ",upper(codestring))
  233.             if linkpos~=0 then do
  234.                 codestring = left(codestring,linkpos-1)
  235.                 codestring = strip(codestring,"L","@")
  236.                 newcode = strip(codestring,"L","{")
  237.                 end
  238.             instring = insert(newcode,instring,(posn1-1))
  239.             end
  240.         outstring = instring
  241.         end
  242.  
  243.     if outstring ~== " " then call writeln("temp",outstring)
  244.  
  245.     end  /* eof input */
  246. call close("temp")
  247.  
  248. filename = temptext
  249. return
  250.  
  251.  
  252.