summaryrefslogtreecommitdiffstats
path: root/source/tools/acpisrc/asremove.c
diff options
context:
space:
mode:
Diffstat (limited to 'source/tools/acpisrc/asremove.c')
-rw-r--r--source/tools/acpisrc/asremove.c84
1 files changed, 65 insertions, 19 deletions
diff --git a/source/tools/acpisrc/asremove.c b/source/tools/acpisrc/asremove.c
index 37b167b..78cbd6e 100644
--- a/source/tools/acpisrc/asremove.c
+++ b/source/tools/acpisrc/asremove.c
@@ -638,7 +638,9 @@ AsCleanupSpecialMacro (
{
char *SubString;
char *SubBuffer;
- char *LastNonSpace;
+ char *CommentEnd;
+ int NewLine;
+ int NestLevel;
SubBuffer = Buffer;
@@ -650,40 +652,84 @@ AsCleanupSpecialMacro (
if (SubString)
{
- /* Find start of the line */
+ /* Find start of the macro parameters */
- SubBuffer = SubString;
- while (*(SubBuffer - 1) == ' ')
+ while (*SubString != '(')
{
- SubBuffer--;
+ SubString++;
}
+ SubString++;
- if (*(SubBuffer - 1) == '\n')
+ NestLevel = 1;
+ while (*SubString)
{
- /* Find last non-space character */
+ if (*SubString == '(')
+ {
+ NestLevel++;
+ }
+ else if (*SubString == ')')
+ {
+ NestLevel--;
+ }
+
+ SubString++;
- LastNonSpace = SubBuffer - 1;
- while (isspace ((int) *LastNonSpace))
+ if (NestLevel == 0)
{
- LastNonSpace--;
+ break;
}
+ }
+
+SkipLine:
+
+ /* Find end of the line */
- if (*LastNonSpace != '\\')
+ NewLine = FALSE;
+ while (!NewLine && *SubString)
+ {
+ if (*SubString == '\n' && *(SubString - 1) != '\\')
{
- /* Remove the extra spaces */
+ NewLine = TRUE;
+ }
+ SubString++;
+ }
+
+ /* Find end of the line */
+
+ if (*SubString == '#' || *SubString == '\n')
+ {
+ goto SkipLine;
+ }
- SubString = AsRemoveData (SubBuffer, SubString);
+ SubBuffer = SubString;
- /* Enforce an empty line between the invocations */
+ /* Find start of the non-space */
- if (*(SubBuffer - 2) == ')')
- {
- AsInsertData (SubBuffer, "\n", 1);
- }
+ while (*SubString == ' ')
+ {
+ SubString++;
+ }
+
+ /* Find end of the line */
+
+ if (*SubString == '#' || *SubString == '\n')
+ {
+ goto SkipLine;
+ }
+
+ /* Find end of the line */
+
+ if (*SubString == '/' || *SubString == '*')
+ {
+ CommentEnd = strstr (SubString, "*/");
+ if (CommentEnd)
+ {
+ SubString = CommentEnd + 2;
+ goto SkipLine;
}
}
- SubBuffer = SubString + strlen (Keyword);
+ SubString = AsRemoveData (SubBuffer, SubString);
}
}
}
OpenPOWER on IntegriCloud