home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / ME494-6.ZIP / INTERCEP.SRC < prev    next >
Encoding:
Text File  |  1990-04-17  |  12.7 KB  |  419 lines

  1. $MACRO_FILE INTERCEP;
  2. {******************************************************************************
  3. Contains a means of intercepting and filtering keystrokes for various purposes.
  4.  
  5.     INTERCEP - The main intercept macro.
  6.  
  7. The remaining macros are simply examples of just a few things that can be done
  8. with INTERCEP:
  9.  
  10.     ASCICODE - Constantly displays the ASCII code of the current character.
  11.     CURCOLOR - An interface for setting the color for HIGHLITE.
  12.     HILITE - Displays the cursor line in a different color.
  13.     ASM_CAPS - Provides an interesting language support for Assembly.
  14.  
  15.                                 Copyright 1989 by American Cybernetics, Inc.
  16. ******************************************************************************}
  17.  
  18. $MACRO INTERCEP;
  19. {******************************************************************************
  20.                                                              MULTI-EDIT MACRO
  21.  
  22. NAME:  INTERCEP
  23.  
  24. DESCRIPTION:  Intercepts all keystrokes and can be used to process keystrokes
  25. based on whatever conditions the user wishes to add.  Once inside this macro,
  26. the only way you can get out is by exiting the editor, or pressing a special
  27. "hot" key currently defined as <ALTQ>.
  28.  
  29.                              (C) Copyright 1989 by American Cybernetics, Inc.
  30. ******************************************************************************}
  31.  
  32. {This simply initializes the color for the macro HILITE}
  33. IF (GLOBAL_INT('Cursor_Line_Color') = 0) THEN
  34.     SET_GLOBAL_INT('Cursor_Line_Color',Error_Color);
  35. END;
  36.  
  37. DO_READ_KEY:
  38.  
  39. {Here is a macro that unconditionally gets run after every keystroke. It
  40. displays the ASCII code of the character at the cursor in decimal and Hex.  If
  41. you don't like it, simply comment out the following line and the similar line
  42. before the GOTO EXIT statement.}
  43.     Run_Macro('ASCICODE /D=Y');
  44.  
  45. {Here is another macro that unconditionally gets run after every keystroke. It
  46. displays the Line the Cursor is on in a user defined color.  Here again, you
  47. may wish to comment it out, along with the matching exit call.
  48.     Run_Macro('HILITE /D=Y');
  49. }
  50.     Read_Key;
  51.  
  52. {Here is the "escape hatch"}
  53.     IF ((Key1 = 0) and (Key2 = 16)) THEN                                    {if ALT-Q was pressed}
  54.         Run_Macro('ASCICODE /D=N');
  55. {        Run_Macro('HILITE /D=N');}
  56.         Goto EXIT;
  57.     END;
  58.  
  59. {The following is an example of a special condition to process keystrokes if the
  60. extension is .ASM for assembly language editing.  If you don't like this one,
  61. comment out the next 3 lines plus the 6th line down.
  62.     IF (Caps(Get_Extension(File_Name)) = 'ASM') THEN
  63.         Run_Macro('ASM_CAPS');
  64.     ELSE}
  65. {Otherwise, the keystroke will be passed to the editor normally}
  66.         Pass_Key(Key1,Key2);
  67. {    END;}
  68.  
  69. {This is to trap any errors generated by macros}
  70.     IF (Error_Level) THEN
  71.         Run_Macro('Meerror');
  72.     END;
  73.  
  74.     Goto DO_READ_KEY;
  75.  
  76. EXIT:
  77. END_MACRO;
  78.  
  79. $MACRO ASCICODE;
  80. {******************************************************************************
  81.                                                              MULTI-EDIT MACRO
  82.  
  83. NAME:  ASCICODE
  84.  
  85. DESCRIPTION:  Constantly displays the decimal and hex ASCII code of the
  86. character at the cursor.
  87.  
  88.                              (C) Copyright 1989 by American Cybernetics, Inc.
  89. ******************************************************************************}
  90.  
  91.     Def_Int(ASCII_Code,X_Offset);
  92.     Def_Str(Ascii_String);
  93. {Set up X coordinate according to window coordinates and whether or not window
  94. is in document mode}
  95.         X_Offset := Win_X1 + (Doc_Mode * 7) + 3;
  96.  
  97. {Check to see if parameter was passed to turn display off}
  98.     IF (Parse_Str('/D=',MParm_Str) = 'N') THEN
  99.         Write('───────────────────',X_Offset,Win_Y1,0,B_color);
  100.         Goto EXIT;
  101.     END;
  102.  
  103. {Store decimal ascii value in integer and string variables}
  104.         ASCII_Code := Ascii(Cur_Char);
  105.         Ascii_String := Str(Ascii_Code);
  106. {Write outlines and zero character padding for decimal}
  107.         Write('D:   ─H:',X_Offset,Win_Y1,0,B_color);
  108.         Write('000',X_Offset + 2,3,0,S_color);
  109. {Write decimal value}
  110.         Write(Ascii_String,X_Offset + 5 - Length(Ascii_String),Win_Y1,0,
  111.                                                                                                                                     S_color);
  112. {Write hex value}
  113.         Write(Copy('0123456789ABCDEF',(ASCII_Code SHR 4) + 1,1) +
  114.                                                         Copy('0123456789ABCDEF',(ASCII_Code and 15) + 1,1),
  115.                                                                         X_Offset + 8,Win_Y1,0,S_color);
  116. EXIT:
  117. END_MACRO;
  118.  
  119. $MACRO CURCOLOR;
  120. {******************************************************************************
  121.                                                              MULTI-EDIT MACRO
  122.  
  123. NAME:  CURCOLOR
  124.  
  125. DESCRIPTION:  Allows the user to set the background and foreground colors for
  126. the macro HILITE
  127.  
  128.                              (C) Copyright 1989 by American Cybernetics, Inc.
  129. ******************************************************************************}
  130.     Def_Int(X1,Y1,Temp_Fore,Temp_Back);
  131.  
  132. {Initialize variables}
  133.     X1 := 20;
  134.     Y1 := 4;
  135.     Temp_Fore := GLOBAL_INT('Cursor_Line_Color') and $0F;
  136.     Temp_Back := GLOBAL_INT('Cursor_Line_Color') shr 4;
  137.     Put_Box(X1,Y1 - 1,X1 + 34,Y1 + 4,0,M_B_Color,'CURSOR LINE COLOR',true);
  138.  
  139. COLOR_LOOP:
  140.     write(' to change foreground color  ',X1 + 1,Y1,0,(Temp_Back shl 4) or (Temp_Fore and $0F));
  141.     write('|27 to change background color. ',X1 + 1,Y1 + 1,0,(Temp_Back shl 4) or (Temp_Fore and $0F));
  142.     write('<ENTER> to accept, <ESC> aborts',X1 + 1,Y1 + 2,0,(Temp_Back shl 4) or (Temp_Fore and $0F));
  143.  
  144.     Read_Key;
  145.  
  146.     IF (Key1 = 27) THEN
  147.         Goto EXIT;
  148.     END;
  149.     IF (Key1 = 13) THEN
  150.         SET_GLOBAL_INT('Cursor_Line_Color',(Temp_Back shl 4) or (Temp_Fore and $0F));
  151.         Goto EXIT;
  152.     END;
  153.     IF (Key1 = 0) THEN
  154.         IF (Key2 = 72) THEN
  155.             --Temp_Fore;
  156.         END;
  157.         IF (Key2 = 80) THEN
  158.             ++Temp_Fore;
  159.         END;
  160.         IF (Key2 = 75) THEN
  161.             --Temp_Back;
  162.         END;
  163.         IF (Key2 = 77) THEN
  164.             ++Temp_Back;
  165.         END;
  166.     END;
  167.     Goto Color_LOOP;
  168.  
  169. EXIT:
  170.     Kill_Box;
  171.  
  172. END_MACRO;
  173.  
  174. $MACRO HILITE;
  175. {******************************************************************************
  176.                                                              MULTI-EDIT MACRO
  177.  
  178. NAME:  HILITE
  179.  
  180. DESCRIPTION:  Constantly displays the line the cursor is on in a user
  181. definable color.  This macro cannot address the problem of horizontal
  182. scrolling or changed lines.
  183.  
  184.                              (C) Copyright 1989 by American Cybernetics, Inc.
  185. ******************************************************************************}
  186.  
  187.     IF (Parse_Str('/D=',MParm_Str) = 'N') THEN
  188. {Exit routine, sets display back to normal}
  189.         Redraw;
  190.         Goto EXIT;
  191.     END;
  192.  
  193.     IF (Marking) THEN
  194.         Goto EXIT;
  195.     END;
  196.  
  197.     Def_Str(Temp_String[132]);
  198.     Def_Int(Width,Jx,Jy,Jz,Reverse);
  199.  
  200.     Reverse := ((Global_Int('Cursor_Line_Color') and $0F) Shl 4) or (GLOBAL_INT('Cursor_Line_Color') shr 4);
  201.  
  202.     Width := Win_X2 - Win_X1 - 1;
  203.  
  204. {If an arrow key was pressed, then write the previously hilited line in normal
  205. colors}
  206.     IF ((Key1 = 0) and (Key2 = 72)) THEN {Up Arrow}
  207. {Go to the line below}
  208.         Down;
  209. {Store displayable part of the line into a variable with enough space padding
  210. to allow for blank lines.  The padding is neccesary if the background color is
  211. different than the regular background color}
  212.         Temp_String := Copy(Get_Line +
  213.                 '                                                                  ' +
  214.                 '                                                                  '
  215.                                                                                                             ,1,Width);
  216. {Change the tab characters to space characters}
  217.         IF Not(Display_Tabs) THEN
  218.             Tabs_To_Spaces(Temp_String);
  219.         END;
  220. {Write it}
  221.         IF (Line_Changed) THEN
  222.             Write(Temp_String,Win_X1 + 1,WhereY,0,C_Color);
  223.         ELSE
  224.             Write(Temp_String,Win_X1 + 1,WhereY,0,T_Color);
  225.         END;
  226. {If we happen to be on a line with a block defined, then write the block in
  227. reverse video}
  228.         IF (Block_Stat) THEN
  229.             IF ((C_Line >= Block_Line1) and (C_Line <= Block_Line2)) THEN
  230.                 IF (Block_Stat = 1) THEN {Line blocks}
  231.                     Write(Temp_String,Win_X1 + 1,WhereY,0,H_Color);
  232.                 END;
  233.                 IF (Block_Stat = 2) THEN {Column blocks}
  234.                     IF (Block_Col1 <= Width) THEN
  235.                         Jx := Block_Col2;
  236.                         IF (Jx > Width) THEN
  237.                             Jx := Width;
  238.                         END;
  239.                         Write(Copy(Temp_String,Block_Col1,Jx - Block_Col1 + 1),
  240.                                                                             Block_Col1,WhereY,0,H_Color);
  241.                     END;
  242.                 END;
  243.                 IF (Block_Stat = 3) THEN {Stream blocks}
  244.                     Jx := 1;
  245.                     Jy := Width;
  246.                     Jz := Jx;
  247.                     IF (C_Line = Block_Line1) THEN
  248.                         IF (Block_Col1 <= Width) THEN
  249.                             Jx := Block_Col1;
  250.                             Jy := Width - Block_Col1 + 1;
  251.                             Jz := Block_Col1;
  252.                         ELSE
  253.                             Goto SKIP1;
  254.                         END;
  255.                     END;
  256.                     IF (C_Line = Block_Line2) THEN
  257.                         IF (Block_Col2 <= Width) THEN
  258.                             Jy := Block_Col2 - Jx + 1;
  259.                         ELSE
  260.                             Jy := Width - Jx + 1;
  261.                         END;
  262.                     END;
  263.                     Write(Copy(Temp_String,Jx,Jy),Jz,WhereY,0,H_Color);
  264.                 END;
  265.             END;
  266.         END;
  267. SKIP1:
  268. {Now, move back where your supposed to be!}
  269.         Up;
  270.     END;
  271.     IF ((Key1 = 0) and (Key2 = 80)) THEN {Down Arrow}
  272.         Up;
  273.         Temp_String := Copy(Get_Line +
  274.                 '                                                                  ' +
  275.                 '                                                                  '
  276.                                                                                                             ,1,Width);
  277.         IF Not(Display_Tabs) THEN
  278.             Tabs_To_Spaces(Temp_String);
  279.         END;
  280.         IF (Line_Changed) THEN
  281.             Write(Temp_String,Win_X1 + 1,WhereY,0,C_Color);
  282.         ELSE
  283.             Write(Temp_String,Win_X1 + 1,WhereY,0,T_Color);
  284.         END;
  285.         IF (Block_Stat) THEN
  286.             IF ((C_Line >= Block_Line1) and (C_Line <= Block_Line2)) THEN
  287.                 IF (Block_Stat = 1) THEN {Line blocks}
  288.                     Write(Temp_String,Win_X1 + 1,WhereY,0,H_Color);
  289.                 END;
  290.                 IF (Block_Stat = 2) THEN {Column blocks}
  291.                     IF (Block_Col1 <= Width) THEN
  292.                         Jx := Block_Col2;
  293.                         IF (Jx > Width) THEN
  294.                             Jx := Width;
  295.                         END;
  296.                         Write(Copy(Temp_String,Block_Col1,Jx - Block_Col1 + 1),
  297.                                                                             Block_Col1,WhereY,0,H_Color);
  298.                     END;
  299.                 END;
  300.                 IF (Block_Stat = 3) THEN {Stream blocks}
  301.                     Jx := 1;
  302.                     Jy := Width;
  303.                     Jz := Jx;
  304.                     IF (C_Line = Block_Line1) THEN
  305.                         IF (Block_Col1 <= Width) THEN
  306.                             Jx := Block_Col1;
  307.                             Jy := Width - Block_Col1 + 1;
  308.                             Jz := Block_Col1;
  309.                         ELSE
  310.                             Goto SKIP2;
  311.                         END;
  312.                     END;
  313.                     IF (C_Line = Block_Line2) THEN
  314.                         IF (Block_Col2 <= Width) THEN
  315.                             Jy := Block_Col2 - Jx + 1;
  316.                         ELSE
  317.                             Jy := Width - Jx + 1;
  318.                         END;
  319.                     END;
  320.                     Write(Copy(Temp_String,Jx,Jy),Jz,WhereY,0,H_Color);
  321.                 END;
  322.             END;
  323.         END;
  324. SKIP2:
  325.         Down;
  326.     END;
  327. {This is the same as above, except it is written to the screen in the alternate
  328. color}
  329.         Temp_String := Copy(Get_Line +
  330.                 '                                                                  ' +
  331.                 '                                                                  '
  332.                                                                                                             ,1,Width);
  333.         IF Not(Display_Tabs) THEN
  334.             Tabs_To_Spaces(Temp_String);
  335.         END;
  336.     Write(Temp_String,Win_X1 + 1,WhereY,0,Global_Int('Cursor_Line_Color'));
  337.         IF (Block_Stat) THEN
  338.             IF ((C_Line >= Block_Line1) and (C_Line <= Block_Line2)) THEN
  339.                 IF (Block_Stat = 1) THEN {Line blocks}
  340.                     Write(Temp_String,Win_X1 + 1,WhereY,0,Reverse);
  341.                 END;
  342.                 IF (Block_Stat = 2) THEN {Column blocks}
  343.                     IF (Block_Col1 <= Width) THEN
  344.                         Jx := Block_Col2;
  345.                         IF (Jx > Width) THEN
  346.                             Jx := Width;
  347.                         END;
  348.                         Write(Copy(Temp_String,Block_Col1,Jx - Block_Col1 + 1),
  349.                                                                             Block_Col1,WhereY,0,Reverse);
  350.                     END;
  351.                 END;
  352.                 IF (Block_Stat = 3) THEN {Stream blocks}
  353.                     Jx := 1;
  354.                     Jy := Width;
  355.                     Jz := Jx;
  356.                     IF (C_Line = Block_Line1) THEN
  357.                         IF (Block_Col1 <= Width) THEN
  358.                             Jx := Block_Col1;
  359.                             Jy := Width - Block_Col1 + 1;
  360.                             Jz := Block_Col1;
  361.                         ELSE
  362.                             Goto SKIP3;
  363.                         END;
  364.                     END;
  365.                     IF (C_Line = Block_Line2) THEN
  366.                         IF (Block_Col2 <= Width) THEN
  367.                             Jy := Block_Col2 - Jx + 1;
  368.                         ELSE
  369.                             Jy := Width - Jx + 1;
  370.                         END;
  371.                     END;
  372.                     Write(Copy(Temp_String,Jx,Jy),Jz,WhereY,0,Reverse);
  373.                 END;
  374.             END;
  375.         END;
  376. SKIP3:
  377. EXIT:
  378. END_MACRO;
  379.  
  380. $MACRO ASM_CAPS;
  381. {******************************************************************************
  382.                                                              MULTI-EDIT MACRO
  383.  
  384. NAME:  ASM_CAPS
  385.  
  386. DESCRIPTION:  This macro is called by INTERCEP.MAC.  It will simulate a forced
  387. "Caps Lock" until a ';' comment delimiter is encountered.  Then it will pass
  388. the keystrokes unaltered.  When <ENTER> is pressed, it will go back to caps lock.
  389.  
  390.                              (C) Copyright 1989 by American Cybernetics, Inc.
  391. ******************************************************************************}
  392.  
  393.     Def_Int(New_Key1,Caps_Lock);
  394.  
  395. {Initialize Caps_Lock flag}
  396.     IF (First_Run) THEN
  397.         Set_Global_Int('Caps_Lock',True);
  398.     END;
  399.  
  400. {Save keycode into a variable}
  401.     New_Key1 := Key1;
  402.     IF (New_Key1 = 13) THEN                                                            {if <ENTER> was pressed}
  403.         Set_Global_Int('Caps_Lock',True);
  404.     END;
  405.     IF (New_Key1 = 59) THEN                                                                        {if ; was pressed}
  406.         Set_Global_Int('Caps_Lock',False);
  407.     END;
  408. {Check status of Caps_Lock flag}
  409.     IF (Global_Int('Caps_Lock')) THEN
  410.         IF (New_Key1 > 96) and (New_Key1 < 123) THEN
  411. {"Upper case" the key code}
  412.             New_Key1 := New_Key1 - 32;
  413.         END;
  414.     END;
  415. {Pass the altered keystoke to the editor}
  416.     Pass_Key(New_Key1,Key2);
  417.  
  418. END_MACRO;
  419.