home *** CD-ROM | disk | FTP | other *** search
/ Power Programming / powerprogramming1994.iso / progtool / pibterm / pibt41s1.arc / GETCONFI.MOD < prev    next >
Text File  |  1988-02-06  |  5KB  |  119 lines

  1. (*--------------------------------------------------------------------------*)
  2. (*      Get_Config_File_Line --- Get one parameter line from config file    *)
  3. (*--------------------------------------------------------------------------*)
  4.  
  5. FUNCTION Get_Config_File_Line(  VAR Config_File : Text_File;
  6.                                 VAR Param_Num   : INTEGER;
  7.                                 VAR Param_Str   : AnyStr;
  8.                                 VAR Param_Ival  : INTEGER;
  9.                                 VAR Param_Rval  : LONGINT ) : BOOLEAN;
  10.  
  11. (*--------------------------------------------------------------------------*)
  12. (*                                                                          *)
  13. (*     Function:  Get_Config_File_Line                                      *)
  14. (*                                                                          *)
  15. (*     Purpose:   Reads and interprets one line of configuration file       *)
  16. (*                                                                          *)
  17. (*     Calling Sequence:                                                    *)
  18. (*                                                                          *)
  19. (*        QGot := Get_Config_File_Line(  VAR Config_File : Text_File;       *)
  20. (*                                       VAR Param_Num   : INTEGER;         *)
  21. (*                                       VAR Param_Str   : AnyStr;          *)
  22. (*                                       VAR Param_Ival  : INTEGER;         *)
  23. (*                                       VAR Param_Rval  : LONGINT):BOOLEAN;*)
  24. (*                                                                          *)
  25. (*           Config_File --- the configuration file                         *)
  26. (*           Param_Num   --- parameter number of this line                  *)
  27. (*           Param_Str   --- string value of parameter                      *)
  28. (*           Param_Ival  --- Integer value of parameter                     *)
  29. (*           Param_Rval  --- Real value of parameter                        *)
  30. (*                                                                          *)
  31. (*           Qgot        --- TRUE if configuration line returned;           *)
  32. (*                           FALSE if end-of-file encountered on            *)
  33. (*                           configuration file.                            *)
  34. (*                                                                          *)
  35. (*--------------------------------------------------------------------------*)
  36.  
  37. VAR
  38.    I:       INTEGER;
  39.    S:       AnyStr;
  40.    PName:   Char_2;
  41.    L:       INTEGER;
  42.    NumDone: BOOLEAN;
  43.    IVal   : LONGINT;
  44.  
  45. BEGIN (* Get_Config_File_Line *)
  46.                                    (* Initialize parameter values *)
  47.    Param_Num  := 0;
  48.    Param_Str  := '';
  49.    Param_Ival := 0;
  50.    Param_Rval := 0;
  51.    IVal       := 0;
  52.  
  53.    IF NOT EOF( Config_File ) THEN
  54.       BEGIN
  55.  
  56.          Get_Config_File_Line := TRUE;
  57.  
  58.                                    (* Indicate line from configuration file *)
  59.          READLN( Config_File , S );
  60.  
  61.                                    (* If comment line, skip it.             *)
  62.  
  63.          IF ( LENGTH( S ) > 0 ) THEN
  64.             IF ( S[1] = '*' ) THEN
  65.                EXIT;
  66.                                    (* Pick up parameter name.  Only first 2 *)
  67.                                    (* characters matter, skip rest up to    *)
  68.                                    (* '='.                                  *)
  69.  
  70.          S         := S + '    ';
  71.          PName[1]  := UpCase( S[1] );
  72.          PName[2]  := UpCase( S[2] );
  73.          L         := LENGTH( S );
  74.          I         := 1;
  75.  
  76.          WHILE( ( I <= L ) AND ( S[I] <> '=' ) ) DO
  77.             INC( I );
  78.  
  79.          Param_Str := Trim( COPY( S, SUCC( I ), LENGTH( S ) - I ) );
  80.  
  81.                                    (* Search for parameter.           *)
  82.                                    (* If found, convert to numeric if *)
  83.                                    (* appropriate                     *)
  84.  
  85.          Param_Num := Look_Up_Parameter( PName );
  86.  
  87.          IF ( Param_Num > 0 ) THEN
  88.             BEGIN
  89.  
  90.                   L       := LENGTH( Param_Str );
  91.                   NumDone := ( L = 0 );
  92.                   I       := 0;
  93.  
  94.                   WHILE ( NOT NumDone ) DO
  95.                      BEGIN
  96.                         INC( I );
  97.                         IF Param_Str[I] IN ['0'..'9'] THEN
  98.                            Ival := Ival * 10 +
  99.                                    ORD( Param_Str[I] ) - ORD( '0' );
  100.                         NumDone := NumDone OR ( I >= L ) OR
  101.                                    ( Param_Str[I] = ' ');
  102.                      END;
  103.  
  104.                   IF ( L > 0 ) THEN
  105.                      IF ( UpCase( Param_Str[1] ) = 'Y' ) THEN
  106.                         Ival := 1;
  107.  
  108.                Param_IVal := IVal;
  109.                Param_Rval := Ival;
  110.  
  111.             END;
  112.  
  113.       END
  114.  
  115.    ELSE
  116.       Get_Config_File_Line := FALSE;
  117.  
  118. END   (* Get_Config_File_Line *);
  119.