&SCOPED-DEFINE BEG-STR "$Id:"
&SCOPED-DEFINE END-STR "$"
def temp-table zt-cvs
field seq as inte format ">>9" label "Seq"
field prog as char format "x(22)" label "Program"
field ver as char format "x(7)" label "Version"
field dt as char format "x(19)" label "Date/Time"
field dev as char format "x(8)" label "Dev"
index seq as primary unique
seq
index prog as unique
prog.
procedure cvs-scan:
define input parameter ps-file as char no-undo.
define var ys-text as char no-undo.
define var ys-cvs as char no-undo.
define var ys-prog as char no-undo.
define var ys-id as char no-undo.
define var yi-line as inte no-undo.
define var yi-lines as inte no-undo.
define var yi-seq as inte no-undo.
define var yi-beg as inte no-undo.
define var yi-end as inte no-undo.
define var yi-len as inte no-undo.
for each zt-cvs:
delete zt-cvs.
end.
if not file-found(r-code(ps-file)) then
RETURN.
/* store the r-code in an editor in a hidden frame */
define frame yf-text
ys-text view-as editor large size 319 by 10
with width 320.
hide frame yf-text.
ys-text:read-file(r-code(ps-file)).
yi-lines = ys-text:num-lines.
/* Delete lines until "index" finds "TXS", which marks the variable section */
do yi-line = 1 to yi-lines:
if index(ys-text:screen-value, "TXS") = 0 then
ys-text:delete-line().
else
LEAVE.
end. /* do yi-line = 1 to yi-lines: */
/* Remove all garbage preceeding the "TXS" for maximum "index" reach */
ys-text:set-selection(1, index(ys-text:screen-value, "TXS")).
ys-text:replace-selection-text("").
yi-seq = -1. /* start with 0 */
repeat:
/* Sometimes there are gaps exceeding 32767 bytes - skip gaps here */
if index(ys-text:screen-value, {&BEG-STR}) = 0 then do:
yi-lines = ys-text:num-lines.
/* Delete lines until "index" finds &BEG-STR */
do yi-line = 1 to yi-lines:
if index(ys-text:screen-value, {&BEG-STR}) = 0 then
ys-text:delete-line().
else
LEAVE.
end. /* do yi-line = 1 to yi-lines: */
/* Remove all garbage preceeding the &BEG-STR for maximum "index" reach */
ys-text:set-selection(1, index(ys-text:screen-value, {&BEG-STR})).
ys-text:replace-selection-text("").
end. /* if index(ys-text:screen-value, {&BEG-STR}) = 0 */
assign
yi-seq = yi-seq + 1
yi-beg = index(ys-text:screen-value, {&BEG-STR})
yi-end = index( ys-text:screen-value, {&END-STR}, yi-beg + 1)
no-error.
if yi-end = 0 then
LEAVE.
assign
yi-beg = yi-beg + length({&BEG-STR}) + 1
yi-len = yi-end - yi-beg - 1
ys-cvs = substring(ys-text:screen-value, yi-beg, yi-len)
ys-prog = entry(1, entry(1, ys-cvs, " "), ",")
.
/* If record exists, then we've scanned past the main variable section */
find zt-cvs where zt-cvs.prog = ys-prog no-error.
if available zt-cvs then
LEAVE.
create zt-cvs.
assign
zt-cvs.seq = yi-seq
zt-cvs.prog = ys-prog
zt-cvs.ver = entry(2, ys-cvs, " ")
zt-cvs.dt = entry(3, ys-cvs, " ") + " " + entry(4, ys-cvs, " ")
zt-cvs.dev = entry(5, ys-cvs, " ")
.
/* Delete as we go to avoid the 32767 byte limit on the "index" function */
ys-text:set-selection(1, yi-end).
ys-text:replace-selection-text("").
end. /* repeat */
end procedure. /* cvs-scan */