ACPI_STATUS FlIsFileAsciiSource ( char *Filename, BOOLEAN DisplayErrors) { UINT8 Byte; ACPI_SIZE BadBytes = 0; BOOLEAN OpeningComment = FALSE; ASL_FILE_STATUS Status; FILE *Handle; /* Open file in text mode so file offset is always accurate */ Handle = fopen (Filename, "rb"); if (!Handle) { perror ("Could not open input file"); return (AE_ERROR); } Status.Line = 1; Status.Offset = 0; /* Read the entire file */ while (fread (&Byte, 1, 1, Handle) == 1) { /* Ignore comment fields (allow non-ascii within) */ if (OpeningComment) { /* Check for second comment open delimiter */ if (Byte == '*') { FlConsumeAnsiComment (Handle, &Status); } if (Byte == '/') { FlConsumeNewComment (Handle, &Status); } /* Reset */ OpeningComment = FALSE; } else if (Byte == '/') { OpeningComment = TRUE; } /* Check for an ASCII character */ if (!ACPI_IS_ASCII (Byte)) { if ((BadBytes < 10) && (DisplayErrors)) { AcpiOsPrintf ( "Found non-ASCII character in source text: " "0x%2.2X in line %u, file offset 0x%2.2X\n", Byte, Status.Line, Status.Offset); } BadBytes++; } /* Ensure character is either printable or a "space" char */ else if (!isprint (Byte) && !isspace (Byte)) { if ((BadBytes < 10) && (DisplayErrors)) { AcpiOsPrintf ( "Found invalid character in source text: " "0x%2.2X in line %u, file offset 0x%2.2X\n", Byte, Status.Line, Status.Offset); } BadBytes++; } /* Update line counter as necessary */ if (Byte == 0x0A) { Status.Line++; } Status.Offset++; } fclose (Handle); /* Were there any non-ASCII characters in the file? */ if (BadBytes) { if (DisplayErrors) { AcpiOsPrintf ( "Total %u invalid characters found in input source text, " "could be a binary file\n", BadBytes); AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, Filename); } return (AE_BAD_CHARACTER); } /* File is OK (100% ASCII) */ return (AE_OK); }
ACPI_STATUS FlCheckForAscii ( FILE *Handle, char *Filename, BOOLEAN DisplayErrors) { UINT8 Byte; ACPI_SIZE BadBytes = 0; BOOLEAN OpeningComment = FALSE; ASL_FILE_STATUS Status; Status.Line = 1; Status.Offset = 0; /* Read the entire file */ while (fread (&Byte, 1, 1, Handle) == 1) { /* Ignore comment fields (allow non-ascii within) */ if (OpeningComment) { /* Check for second comment open delimiter */ if (Byte == '*') { FlConsumeAnsiComment (Handle, &Status); } if (Byte == '/') { FlConsumeNewComment (Handle, &Status); } /* Reset */ OpeningComment = FALSE; } else if (Byte == '/') { OpeningComment = TRUE; } /* Check for an ASCII character */ if (!ACPI_IS_ASCII (Byte)) { if ((BadBytes < 10) && (DisplayErrors)) { AcpiOsPrintf ( "Non-ASCII character [0x%2.2X] found in line %u, file offset 0x%.2X\n", Byte, Status.Line, Status.Offset); } BadBytes++; } /* Update line counter */ else if (Byte == 0x0A) { Status.Line++; } Status.Offset++; } /* Seek back to the beginning of the source file */ fseek (Handle, 0, SEEK_SET); /* Were there any non-ASCII characters in the file? */ if (BadBytes) { if (DisplayErrors) { AcpiOsPrintf ( "%u non-ASCII characters found in input source text, could be a binary file\n", BadBytes); AslError (ASL_ERROR, ASL_MSG_NON_ASCII, NULL, Filename); } return (AE_BAD_CHARACTER); } /* File is OK (100% ASCII) */ return (AE_OK); }