home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / PIBTERM / PIBT41S4.ARC / SETINPKS.MOD < prev    next >
Encoding:
Text File  |  1988-02-23  |  25.8 KB  |  728 lines

  1. (*----------------------------------------------------------------------*)
  2. (*      Read_Key_Defs_From_File --- get key definitions from file       *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Read_Key_Defs_From_File( File_Name : AnyStr; Tell : BOOLEAN );
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure:  Read_Key_Defs_From_File                              *)
  10. (*                                                                      *)
  11. (*     Purpose:    Reads function key and keypad key values from file   *)
  12. (*                                                                      *)
  13. (*     Calling Sequence:                                                *)
  14. (*                                                                      *)
  15. (*        Read_Key_Defs_From_File;                                      *)
  16. (*                                                                      *)
  17. (*----------------------------------------------------------------------*)
  18.  
  19. VAR
  20.    Input_Key_File      : TEXT;
  21.    Input_Key_File_Name : AnyStr;
  22.    Key_Name            : STRING[5];
  23.    Key_Text            : AnyStr;
  24.    Section_No          : INTEGER;
  25.    Key_Def_Text        : AnyStr;
  26.    Key_Number          : INTEGER;
  27.    L_Text              : INTEGER;
  28.    I                   : INTEGER;
  29.    J                   : INTEGER;
  30.    Save_Name           : AnyStr;
  31.    Ch                  : CHAR;
  32.    X                   : INTEGER;
  33.    Y                   : INTEGER;
  34.    W                   : INTEGER;
  35.  
  36. (*----------------------------------------------------------------------*)
  37. (*       Process_Key_Definition --- Process Function Key Definition     *)
  38. (*----------------------------------------------------------------------*)
  39.  
  40. PROCEDURE Process_Key_Definition;
  41.  
  42. (*----------------------------------------------------------------------*)
  43. (*                                                                      *)
  44. (*     Procedure:  Process_Key_Definition                               *)
  45. (*                                                                      *)
  46. (*     Purpose:    Process and store key definition string              *)
  47. (*                                                                      *)
  48. (*     Calling Sequence:                                                *)
  49. (*                                                                      *)
  50. (*        Process_Key_Definition;                                       *)
  51. (*                                                                      *)
  52. (*           On entry, Key_Text should have the key definition text     *)
  53. (*           as read from a file.                                       *)
  54. (*                                                                      *)
  55. (*----------------------------------------------------------------------*)
  56.  
  57. BEGIN (* Process_Key_Definition *)
  58.  
  59.                                    (* Ignore comment line *)
  60.    IF ( Key_Text[1] <> '*' ) THEN
  61.       BEGIN
  62.                                    (* Get key name   *)
  63.  
  64.          I        := POS( '=' , Key_Text );
  65.          L_Text   := LENGTH( Key_Text );
  66.  
  67.          IF ( I > 0 ) THEN
  68.             Define_Key( COPY( Key_Text, 1, PRED( I ) ) ,
  69.                         COPY( Key_Text, SUCC( I ) , L_Text - I ) );
  70.  
  71.       END;
  72.  
  73. END   (* Process_Key_Definition *);
  74.  
  75. (*----------------------------------------------------------------------*)
  76.  
  77. BEGIN (* Read_Key_Defs_From_File *)
  78.  
  79.                                    (* Announce input key definition *)
  80.  
  81.    Tell                := Tell OR ( File_Name = '' );
  82.    Input_Key_File_Name := File_Name;
  83.  
  84.    IF Tell THEN
  85.       BEGIN
  86.  
  87.          Draw_Titled_Box( Saved_Screen, 10, 10, 75, 16, 'Read Input Key Definitions' );
  88.  
  89.                                    (* Prompt for file with definitions *)
  90.                                    (* if not already specified         *)
  91.  
  92.          TextColor( Menu_Text_Color_2 );
  93.  
  94.          GoToXY( 2 , 1 );
  95.          WRITE('Enter file name from which to read definitions (ESC to exit): ');
  96.          ClrEol;
  97.          GoToXY( 2 , 2 );
  98.          WRITE('>');
  99.          ClrEol;
  100.  
  101.          TextColor( Menu_Text_Color );
  102.  
  103.          IF ( LENGTH( Input_Key_File_Name ) <= 0 ) THEN
  104.             BEGIN
  105.                Input_Key_File_Name := Function_Key_Name;
  106.                Read_Edited_String( Input_Key_File_Name );
  107.                WRITELN;
  108.             END
  109.          ELSE
  110.             BEGIN
  111.                WRITELN( Input_Key_File_Name );
  112.                Window_Delay;
  113.             END;
  114.  
  115.          IF ( ( LENGTH( Input_Key_File_Name ) <= 0 ) OR
  116.               ( Input_Key_File_Name = CHR( ESC ) ) ) THEN
  117.             BEGIN
  118.                Restore_Screen_And_Colors( Saved_Screen );
  119.                EXIT;
  120.             END;
  121.  
  122.       END;
  123.  
  124.    Input_Key_File_Name := UpperCase( Input_Key_File_Name );
  125.  
  126.                                    (* Assume .FNC if type not given *)
  127.  
  128.    IF ( POS( '.', Input_Key_File_Name ) = 0 ) THEN
  129.       Input_Key_File_Name := Input_Key_File_Name + '.FNC';
  130.  
  131.    Save_Name := Input_Key_File_Name;
  132.  
  133.                                    (* Append function key path if needed *)
  134.  
  135.    Add_Path( Input_Key_File_Name, Function_Key_Path, Input_Key_File_Name );
  136.  
  137.    IF Tell THEN
  138.       TextColor( Menu_Text_Color_2 );
  139.  
  140.                                    (* Attach file with definitions *)
  141.  
  142.    ASSIGN( Input_Key_File , Input_Key_File_Name );
  143.        (*!I-*)
  144.    RESET ( Input_Key_File );
  145.        (*!I+*)
  146.                                    (* See if openable *)
  147.  
  148.    IF ( ( Int24Result <> 0 ) AND Tell ) THEN
  149.       BEGIN (* File bad *)
  150.          WRITELN;
  151.          WRITELN(' *** File ',Input_Key_File_Name,' can''t be found.');
  152.          Window_Delay;
  153.       END   (* File bad *)
  154.    ELSE
  155.       BEGIN (* File OK, read definitions *)
  156.  
  157.          REPEAT
  158.  
  159.             Key_Text       := ' ';
  160.                                    (* Read key definition *)
  161.  
  162.             READLN( Input_Key_File , Key_Text );
  163.  
  164.                                    (* Process it *)
  165.  
  166.             Process_Key_Definition;
  167.  
  168.          UNTIL( EOF( Input_Key_File ) );
  169.  
  170.                                    (* Indicate definitions finished *)
  171.  
  172.  
  173.          IF Tell THEN
  174.             BEGIN
  175.  
  176.                WRITELN(' Function key definitions loaded.');
  177.  
  178.                Window_Delay;
  179.  
  180.                Function_Key_Name := Save_Name;
  181.  
  182.             END;
  183.  
  184.          CLOSE( Input_Key_File );
  185.  
  186.       END   (* File OK, read definitions *);
  187.  
  188.                                    (* Restore previous screen          *)
  189.  
  190.    IF Tell THEN
  191.       Restore_Screen_And_Colors( Saved_Screen );
  192.  
  193. END   (* Read_Key_Defs_From_File *);
  194.  
  195. (*----------------------------------------------------------------------*)
  196. (*       Get_Key_Defs_From_Keyboard --- get key defs. from keyboard     *)
  197. (*----------------------------------------------------------------------*)
  198.  
  199. PROCEDURE Get_Key_Defs_From_Keyboard;
  200.  
  201. (*----------------------------------------------------------------------*)
  202. (*                                                                      *)
  203. (*     Procedure:  Get_Key_Defs_From_Keyboard                           *)
  204. (*                                                                      *)
  205. (*     Purpose:    Read function and keypad key values from keyboard    *)
  206. (*                                                                      *)
  207. (*     Calling Sequence:                                                *)
  208. (*                                                                      *)
  209. (*        Get_Key_Defs_From_Keyboard;                                   *)
  210. (*                                                                      *)
  211. (*----------------------------------------------------------------------*)
  212.  
  213. VAR
  214.    Local_Save : Saved_Screen_Ptr;
  215.    Page_No    : INTEGER;
  216.    Key_Type   : INTEGER;
  217.    Defs_Done  : BOOLEAN;
  218.    Key_Text   : AnyStr;
  219.  
  220. (*----------------------------------------------------------------------*)
  221. (*              Update_Key_Defs --- Update key definitions              *)
  222. (*----------------------------------------------------------------------*)
  223.  
  224. PROCEDURE Update_Key_Defs( VAR Defs_Done : BOOLEAN );
  225.  
  226. (*----------------------------------------------------------------------*)
  227. (*                                                                      *)
  228. (*     Procedure:  Update_Key_Defs                                      *)
  229. (*                                                                      *)
  230. (*     Purpose:    Update key definitions                               *)
  231. (*                                                                      *)
  232. (*     Calling Sequence:                                                *)
  233. (*                                                                      *)
  234. (*        Update_Key_Defs( VAR Defs_Done : BOOLEAN );                   *)
  235. (*                                                                      *)
  236. (*----------------------------------------------------------------------*)
  237.  
  238. VAR
  239.    Key_No     : INTEGER;
  240.    OK_KeyHit  : BOOLEAN;
  241.    I          : INTEGER;
  242.    J          : INTEGER;
  243.    Ch         : CHAR;
  244.    Key_Name   : ShortStr;
  245.    X          : INTEGER;
  246.    Y          : INTEGER;
  247.    W          : INTEGER;
  248.    LKey_Text  : INTEGER;
  249.    LDef       : INTEGER;
  250.  
  251. BEGIN (* Update_Key_Defs *)
  252.                                    (* Not through with definitions yet *)
  253.    Defs_Done := FALSE;
  254.                                    (* Get number of key to change *)
  255.    REPEAT
  256.                                    (* Clear any previous error         *)
  257.       GoToXY( 1 , 2 );
  258.       ClrEol;
  259.  
  260.       TextColor( Menu_Text_Color_2 );
  261.       GoToXY( 1 , 1 );
  262.       WRITE(' Hit key to define or <ESC> to quit: ');
  263.       ClrEol;
  264.       TextColor( Menu_Text_Color );
  265.  
  266.                                    (* Pick ESC or function key sequence *)
  267.       Read_Kbd( Ch );
  268.  
  269.       IF ( Ch <> CHR( ESC ) ) THEN
  270.          OK_KeyHit := FALSE
  271.       ELSE
  272.          IF ( NOT PibTerm_KeyPressed ) THEN
  273.             BEGIN
  274.                Defs_Done := TRUE;
  275.                OK_KeyHit := TRUE;
  276.             END
  277.          ELSE
  278.             BEGIN
  279.                Read_Kbd( Ch );
  280.                Key_No      := ORD( Ch );
  281.                OK_KeyHit   := ( PibTerm_Command_Table[ Key_No ] = KeySendSy );
  282.             END;
  283.                                    (* Not just plain escape -- must be *)
  284.                                    (* function key.                    *)
  285.       IF ( NOT OK_KeyHit ) THEN
  286.          BEGIN
  287.             GoToXY( 1 , 2 );
  288.             WRITE(' *** Not a valid key');
  289.             ClrEol;
  290.             Window_Delay;
  291.          END;
  292.  
  293.    UNTIL ( OK_KeyHit OR Defs_Done );
  294.  
  295.                                    (* If CR entered, quit;        *)
  296.                                    (* else, pick up definition.   *)
  297.    IF ( NOT Defs_Done ) THEN
  298.       BEGIN
  299.                                    (* Display key name *)
  300.  
  301.          Get_Long_Key_Name( Key_Definitions[Key_No].Name , Key_Name );
  302.          WRITE( Key_Name );
  303.          ClrEol;
  304.  
  305.          TextColor( Menu_Text_Color_2 );
  306.          GoToXY( 1 , 2 );
  307.          WRITE(' -->');
  308.          ClrEol;
  309.          TextColor( Menu_Text_Color );
  310.  
  311.                                     (* Prompt for and read new definition *)
  312.  
  313.          WITH Key_Definitions[Key_No] DO
  314.             BEGIN
  315.  
  316.                IF ( Def = NIL ) THEN
  317.                   Key_Text := ''
  318.                ELSE
  319.                   Key_Text := Write_Ctrls( Def^ );
  320.  
  321.                X  := WhereX;
  322.                Y  := WhereY;
  323.  
  324.                W  := MAX( 1 , PRED( Lower_Right_Column - ( PRED( X ) + Upper_Left_Column ) ) );
  325.  
  326.                Ch := Edit_String( Key_Text, 255, X, X, Y, W, FALSE, 0 );
  327.  
  328.                Key_Text  := Read_Ctrls( Key_Text );
  329.                LKey_Text := LENGTH( Key_Text );
  330.  
  331.                IF ( Def = NIL ) THEN
  332.                   GETMEM( Def , SUCC( LKey_Text ) );
  333.  
  334.                IF ( Def <> NIL ) THEN
  335.                   BEGIN
  336.                      LDef := LENGTH( Def^ );
  337.                      IF ( LKey_Text > LDef ) THEN
  338.                         IF ( ( Key_No <> BS_Key ) AND
  339.                              ( Key_No <> Ctrl_BS_Key ) ) THEN
  340.                            BEGIN
  341.                               MyFreeMem( Def , SUCC( LDef ) );
  342.                               GETMEM   ( Def , SUCC( LKey_Text ) );
  343.                            END;
  344.                      IF( Def <> NIL ) THEN
  345.                         Def^ := Key_Text;
  346.                   END;
  347.  
  348.             END (* With *);
  349.  
  350.       END (* NOT Defs_Done *);
  351.  
  352. END   (* Update_Key_Defs *);
  353.  
  354. (*----------------------------------------------------------------------*)
  355.  
  356. BEGIN (* Get_Key_Defs_From_Keyboard *)
  357.  
  358.                                    (* Save screen *)
  359.    Save_Screen( Local_Save );
  360.                                    (* Get back whole screen as window *)
  361.                                    (* for key display                 *)
  362.    PibTerm_Window( 1, 1, 80, 25 );
  363.  
  364.    Draw_Menu_Frame( 5, 11, 75, 16, Menu_Frame_Color, Menu_Title_Color,
  365.                     Menu_Text_Color, 'Input key definition' );
  366.  
  367.    PibTerm_Window( 6, 12, 74, 15 );
  368.  
  369.                                    (* Update key definitions           *)
  370.    REPEAT
  371.       Update_Key_Defs( Defs_Done );
  372.    UNTIL ( Defs_Done );
  373.                                    (* Restore previous screen          *)
  374.  
  375.    Restore_Screen_And_Colors( Local_Save );
  376.  
  377. END   (* Get_Key_Defs_From_Keyboard *);
  378.  
  379. (*----------------------------------------------------------------------*)
  380. (*     Display_Current_Key_Defs --- Display current key definitions     *)
  381. (*----------------------------------------------------------------------*)
  382.  
  383. PROCEDURE Display_Current_Key_Defs;
  384.  
  385. (*----------------------------------------------------------------------*)
  386. (*                                                                      *)
  387. (*     Procedure:  Display_Current_Key_Defs                             *)
  388. (*                                                                      *)
  389. (*     Purpose:    Displays current key definitions                     *)
  390. (*                                                                      *)
  391. (*     Calling Sequence:                                                *)
  392. (*                                                                      *)
  393. (*        Display_Current_Key_Defs;                                     *)
  394. (*                                                                      *)
  395. (*----------------------------------------------------------------------*)
  396.  
  397. CONST
  398.    Quit_Item  = 12;
  399.  
  400. VAR
  401.    Local_Save : Saved_Screen_Ptr;
  402.    Page_No    : INTEGER;
  403.    Key_Menu   : Menu_Type;
  404.    Key_Type   : INTEGER;
  405.    Defs_Done  : BOOLEAN;
  406.    Ch         : CHAR;
  407.    Done       : BOOLEAN;
  408.  
  409. (*----------------------------------------------------------------------*)
  410. (*       Display_Key_Defs --- Display current key definitions           *)
  411. (*----------------------------------------------------------------------*)
  412.  
  413. PROCEDURE Display_Key_Defs( Key_Type : INTEGER );
  414.  
  415. (*----------------------------------------------------------------------*)
  416. (*                                                                      *)
  417. (*     Procedure:  Display_Key_Defs                                     *)
  418. (*                                                                      *)
  419. (*     Purpose:    Display portion of current key definitions           *)
  420. (*                                                                      *)
  421. (*     Calling Sequence:                                                *)
  422. (*                                                                      *)
  423. (*        Display_Key_Defs( Key_Type: INTEGER );                        *)
  424. (*                                                                      *)
  425. (*           Key_Type --- Key type to display.                          *)
  426. (*                        = 1:  F1 through F12                          *)
  427. (*                        = 2:  Shift F1 through Shift F12              *)
  428. (*                        = 3:  Ctrl F1 through Ctrl F12                *)
  429. (*                        = 4:  Alt F1 through Alt F12                  *)
  430. (*                        = 5:  Keypad keys                             *)
  431. (*                        = 6:  Alt keypad keys                         *)
  432. (*                        = 7:  Ctrl keypad keys                        *)
  433. (*                        = 8:  Alt-Number keys                         *)
  434. (*                        = 9:  Extended cursor keys                    *)
  435. (*                        = 10: Extended keypad keys                    *)
  436. (*                        = 11: Miscellaneous keys                      *)
  437. (*                                                                      *)
  438. (*----------------------------------------------------------------------*)
  439.  
  440. VAR
  441.    I          : INTEGER;
  442.    Last_Key   : INTEGER;
  443.    Key_Name   : ShortStr;
  444.    Key_Num    : INTEGER;
  445.    Local_Save : Saved_Screen_Ptr;
  446.    Key_Nos    : ARRAY[1..18] OF BYTE;
  447.  
  448. (* STRUCTURED *) CONST
  449.  
  450.    Keypad_Keys     :  ARRAY[1..16] OF BYTE
  451.                       = (  71,  72,  73,  74,  75,  76,  77,
  452.                            78,  79,  80,  81,  82,  83, 1, 4, 7 );
  453.  
  454.    Alt_Keypad_Keys :  ARRAY[1..16] OF BYTE
  455.                       = ( 173, 174, 175, 176, 177, 178, 179,
  456.                           180, 181, 182, 183, 184, 185, 2, 5, 8 );
  457.  
  458.    Ctrl_Keypad_Keys :  ARRAY[1..16] OF BYTE
  459.                        = ( 119, 160, 132, 161, 115, 162, 116,
  460.                            163, 117, 164, 118, 165, 166, 3, 6, 9 );
  461.  
  462. BEGIN (* Display_Key_Defs *)
  463.  
  464.    GoToXY( 1 , 1 );
  465.                                    (* Display title                *)
  466.    TextColor( Menu_Text_Color_2 );
  467.  
  468.    WRITELN(' --Key Name-- ',
  469.            '   ------------------------Definition-------------------------- ');
  470.    WRITELN(' ');
  471.  
  472.    CASE Key_Type OF
  473.  
  474.       1,
  475.       2,
  476.       3,
  477.       4:  BEGIN
  478.              Last_Key   := 12;
  479.              FOR I := 1 TO 10 DO
  480.                 Key_Nos[ I ] := Funk_Bases[ Key_Type ] + I;
  481.              Key_Nos[ 11 ] := Funk_Bases_2[ Key_Type ] + 11;
  482.              Key_Nos[ 12 ] := Funk_Bases_2[ Key_Type ] + 12;
  483.           END;
  484.       5:  BEGIN
  485.              Last_Key   := 16;
  486.              MOVE( Keypad_Keys[1], Key_Nos[1], 16 );
  487.           END;
  488.       6:  BEGIN
  489.              Last_Key   := 16;
  490.              MOVE( Alt_Keypad_Keys[1], Key_Nos[1], 16 );
  491.           END;
  492.       7:  BEGIN
  493.              Last_Key   := 16;
  494.              MOVE( Ctrl_Keypad_Keys[1], Key_Nos[1], 16 );
  495.           END;
  496.       8:  BEGIN
  497.              Last_Key   := 12;
  498.              FOR I := 1 TO 12 DO
  499.                 Key_Nos[ I ] := PRED( Alt_1 ) + I;
  500.           END;
  501.       9:  BEGIN
  502.              Last_Key := 12;
  503.              FOR I := 1 TO 12 DO
  504.                 Key_Nos[ I ] := PRED( X_U_Arrow ) + I;
  505.           END;
  506.      10:  BEGIN
  507.              Last_Key := 18;
  508.              FOR I := 1 TO 18 DO
  509.                 Key_Nos[ I ] := PRED( X_Home ) + I;
  510.           END;
  511.      11:  BEGIN
  512.              Last_Key := No_Misc_Keys;
  513.              MOVE( Misc_Keys[ 1 ], Key_Nos[ 1 ], No_Misc_Keys );
  514.           END;
  515.  
  516.       ELSE;
  517.  
  518.    END (* CASE *);
  519.                                    (* Display current definitions *)
  520.    FOR I := 1 TO Last_Key DO
  521.       BEGIN
  522.  
  523.          GoToXY( 1 , I + 2 );
  524.          ClrEol;
  525.  
  526.          TextColor( Menu_Text_Color_2 );
  527.  
  528.          Key_Num := Key_Nos[ I ];
  529.  
  530.          Get_Long_Key_Name( Key_Definitions[Key_Num].Name , Key_Name );
  531.          WRITE( ' ', Key_Name );
  532.  
  533.          TextColor( Menu_Text_Color );
  534.  
  535.          GoToXY( 18 , I + 2 );
  536.          IF ( Key_Definitions[Key_Num].Def <> NIL ) THEN
  537.             WRITE( Write_Ctrls( Key_Definitions[ Key_Num ].Def^ ) );
  538.  
  539.       END (* FOR *);
  540.                                    (* Blank out remaining lines *)
  541.  
  542.    FOR I := SUCC( WhereY ) TO 20 DO
  543.       BEGIN
  544.          GoToXY( 1 , I );
  545.          ClrEol;
  546.       END;
  547.  
  548. END   (* Display_Key_Defs *);
  549.  
  550. (*----------------------------------------------------------------------*)
  551.  
  552. BEGIN (* Display_Current_Key_Defs *)
  553.  
  554.                                    (* Save screen *)
  555.  
  556.    Draw_Titled_Box( Local_Save, 1, 2, 80, 24, 'Display input key definitions' );
  557.  
  558.    PibTerm_Window( 2, 3, 78, 23 );
  559.                                    (* Set up menu *)
  560.  
  561.    Make_A_Menu( Key_Menu, Quit_Item, 11, 15, 0, 0, 1,
  562.                 'Select keys to display',
  563.                 'a) Function keys 1 to 12;b) Shifted function keys;c) Ctrl + function keys;' +
  564.                 'd) Alt + function keys;e) Keypad keys;f) Alt + keypad keys;' +
  565.                 'g) Ctrl + keypad keys;h) Alt + number keys;' +
  566.                 'i) Extended cursor keys;j) Extended keypad keys;' +
  567.                 'k) Miscellaneous keys;q) Quit;',
  568.                 FALSE );
  569.  
  570.                                    (* Loop until quit chosen *)
  571.    Done := FALSE;
  572.  
  573.    REPEAT
  574.                                    (* Display menu of choices *)
  575.  
  576.       Menu_Display_Choices( Key_Menu );
  577.       Key_Type := Menu_Get_Choice( Key_Menu , Erase_Menu );
  578.  
  579.                                    (* Do requested operation *)
  580.  
  581.       IF ( ( Key_Type > 0 ) AND ( Key_Type <> Quit_Item ) ) THEN
  582.          BEGIN
  583.             TextColor( Menu_Text_Color );
  584.             TextBackGround( BLACK );
  585.             Display_Key_Defs( Key_Type );
  586.             GoToXY( 1 , 21 );
  587.             TextColor( Menu_Text_Color_2 );
  588.             Press_Any;
  589.          END
  590.       ELSE
  591.          Done := TRUE;
  592.  
  593.       Key_Menu.Menu_Default := Quit_Item;
  594.  
  595.    UNTIL Done;
  596.                                    (* Restore previous screen          *)
  597.  
  598.    Restore_Screen_And_Colors( Local_Save );
  599.  
  600. END   (* Display_Current_Key_Defs *);
  601.  
  602. (*----------------------------------------------------------------------*)
  603. (*  Write_Key_Defs_To_File --- write revised key definitions to file    *)
  604. (*----------------------------------------------------------------------*)
  605.  
  606. PROCEDURE Write_Key_Defs_To_File;
  607.  
  608. (*----------------------------------------------------------------------*)
  609. (*                                                                      *)
  610. (*     Procedure:  Write_Key_Defs_To_File                               *)
  611. (*                                                                      *)
  612. (*     Purpose:    Write updated function key and keypad key values     *)
  613. (*                                                                      *)
  614. (*     Calling Sequence:                                                *)
  615. (*                                                                      *)
  616. (*        Write_Key_Defs_To_File;                                       *)
  617. (*                                                                      *)
  618. (*----------------------------------------------------------------------*)
  619.  
  620. VAR
  621.    Local_Save          : Saved_Screen_Ptr;
  622.    Input_Key_File      : TEXT;
  623.    Input_Key_File_Name : AnyStr;
  624.    Key_Name            : STRING[5];
  625.    Key_Text            : AnyStr;
  626.    Section_No          : INTEGER;
  627.    Key_Def_Text        : AnyStr;
  628.    Key_Number          : INTEGER;
  629.    L_Text              : INTEGER;
  630.    I                   : INTEGER;
  631.    J                   : INTEGER;
  632.    Save_Name           : AnyStr;
  633.  
  634. BEGIN (* Write_Key_Defs_To_File *)
  635.  
  636.                                    (* Indicate write to file *)
  637.  
  638.    Draw_Titled_Box( Local_Save, 10, 10, 75, 14,
  639.                     'Write Function Key Definitions' );
  640.  
  641.                                    (* Get name of file to write to *)
  642.  
  643.    TextColor( Menu_Text_Color_2 );
  644.  
  645.    GoToXY( 2 , 1 );
  646.    WRITE('Enter file name to write definitions to (ESC to exit): ');
  647.    ClrEol;
  648.    GoToXY( 2 , 2 );
  649.    WRITE('>');
  650.    ClrEol;
  651.  
  652.    Input_Key_File_Name := Function_Key_Name;
  653.  
  654.    TextColor( Menu_Text_Color );
  655.    Read_Edited_String( Input_Key_File_Name );
  656.  
  657.    IF ( ( LENGTH( Input_Key_File_Name ) = 0 ) OR
  658.         ( Input_Key_File_Name = CHR( ESC ) ) ) THEN
  659.       BEGIN
  660.          Restore_Screen( Local_Save );
  661.          EXIT;
  662.       END;
  663.                                    (* Assume .FNC if type not given *)
  664.  
  665.    Input_Key_File_Name := UpperCase( Input_Key_File_Name );
  666.  
  667.    IF ( POS( '.', Input_Key_File_Name ) = 0 ) THEN
  668.       Input_Key_File_Name := Input_Key_File_Name + '.FNC';
  669.  
  670.    Save_Name := Input_Key_File_Name;
  671.  
  672.    TextColor( Menu_Text_Color_2 );
  673.  
  674.                                    (* Append function key path if none *)
  675.                                    (* specified                        *)
  676.  
  677.    Add_Path( Input_Key_File_Name, Function_Key_Path, Input_Key_File_Name );
  678.  
  679.                                    (* Ensure file can be opened *)
  680.  
  681.    IF LENGTH( Input_Key_File_Name ) > 0 THEN
  682.       BEGIN
  683.  
  684.          ASSIGN( Input_Key_File , Input_Key_File_Name );
  685.             (*!I-*)
  686.          REWRITE( Input_Key_File );
  687.             (*!I+*)
  688.  
  689.          IF Int24Result <> 0 THEN
  690.             BEGIN (* File bad *)
  691.  
  692.                GoToXY( 2 , 3 );
  693.                WRITE('*** File ',Input_Key_File_Name,' can''t be opened.');
  694.                ClrEol;
  695.  
  696.                Window_Delay;
  697.  
  698.             END   (* File bad *)
  699.          ELSE
  700.             BEGIN (* File OK, definitions written *)
  701.  
  702.                FOR I := 0 TO Max_Key_Def DO
  703.                   WITH Key_Definitions[I] DO
  704.                      IF ( Def <> NIL ) THEN
  705.                         IF LENGTH( Def^ ) > 0 THEN
  706.                            WRITELN( Input_Key_File, Name, '=', Write_Ctrls( Def^ ) );
  707.  
  708.                CLOSE( Input_Key_File );
  709.  
  710.                GoToXY( 2 , 3 );
  711.  
  712.                WRITE('Function key definitions written to ',
  713.                       Input_Key_File_Name );
  714.  
  715.                ClrEol;
  716.  
  717.                Window_Delay;
  718.  
  719.                Function_Key_Name := Save_Name;
  720.  
  721.             END   (* File OK, definitions written *);
  722.  
  723.       END;
  724.                                    (* Restore previous screen          *)
  725.    Restore_Screen( Local_Save );
  726.  
  727. END   (* Write_Key_Defs_To_File *);
  728.