home *** CD-ROM | disk | FTP | other *** search
- /*
- Import AmigaGuide
-
- 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.
-
- Written by Don Cox, Jul. 95, based on AutoImportText.
- */
- /* $VER: ImportAmigaGuide Jul 95 */
-
- /*call open("STDERR","ram:traceIA","W")
- trace r */
-
- call SafeEndEdit.rexx()
- call ppm_AutoUpdate(0)
- currentunits = ppm_GetUnits()
- call ppm_SetUnits(2)
- address command
-
- temptext="PPage:temp.text" /* temp. file - you could change this */
- typesize = 9.000 /* You could change this */
- bigtypesize = 24.000
- currentpage = ppm_CurrentPage()
-
- if currentpage ~= 0 then do /* Page exists, select box */
- filename = ppm_GetFileName("Open AmigaGuide File:", "", "")
- if filename = '' then call exit_msg()
- box = ppm_ClickOnBox("Click on box in which to import text")
- end
-
- else do /* No page exists, make from default */
- filename = ppm_GetFileName("Open AmigaGuide File:", "", "")
- if filename = '' then call exit_msg()
- currentpage = ppm_CreatePage(1,1,1,1,0)
- box = ppm_PageFirstBox(currentpage)
- if box = '' then call exit_msg("No box on default page, cannot import text.")
- end
-
- startpage = currentpage
-
- if box = 0 then exit_msg("No box selected")
- info = ppm_GetBoxInfo(box)
- fword = upper(word(info, 1))
- lword = word(info, words(info))
-
- if fword ~= "EMPTY" & lword ~= "0" then exit_msg("You must select an empty text box to use this Genie")
- if word(info, 3) = 1 | word(info, 1) = word(info, 3) then leave
-
- donumbers = ppm_Inform(2, "Number the pages?",,)
-
- cpage = ppm_CurrentPage()
- pagebox = 0 /* Is there a page number box already? */
- testbox = ppm_PageFirstBox(cpage)
- do until testbox=0
- boxtxt = ppm_GetBoxText(testbox,1)
- if (words(boxtxt)=2 & pos("Page \#<Pc0>",boxtxt)~=0) then pagebox = 1
- if pagebox = 1 then numberbox = testbox
- if pagebox = 1 then break
- testbox = ppm_PageNextBox(testbox)
- end
- if (donumbers = 0 & pagebox = 1) then do
- DeleteIt = ppm_Inform(2, "Delete existing Page number box?",,)
- if DeleteIt = 1 then call ppm_DeleteBox(numberbox)
- end
-
- /* make page number box */
- if donumbers = 1 then do
- psize = ppm_GetPageSize(cpage)
- startpage = cpage
- pagewidth = word(psize,1)
- pageheight = word(psize,2)
- numberleft = pagewidth-6
- numbertop = pageheight-2
- numberbox = 0
-
- if pagebox = 0 then do
- numberbox = ppm_CreateBox(numberleft, numbertop,3,1,0,)
- call ppm_SetSize(12)
- overflow = ppm_TextIntoBox(numberbox,"\jl\fs<12.000>Page \#<Pc0>")
- call ppm_SetSize(typesize)
- end
-
- end
-
- /* Go to first box of chain */
- prevbox = box
- outbox = 0
-
- do forever
- prevbox = ppm_ArtNextBox(prevbox)
- if prevbox = 0 | ppm_BoxPage(prevbox) ~= currentpage then leave
- outbox = prevbox
- end
-
-
-
- call guideproc /* pre-process file */
-
-
- if ~ppm_ImportText(box, filename) then call exit_msg("Could not import "filename" - box not empty?") /* Box must be empty for flowing text */
-
- call ppm_ShowStatus(" Importing AmigaGuide file into Pro Page ...")
-
- call ppm_SetMagMode(100)
- moretodo = ppm_TextOverFlow( box )
-
- if ~moretodo then exit_msg("Done")
- boxoff = boxoffset(box, currentpage)
- if outbox = 0 then do
- outbox = box
- outboxoff = boxoff
- end
- else
- outboxoff = boxoffset(outbox, currentpage)
-
- do while moretodo
- call ppm_CopyPage(currentpage, currentpage, 1)
- call ppm_MovePage(currentpage, currentpage + 1)
- currentpage = currentpage + 1
- box = ppm_PageFirstBox(currentpage)
- fbox = box
- do boxoff
- box = ppm_PageNextBox(box)
- end
- call ppm_DeleteContents(box)
- call ppm_LinkBox(outbox, box)
- outbox = fbox
- do outboxoff
- outbox = ppm_PageNextBox(outbox)
- end
- moretodo = ppm_TextOverFlow(outbox)
-
- if moretodo then do
- info = ppm_GetBoxInfo(box)
- b_width = word(info,5)
- if (b_width = 0) then exit_msg("Word too wide for box.")
- end
- end
-
- newpage = ppm_GoToPage(startpage)
- numpages = currentpage-startpage+1
- if numpages = 1 then call ppm_DeleteBox(numberbox) /* Don't number 1 page */
-
- call exit_msg("Made "numpages" pages")
-
- /* +++++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++ */
-
- /* Box Offset Procedure */
- boxoffset: procedure
- do
- arg box, page
- cbox = ppm_PageFirstBox(page)
- bcount = 0
- do while cbox ~= 0
- if cbox = box then return(bcount)
- cbox = ppm_PageNextBox(cbox)
- bcount = bcount + 1
- end
- exit_msg("An internal error has occurred. Please try again")
- end
-
- /* ++++++++++++++++++++++++++++ ++++++++++++++++++++++++++++++++++++++++ */
-
- /* Exit Msg Procedure */
- exit_msg:
- do
- parse arg message
- if message ~= '' then call ppm_Inform(1, message,)
- call ppm_AutoUpdate(1)
- call ppm_ClearStatus()
- call ppm_SetUnits(currentunits)
- exit
- end
-
- /* ++++++++++++++++++++++++++++++ +++++++++++++++++++++++++++++++++++++++ */
-
- guideproc: /* convert AmigaGuide codes */
-
- call ppm_ShowStatus(" Processing AmigaGuide file...")
-
- call open("input",filename)
- call open("temp",temptext,"W")
- linecount = 0
- do until eof("input")
- instring = readln("input")
- linecount = linecount+1
- if linecount//25=0 then do
- call ppm_ShowStatus(" Processing AmigaGuide file, line "linecount)
- end
- posn1 = 1
- posn2 = 2
- outstring = ""
- if instring~="" then do
- stringlength = length(instring)
- if left(instring,1) = " " then do
- instring = substr(instring,2) /* remove leading space */
- instring = "\N"||instring /* replace with N space */
- end
- do until posn1=0
- upstring = upper(instring)
- if pos("@REMARK",upstring)~=0 then instring = " "
- if pos("@ENDNODE",upstring)~=0 then instring = " "
- if pos("@DNODE",upstring)~=0 then instring = " "
- if pos("@MASTER",upstring)~=0 then instring = " "
- if pos("@NEXT",upstring)~=0 then instring = " "
- if pos("@PREV",upstring)~=0 then instring = " "
- if pos("@TOC",upstring)~=0 then instring = " "
- if pos("@INDEX",upstring)~=0 then instring = " "
- if pos("@DATABASE",upstring)~=0 then instring = substr(instring,10)
- if pos("@$VER:",upstring)~=0 then instring = substr(instring,2)
- if pos("@AUTHOR",upstring)~=0 then instring = substr(instring,2)
- if pos("@TITLE",upstring)~=0 then instring = substr(instring,8)
- if pos("@(C)",upstring)~=0 then instring=substr(instring,2)
- if pos("@NODE", upstring)~=0 then instring = "\P"
- posn1 = pos("@{",instring,posn1)
- if posn1 = 0 then break
- posn2 = pos("}",instring,posn1)
- if posn2 = 0 then break
-
- newcode = ""
- codelength = posn2-posn1+1
- codestring = substr(instring,posn1,codelength)
- instring = delstr(instring,posn1,codelength)
- select
- when upper(codestring) = "@{U}" then newcode = "\U"
- when upper(codestring) = "@{UU}" then newcode = "\u"
- when upper(codestring) = "@{FG HIGHLIGHT}" then newcode="\B"
- when upper(codestring) = "@{FG TEXT}" then newcode = "\b"
- when upper(codestring) = "@{B}" then newcode = "\B"
- when upper(codestring) = "@{UB}" then newcode = "\b"
- otherwise newcode = ""
- end
- linkpos = pos(" LINK ",upper(codestring))
- if linkpos~=0 then do
- codestring = left(codestring,linkpos-1)
- codestring = strip(codestring,"L","@")
- newcode = strip(codestring,"L","{")
- end
- instring = insert(newcode,instring,(posn1-1))
- end
- outstring = instring
- end
-
- if outstring ~== " " then call writeln("temp",outstring)
-
- end /* eof input */
- call close("temp")
-
- filename = temptext
- return
-
-
-