int AsReplaceString ( char *Target, char *Replacement, UINT8 Type, char *Buffer) { char *SubString1; char *SubString2; char *SubBuffer; int TargetLength; int ReplacementLength; int ReplaceCount = 0; TargetLength = strlen (Target); ReplacementLength = strlen (Replacement); SubBuffer = Buffer; SubString1 = Buffer; while (SubString1) { /* Find the target string */ SubString1 = strstr (SubBuffer, Target); if (!SubString1) { return (ReplaceCount); } /* * Check for translation escape string -- means to ignore * blocks of code while replacing */ if (Gbl_IgnoreTranslationEscapes) { SubString2 = NULL; } else { SubString2 = strstr (SubBuffer, AS_START_IGNORE); } if ((SubString2) && (SubString2 < SubString1)) { /* Find end of the escape block starting at "Substring2" */ SubString2 = strstr (SubString2, AS_STOP_IGNORE); if (!SubString2) { /* Didn't find terminator */ return (ReplaceCount); } /* Move buffer to end of escape block and continue */ SubBuffer = SubString2; } /* Do the actual replace if the target was found */ else { if ((Type & REPLACE_MASK) == REPLACE_WHOLE_WORD) { if (!AsMatchExactWord (SubString1, TargetLength)) { SubBuffer = SubString1 + 1; continue; } } SubBuffer = AsReplaceData (SubString1, TargetLength, Replacement, ReplacementLength); if ((Type & EXTRA_INDENT_C) && (!Gbl_StructDefs)) { SubBuffer = AsInsertData (SubBuffer, " ", 8); } ReplaceCount++; } } return (ReplaceCount); }
void AsInsertPrefix ( char *Buffer, char *Keyword, UINT8 Type) { char *SubString; char *SubBuffer; char *EndKeyword; int InsertLength; char *InsertString; int TrailingSpaces; char LowerKeyword[128]; int KeywordLength; switch (Type) { case SRC_TYPE_STRUCT: InsertString = "struct "; break; case SRC_TYPE_UNION: InsertString = "union "; break; default: return; } strcpy (LowerKeyword, Keyword); AcpiUtStrlwr (LowerKeyword); SubBuffer = Buffer; SubString = Buffer; InsertLength = strlen (InsertString); KeywordLength = strlen (Keyword); while (SubString) { /* Find an instance of the keyword */ SubString = strstr (SubBuffer, LowerKeyword); if (!SubString) { return; } SubBuffer = SubString; /* Must be standalone word, not a substring */ if (AsMatchExactWord (SubString, KeywordLength)) { /* Make sure the keyword isn't already prefixed with the insert */ if (!strncmp (SubString - InsertLength, InsertString, InsertLength)) { /* Add spaces if not already at the end-of-line */ if (*(SubBuffer + KeywordLength) != '\n') { /* Already present, add spaces after to align structure members */ #if 0 /* ONLY FOR C FILES */ AsInsertData (SubBuffer + KeywordLength, " ", 8); #endif } goto Next; } /* Make sure the keyword isn't at the end of a struct/union */ /* Note: This code depends on a single space after the brace */ if (*(SubString - 2) == '}') { goto Next; } /* Prefix the keyword with the insert string */ Gbl_MadeChanges = TRUE; /* Is there room for insertion */ EndKeyword = SubString + strlen (LowerKeyword); TrailingSpaces = 0; while (EndKeyword[TrailingSpaces] == ' ') { TrailingSpaces++; } /* * Use "if (TrailingSpaces > 1)" if we want to ignore casts */ SubBuffer = SubString + InsertLength; if (TrailingSpaces > InsertLength) { /* Insert the keyword */ memmove (SubBuffer, SubString, KeywordLength); /* Insert the keyword */ memmove (SubString, InsertString, InsertLength); } else { AsInsertData (SubString, InsertString, InsertLength); } } Next: SubBuffer += KeywordLength; } }
void AsRemoveConditionalCompile ( char *Buffer, char *Keyword) { char *SubString; char *SubBuffer; char *IfPtr; char *EndifPtr; char *ElsePtr; char *Comment; int KeywordLength; KeywordLength = strlen (Keyword); SubBuffer = Buffer; SubString = Buffer; while (SubString) { SubBuffer = strstr (SubString, Keyword); if (!SubBuffer) { return; } /* * Check for translation escape string -- means to ignore * blocks of code while replacing */ Comment = strstr (SubString, AS_START_IGNORE); if ((Comment) && (Comment < SubBuffer)) { SubString = strstr (Comment, AS_STOP_IGNORE); if (!SubString) { return; } SubString += 3; continue; } /* Check for ordinary comment */ Comment = strstr (SubString, "/*"); if ((Comment) && (Comment < SubBuffer)) { SubString = strstr (Comment, "*/"); if (!SubString) { return; } SubString += 2; continue; } SubString = SubBuffer; if (!AsMatchExactWord (SubString, KeywordLength)) { SubString++; continue; } /* Find start of this line */ while (*SubString != '\n' && (SubString > Buffer)) { SubString--; } SubString++; /* Find the "#ifxxxx" */ IfPtr = strstr (SubString, "#if"); if (!IfPtr) { return; } if (IfPtr > SubBuffer) { /* Not the right #if */ SubString = SubBuffer + strlen (Keyword); continue; } /* Find closing #endif or #else */ EndifPtr = strstr (SubBuffer, "#endif"); if (!EndifPtr) { /* There has to be an #endif */ return; } ElsePtr = strstr (SubBuffer, "#else"); if ((ElsePtr) && (EndifPtr > ElsePtr)) { /* This #ifdef contains an #else clause */ /* Find end of this line */ SubBuffer = AsSkipPastChar (ElsePtr, '\n'); if (!SubBuffer) { return; } /* Remove the #ifdef .... #else code */ AsRemoveData (SubString, SubBuffer); /* Next, we will remove the #endif statement */ EndifPtr = strstr (SubString, "#endif"); if (!EndifPtr) { /* There has to be an #endif */ return; } SubString = EndifPtr; } /* Remove the ... #endif part */ /* Find end of this line */ SubBuffer = AsSkipPastChar (EndifPtr, '\n'); if (!SubBuffer) { return; } /* Remove the lines */ SubBuffer = AsRemoveData (SubString, SubBuffer); } }
int AsLowerCaseString ( char *Target, char *Buffer) { char *SubString1; char *SubString2; char *SubBuffer; int TargetLength; int LowerCaseCount = 0; int i; TargetLength = strlen (Target); SubBuffer = Buffer; SubString1 = Buffer; while (SubString1) { /* Find the target string */ SubString1 = strstr (SubBuffer, Target); if (!SubString1) { return (LowerCaseCount); } /* * Check for translation escape string -- means to ignore * blocks of code while replacing */ if (Gbl_IgnoreTranslationEscapes) { SubString2 = NULL; } else { SubString2 = strstr (SubBuffer, AS_START_IGNORE); } if ((SubString2) && (SubString2 < SubString1)) { /* Find end of the escape block starting at "Substring2" */ SubString2 = strstr (SubString2, AS_STOP_IGNORE); if (!SubString2) { /* Didn't find terminator */ return (LowerCaseCount); } /* Move buffer to end of escape block and continue */ SubBuffer = SubString2; } /* Do the actual replace if the target was found */ else { if (!AsMatchExactWord (SubString1, TargetLength)) { SubBuffer = SubString1 + 1; continue; } for (i = 0; i < TargetLength; i++) { SubString1[i] = (char) tolower ((int) SubString1[i]); } SubBuffer = SubString1 + TargetLength; if ((Gbl_WidenDeclarations) && (!Gbl_StructDefs)) { if ((SubBuffer[0] == ' ') && (SubBuffer[1] == ' ')) { AsInsertData (SubBuffer, " ", 8); } } LowerCaseCount++; } } return (LowerCaseCount); }
void AsRemoveStatement ( char *Buffer, char *Keyword, UINT32 Type) { char *SubString; char *SubBuffer; int KeywordLength; KeywordLength = strlen (Keyword); SubBuffer = Buffer; SubString = Buffer; while (SubString) { SubString = strstr (SubBuffer, Keyword); if (SubString) { SubBuffer = SubString; if ((Type == REPLACE_WHOLE_WORD) && (!AsMatchExactWord (SubString, KeywordLength))) { SubBuffer++; continue; } /* Find start of this line */ while (*SubString != '\n') { SubString--; } SubString++; /* Find end of this statement */ SubBuffer = AsSkipPastChar (SubBuffer, ';'); if (!SubBuffer) { return; } /* Find end of this line */ SubBuffer = AsSkipPastChar (SubBuffer, '\n'); if (!SubBuffer) { return; } /* If next line is blank, remove it too */ if (*SubBuffer == '\n') { SubBuffer++; } /* Remove the lines */ SubBuffer = AsRemoveData (SubString, SubBuffer); } } }