home *** CD-ROM | disk | FTP | other *** search
/ High Voltage Shareware / high1.zip / high1 / DIR8 / COMMENT5.ZIP / COMMENT5.S next >
Text File  |  1993-06-25  |  18KB  |  519 lines

  1. //*************************************************************************
  2. /************************  Start Comment Area *****************************
  3. File:  comment5.s                                 Tuesday -  June 22, 1993
  4.                                                  Thursday -  June 24, 1993
  5.                                                    Friday -  June 25, 1993
  6.                                TSE Macro
  7.                          COMMENTER version 0.05
  8.       ≈≈    TAKnet Information Service  Fort Wayne, Indiana    ≈≈
  9.       ≈≈        Thomas A. Klein; a.k.a Tom Klein, tak'y        ≈≈
  10.  
  11.   Use, abuse or modify this macro to suit your own needs - \\\...tak
  12.  
  13.   Here's a TSE macro that will place comment characters in front of
  14.   blocked text. It lets you choose from several common comment formats.
  15.   e.g.  `//' `:' `REM' ; or spaces(3-spaces)
  16.  
  17.   For all commented lines the text is moved over three spaces for all
  18.   comment characters except 'REM' which is moved over four spaces.
  19.  
  20. =========================================================================
  21. ___Original Line above:
  22.  
  23.    Samples of Commenter Below 
  24. // =========================================================================
  25. :  =========================================================================
  26. :: =========================================================================
  27. REM =========================================================================
  28. ;  =========================================================================
  29.    =========================================================================
  30.  
  31. comment5:
  32. 06/25/93:  TAK-  First public offering - version 0.05 as 'comment5.zip'
  33.  
  34. 06/25/93:  TAK - Added <space> as a comment character.  When selected it
  35.                  has the effect of moving columns and wrapping text is
  36.                  WordWrap is selected.  Comment to line now does not
  37.                  require block marking, just press comment 'hot key'.
  38.                  Multiple lines may be marked with multiple presses.
  39.  
  40. 06/24/93:  TAK - general cleanup, '// ' now default with comments added
  41.                  instructing the macro user how to change the source
  42.                  file to select the character on the first_pass through
  43.                  the editor.
  44.  
  45. comment4:
  46. 06/22/93:  TAK - still no fix for no comments on lines added by WrapPara(),
  47.                  comment character is now selected only on the
  48.                  'first_pass' thru the macro, moved ChooseChar() to
  49.                  CommenterMenu.  Also on menu are WordWrap toggle, Set
  50.                  Left & Right margins
  51.  
  52. comment3:
  53. 06/16/93:  TAK - remove BackWrap() & WrapPara() and use the TSE internal
  54.                  WrapPara() instead.  Problems listed below. v0.03
  55. comment2:
  56. 06/08/93:  TAK - fix no comments on if line BackWrap()  added lines
  57. 06/07/93:  TAK - first revision to add BackWrap() & WrapPara() and spacing.
  58. 06/07/93:  TAK - making all revisions from this date forward.
  59.  
  60. 05/30/93:  Bob Campbell's original - both comment and reblock
  61.  
  62. //*************************************************************************
  63. //*************************************************************************
  64.  
  65. TAK DEFAULT Key Bindings:
  66.  
  67. < Shift CursorDown >     CommenterMenu()
  68. < Shift CursorLeft >     mLeftMargin()
  69. < Shift CursorRight>     mRightMargin()
  70.  
  71. <Shift CenterCursor>     mCommentLines()   //Keypad 5/CenterCursor
  72.                                            //NumLock must be ON
  73.  
  74. //*************************************************************************
  75.  
  76. 'reblock.s' source is within this file and is not needed externally as
  77. was the case with the orginal version.
  78.  
  79. //*************************************************************************
  80.  
  81. \\\...tak Change dates are noted above.  These additions to the basic
  82.           macro for adding comments (//, ::, REM) to block marked text
  83.           were:
  84.  
  85.  1.  Adding WrapPara() to wrap the paragraph so that commented lines
  86.      would not scroll off the screen.
  87.  
  88.      PROBLEM 1: ColumnBlock marked does not comment lines that may have
  89.                  been added by WrapPara()
  90.  
  91.      PROBLEM 2: LineMarked block adds a comment line to the original
  92.                 paragraph if no line was added by WrapPara().
  93.  
  94.  2.  Added a menu item to change the right & left margin, WordWrap()
  95.  
  96.  3.  CommenterMenu() has selections to Select Comment character, WordWrap
  97.      Toggle(ON/OFF), and items to select the right and left margins with
  98.      the current margins displayed.
  99.  
  100.  4.  Removed the selection of comment character from the Main() loop so
  101.      now if no comment character is chosen the default is '// ' or user
  102.      may change the source code to enable selection on the first_pass
  103.      thru the macro.
  104.  
  105.      To change the commenting character at anytime choose 'Select Char.'
  106.      from the CommenterMenu() via <Shift CursorDown> key. Selection is
  107.      never prompted and will remain either the default or previously
  108.      selected character until changed via the Commenter Menu.  Current
  109.      character is also displayed on the menu.
  110.  
  111. Acknowledgements:  Bob Campbell for the original commenting macro.
  112.                    George J. De Bruin for his selection menu in 'boxit'
  113.                    and several unremembered messagers who's ideas I may
  114.                    have adapted or even used outright <BGWD&R>.
  115.                    All of the SemWare Team for such a great platform.
  116.  
  117. Thanks to all.
  118. ===========================================================================
  119.              Original -- Date: 05-30-93  From: BOB CAMPBELL
  120.    Subj: TSE - Comment.s & Reblock.s  Note: Both within this macro
  121. ---------------------------------------------------------------------------
  122.  
  123.   *************************************************************************/
  124. //tak******************* END of Comment Area ******************************
  125.  
  126.  
  127. /************************************************************************
  128.   Comment.s  -   Macro places comment characters in front of blocked text
  129.  *************************************************************************/
  130.  
  131. /************************************************************************
  132.  
  133. 05-30-93: 'comment.s' & 'reblock.s' submitted by Bob Campbell
  134.  
  135.            Code for LongestLine() is barrowed from LONGSTLN.S by Ray Asbury
  136.  
  137.    ASSUMPTIONS: ReBlock.s must be available for compiling the original
  138.                 'comment.s' but is within this comment# macro so the
  139.                 code is standalone and requires nothing else to function.
  140.  
  141.    GLOBAL VARS: integer h
  142.                 string char[1]
  143.                 string character1[1]
  144.                 string character2[1]
  145.                 string character3[1]
  146.                 integer first_line, line_no
  147.  
  148.    LOCAL VARS:
  149.                 integer n
  150.                 integer Tp=0
  151.                 integer Bm=0
  152.                 integer h2
  153.  
  154.  **************************************************************************/
  155.  
  156. //*************************************************************************
  157. // #include "reblock.s"  // Instead of #include source code is here
  158. //*************************************************************************
  159.  
  160. /**************************************************************************
  161.   File:  a:\reblock.s         Tuesday -  June 1, 1993 at 0733 hrs.
  162. ===========================================================================
  163.   Date: 05-30-93 (23:05) From: BOB CAMPBELL Subj: TSE - Reblock.s
  164. ---------------------------------------------------------------------------
  165.  
  166. ReBlock() will probably come in handy for a lot of macros that use
  167. blocking so I wrote it as an #include file.
  168.  
  169. It converts MarkLine to Column Blocking.  <-------- important
  170.  
  171. I plan to improve it by making it work both ways, Column to MarkLine and
  172. MarkLine to Column .
  173.  
  174.  ************************************************************************/
  175. //tak******************* END of Comment Area ******************************
  176.  
  177. /************************************************************************
  178.          Reblocks MarkLine blocked text to Column Blocked
  179. *************************************************************************/
  180.  
  181. /* 05-30-93: Submitted by Bob Campbell
  182.  
  183.    Code for BigestLine() is barrowed from LONGSTLN.S by Ray Asbury
  184.  
  185.    LOCAL VARS:
  186.             BiggesttLine():
  187.                 integer max_len
  188.                 integer last_line
  189.                 integer line_no
  190.             ReBlock():
  191.                 integer LastCol
  192. **************************************************************************/
  193. //tak******************* END of Comment Area *****************************
  194.  
  195. //  Code for BiggestLine() is barrowed from LONGSTLN.S by Ray Asbury
  196.  
  197. Integer first_line, last_line
  198.  
  199. proc BiggestLine()
  200.  
  201.      integer         max_len = 0,
  202.                      line_no,
  203.                      first_col
  204.  
  205.     GotoBlockBegin()
  206.     last_line = Query(BlockEndLine)
  207.     max_len = CurrLineLen()
  208.     line_no = CurrLine()
  209.     first_line = line_no
  210.  
  211.     while Down() and (CurrLine() <= last_line)
  212.         if CurrLineLen() > max_len
  213.             max_len = CurrLineLen()
  214.             line_no = CurrLine()
  215.         endif
  216.     endwhile
  217.  
  218.         KillPosition()          // kill pushed position since
  219.         GotoLine(line_no)       // we're going to the new line
  220.     return ()
  221.  
  222. end BiggestLine
  223.  
  224. /*************************************************************************/
  225.  
  226. proc ReBlock()           // ReBlocks  _LINE_ block with _COLUMN_ block
  227.     integer LastCol
  228.     BiggestLine()
  229.     EndLine()
  230.     LastCol=CurrCol()
  231.     GotoBlockEnd()
  232.     GotoColumn(LastCol)
  233.     PushPosition()
  234.     GotoBlockBegin()
  235.     BegLine()
  236.     UnMarkBlock()
  237.     MarkColumn()
  238.     PopPosition()
  239. end ReBlock
  240. /**************************************************************************
  241.     TSE reblock() for changing BlockMarking to ColumnMarking
  242.  **************************************************************************/
  243.  
  244. //*************************************************************************
  245. //GLOBAL VARIABLES:
  246.  
  247.     integer h
  248.     string char[1]=" ",
  249.            character1[1]=" ",
  250.            character2[1]=" ",
  251.            character3[1]=" "
  252.  
  253. //Global Variables for menus 06/24/93 & 06/25/93
  254.  
  255. string symbol[3]="// "       //Used display current selection in menu
  256. integer first_pass = 0       //0 on first run to select comment character
  257.  
  258. //*************************************************************************
  259. menu Charmenu()
  260.  
  261.     Title = "Character Selections"
  262.     Width = 26
  263.     History                         // Added this line rev. 06/01/93
  264.     "&// "
  265.     "&:     Colon"
  266.     ":: "
  267.     "&REM "
  268.     "&;     Semicolon"              // Added '; ' for asm   06/24/93
  269.     "<&sp>  3 spaces"
  270.     "&Quit"
  271.  
  272. end
  273.  
  274. //*************************************************************************
  275. proc ChooseChar()
  276.  
  277.     integer n=Charmenu()
  278.  
  279. //Global String Variable 'symbol' added for displaying current selection
  280.  
  281.     case(n)
  282.         when 1
  283.             character1="/"
  284.             character2="/"
  285.             character3=" "
  286.             symbol=character1+character2+character3
  287.         when 2
  288.             character1=":"
  289.             character2=" "
  290.             character3=" "
  291.             symbol=character1+character2+character3
  292.         when 3
  293.             character1=":"
  294.             character2=":"
  295.             character3=" "
  296.             symbol=character1+character2+character3
  297.         when 4
  298.             character1="R"
  299.             character2="E"
  300.             character3="M"
  301.             symbol=character1+character2+character3
  302.         when 5
  303.             character1=";"
  304.             character2=" "
  305.             character3=" "
  306.             symbol=character1+character2+character3
  307.         when 6
  308.             character1=" "
  309.             character2=" "
  310.             character3=" "
  311.             symbol="sp "
  312.  
  313.         when 7
  314.             character3="Q"
  315.     endcase
  316. first_pass=99
  317. end
  318.  
  319. //*************************************************************************
  320. Integer proc BoxHeight() // Returns Height of Block
  321.  
  322.     integer Tp=0, Bm=0
  323.     GotoBlockBegin()
  324.     Tp = CurrLine()
  325.     GotoBlockEnd()
  326.     Bm = CurrLine()
  327.     return(Bm-Tp+1)
  328.  
  329. end BoxHeight
  330.  
  331. //*************************************************************************
  332. ///Original code with tak revision to add BackWrap            June 22, 1993
  333.  
  334. proc MoveOver()            // Move block Right by three spaces
  335.  
  336.     integer col_location
  337. //    string  debug_info[40]
  338.  
  339.     GotoBlockBegin()
  340.     Cut()
  341.     BegLine()
  342.     if character3 == " "
  343.         Right(3)
  344.     else
  345.         Right(4)
  346.     endif
  347.     Paste()
  348.  
  349. // UnMarkBlock()                        //original location
  350. // end                                  //MoveOver()
  351. // END MoveOver()                       //original END
  352.  
  353.  
  354. //**************************************************************************
  355. //tak <start of changes>                            Tuesday -  June 22, 1993
  356.       if Query(WordWrap)==ON
  357.       WrapPara()
  358.       endif
  359.       GoToLine(first_line)
  360.       UnMarkBlock()                       //From original code
  361.  
  362. end MoveOver
  363.  
  364. // ************************************************************************
  365. // New end of MoveOver()  Tuesday -  June 22, 1993
  366. // ************************************************************************
  367.  
  368. proc fillchar()          // Fill vertical block with comment character
  369.  
  370.     integer h2=h
  371.     MarkColumn()
  372.        While(h2>=1)
  373.            Down()
  374.            h2=h2-1
  375.        Endwhile
  376.     FillBlock(char)
  377.     UnMarkBlock()
  378. end
  379.  
  380. //*************************************************************************
  381. proc Comment()           // Selects columns for comment characters
  382.  
  383.     char=character1      // fills column one
  384.     BegLine()
  385.     pushposition()
  386.     FillChar()
  387.  
  388.     char=character2      // fills column two
  389.     UnMarkBlock()
  390.     popposition()
  391.     pushposition()
  392.     Right(1)
  393.     FillChar()
  394.  
  395.     char=character3      // fills column three
  396.     UnMarkBlock()
  397.     popposition()
  398.     Right(2)
  399.     FillChar()
  400.     UnMarkBlock()
  401. end
  402.  
  403.  
  404. //*************************************************************************
  405. //Previously main() macro
  406. //*************************************************************************
  407.  
  408. proc mCommentLines()
  409.  
  410. // On the first pass select the default comment characters and
  411. // thereafter don't ask.  To change character use the CommenterMenu.
  412.  
  413. if first_pass==0
  414.  
  415. // Sets default comment character to '// '
  416.  
  417.       character1="/"
  418.       character2="/"
  419.       character3=" "
  420.       symbol=character1+character2+character3
  421.  
  422. //  If you want to select the comment character the first time the macro
  423. //  is run the comment out the above default and uncomment the items
  424. //  below. A selection will occur only on the first_pass.  If you want
  425. //  to change the after the first pass then use the menu 'Select Char.'
  426. //  item.
  427.  
  428. //      ChooseChar()
  429. //          if character3=="Q"
  430. //          return()
  431. //      endif
  432.  
  433.    first_pass=99
  434.  
  435. endif
  436.  
  437.     if isBlockInCurrFile() == FALSE
  438.         markline()
  439.     endif
  440.     ReBlock()
  441.     h=BoxHeight()
  442.     if h>=1
  443.         h=h-1
  444.         MoveOver()      //now contains WrapPara()
  445.         Comment()
  446.         Copy(_append_)
  447.     endif
  448.     BegLine()
  449.     GoToLine(last_line +1)    //This allows marking single lines without
  450.                               //having to mark any block. Uses CurrLine
  451.  
  452. end  mCommentLines
  453.  
  454. // <Shift CenterCursor>  mCommentLines()   //Keypad 5/CenterCursor
  455.  
  456. //***********************************************************************/
  457. // Monday -  June 7, 1993  Macros to view and/or set Right & Left Margins
  458. // mRightMargin()-keypad 6/CursorRight; mLeftMargin()-keypad 4/CursorLeft
  459. //***********************************************************************/
  460.  
  461.  
  462. Proc mRightMargin()
  463.     string fn[3] = ""
  464.     Message("Current Right Margin: ",Query(RightMargin))
  465.     if Ask("Right Margin: ",fn) and Length(fn)
  466.         Set(Rightmargin,Val(fn))
  467.     endif
  468. End  // bound to keypad 6/CursorRight
  469.  
  470. Proc mLeftMargin()
  471.     string fn[3] = ""
  472.     Message("Current Left Margin: ",Query(LeftMargin))
  473.     if Ask("Left Margin: ",fn) and Length(fn)
  474.         Set(LeftMargin,Val(fn))
  475.     endif
  476. End  // bound to keypad 4/CursorLeft
  477.  
  478. //*************************************************************************
  479. //*************************************************************************
  480.  
  481. /* ------------------------------------------------------------------- */
  482. // Used for CommenterMenu ON/OFF Toggle                       06/17/93
  483.         string proc OnOffStr(integer i)
  484.             return (iif(i, "On", "Off"))
  485. end
  486. /* ------------------------------------------------------------------- */
  487.  
  488. menu CommenterMenu()
  489.  
  490.     Title = 'Commenter 0.05 Menu'
  491.     NoKeys
  492.     History
  493.     "",,Skip
  494.     "&Add comment to Block", mCommentLines()
  495.     "&Select Char.  Now -->"[Symbol:3],ChooseChar()
  496.     "&PURGE This Macro", PurgeMacro(CurrMacroFileName())
  497.     "",,divide
  498.     "        SET Options",,Skip
  499.     "",,divide
  500.     "&WordWrap"   [OnOffStr(Query(WordWrap)):3], Toggle(WordWrap),
  501.            DontClose
  502.     "&RIGHT Margin"  [Query(RightMargin):3], mRightMargin(), DontClose
  503.     "&Left Margin"   [Query(LeftMargin):3],  mLeftMargin() , DontClose
  504.  
  505. end // CommenterMenu()
  506.  
  507. // TAK keypresses: NumLock=ON and use Keypad with no Shift key press
  508.  
  509. < Shift CursorDown >     CommenterMenu()
  510. < Shift CursorLeft >     mLeftMargin()
  511. < Shift CursorRight>     mRightMargin()
  512.  
  513. <Shift CenterCursor>     mCommentLines()   //Keypad 5/CenterCursor
  514.                                            //NumLock must be ON
  515. /**************************************************************************
  516.  Two macros:  reblock.s and comment.s - combined for comment#.s   06/22/93
  517.  Thursday -  June 24, 1993;
  518. **************************************************************************/
  519.