home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Professional / OS2PRO194.ISO / os2 / prgramer / vcomp / vc.cb < prev    next >
Text File  |  1992-03-05  |  7KB  |  185 lines

  1. /*
  2.  *  Function:  Run Visual Compare and locate the next and previous deletion or
  3.  *             insertion.
  4.  *  To run:    While editing the second of two files you wish to compare
  5.  *             (filetwo), execute the macro VC with a fileone parameter (where
  6.  *             fileone is the first of two files you wish to compare).  If
  7.  *             you omit fileone, VC will prompt you for it.  VC will save
  8.  *             fileone and filetwo if necessary, run Visual Compare (using the
  9.  *             /C command line option and with the composite file redirected to
  10.  *             the file VC.TMP), load VC.TMP, and locate the first deletion or
  11.  *             insertion.  To locate the next deletion or insertion, press the
  12.  *             <Alt-v><Alt-n> key sequence.  To locate the previous deletion or
  13.  *             insertion, press the <Alt-v><Alt-p> key sequence.  If the file
  14.  *             VC.TMP already exists, execute VC with "!next" for the fileone
  15.  *             parameter to load VC.TMP and locate the first deletion or
  16.  *             insertion.
  17.  *  Requires:  BRIEF 3.0
  18.  */
  19.  
  20. void vc( void )
  21. {
  22.     string vc_next_key = "<Alt-v><Alt-n>";
  23.     string vc_prev_key = "<Alt-v><Alt-p>";
  24.     string vc_one_start = "START  \\$\\$\\$\\$\\$";
  25.     string vc_two_start = "START  \\$\\$\\$\\$\\$";
  26.     string fileone;
  27.     string filetwo;
  28.     int buffer_cur;
  29.     int buffer_tmp;
  30.     string buffer_tmp_name;
  31.     int ret_code;
  32.     string command_string;
  33.     int window_cur;
  34.     int window_tmp;
  35.  
  36.     if ( !get_parm( 0, fileone, "Enter fileone: " ))
  37.         return;
  38.     fileone = lower( fileone );
  39.     if ( fileone != "!next" && fileone != "!prev" )
  40.     {
  41.         /* Look for a vc.tmp buffer. */
  42.         buffer_cur = inq_buffer();
  43.         do
  44.         {
  45.             buffer_tmp = next_buffer();
  46.             set_buffer( buffer_tmp );
  47.             inq_names( NULL, NULL, buffer_tmp_name );
  48.         }
  49.         while ( buffer_tmp != buffer_cur && buffer_tmp_name != "vc.tmp" );
  50.         if ( buffer_tmp_name == "vc.tmp" )
  51.         {
  52.             /*
  53.              *  Make the current buffer the same as the buffer attached to the
  54.              *  current window.
  55.              */
  56.             set_buffer( buffer_cur );
  57.             ret_code = inq_views( buffer_tmp );
  58.             if ( !ret_code )
  59.                 delete_buffer( buffer_tmp );
  60.             else
  61.             {
  62.                 /* Can't delete a viewed buffer. */
  63.                 message( "Unable to delete vc.tmp buffer" );
  64.                 return;
  65.             }
  66.         }
  67.         /* Look for a fileone buffer. */
  68.         do
  69.         {
  70.             buffer_tmp = next_buffer();
  71.             set_buffer( buffer_tmp );
  72.             inq_names( NULL, NULL, buffer_tmp_name );
  73.         }
  74.         while ( buffer_tmp != buffer_cur && buffer_tmp_name != fileone );
  75.         if ( buffer_tmp_name == fileone )
  76.         {
  77.             /* If the fileone buffer has been modified, write it to disk. */
  78.             if ( inq_modified() && write_buffer() <= 0 )
  79.                 return;
  80.             /* Get the full file name associated with the fileone buffer. */
  81.             inq_names( fileone );
  82.             /*
  83.              *  Make the current buffer the same as the buffer attached to the
  84.              *  current window.
  85.              */
  86.             set_buffer( buffer_cur );
  87.         }
  88.         /* If the current buffer has been modified, write it to disk. */
  89.         if ( inq_modified() && write_buffer() <= 0 )
  90.             return;
  91.         /* Get the full file name associated with the current buffer. */
  92.         inq_names( filetwo );
  93.         /*
  94.          *  Write the composite file to VC.TMP.  If you are running OS/2,
  95.          *  change vcomp to vcompp.
  96.          */
  97.         sprintf( command_string, "vcomp %s %s /C > VC.TMP", fileone, filetwo );
  98.         if ( dos( command_string, 0 ))
  99.             return;
  100.         ret_code = edit_file( "VC.TMP" );
  101.         if ( ret_code <= 0 )
  102.             return;
  103.         if ( ret_code == 1 )
  104.         {
  105.             message( "New VC.TMP file not loaded" );
  106.             return;
  107.         }
  108.     }
  109.     else
  110.     {
  111.         /* Look for a window with a vc.tmp buffer attached to it. */
  112.         window_cur = inq_window();
  113.         buffer_cur = inq_buffer();
  114.         window_tmp = window_cur;
  115.         inq_names( NULL, NULL, buffer_tmp_name );
  116.         if ( buffer_tmp_name != "vc.tmp" )
  117.         {
  118.             do
  119.             {
  120.                 window_tmp = next_window( window_tmp );
  121.                 inq_window_info( window_tmp, buffer_tmp );
  122.                 set_buffer( buffer_tmp );
  123.                 inq_names( NULL, NULL, buffer_tmp_name );
  124.             }
  125.             while ( window_tmp != window_cur && buffer_tmp_name != "vc.tmp" );
  126.         }
  127.         if ( buffer_tmp_name == "vc.tmp" )
  128.         {
  129.             /*
  130.              *  Make the current buffer the same as the buffer attached to the
  131.              *  current window.
  132.              */
  133.             set_buffer( buffer_cur );
  134.             /* Jump to the window with a vc.tmp buffer attached to it. */
  135.             set_window( window_tmp );
  136.             ret_code = 1;              /* The buffer already existed. */
  137.         }
  138.         else
  139.         {
  140.             /*
  141.              *  Attach an existing vc.tmp buffer to the current window or
  142.              *  create a new vc.tmp buffer.
  143.              */
  144.             ret_code = edit_file( "VC.TMP" );
  145.             if ( ret_code <= 0 )
  146.                 return;
  147.         }
  148.     }
  149.     sprintf( command_string, "{%s}|{%s}", vc_one_start, vc_two_start );
  150.     if ( ret_code == 1 )
  151.     {
  152.         /* The buffer already existed. */
  153.         save_position();
  154.         ret_code = 0;                  /* Assume search failed. */
  155.         /*
  156.          *  Move the current position before calling the appropriate search
  157.          *  routine so as to not find the same deletion or insertion a second
  158.          *  time.
  159.          */
  160.         if ( fileone == "!next" && next_char())
  161.             /* Locate the next deletion or insertion. */
  162.             ret_code = search_fwd( command_string );
  163.         else if ( fileone == "!prev" && prev_char())
  164.             /* Locate the previous deletion or insertion. */
  165.             ret_code = search_back( command_string );
  166.         /* If search failed, restore the previous position. */
  167.         restore_position( !ret_code );
  168.     }
  169.     else
  170.     {
  171.         /*
  172.          *  The buffer was newly created.  Define keys to find the next and
  173.          *  previous deletion or insertion.
  174.          */
  175.         assign_to_key( vc_next_key, "vc !next" );
  176.         assign_to_key( vc_prev_key, "vc !prev" );
  177.         /* Locate the next deletion or insertion. */
  178.         ret_code = search_fwd( command_string );
  179.     }
  180.     if ( ret_code > 0 )
  181.         message( "" );
  182.     else if ( !ret_code )
  183.         message( "No more deletions or insertions" );
  184. }
  185.