home *** CD-ROM | disk | FTP | other *** search
/ DP Tool Club 24 / CD_ASCQ_24_0995.iso / dos / tools / aurora21 / compare.aml < prev    next >
Text File  |  1995-08-10  |  3KB  |  117 lines

  1. /* ------------------------------------------------------------------ */
  2. /* Macro:        COMPARE.AML                                          */
  3. /* Written by:   nuText Systems                                       */
  4. /*                                                                    */
  5. /* Description:  This macro compares two files, with various options. */
  6. /*                                                                    */
  7. /* Usage:        Select this macro from the Macro List (on the Macro  */
  8. /*               menu), or run it from the macro picklist <shift f12> */
  9. /* ------------------------------------------------------------------ */
  10.  
  11.   include bootpath "define.aml"
  12.  
  13.   var file2
  14.   var options
  15.  
  16.   // set default filenames
  17.   file1 = getbufname
  18.   file2 = if _BackupDir then
  19.             qualify (getname file1) (qualify _BackupDir)
  20.           else
  21.             forceext file1 _BackupExt
  22.           end
  23.  
  24.   // compare dialog box
  25.   dialog "Compare Files" 65 10 "c"
  26.   field "&Compare: >"  3  2 40 file1 "_load"
  27.   field "&With:    >"  3  4 40 file2 "_load"
  28.  
  29.   // initialize to previous options, if possible
  30.   options = if lookup "cmpopt" 'prf' 'e' then
  31.               lookup "cmpopt" 'prf'
  32.             else
  33.               "lo"
  34.             end
  35.  
  36.   // compare options group box
  37.   groupbox '' 3 6
  38.     (menu ''
  39.        item " [ ] Show &Line Numbers"
  40.        item " [ ] &Ignore Case"
  41.        item " [ ] Show &First and Last Lines Only "
  42.        item " [ ] Use &Open Files if Possible"
  43.      end) '' options "lifo"
  44.  
  45.   // ok/cancel buttons
  46.   button "O&k"      55 2 8
  47.   button "Cancel"   55 4 8
  48.  
  49.   // display dialog box and get control values
  50.   if (getdialog ref file1 ref file2 ref options) == 'Ok' then
  51.  
  52.     // save options for next time
  53.     setobj cmpopt options 'prf'
  54.  
  55.     oldbuf = getcurrbuf
  56.  
  57.     // use open files
  58.     if pos 'o' options then
  59.  
  60.       // file 1
  61.       buffer = findbuf file1
  62.       if buffer then
  63.         oldfile1 = file1
  64.         file1 = (getpath file1) + "@@@@CMP1"
  65.         gotobuf buffer
  66.         ok = save file1
  67.         gotobuf oldbuf
  68.         if not ok then
  69.           msgbox "Save Error!"
  70.           return
  71.         end
  72.       end
  73.  
  74.       // file 2
  75.       buffer = findbuf file2
  76.       if buffer then
  77.         oldfile2 = file2
  78.         file2 = (getpath file2) + "@@@@CMP2"
  79.         gotobuf buffer
  80.         ok = save file2
  81.         gotobuf oldbuf
  82.         if not ok then
  83.           msgbox "Save Error!"
  84.           return
  85.         end
  86.       end
  87.     end
  88.  
  89.     // run the DOS 'FC' command and capture the output
  90.     runcap "fc " + file1 + ' ' + file2 +
  91.            (if? (pos 'l' options) ' /n') +
  92.            (if? (pos 'f' options) ' /a') +
  93.            (if? (pos 'i' options) ' /c')
  94.  
  95.     if getcurrbuf <> oldbuf then
  96.       // change temporary filenames back to actual filenames in
  97.       // the comparison report
  98.       if oldfile1 then
  99.         replace file1 oldfile1 '*ag'
  100.       end
  101.       if oldfile2 then
  102.         replace file1 oldfile2 '*ag'
  103.       end
  104.       // turn off the buffer modified flag
  105.       bufferflag '-m'
  106.     end
  107.  
  108.     // cleanup temporary files
  109.     if oldfile1 then
  110.       deletefile file1
  111.     end
  112.     if oldfile2 then
  113.       deletefile file2
  114.     end
  115.  
  116.   end
  117.