FreeBSD/sys/contrib/dev/acpica/compiler/aslerror.c
/*******************************************************************************
 *
 * FUNCTION:    AePrintException
 *
 * PARAMETERS:  FileId          - ID of output file
 *              Enode           - Error node to print
 *              Header          - Additional text before each message
 *
 * RETURN:      None
 *
 * DESCRIPTION: Print the contents of an error node.
 *
 * NOTE:        We don't use the FlxxxFile I/O functions here because on error
 *              they abort the compiler and call this function!  Since we
 *              are reporting errors here, we ignore most output errors and
 *              just try to get out as much as we can.
 *
 ******************************************************************************/
AePrintException
PARAMETERS:  FileId          - ID of output file
Enode           - Error node to print
Header          - Additional text before each message

None

Print the contents of an error node.

We don't use the FlxxxFile I/O functions here because on error
they abort the compiler and call this function.  Since we
are reporting errors here, we ignore most output errors and
just try to get out as much as we can.
AePrintException PARAMETERS : FileId - ID of output file Enode - Error node to print Header - Additional text before each message None Print the contents of an error node . We don ' t use the FlxxxFile I / O functions here because on error they abort the compiler and call this function . Since we are reporting errors here we ignore most output errors and just try to get out as much as we can .
void
AePrintException (
    UINT32                  FileId,
    ASL_ERROR_MSG           *Enode,
    char                    *Header)
{
    UINT8                   SourceByte;
    int                     Actual;
    size_t                  RActual;
    UINT32                  MsgLength;
    const char              *MainMessage;
    char                    *ExtraMessage;
    UINT32                  SourceColumn;
    UINT32                  ErrorColumn;
    FILE                    *OutputFile;
    FILE                    *SourceFile = NULL;
    long                    FileSize;
    BOOLEAN                 PrematureEOF = FALSE;
    UINT32                  Total = 0;
    if (Gbl_NoErrors)
    {
        return;
    }
    if (!Header)
    {
        switch (Enode->Level)
        {
        case ASL_WARNING:
        case ASL_WARNING2:
        case ASL_WARNING3:
            if (!Gbl_DisplayWarnings)
            {
                return;
            }
            break;
        case ASL_REMARK:
            if (!Gbl_DisplayRemarks)
            {
                return;
            }
            break;
        case ASL_OPTIMIZATION:
            if (!Gbl_DisplayOptimizations)
            {
                return;
            }
            break;
        default:
            break;
        }
    }
    OutputFile = Gbl_Files[FileId].Handle;
    if (!Enode->SourceLine)
    {
        SourceFile = Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Handle;
        if (!SourceFile)
        {
            SourceFile = Gbl_Files[ASL_FILE_INPUT].Handle;
        }
        if (SourceFile)
        {
            fseek (SourceFile, 0, SEEK_END);
            FileSize = ftell (SourceFile);
            if ((long) Enode->LogicalByteOffset >= FileSize)
            {
                PrematureEOF = TRUE;
            }
        }
    }
    if (Header)
    {
        fprintf (OutputFile, "%s", Header);
    }
    if (Enode->Filename)
    {
        if (Gbl_VerboseErrors)
        {
            fprintf (OutputFile, "%-8s", Enode->Filename);
            if (Enode->LineNumber)
            {
                if (Enode->SourceLine)
                {
                    fprintf (OutputFile, " %6u: %s",
                        Enode->LineNumber, Enode->SourceLine);
                }
                else
                {
                    fprintf (OutputFile, " %6u: ", Enode->LineNumber);
                    if (!PrematureEOF)
                    {
                        Actual = fseek (SourceFile,
                            (long) Enode->LogicalByteOffset, (int) SEEK_SET);
                        if (Actual)
                        {
                            fprintf (OutputFile,
                                "[*** iASL: Seek error on source code temp file %s ***]",
                                Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
                        }
                        else
                        {
                            RActual = fread (&SourceByte, 1, 1, SourceFile);
                            if (RActual != 1)
                            {
                                fprintf (OutputFile,
                                    "[*** iASL: Read error on source code temp file %s ***]",
                                    Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
                            }
                            else
                            {
                                while (RActual && SourceByte && (SourceByte != '\n'))
                                {
                                    if (Total < 256)
                                    {
                                        if (fwrite (&SourceByte, 1, 1, OutputFile) != 1)
                                        {
                                            printf ("[*** iASL: Write error on output file ***]\n");
                                            return;
                                        }
                                    }
                                    else if (Total == 256)
                                    {
                                        fprintf (OutputFile,
                                            "\n[*** iASL: Very long input line, message below refers to column %u ***]",
                                            Enode->Column);
                                    }
                                    RActual = fread (&SourceByte, 1, 1, SourceFile);
                                    if (RActual != 1)
                                    {
                                        fprintf (OutputFile,
                                            "[*** iASL: Read error on source code temp file %s ***]",
                                            Gbl_Files[ASL_FILE_SOURCE_OUTPUT].Filename);
                                        return;
                                    }
                                    Total++;
                                }
                            }
                        }
                    }
                    fprintf (OutputFile, "\n");
                }
            }
        }
        else
        {
            fprintf (OutputFile, "%s", Enode->Filename);
            if (Enode->LineNumber)
            {
                fprintf (OutputFile, "(%u) : ",
                    Enode->LineNumber);
            }
        }
    }
    if (Enode->MessageId == 0)
    {
        fprintf (OutputFile, "%s\n", Enode->Message);
        return;
    }
    fprintf (OutputFile, "%s %4.4d -",
        AeDecodeExceptionLevel (Enode->Level),
        AeBuildFullExceptionCode (Enode->Level, Enode->MessageId));
    MainMessage = AeDecodeMessageId (Enode->MessageId);
    ExtraMessage = Enode->Message;
    if (!Enode->LineNumber)
    {
        fprintf (OutputFile, " %s %s\n\n", MainMessage, ExtraMessage);
        return;
    }
    MsgLength = strlen (MainMessage);
    if (MsgLength == 0)
    {
        MainMessage = Enode->Message;
        if (!MainMessage)
        {
            MainMessage = "";
        }
        MsgLength = strlen (MainMessage);
        ExtraMessage = NULL;
    }
    if (Gbl_VerboseErrors && !PrematureEOF)
    {
        if (Total >= 256)
        {
            fprintf (OutputFile, "    %s",
                MainMessage);
        }
        else
        {
            SourceColumn = Enode->Column + Enode->FilenameLength + 6 + 2;
            ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1;
            if ((MsgLength + ErrorColumn) < (SourceColumn - 1))
            {
                fprintf (OutputFile, "%*s%s",
                    (int) ((SourceColumn - 1) - ErrorColumn),
                    MainMessage, " ^ ");
            }
            else
            {
                fprintf (OutputFile, "%*s %s",
                    (int) ((SourceColumn - ErrorColumn) + 1), "^",
                    MainMessage);
            }
        }
    }
    else
    {
        fprintf (OutputFile, " %s", MainMessage);
    }
    if (ExtraMessage)
    {
        fprintf (OutputFile, " (%s)", ExtraMessage);
    }
    if (PrematureEOF)
    {
        fprintf (OutputFile, " and premature End-Of-File");
    }
    fprintf (OutputFile, "\n");
    if (Gbl_VerboseErrors)
    {
        fprintf (OutputFile, "\n");
    }
}
void AePrintException ( UINT32 FileId , ASL_ERROR_MSG * Enode , char * Header ) { UINT8 SourceByte ; int Actual ; size_t RActual ; UINT32 MsgLength ; const char * MainMessage ; char * ExtraMessage ; UINT32 SourceColumn ; UINT32 ErrorColumn ; FILE * OutputFile ; FILE * SourceFile = NULL ; long FileSize ; BOOLEAN PrematureEOF = FALSE ; UINT32 Total = 0 ; if ( Gbl_NoErrors ) { return ; } if ( ! Header ) { switch ( Enode -> Level ) { case ASL_WARNING : case ASL_WARNING2 : case ASL_WARNING3 : if ( ! Gbl_DisplayWarnings ) { return ; } break ; case ASL_REMARK : if ( ! Gbl_DisplayRemarks ) { return ; } break ; case ASL_OPTIMIZATION : if ( ! Gbl_DisplayOptimizations ) { return ; } break ; default : break ; } } OutputFile = Gbl_Files [ FileId ] . Handle ; if ( ! Enode -> SourceLine ) { SourceFile = Gbl_Files [ ASL_FILE_SOURCE_OUTPUT ] . Handle ; if ( ! SourceFile ) { SourceFile = Gbl_Files [ ASL_FILE_INPUT ] . Handle ; } if ( SourceFile ) { fseek ( SourceFile , 0 , SEEK_END ) ; FileSize = ftell ( SourceFile ) ; if ( ( long ) Enode -> LogicalByteOffset >= FileSize ) { PrematureEOF = TRUE ; } } } if ( Header ) { fprintf ( OutputFile , " " , Header ) ; } if ( Enode -> Filename ) { if ( Gbl_VerboseErrors ) { fprintf ( OutputFile , " " , Enode -> Filename ) ; if ( Enode -> LineNumber ) { if ( Enode -> SourceLine ) { fprintf ( OutputFile , " " , Enode -> LineNumber , Enode -> SourceLine ) ; } else { fprintf ( OutputFile , " " , Enode -> LineNumber ) ; if ( ! PrematureEOF ) { Actual = fseek ( SourceFile , ( long ) Enode -> LogicalByteOffset , ( int ) SEEK_SET ) ; if ( Actual ) { fprintf ( OutputFile , " " , Gbl_Files [ ASL_FILE_SOURCE_OUTPUT ] . Filename ) ; } else { RActual = fread ( & SourceByte , 1 , 1 , SourceFile ) ; if ( RActual != 1 ) { fprintf ( OutputFile , " " , Gbl_Files [ ASL_FILE_SOURCE_OUTPUT ] . Filename ) ; } else { while ( RActual && SourceByte && ( SourceByte != ' \n ' ) ) { if ( Total < 256 ) { if ( fwrite ( & SourceByte , 1 , 1 , OutputFile ) != 1 ) { printf ( " \n " ) ; return ; } } else if ( Total == 256 ) { fprintf ( OutputFile , " \n " , Enode -> Column ) ; } RActual = fread ( & SourceByte , 1 , 1 , SourceFile ) ; if ( RActual != 1 ) { fprintf ( OutputFile , " " , Gbl_Files [ ASL_FILE_SOURCE_OUTPUT ] . Filename ) ; return ; } Total ++ ; } } } } fprintf ( OutputFile , " \n " ) ; } } } else { fprintf ( OutputFile , " " , Enode -> Filename ) ; if ( Enode -> LineNumber ) { fprintf ( OutputFile , " " , Enode -> LineNumber ) ; } } } if ( Enode -> MessageId == 0 ) { fprintf ( OutputFile , " \n " , Enode -> Message ) ; return ; } fprintf ( OutputFile , " " , AeDecodeExceptionLevel ( Enode -> Level ) , AeBuildFullExceptionCode ( Enode -> Level , Enode -> MessageId ) ) ; MainMessage = AeDecodeMessageId ( Enode -> MessageId ) ; ExtraMessage = Enode -> Message ; if ( ! Enode -> LineNumber ) { fprintf ( OutputFile , " \n \n " , MainMessage , ExtraMessage ) ; return ; } MsgLength = strlen ( MainMessage ) ; if ( MsgLength == 0 ) { MainMessage = Enode -> Message ; if ( ! MainMessage ) { MainMessage = " " ; } MsgLength = strlen ( MainMessage ) ; ExtraMessage = NULL ; } if ( Gbl_VerboseErrors && ! PrematureEOF ) { if ( Total >= 256 ) { fprintf ( OutputFile , " " , MainMessage ) ; } else { SourceColumn = Enode -> Column + Enode -> FilenameLength + 6 + 2 ; ErrorColumn = ASL_ERROR_LEVEL_LENGTH + 5 + 2 + 1 ; if ( ( MsgLength + ErrorColumn ) < ( SourceColumn - 1 ) ) { fprintf ( OutputFile , " " , ( int ) ( ( SourceColumn - 1 ) - ErrorColumn ) , MainMessage , " " ) ; } else { fprintf ( OutputFile , " " , ( int ) ( ( SourceColumn - ErrorColumn ) + 1 ) , " " , MainMessage ) ; } } } else { fprintf ( OutputFile , " " , MainMessage ) ; } if ( ExtraMessage ) { fprintf ( OutputFile , " " , ExtraMessage ) ; } if ( PrematureEOF ) { fprintf ( OutputFile , " " ) ; } fprintf ( OutputFile , " \n " ) ; if ( Gbl_VerboseErrors ) { fprintf ( OutputFile , " \n " ) ; } }
FUNCTION:    AePrintException
 PARAMETERS:  FileId          - ID of output file
              Enode           - Error node to print
              Header          - Additional text before each message
FUNCTION : AePrintException PARAMETERS : FileId - ID of output file Enode - Error node to print Header - Additional text before each message
/*
     * Only listing files have a header, and remarks/optimizations
     * are always output
     */ /* Ignore remarks if requested */ /* Get the various required file handles */ /*
         * Use the merged header/source file if present, otherwise
         * use input file
         */ /* Determine if the error occurred at source file EOF */ /* Print filename and line number if present and valid */ /*
                     * If not at EOF, get the corresponding source code line
                     * and display it. Don't attempt this if we have a
                     * premature EOF condition.
                     */ /*
                         * Seek to the offset in the combined source file,
                         * read the source line, and write it to the output.
                         */ /* Read/write the source line, up to the maximum line length */ /* After the max line length, we will just read the line, no write */ /*
             * Less verbose version of the error message, enabled via the
             * -vi switch. The format is compatible with MS Visual Studio.
             */ /* If a NULL message ID, just print the raw message */ /* Decode the message ID */ /* If a NULL line number, just print the decoded message */ /* Use the secondary/extra message as main message */ /* Print the extra info message if present */