efiutilitymsgs.c

来自「EFI BIOS是Intel提出的下一代的BIOS标准。这里上传的Edk源代码是」· C语言 代码 · 共 757 行 · 第 1/2 页

C
757
字号
/*++

Copyright (c) 2004, Intel Corporation                                                         
All rights reserved. This program and the accompanying materials                          
are licensed and made available under the terms and conditions of the BSD License         
which accompanies this distribution.  The full text of the license may be found at        
http://opensource.org/licenses/bsd-license.php                                            
                                                                                          
THE PROGRAM IS DISTRIBUTED UNDER THE BSD LICENSE ON AN "AS IS" BASIS,                     
WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED.             

Module Name:  

  EfiUtilityMsgs.c
  
Abstract:

  EFI tools utility functions to display warning, error, and informational
  messages.
  
--*/

#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdarg.h>

#include "Tiano.h"
#include "EfiUtilityMsgs.h"

#define MAX_LINE_LEN  200

//
// Declare module globals for keeping track of the the utility's
// name and other settings.
//
static STATUS mStatus                 = STATUS_SUCCESS;
static INT8   mUtilityName[50]        = { 0 };
static UINT32 mDebugMsgMask           = 0;
static INT8   *mSourceFileName        = NULL;
static UINT32 mSourceFileLineNum      = 0;
static UINT32 mErrorCount             = 0;
static UINT32 mWarningCount           = 0;
static UINT32 mMaxErrors              = 0;
static UINT32 mMaxWarnings            = 0;
static UINT32 mMaxWarningsPlusErrors  = 0;
static INT8   mPrintLimitsSet         = 0;

static
void
PrintMessage (
  INT8    *Type,
  INT8    *FileName,
  UINT32  LineNumber,
  UINT32  MessageCode,
  INT8    *Text,
  INT8    *MsgFmt,
  va_list List
  );

static
void
PrintLimitExceeded (
  VOID
  );

void
Error (
  INT8    *FileName,
  UINT32  LineNumber,
  UINT32  MessageCode,
  INT8    *Text,
  INT8    *MsgFmt,
  ...
  )
/*++

Routine Description:
  Prints an error message.
  
Arguments:
  All arguments are optional, though the printed message may be useless if
  at least something valid is not specified.
  
  FileName - name of the file or application. If not specified, then the
             utilty name (as set by the utility calling SetUtilityName()
             earlier) is used. Otherwise "Unknown utility" is used.
  
  LineNumber - the line number of error, typically used by parsers. If the
               utility is not a parser, then 0 should be specified. Otherwise
               the FileName and LineNumber info can be used to cause
               MS Visual Studio to jump to the error.
               
  MessageCode - an application-specific error code that can be referenced in
              other documentation. 

  Text        - the text in question, typically used by parsers.
  
  MsgFmt - the format string for the error message. Can contain formatting
           controls for use with the varargs.
           
Returns:
  None.
  
Notes:
  We print the following (similar to the Warn() and Debug() 
  W
  Typical error/warning message format:

  bin\VfrCompile.cpp(330) : error C2660: 'AddVfrDataStructField' : function does not take 2 parameters

  BUGBUG -- these three utility functions are almost identical, and
  should be modified to share code.

  Visual Studio does not find error messages with:
  
     " error :"
     " error 1:"
     " error c1:"
     " error 1000:"
     " error c100:"

  It does find:
     " error c1000:"     
--*/
{
  va_list List;
  //
  // If limits have been set, then check that we have not exceeded them
  //
  if (mPrintLimitsSet) {
    //
    // See if we've exceeded our total count
    //
    if (mMaxWarningsPlusErrors != 0) {
      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
        PrintLimitExceeded ();
        return ;
      }
    }
    //
    // See if we've exceeded our error count
    //
    if (mMaxErrors != 0) {
      if (mErrorCount > mMaxErrors) {
        PrintLimitExceeded ();
        return ;
      }
    }
  }

  mErrorCount++;
  va_start (List, MsgFmt);
  PrintMessage ("error", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
  va_end (List);
  //
  // Set status accordingly
  //
  if (mStatus < STATUS_ERROR) {
    mStatus = STATUS_ERROR;
  }
}

void
ParserError (
  UINT32  MessageCode,
  INT8    *Text,
  INT8    *MsgFmt,
  ...
  )
/*++

Routine Description:
  Print a parser error, using the source file name and line number
  set by a previous call to SetParserPosition().

Arguments:
  MessageCode   - application-specific error code
  Text          - text to print in the error message
  MsgFmt        - format string to print at the end of the error message

Returns:
  NA

--*/
{
  va_list List;
  //
  // If limits have been set, then check them
  //
  if (mPrintLimitsSet) {
    //
    // See if we've exceeded our total count
    //
    if (mMaxWarningsPlusErrors != 0) {
      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
        PrintLimitExceeded ();
        return ;
      }
    }
    //
    // See if we've exceeded our error count
    //
    if (mMaxErrors != 0) {
      if (mErrorCount > mMaxErrors) {
        PrintLimitExceeded ();
        return ;
      }
    }
  }

  mErrorCount++;
  va_start (List, MsgFmt);
  PrintMessage ("error", mSourceFileName, mSourceFileLineNum, MessageCode, Text, MsgFmt, List);
  va_end (List);
  //
  // Set status accordingly
  //
  if (mStatus < STATUS_ERROR) {
    mStatus = STATUS_ERROR;
  }
}

void
ParserWarning (
  UINT32  ErrorCode,
  INT8    *OffendingText,
  INT8    *MsgFmt,
  ...
  )
/*++

Routine Description:
  Print a parser warning, using the source file name and line number
  set by a previous call to SetParserPosition().

Arguments:
  ErrorCode     - application-specific error code
  OffendingText - text to print in the warning message
  MsgFmt        - format string to print at the end of the warning message

Returns:
  NA

--*/
{
  va_list List;
  //
  // If limits have been set, then check them
  //
  if (mPrintLimitsSet) {
    //
    // See if we've exceeded our total count
    //
    if (mMaxWarningsPlusErrors != 0) {
      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
        PrintLimitExceeded ();
        return ;
      }
    }
    //
    // See if we've exceeded our warning count
    //
    if (mMaxWarnings != 0) {
      if (mWarningCount > mMaxWarnings) {
        PrintLimitExceeded ();
        return ;
      }
    }
  }

  mWarningCount++;
  va_start (List, MsgFmt);
  PrintMessage ("warning", mSourceFileName, mSourceFileLineNum, ErrorCode, OffendingText, MsgFmt, List);
  va_end (List);
  //
  // Set status accordingly
  //
  if (mStatus < STATUS_WARNING) {
    mStatus = STATUS_WARNING;
  }
}

void
Warning (
  INT8    *FileName,
  UINT32  LineNumber,
  UINT32  MessageCode,
  INT8    *Text,
  INT8    *MsgFmt,
  ...
  )
/*++

Routine Description:
  Print a warning message.

Arguments:
  FileName    - name of the file where the warning was detected, or the name
                of the application that detected the warning
  
  LineNumber  - the line number where the warning was detected (parsers).
                0 should be specified if the utility is not a parser.
               
  MessageCode - an application-specific warning code that can be referenced in
                other documentation. 

  Text        - the text in question (parsers)
  
  MsgFmt      - the format string for the warning message. Can contain formatting
                controls for use with varargs.
           
Returns:
  None.

--*/
{
  va_list List;
  //
  // If limits have been set, then check them
  //
  if (mPrintLimitsSet) {
    //
    // See if we've exceeded our total count
    //
    if (mMaxWarningsPlusErrors != 0) {
      if (mErrorCount + mWarningCount > mMaxWarningsPlusErrors) {
        PrintLimitExceeded ();
        return ;
      }
    }
    //
    // See if we've exceeded our warning count
    //
    if (mMaxWarnings != 0) {
      if (mWarningCount > mMaxWarnings) {
        PrintLimitExceeded ();
        return ;
      }
    }
  }

  mWarningCount++;
  va_start (List, MsgFmt);
  PrintMessage ("warning", FileName, LineNumber, MessageCode, Text, MsgFmt, List);
  va_end (List);
  //
  // Set status accordingly
  //
  if (mStatus < STATUS_WARNING) {
    mStatus = STATUS_WARNING;
  }
}

void
DebugMsg (
  INT8    *FileName,
  UINT32  LineNumber,
  UINT32  MsgMask,
  INT8    *Text,
  INT8    *MsgFmt,
  ...
  )
/*++

Routine Description:
  Print a warning message.

Arguments:
  FileName    - typically the name of the utility printing the debug message, but
                can be the name of a file being parsed.
  
  LineNumber  - the line number in FileName (parsers) 
               
  MsgMask     - an application-specific bitmask that, in combination with mDebugMsgMask,
                determines if the debug message gets printed.

  Text        - the text in question (parsers)
  

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?