home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / VC140.ZIP / VCS.KEX < prev   
Text File  |  1992-03-20  |  7KB  |  220 lines

  1. * Function:  Display fileone and filetwo in separate windows and locate the
  2. *            next and previous deletion or insertion.
  3. * To run:    While editing the second of two files you wish to compare
  4. *            (filetwo), execute the macro VCS with a fileone parameter (where
  5. *            fileone is the first of two files you wish to compare).  VCS will
  6. *            save fileone and filetwo if necessary, run Visual Compare (using
  7. *            the /D command line option and with the difference file redirected
  8. *            to the file VCS.TMP), load VCS.TMP, and locate the first deletion
  9. *            or insertion.  To locate the next deletion or insertion, press the
  10. *            Alt-N key or the key defined by the EDITV variable "vc_next_key."
  11. *            To locate the previous deletion or insertion, press the ALT-P key
  12. *            or the key defined by the EDITV variable "vc_prev_key."  To toggle
  13. *            between vertical and horizontal windows, press the F9 key or the
  14. *            key defined by the EDITV variable "vc_split_key."  You can also
  15. *            execute the macro VCS with both fileone and filetwo parameters.
  16. *            To execute the macro VCS from the DOS or OS/2 command line, see
  17. *            VCS.BAT or VCS.CMD respectively.
  18. * Requires:  KEDIT 4.0
  19. * User set EDITV variables:
  20. *   vcs_next_key   default:  "Alt-N"  locate next deletion or insertion
  21. *   vcs_prev_key   default:  "Alt-P"  locate previous deletion or insertion
  22. *   vcs_split_key  default:  "F9"     toggle between vertical and horizontal
  23. *                                     windows
  24. * Internal EDITV variables:
  25. *   vcs_fileone
  26. *   vcs_filetwo
  27. *   vcs.0          number of differences
  28. *   vcs.1...vcs.n  whether each difference is deletion or insertion
  29. *   vcs_current    current difference
  30.  
  31. arg = arg(1)
  32. IF arg = '!split' THEN
  33.     DO
  34.     'extract /screen'
  35.     IF word(screen.1, 1) = 'SIZE' & word(screen.1, 3) = 'SPLIT' THEN
  36.         'set screen 2'
  37.     ELSE
  38.         'set screen 2 v'
  39.     'sos current firstcol'
  40.     exit
  41.     END
  42. 'editv get vcs.0'
  43. IF arg <> '!next' & arg <> '!prev' THEN
  44.     DO
  45.     IF word(arg, 3) = '!cline' THEN
  46.         'macro' defprofile.1()
  47.     vcs_fileone = word(arg, 1)
  48.     vcs_filetwo = word(arg, 2)
  49.     IF vcs_filetwo = '' THEN
  50.         vcs_filetwo = fileid.1()
  51.     'kedit' vcs_fileone '(nodefext'
  52.     IF rc <> 0 THEN
  53.         exit
  54.     vcs_fileone = fileid.1()
  55.     IF alt() THEN
  56.         DO
  57.         'save'
  58.         IF rc <> 0 THEN
  59.             exit
  60.         END
  61.     'kedit' vcs_filetwo '(nodefext'
  62.     IF rc <> 0 THEN
  63.         exit
  64.     vcs_filetwo = fileid.1()
  65.     IF alt() THEN
  66.         DO
  67.         'save'
  68.         IF rc <> 0 THEN
  69.             exit
  70.         END
  71.     'editv put vcs_fileone vcs_filetwo'
  72.     IF word(arg, 3) <> '!cline' THEN
  73.         * Write the difference file to VCS.TMP.  If you are running OS/2,
  74.         * change vcomp to vcompp.
  75.         'dos vcomp' vcs_fileone vcs_filetwo '/D > VCS.TMP'
  76.     'kedit .:.\VCS.TMP (noprof'
  77.     IF rc <> 0 THEN
  78.         exit
  79.     IF size.1() = 0 THEN
  80.         DO
  81.         'quit'
  82.         'erase .:.\VCS.TMP'
  83.         exit
  84.         END
  85.     filetmp = fileid.1()
  86.     * Process VCS.TMP.
  87.     vcs_current = 0
  88.         DO FOREVER
  89.             'kedit' filetmp '(noprof'
  90.             'next'
  91.             IF rc <> 0 THEN
  92.                 DO
  93.                 'quit'
  94.                 'erase .:.\VCS.TMP'
  95.                 leave
  96.                 END
  97.             vcs_current = vcs_current + 1
  98.             'extract /curline'
  99.             * Save whether this difference is a deletion or an insertion.
  100.             vcs.vcs_current = word(curline.3, 3)
  101.             'editv put vcs.'vcs_current
  102.             * Save the corresponding file positions and the end of the deletion
  103.             * or insertion block by naming them.
  104.             'kedit' vcs_fileone '(nodefext'
  105.             'locate :'word(curline.3, 1)
  106.             'set point .vcs1.'vcs_current
  107.             IF vcs.vcs_current = '1' THEN
  108.                 DO
  109.                 * Save end of deletion block.
  110.                 'locate' word(curline.3, 4) + 1
  111.                 'set point .vcs2.'vcs_current
  112.                 END
  113.             'kedit' vcs_filetwo '(nodefext'
  114.             'locate :'word(curline.3, 2)
  115.             'set point .vcs1.'vcs_current
  116.             IF vcs.vcs_current = '2' THEN
  117.                 DO
  118.                 * Save end of insertion block.
  119.                 'locate' word(curline.3, 4) + 1
  120.                 'set point .vcs2.'vcs_current
  121.                 END
  122.         END
  123.     * Clear extra EDITV variables from last run.
  124.     IF datatype(vcs.0, 'n') THEN
  125.         DO i = vcs_current + 1 to vcs.0
  126.         'editv set vcs'.i
  127.         END
  128.     vcs.0 = vcs_current
  129.     'editv put vcs.0'
  130.     'editv get vcs_next_key vcs_prev_key vcs_split_key'
  131.     IF vcs_next_key = '' THEN
  132.         vcs_next_key = 'Alt-N'
  133.     IF vcs_prev_key = '' THEN
  134.         vcs_prev_key = 'Alt-P'
  135.     IF vcs_split_key = '' THEN
  136.         vcs_split_key = 'F9'
  137.     * Define key to find the next deletion or insertion.
  138.     'define' vcs_next_key '"macro vcs !next"'
  139.     * Define key to find the previous deletion or insertion.
  140.     'define' vcs_prev_key '"macro vcs !prev"'
  141.     * Define key to toggle between vertical and horizontal windows.
  142.     'define' vcs_split_key '"macro vcs !split"'
  143.     vcs_current = 0
  144.     'editv put vcs_current'
  145.     arg = '!next'
  146.     END
  147. 'editv get vcs_current'
  148. IF arg = '!next' THEN
  149.     vcs_current = min(vcs_current + 1, vcs.0 + 1)
  150. ELSE
  151.     vcs_current = max(vcs_current - 1, 0)
  152. IF vcs_current < 1 | vcs_current > vcs.0 THEN
  153.     DO
  154.     'emsg No more deletions or insertions'
  155.     exit
  156.     END
  157. 'editv put vcs_current'
  158. * Make sure two windows.
  159. 'extract /screen'
  160. DO i = 1
  161.     IF word(screen.1, i) = '' THEN
  162.         leave
  163. END
  164. IF i <> 4 | word(screen.1, 1) <> 'SIZE' THEN
  165.     'screen 2 v'
  166. * Locate the corresponding file positions in both files and mark the deletion
  167. * or insertion block.  Start with left or top window.
  168. IF lscreen.3() <> 1 | lscreen.4() <> 1 THEN
  169.     'sos tabcmdf'
  170. 'editv get vcs_fileone vcs_filetwo vcs.'vcs_current
  171. * Locate the fileone position.
  172. 'kedit' vcs_fileone '(nodefext'
  173. IF rc <> 0 THEN
  174.     exit
  175. 'locate .vcs1.'vcs_current
  176. IF rc > 1 THEN
  177.     exit
  178. IF vcs.vcs_current = '1' THEN
  179.     DO
  180.     * Mark the deletion block.
  181.     'reset block'
  182.     i = line.1()
  183.     'locate 1'
  184.     'mark line'
  185.     'locate .vcs2.'vcs_current
  186.     IF rc > 1 THEN
  187.         exit
  188.     'locate -1'
  189.     'mark line'
  190.     IF line.1() = i THEN
  191.         'reset block'
  192.     'locate :'i
  193.     END
  194. * Move to right or bottom window.
  195. 'sos tabcmdf'
  196. * Locate the filetwo position.
  197. 'kedit' vcs_filetwo '(nodefext'
  198. IF rc <> 0 THEN
  199.     exit
  200. 'locate .vcs1.'vcs_current
  201. IF rc > 1 THEN
  202.     exit
  203. IF vcs.vcs_current = '2' THEN
  204.     DO
  205.     * Mark the insertion block.
  206.     'reset block'
  207.     i = line.1()
  208.     'locate 1'
  209.     'mark line'
  210.     'locate .vcs2.'vcs_current
  211.     IF rc > 1 THEN
  212.         exit
  213.     'locate -1'
  214.     'mark line'
  215.     IF line.1() = i THEN
  216.         'reset block'
  217.     'locate :'i
  218.     END
  219. 'sos current firstcol'
  220.