Compare commits
1
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0f55fc23f3 |
@@ -0,0 +1,217 @@
|
||||
begin gened
|
||||
;
|
||||
class Gened = {Base}
|
||||
;
|
||||
let Gened.trace = @false
|
||||
;
|
||||
let Gened.name = ''
|
||||
let Gened.query = ''
|
||||
;
|
||||
let Gened.breakInfo = ''
|
||||
let Gened.breakCount = 0
|
||||
;
|
||||
let Gened.recordCount = 0
|
||||
let Gened.init = @true
|
||||
let Gened.first = @true
|
||||
let Gened.last = @false
|
||||
let Gened.currentRecord = ''
|
||||
let Gened.precRecord = ''
|
||||
;
|
||||
; breakInfo, champs en multi-valeurs :
|
||||
let Gened.BREAKFIELDNUM = 1 ; {1} = num champ dans l'enregistrement
|
||||
let Gened.BREAKFIELDVAL = 2 ; {2} = valeur champ enreg en cours
|
||||
let Gened.BREAKFIELDVALPREC = 3 ; {2} = valeur champ enreg en cours
|
||||
let Gened.BREAKDIFF = 4 ; {4} = flag si difference pour ce niveau
|
||||
let Gened.BREAKCOUNTER = 5 ; {5} = compteur d'enregs pour ce niveau de rupture
|
||||
;
|
||||
sub Gened.ParamSection()
|
||||
; maj de name/query/breakInfo{1}
|
||||
if this.trace then
|
||||
echonl "ED => in ParamSection"
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.SetQuery()
|
||||
; creer la requete de recuperation des enregistrements (utilise query)
|
||||
if this.trace then
|
||||
echonl "ED => in SetQuery"
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.GetNextRecord()
|
||||
; recupere l'enregistrement suivant, et l'ecrit dans this.currentRecord et this.last = @false, sinon this.last = @true et this.currentRecord = ''
|
||||
if this.trace then
|
||||
echonl "ED => in GetNextRecord"
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.EndOfQuery()
|
||||
; terminer la requete de recup. des enregistrements
|
||||
if this.trace then
|
||||
echonl "ED => in EndOfQuery"
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.InitSection()
|
||||
if this.trace then
|
||||
echonl "ED => in InitSection"
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.DoSection()
|
||||
if this.trace then
|
||||
echonl "ED => in DoSection, record #23":this.recordCount:' => ':this.currentRecord
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.EndSection()
|
||||
if this.trace then
|
||||
echonl "ED => in EndSection"
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.LevelBreakHeader(level)
|
||||
if this.trace then
|
||||
echonl "ED => in LevelBreakHeader:":level:' ':field(this.breakInfo{this.BREAKFIELDVAL, level}, "#FC", level)
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.LevelBreakFooter(level)
|
||||
if this.trace then
|
||||
echonl "ED => in LevelBreakFooter:":level:' ':field(this.breakInfo{this.BREAKFIELDVALPREC, level}, "#FC", level):' last(':this.last:')'
|
||||
endif
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub Gened.Execute()
|
||||
declare un, moinsUn, breakVal, breakNum ; compteur des niveaux de rupture
|
||||
let un = 1
|
||||
let moinsUn = neg(1)
|
||||
declare SVM
|
||||
let SVM = "#FC"
|
||||
let breakVal = ''
|
||||
let breakNum = 0
|
||||
;
|
||||
do this.ParamSection()
|
||||
;
|
||||
do this.SetQuery()
|
||||
;
|
||||
do this.GetNextRecord()
|
||||
;
|
||||
let this.recordCount = 0
|
||||
let this.breakCount = dcount(this.breakInfo, this.BREAKFIELDNUM)
|
||||
;
|
||||
do this.InitSection()
|
||||
;
|
||||
if not(this.last) then
|
||||
loop
|
||||
breakon this.last
|
||||
if not(this.init) then
|
||||
do this.GetNextRecord()
|
||||
else
|
||||
let this.init = @false
|
||||
endif
|
||||
;
|
||||
foreach breakNum in un, this.breakCount
|
||||
let breakVal = this.currentRecord{ this.breakInfo{this.BREAKFIELDNUM, breakNum} }
|
||||
if breakNum > un then
|
||||
let breakVal = this.breakInfo{this.BREAKFIELDVAL, breakNum - 1}:SVM:breakVal
|
||||
endif
|
||||
let this.breakInfo{this.BREAKFIELDVAL, breakNum} = breakVal
|
||||
let this.breakInfo{this.BREAKDIFF, breakNum} = (this.breakInfo{this.BREAKFIELDVALPREC, breakNum} # breakVal)
|
||||
endfor
|
||||
;
|
||||
if this.breakCount > 0 and (this.first or this.last or this.breakInfo{4, this.breakCount}) then
|
||||
if not(this.first) then
|
||||
foreach breakNum in this.breakCount, un, moinsUn
|
||||
if this.last or this.breakInfo{this.BREAKDIFF, breakNum} then
|
||||
do this.LevelBreakFooter(breakNum)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
if not(this.last) then
|
||||
foreach breakNum in un, this.breakCount
|
||||
if this.first or this.breakInfo{this.BREAKDIFF, breakNum} then
|
||||
let this.breakInfo{this.BREAKCOUNTER, breakNum} = 0
|
||||
do this.LevelBreakHeader(breakNum)
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
let this.first = @false
|
||||
endif
|
||||
;
|
||||
if not(this.last) then
|
||||
foreach breakNum in un, this.breakCount
|
||||
let this.breakInfo{this.BREAKCOUNTER, breakNum} = this.breakInfo{this.BREAKCOUNTER, breakNum} + 1
|
||||
endfor
|
||||
let this.recordCount = this.recordCount + 1
|
||||
;
|
||||
do this.DoSection()
|
||||
;
|
||||
let this.precRecord = this.currentRecord
|
||||
let this.breakInfo{this.BREAKFIELDVALPREC} = this.breakInfo{this.BREAKFIELDVAL}
|
||||
endif
|
||||
endloop
|
||||
endif
|
||||
;
|
||||
do this.EndSection()
|
||||
;
|
||||
do this.EndOfQuery()
|
||||
;
|
||||
except
|
||||
; TODO
|
||||
echonl "Exception in Execute"
|
||||
endsub
|
||||
;
|
||||
class EdTest = {Gened}
|
||||
;
|
||||
sub EdTest.SetQuery()
|
||||
declare path
|
||||
let path = 'data.txt'
|
||||
let this.data = ''
|
||||
let this.line = 0
|
||||
;
|
||||
invoke file&get(path, this.data)
|
||||
let this.data = change(this.data, '#0A', @fm)
|
||||
;
|
||||
let this.breakInfo = "3":@vm:5
|
||||
;
|
||||
do parent.SetQuery
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub EdTest.InitSection()
|
||||
;echonl 'nb break: ':this.breakCount
|
||||
do parent.InitSection
|
||||
except
|
||||
endsub
|
||||
;
|
||||
sub EdTest.GetNextRecord()
|
||||
let this.line = this.line + 1
|
||||
let this.currentRecord = this.data{this.line}
|
||||
if this.currentRecord = '' then
|
||||
let this.last = @true
|
||||
else
|
||||
let this.currentRecord = change(this.currentRecord, ';', @fm)
|
||||
endif
|
||||
;echonl "EdTest GetNextRecord: ":this.last:' / line ':this.line:' => ':this.currentRecord
|
||||
except
|
||||
endsub
|
||||
;
|
||||
declare ed
|
||||
let ed = new EdTest
|
||||
let ed.trace = @true
|
||||
do ed.Execute()
|
||||
;
|
||||
except
|
||||
;
|
||||
echonl "Exception in main: ":@except
|
||||
end
|
||||
Reference in new issue
Block a user