home *** CD-ROM | disk | FTP | other *** search
- /*****************************************************************************/
- /* Announce utility for T-Fix */
- /* (c)1996 by Dmitry Dyakonov */
- /*****************************************************************************/
-
- InFile=''; OutFile=''; SelFile=''; TplFile='tfann.tpl'
- area.0=0; bytes.0=0; selectarea.0=0; fdpos=20; fdlen=20
- Version='1.1/REXX'; SortOption='yes'
- palka.1='|'; palka.2='/'; palka.3='─'; palka.4='\'; pidx=1
- annheader.0=0; annareaheader.0=0
- anntext.0=0
- annareafooter.0=0; annfooter.0=0
- lowfname='NO'
-
- say ; say 'Announce utility v'Version 'for T-Fix'
- parse arg InFile OutFile rest
- If InFile='' | OutFile='' Then call Usage
- If stream(InFile,'c','open read') \= 'READY:' Then
- call EndProgram "Can't open file:" InFile
- do i=1 to words(rest)
- p=word(rest,i)
- select
- when p='?' | p='/?' | p='-?' then call Usage
- when translate(p)='/NS' then SortOption='no'
- when substr(p,1,1)='@' then
- do
- SelFile=strip(p,'l','@')
- If stream(SelFile,'c','open read') \= 'READY:' Then
- call EndProgram "Can't open file:" SelFile
- call ReadSelect
- end
- when substr(p,1,1)='#' then TplFile=strip(p,'l','#')
- otherwise do
- selectarea.0=selectarea.0+1; i=selectarea.0;
- selectarea.i=translate(p)
- end
- end
- end
- If stream(TplFile,'c','open read') \= 'READY:' Then
- call EndProgram "Can't open file:" Tplfile
- call ReadTpl
- call ReadData
- if area.0 \= 0 then
- do
- do i=1 to area.0
- bytes.0=bytes.0+1; bytes.i=0
- do j=1 to files.i.0
- bytes.i=bytes.i+word(files.i.j,2)
- end
- end
- if SortOption = 'no' then say ' ■ Sorting areas: disabled.'
- else call SortFiles
- call Announce
- end
- call EndProgram 'Thanks for using this program.'
-
- /* ------------------------------------------------------------------------- */
- ReadTpl:
- do while lines(TplFile)
- str=linein(TplFile)
- if str='' | substr(str,1,1)=';' then iterate
- word=translate(word(str,1))
- select
- when word='LOWFNAME' then lowfname=translate(word(str,2))
- when word='ANNHEADER' then call read_section 'annheader'
- when word='ANNAREAHEADER' then call read_section 'annareaheader'
- when word='ANNTEXT' then call read_section 'anntext'
- when word='ANNAREAFOOTER' then call read_section 'annareafooter'
- when word='ANNFOOTER' then call read_section 'annfooter'
- otherwise iterate
- end
- end
- call stream TplFile,'c','close'
- return
-
- /* ------------------------------------------------------------------------- */
- read_section:
- parse arg array
- s=''; i=0
- do while lines(TplFile)
- s=linein(TplFile)
- if translate(word(s,1))='END' then leave
- interpret array'.0='array'.0+1'
- interpret 'i='array'.0'
- interpret array'.'i'="'s'"'
- end
- return
-
- /* ------------------------------------------------------------------------- */
- ReadData:
- do while lines(InFile)
- str=strip(linein(InFile))
- if str = "" then iterate
- parse var str word rest
- parse upper var word word
- select
- when word = "AREA" then
- do
- if selectarea.0 \= 0 then
- do
- if AreaCmp(word(rest,1))\=0 then
- do
- str=linein(InFile) /* skip file record */
- iterate
- end
- end
- i=QueryExist(word(rest,1))
- if i=0 then
- do
- area.0=area.0+1; i=area.0; area.i=rest; files.i.0=0
- end
- end
- when word = "FILE" then
- do
- files.i.0=files.i.0+1; j=files.i.0;
- files.i.j=translate(rest,'H','ì')
- end
- otherwise call lineout 'unknown.txt', str
- end
- end
- call stream InFile,'c','close'
- return
-
- /* ------------------------------------------------------------------------- */
- QueryExist: procedure expose area.
- do i=1 to area.0
- if compare(translate(Arg(1)),translate(word(area.i,1)))=0 then return i
- end
- return 0
-
- /* ------------------------------------------------------------------------- */
- ReadSelect: procedure expose SelFile selectarea.
- do while lines(SelFile)
- str=strip(linein(SelFile))
- if str = '' | substr(str,1,1) = ';' then iterate
- selectarea.0=selectarea.0+1; i=selectarea.0; selectarea.i=translate(str)
- end
- call stream SelFile,'c','close'
- return
-
- /* ------------------------------------------------------------------------- */
- Announce:
- If stream(OutFile,'c','open write') \= 'READY:' Then
- call EndProgram "Can't create/append file:" OutFile
-
- call handle_macros 'annheader'
- call handle_macros 'annareaheader'
- call handle_macros 'anntext'
- call handle_macros 'annareafooter'
- call handle_macros 'annfooter'
-
- call write_section 'annheader'
- do i=1 to area.0
- call write_section 'annareaheader'
- call WriteArea
- call write_section 'annareafooter'
- end
- call write_section 'annfooter'
- call stream OutFile,'c','close'; say left(' ■ Writing areas: done.',79)
- return
-
- /* ------------------------------------------------------------------------- */
- handle_macros:
- parse arg section
- interpret 'num =' section'.0'
- do m=1 to num
- interpret 'cmd =' section'.'m
- if pos('%', cmd) \= 0 then
- do
- cmd = section'.'m "= process_macro("section'.'m")"
- interpret cmd
- end
- end
- return
-
- /* ------------------------------------------------------------------------- */
- write_section:
- parse arg section
- interpret 'num =' section'.0'
- do m=1 to num
- interpret 'cmd =' section'.'m
- cmd = 'call lineout' OutFile', "'cmd'"'
- interpret cmd
- end
- return
-
- /* ------------------------------------------------------------------------- */
- WriteArea:
- do j=1 to files.i.0
- parse var files.i.j fname fsize fdesc
- ldesc.0=0
- call process_ld fdesc
- fdesc=ldesc.1
- do m=1 to anntext.0
- pidx=pidx+1; if pidx > 4 then pidx=1
- call charout ,left(' ■ Writing area:' word(area.i,1) palka.pidx,79)''d2c(13)
- interpret 'call lineout' OutFile', "'anntext.m'"'
- p = pos('fdesc', anntext.m)
- if p \= 0 then
- do
- p=lastpos('"',anntext.m,p)-1
- ld=substr(anntext.m, 1, p)
- interpret 'ld = "'ld'"'
- fdpos=length(ld)
- do k=2 to ldesc.0
- if substr(fdlen,1,1)='-' then
- call lineout OutFile,left('',fdpos)''left(ldesc.k,substr(fdlen,2))
- else
- call lineout OutFile,left('',fdpos)''right(ldesc.k,fdlen)
- end
- end
- end
- end
- return
-
- /* ------------------------------------------------------------------------- */
- process_ld: procedure expose ldesc. fdlen
- parse arg fdesc
- fdesclen = strip(fdlen,'l','-')
- fdesc=strip(fdesc); str=fdesc; ldesc.0=0
- if length(fdesc) < fdesclen then
- do
- ldesc.0=1; ldesc.1=fdesc; return
- end
- do while length(fdesc) > fdesclen
- p='z'; k=fdesclen
- do while p\=' ' & k>0
- fdesc=substr(str,k)
- p=substr(fdesc,1,1)
- k=k-1
- end
- if k=0 then
- fdesc=substr(str,1,fdesclen)
- else
- fdesc=substr(str,1,k)
- ldesc.0=ldesc.0+1; i=ldesc.0; ldesc.i=fdesc
- if k=0 then
- fdesc=substr(str,fdesclen+1)
- else
- fdesc=substr(str,k+2)
- str=fdesc
- end
- ldesc.0=ldesc.0+1; i=ldesc.0; ldesc.i=fdesc
- return
-
- /* ------------------------------------------------------------------------- */
- process_macro: procedure expose fdlen lowfname
- parse arg s
- out=''; p=pos('%',s)
- do while (p > 0)
- out=out''substr(s,1,p-1) /* ß«σpá¡∩Ѽ »pÑñδñπΘπε τáßΓ∞ »ÑpÑñ % */
- s=substr(s,p+1) /* ñѽáѼ % - »Ñpóδ¼ ß¿¼ó«½«¼ */
- s=parse_macro(s)
- out=out''substr(s,1,1) /* ¡á ß½πτá⌐, Ñß½¿ íδ½ ¡Ñ¿ºóÑßΓ¡δ⌐ ¼á¬p«ß */
- s=substr(s,2)
- p=pos('%',s)
- end
- out=out''s
- return out
-
- /* ------------------------------------------------------------------------- */
- parse_macro:
- parse arg macro
- align=''; tmp=''
- do forever
- ch=substr(macro,1,1)
- if ch='-' | datatype(ch,'N')=1 then
- do
- align=align''ch /* ß«σpá¡∩Ѽ - ¿½¿ µ¿Σpπ */
- macro=substr(macro,2) /* ñó¿úáѼß∩ ñá½∞ΦÑ */
- iterate
- end
- if datatype(ch,'M')=1 then
- do
- ch=translate(substr(macro,1,2))
- macro=substr(macro,3)
- select
- when ch='TH' then tmp="substr(time('n'),1,5)"
- when ch='DT' then tmp="date('l')"
- when ch='FN' then if lowfname='YES' then tmp='tolower(fname)'
- else tmp='fname'
- when ch='FS' then tmp='fsize'
- when ch='FD' then do
- tmp='fdesc'; fdlen=align
- end
- when ch='AT' then tmp='word(area.i,1)'
- when ch='AD' then tmp='subword(area.i,2)'
- when ch='AS' then tmp='bytes.i'
- when ch='A#' then tmp='files.i.0'
- otherwise
- return '%'align''ch''macro
- end
- if align='' then return '"'tmp'"'macro
- if substr(align,1,1)='-' then
- return '"left('tmp','substr(align,2)')"'macro
- else
- return '"right('tmp','align')"'macro
- end
- end
- return
-
- /* ------------------------------------------------------------------------- */
- AreaCmp: procedure expose selectarea.
- do i=1 to selectarea.0
- if MaskCmp(arg(1),selectarea.i) = 0 then return 0
- end
- return 1
-
- /* ------------------------------------------------------------------------- */
- MaskCmp: procedure
- areaname=arg(1); mask=arg(2)
- do while(mask\='' | areaname\='')
- mchar=substr(mask,1,1)
- if mchar='*' then
- do
- mask=substr(mask,2)
- mchar=substr(mask,1,1); achar=substr(areaname,1,1)
- do while(achar\=' ' & achar\=mchar)
- areaname=substr(areaname,2)
- achar=substr(areaname,1,1)
- end
- end
- else
- do
- achar=substr(areaname,1,1)
- if mchar\=achar then return 1
- mask=substr(mask,2)
- areaname=substr(areaname,2)
- end
- end
- return 0
-
- /* ------------------------------------------------------------------------- */
- SortFiles:
- do i=1 to area.0
- do j=1 to files.i.0
- do k=j+1 to files.i.0
- call charout ,left(' ■ Sorting area:' word(area.i,1) palka.pidx,79)''d2c(13)
- pidx=pidx+1; if pidx > 4 then pidx=1
- if word(files.i.j,1) > word(files.i.k,1) then
- do; str=files.i.j; files.i.j=files.i.k; files.i.k=str; end
- end
- end
- end; say left(' ■ Sorting areas: done.',79)
- return
-
- /* ------------------------------------------------------------------------- */
- tolower: procedure
- t1="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- t2="abcdefghijklmnopqrstuvwxyz"
- return translate(arg(1),t2,t1)
-
- /* ------------------------------------------------------------------------- */
- Usage:
- say 'Usage:'
- say 'TFANN <infile> <outfile> [#<tplfile>] [mask [mask]... @<selectfile>] [/ns]'
- call EndProgram ''
- return
-
- /* ------------------------------------------------------------------------- */
- EndProgram:
- say Arg(1); exit
- return
-