home *** CD-ROM | disk | FTP | other *** search
- /*
- * Parse_PCF.rexx
- *
- * USAGE: Parse_PCF(OleObj,SpreadFile,Range)
- *
- * This script take the hard job of parsing a PCF file format to extract
- * all usefull information to help programs that need to manage ProCalc
- * worksheet. In future this module of my OLE system will be written in C
- * to speed-up the operation.
- *
- * $(C): (1994, Rocco Coluccelli, Bologna)
- * $VER: Parse_PCF.rexx 1.24 (17.Oct.1994)
- */
-
- LF = '0A'X
-
- PARSE ARG oleobj,spreadfile,range
-
- NUMERIC DIGITS 4
-
- IF ~OPEN(pcf,spreadfile,'R') THEN EXIT 20
-
- /*
- * Set default values for all cells
- */
- row. = 0
- col. = 0
- cell. = 0
- data. = 0
- exts. = 'þTOPAZÞ' 8 0 0 0 0
-
- /*
- * Set alignements left right center
- */
- def.0.001 = 100
- def.1.001 = 010
- def.0.000 = 010
- def.1.000 = 100
- def.0.010 = 010
- def.1.010 = 010
- def.1.100 = 001
- def.0.100 = 001
-
-
- IF ~OPEN(pip,'PIPE:' || oleobj,'W') THEN DO
- CALL CLOSE(pcf)
- EXIT 20
- END
-
- CALL WRITELN(pip,spreadfile)
- CALL WRITELN(pip,range)
-
- minrow = 10000
- maxrow = 1
- mincol = 10000
- maxcol = 1
-
- DO UNTIL range = ''
- PARSE VAR range firstcell':'lastcell range
-
- pos = POS('-',firstcell)
- head = (pos = 0)
- firstcell = SUBSTR(firstcell,pos + 1)
-
- PARSE VALUE To_coords(firstcell) To_coords(lastcell) WITH startrow startcol endrow endcol .
-
- DO i = startrow TO endrow
- row.i = 1
-
- DO j = startcol TO endcol
- cell.i.j = head
- END
- END
-
- DO j = startcol TO endcol
- col.j = 1
- END
-
- minrow = MIN(minrow,startrow)
- maxrow = MAX(maxrow,endrow)
- mincol = MIN(mincol,startcol)
- maxcol = MAX(maxcol,endcol)
- END
-
- /*
- * Read all chunks in the input file
- */
- DO FOREVER
-
- PARSE VALUE READCH(pcf,3) WITH head +1 len +2
- head = C2D(head)
- len = C2D(len)
-
- SELECT
-
- /*
- * Number cell
- * Label cell
- */
- WHEN head = 110 | head = 120 | head = 100 THEN DO
- PARSE VALUE READCH(pcf,len) WITH row +2 col +2 rest
-
- row = C2D(row)
- col = C2D(col)
- IF ~cell.row.col THEN ITERATE
-
- IF head = 100 THEN
- PARSE VAR rest bitset +4 color +1 len +1 rest
- ELSE
- PARSE VAR rest bitset +4 color +1 +3 ieee +8 len +1 rest
-
- PARSE VALUE C2B(bitset) WITH +17 italic +1 bold +1 underline +1 align +3 .
-
- len = C2D(len)
- PARSE VAR rest +len len +1 text '00'x
- len = C2D(len) - 1
-
- IF len = -1 THEN DO
- text = C2F(ieee)
- len = LENGTH(text)
- END
-
- num = DATATYPE(text,'N')
-
- data.row.col = def.num.align bold italic underline C2D(color) len 'þ'text'Þ'
- END
-
- /*
- * Extended cell informations
- */
- WHEN head = 125 & cell.row.col THEN DO
-
- PARSE VALUE READCH(pcf,len) WITH font'.font' +1 size +2 bits +2
- PARSE VALUE C2B(bits) WITH +1 ldown +1 lup +1 lright +1 lleft +1 .
-
- exts.row.col = 'þ'UPPER(font)'Þ' C2D(size) lleft lright lup ldown
-
- END
-
- /*
- * Default format for cells and rows
- * under construction
- */
- WHEN head = 16 | head = 17 THEN DO
- CALL SEEK(pcf,len)
- END
-
- /*
- * Reached end of file
- */
- WHEN head = 0 THEN DO
- CALL CLOSE(pcf)
- LEAVE
- END
-
- /*
- * Skip forward unknown chunks
- */
- OTHERWISE CALL SEEK(pcf,len)
-
- END /* end SELECT */
-
- END /* end DO */
-
-
- /*
- * Reformat the output table
- */
- row = 0
- DO i = minrow TO maxrow
-
- IF row.i THEN DO
- row = row + 1
- row.i = row
- END
- END
-
- col = 0
- DO j = mincol TO maxcol
-
- IF col.j THEN DO
- col = col + 1
- col.j = col
- END
- END
-
-
- /*
- * When the parse process has finished write out the result.
- *
- * HEADER:
- * spreadfile
- * ranges
- * rows cols
- *
- * DATAS:
- * row col align bold italic underline color len 'þ'text'Þ' 'þ'font'Þ' size lleft lright lup ldown
- *
- * (row col) of the cell, (len) length in chars of (text)
- * (align) aligned with (bold italic underline) style
- * typed in (color) with (font) of (size)
- * with borders (lineleft lineright lineup linedown)
- */
-
- CALL WRITELN(pip,row col)
-
- DO i = minrow TO maxrow
- DO j = mincol TO maxcol
-
- IF data.i.j ~= 0 THEN
- CALL WRITELN(pip,row.i col.j data.i.j exts.i.j)
- END
- END
-
- CALL CLOSE(pip)
-
- EXIT 0
-
-
- /*
- * convert cell coordinates into numbers
- */
- To_coords: PROCEDURE
- ARG cell .
-
- pos = VERIFY(cell,'0123456789','m')
- row = SUBSTR(cell,pos)
-
- cell = RIGHT(LEFT(cell,pos - 1),2,'40'X)
- col = (C2D(LEFT(cell,1)) - 64) * 26 + (C2D(RIGHT(cell,1)) - 64)
-
- RETURN row col
-
-
- C2F: PROCEDURE
- PARSE ARG ieee
-
- PARSE VALUE C2B(ieee) WITH s +1 e +11 fl +32 fh +20
-
- s = -1 ** s
- e = C2D(B2C(e)) - 1023
- f = '1.' || C2D(B2C(fl))
-
- RETURN s * f * (2 ** e)
-