home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Merciful 3
/
Merciful_Release_3.bin
/
software
/
f
/
finalwriter
/
finalwriterv5.03a.dms
/
finalwriterv5.03a.adf
/
FWMacros.lha
/
FWListMerge
next >
Wrap
Text File
|
1994-09-28
|
7KB
|
199 lines
/* ======================================================================= */
/* Final Writer, Final Copy_II ARexx Macro */
/* FWListMerge - Perfoms a list merge from a Final Data database. */
/* $VER: FWListMerge 1.0 (27.7.94) */
/* © 1994 SoftWood, Inc. */
/* Use of this macro is strictly at the user's risk. */
/* */
/* This ARexx macro is to be run from FinalCopy_II or FinalWriter. */
/* It performs a "List Merge" from a FinalData database. It will create */
/* a list of data from a database and put it into your FC or FW document. */
/* To run the macro you need to have your FC or FW document and your */
/* Final Data database file both open. */
/* */
/* Select the rows in the database that you wish to have included in the */
/* list. If no rows are selected then all the rows in the database will be */
/* included in the list. (Note that this macro will use the first database */
/* port that it can find, so it is wise to have only one database window */
/* open when you run this macro. Otherwise the wrong database may be used).*/
/* */
/* In the document window you need to set up a line of text that will tell */
/* the macro which columns of the database you want in the list. This line */
/* of text should include at least one column name from the database, */
/* surrounded by the delimiter characters. (The delimiter charaters are */
/* '<' and '>', but can be set to whatever characters you want by changing */
/* the "begDelim =" and "endDelim =" lines below.) For example, you might */
/* have a line such as: */
/* <First Name> <Last Name> <Phone> */
/* Before you run the macro, place the insertion point somewhere on the */
/* this line of text. When the macro is run it will extract the column */
/* data for each row in the database and substitute the column data for */
/* the column name. You might end up with something like: */
/* <First Name> <Last Name> <Phone> */
/* John Doe 555-1111 */
/* Jane Smith 555-1212 */
/* Fred Flintstone 555-2222 */
/* Note that only the column names will have data substituted. Anything */
/* else on the line will remain in each row of data. This allows you to */
/* separate the columns with tabs or have other text appear on all lines. */
/* ======================================================================= */
OPTIONS RESULTS
/* ---- Load the rexxsupport library ---- */
IF ( ADDLIB("rexxsupport.library", 0, -30, 0) = FALSE) THEN EXIT 20
/* ---- Delimiters for column names. ---- */
begDelim = "<"
endDelim = ">"
/* ---- Get the address of the port we were called from. ---- */
WPPort = ADDRESS()
HostId = LEFT(WPPort, 7)
IF ( HostId ~= "FINALC." & HostId ~= "FINALW." ) THEN DO
IF ( HostId = "FINALD." ) THEN
ShowMessage 1 1 '"This macro must be run from" "FinalCopy_II or FinalWriter!" "" "OK" "" ""'
EXIT 10
END
/* ---- Find the address of the Final Data port. ---- */
/* ---- This will use the first port it can find ---- */
/* ---- with the base name of FinalD. --------------- */
FDPortBase = "FINALD."
found = 0
DO p = 1 TO 50
IF ( SHOWLIST('P', FDPortBase || p) ) THEN DO
FDPort = FDPortBase || p
found = 1
LEAVE
END
END
IF ( ~ found ) THEN DO
ShowMessage 1 1 '"Can not find Final Data ARexx port!" "" "" "OK" "" ""'
EXIT 10
END
/* ---- Determine the number of columns and rows in the database. ---- */
ADDRESS VALUE FDPort
NumRows
nrows = RESULT
NumColumns
ncols = RESULT
IF ( nrows = 0 ) THEN DO
ShowMessage 1 1 '"No rows of data in database!" "" "" "OK" "" ""'
EXIT 10
END
IF ( ncols = 0 ) THEN DO
ShowMessage 1 1 '"No columns defined in database!" "" "" "OK" "" ""'
EXIT 10
END
/* ---- Determine which rows will get transferred. If ---------- */
/* ---- selection is ROWS then only use the selected rows. ----- */
/* ---- Otherwise, use all the rows in the database. ----------- */
firstRow = 1
lastRow = nrows
SelectionInfo
PARSE VAR RESULT selType selFrom selTo
IF ( selType = "ROWS" ) THEN DO
firstRow = selFrom
lastRow = selTo
END
/* ---- Select and extract the data of the current wp line. ---- */
ADDRESS VALUE WPPort
CtrlDown
AltDown
Cursor Left
ShiftDown
Cursor Right
Extract
OrigText = RESULT
ShiftUp
Cursor Right
CtrlUp
AltUp
NewParagraph
/* ---- Determine indexes into original text ------- */
/* ---- Set up the Data structure for the merge ---- */
ADDRESS VALUE FDPort
numFlds = 0
txtlen = LENGTH(OrigText)
start = 1
err = 0
DO FOREVER
/* ---- Search for beginning delimiter. ------- */
/* ---- If we don't find one, leave the ------- */
/* ---- loop, as there are no more fields. ---- */
begidx = INDEX(OrigText, begDelim, start)
IF ( begidx = 0 ) THEN LEAVE
/* ---- Search for ending delimiter. ---- */
/* ---- If we can't find one, leave ----- */
/* ---- the loop with an error. --------- */
endidx = INDEX(OrigText, endDelim, begidx)
IF ( endidx = 0 ) THEN DO
err = 1
LEAVE
END
start = endidx
/* ---- We found beginning and ending delimiters. ---- */
/* ---- Save some data needed for the merge. --------- */
Data.numFlds.fldbeg = begidx
Data.numFlds.fldend = endidx
cname = SUBSTR(OrigText, begidx+1, endidx-begidx-1)
cname = '"' || cname || '"' /* need quotes in case name has spaces */
GetColumnPosition NAME cname
IF ( RC ~= 0 ) THEN DO
err = 2
LEAVE
END
Data.numFlds.colpos = RESULT
numFlds = numFlds + 1
END /* end forever loop */
IF ( err = 0 & numFlds = 0 ) THEN err = 3
IF ( err ~= 0 ) THEN DO
SELECT
WHEN ( err = 1 ) THEN DO
ShowMessage 1 1 '"Ending delimiter not found!" "" "" "OK" "" ""'
END
WHEN ( err = 2 ) THEN DO
ShowMessage 1 1 '"Column name not found in database:"' cname '"" "OK" "" ""'
END
WHEN ( err = 3 ) THEN DO
ShowMessage 1 1 '"No columns found to merge!" "" "" "OK" "" ""'
END
OTHERWISE DO
END
END /* end select */
EXIT 10
END
/* ---- We don't want the newline character at the end of the text. ---- */
lastChar = RIGHT(OrigText, 1)
IF ( lastChar = D2C(10) ) THEN
OrigText = DELSTR(OrigText, LENGTH(OrigText), 1)
/* ---- Do the actual merging of the data. ---- */
DO r = firstRow TO lastRow
ADDRESS VALUE FDPort
newText = OrigText
DO i=numFlds-1 TO 0 BY -1
CellData Data.i.colpos r
newData = RESULT
newText = DELSTR(newText, Data.i.fldbeg, Data.i.fldend - Data.i.fldbeg + 1)
newText = INSERT(newData, newText, Data.i.fldbeg-1)
END
ADDRESS VALUE WPPort
Type newText
IF ( r ~= lastRow ) THEN
NewParagraph
END /* end row */
/* END OF MACRO FILE */