Home | History | Annotate | Download | only in Common
      1 /*++
      2 
      3 Copyright (c) 2004 - 2010, Intel Corporation. All rights reserved.<BR>
      4 This program and the accompanying materials
      5 are licensed and made available under the terms and conditions of the BSD License
      6 which accompanies this distribution.  The full text of the license may be found at
      7 http://opensource.org/licenses/bsd-license.php
      8 
      9 THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,
     10 WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.
     11 
     12 Module Name:
     13 
     14   ParseInf.h
     15 
     16 Abstract:
     17 
     18   Header file for helper functions useful for parsing INF files.
     19 
     20 --*/
     21 
     22 #ifndef _EFI_PARSE_INF_H
     23 #define _EFI_PARSE_INF_H
     24 
     25 #include "TianoCommon.h"
     26 #include <stdio.h>
     27 #include <stdlib.h>
     28 
     29 //
     30 // Common data structures
     31 //
     32 typedef struct {
     33   CHAR8 *FileImage;
     34   CHAR8 *Eof;
     35   CHAR8 *CurrentFilePointer;
     36 } MEMORY_FILE;
     37 
     38 //
     39 // Functions declarations
     40 //
     41 CHAR8 *
     42 ReadLine (
     43   IN MEMORY_FILE    *InputFile,
     44   IN OUT CHAR8      *InputBuffer,
     45   IN UINT32         MaxLength
     46   );
     47 
     48 /*++
     49 
     50 Routine Description:
     51 
     52   This function reads a line, stripping any comments.
     53   The function reads a string from the input stream argument and stores it in
     54   the input string. ReadLine reads characters from the current file position
     55   to and including the first newline character, to the end of the stream, or
     56   until the number of characters read is equal to MaxLength - 1, whichever
     57   comes first.  The newline character, if read, is replaced with a \0.
     58 
     59 Arguments:
     60 
     61   InputFile     Memory file image.
     62   InputBuffer   Buffer to read into, must be _MAX_PATH size.
     63   MaxLength     The maximum size of the input buffer.
     64 
     65 Returns:
     66 
     67   NULL if error or EOF
     68   InputBuffer otherwise
     69 
     70 --*/
     71 BOOLEAN
     72 FindSection (
     73   IN MEMORY_FILE    *InputFile,
     74   IN CHAR8          *Section
     75   );
     76 
     77 /*++
     78 
     79 Routine Description:
     80 
     81   This function parses a file from the beginning to find a section.
     82   The section string may be anywhere within a line.
     83 
     84 Arguments:
     85 
     86   InputFile     Memory file image.
     87   Section       Section to search for
     88 
     89 Returns:
     90 
     91   FALSE if error or EOF
     92   TRUE if section found
     93 
     94 --*/
     95 EFI_STATUS
     96 FindToken (
     97   IN MEMORY_FILE    *InputFile,
     98   IN CHAR8          *Section,
     99   IN CHAR8          *Token,
    100   IN UINTN          Instance,
    101   OUT CHAR8         *Value
    102   );
    103 
    104 /*++
    105 
    106 Routine Description:
    107 
    108   Finds a token value given the section and token to search for.
    109 
    110 Arguments:
    111 
    112   InputFile Memory file image.
    113   Section   The section to search for, a string within [].
    114   Token     The token to search for, e.g. EFI_PEIM_RECOVERY, followed by an = in the INF file.
    115   Instance  The instance of the token to search for.  Zero is the first instance.
    116   Value     The string that holds the value following the =.  Must be _MAX_PATH in size.
    117 
    118 Returns:
    119 
    120   EFI_SUCCESS             Value found.
    121   EFI_ABORTED             Format error detected in INF file.
    122   EFI_INVALID_PARAMETER   Input argument was null.
    123   EFI_LOAD_ERROR          Error reading from the file.
    124   EFI_NOT_FOUND           Section/Token/Value not found.
    125 
    126 --*/
    127 
    128 EFI_STATUS
    129 FindTokenInstanceInSection (
    130   IN MEMORY_FILE    *InputFile,
    131   IN CHAR8          *Section,
    132   IN UINTN          Instance,
    133   OUT CHAR8         *Token,
    134   OUT CHAR8         *Value
    135   )
    136 ;
    137 /*++
    138 
    139 Routine Description:
    140 
    141   Finds the Instance-th token in a section.
    142 
    143 Arguments:
    144 
    145   InputFile Memory file image.
    146   Section   The section to search for, a string within [].
    147   Instance  Specify the Instance-th token to search for, starting from zero
    148   Token     The token name to return. Caller should allocate the buffer.
    149             Must be _MAX_PATH in size.
    150   Value     The token value to return. Caller should allocate the buffer.
    151             Must be _MAX_PATH in size.
    152 
    153 Returns:
    154 
    155   EFI_SUCCESS             Token and Value found.
    156   EFI_ABORTED             Format error detected in INF file.
    157   EFI_INVALID_PARAMETER   Input argument was null.
    158   EFI_LOAD_ERROR          Error reading from the file.
    159   EFI_NOT_FOUND           Section/Token/Value not found.
    160 
    161 --*/
    162 
    163 EFI_STATUS
    164 StringToGuid (
    165   IN CHAR8        *AsciiGuidBuffer,
    166   OUT EFI_GUID    *GuidBuffer
    167   );
    168 
    169 /*++
    170 
    171 Routine Description:
    172 
    173   Converts a string to an EFI_GUID.  The string must be in the
    174   xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx format.
    175 
    176 Arguments:
    177 
    178   GuidBuffer      - pointer to destination Guid
    179   AsciiGuidBuffer - pointer to ascii string
    180 
    181 Returns:
    182 
    183   EFI_ABORTED    Could not convert the string
    184   EFI_SUCCESS    The string was successfully converted
    185 
    186 --*/
    187 EFI_STATUS
    188 AsciiStringToUint64 (
    189   IN CONST CHAR8  *AsciiString,
    190   IN BOOLEAN      IsHex,
    191   OUT UINT64      *ReturnValue
    192   );
    193 
    194 /*++
    195 
    196 Routine Description:
    197 
    198   Converts a null terminated ascii string that represents a number into a
    199   UINT64 value.  A hex number may be preceeded by a 0x, but may not be
    200   succeeded by an h.  A number without 0x or 0X is considered to be base 10
    201   unless the IsHex input is true.
    202 
    203 Arguments:
    204 
    205   AsciiString   The string to convert.
    206   IsHex         Force the string to be treated as a hex number.
    207   ReturnValue   The return value.
    208 
    209 Returns:
    210 
    211   EFI_SUCCESS   Number successfully converted.
    212   EFI_ABORTED   Invalid character encountered.
    213 
    214 --*/
    215 CHAR8 *
    216 ReadLineInStream (
    217   IN FILE       *InputFile,
    218   IN OUT CHAR8  *InputBuffer
    219   );
    220 
    221 /*++
    222 
    223 Routine Description:
    224 
    225   This function reads a line, stripping any comments.
    226 
    227 Arguments:
    228 
    229   InputFile     Stream pointer.
    230   InputBuffer   Buffer to read into, must be _MAX_PATH size.
    231 
    232 Returns:
    233 
    234   NULL if error or EOF
    235   InputBuffer otherwise
    236 
    237 --*/
    238 BOOLEAN
    239 FindSectionInStream (
    240   IN FILE       *InputFile,
    241   IN CHAR8      *Section
    242   );
    243 
    244 /*++
    245 
    246 Routine Description:
    247 
    248   This function parses a stream file from the beginning to find a section.
    249   The section string may be anywhere within a line.
    250 
    251 Arguments:
    252 
    253   InputFile     Stream pointer.
    254   Section       Section to search for
    255 
    256 Returns:
    257 
    258   FALSE if error or EOF
    259   TRUE if section found
    260 
    261 --*/
    262 #endif
    263