Modified to strip leading white-space characters and ignore blank or comment only lines

git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@4080 6f19259b-4bc3-4df7-8a09-765794883524
This commit is contained in:
lhauch 2007-10-10 17:03:48 +00:00
parent a7593b363b
commit 2e7ddad2a0
1 changed files with 30 additions and 0 deletions

View File

@ -30,6 +30,8 @@ Abstract:
#define MAX_LINE_LEN 256 #define MAX_LINE_LEN 256
#define STATUS_IGNORE 0xA
// //
// Structure definition for a microcode header // Structure definition for a microcode header
// //
@ -120,6 +122,7 @@ Returns:
{ {
char Line[MAX_LINE_LEN]; char Line[MAX_LINE_LEN];
char *cptr; char *cptr;
unsigned int ctr;
Line[MAX_LINE_LEN - 1] = 0; Line[MAX_LINE_LEN - 1] = 0;
*Data = 0; *Data = 0;
@ -132,6 +135,17 @@ Returns:
if (Line[MAX_LINE_LEN - 1] != 0) { if (Line[MAX_LINE_LEN - 1] != 0) {
return STATUS_ERROR; return STATUS_ERROR;
} }
// Strip leading white-space characters (except carriage returns) from Line
//
if (isspace(Line[0]) && Line[0] != '\n') {
while (isspace(Line[0])) {
for (ctr = 0; ctr < strlen(Line); ctr++)
if (Line[ctr] != '\n')
Line[ctr] = Line[ctr + 1];
}
}
// //
// Look for // Look for
// dd 000000001h ; comment // dd 000000001h ; comment
@ -155,6 +169,12 @@ Returns:
} }
return STATUS_SUCCESS; return STATUS_SUCCESS;
} }
if (strlen(Line) == 1) {
return STATUS_IGNORE;
}
if (tolower(cptr[0]) == ';') {
return STATUS_IGNORE;
}
return STATUS_ERROR; return STATUS_ERROR;
} }
@ -188,6 +208,7 @@ Returns:
unsigned int Checksum; unsigned int Checksum;
char *Buffer; char *Buffer;
char *Ptr; char *Ptr;
char *OrigPtr;
unsigned int TotalSize; unsigned int TotalSize;
Status = STATUS_ERROR; Status = STATUS_ERROR;
@ -212,6 +233,9 @@ Returns:
if (Status == STATUS_SUCCESS) { if (Status == STATUS_SUCCESS) {
Size += sizeof (Data); Size += sizeof (Data);
} }
if (Status == STATUS_IGNORE) {
Status = STATUS_SUCCESS;
}
} while (Status == STATUS_SUCCESS); } while (Status == STATUS_SUCCESS);
// //
// Error if no data. // Error if no data.
@ -237,12 +261,18 @@ Returns:
// //
fseek (InFptr, 0, SEEK_SET); fseek (InFptr, 0, SEEK_SET);
Ptr = Buffer; Ptr = Buffer;
OrigPtr = Ptr;
do { do {
OrigPtr = Ptr;
Status = MicrocodeReadData (InFptr, &Data); Status = MicrocodeReadData (InFptr, &Data);
if (Status == STATUS_SUCCESS) { if (Status == STATUS_SUCCESS) {
*(unsigned int *) Ptr = Data; *(unsigned int *) Ptr = Data;
Ptr += sizeof (Data); Ptr += sizeof (Data);
} }
if (Status == STATUS_IGNORE) {
Ptr = OrigPtr;
Status = STATUS_SUCCESS;
}
} while (Status == STATUS_SUCCESS); } while (Status == STATUS_SUCCESS);
// //
// Can't do much checking on the header because, per the spec, the // Can't do much checking on the header because, per the spec, the