home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s1.arc / GETOTHER.MOD < prev    next >
Text File  |  1988-02-23  |  18KB  |  481 lines

  1. (*----------------------------------------------------------------------*)
  2. (*                Get_Other_Files --- read initialization files         *)
  3. (*----------------------------------------------------------------------*)
  4.  
  5. PROCEDURE Get_Other_Files;
  6.  
  7. (*----------------------------------------------------------------------*)
  8. (*                                                                      *)
  9. (*     Procedure: Get_Other_Files                                       *)
  10. (*                                                                      *)
  11. (*     Purpose:   Reads other initialization files than primary config. *)
  12. (*                file PIBTERM.CNF.                                     *)
  13. (*                                                                      *)
  14. (*     Calling Sequence:                                                *)
  15. (*                                                                      *)
  16. (*        Get_Other_Files;                                              *)
  17. (*                                                                      *)
  18. (*     Calls:                                                           *)
  19. (*                                                                      *)
  20. (*----------------------------------------------------------------------*)
  21.  
  22. VAR
  23.    I                    : INTEGER;
  24.  
  25. (*----------------------------------------------------------------------*)
  26. (*            Read_Prefix_File --- Read dialing prefix file             *)
  27. (*----------------------------------------------------------------------*)
  28.  
  29. PROCEDURE Read_Prefix_File;
  30.  
  31. (*----------------------------------------------------------------------*)
  32. (*                                                                      *)
  33. (*     Procedure:  Read_Prefix_File                                     *)
  34. (*                                                                      *)
  35. (*     Purpose:    Reads dialing prefix file                            *)
  36. (*                                                                      *)
  37. (*     Calling Sequence:                                                *)
  38. (*                                                                      *)
  39. (*        Read_Prefix_File;                                             *)
  40. (*                                                                      *)
  41. (*      Calls:   Read_Config_File                                       *)
  42. (*               Read_Prefix_File                                       *)
  43. (*               Read_Phone_Directory                                   *)
  44. (*                                                                      *)
  45. (*----------------------------------------------------------------------*)
  46.  
  47. VAR
  48.    IPrefix           : INTEGER;
  49.    OK_To_Read        : BOOLEAN;
  50.    Full_Name         : AnyStr;
  51.    Phone_Prefix_File : Text_File;
  52.  
  53. BEGIN (* Read_Prefix_File *)
  54.                                    (* Clear out prefix entries *)
  55.  
  56.    FOR IPrefix := 1 TO Max_Phone_Prefixes DO
  57.       Phone_Prefix_Nos[IPrefix] := '';
  58.  
  59.                                    (* Assign phone prefix file *)
  60.  
  61.    Add_Path( Prefix_File_Name, Home_Dir, Full_Name );
  62.  
  63.    ASSIGN( Phone_Prefix_File , Full_Name );
  64.         (*!I-*)
  65.    RESET( Phone_Prefix_File );
  66.         (*!I+*)
  67.  
  68.    OK_To_Read := ( Int24Result = 0 );
  69.    TextColor( WHITE );
  70.  
  71.    IF NOT OK_To_Read THEN
  72.       WRITELN('Can''t find prefix file ',Full_Name,', no prefixes set.')
  73.  
  74.                                    (* Read prefix entries *)
  75.    ELSE
  76.       BEGIN
  77.  
  78.          WRITELN('Reading phone prefixes from ',Full_Name);
  79.  
  80.          IPrefix := 1;
  81.  
  82.          REPEAT
  83.             READLN( Phone_Prefix_File , Phone_Prefix_Nos[ IPrefix ] );
  84.             Phone_Prefix_Nos[ IPrefix ] :=
  85.                Read_Ctrls( Phone_Prefix_Nos[ IPrefix ] );
  86.             IPrefix := IPrefix + 1;
  87.          UNTIL( EOF( Phone_Prefix_File ) OR ( IPrefix > Max_Phone_Prefixes ) );
  88.  
  89.               (*!I-*)
  90.          CLOSE( Phone_Prefix_File );
  91.               (*!I+*)
  92.  
  93.       END;
  94.                                    (* Write new prefix file *)
  95.  
  96.    IF NOT Ok_To_Read THEN
  97.       BEGIN
  98.  
  99.          ASSIGN( Phone_Prefix_File , Full_Name );
  100.              (*!I-*)
  101.          REWRITE( Phone_Prefix_File );
  102.              (*!I+*)
  103.  
  104.          IF Int24Result <> 0 THEN
  105.             BEGIN
  106.                WRITELN;
  107.                WRITELN('Can''t create new dialing prefix file ',Full_Name,'.')
  108.             END
  109.          ELSE
  110.             BEGIN
  111.  
  112.                WRITELN;
  113.                WRITELN('Creating dialing prefix file ',Full_Name,'.');
  114.  
  115.                FOR IPrefix := 1 TO Max_Phone_Prefixes DO
  116.                   WRITELN( Phone_Prefix_File , Phone_Prefix_Nos[ IPrefix ] );
  117.  
  118.                CLOSE( Phone_Prefix_File );
  119.  
  120.             END;
  121.  
  122.       END;
  123.  
  124. END   (* Read_Prefix_File *);
  125.  
  126. (*----------------------------------------------------------------------*)
  127. (*        Read_Phone_Directory --- Read phone number directory          *)
  128. (*----------------------------------------------------------------------*)
  129.  
  130. PROCEDURE Read_Phone_Directory;
  131.  
  132. (*----------------------------------------------------------------------*)
  133. (*                                                                      *)
  134. (*     Procedure:  Read_Phone_Directory                                 *)
  135. (*                                                                      *)
  136. (*     Purpose:    Read phone directory entries                         *)
  137. (*                                                                      *)
  138. (*     Calling Sequence:                                                *)
  139. (*                                                                      *)
  140. (*        Read_Phone_Directory;                                         *)
  141. (*                                                                      *)
  142. (*      Calls:   Read_Config_File                                       *)
  143. (*               Read_Prefix_File                                       *)
  144. (*                                                                      *)
  145. (*      Remarks:                                                        *)
  146. (*                                                                      *)
  147. (*          Watch out -- some tricky stuff with accessing string data   *)
  148. (*          and lengths is used here.                                   *)
  149. (*                                                                      *)
  150. (*----------------------------------------------------------------------*)
  151.  
  152. VAR
  153.    I          : INTEGER;
  154.    J          : INTEGER;
  155.    L          : INTEGER;
  156.    OK_To_Read : BOOLEAN;
  157.    T_String   : AnyStr;
  158.    Phone_File : Text_File;
  159.    Phone_Str  : AnyStr;
  160.    Full_Name  : AnyStr;
  161.  
  162. BEGIN (* Read_Phone_Directory *)
  163.                                    (* If there wasn't room to store the    *)
  164.                                    (* directory, don't read it in.         *)
  165.  
  166.    IF ( Dialing_Directory = NIL ) THEN
  167.       BEGIN
  168.          Dialing_Dir_Size := 0;
  169.          EXIT;
  170.       END;
  171.                                    (* Indicate we're reading phone numbers *)
  172.  
  173.    Add_Path( Dialing_File_Name, Home_Dir, Full_Name );
  174.  
  175.    WRITELN('Reading dialing directory ',Full_Name);
  176.  
  177.                                    (* Assign phone number file *)
  178.  
  179.    ASSIGN( Phone_File , Full_Name );
  180.         (*!I-*)
  181.    SetTextBuf( Phone_File , Sector_Data );
  182.    RESET( Phone_File );
  183.         (*!I+*)
  184.  
  185.    OK_To_Read := ( INT24Result = 0 );
  186.    TextColor( WHITE );
  187.                                    (* Create phone directory if needed *)
  188.  
  189.    IF ( NOT OK_To_Read ) THEN
  190.       BEGIN  (* Phone directory doesn't exist *)
  191.  
  192.          ASSIGN( Phone_File , Full_Name );
  193.              (*!I-*)
  194.          SetTextBuf( Phone_File , Sector_Data );
  195.          REWRITE( Phone_File );
  196.              (*!I+*)
  197.  
  198.          IF Int24Result <> 0 THEN
  199.             BEGIN
  200.                WRITELN;
  201.                WRITELN('Can''t create new phone directory ',Full_Name,'.')
  202.             END
  203.          ELSE
  204.             BEGIN  (* Create phone directory *)
  205.  
  206.                WRITELN;
  207.                WRITELN('Creating phone directory ',Full_Name,'.');
  208.  
  209.                WITH Phone_Entry_Data DO
  210.                   BEGIN
  211.  
  212.                      CopyStoA( Dupl( '-' , 25 ) , Phone_Name ,   25 );
  213.                      CopyStoA( ' # ### ###-####' , Phone_Number , 15 );
  214.  
  215.                      Phone_Parity   := Parity;
  216.  
  217.                      STR ( Baud_Rate:5 , T_String );
  218.                      CopyStoA( T_String , Phone_Baud , 5 );
  219.  
  220.                      STR ( Data_Bits:1 , T_String );
  221.                      Phone_Databits := T_STRING[1];
  222.  
  223.                      STR ( Stop_Bits:1 , T_String );
  224.                      Phone_StopBits := T_STRING[1];
  225.  
  226.                      IF Local_Echo THEN
  227.                         Phone_Echo := 'Y'
  228.                      ELSE
  229.                         Phone_Echo := 'N';
  230.  
  231.                      IF ( BS_String = CHR( BS ) ) THEN
  232.                         Phone_BackSpace := 'B'
  233.                      ELSE IF ( BS_String = CHR( DEL ) ) THEN
  234.                         Phone_BackSpace := 'D'
  235.                      ELSE
  236.                         Phone_BackSpace := ' ';
  237.  
  238.                      IF Add_LF THEN
  239.                         Phone_LineFeed := 'Y'
  240.                      ELSE
  241.                         Phone_LineFeed := 'N';
  242.  
  243.                      T_String          := COPY( Dec_To_Hex( ORD( Terminal_to_Emulate ) ), 1, 1 );
  244.                      Phone_Term_Type   := T_String[1];
  245.  
  246.                      Phone_Trans_Type  := Trans_Type_Name[ Default_Transfer_Type ];
  247.  
  248.                      Phone_Script      := '         ';
  249.  
  250.                      Phone_Last_Date   := '        ';
  251.  
  252.                      Phone_Last_Time   := '        ';
  253.  
  254.                   END;
  255.  
  256.                Phone_Str[0] := CHR( Dialing_Dir_Entry_Length );
  257.                MOVE( Phone_Entry_Data, Phone_Str[1],
  258.                      Dialing_Dir_Entry_Length );
  259.  
  260.                FOR I := 1 TO Dialing_Dir_Size_Max DO
  261.                   BEGIN
  262.                     Dialing_Directory^[I] := Phone_Entry_Data;
  263.                     WRITELN( Phone_File , Phone_Str );
  264.                   END;
  265.  
  266.                CLOSE( Phone_File );
  267.  
  268.                Dialing_Dir_Size := Dialing_Dir_Size_Max;
  269.  
  270.                EXIT;
  271.  
  272.             END    (* Create phone directory *);
  273.  
  274.       END   (* Phone directory doesn't exist *);
  275.  
  276.                                    (* Finally, read in directory! *)
  277.       (*!I-*)
  278.  
  279.    Dialing_Dir_Size := 0;
  280.  
  281.    REPEAT
  282.  
  283.       READLN( Phone_File, Phone_Str );
  284.  
  285.       L := LENGTH( Phone_Str );
  286.       FOR J := ( L + 1 ) TO Dialing_Dir_Entry_Length DO
  287.          Phone_Str[J] := ' ';
  288.  
  289.       MOVE( Phone_Str[1], Phone_Entry_Data, Dialing_Dir_Entry_Length );
  290.  
  291.       Dialing_Dir_Size                     := Dialing_Dir_Size + 1;
  292.       Dialing_Directory^[Dialing_Dir_Size] := Phone_Entry_Data;
  293.  
  294.    UNTIL( EOF( Phone_File ) OR ( Dialing_Dir_Size >= Dialing_Dir_Size_Max ) );
  295.  
  296.    CLOSE( Phone_File );
  297.       (*!I+*)
  298.  
  299.    I := INT24Result;
  300.  
  301. END   (* Read_Phone_Directory *);
  302.  
  303. (*----------------------------------------------------------------------*)
  304. (*        Read_Function_Keys --- Read function key definitions          *)
  305. (*----------------------------------------------------------------------*)
  306.  
  307. PROCEDURE Read_Function_Keys;
  308.  
  309. (*----------------------------------------------------------------------*)
  310. (*                                                                      *)
  311. (*     Procedure:  Read_Function_Keys                                   *)
  312. (*                                                                      *)
  313. (*     Purpose:    Read function key definitions                        *)
  314. (*                                                                      *)
  315. (*     Calling Sequence:                                                *)
  316. (*                                                                      *)
  317. (*        Read_Function_Keys;                                           *)
  318. (*                                                                      *)
  319. (*      Calls:   Read_Config_File                                       *)
  320. (*               Read_Prefix_File                                       *)
  321. (*               Read_Phone_Directory                                   *)
  322. (*                                                                      *)
  323. (*----------------------------------------------------------------------*)
  324.  
  325. VAR
  326.    Input_Key_File : Text;
  327.    Key_Name       : STRING[4];
  328.    Key_Text       : AnyStr;
  329.    Section_No     : INTEGER;
  330.    Key_Def_Text   : AnyStr;
  331.    Key_Number     : INTEGER;
  332.    L_Text         : INTEGER;
  333.    I              : INTEGER;
  334.    J              : INTEGER;
  335.    Full_Name      : AnyStr;
  336.  
  337. (*----------------------------------------------------------------------*)
  338. (*       Process_Key_Definition --- Process Function Key Definition     *)
  339. (*----------------------------------------------------------------------*)
  340.  
  341. PROCEDURE Process_Key_Definition;
  342.  
  343. (*----------------------------------------------------------------------*)
  344. (*                                                                      *)
  345. (*     Procedure:  Process_Key_Definition                               *)
  346. (*                                                                      *)
  347. (*     Purpose:    Process and store key definition string              *)
  348. (*                                                                      *)
  349. (*     Calling Sequence:                                                *)
  350. (*                                                                      *)
  351. (*        Process_Key_Definition;                                       *)
  352. (*                                                                      *)
  353. (*           On entry, Key_Text should have the key definition text     *)
  354. (*           as read from a file.                                       *)
  355. (*                                                                      *)
  356. (*----------------------------------------------------------------------*)
  357.  
  358. BEGIN (* Process_Key_Definition *)
  359.  
  360.                                    (* Get key name   *)
  361.  
  362.    I        := POS( '=' , Key_Text );
  363.    L_Text   := LENGTH( Key_Text );
  364.  
  365.    IF ( I > 0 ) THEN
  366.       Define_Key( COPY( Key_Text, 1, PRED( I ) ) ,
  367.                   COPY( Key_Text, SUCC( I ) , L_Text - I ) );
  368.  
  369. END   (* Process_Key_Definition *);
  370.  
  371. (*----------------------------------------------------------------------*)
  372.  
  373. BEGIN (* Read_Function_Keys *)
  374.                                    (* Attach file with definitions *)
  375.  
  376.    Add_Path( Function_Key_Name, Home_Dir, Full_Name );
  377.  
  378.    ASSIGN( Input_Key_File , Full_Name );
  379.        (*!I-*)
  380.    RESET ( Input_Key_File );
  381.        (*!I+*)
  382.                                    (* See if openable *)
  383.    IF ( Int24Result = 0 ) THEN
  384.       BEGIN (* File OK, read definitions *)
  385.  
  386.          WRITELN('Reading key definitions from ',Full_Name);
  387.  
  388.          REPEAT
  389.  
  390.             Key_Text       := ' ';
  391.                                    (* Read key definition *)
  392.  
  393.             READLN( Input_Key_File , Key_Text );
  394.  
  395.                                    (* Process it *)
  396.  
  397.             Process_Key_Definition;
  398.  
  399.          UNTIL( EOF( Input_Key_File ) );
  400.  
  401.          CLOSE( Input_Key_File );
  402.  
  403.       END   (* File OK, read definitions *);
  404.  
  405. END   (* Read_Function_Keys *);
  406.  
  407. (*----------------------------------------------------------------------*)
  408. (*        Read_Translate_Table --- Read translate table definitions     *)
  409. (*----------------------------------------------------------------------*)
  410.  
  411. PROCEDURE Read_Translate_Table;
  412.  
  413. (*----------------------------------------------------------------------*)
  414. (*                                                                      *)
  415. (*     Procedure:  Read_Translate_Table                                 *)
  416. (*                                                                      *)
  417. (*     Purpose:    Read translate table definitions                     *)
  418. (*                                                                      *)
  419. (*     Calling Sequence:                                                *)
  420. (*                                                                      *)
  421. (*        Read_Translate_Table;                                         *)
  422. (*                                                                      *)
  423. (*      Calls:   Read_Config_File                                       *)
  424. (*               Read_Prefix_File                                       *)
  425. (*               Read_Phone_Directory                                   *)
  426. (*                                                                      *)
  427. (*----------------------------------------------------------------------*)
  428.  
  429. VAR
  430.    TrTab_File : TEXT;
  431.    I          : INTEGER;
  432.    J          : INTEGER;
  433.    Full_Name  : AnyStr;
  434.  
  435. BEGIN (* Read_Translate_Table *)
  436.  
  437.    Add_Path( Translate_File_Name, Home_Dir, Full_Name );
  438.  
  439.    ASSIGN( TrTab_File , Full_Name );
  440.       (*!I-*)
  441.    RESET ( TrTab_File );
  442.       (*!I+*)
  443.  
  444.    IF ( Int24Result = 0 ) THEN
  445.       BEGIN (* File OK, read definition *)
  446.  
  447.          WRITELN('Reading translate table from ', Full_Name);
  448.  
  449.          REPEAT
  450.                (*!I-*)
  451.             READLN( TrTab_File , I, J );
  452.                (*!I+*)
  453.             IF Int24Result = 0 THEN
  454.                IF ( I >= 0 ) AND ( I <= 255 ) AND
  455.                   ( J >= 0 ) AND ( J <= 255 ) THEN
  456.                   TrTab[CHR(I)] := CHR( J );
  457.  
  458.          UNTIL( EOF( TrTab_File ) );
  459.  
  460.             (*!I-*)
  461.          CLOSE( TrTab_File );
  462.             (*!I+*)
  463.  
  464.       END   (* Get definition from file *);
  465.  
  466. END   (* Read_Translate_Table *);
  467.  
  468. (*----------------------------------------------------------------------*)
  469.  
  470. BEGIN (* Get_Other_Files *)
  471.                                    (* Read dialing prefix file        *)
  472.    Read_Prefix_File;
  473.                                    (* Read dialing entries            *)
  474.    Read_Phone_Directory;
  475.                                    (* Read function key definitions   *)
  476.    Read_Function_Keys;
  477.                                    (* Read translate table definitions*)
  478.    Read_Translate_Table;
  479.  
  480. END   (* Get_Other_Files *);
  481.