home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 11 Util / 11-Util.zip / lpt197.zip / lpts.cmd < prev    next >
OS/2 REXX Batch file  |  1997-02-28  |  9KB  |  217 lines

  1. /* Synchronize local and remote directory using LPT 1.78     JvW 25-02-97    */
  2. /*                                                                           */
  3. /* 28-02-97 JvW Added options 1, T and S for subdirectories; L for logging   */
  4.  
  5.    Parse Source with . myself .
  6.    Parse Arg lspec rspec options attribs
  7.  
  8.    if lspec <> '' then
  9.    do
  10.       if Address() <> 'LPT' then
  11.       do
  12.          Address cmd '@lptq run' myself lspec rspec options attribs
  13.       end; else
  14.       do
  15.          call lptslog '>>> LPTS lspec: "'lspec'" rspec: "'rspec'"' ||,
  16.                                 ' options: "'options'" attribs: "'attribs'"'
  17.          Say ''
  18.          Say 'Synchronize directories using LPT, (c) 1997 Jan van Wijk'
  19.          Say 'Test connection to remote LPT (daemon) ...'
  20.          prc = lptc('ping')
  21.          if (prc = 0) | (prc = 8) then
  22.          do
  23.             select
  24.             when substr(lspec,1,1) = '\'   then
  25.             do
  26.                lspec = substr(directory(),1,2) || lspec
  27.             end
  28.             when lspec = '.'                then lspec = directory()'\'
  29.             when substr(lspec,2,2) <> ':\'  then lspec = directory()'\'lspec
  30.             otherwise nop
  31.             end
  32.  
  33.             select
  34.             when (rspec = '') | (rspec = '=') then rspec = lspec
  35.             otherwise nop
  36.             end
  37.             call lptslog 'lspec: "'lspec'" rspec: "'rspec'"'
  38.  
  39.             Say 'Synchronize local' lspec 'with remote' rspec
  40.             lbase = GetDirFromSpec( lspec, '')
  41.             rbase = GetDirFromSpec( rspec, 'r')
  42.             call lptslog 'lbase: "'lbase'" rbase: "'rbase'"'
  43.                                                                            /* 
  44.                                                                            */
  45.             Say 'Get remote file-list :' rspec '          Please wait ...'
  46.             call lptc 'screen off'; call lptc 'lptqscr off'
  47.             call lptc 'rexec @say'
  48.             call lptc 'rexec @say LPTS sync started; Send file-list for:' rspec
  49.             call lptc 'rexec @screen off'
  50.             call lptc 'rexec @tstree' rspec lbase 'F'options attribs
  51.             call lptc 'CopyOutput     rtree.'
  52.             call lptc 'rexec @screen on'
  53.             call lptc 'screen on';  call lptc 'lptqscr on'
  54.             call lptc Say 'Get local  file-list :' lspec
  55.             call lptc 'screen off'; call lptc 'lptqscr off'
  56.             call lptc 'tstree'      lspec  rbase 'F'options attribs
  57.             call lptc 'CopyOutput   ltree.'
  58.             call lptc 'screen on';  call lptc 'lptqscr on'
  59.  
  60.             if pos('T', Translate(options)) <> 0 then
  61.             do
  62.                lptcmd = 'show'
  63.                remote = 'rexec '
  64.                sverb  = 'to be sent'
  65.                rverb  = 'to be received'
  66.             end; else
  67.             do
  68.                lptcmd = 'send'
  69.                remote = '*'
  70.                sverb  = 'sent'
  71.                rverb  = 'received'
  72.             end
  73.                                                                            /* 
  74.                                                                            */
  75.             NUMERIC DIGITS 20
  76.             rdone = 0
  77.             if pos('1', options) <> 0 then
  78.             do
  79.                Say 'One-way sync' lptcmd 'remote:' rbase 'with local:' lspec
  80.             end; else
  81.             do
  82.                Say 'Two-way sync' lptcmd 'remote:' rspec 'with local:' lspec
  83.                if rtree.0 <> 0 then Say ''
  84.                Say 'Sync REMOTE to local :' lbase
  85.                do i=1 to rtree.0
  86.                   parse value rtree.i with rstamp rname '»' ldest
  87.                   exist = 0
  88.                   do j=1 to ltree.0
  89.                      parse value ltree.j with lstamp lname '»' .
  90.                      rrelative = substr(strip(rname), length(rbase))
  91.                      lrelative = substr(strip(lname), length(lbase))
  92.                      if rrelative = lrelative then
  93.                      do
  94.                         exist = 1
  95.                         if (lstamp < rstamp) & (lname <> '') then
  96.                         do
  97.                            call lptc remote || lptcmd rname ldest 'p'
  98.                            rdone = rdone + 1
  99.                         end
  100.                      end
  101.                   end
  102.                   if exist = 0 then
  103.                   do
  104.                      call lptc remote || lptcmd rname ldest 'p'
  105.                      rdone = rdone + 1
  106.                   end
  107.                end
  108.                'watch 1 1'
  109.             end
  110.             if ltree.0 <> 0 then Say ''
  111.             Say 'Sync LOCAL to remote :' rbase
  112.             ldone = 0
  113.             do i=1 to ltree.0
  114.                parse value ltree.i with lstamp lname '»' rdest
  115.                exist = 0
  116.                do j=1 to rtree.0
  117.                   parse value rtree.j with rstamp rname '»' ldest
  118.                   rrelative = substr(strip(rname), length(rbase))
  119.                   lrelative = substr(strip(lname), length(lbase))
  120.                   if rrelative = lrelative then
  121.                   do
  122.                      exist = 1
  123.                      if (rstamp < lstamp) & (lname <> '') then
  124.                      do
  125.                         call lptc lptcmd lname rdest 'p'
  126.                         ldone = ldone + 1
  127.                      end
  128.                   end
  129.                end
  130.                if exist = 0 then
  131.                do
  132.                   call lptc lptcmd lname rdest 'p'
  133.                   ldone = ldone + 1
  134.                end
  135.             end
  136.                                                                            /* 
  137.                                                                            */
  138.             Say ''; Say 'LPTS' lptcmd 'finished, ' ||,
  139.                                          sverb':' ldone rverb':' rdone
  140.             call lptc 'screen off'
  141.             call lptc 'lptqscr off'
  142.             call lptc 'rexec @say LPTS'  lptcmd 'finished, ' ||,
  143.                                          sverb':' rdone rverb':' ldone
  144.             call lptc 'rexec @say'
  145.             call lptc 'screen on'
  146.             call lptc 'lptqscr on'
  147.          end; else
  148.          do
  149.             Say 'Remote LPT (deamon) not running or not connected ...'
  150.          end
  151.       end
  152.    end; else
  153.    do
  154.       Say ''
  155.       Say 'Synchronize directories using LPT, (c) 1997 Jan van Wijk'
  156.       Say ''
  157.       Say 'Usage:' myself 'Local-Spec [Remote-Spec [options [attributes]]]'
  158.       Say ''
  159.       Say '  Local-Spec  =  Local directory specification including final "\",'
  160.       Say '              or Local directory + file-specification (wildcard),'
  161.       Say '              or "." for the current directory.'
  162.       Say ''
  163.       Say '  Remote-Spec =  Remote directory specification including final "\",'
  164.       Say '              or Remote directory + file-specification (wildcard),'
  165.       Say '              or "=" or empty for same as Local-Spec'
  166.       Say ''
  167.       Say '  options     :  s for subdirectories included (recursive)'
  168.       Say '                 1 for one-way update from local to remote only'
  169.       Say '                 t Test modus, just show files to be updated'
  170.       Say '                 l Log  modus, log lpt commands to LPTSCMDS.log'
  171.       Say ''
  172.       Say '  attributes  =  File attributes for files to include in the sync:'
  173.       Say '                 A = Archive, R = Read-only, S = System, H = Hidden'
  174.       Say '                     Prefix each with "+" for set and "-" for reset'
  175.       Say ''
  176.       Say 'Examples:' myself '.'
  177.       Say '         ' myself 'H:\data\*.txt D:\myfiles\archive\*.txt'
  178.       Say '         ' myself 'R:\code\*     =   s'
  179.    end
  180. exit 0
  181.  
  182.                                                                            /* 
  183.                                                                            */
  184. GetDirFromSpec: procedure
  185.    Parse arg fspec, at
  186.    dir = '.\'
  187.    p = LastPos('\', fspec)
  188.    if p = 0 then                                /* relative, use current .   */
  189.    do
  190.       if substr(fspec,2,1) = ':' then           /* drive only, get curdir    */
  191.       do
  192.          'screen off'; 'lptqscr off'
  193.          at 'cd' substr(fspec,1,2)
  194.          'CopyOutput    curdir.'
  195.          'screen on';  'lptqscr on'
  196.          if curdir.0 = 1 then dir = curdir.1
  197.       end
  198.    end; else dir = substr( fspec, 1, p)
  199.    return strip(dir)
  200.  
  201. lptc:
  202.    Parse arg lpt_cmd
  203.    lpt_cmd
  204.    lptrc = rc
  205.    call lptslog 'RC:' lptrc 'on: "'lpt_cmd'"'
  206.    rc = lptrc
  207.    return lptrc
  208.  
  209. lptslog:
  210.    Parse arg logline
  211.    if pos('l', options) <> 0 then
  212.    do
  213.       call lineout 'LPTSCMDS.log', logline
  214.       call Stream  'LPTSCMDS.log', 'C', 'close'
  215.    end
  216.    return ''
  217.