home *** CD-ROM | disk | FTP | other *** search
- /* Synchronize local and remote directory using LPT 1.78 JvW 25-02-97 */
- /* */
- /* 28-02-97 JvW Added options 1, T and S for subdirectories; L for logging */
-
- Parse Source with . myself .
- Parse Arg lspec rspec options attribs
-
- if lspec <> '' then
- do
- if Address() <> 'LPT' then
- do
- Address cmd '@lptq run' myself lspec rspec options attribs
- end; else
- do
- call lptslog '>>> LPTS lspec: "'lspec'" rspec: "'rspec'"' ||,
- ' options: "'options'" attribs: "'attribs'"'
- Say ''
- Say 'Synchronize directories using LPT, (c) 1997 Jan van Wijk'
- Say 'Test connection to remote LPT (daemon) ...'
- prc = lptc('ping')
- if (prc = 0) | (prc = 8) then
- do
- select
- when substr(lspec,1,1) = '\' then
- do
- lspec = substr(directory(),1,2) || lspec
- end
- when lspec = '.' then lspec = directory()'\'
- when substr(lspec,2,2) <> ':\' then lspec = directory()'\'lspec
- otherwise nop
- end
-
- select
- when (rspec = '') | (rspec = '=') then rspec = lspec
- otherwise nop
- end
- call lptslog 'lspec: "'lspec'" rspec: "'rspec'"'
-
- Say 'Synchronize local' lspec 'with remote' rspec
- lbase = GetDirFromSpec( lspec, '')
- rbase = GetDirFromSpec( rspec, 'r')
- call lptslog 'lbase: "'lbase'" rbase: "'rbase'"'
- /*
- */
- Say 'Get remote file-list :' rspec ' Please wait ...'
- call lptc 'screen off'; call lptc 'lptqscr off'
- call lptc 'rexec @say'
- call lptc 'rexec @say LPTS sync started; Send file-list for:' rspec
- call lptc 'rexec @screen off'
- call lptc 'rexec @tstree' rspec lbase 'F'options attribs
- call lptc 'CopyOutput rtree.'
- call lptc 'rexec @screen on'
- call lptc 'screen on'; call lptc 'lptqscr on'
- call lptc Say 'Get local file-list :' lspec
- call lptc 'screen off'; call lptc 'lptqscr off'
- call lptc 'tstree' lspec rbase 'F'options attribs
- call lptc 'CopyOutput ltree.'
- call lptc 'screen on'; call lptc 'lptqscr on'
-
- if pos('T', Translate(options)) <> 0 then
- do
- lptcmd = 'show'
- remote = 'rexec '
- sverb = 'to be sent'
- rverb = 'to be received'
- end; else
- do
- lptcmd = 'send'
- remote = '*'
- sverb = 'sent'
- rverb = 'received'
- end
- /*
- */
- NUMERIC DIGITS 20
- rdone = 0
- if pos('1', options) <> 0 then
- do
- Say 'One-way sync' lptcmd 'remote:' rbase 'with local:' lspec
- end; else
- do
- Say 'Two-way sync' lptcmd 'remote:' rspec 'with local:' lspec
- if rtree.0 <> 0 then Say ''
- Say 'Sync REMOTE to local :' lbase
- do i=1 to rtree.0
- parse value rtree.i with rstamp rname '»' ldest
- exist = 0
- do j=1 to ltree.0
- parse value ltree.j with lstamp lname '»' .
- rrelative = substr(strip(rname), length(rbase))
- lrelative = substr(strip(lname), length(lbase))
- if rrelative = lrelative then
- do
- exist = 1
- if (lstamp < rstamp) & (lname <> '') then
- do
- call lptc remote || lptcmd rname ldest 'p'
- rdone = rdone + 1
- end
- end
- end
- if exist = 0 then
- do
- call lptc remote || lptcmd rname ldest 'p'
- rdone = rdone + 1
- end
- end
- 'watch 1 1'
- end
- if ltree.0 <> 0 then Say ''
- Say 'Sync LOCAL to remote :' rbase
- ldone = 0
- do i=1 to ltree.0
- parse value ltree.i with lstamp lname '»' rdest
- exist = 0
- do j=1 to rtree.0
- parse value rtree.j with rstamp rname '»' ldest
- rrelative = substr(strip(rname), length(rbase))
- lrelative = substr(strip(lname), length(lbase))
- if rrelative = lrelative then
- do
- exist = 1
- if (rstamp < lstamp) & (lname <> '') then
- do
- call lptc lptcmd lname rdest 'p'
- ldone = ldone + 1
- end
- end
- end
- if exist = 0 then
- do
- call lptc lptcmd lname rdest 'p'
- ldone = ldone + 1
- end
- end
- /*
- */
- Say ''; Say 'LPTS' lptcmd 'finished, ' ||,
- sverb':' ldone rverb':' rdone
- call lptc 'screen off'
- call lptc 'lptqscr off'
- call lptc 'rexec @say LPTS' lptcmd 'finished, ' ||,
- sverb':' rdone rverb':' ldone
- call lptc 'rexec @say'
- call lptc 'screen on'
- call lptc 'lptqscr on'
- end; else
- do
- Say 'Remote LPT (deamon) not running or not connected ...'
- end
- end
- end; else
- do
- Say ''
- Say 'Synchronize directories using LPT, (c) 1997 Jan van Wijk'
- Say ''
- Say 'Usage:' myself 'Local-Spec [Remote-Spec [options [attributes]]]'
- Say ''
- Say ' Local-Spec = Local directory specification including final "\",'
- Say ' or Local directory + file-specification (wildcard),'
- Say ' or "." for the current directory.'
- Say ''
- Say ' Remote-Spec = Remote directory specification including final "\",'
- Say ' or Remote directory + file-specification (wildcard),'
- Say ' or "=" or empty for same as Local-Spec'
- Say ''
- Say ' options : s for subdirectories included (recursive)'
- Say ' 1 for one-way update from local to remote only'
- Say ' t Test modus, just show files to be updated'
- Say ' l Log modus, log lpt commands to LPTSCMDS.log'
- Say ''
- Say ' attributes = File attributes for files to include in the sync:'
- Say ' A = Archive, R = Read-only, S = System, H = Hidden'
- Say ' Prefix each with "+" for set and "-" for reset'
- Say ''
- Say 'Examples:' myself '.'
- Say ' ' myself 'H:\data\*.txt D:\myfiles\archive\*.txt'
- Say ' ' myself 'R:\code\* = s'
- end
- exit 0
-
- /*
- */
- GetDirFromSpec: procedure
- Parse arg fspec, at
- dir = '.\'
- p = LastPos('\', fspec)
- if p = 0 then /* relative, use current . */
- do
- if substr(fspec,2,1) = ':' then /* drive only, get curdir */
- do
- 'screen off'; 'lptqscr off'
- at 'cd' substr(fspec,1,2)
- 'CopyOutput curdir.'
- 'screen on'; 'lptqscr on'
- if curdir.0 = 1 then dir = curdir.1
- end
- end; else dir = substr( fspec, 1, p)
- return strip(dir)
-
- lptc:
- Parse arg lpt_cmd
- lpt_cmd
- lptrc = rc
- call lptslog 'RC:' lptrc 'on: "'lpt_cmd'"'
- rc = lptrc
- return lptrc
-
- lptslog:
- Parse arg logline
- if pos('l', options) <> 0 then
- do
- call lineout 'LPTSCMDS.log', logline
- call Stream 'LPTSCMDS.log', 'C', 'close'
- end
- return ''
-