home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s1.arc / GETAREAC.MOD < prev    next >
Text File  |  1988-02-01  |  7KB  |  191 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*            GetAreaCode --- Get area code for city/state/country          *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. PROCEDURE GetAreaCode;
  6.  
  7. (*--------------------------------------------------------------------------*)
  8. (*                                                                          *)
  9. (*     Procedure:  GetAreaCode                                              *)
  10. (*                                                                          *)
  11. (*     Purpose:    Searches area code directory                             *)
  12. (*                                                                          *)
  13. (*     Calling sequence:                                                    *)
  14. (*                                                                          *)
  15. (*        GetAreaCode;                                                      *)
  16. (*                                                                          *)
  17. (*     Calls:                                                               *)
  18. (*                                                                          *)
  19. (*        UpperCase                                                         *)
  20. (*        Save_Screen                                                       *)
  21. (*        Draw_Menu_Frame                                                   *)
  22. (*        Restore_Screen                                                    *)
  23. (*        Reset_Global_Colors                                               *)
  24. (*                                                                          *)
  25. (*     Called by:  Execute_Command                                          *)
  26. (*                                                                          *)
  27. (*     Credit:  This area code search is based upon one by Tom Hanlin III   *)
  28. (*              in his ETERM and PASCTERM programs, and one by Martin Smith *)
  29. (*              in his AREA2.EXE program.                                   *)
  30. (*                                                                          *)
  31. (*--------------------------------------------------------------------------*)
  32.  
  33. CONST
  34.    MaxAreaCodes = 300;
  35.  
  36. TYPE
  37.    AreaCodeVectorType = ARRAY[0..MaxAreaCodes] OF STRING[60];
  38.    AreaCodePtr        = ^AreaCodeVectorType;
  39.  
  40. VAR
  41.    LF             : BYTE;
  42.    RT             : BYTE;
  43.    Ptr            : BYTE;
  44.    I              : BYTE;
  45.    Code           : STRING[20];
  46.    Any_Ch         : CHAR;
  47.    AreaCode       : AreaCodePtr;
  48.    AreaCodeFile   : TEXT;
  49.    N_Area_Codes   : INTEGER;
  50.    Searching_Done : BOOLEAN;
  51.    AreaCodeBuf    : ARRAY[1..1024] OF CHAR;
  52.    
  53. (*--------------------------------------------------------------------------*)
  54.  
  55. PROCEDURE Do_Area_Code_Search;
  56.  
  57. VAR
  58.    I: INTEGER;
  59.    
  60. BEGIN (* Searching_Done *)
  61.                                    (* Convert to upper case *)
  62.     Code := UpperCase( Code );
  63.  
  64.                                    (* Determine type of request *)
  65.     IF ( RT = 2 ) AND
  66.        ( Code[1] IN ['A'..'Z']) AND ( Code[2] IN ['A'..'Z'] ) THEN
  67.           LF := 4
  68.     ELSE IF ( RT = 3 ) AND
  69.        ( Code[1] IN ['0'..'9'] ) AND
  70.        ( Code[2] IN ['0'..'9'] ) AND
  71.        ( Code[3] IN ['0'..'9'] ) THEN
  72.           LF := 1
  73.     ELSE IF RT <> 0 THEN
  74.           LF := 6;
  75.                                    (* Display search message *)
  76.  
  77.     Draw_Menu_Frame( 5, 4, 75, 23, Menu_Frame_Color, Menu_Title_Color,
  78.                      Menu_Text_Color, 'Searching for: ' + Code );
  79.  
  80.                                    (* Perform search *)
  81.     View_Count := 0;
  82.     View_Done  := FALSE;
  83.  
  84.     FOR I := 0 TO N_Area_Codes DO
  85.        IF ( NOT View_Done ) THEN
  86.           IF UpperCase( Copy( AreaCode^[I], LF, RT ) ) = Code THEN
  87.              BEGIN
  88.  
  89.                 WRITE  ( '     ' );
  90.                 WRITE  ( Copy( AreaCode^[I], 1, 3 ), '   ' );
  91.                 WRITE  ( Copy( AreaCode^[I], 4, 2 ) ,'   ' );
  92.                 WRITELN( Copy( AreaCode^[I], 6, LENGTH( AreaCode^[I] ) - 5 ) );
  93.  
  94.                 INC( View_Count );
  95.  
  96.                 IF View_Count > 16 THEN
  97.                    View_Prompt( View_Done, View_Count );
  98.  
  99.              END;
  100.  
  101.     RvsVideoOn ( Menu_Text_Color , BLACK );
  102.     WRITE('Search complete. Hit any key to continue.');
  103.     RvsVideoOff( Menu_Text_Color , BLACK );
  104.  
  105.     Read_Kbd( Any_Ch );
  106.     IF ( Any_Ch = CHR( ESC ) ) AND PibTerm_KeyPressed THEN
  107.        Read_Kbd( Any_Ch );
  108.  
  109. END   (* Searching_Done *);
  110.  
  111. (*--------------------------------------------------------------------------*)
  112.  
  113. BEGIN (* GetAreaCode *)
  114.                                    (* Save current screen *)
  115.     Save_Screen( Saved_Screen );
  116.                                    (* Display area code prompt box *)
  117.  
  118.     Draw_Menu_Frame( 5, 4, 75, 23, Menu_Frame_Color, Menu_Title_Color,
  119.                      Menu_Text_Color, 'Area code search' );
  120.  
  121.                                    (* Open area code directory file *)
  122.  
  123.     ASSIGN    ( AreaCodeFile , Home_Dir + 'PIBTERM.ACO' );
  124.     SetTextBuf( AreaCodeFile , AreaCodeBuf );
  125.        (*!I-*)
  126.     RESET ( AreaCodeFile );
  127.        (*!I+*)
  128.                                    (* Check if open went OK *)
  129.     IF ( Int24Result <> 0 ) THEN
  130.        BEGIN
  131.           WRITELN('Area code file ', Home_Dir, ' PIBTERM.ACO cannot be opened.');
  132.           WRITELN;
  133.           Window_Delay;
  134.           Restore_Screen_And_Colors( Saved_Screen );
  135.           EXIT;
  136.        END;
  137.                                    (* Get space for area code entries *)
  138.  
  139.     GetMem( AreaCode , SIZEOF( AreaCodeVectorType ) );
  140.  
  141.     IF ( AreaCode = NIL ) THEN
  142.        BEGIN
  143.           WRITELN('Not enough memory to store area codes for searching.');
  144.           WRITELN;
  145.           Window_Delay;
  146.           Restore_Screen_And_Colors( Saved_Screen );
  147.           EXIT;
  148.        END;
  149.                                    (* Read in area code data *)
  150.  
  151.     WRITELN('Reading area code information ... ');
  152.  
  153.     N_Area_Codes := -1;
  154.  
  155.     REPEAT
  156.        INC( N_Area_Codes );
  157.        READLN( AreaCodeFile , AreaCode^[N_Area_Codes] );
  158.     UNTIL ( EOF( AreaCodeFile ) );
  159.  
  160.        (*!I-*)
  161.     CLOSE( AreaCodeFile );
  162.        (*!I+*)
  163.                                    (* Prompt for and read area code req. *)
  164.     Searching_Done := FALSE;
  165.  
  166.     REPEAT
  167.  
  168.        Clear_Window;
  169.  
  170.        WRITE('Enter area code, state/country, or state initials: ');
  171.        Code := '';
  172.        Read_Edited_String( Code );
  173.  
  174.        RT := LENGTH( Code );
  175.  
  176.        IF ( ( RT > 0 ) AND ( Code <> CHR( ESC ) ) ) THEN
  177.           Do_Area_Code_Search
  178.        ELSE
  179.           Searching_Done := TRUE;
  180.  
  181.     UNTIL( Searching_Done );
  182.                                    (* Free memory for area codes *)
  183.  
  184.     FreeMem( AreaCode , SIZEOF( AreaCodeVectorType ) );
  185.  
  186.                                    (* Restore previous screen *)
  187.  
  188.     Restore_Screen_And_Colors( Saved_Screen );
  189.  
  190. END   (* GetAreaCode *);
  191.