home *** CD-ROM | disk | FTP | other *** search
/ Piper's Pit BBS/FTP: ibm 0010 - 0019 / ibm0010-0019 / ibm0010.tar / ibm0010 / ME494-6.ZIP / KEYMAC.SRC < prev    next >
Encoding:
Text File  |  1990-06-08  |  11.4 KB  |  423 lines

  1. $MACRO_FILE KEYMAC;
  2. $MACRO KEYMAC_LIST;
  3. {
  4. @DISPLAY_STRING=D=26K=16
  5. /TP=9/C=1/L=1/W=15/H=KM/T=Keystroke assignment:/DBF=K
  6. /C=1/L=2/W=25/H=KM/T=Description:         /DBF=D
  7. /TP=3/C=1/L=3/W=9/H=KM/T=Mode:                /DBF=M/ISTR=EDIT(KM)DOS_SHELL()TERM()ALL()
  8. /TP=8/C=0/L=4/W=0/H=KM/T=/DBF=S/GSET=1/GSTR=@KM!/ISTR=Edit keystrokes/M=KEYMAC^KEYMAC_EDIT
  9. ****START****
  10. }
  11.     Def_Str(K_Str[2048]);
  12.     Def_Int(T_Mode,K1,K2);
  13.  
  14. {Unload all keys first}
  15.     RM('KEYMAC_LOAD /LM=2/KW=1');
  16. {Bring up editing menu}
  17.   Create_Global_Str('@KMEV1','/T=Playback keystrokes/K1=13/K2=28/R=1/LL=1');
  18.     RM('USERIN^DB /F=KEYMAC.DB/NOALPHA=1/PRE=KM/GLO=@KMG#/LO=3/H=KM/EV1=@KMEV1/S=' +
  19.         Parse_Str('/S=',MParm_Str) +
  20.         '/LT=KEYSTROKE MACRO MANAGER/DT=EDITING KEYSTROKE MACRO/MACRO=KEYMAC_CHECK');
  21.  
  22.     Set_Global_Str('@KMEV1','');
  23.     T_Mode := Return_Int;
  24. {Load new list}
  25.     RM('KEYMAC_LOAD');
  26.     IF (T_Mode = 1) THEN
  27. {Run keystroke macro from menu by temporarily assigning it to a non existant
  28. keystroke, invoking the keystroke, then unassigning it.}
  29.         K_Str := Global_Str('@KMG#');
  30.         T_Mode := Parse_int('M=',K_Str) - 1;
  31.         IF (T_Mode < 0) THEN
  32.             T_Mode := 0;
  33.         END;
  34.         IF (T_Mode = mode) THEN
  35. {Don't do it unless we are in the same mode}
  36.         set_global_str('@KMTEMP!#',Reconvert_String(Parse_str('S=',K_Str)));
  37.         global_to_key($FFFF,'@KMTEMP!#',T_Mode);
  38.             Pass_Key($FF,$FF);
  39.         END;
  40.     END;
  41.  
  42. END_MACRO;
  43.  
  44. $MACRO KEYMAC_EDIT;
  45.     Def_Str(Key_Buf[2048],T_Return_Str);
  46.     Def_Int(Index,Active_Window,Menu_Window,K1,K2,Col,Row,Result,Choice,Old_Row,
  47.                     T_Insert_Mode,TBc,T_Refresh,T_Truncate_Spaces);
  48.  
  49.     Active_Window := Window_Id;
  50.     T_Truncate_Spaces := Truncate_Spaces;
  51.     T_Return_Str := Return_Str;
  52.     T_Refresh := Refresh;
  53.     Refresh := False;
  54.     T_Insert_Mode := Insert_Mode;
  55.     TBC := Box_Count;
  56.     Choice := 1;
  57.     Old_Row := 1;
  58.     Row := Parse_Int('/Y=',MParm_Str);
  59.     IF (Row < 4) THEN
  60.         Row := 4;
  61.     END;
  62.     Col := Parse_Int('/X=',MParm_Str);
  63.     IF (Col < 1) THEN
  64.         Col := 1;
  65.     END;
  66.     Key_Buf := reconvert_string(Global_Str('@KM!'));
  67.     Create_Window;
  68.     Menu_Window := Window_Id;
  69.     File_Name := Fexpand('KEYMAC.TMP');
  70.     Index := 0;
  71.     WHILE (Index < Svl(Key_Buf)) DO
  72.         ++Index;
  73.         K1 := Ascii(Str_Char(Key_Buf,Index));
  74.         ++Index;
  75.         K2 := Ascii(Str_Char(Key_Buf,Index));
  76.         RM('SETUP^MAKEKEY /K1=' + Str(K1) + '/K2=' + Str(K2));
  77.         Put_Line(Return_Str);
  78.         Down;
  79.     END;
  80.     File_Changed := False;
  81.  
  82. KEY_MENU:
  83.     Create_Global_Str('@KMEV1', '/T=Accept/K1=13/K2=28/R=1/LL=1');
  84.     Create_Global_Str('@KMEV2', '/T=Cancel/K1=27/K2=1/R=0/LL=1');
  85.     Create_Global_Str('@KMEV3', '/T=Add/K1=0/K2=82/R=2');
  86.     Create_Global_Str('@KMEV4', '/T=Delete/K1=0/K2=83/R=3');
  87.     Create_Global_Str('@KMEV5', '/T=Change/K1=0/K2=61/R=4');
  88.  
  89.     RM('USERIN^WMENU /OEM=1/NK=1/SP=%<*/EV=@KMEV/EV#=5/T=EDIT KEYSTROKES/H=EDITKS/X=' +
  90.         Str(Col) + '/Y='    + Str(Row) + '/S=' + Str(Choice) + '/OR=' + Str(Old_Row));
  91.  
  92.     Choice := C_Line;
  93.     Old_Row := C_Row;
  94.     Result := Return_Int;
  95.  
  96.     IF (Result = 0) THEN
  97. {Abort edit}
  98.         IF (Global_Str('@KM!') <> convert_string(Key_Buf)) THEN
  99.             RM('USERIN^VERIFY /T=Abort the changes?/C=' + Str(Col + 2) + '/L=' + Str(Row + 2));
  100.             IF (Return_Int) THEN
  101.                 Goto EXIT;
  102.             END;
  103.             Kill_Box;
  104.             Goto KEY_MENU;
  105.         ELSE
  106.             Goto EXIT;
  107.         END;
  108.     END;
  109.     IF (Result = 1) THEN
  110. {Exit and save}
  111.         Set_Global_Str('@KM!',convert_string(Key_Buf));
  112.         Goto EXIT;
  113.     END;
  114.     IF (Result = 2) THEN
  115. {Add a keystroke}
  116.         RM('KEYMAC^KEYMAC_K_PROMPT /T=ADDING A KEYSTROKE/X=' + Str(Col) +
  117.                 '/Y=' + Str(Row + Choice));
  118.         IF (Get_Line <> '') THEN
  119.             Insert_Mode := True;
  120.             Eol;
  121.             Cr;
  122.         END;
  123.          Truncate_Spaces := False;
  124.         Put_Line(Return_Str);
  125.         Choice := C_Line;
  126.         Key_Buf := Str_Ins(Char(Key1) + Char(Key2),Key_Buf,(C_Line * 2) - 1);
  127.         Kill_Box;
  128.         Goto KEY_MENU;
  129.     END;
  130.     IF (Result = 3) THEN
  131. {Delete a keystroke}
  132.         Key_Buf := Str_Del(Key_Buf,(C_Line * 2) - 1,2);
  133.         Del_Line;
  134.         IF (At_Eof) THEN
  135.             --Choice;
  136.         END;
  137.         Kill_Box;
  138.         Goto KEY_MENU;
  139.     END;
  140.     IF (Result = 4) THEN
  141. {change a keystroke}
  142.         Key_Buf := Str_Del(Key_Buf,(C_Line * 2) - 1,2);
  143.         RM('KEYMAC^KEYMAC_K_PROMPT /T=CHANGING A KEYSTROKE/X=' + Str(Col) +
  144.                 '/Y=' + Str(Row + Old_Row + 1));
  145.         Truncate_Spaces := False;
  146.         Put_Line(Return_Str);
  147.         Key_Buf := Str_Ins(Char(Key1) + Char(Key2),Key_Buf,(C_Line * 2) - 1);
  148.         Kill_Box;
  149.         Goto KEY_MENU;
  150.     END;
  151.  
  152. EXIT:
  153.     WHILE (Box_Count > TBC) DO
  154.         Kill_Box;
  155.     END;
  156.     IF (Switch_Win_Id(Menu_Window)) THEN
  157.         Delete_Window;
  158.     END;
  159.     IF (Switch_Win_Id(Active_Window)) THEN
  160.     END;
  161.     Insert_Mode := T_Insert_Mode;
  162.     Return_Str := T_Return_Str;
  163.     Refresh := T_Refresh;
  164. END_MACRO;
  165.  
  166. $MACRO KEYMAC_CHECK;
  167.     Def_int(T_Refresh,k_int,M_Int,K_line,T_Reg_Exp_stat,K_Type,Choice);
  168.     Def_Str(K_Str[30],E_Str[20],M_Str[15],T_Rec[2048]);
  169.  
  170.     IF (Parse_Int('/P=',Mparm_str)) THEN
  171.         T_Refresh := Refresh;
  172.         Refresh := False;
  173.  
  174.         IF (Parse_Str('D=',Global_Str('@KMG#')) = '') THEN
  175. {Don't allow a blank description, put a default one in}
  176.             T_Rec := Global_Str('@KMG#');
  177.             Set_Global_Str('@KMG#','K=' + Parse_Str('K=',T_Rec) +
  178.                 'D=(unnamed)M=' + Parse_Str('M=',T_Rec) +
  179.                 'S=' + Parse_Str('S=',T_Rec));
  180.         END;
  181.  
  182. RECHECK:
  183.         Choice := 0;
  184.         T_Rec := Global_Str('@KMG#');
  185.         K_int := Parse_int('K=',T_Rec);
  186.         M_int := Parse_int('M=',T_Rec) - 1;
  187.         IF (M_Int < 0) THEN
  188.             M_Int := 0;
  189.         END;
  190.         IF (K_int > 0) THEN
  191.  
  192. {First, search for a conflict in the list}
  193.             T_Reg_Exp_Stat := Reg_exp_stat;
  194.             Mark_Pos;
  195.             K_Line := C_Line;
  196.             Tof;
  197.             Reg_exp_stat := true;
  198.  
  199. Search_AGAIN:
  200.             IF (Search_Fwd('K=' + Str(K_Int) + '||$',0)) THEN
  201.                 IF (C_Line = K_Line) THEN
  202.                     Eol;
  203.                     Goto SEARCH_AGAIN;
  204.                 END;
  205.                 K_Type := -1;
  206.                 Goto KEYSTROKE_CONFLICT;
  207.             END;
  208. {Next, check for a conflict in memory}
  209.             K_Type := Inq_Key(K_Int and $FF,(K_Int shr 8) and $FF,M_Int,K_Str);
  210.             IF (K_Type) THEN
  211.                 M_Str := 'Ignore(KM)';
  212.                 IF (K_Type = 1) THEN
  213.                     E_Str := 'macro.';
  214.                 ELSIF (K_Type = 2) THEN
  215. KEYSTROKE_CONFLICT:
  216.                     E_Str := 'keystroke macro.';
  217.                     M_Str := 'Replace(KM)';
  218.                 ELSE
  219.                     E_Str := 'command.';
  220.                 END;
  221.             RM('SETUP^MAKEKEY /K1=' + Str(K_Int and $FF) + '/K2=' +
  222.                     Str((K_Int shr 8) and $FF));
  223.                 RM('MEERROR^Beeps /C=1');
  224.                 Put_Box(15,5,55,10,0,M_B_Color,'WARNING',True);
  225.                 Write('The QuickStroke: ' + Return_Str + ' is already',17,6,0,M_B_Color);
  226.                 Write('assigned to a ' + E_Str,17,7,0,M_B_Color);
  227.                 RM('USERIN^XMENU /T=0/X=17/Y=8/S=1/M=Assign different key(KM)Cancel()'
  228.                     + M_Str);
  229.                 Choice := Return_Int;
  230.                 IF (Choice = 1) THEN
  231.                     RM('KEYMAC^KEYMAC_K_PROMPT /T=ENTER A NEW QuickStroke/X=20/Y=7');
  232.                     Set_Global_Str('@KMG#','D=' + Parse_Str('D=',T_Rec) +
  233.                      'K=' + Str(Return_Int)+
  234.                         'M=' + Str(M_Int) + 'S=' + Parse_Str('S=',T_Rec));
  235.  
  236.                 ELSIF (Choice = 3) THEN
  237.                     IF (K_Type = -1) THEN
  238.                         Put_Line('D=' + Parse_Str('D=',Get_Line) +
  239.                             'M=' + Parse_Str('M=',Get_Line) +
  240.                             'S=' + Parse_Str('S=',Get_Line));
  241.                         Set_Global_Int('@DB_NEED_REBUILD!',1);
  242.                     END;
  243.                 ELSE
  244.                     Set_Global_Str('@KMG#','D=' + Parse_Str('D=',T_Rec) +
  245.                         'M=' + Str(M_Int) + 'S=' + Parse_Str('S=',T_Rec));
  246.                 END;
  247.                 Kill_Box;
  248.             END;
  249.  
  250.             Goto_Mark;
  251.             Reg_Exp_Stat := T_Reg_exp_stat;
  252.  
  253.             IF (Choice = 1) THEN
  254.                 Goto RECHECK;
  255.             END;
  256.  
  257.         END;
  258.  
  259.         Refresh := T_Refresh;
  260.     END;
  261.  
  262. END_MACRO;
  263.  
  264. $MACRO KEYMAC_LOAD;
  265.     Def_Int(Active_Window,Keymac_Window,Window_Created,Keymac_Count,
  266.                     T_Reg_Exp_Stat,T_Mode,T_Refresh,Load_Mode,K_int,Keep_Window);
  267.  
  268.     T_Reg_Exp_Stat := Reg_Exp_Stat;
  269.     T_Refresh := Refresh;
  270.     Refresh := False;
  271.     Load_Mode := Parse_Int('/LM=',MParm_Str);
  272.     Keep_Window := Parse_Int('/KW=',MParm_Str);
  273.     Keymac_Count := 0;
  274.     Reg_Exp_Stat := false;
  275.     Active_Window := Window_Id;
  276.     Return_Str := 'KEYMAC.DB';
  277.     RM('MAKEUSERPATH /DF=1');
  278.     IF (Switch_File(Return_Str) = 0) THEN
  279.         Window_Created := True;
  280.         Create_Window;
  281.         Load_File(Return_Str);
  282.         IF (Error_Level) THEN
  283.             IF (Parse_Int('/NE=',MParm_Str)) THEN
  284.                 Error_Level := 0;
  285.                 Goto EXIT;
  286.             END;
  287.             IF (Load_Mode = 1) THEN
  288.                 RM('MEERROR /EM=Can''t find ' + Return_Str + ' to save this keystroke macro in.');
  289.             ELSIF (Load_mode = 2) THEN
  290.                 RM('MEERROR /EM=Can''t find ' + Return_Str + ' to erase keystroke macros.');
  291.             ELSE
  292.                 RM('MEERROR /EM=Can''t find ' + Return_Str + ' to load keystroke macros.');
  293.             END;
  294.             Goto EXIT;
  295.         END;
  296.     END;
  297.  
  298.     IF (Load_Mode = 1) THEN
  299.         Eof;
  300.         IF (C_Col > 1) THEN
  301.             Down;
  302.         END;
  303.         Put_Line('D=' + Parse_Str('/D=',MParm_Str) + 'K=' +
  304.             Parse_Str('/K=',MParm_Str) + 'M=' + Parse_Str('/M=',MParm_Str) +
  305.             'S=' + Convert_String(Get_Record_Buffer));
  306.         Save_File;
  307.         IF (Error_Level) THEN
  308.             RM('MEERROR /EM=Error saving ' + Return_Str + ' to disk.');
  309.         END;
  310.         Return_Int := C_Line - 6;
  311.     ELSE
  312. {Find each keystroke macro record and set up the global and key assignment}
  313.         Tof;
  314.         IF (Search_Fwd('****START****',0)) THEN
  315.             Down;
  316.             WHILE (Not(At_Eof)) DO
  317.                 IF (Get_Line <> '') THEN
  318.                     T_Mode := Parse_Int('M=',Get_Line) - 1;
  319.                     IF ((T_Mode <> 0) and (T_Mode <> 1) and (T_Mode <> 3)) THEN
  320. {Make sure the ME mode is a legal value}
  321.                         T_Mode := 0;
  322.                     END;
  323.                     K_Int := Parse_Int('K=',Get_Line);
  324.                     IF (K_Int) THEN
  325. {Only load those macros who have a key assigned to them}
  326.                         ++keymac_count;
  327.                         IF (Load_Mode = 2) THEN
  328. {This will unload the macros from memory}
  329.                         set_global_str('@KM!#' + str(keymac_count),'');
  330.                             Unassign_key(k_int,t_mode);
  331.                         ELSE
  332.                         set_global_str('@KM!#' + str(keymac_count),Reconvert_String(Parse_str('S=',Get_Line)));
  333.                         global_to_key(K_Int, '@KM!#' + str(keymac_count),T_Mode);
  334.                         END;
  335.                     END;
  336.                 END;
  337.                 Down;
  338.             END;
  339.         END;
  340.         IF (Load_Mode = 2) THEN
  341.           set_global_int('@KEYMACRO_COUNT@',0);
  342.         ELSE
  343.           set_global_int('@KEYMACRO_COUNT@', keymac_count );
  344.         END;
  345.     END;
  346.  
  347. EXIT:
  348. {
  349. Refresh := True;
  350. Window_Attr := 0;
  351. Eof;
  352. Redraw;
  353. Read_Key;
  354. }
  355.     IF (Window_Created) THEN
  356.         IF (Keep_Window) THEN
  357.             Window_Attr := $81;
  358.         ELSE
  359.             Delete_Window;
  360.         END;
  361.     END;
  362.     IF (Switch_Win_id(Active_Window)) THEN
  363.     END;
  364.     Reg_Exp_Stat := T_Reg_Exp_Stat;
  365.     Refresh := T_Refresh;
  366. END_MACRO;
  367.  
  368. $MACRO KEYMAC_K_PROMPT;
  369.     Def_Int(Col,Row,Width);
  370.     Def_Str(Title[80]);
  371.  
  372.     Row := Parse_Int('/Y=',MParm_Str) + 3;
  373.     IF (Row < 4) THEN
  374.         Row := 4;
  375.     END;
  376.     IF (Row > (Max_Window_Row - 4)) THEN
  377.         Row := 4;
  378.     END;
  379.     Col := Parse_Int('/X=',MParm_Str) + 1;
  380.     IF (Col < 1) THEN
  381.         Col := 1;
  382.     END;
  383.     Title := Parse_Str('/T=',MParm_Str);
  384.     Width := 25;
  385.     IF ((Svl(Title) + 3) > Width) THEN
  386.         Width := Svl(Title) + 3;
  387.     END;
  388.  
  389.     Put_Box(Col,Row,Col + Width,Row + 3,0,M_B_Color,Title,true);
  390.     Write('Press the desired key.',(Col + 1) + (((Width - 3) - 22) / 2),Row + 1,0,M_B_Color);
  391.     Read_Key;
  392.     Return_Int := (Key2 shl 8) or Key1;
  393.  
  394.     RM('MAKEKEY /K1=' + Str(Key1) + '/K2=' + Str(key2));
  395.     Kill_Box;
  396.  
  397. END_MACRO;
  398.  
  399. {*******************************MULTI-EDIT MACRO******************************
  400.  
  401. Name: MakeKeyMac
  402.  
  403. Description:  Takes the keystroke macro information and puts it into
  404.   a global variable.
  405.  
  406.                (C) Copyright 1989 by American Cybernetics, Inc.
  407. ******************************************************************************}
  408. $MACRO MakeKeyMac;
  409.   def_int(count,K_Int);
  410.  
  411.   {Flush the keystroke buffer}
  412.   count := 0;
  413.   WHILE (check_key) AND (count < 100) DO
  414.     ++count;
  415.   END;
  416. {Add the macro to the list}
  417.     RM('KEYMAC^KEYMAC_LOAD /KW=1/LM=1/M=' + Str(Mode + 1));
  418. {Pop up the list and immediately get into the data_in screen for the new macro}
  419.     Push_Key(0,61);
  420.     RM('KEYMAC_LIST /S=' + Str(Return_int));
  421.     Update_Status_Line;
  422. EXIT:
  423. END_MACRO;