From: bbahnsen Date: Wed, 31 May 2006 21:02:55 +0000 (+0000) Subject: Add Mde String and PrintLibs. Port StrGather to the Mde Unicode implementation. Compi... X-Git-Tag: edk2-stable201903~25372 X-Git-Url: https://git.proxmox.com/?p=mirror_edk2.git;a=commitdiff_plain;h=d2ec0d9ef6af0b8d3dc7113fa8d631709c814a06 Add Mde String and PrintLibs. Port StrGather to the Mde Unicode implementation. Compile with 2 byte wchars. Now StrGather works with gcc. git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@358 6f19259b-4bc3-4df7-8a09-765794883524 --- diff --git a/Tools/Source/TianoTools/Common/CommonLib.h b/Tools/Source/TianoTools/Common/CommonLib.h index 63f77e4557..80cd883024 100644 --- a/Tools/Source/TianoTools/Common/CommonLib.h +++ b/Tools/Source/TianoTools/Common/CommonLib.h @@ -127,6 +127,8 @@ PrintGuidToBuffer ( ) ; +#define ASSERT(x) assert(x) + #ifdef __GNUC__ #define stricmp strcasecmp #define strnicmp strncasecmp diff --git a/Tools/Source/TianoTools/StrGather/StrGather.c b/Tools/Source/TianoTools/StrGather/StrGather.c index 3ad77247ae..1fc204d147 100644 --- a/Tools/Source/TianoTools/StrGather/StrGather.c +++ b/Tools/Source/TianoTools/StrGather/StrGather.c @@ -1248,21 +1248,21 @@ ProcessTokenLanguage ( // quoted strings, and concatenate them until we get a failure // back from the string parser. // - Len = wcslen (String) + 1; + Len = StrLen (String) + 1; ParserSetPosition (SourceFile->FileName, SourceFile->LineNum); do { SkipWhiteSpace (SourceFile); SecondString = GetQuotedString (SourceFile, TRUE); if (SecondString != NULL) { - Len += wcslen (SecondString); + Len += StrLen (SecondString); TempString = (WCHAR *) malloc (Len * sizeof (WCHAR)); if (TempString == NULL) { Error (NULL, 0, 0, "application error", "failed to allocate memory"); return ; } - wcscpy (TempString, String); - wcscat (TempString, SecondString); + StrCpy (TempString, String); + StrCat (TempString, SecondString); free (String); free (SecondString); String = TempString; @@ -1973,14 +1973,14 @@ AddCommandLineLanguage ( // long. If we find a comma, then we're done with this group, so // break out. // - swprintf (WNewList->Str, L"%S", Language); + UnicodeSPrint (WNewList->Str, (strlen (Language) + 1) * sizeof (WCHAR), L"%a", Language); From = To = WNewList->Str; while (*From) { if (*From == L',') { break; } - if ((wcslen (From) < LANGUAGE_IDENTIFIER_NAME_LEN) || + if ((StrLen (From) < LANGUAGE_IDENTIFIER_NAME_LEN) || ( (From[LANGUAGE_IDENTIFIER_NAME_LEN] != 0) && (From[LANGUAGE_IDENTIFIER_NAME_LEN] != UNICODE_PLUS_SIGN) && @@ -1993,7 +1993,7 @@ AddCommandLineLanguage ( return STATUS_ERROR; } - wcsncpy (To, From, LANGUAGE_IDENTIFIER_NAME_LEN); + StrnCpy (To, From, LANGUAGE_IDENTIFIER_NAME_LEN); To += LANGUAGE_IDENTIFIER_NAME_LEN; From += LANGUAGE_IDENTIFIER_NAME_LEN; if (*From == L'+') { @@ -2114,8 +2114,8 @@ ParseIndirectionFiles ( goto Done; } - swprintf (NewList->Str1, L"%S", StringName); - swprintf (NewList->Str2, L"%S", ScopeName); + UnicodeSPrint (NewList->Str1, strlen (StringName) + 1, L"%a", StringName); + UnicodeSPrint (NewList->Str2, strlen (ScopeName) + 1, L"%a", ScopeName); if (mGlobals.IndirectionList == NULL) { mGlobals.IndirectionList = NewList; } else { diff --git a/Tools/Source/TianoTools/StrGather/StringDB.c b/Tools/Source/TianoTools/StrGather/StringDB.c index f452bbc86b..353fabb682 100644 --- a/Tools/Source/TianoTools/StrGather/StringDB.c +++ b/Tools/Source/TianoTools/StrGather/StringDB.c @@ -26,6 +26,7 @@ Abstract: #include #include #include +#include #include "EfiUtilityMsgs.h" #include "StrGather.h" #include "StringDB.h" @@ -399,6 +400,7 @@ StringDBDumpCStrings ( WCHAR *TempStringPtr; WCHAR *LangName; STRING_IDENTIFIER *StringIdentifier; + WCHAR Line[200]; if ((Fptr = fopen (FileName, "w")) == NULL) { Error (NULL, 0, 0, FileName, "failed to open output C string file"); @@ -434,7 +436,7 @@ StringDBDumpCStrings ( if (LanguagesOfInterest != NULL) { LanguageOk = FALSE; for (LOIPtr = LanguagesOfInterest; LOIPtr != NULL; LOIPtr = LOIPtr->Next) { - if (wcsncmp (LOIPtr->Str, Lang->LanguageName, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) { + if (StrnCmp (LOIPtr->Str, Lang->LanguageName, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) { LangName = LOIPtr->Str; LanguageOk = TRUE; break; @@ -460,13 +462,13 @@ StringDBDumpCStrings ( // Offset[] -- an array of offsets to strings, of type RELOFST each // String[] -- the actual strings themselves // - fprintf ( - Fptr, + AsciiSPrint ( Line, sizeof(Line), "\n//******************************************************************************" - "\n// Start of string definitions for %S/%S", + "\n// Start of string definitions for %s/%s", Lang->LanguageName, Lang->PrintableLanguageName ); + fprintf (Fptr, "%s", Line); memset ((char *) &StringPack, 0, sizeof (EFI_HII_STRING_PACK)); StringPack.Header.Type = EFI_HII_STRING; StringPack.NumStringPointers = (UINT16) mDBData.NumStringIdentifiersReferenced; @@ -479,7 +481,7 @@ StringDBDumpCStrings ( // entry for the printable language name as well. // StringPack.LanguageNameString = (STRING_OFFSET) (sizeof (EFI_HII_STRING_PACK) + (mDBData.NumStringIdentifiersReferenced * sizeof (STRING_OFFSET))); - StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (wcslen (LangName) + 1) * sizeof (WCHAR)); + StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (StrLen (LangName) + 1) * sizeof (WCHAR)); // // Add up the size of all strings so we can fill in our header. // @@ -490,7 +492,7 @@ StringDBDumpCStrings ( // requested it. We set LangName to point to the proper language name string above. // if (StringIndex == STRING_ID_LANGUAGE_NAME) { - Len += (wcslen (LangName) + 1) * sizeof (WCHAR); + Len += (StrLen (LangName) + 1) * sizeof (WCHAR); } else { // // Find a string with this language.stringname @@ -578,13 +580,14 @@ StringDBDumpCStrings ( return STATUS_ERROR; } - fprintf (Fptr, " // offset to string %S (0x%04X)", StringIdentifier->StringName, StringIndex); + AsciiSPrint (Line, sizeof(Line) , " // offset to string %s (0x%04X)", StringIdentifier->StringName, StringIndex); + fprintf (Fptr, "%s", Line); // // For the first string (language name), we print out the "spacat" if they // requested it. We set LangName to point to the proper language name string above. // if (StringIndex == STRING_ID_LANGUAGE_NAME) { - Offset += (wcslen (LangName) + 1) * sizeof (WCHAR); + Offset += (StrLen (LangName) + 1) * sizeof (WCHAR); CurrString = StringDBFindString ( Lang->LanguageName, StringIdentifier->StringName, @@ -634,12 +637,13 @@ StringDBDumpCStrings ( if (CurrString->Flags & STRING_FLAGS_UNDEFINED) { fprintf (Fptr, " - not defined for this language"); - } else if (wcscmp (CurrString->LanguageName, Lang->LanguageName) != 0) { - fprintf ( - Fptr, - " - not defined for this language -- using secondary language %S definition", + } else if (StrCmp (CurrString->LanguageName, Lang->LanguageName) != 0) { + AsciiSPrint ( + Line, sizeof(Line), + " - not defined for this language -- using secondary language %s definition", CurrString->LanguageName ); + fprintf ( Fptr, "%s", Line); } fprintf (Fptr, "\n"); @@ -650,7 +654,8 @@ StringDBDumpCStrings ( while (StringIndex < mDBData.NumStringIdentifiers) { StringIdentifier = StringDBFindStringIdentifierByIndex (StringIndex); if (StringIdentifier != NULL) { - fprintf (Fptr, " // %S not referenced\n", StringIdentifier->StringName); + AsciiSPrint (Line, sizeof(Line), " // %s not referenced\n", StringIdentifier->StringName); + fprintf (Fptr, "%s", Line); } StringIndex++; @@ -669,7 +674,8 @@ StringDBDumpCStrings ( return STATUS_ERROR; } - fprintf (Fptr, " // string %S offset 0x%08X\n ", StringIdentifier->StringName, Offset); + AsciiSPrint (Line, sizeof(Line), " // string %s offset 0x%08X\n ", StringIdentifier->StringName, Offset); + fprintf (Fptr, "%s", Line); // // For the first string (language name), we print out the "spacat" if they // requested it. We set LangName to point to the proper language name string above. @@ -795,6 +801,7 @@ StringDBDumpStringDefines ( FILE *Fptr; STRING_IDENTIFIER *Identifier; INT8 CopyBaseName[100]; + WCHAR Line[200]; UINT32 Index; const INT8 *StrDefHeader[] = { "#ifndef _%s_STRINGS_DEFINE_H_\n", @@ -844,9 +851,11 @@ StringDBDumpStringDefines ( } if (Identifier->Flags & STRING_FLAGS_REFERENCED) { - fprintf (Fptr, "#define %-40S 0x%04X\n", Identifier->StringName, Identifier->Index); + AsciiSPrint (Line, sizeof(Line), "#define %-40s 0x%04X\n", Identifier->StringName, Identifier->Index); + fprintf (Fptr, "%s", Line); } else { - fprintf (Fptr, "//#define %-40S 0x%04X // not referenced\n", Identifier->StringName, Identifier->Index); + AsciiSPrint (Line, sizeof(Line), "//#define %-40s 0x%04X // not referenced\n", Identifier->StringName, Identifier->Index); + fprintf (Fptr, "%s", Line); } Identifier = Identifier->Next; @@ -909,13 +918,13 @@ StringDBAddStringIdentifier ( } memset ((char *) StringIdentifier, 0, sizeof (STRING_IDENTIFIER)); - StringIdentifier->StringName = (WCHAR *) malloc ((wcslen (StringName) + 1) * sizeof (WCHAR)); + StringIdentifier->StringName = (WCHAR *) malloc ((StrLen (StringName) + 1) * sizeof (WCHAR)); if (StringIdentifier->StringName == NULL) { Error (NULL, 0, 0, NULL, "memory allocation error"); return STATUS_ERROR; } - wcscpy (StringIdentifier->StringName, StringName); + StrCpy (StringIdentifier->StringName, StringName); if (*NewId != STRING_ID_INVALID) { StringIdentifier->Index = *NewId; StringIdentifier->Flags |= STRING_FLAGS_INDEX_ASSIGNED; @@ -991,7 +1000,7 @@ StringDBAddString ( // Truncate at 3 if it's longer, or make it 3 if it's shorter. // if (LanguageName != NULL) { - Size = wcslen (LanguageName); + Size = StrLen (LanguageName); if (Size != 3) { ParserError (0, "invalid length for language name", "%S", LanguageName); if (Size > 3) { @@ -1002,7 +1011,7 @@ StringDBAddString ( // 3 characters since we make assumptions elsewhere in this program // on the length. // - wcscpy (TempLangName, LanguageName); + StrCpy (TempLangName, LanguageName); for (; Size < 3; Size++) { TempLangName[Size] = L'?'; } @@ -1061,8 +1070,8 @@ StringDBAddString ( // user does not specifically define them. // if (StringDBFindString (Lang->LanguageName, StringName, Scope, NULL, NULL) != NULL) { - if ((wcscmp (StringName, LANGUAGE_NAME_STRING_NAME) == 0) && - (wcscmp (StringName, PRINTABLE_LANGUAGE_NAME_STRING_NAME) == 0) + if ((StrCmp (StringName, LANGUAGE_NAME_STRING_NAME) == 0) && + (StrCmp (StringName, PRINTABLE_LANGUAGE_NAME_STRING_NAME) == 0) ) { ParserError ( 0, @@ -1092,7 +1101,7 @@ StringDBAddString ( } memset ((char *) Str, 0, sizeof (STRING_LIST)); - Size = (wcslen (String) + 1) * sizeof (WCHAR); + Size = (StrLen (String) + 1) * sizeof (WCHAR); Str->Flags = Flags; Str->Scope = Scope; Str->StringName = StringIdentifier->StringName; @@ -1105,7 +1114,7 @@ StringDBAddString ( // // If not formatting, just copy the string. // - wcscpy (Str->Str, String); + StrCpy (Str->Str, String); if (Format) { StringDBFormatString (Str->Str); } @@ -1114,7 +1123,7 @@ StringDBAddString ( // the actual size of the string, including the null for // easier processing later. // - Str->Size = (wcslen (Str->Str) + 1) * sizeof (WCHAR); + Str->Size = (StrLen (Str->Str) + 1) * sizeof (WCHAR); if (Lang->String == NULL) { Lang->String = Str; } else { @@ -1152,7 +1161,7 @@ StringDBFindLanguageList ( Lang = mDBData.LanguageList; while (Lang != NULL) { - if (wcscmp (LanguageName, Lang->LanguageName) == 0) { + if (StrCmp (LanguageName, Lang->LanguageName) == 0) { break; } @@ -1196,7 +1205,7 @@ StringDBAddLanguage ( // // Better be the same printable name // - if (wcscmp (PrintableLanguageName, Lang->PrintableLanguageName) != 0) { + if (StrCmp (PrintableLanguageName, Lang->PrintableLanguageName) != 0) { ParserError ( 0, "language redefinition", @@ -1228,14 +1237,14 @@ StringDBAddLanguage ( // Save the language name, then allocate memory to save the // printable language name // - wcscpy (Lang->LanguageName, LanguageName); - Lang->PrintableLanguageName = (WCHAR *) malloc ((wcslen (PrintableLanguageName) + 1) * sizeof (WCHAR)); + StrCpy (Lang->LanguageName, LanguageName); + Lang->PrintableLanguageName = (WCHAR *) malloc ((StrLen (PrintableLanguageName) + 1) * sizeof (WCHAR)); if (Lang->PrintableLanguageName == NULL) { Error (NULL, 0, 0, NULL, "memory allocation error"); return STATUS_ERROR; } - wcscpy (Lang->PrintableLanguageName, PrintableLanguageName); + StrCpy (Lang->PrintableLanguageName, PrintableLanguageName); if (mDBData.LanguageList == NULL) { mDBData.LanguageList = Lang; @@ -1284,7 +1293,7 @@ StringDBFindStringIdentifierByName ( Identifier = mDBData.StringIdentifier; while (Identifier != NULL) { - if (wcscmp (StringName, Identifier->StringName) == 0) { + if (StrCmp (StringName, Identifier->StringName) == 0) { return Identifier; } @@ -1366,22 +1375,22 @@ StringDBFormatString ( // when you have "define STR L"ABC"", then sizeof(ABC) is 8 because the null char is // counted. Make adjustments for this. We advance From below, so subtract 2 each time. // - if (wcsncmp (From, UNICODE_WIDE_STRING, sizeof (UNICODE_WIDE_STRING) / sizeof (WCHAR) - 1) == 0) { + if (StrnCmp (From, UNICODE_WIDE_STRING, sizeof (UNICODE_WIDE_STRING) / sizeof (WCHAR) - 1) == 0) { *To = WIDE_CHAR; From += sizeof (UNICODE_WIDE_STRING) / sizeof (WCHAR) - 2; - } else if (wcsncmp (From, UNICODE_NARROW_STRING, sizeof (UNICODE_NARROW_STRING) / sizeof (WCHAR) - 1) == 0) { + } else if (StrnCmp (From, UNICODE_NARROW_STRING, sizeof (UNICODE_NARROW_STRING) / sizeof (WCHAR) - 1) == 0) { // // Found: \narrow // *To = NARROW_CHAR; From += sizeof (UNICODE_NARROW_STRING) / sizeof (WCHAR) - 2; - } else if (wcsncmp (From, UNICODE_NBR_STRING, sizeof (UNICODE_NBR_STRING) / sizeof (WCHAR) - 1) == 0) { + } else if (StrnCmp (From, UNICODE_NBR_STRING, sizeof (UNICODE_NBR_STRING) / sizeof (WCHAR) - 1) == 0) { // // Found: \nbr // *To = NON_BREAKING_CHAR; From += sizeof (UNICODE_NBR_STRING) / sizeof (WCHAR) - 2; - } else if (wcsncmp (From, UNICODE_BR_STRING, sizeof (UNICODE_BR_STRING) / sizeof (WCHAR) - 1) == 0) { + } else if (StrnCmp (From, UNICODE_BR_STRING, sizeof (UNICODE_BR_STRING) / sizeof (WCHAR) - 1) == 0) { // // Found: \br -- pass through untouched // @@ -1594,7 +1603,7 @@ StringDBWriteDatabase ( { STRING_DB_HEADER DbHeader; UINT32 Counter; - UINT32 StrLen; + UINT32 StrLength; LANGUAGE_LIST *Lang; STRING_IDENTIFIER *StringIdentifier; STRING_LIST *StrList; @@ -1629,8 +1638,8 @@ StringDBWriteDatabase ( DbHeader.NumStringIdenfiers = mDBData.NumStringIdentifiers; StringIdentifier = mDBData.StringIdentifier; for (Counter = 0; Counter < mDBData.NumStringIdentifiers; Counter++) { - StrLen = wcslen (StringIdentifier->StringName) + 1; - DbHeader.StringIdentifiersSize += StrLen * sizeof (WCHAR) + sizeof (StringIdentifier->Flags); + StrLength = StrLen (StringIdentifier->StringName) + 1; + DbHeader.StringIdentifiersSize += StrLength * sizeof (WCHAR) + sizeof (StringIdentifier->Flags); StringIdentifier = StringIdentifier->Next; } @@ -1688,7 +1697,7 @@ StringDBSetStringReferenced ( // Status = STATUS_SUCCESS; WName = (WCHAR *) malloc ((strlen (StringIdentifierName) + 1) * sizeof (WCHAR)); - swprintf (WName, L"%S", StringIdentifierName); + UnicodeSPrint (WName, (strlen (StringIdentifierName) + 1) * sizeof (WCHAR), L"%a", StringIdentifierName); Id = StringDBFindStringIdentifierByName (WName); if (Id != NULL) { Id->Flags |= STRING_FLAGS_REFERENCED; @@ -1765,8 +1774,8 @@ StringDBDumpDatabase ( // The default control character is '/'. Make it '#' by writing // "/=#" to the output file. // - swprintf (Line, L"/=#"); - fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr); + UnicodeSPrint (Line, sizeof(Line), L"/=#"); + fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); // @@ -1778,24 +1787,24 @@ StringDBDumpDatabase ( // Write the "#define " string // if (StringIdentifier->Flags & STRING_FLAGS_REFERENCED) { - swprintf ( + UnicodeSPrint ( Line, - L"%s %-60.60s 0x%04X", + sizeof(Line), L"%s %-60.60s 0x%04X", DEFINE_STR, StringIdentifier->StringName, StringIdentifier->Index ); } else { - swprintf ( + UnicodeSPrint ( Line, - L"%s %-60.60s 0x%04X // NOT REFERENCED", + sizeof(Line), L"%s %-60.60s 0x%04X // NOT REFERENCED", DEFINE_STR, StringIdentifier->StringName, StringIdentifier->Index ); } - fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr); + fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); } @@ -1807,8 +1816,8 @@ StringDBDumpDatabase ( Scope = NULL; for (Lang = mDBData.LanguageList; Lang != NULL; Lang = Lang->Next) { fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); - swprintf (Line, L"#langdef %s \"%s\"", Lang->LanguageName, Lang->PrintableLanguageName); - fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr); + UnicodeSPrint (Line, sizeof(Line), L"#langdef %s \"%s\"", Lang->LanguageName, Lang->PrintableLanguageName); + fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); // @@ -1819,29 +1828,29 @@ StringDBDumpDatabase ( // // Print the internal flags for debug // - swprintf (Line, L"// flags=0x%02X", (UINT32) StrList->Flags); - fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr); + UnicodeSPrint (Line, sizeof(Line), L"// flags=0x%02X", (UINT32) StrList->Flags); + fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); // // Print the scope if changed // - if ((Scope == NULL) || (wcscmp (Scope, StrList->Scope) != 0)) { - swprintf (Line, L"#scope %s", StrList->Scope); - fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr); + if ((Scope == NULL) || (StrCmp (Scope, StrList->Scope) != 0)) { + UnicodeSPrint (Line, sizeof(Line), L"#scope %s", StrList->Scope); + fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); Scope = StrList->Scope; } - swprintf ( + UnicodeSPrint ( Line, - L"#string %-50.50s #language %s \"", + sizeof(Line), L"#string %-50.50s #language %s \"", StrList->StringName, Lang->LanguageName ); - fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr); + fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr); fwrite (StrList->Str, StrList->Size - sizeof (WCHAR), 1, OutFptr); - swprintf (Line, L"\""); - fwrite (Line, wcslen (Line) * sizeof (WCHAR), 1, OutFptr); + UnicodeSPrint (Line, sizeof(Line), L"\""); + fwrite (Line, StrLen (Line) * sizeof (WCHAR), 1, OutFptr); fwrite (&CrLf, sizeof (CrLf), 1, OutFptr); } } @@ -2175,7 +2184,7 @@ StringDBWriteGenericString ( Flags = STRING_FLAGS_UNDEFINED; } else { Flags = 0; - Size = (UINT16) ((wcslen (Str) + 1) * sizeof (WCHAR)); + Size = (UINT16) ((StrLen (Str) + 1) * sizeof (WCHAR)); } if (fwrite (&Size, sizeof (UINT16), 1, DBFptr) != 1) { @@ -2220,7 +2229,7 @@ StringDBFindString ( // if (IndirectionList != NULL) { for (IndListPtr = IndirectionList; IndListPtr != NULL; IndListPtr = IndListPtr->Next) { - if (wcscmp (StringName, IndListPtr->Str1) == 0) { + if (StrCmp (StringName, IndListPtr->Str1) == 0) { CurrString = StringDBFindString (LanguageName, StringName, IndListPtr->Str2, LanguagesOfInterest, NULL); if (CurrString != NULL) { return CurrString; @@ -2232,18 +2241,18 @@ StringDBFindString ( // First look for exact match language.stringname // for (Lang = mDBData.LanguageList; Lang != NULL; Lang = Lang->Next) { - if (wcscmp (LanguageName, Lang->LanguageName) == 0) { + if (StrCmp (LanguageName, Lang->LanguageName) == 0) { // // Found language match. Try to find string name match // for (CurrString = Lang->String; CurrString != NULL; CurrString = CurrString->Next) { - if (wcscmp (StringName, CurrString->StringName) == 0) { + if (StrCmp (StringName, CurrString->StringName) == 0) { // // Found a string name match. See if we're supposed to find // a scope match. // if (Scope != NULL) { - if (wcscmp (CurrString->Scope, Scope) == 0) { + if (StrCmp (CurrString->Scope, Scope) == 0) { return CurrString; } } else { @@ -2263,19 +2272,19 @@ StringDBFindString ( // If this is the language we're looking for, then process the // languages of interest list for it. // - if (wcsncmp (LanguageName, LanguagesOfInterest->Str, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) { + if (StrnCmp (LanguageName, LanguagesOfInterest->Str, LANGUAGE_IDENTIFIER_NAME_LEN) == 0) { WCharPtr = LanguagesOfInterest->Str + LANGUAGE_IDENTIFIER_NAME_LEN; while (*WCharPtr) { // // Double-check the length, though it should have been checked on the // command line. // - if (wcslen (WCharPtr) < LANGUAGE_IDENTIFIER_NAME_LEN) { + if (StrLen (WCharPtr) < LANGUAGE_IDENTIFIER_NAME_LEN) { Error (NULL, 0, 0, "malformed alternate language list", "%S", LanguagesOfInterest->Str); return NULL; } - wcsncpy (TempLangName, WCharPtr, LANGUAGE_IDENTIFIER_NAME_LEN); + StrnCpy (TempLangName, WCharPtr, LANGUAGE_IDENTIFIER_NAME_LEN); TempLangName[LANGUAGE_IDENTIFIER_NAME_LEN] = 0; CurrString = StringDBFindString (TempLangName, StringName, NULL, NULL, IndirectionList); if (CurrString != NULL) { @@ -2401,13 +2410,13 @@ DuplicateString ( return NULL; } - NewStr = MALLOC ((wcslen (Str) + 1) * sizeof (WCHAR)); + NewStr = MALLOC ((StrLen (Str) + 1) * sizeof (WCHAR)); if (NewStr == NULL) { Error (NULL, 0, 0, "memory allocation failure", NULL); return NULL; } - wcscpy (NewStr, Str); + StrCpy (NewStr, Str); return NewStr; } @@ -2515,7 +2524,7 @@ StringDBCreateHiiExportPack ( // entry for the printable language name as well. // StringPack.LanguageNameString = (STRING_OFFSET) (sizeof (EFI_HII_STRING_PACK) + (mDBData.NumStringIdentifiersReferenced * sizeof (STRING_OFFSET))); - StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (wcslen (LangName) + 1) * sizeof (WCHAR)); + StringPack.PrintableLanguageName = (STRING_OFFSET) (StringPack.LanguageNameString + (StrLen (LangName) + 1) * sizeof (WCHAR)); // // Add up the size of all strings so we can fill in our header. // @@ -2526,7 +2535,7 @@ StringDBCreateHiiExportPack ( // requested it. We set LangName to point to the proper language name string above. // if (StringIndex == STRING_ID_LANGUAGE_NAME) { - Len += (wcslen (LangName) + 1) * sizeof (WCHAR); + Len += (StrLen (LangName) + 1) * sizeof (WCHAR); } else { // // Find a string with this language.stringname @@ -2611,7 +2620,7 @@ StringDBCreateHiiExportPack ( // requested it. We set LangName to point to the proper language name string above. // if (StringIndex == STRING_ID_LANGUAGE_NAME) { - Offset += (wcslen (LangName) + 1) * sizeof (WCHAR); + Offset += (StrLen (LangName) + 1) * sizeof (WCHAR); CurrString = StringDBFindString ( Lang->LanguageName, StringIdentifier->StringName, diff --git a/Tools/Source/TianoTools/StrGather/build.xml b/Tools/Source/TianoTools/StrGather/build.xml index 0bee87089f..96658e870c 100644 --- a/Tools/Source/TianoTools/StrGather/build.xml +++ b/Tools/Source/TianoTools/StrGather/build.xml @@ -86,6 +86,8 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. libtool="${haveLibtool}" debug="false"> + + + - + diff --git a/Tools/Source/TianoTools/String/PrintLib.c b/Tools/Source/TianoTools/String/PrintLib.c new file mode 100644 index 0000000000..868a73eb6c --- /dev/null +++ b/Tools/Source/TianoTools/String/PrintLib.c @@ -0,0 +1,667 @@ +/** @file + Print Library. + + Copyright (c) 2006, 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: PrintLib.c + +**/ + +#include +#include +#include +#include +#include "PrintLibInternal.h" + +typedef struct { + RETURN_STATUS Status; + CHAR8 *String; +} STATUS_LOOKUP_TABLE_ENTRY; + +static CONST STATUS_LOOKUP_TABLE_ENTRY StatusString[] = { + { RETURN_SUCCESS, "Success" }, + { RETURN_LOAD_ERROR, "Load Error" }, + { RETURN_INVALID_PARAMETER, "Invalid Parameter" }, + { RETURN_UNSUPPORTED, "Unsupported" }, + { RETURN_BAD_BUFFER_SIZE, "Bad Buffer Size" }, + { RETURN_BUFFER_TOO_SMALL, "Buffer Too Small" }, + { RETURN_NOT_READY, "Not Ready" }, + { RETURN_DEVICE_ERROR, "Device Error" }, + { RETURN_WRITE_PROTECTED, "Write Protected" }, + { RETURN_OUT_OF_RESOURCES, "Out of Resources" }, + { RETURN_VOLUME_CORRUPTED, "Volume Corrupt" }, + { RETURN_VOLUME_FULL, "Volume Full" }, + { RETURN_NO_MEDIA, "No Media" }, + { RETURN_MEDIA_CHANGED, "Media changed" }, + { RETURN_NOT_FOUND, "Not Found" }, + { RETURN_ACCESS_DENIED, "Access Denied" }, + { RETURN_NO_RESPONSE, "No Response" }, + { RETURN_NO_MAPPING, "No mapping" }, + { RETURN_TIMEOUT, "Time out" }, + { RETURN_NOT_STARTED, "Not started" }, + { RETURN_ALREADY_STARTED, "Already started" }, + { RETURN_ABORTED, "Aborted" }, + { RETURN_ICMP_ERROR, "ICMP Error" }, + { RETURN_TFTP_ERROR, "TFTP Error" }, + { RETURN_PROTOCOL_ERROR, "Protocol Error" }, + { RETURN_WARN_UNKNOWN_GLYPH, "Warning Unknown Glyph" }, + { RETURN_WARN_DELETE_FAILURE, "Warning Delete Failure" }, + { RETURN_WARN_WRITE_FAILURE, "Warning Write Failure" }, + { RETURN_WARN_BUFFER_TOO_SMALL, "Warning Buffer Too Small" }, + { 0, NULL } +}; + + +/** + VSPrint function to process format and place the results in Buffer. Since a + VA_LIST is used this rountine allows the nesting of Vararg routines. Thus + this is the main print working routine + + @param StartOfBuffer Unicode buffer to print the results of the parsing of Format into. + + @param BufferSize Maximum number of characters to put into buffer. Zero means + no limit. + + @param Flags Intial flags value. Can only have FORMAT_UNICODE and OUTPUT_UNICODE set + + @param FormatString Unicode format string see file header for more details. + + @param Marker Vararg list consumed by processing Format. + + @return Number of characters printed. + +**/ +UINTN +BasePrintLibVSPrint ( + OUT CHAR8 *Buffer, + IN UINTN BufferSize, + IN UINTN Flags, + IN CONST CHAR8 *Format, + IN VA_LIST Marker + ) +{ + CHAR8 *OriginalBuffer; + CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS]; + UINTN BytesPerOutputCharacter; + UINTN BytesPerFormatCharacter; + UINTN FormatMask; + UINTN FormatCharacter; + UINTN Width; + UINTN Precision; + INT64 Value; + CHAR8 *ArgumentString; + UINTN Character; + GUID *TmpGuid; + TIME *TmpTime; + UINTN Count; + UINTN ArgumentMask; + INTN BytesPerArgumentCharacter; + UINTN ArgumentCharacter; + BOOLEAN Done; + UINTN Index; + CHAR8 Prefix; + BOOLEAN ZeroPad; + BOOLEAN Comma; + UINTN Digits; + UINTN Radix; + RETURN_STATUS Status; + + OriginalBuffer = Buffer; + + if ((Flags & OUTPUT_UNICODE) != 0) { + BytesPerOutputCharacter = 2; + } else { + BytesPerOutputCharacter = 1; + } + if ((Flags & FORMAT_UNICODE) != 0) { + BytesPerFormatCharacter = 2; + FormatMask = 0xffff; + } else { + BytesPerFormatCharacter = 1; + FormatMask = 0xff; + } + + // + // Reserve space for the Null terminator. + // If BufferSize is 0, this will set BufferSize to the max unsigned value + // + BufferSize--; + + // + // Get the first character from the format string + // + FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask; + + // + // Loop until the end of the format string is reached or the output buffer is full + // + while (FormatCharacter != 0 && BufferSize > 0) { + // + // Clear all the flag bits except those that may have been passed in + // + Flags &= (OUTPUT_UNICODE | FORMAT_UNICODE); + + // + // Set the default width to zero, and the default precision to 1 + // + Width = 0; + Precision = 1; + Prefix = 0; + Comma = FALSE; + ZeroPad = FALSE; + Count = 0; + Digits = 0; + + switch (FormatCharacter) { + case '%': + // + // Parse Flags and Width + // + for (Done = FALSE; !Done; ) { + Format += BytesPerFormatCharacter; + FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask; + switch (FormatCharacter) { + case '.': + Flags |= PRECISION; + break; + case '-': + Flags |= LEFT_JUSTIFY; + break; + case '+': + Flags |= PREFIX_SIGN; + break; + case ' ': + Flags |= PREFIX_BLANK; + break; + case ',': + Flags |= COMMA_TYPE; + break; + case 'L': + case 'l': + Flags |= LONG_TYPE; + break; + case '*': + if ((Flags & PRECISION) == 0) { + Flags |= PAD_TO_WIDTH; + Width = VA_ARG (Marker, UINTN); + } else { + Precision = VA_ARG (Marker, UINTN); + } + break; + case '0': + if ((Flags & PRECISION) == 0) { + Flags |= PREFIX_ZERO; + } + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + for (Count = 0; ((FormatCharacter >= '0') && (FormatCharacter <= '9')); ){ + Count = (Count * 10) + FormatCharacter - '0'; + Format += BytesPerFormatCharacter; + FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask; + } + Format -= BytesPerFormatCharacter; + if ((Flags & PRECISION) == 0) { + Flags |= PAD_TO_WIDTH; + Width = Count; + } else { + Precision = Count; + } + break; + default: + Done = TRUE; + break; + } + } + + // + // Limit the maximum field width to the remaining characters in the output buffer + // + if (Width > BufferSize) { + Width = BufferSize; + } + + // + // Handle each argument type + // + switch (FormatCharacter) { + case 'X': + Flags |= PREFIX_ZERO; + // + // break skiped on purpose + // + case 'x': + Flags |= RADIX_HEX; + // + // break skiped on purpose + // + case 'd': + if ((Flags & LONG_TYPE) == 0) { + Value = (VA_ARG (Marker, INTN)); + } else { + Value = VA_ARG (Marker, INT64); + } + if ((Flags & PREFIX_BLANK) != 0) { + Prefix = ' '; + } + if ((Flags & PREFIX_SIGN) != 0) { + Prefix = '+'; + } + if ((Flags & COMMA_TYPE) != 0) { + Comma = TRUE; + } + if ((Flags & RADIX_HEX) == 0) { + Radix = 10; + if (Comma) { + Flags &= (~PREFIX_ZERO); + Precision = 1; + } + if (Value < 0) { + Flags |= PREFIX_SIGN; + Prefix = '-'; + Value = -Value; + } + } else { + Radix = 16; + Comma = FALSE; + if ((Flags & LONG_TYPE) == 0 && Value < 0) { + Value = (UINTN)Value; + } + } + // + // Convert Value to a reversed string + // + Count = BasePrintLibValueToString (ValueBuffer, Value, Radix); + if (Value == 0 && Precision == 0) { + Count = 0; + } + ArgumentString = (CHAR8 *)ValueBuffer + Count; + Digits = 3 - (Count % 3); + if (Comma && Count != 0) { + Count += ((Count - 1) / 3); + } + if (Prefix != 0) { + Count++; + } + Flags |= ARGUMENT_REVERSED; + ZeroPad = TRUE; + if ((Flags & PREFIX_ZERO) != 0) { + if ((Flags & PAD_TO_WIDTH) != 0) { + if ((Flags & PRECISION) == 0) { + Precision = Width; + } + } + } + break; + + case 's': + case 'S': + Flags |= ARGUMENT_UNICODE; + // + // break skipped on purpose + // + case 'a': + ArgumentString = (CHAR8 *)VA_ARG (Marker, CHAR8 *); + if (ArgumentString == NULL) { + Flags &= (~ARGUMENT_UNICODE); + ArgumentString = ""; + } + break; + + case 'c': + Character = VA_ARG (Marker, UINTN) & 0xffff; + ArgumentString = (CHAR8 *)&Character; + Flags |= ARGUMENT_UNICODE; + break; + + case 'g': + TmpGuid = VA_ARG (Marker, GUID *); + if (TmpGuid == NULL) { + ArgumentString = ""; + } else { + BasePrintLibSPrint ( + ValueBuffer, + 0, + 0, + "%08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x", + TmpGuid->Data1, + TmpGuid->Data2, + TmpGuid->Data3, + TmpGuid->Data4[0], + TmpGuid->Data4[1], + TmpGuid->Data4[2], + TmpGuid->Data4[3], + TmpGuid->Data4[4], + TmpGuid->Data4[5], + TmpGuid->Data4[6], + TmpGuid->Data4[7] + ); + ArgumentString = ValueBuffer; + } + break; + + case 't': + TmpTime = VA_ARG (Marker, TIME *); + if (TmpTime == NULL) { + ArgumentString = ""; + } else { + BasePrintLibSPrint ( + ValueBuffer, + 0, + 0, + "%02d/%02d/%04d %02d:%02d", + TmpTime->Month, + TmpTime->Day, + TmpTime->Year, + TmpTime->Hour, + TmpTime->Minute + ); + ArgumentString = ValueBuffer; + } + break; + + case 'r': + Status = VA_ARG (Marker, RETURN_STATUS); + ArgumentString = ValueBuffer; + for (Index = 0; StatusString[Index].String != NULL; Index++) { + if (Status == StatusString[Index].Status) { + ArgumentString = StatusString[Index].String; + } + } + if (ArgumentString == ValueBuffer) { + BasePrintLibSPrint ((CHAR8 *) ValueBuffer, 0, 0, "%08X", Status); + } + break; + + case '%': + default: + // + // if the type is '%' or unknown, then print it to the screen + // + ArgumentString = (CHAR8 *)&FormatCharacter; + Flags |= ARGUMENT_UNICODE; + break; + } + break; + case '\n': + ArgumentString = "\r\n"; + break; + default: + ArgumentString = (CHAR8 *)&FormatCharacter; + Flags |= ARGUMENT_UNICODE; + break; + } + + // + // Retrieve the ArgumentString attriubutes + // + if ((Flags & ARGUMENT_UNICODE) != 0) { + ArgumentMask = 0xffff; + BytesPerArgumentCharacter = 2; + } else { + ArgumentMask = 0xff; + BytesPerArgumentCharacter = 1; + } + if ((Flags & ARGUMENT_REVERSED) != 0) { + BytesPerArgumentCharacter = -BytesPerArgumentCharacter; + } else { + // + // Compute the number of characters in ArgumentString and store it in Count + // ArgumentString is either null-terminated, or it contains Precision characters + // + for (Count = 0; Count < Precision || ((Flags & PRECISION) == 0); Count++) { + ArgumentCharacter = ((ArgumentString[Count * BytesPerArgumentCharacter] & 0xff) | ((ArgumentString[Count * BytesPerArgumentCharacter + 1]) << 8)) & ArgumentMask; + if (ArgumentCharacter == 0) { + break; + } + } + } + + // + // Limit the length of the string to append to the remaining characters in the output buffer + // + if (Count > BufferSize) { + Count = BufferSize; + } + if (Precision < Count) { + Precision = Count; + } + + // + // Pad before the string + // + if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH)) { + Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter); + } + + if (ZeroPad) { + if (Prefix != 0) { + Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter); + } + Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, '0', BytesPerOutputCharacter); + } else { + Buffer = BasePrintLibFillBuffer (Buffer, Precision - Count, ' ', BytesPerOutputCharacter); + if (Prefix != 0) { + Buffer = BasePrintLibFillBuffer (Buffer, 1, Prefix, BytesPerOutputCharacter); + } + } + + // + // Output the Prefix character if it is present + // + Index = 0; + if (Prefix) { + Index++; + } + + // + // Copy the string into the output buffer performing the required type conversions + // + while (Index < Count) { + ArgumentCharacter = ((*ArgumentString & 0xff) | (*(ArgumentString + 1) << 8)) & ArgumentMask; + + Buffer = BasePrintLibFillBuffer (Buffer, 1, ArgumentCharacter, BytesPerOutputCharacter); + ArgumentString += BytesPerArgumentCharacter; + Index++; + if (Comma) { + Digits++; + if (Digits == 3) { + Digits = 0; + Index++; + if (Index < Count) { + Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', BytesPerOutputCharacter); + } + } + } + } + + // + // Pad after the string + // + if ((Flags & (PAD_TO_WIDTH | LEFT_JUSTIFY)) == (PAD_TO_WIDTH | LEFT_JUSTIFY)) { + Buffer = BasePrintLibFillBuffer (Buffer, Width - Precision, ' ', BytesPerOutputCharacter); + } + + // + // Reduce the number of characters + // + BufferSize -= Count; + + // + // Get the next character from the format string + // + Format += BytesPerFormatCharacter; + + // + // Get the next character from the format string + // + FormatCharacter = (*Format | (*(Format + 1) << 8)) & FormatMask; + } + + // + // Null terminate the Unicode or ASCII string + // + Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, BytesPerOutputCharacter); + + return ((Buffer - OriginalBuffer) / BytesPerOutputCharacter); +} + +UINTN +BasePrintLibSPrint ( + OUT CHAR8 *StartOfBuffer, + IN UINTN BufferSize, + IN UINTN Flags, + IN CONST CHAR8 *FormatString, + ... + ) +{ + VA_LIST Marker; + + VA_START (Marker, FormatString); + return BasePrintLibVSPrint (StartOfBuffer, BufferSize, Flags, FormatString, Marker); +} + +UINTN +EFIAPI +UnicodeVSPrint ( + OUT CHAR16 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR16 *FormatString, + IN VA_LIST Marker + ) +{ + return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, FORMAT_UNICODE | OUTPUT_UNICODE, (CHAR8 *)FormatString, Marker); +} + +UINTN +EFIAPI +UnicodeSPrint ( + OUT CHAR16 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR16 *FormatString, + ... + ) +{ + VA_LIST Marker; + + VA_START (Marker, FormatString); + return UnicodeVSPrint (StartOfBuffer, BufferSize, FormatString, Marker); +} + +UINTN +EFIAPI +UnicodeVSPrintAsciiFormat ( + OUT CHAR16 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR8 *FormatString, + IN VA_LIST Marker + ) +{ + return BasePrintLibVSPrint ((CHAR8 *)StartOfBuffer, BufferSize >> 1, OUTPUT_UNICODE,FormatString, Marker); +} + +UINTN +EFIAPI +UnicodeSPrintAsciiFormat ( + OUT CHAR16 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR8 *FormatString, + ... + ) +{ + VA_LIST Marker; + + VA_START (Marker, FormatString); + return UnicodeVSPrintAsciiFormat (StartOfBuffer, BufferSize >> 1, FormatString, Marker); +} + +UINTN +EFIAPI +AsciiVSPrint ( + OUT CHAR8 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR8 *FormatString, + IN VA_LIST Marker + ) +{ + return BasePrintLibVSPrint (StartOfBuffer, BufferSize, 0, FormatString, Marker); +} + +UINTN +EFIAPI +AsciiSPrint ( + OUT CHAR8 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR8 *FormatString, + ... + ) +{ + VA_LIST Marker; + + VA_START (Marker, FormatString); + return AsciiVSPrint (StartOfBuffer, BufferSize, FormatString, Marker); +} + +UINTN +EFIAPI +AsciiVSPrintUnicodeFormat ( + OUT CHAR8 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR16 *FormatString, + IN VA_LIST Marker + ) +{ + return BasePrintLibVSPrint (StartOfBuffer, BufferSize, FORMAT_UNICODE, (CHAR8 *)FormatString, Marker); +} + +UINTN +EFIAPI +AsciiSPrintUnicodeFormat ( + OUT CHAR8 *StartOfBuffer, + IN UINTN BufferSize, + IN CONST CHAR16 *FormatString, + ... + ) +{ + VA_LIST Marker; + + VA_START (Marker, FormatString); + return AsciiVSPrintUnicodeFormat (StartOfBuffer, BufferSize, FormatString, Marker); +} + +UINTN +EFIAPI +UnicodeValueToString ( + IN OUT CHAR16 *Buffer, + IN UINTN Flags, + IN INT64 Value, + IN UINTN Width + ) +{ + return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 2); +} + +UINTN +EFIAPI +AsciiValueToString ( + IN OUT CHAR8 *Buffer, + IN UINTN Flags, + IN INT64 Value, + IN UINTN Width + ) +{ + return BasePrintLibConvertValueToString ((CHAR8 *)Buffer, Flags, Value, Width, 1); +} diff --git a/Tools/Source/TianoTools/String/PrintLibInternal.c b/Tools/Source/TianoTools/String/PrintLibInternal.c new file mode 100644 index 0000000000..a475815375 --- /dev/null +++ b/Tools/Source/TianoTools/String/PrintLibInternal.c @@ -0,0 +1,137 @@ +/** @file + Print Library worker functions. + + Copyright (c) 2006, 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: PrintLibInternal.c + +**/ + +#include +#include +#include +#include +#include +#include "PrintLibInternal.h" + +static CONST CHAR8 mHexStr[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; + +CHAR8 * +BasePrintLibFillBuffer ( + CHAR8 *Buffer, + INTN Length, + UINTN Character, + INTN Increment + ) +{ + INTN Index; + + for (Index = 0; Index < Length; Index++) { + *Buffer = (CHAR8) Character; + *(Buffer + 1) = (CHAR8) (Character >> 8); + Buffer += Increment; + } + return Buffer; +} + +/** + Print worker function that prints a Value as a decimal number in Buffer. + + @param Buffer Location to place the Unicode or ASCII string of Value. + + @param Value Value to convert to a Decimal or Hexidecimal string in Buffer. + + @param Flags Flags to use in printing string, see file header for details. + + @param Precision Minimum number of digits to return in the ASCII string + + @return Number of characters printed. + +**/ +UINTN +EFIAPI +BasePrintLibValueToString ( + IN OUT CHAR8 *Buffer, + IN INT64 Value, + IN UINTN Radix + ) +{ + UINTN Digits; + UINT32 Remainder; + + // + // Loop to convert one digit at a time in reverse order + // + *(Buffer++) = 0; + Digits = 0; + do { + // Value = (INT64)DivU64x32Remainder ((UINT64)Value, (UINT32)Radix, &Remainder); + Remainder = (UINT64)Value % (UINT32)Radix; + Value = (UINT64)Value / (UINT32)Radix; + *(Buffer++) = mHexStr[Remainder]; + Digits++; + } while (Value != 0); + return Digits; +} + +UINTN +BasePrintLibConvertValueToString ( + IN OUT CHAR8 *Buffer, + IN UINTN Flags, + IN INT64 Value, + IN UINTN Width, + IN UINTN Increment + ) +{ + CHAR8 *OriginalBuffer; + CHAR8 ValueBuffer[MAXIMUM_VALUE_CHARACTERS]; + UINTN Count; + UINTN Digits; + UINTN Index; + + OriginalBuffer = Buffer; + + if (Width == 0 || (Flags & COMMA_TYPE) != 0) { + Flags &= (~PREFIX_ZERO); + } + + if (Width == 0 || Width > (MAXIMUM_VALUE_CHARACTERS - 1)) { + Width = MAXIMUM_VALUE_CHARACTERS - 1; + } + + if (Value < 0) { + Value = -Value; + Buffer = BasePrintLibFillBuffer (Buffer, 1, '-', Increment); + } + + Count = BasePrintLibValueToString (ValueBuffer, Value, 10); + + if ((Flags & PREFIX_ZERO) != 0) { + Buffer = BasePrintLibFillBuffer (Buffer, Width - Count, '0', Increment); + } + + Digits = 3 - (Count % 3); + for (Index = 0; Index < Count; Index++) { + Buffer = BasePrintLibFillBuffer (Buffer, 1, ValueBuffer[Count - Index], Increment); + if ((Flags & COMMA_TYPE) != 0) { + Digits++; + if (Digits == 3) { + Digits = 0; + if ((Index + 1) < Count) { + Buffer = BasePrintLibFillBuffer (Buffer, 1, ',', Increment); + } + } + } + } + + Buffer = BasePrintLibFillBuffer (Buffer, 1, 0, Increment); + + return ((Buffer - OriginalBuffer) / Increment); +} diff --git a/Tools/Source/TianoTools/String/PrintLibInternal.h b/Tools/Source/TianoTools/String/PrintLibInternal.h new file mode 100644 index 0000000000..c7fecfd34c --- /dev/null +++ b/Tools/Source/TianoTools/String/PrintLibInternal.h @@ -0,0 +1,95 @@ +/** @file + Print Library. + + Copyright (c) 2006, 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: PrintLibInternal.h + +**/ + + + +// +// Print primitives +// +//#define LEFT_JUSTIFY 0x01 +#define PREFIX_SIGN 0x02 +#define PREFIX_BLANK 0x04 +//#define COMMA_TYPE 0x08 +#define LONG_TYPE 0x10 +//#define PREFIX_ZERO 0x20 +#define OUTPUT_UNICODE 0x40 +#define RADIX_HEX 0x80 +#define FORMAT_UNICODE 0x100 +#define PAD_TO_WIDTH 0x200 +#define ARGUMENT_UNICODE 0x400 +#define PRECISION 0x800 +#define ARGUMENT_REVERSED 0x1000 + +/// +/// Define the maximum number of characters that are required to encode +/// a decimal, hexidecimal, GUID, or TIME value with a Nll terminator. +/// Maximum Length Decimal String = 28 "-9,223,372,036,854,775,808" +/// Maximum Length Hexidecimal String = 17 "FFFFFFFFFFFFFFFF" +/// Maximum Length GUID = 37 "00000000-0000-0000-0000-000000000000" +/// Maximum Length TIME = 18 "12/12/2006 12:12" +/// +#define MAXIMUM_VALUE_CHARACTERS 38 + +// +// +// +typedef struct { + UINT16 Year; + UINT8 Month; + UINT8 Day; + UINT8 Hour; + UINT8 Minute; + UINT8 Second; + UINT8 Pad1; + UINT32 Nanosecond; + INT16 TimeZone; + UINT8 Daylight; + UINT8 Pad2; +} TIME; + +UINTN +BasePrintLibSPrint ( + OUT CHAR8 *Buffer, + IN UINTN BufferSize, + IN UINTN Flags, + IN CONST CHAR8 *FormatString, + ... + ); + +CHAR8 * +BasePrintLibFillBuffer ( + CHAR8 *Buffer, + INTN Length, + UINTN Character, + INTN Increment + ); + +UINTN +EFIAPI +BasePrintLibValueToString ( + IN OUT CHAR8 *Buffer, + IN INT64 Value, + IN UINTN Radix + ); + +UINTN +BasePrintLibConvertValueToString ( + IN OUT CHAR8 *Buffer, + IN UINTN Flags, + IN INT64 Value, + IN UINTN Width, + IN UINTN Increment + ); diff --git a/Tools/Source/TianoTools/String/String.c b/Tools/Source/TianoTools/String/String.c new file mode 100644 index 0000000000..10051806ad --- /dev/null +++ b/Tools/Source/TianoTools/String/String.c @@ -0,0 +1,809 @@ +/** @file + Unicode string primatives. + + Copyright (c) 2006, 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: String.c + +**/ + +#include +#include +#include +#include +#include +#include +#define _gPcd_FixedAtBuild_PcdMaximumUnicodeStringLength 0 +#define _gPcd_FixedAtBuild_PcdMaximumAsciiStringLength 0 + +/** + Copies one Null-terminated Unicode string to another Null-terminated Unicode + string and returns the new Unicode string. + + This function copies the contents of the Unicode string Source to the Unicode + string Destination, and returns Destination. If Source and Destination + overlap, then the results are undefined. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If Source and Destination overlap, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and Source contains more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated Unicode string. + @param Source Pointer to a Null-terminated Unicode string. + + @return Destiantion + +**/ +CHAR16 * +EFIAPI +StrCpy ( + OUT CHAR16 *Destination, + IN CONST CHAR16 *Source + ) +{ + CHAR16 *ReturnValue; + + // + // Destination cannot be NULL + // + ASSERT (Destination != NULL); + + // + // Destination and source cannot overlap + // + ASSERT ((UINTN)(Destination - Source) > StrLen (Source)); + ASSERT ((UINTN)(Source - Destination) > StrLen (Source)); + + ReturnValue = Destination; + while (*Source) { + *(Destination++) = *(Source++); + } + *Destination = 0; + return ReturnValue; +} + +/** + Copies one Null-terminated Unicode string with a maximum length to another + Null-terminated Unicode string with a maximum length and returns the new + Unicode string. + + This function copies the contents of the Unicode string Source to the Unicode + string Destination, and returns Destination. At most, Length Unicode + characters are copied from Source to Destination. If Length is 0, then + Destination is returned unmodified. If Length is greater that the number of + Unicode characters in Source, then Destination is padded with Null Unicode + characters. If Source and Destination overlap, then the results are + undefined. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If Source and Destination overlap, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and Source contains more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated Unicode string. + @param Source Pointer to a Null-terminated Unicode string. + @param Length Maximum number of Unicode characters to copy. + + @return Destination + +**/ +CHAR16 * +EFIAPI +StrnCpy ( + OUT CHAR16 *Destination, + IN CONST CHAR16 *Source, + IN UINTN Length + ) +{ + CHAR16 *ReturnValue; + + if (Length == 0) { + return Destination; + } + + // + // Destination cannot be NULL if Length is not zero + // + ASSERT (Destination != NULL); + + // + // Destination and source cannot overlap + // Q: Does Source have to be NULL-terminated? + // + ASSERT ((UINTN)(Destination - Source) > StrLen (Source)); + ASSERT ((UINTN)(Source - Destination) >= Length); + + ReturnValue = Destination; + + while ((*Source != L'\0') && (Length > 0)) { + *(Destination++) = *(Source++); + Length--; + } + + // ZeroMem (Destination, Length * sizeof (*Destination)); + memset (Destination, 0, Length * sizeof (*Destination)); + return ReturnValue; +} + +/** + Returns the length of a Null-terminated Unicode string. + + This function returns the number of Unicode characters in the Null-terminated + Unicode string specified by String. + + If String is NULL, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and String contains more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param String Pointer to a Null-terminated Unicode string. + + @return The length of String. + +**/ +UINTN +EFIAPI +StrLen ( + IN CONST CHAR16 *String + ) +{ + UINTN Length; + + ASSERT (String != NULL); + + for (Length = 0; *String != L'\0'; String++, Length++) { + // + // If PcdMaximumUnicodeStringLength is not zero, + // length should not more than PcdMaximumUnicodeStringLength + // + if (FixedPcdGet32 (PcdMaximumUnicodeStringLength) != 0) { + ASSERT (Length < FixedPcdGet32 (PcdMaximumUnicodeStringLength)); + } + } + return Length; +} + +/** + Returns the size of a Null-terminated Unicode string in bytes, including the + Null terminator. + + This function returns the size, in bytes, of the Null-terminated Unicode + string specified by String. + + If String is NULL, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and String contains more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param String Pointer to a Null-terminated Unicode string. + + @return The size of String. + +**/ +UINTN +EFIAPI +StrSize ( + IN CONST CHAR16 *String + ) +{ + return (StrLen (String) + 1) * sizeof (*String); +} + +/** + Compares two Null-terminated Unicode strings, and returns the difference + between the first mismatched Unicode characters. + + This function compares the Null-terminated Unicode string FirstString to the + Null-terminated Unicode string SecondString. If FirstString is identical to + SecondString, then 0 is returned. Otherwise, the value returned is the first + mismatched Unicode character in SecondString subtracted from the first + mismatched Unicode character in FirstString. + + If FirstString is NULL, then ASSERT(). + If SecondString is NULL, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more + than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more + than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param FirstString Pointer to a Null-terminated Unicode string. + @param SecondString Pointer to a Null-terminated Unicode string. + + @retval 0 FirstString is identical to SecondString. + @retval !=0 FirstString is not identical to SecondString. + +**/ +INTN +EFIAPI +StrCmp ( + IN CONST CHAR16 *FirstString, + IN CONST CHAR16 *SecondString + ) +{ + // + // ASSERT both strings are less long than PcdMaximumUnicodeStringLength + // + ASSERT (StrSize (FirstString) != 0); + ASSERT (StrSize (SecondString) != 0); + + while ((*FirstString != L'\0') && (*FirstString == *SecondString)) { + FirstString++; + SecondString++; + } + return *FirstString - *SecondString; +} + +/** + Compares two Null-terminated Unicode strings with maximum lengths, and + returns the difference between the first mismatched Unicode characters. + + This function compares the Null-terminated Unicode string FirstString to the + Null-terminated Unicode string SecondString. At most, Length Unicode + characters will be compared. If Length is 0, then 0 is returned. If + FirstString is identical to SecondString, then 0 is returned. Otherwise, the + value returned is the first mismatched Unicode character in SecondString + subtracted from the first mismatched Unicode character in FirstString. + + If FirstString is NULL, then ASSERT(). + If SecondString is NULL, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and FirstString contains more + than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and SecondString contains more + than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param FirstString Pointer to a Null-terminated Unicode string. + @param SecondString Pointer to a Null-terminated Unicode string. + @param Length Maximum number of Unicode characters to compare. + + @retval 0 FirstString is identical to SecondString. + @retval !=0 FirstString is not identical to SecondString. + +**/ +INTN +EFIAPI +StrnCmp ( + IN CONST CHAR16 *FirstString, + IN CONST CHAR16 *SecondString, + IN UINTN Length + ) +{ + if (Length == 0) { + return 0; + } + + // + // ASSERT both strings are less long than PcdMaximumUnicodeStringLength. + // Length tests are performed inside StrLen(). + // + ASSERT (StrSize (FirstString) != 0); + ASSERT (StrSize (SecondString) != 0); + + while ((*FirstString != L'\0') && + (*FirstString == *SecondString) && + (Length > 1)) { + FirstString++; + SecondString++; + Length--; + } + + return *FirstString - *SecondString; +} + +/** + Concatenates one Null-terminated Unicode string to another Null-terminated + Unicode string, and returns the concatenated Unicode string. + + This function concatenates two Null-terminated Unicode strings. The contents + of Null-terminated Unicode string Source are concatenated to the end of + Null-terminated Unicode string Destination. The Null-terminated concatenated + Unicode String is returned. If Source and Destination overlap, then the + results are undefined. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If Source and Destination overlap, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and Destination contains more + than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and Source contains more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination + and Source results in a Unicode string with more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated Unicode string. + @param Source Pointer to a Null-terminated Unicode string. + + @return Destination + +**/ +CHAR16 * +EFIAPI +StrCat ( + IN OUT CHAR16 *Destination, + IN CONST CHAR16 *Source + ) +{ + StrCpy (Destination + StrLen (Destination), Source); + + // + // Size of the resulting string should never be zero. + // PcdMaximumUnicodeStringLength is tested inside StrLen(). + // + ASSERT (StrSize (Destination) != 0); + return Destination; +} + +/** + Concatenates one Null-terminated Unicode string with a maximum length to the + end of another Null-terminated Unicode string, and returns the concatenated + Unicode string. + + This function concatenates two Null-terminated Unicode strings. The contents + of Null-terminated Unicode string Source are concatenated to the end of + Null-terminated Unicode string Destination, and Destination is returned. At + most, Length Unicode characters are concatenated from Source to the end of + Destination, and Destination is always Null-terminated. If Length is 0, then + Destination is returned unmodified. If Source and Destination overlap, then + the results are undefined. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If Source and Destination overlap, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and Destination contains more + than PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and Source contains more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + If PcdMaximumUnicodeStringLength is not zero, and concatenating Destination + and Source results in a Unicode string with more than + PcdMaximumUnicodeStringLength Unicode characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated Unicode string. + @param Source Pointer to a Null-terminated Unicode string. + @param Length Maximum number of Unicode characters to concatenate from + Source. + + @return Destination + +**/ +CHAR16 * +EFIAPI +StrnCat ( + IN OUT CHAR16 *Destination, + IN CONST CHAR16 *Source, + IN UINTN Length + ) +{ + StrnCpy (Destination + StrLen (Destination), Source, Length); + + // + // Size of the resulting string should never be zero. + // PcdMaximumUnicodeStringLength is tested inside StrLen(). + // + ASSERT (StrSize (Destination) != 0); + return Destination; +} + +/** + Copies one Null-terminated ASCII string to another Null-terminated ASCII + string and returns the new ASCII string. + + This function copies the contents of the ASCII string Source to the ASCII + string Destination, and returns Destination. If Source and Destination + overlap, then the results are undefined. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If Source and Destination overlap, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and Source contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated ASCII string. + @param Source Pointer to a Null-terminated ASCII string. + + @return Destination + +**/ +CHAR8 * +EFIAPI +AsciiStrCpy ( + OUT CHAR8 *Destination, + IN CONST CHAR8 *Source + ) +{ + CHAR8 *ReturnValue; + + // + // Destination cannot be NULL + // + ASSERT (Destination != NULL); + + // + // Destination and source cannot overlap + // + ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source)); + ASSERT ((UINTN)(Source - Destination) > AsciiStrLen (Source)); + + ReturnValue = Destination; + while (*Source) { + *(Destination++) = *(Source++); + } + *Destination = 0; + return ReturnValue; +} + +/** + Copies one Null-terminated ASCII string with a maximum length to another + Null-terminated ASCII string with a maximum length and returns the new ASCII + string. + + This function copies the contents of the ASCII string Source to the ASCII + string Destination, and returns Destination. At most, Length ASCII characters + are copied from Source to Destination. If Length is 0, then Destination is + returned unmodified. If Length is greater that the number of ASCII characters + in Source, then Destination is padded with Null ASCII characters. If Source + and Destination overlap, then the results are undefined. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If Source and Destination overlap, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and Source contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated ASCII string. + @param Source Pointer to a Null-terminated ASCII string. + @param Length Maximum number of ASCII characters to copy. + + @return Destination + +**/ +CHAR8 * +EFIAPI +AsciiStrnCpy ( + OUT CHAR8 *Destination, + IN CONST CHAR8 *Source, + IN UINTN Length + ) +{ + CHAR8 *ReturnValue; + + if (Length == 0) { + return Destination; + } + + // + // Destination cannot be NULL + // + ASSERT (Destination != NULL); + + // + // Destination and source cannot overlap + // + ASSERT ((UINTN)(Destination - Source) > AsciiStrLen (Source)); + ASSERT ((UINTN)(Source - Destination) >= Length); + + ReturnValue = Destination; + + while (*Source && Length > 0) { + *(Destination++) = *(Source++); + Length--; + } + + // ZeroMem (Destination, Length * sizeof (*Destination)); + memset (Destination, 0, Length * sizeof (*Destination)); + return ReturnValue; +} + +/** + Returns the length of a Null-terminated ASCII string. + + This function returns the number of ASCII characters in the Null-terminated + ASCII string specified by String. + + If String is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and String contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + + @param String Pointer to a Null-terminated ASCII string. + + @return The length of String. + +**/ +UINTN +EFIAPI +AsciiStrLen ( + IN CONST CHAR8 *String + ) +{ + UINTN Length; + + ASSERT (String != NULL); + + for (Length = 0; *String != '\0'; String++, Length++) { + // + // If PcdMaximumUnicodeStringLength is not zero, + // length should not more than PcdMaximumUnicodeStringLength + // + if (FixedPcdGet32 (PcdMaximumAsciiStringLength) != 0) { + ASSERT (Length < FixedPcdGet32 (PcdMaximumAsciiStringLength)); + } + } + return Length; +} + +/** + Returns the size of a Null-terminated ASCII string in bytes, including the + Null terminator. + + This function returns the size, in bytes, of the Null-terminated ASCII string + specified by String. + + If String is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and String contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + + @param String Pointer to a Null-terminated ASCII string. + + @return The size of String. + +**/ +UINTN +EFIAPI +AsciiStrSize ( + IN CONST CHAR8 *String + ) +{ + return (AsciiStrLen (String) + 1) * sizeof (*String); +} + +/** + Compares two Null-terminated ASCII strings, and returns the difference + between the first mismatched ASCII characters. + + This function compares the Null-terminated ASCII string FirstString to the + Null-terminated ASCII string SecondString. If FirstString is identical to + SecondString, then 0 is returned. Otherwise, the value returned is the first + mismatched ASCII character in SecondString subtracted from the first + mismatched ASCII character in FirstString. + + If FirstString is NULL, then ASSERT(). + If SecondString is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and FirstString contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and SecondString contains more + than PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + + @param FirstString Pointer to a Null-terminated ASCII string. + @param SecondString Pointer to a Null-terminated ASCII string. + + @retval 0 FirstString is identical to SecondString. + @retval !=0 FirstString is not identical to SecondString. + +**/ +INTN +EFIAPI +AsciiStrCmp ( + IN CONST CHAR8 *FirstString, + IN CONST CHAR8 *SecondString + ) +{ + // + // ASSERT both strings are less long than PcdMaximumAsciiStringLength + // + ASSERT (AsciiStrSize (FirstString)); + ASSERT (AsciiStrSize (SecondString)); + + while ((*FirstString != '\0') && (*FirstString == *SecondString)) { + FirstString++; + SecondString++; + } + + return *FirstString - *SecondString; +} + +STATIC +CHAR8 +EFIAPI +AsciiToUpper ( + IN CHAR8 Chr + ) +{ + return (Chr >= 'a' && Chr <= 'z') ? Chr - ('a' - 'A') : Chr; +} + +/** + Performs a case insensitive comparison of two Null-terminated ASCII strings, + and returns the difference between the first mismatched ASCII characters. + + This function performs a case insensitive comparison of the Null-terminated + ASCII string FirstString to the Null-terminated ASCII string SecondString. If + FirstString is identical to SecondString, then 0 is returned. Otherwise, the + value returned is the first mismatched lower case ASCII character in + SecondString subtracted from the first mismatched lower case ASCII character + in FirstString. + + If FirstString is NULL, then ASSERT(). + If SecondString is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and FirstString contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and SecondString contains more + than PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + + @param FirstString Pointer to a Null-terminated ASCII string. + @param SecondString Pointer to a Null-terminated ASCII string. + + @retval 0 FirstString is identical to SecondString using case insensitive + comparisons. + @retval !=0 FirstString is not identical to SecondString using case + insensitive comparisons. + +**/ +INTN +EFIAPI +AsciiStriCmp ( + IN CONST CHAR8 *FirstString, + IN CONST CHAR8 *SecondString + ) +{ + // + // ASSERT both strings are less long than PcdMaximumAsciiStringLength + // + ASSERT (AsciiStrSize (FirstString)); + ASSERT (AsciiStrSize (SecondString)); + + while ((*FirstString != '\0') && + (AsciiToUpper (*FirstString) == AsciiToUpper (*SecondString))) { + FirstString++; + SecondString++; + } + + return AsciiToUpper (*FirstString) - AsciiToUpper (*SecondString); +} + +/** + Compares two Null-terminated ASCII strings with maximum lengths, and returns + the difference between the first mismatched ASCII characters. + + This function compares the Null-terminated ASCII string FirstString to the + Null-terminated ASCII string SecondString. At most, Length ASCII characters + will be compared. If Length is 0, then 0 is returned. If FirstString is + identical to SecondString, then 0 is returned. Otherwise, the value returned + is the first mismatched ASCII character in SecondString subtracted from the + first mismatched ASCII character in FirstString. + + If FirstString is NULL, then ASSERT(). + If SecondString is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and FirstString contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and SecondString contains more + than PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + + @param FirstString Pointer to a Null-terminated ASCII string. + @param SecondString Pointer to a Null-terminated ASCII string. + + @retval 0 FirstString is identical to SecondString. + @retval !=0 FirstString is not identical to SecondString. + +**/ +INTN +EFIAPI +AsciiStrnCmp ( + IN CONST CHAR8 *FirstString, + IN CONST CHAR8 *SecondString, + IN UINTN Length + ) +{ + // + // ASSERT both strings are less long than PcdMaximumAsciiStringLength + // + ASSERT (AsciiStrSize (FirstString)); + ASSERT (AsciiStrSize (SecondString)); + + while ((*FirstString != '\0') && + (*FirstString == *SecondString) && + (Length > 1)) { + FirstString++; + SecondString++; + Length--; + } + return *FirstString - *SecondString; +} + +/** + Concatenates one Null-terminated ASCII string to another Null-terminated + ASCII string, and returns the concatenated ASCII string. + + This function concatenates two Null-terminated ASCII strings. The contents of + Null-terminated ASCII string Source are concatenated to the end of Null- + terminated ASCII string Destination. The Null-terminated concatenated ASCII + String is returned. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and Destination contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and Source contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero and concatenating Destination and + Source results in a ASCII string with more than PcdMaximumAsciiStringLength + ASCII characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated ASCII string. + @param Source Pointer to a Null-terminated ASCII string. + + @return Destination + +**/ +CHAR8 * +EFIAPI +AsciiStrCat ( + IN OUT CHAR8 *Destination, + IN CONST CHAR8 *Source + ) +{ + AsciiStrCpy (Destination + AsciiStrLen (Destination), Source); + + // + // Size of the resulting string should never be zero. + // PcdMaximumUnicodeStringLength is tested inside StrLen(). + // + ASSERT (AsciiStrSize (Destination) != 0); + return Destination; +} + +/** + Concatenates one Null-terminated ASCII string with a maximum length to the + end of another Null-terminated ASCII string, and returns the concatenated + ASCII string. + + This function concatenates two Null-terminated ASCII strings. The contents + of Null-terminated ASCII string Source are concatenated to the end of Null- + terminated ASCII string Destination, and Destination is returned. At most, + Length ASCII characters are concatenated from Source to the end of + Destination, and Destination is always Null-terminated. If Length is 0, then + Destination is returned unmodified. If Source and Destination overlap, then + the results are undefined. + + If Destination is NULL, then ASSERT(). + If Source is NULL, then ASSERT(). + If Source and Destination overlap, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and Destination contains more + than PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and Source contains more than + PcdMaximumAsciiStringLength ASCII characters, then ASSERT(). + If PcdMaximumAsciiStringLength is not zero, and concatenating Destination and + Source results in a ASCII string with more than PcdMaximumAsciiStringLength + ASCII characters, then ASSERT(). + + @param Destination Pointer to a Null-terminated ASCII string. + @param Source Pointer to a Null-terminated ASCII string. + @param Length Maximum number of ASCII characters to concatenate from + Source. + + @return Destination + +**/ +CHAR8 * +EFIAPI +AsciiStrnCat ( + IN OUT CHAR8 *Destination, + IN CONST CHAR8 *Source, + IN UINTN Length + ) +{ + AsciiStrnCpy (Destination + AsciiStrLen (Destination), Source, Length); + + // + // Size of the resulting string should never be zero. + // PcdMaximumUnicodeStringLength is tested inside StrLen(). + // + ASSERT (AsciiStrSize (Destination) != 0); + return Destination; +} diff --git a/Tools/Source/TianoTools/String/build.xml b/Tools/Source/TianoTools/String/build.xml new file mode 100644 index 0000000000..34f44ebb67 --- /dev/null +++ b/Tools/Source/TianoTools/String/build.xml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Unsupported Operating System + Please Contact Intel Corporation + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Tools/Source/TianoTools/build.xml b/Tools/Source/TianoTools/build.xml index 129e99ff9d..64c8fb92ea 100644 --- a/Tools/Source/TianoTools/build.xml +++ b/Tools/Source/TianoTools/build.xml @@ -23,7 +23,7 @@ WITHOUT WARRANTIES OR REPRESENTATIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED. + value="String/build.xml Common/build.xml CustomizedCompress/build.xml PeCoffLoader/build.xml"/>