summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Falcato <pedro.falcato@gmail.com>2022-12-21 01:00:36 +0000
committerPedro Falcato <pedro.falcato@gmail.com>2022-12-21 01:13:30 +0000
commit616e2befdcc35f90fcb5efdfaf9e66ed84c2c4d2 (patch)
treefbf456f7b55a19e04ac720beb925b6c3e8d83885
parent974cc668fc2b40b18e17f7f6eec02ede46205f92 (diff)
downloadacpica-616e2befdcc35f90fcb5efdfaf9e66ed84c2c4d2.tar.gz
asconvert: Fix prefix detection in AsInsertPrefix
Previously, it was assumed prefixes would be directly before the keyword itself. This is a wrong assumption that got broken by some code in actbl2.h. Therefore, look for the prefix on the whole line. Signed-off-by: Pedro Falcato <pedro.falcato@gmail.com>
-rw-r--r--source/tools/acpisrc/asconvrt.c63
1 files changed, 62 insertions, 1 deletions
diff --git a/source/tools/acpisrc/asconvrt.c b/source/tools/acpisrc/asconvrt.c
index ab34a6fe1..a99d28a7c 100644
--- a/source/tools/acpisrc/asconvrt.c
+++ b/source/tools/acpisrc/asconvrt.c
@@ -1618,6 +1618,8 @@ AsInsertPrefix (
int TrailingSpaces;
char LowerKeyword[128];
int KeywordLength;
+ char *LineStart;
+ BOOLEAN FoundPrefix;
switch (Type)
@@ -1664,7 +1666,66 @@ AsInsertPrefix (
{
/* Make sure the keyword isn't already prefixed with the insert */
- if (!strncmp (SubString - InsertLength, InsertString, InsertLength))
+ /* We find the beginning of the line and try to find the InsertString
+ * from LineStart up to SubBuffer (our keyword). If it's not there,
+ * we assume it doesn't have a prefix; this is a limitation, as having
+ * a keyword on another line is absolutely valid C.
+ */
+
+ LineStart = SubString;
+ FoundPrefix = FALSE;
+
+ /* Find the start of the line */
+
+ while (LineStart > Buffer)
+ {
+ if (*LineStart == '\n')
+ {
+ LineStart++;
+ break;
+ }
+
+ LineStart--;
+ }
+
+ /* Try to find InsertString from the start of the line up to SubBuffer */
+ /* Note that this algorithm is a bit naive. */
+
+ while (SubBuffer > LineStart)
+ {
+ if (*LineStart != *InsertString)
+ {
+ LineStart++;
+ continue;
+ }
+
+ if (strncmp (LineStart++, InsertString, InsertLength))
+ {
+ continue;
+ }
+
+ FoundPrefix = TRUE;
+ LineStart += InsertLength - 1;
+
+ /* Now check if there's non-whitespace between InsertString and SubBuffer, as that
+ * means it's not a valid prefix in this case. */
+
+ while (LineStart != SubBuffer)
+ {
+ if (!strchr (" \t\r\n", *LineStart))
+ {
+ /* We found non-whitespace while traversing up to SubBuffer,
+ * so this isn't a prefix.
+ */
+ FoundPrefix = FALSE;
+ break;
+ }
+
+ LineStart++;
+ }
+ }
+
+ if (FoundPrefix)
{
/* Add spaces if not already at the end-of-line */