home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR8 / VDIFF05.ZIP / VDIFF.S < prev   
Text File  |  1993-04-04  |  11KB  |  378 lines

  1. /* -------------------------------------------------------------------------- */
  2. /* File Name...: VDIFF.S                                                                        */
  3. /* Program Name: Visual "diff" Utility for The SemWare Editor                 */
  4. /* Version.....: 0.10                                                                            */
  5. /* Author......: Jim Susoy                                                                        */
  6. /* Notice......: (C) Copyright 1993 - All Rights Reserved                            */
  7. /* Desc........: This TSE macro enables TSE to display the differences (on a  */
  8. /*                   line-by-line basis) of two files by "highlighting" the lines */
  9. /*                   in one file that are different from the lines in another         */
  10. /*                   file.  The user can then move the line (in either direction) */
  11. /*                   to resolve the difference. All the differences are           */
  12. /*                   highlighted simultaneously.                                             */
  13. /*                                                                                                      */
  14. /* Revisions...: 0.10    -    02/01/93    First Coding                                       */
  15. /*                   0.20    -    02/05/93    Added functions to move lines between      */
  16. /*                                             to aid in resolving differences.             */
  17. /*                   0.21    -    04/01/93 Formatted Drive C: (Just seeing if you     */
  18. /*                                             are paying attention!)                             */
  19. /*                   0.30    -    04/02/93    Rewrote mDisplayDiffs() so that highlights*/
  20. /*                                             were not redrawn by TSE between each         */
  21. /*                                             iteration of the while loop.                     */
  22. /*                                             It seems that TSE redraw the entire window*/
  23. /*                                             whenever it is switched to or from.  So   */
  24. /*                                             now VDiff does all its proccessing in         */
  25. /*                                             file2's window (it just switches between    */
  26. /*                                             buffers)                                             */
  27. /* -------------------------------------------------------------------------- */
  28.  
  29.  
  30. /* -------------------------------------------------------------------------- */
  31. /* Global Variables                                                                                 */
  32. /* -------------------------------------------------------------------------- */
  33. integer    Window1                            /* Window ID of first diff window             */
  34. integer    Window2                            /* Window ID of second diff window             */
  35. integer    Buffer1                            /* Buffer ID of first diff file                 */
  36. integer    Buffer2                            /* Buffer ID of second diff file             */
  37. integer    VDiffHiAttr                        /* Attribute to use to highlight diffs     */
  38. string    File1Line[255] = ""            /* Storage for line comparison                 */
  39. string    File2Line[255] = ""            /* Storage for line comparison            */
  40.  
  41. /*
  42. // ^begin^
  43. //
  44. // ────────────────────────────────────────────────────────────────────────────────
  45. // PROC mDisplayDiffs()
  46. // ────────────────────────────────────────────────────────────────────────────────
  47. //
  48. // Desc.     :    This is the macro that does the actual DIFF of the two files
  49. //             and highlighting of the differences.  It is called every time
  50. //                    the cursor row changes in either file
  51. //
  52. // Parameters:                -  void
  53. //
  54. // Returns   : Directly       -  void
  55. //
  56. // Notes     :
  57. //
  58. // ^end^
  59. //
  60. // ***********************    Revision History    ******************************
  61. //
  62. // ^rbegin^
  63. //
  64. // mDisplayDiffs()
  65. //
  66. // 02/01/93 -  First Coding
  67. //
  68. // ^rend^
  69. */
  70. PROC mDisplayDiffs()
  71.    integer     i = 1
  72.    integer    rows
  73.    integer    x                                /* Value of WindowX1 TSe var when called    */
  74.    integer    c                                /* Value of WindowCols                          */
  75.  
  76.    GotoWindow(Window2)
  77.     x = Query(WindowX1)
  78.     c = Query(WindowCols)
  79.    PushPosition()
  80.    rows = Query(WindowRows)            /* Get number of rows in window                 */
  81.  
  82.    while(i <= rows)
  83.         GotoBufferId(Buffer1)            /* Goto specified buffer                         */
  84.         GotoRow(i)                            /* Go to the specified row                     */
  85.         File1Line = GetText(1,255)        /* Get the line                                     */
  86.         GotoBufferId(Buffer2)            /* Goto specified buffer                         */
  87.         GotoRow(i)                            /* Go to the specified row                     */
  88.         File2Line = GetText(1,255)        /* Get the line                                     */
  89.  
  90.        GotoWindow(Window2)
  91.        if(File1Line <> File2Line)
  92.          VGotoXY(x, i+2)
  93.          PutAttr(VDiffHiAttr, Query(WindowCols))
  94.        endif
  95.        i = i + 1
  96.     endwhile
  97.     PopPosition()
  98. END
  99.  
  100.  
  101. /* -------------------------------------------------------------------------- */
  102. /* The following support macros are called to move around and copy lines        */
  103. /* between the two files                                                                         */
  104. /* -------------------------------------------------------------------------- */
  105. PROC mDiffCursorDown()
  106.     GotoWindow(Window1)
  107.     if(Down() <> 0)
  108.         GotoWindow(Window2)
  109.       Down()
  110.    endif
  111.     GotoWindow(Window2)
  112.     UpdateDisplay(_WINDOW_REFRESH_)
  113.     mDisplayDiffs()
  114. END
  115.  
  116.  
  117. PROC mDiffCursorUp()
  118.     GotoWindow(Window1)
  119.     if(Up() <> 0)
  120.         GotoWindow(Window2)
  121.         Up()
  122.         UpdateDisplay(_WINDOW_REFRESH_)
  123.         mDisplayDiffs()
  124.     endif
  125.     GotoWindow(Window2)
  126. END
  127.  
  128.  
  129. PROC mDiffPageUp()
  130.     GotoWindow(Window1)
  131.     if(PageUp() <> 0)
  132.         GotoWindow(Window2)
  133.         PageUp()
  134.         UpdateDisplay(_WINDOW_REFRESH_)
  135.         mDisplayDiffs()
  136.     endif
  137.     GotoWindow(Window2)
  138. END
  139.  
  140.  
  141. PROC mDiffPageDown()
  142.     GotoWindow(Window1)
  143.     if(PageDown() <> 0)
  144.         GotoWindow(Window2)
  145.         PageDown()
  146.         UpdateDisplay(_WINDOW_REFRESH_)
  147.         mDisplayDiffs()
  148.     endif
  149.     GotoWindow(Window2)
  150. END
  151.  
  152.  
  153. PROC mDiffBegFile()
  154.     GotoWindow(Window1)
  155.     if(BegFile() <> 0)
  156.         GotoWindow(Window2)
  157.         BegFile()
  158.         UpdateDisplay(_WINDOW_REFRESH_)
  159.         mDisplayDiffs()
  160.     endif
  161.     GotoWindow(Window2)
  162. END
  163.  
  164. PROC mDiffEndFile()
  165.     GotoWindow(Window1)
  166.     if(EndFile() <> 0)
  167.         GotoWindow(Window2)
  168.         EndFile()
  169.         UpdateDisplay(_WINDOW_REFRESH_)
  170.         mDisplayDiffs()
  171.     endif
  172.     GotoWindow(Window2)
  173. END
  174.  
  175. PROC mDiffCursorRight()
  176.     GotoWindow(Window1)
  177.     if(Right() <> 0)
  178.         GotoWindow(Window2)
  179.         Right()
  180.         UpdateDisplay(_WINDOW_REFRESH_)
  181.         mDisplayDiffs()
  182.     endif
  183.     GotoWindow(Window2)
  184. END
  185.  
  186. PROC mDiffCursorLeft()
  187.     GotoWindow(Window1)
  188.     if(Left() <> 0)
  189.         GotoWindow(Window2)
  190.         Left()
  191.         UpdateDisplay(_WINDOW_REFRESH_)
  192.         mDisplayDiffs()
  193.     endif
  194.     GotoWindow(Window2)
  195. END
  196.  
  197. PROC mDiffTopOfWindow()
  198.     GotoWindow(Window1)
  199.     if(BegWindow() <> 0)
  200.         GotoWindow(Window2)
  201.         BegWindow()
  202.         UpdateDisplay(_WINDOW_REFRESH_)
  203.         mDisplayDiffs()
  204.     endif
  205.     GotoWindow(Window2)
  206. END
  207.  
  208. PROC mDiffBottomOfWindow()
  209.     GotoWindow(Window1)
  210.     if(EndWindow() <> 0)
  211.         GotoWindow(Window2)
  212.         EndWindow()
  213.         UpdateDisplay(_WINDOW_REFRESH_)
  214.         mDisplayDiffs()
  215.     endif
  216.     GotoWindow(Window2)
  217. END
  218.  
  219. PROC mCopyLineFromOneToTwo()
  220.     string     text[255] = ""
  221.     integer     col
  222.  
  223.     GotoWindow(Window1)
  224.     text = GetText(1,255)
  225.     GotoWindow(Window2)
  226.     col = CurrCol()
  227.     InsertText(text,_OVERWRITE_)
  228.     DelToEol()
  229.     GotoColumn(col)
  230.     GotoWindow(Window2)
  231. END
  232.  
  233.  
  234. PROC mCopyLineFromTwoToOne()
  235.     string     text[255] = ""
  236.     integer     col
  237.  
  238.     GotoWindow(Window2)
  239.     text = GetText(1,255)
  240.     GotoWindow(Window1)
  241.     col = CurrCol()
  242.     InsertText(text,_OVERWRITE_)
  243.     DelToEol()
  244.     GotoColumn(col)
  245.     GotoWindow(Window2)
  246. END
  247.  
  248.  
  249. PROC mRollRightDown()
  250.     GotoWindow(Window2)
  251.     RollUp()
  252.     UpdateDisplay(_ALL_WINDOWS_REFRESH_)
  253.     mDisplayDiffs()
  254.     GotoWindow(Window2)
  255. END
  256.  
  257.  
  258. PROC mRollRightUp()
  259.     GotoWindow(Window2)
  260.     RollDown()
  261.     UpdateDisplay(_ALL_WINDOWS_REFRESH_)
  262.    mDisplayDiffs()
  263.    GotoWindow(Window2)
  264. END
  265.  
  266.  
  267.  
  268. PROC mRollWindowsUp()
  269.     GotoWindow(Window1)
  270.     if(RollUp() <> 0)
  271.         GotoWindow(Window2)
  272.         RollUp()
  273.         UpdateDisplay(_WINDOW_REFRESH_)
  274.         mDisplayDiffs()
  275.     endif
  276.     GotoWindow(Window2)
  277. END
  278.  
  279.  
  280. PROC mRollWindowsDown()
  281.     GotoWindow(Window1)
  282.     if(RollDown() <> 0)
  283.         GotoWindow(Window2)
  284.         RollDown()
  285.         UpdateDisplay(_WINDOW_REFRESH_)
  286.         mDisplayDiffs()
  287.     endif
  288.     GotoWindow(Window2)
  289. END
  290.  
  291.  
  292. KEYDEF VDiffKeys
  293.     <CursorUp>          mDiffCursorUp()           /* Move cursor up in window     */
  294.     <CursorDown>        mDiffCursorDown()            /* Move cursor down in window */
  295.     <CursorRight>            mDiffCursorRight()        /* Move cursor right             */
  296.     <CursorLeft>            mDiffCursorLeft()            /* Move cursor left                 */
  297.     <PgUp>                    mDiffPageUp()                /* Page up                             */
  298.     <PgDn>              mDiffPageDown()            /* Page Down                         */
  299.     <CTRL PgUp>            mDiffBegFile()                /* Start Of File                     */
  300.     <CTRL PgDn>            mDiffEndFile()                /* End Of File                     */
  301.  
  302.     <CTRL Home>            mDiffTopOfWindow()        /* Top Of Window                     */
  303.     <CTRL End>                mDiffBottomOfWindow()    /* Bottom Of Window                 */
  304.     <CTRL CursorRight>    mCopyLineFromOneToTwo()    /* Move line from left to right*/
  305.     <CTRL CursorLeft>    mCopyLineFromTwoToOne() /* Move line from right to left*/
  306.     <CTRL CursorUp>        mRollWindowsUp()
  307.     <CTRL CursorDown>    mRollWindowsDown()
  308.  
  309.     <ALT CursorUp>        mRollRightUp()             /* Roll right win up Cursor reamins in sync*/
  310.     <ALT CursorDown>        mRollRightDown()             /* Roll right win Down Cursor reamins in sync*/
  311.  
  312.     <Escape>            EndProcess()                /* Done                                 */
  313. END
  314.  
  315. /*
  316. // ^begin^
  317. //
  318. // ────────────────────────────────────────────────────────────────────────────────
  319. // PROC mVisualDiff(integer attr)
  320. // ────────────────────────────────────────────────────────────────────────────────
  321. //
  322. // Desc.     :    This is the PUBLIC entry point of the macro.  It is responsible
  323. //                    for prompt the user for the name of the two files to DIFF,
  324. //                    as well as setting up the vertical windows and initializing
  325. //                    some global variables.
  326. //
  327. // Parameters: attr           -    The attribute to use to highlight the
  328. //                                            differences in file2
  329. //
  330. // Returns   : Directly       -    void
  331. //
  332. // Notes     :
  333. //
  334. // ^end^
  335. //
  336. // ***********************    Revision History    ******************************
  337. //
  338. // ^rbegin^
  339. //
  340. // mVisualDiff()
  341. //
  342. // 02/01/93 -  First Coding
  343. //
  344. // ^rend^
  345. */
  346. PROC mVisualDiff(integer attr)
  347.     VDiffHiAttr        = attr                            /* Store highlight attribute         */
  348.     Message("Enter filename for file #1...")
  349.     if(EditFile() <> 0)                     /* Load File #1                             */
  350.        Buffer1 = GetBufferId()                    /* Store the buffer ID                     */
  351.        BegFile()                                    /* Goto start if already in buffer     */
  352.        Window1 = WindowID()                        /* Store window ID                         */
  353.        Message("Enter filename for file #2...")
  354.        if(EditFile() <> 0)                        /* Load File #2                             */
  355.           Buffer2 = GetBufferId()                /* Store it's buffer ID                 */
  356.            BegFile()                                /* Goto start if already in buffer     */
  357.           VWindow()                                /* Create Vertical windows               */
  358.           Window2 = WindowID()                    /* Store the window ID                     */
  359.           GotoWindow(Window1)                    /* Goto window #1                         */
  360.           GotoBufferID(Buffer1)                /* and put file #1 in it                 */
  361.           GotoWindow(Window2)                    /* Goto window #2                         */
  362.           GotoBufferID(Buffer2)                /* and put file #2 in it                 */
  363.           UpdateDisplay(_ALL_WINDOWS_REFRESH_)
  364.  
  365.           mDisplayDiffs()                        /* Do the Diffs                             */
  366.           Enable(VDiffKeys)
  367.           Process()                           /* Process User Keystrokes             */
  368.           Disable(VDiffKeys)
  369.           PopWinClose()
  370.            UpdateDisplay(_All_Windows_Refresh_)
  371.        else
  372.            AbandonFile(Buffer1)                    /* If they hit escape, Dump the file*/
  373.        endif
  374.    endif
  375. END
  376.  
  377.  
  378.