| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
|
| 40 |
|
| 41 |
|
| 42 |
|
| 43 |
|
| 44 |
#include "aslcompiler.h" |
| 45 |
|
| 46 |
#define _COMPONENT ASL_PREPROCESSOR |
| 47 |
ACPI_MODULE_NAME ("prutils") |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
|
| 55 |
|
| 56 |
|
| 57 |
|
| 58 |
|
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
|
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
char * |
| 68 |
PrGetNextToken ( |
| 69 |
char *Buffer, |
| 70 |
char *MatchString, |
| 71 |
char **Next) |
| 72 |
{ |
| 73 |
char *TokenStart; |
| 74 |
|
| 75 |
|
| 76 |
if (!Buffer) |
| 77 |
{ |
| 78 |
|
| 79 |
|
| 80 |
Buffer = *Next; |
| 81 |
if (!(*Next)) |
| 82 |
{ |
| 83 |
return (NULL); |
| 84 |
} |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
while (*Buffer) |
| 90 |
{ |
| 91 |
if (strchr (MatchString, *Buffer)) |
| 92 |
{ |
| 93 |
Buffer++; |
| 94 |
} |
| 95 |
else |
| 96 |
{ |
| 97 |
break; |
| 98 |
} |
| 99 |
} |
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
if (!(*Buffer)) |
| 104 |
{ |
| 105 |
*Next = NULL; |
| 106 |
return (NULL); |
| 107 |
} |
| 108 |
|
| 109 |
TokenStart = Buffer; |
| 110 |
|
| 111 |
|
| 112 |
|
| 113 |
while (*Buffer) |
| 114 |
{ |
| 115 |
if (strchr (MatchString, *Buffer)) |
| 116 |
{ |
| 117 |
*Buffer = 0; |
| 118 |
*Next = Buffer+1; |
| 119 |
if (!**Next) |
| 120 |
{ |
| 121 |
*Next = NULL; |
| 122 |
} |
| 123 |
|
| 124 |
return (TokenStart); |
| 125 |
} |
| 126 |
|
| 127 |
Buffer++; |
| 128 |
} |
| 129 |
|
| 130 |
*Next = NULL; |
| 131 |
return (TokenStart); |
| 132 |
} |
| 133 |
|
| 134 |
|
| 135 |
|
| 136 |
|
| 137 |
|
| 138 |
|
| 139 |
|
| 140 |
|
| 141 |
|
| 142 |
|
| 143 |
|
| 144 |
|
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
void |
| 150 |
PrError ( |
| 151 |
UINT8 Level, |
| 152 |
UINT16 MessageId, |
| 153 |
UINT32 Column) |
| 154 |
{ |
| 155 |
#if 0 |
| 156 |
AcpiOsPrintf ("%s (%u) : %s", AslGbl_Files[ASL_FILE_INPUT].Filename, |
| 157 |
AslGbl_CurrentLineNumber, AslGbl_CurrentLineBuffer); |
| 158 |
#endif |
| 159 |
|
| 160 |
|
| 161 |
if (Column > 120) |
| 162 |
{ |
| 163 |
Column = 0; |
| 164 |
} |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
AslCommonError2 (Level, MessageId, |
| 169 |
AslGbl_CurrentLineNumber, Column, |
| 170 |
AslGbl_CurrentLineBuffer, |
| 171 |
AslGbl_Files[ASL_FILE_INPUT].Filename, "Preprocessor"); |
| 172 |
|
| 173 |
AslGbl_PreprocessorError = TRUE; |
| 174 |
} |
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
|
| 179 |
|
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
|
| 186 |
|
| 187 |
|
| 188 |
|
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
void |
| 194 |
PrReplaceResizeSubstring( |
| 195 |
PR_MACRO_ARG *Args, |
| 196 |
UINT32 Diff1, |
| 197 |
UINT32 Diff2, |
| 198 |
UINT32 i, |
| 199 |
char *Token) |
| 200 |
{ |
| 201 |
UINT32 b, PrevOffset; |
| 202 |
char *temp; |
| 203 |
char macro_sep[64]; |
| 204 |
|
| 205 |
|
| 206 |
AslGbl_MacroTokenReplaceBuffer = (char *) realloc (AslGbl_MacroTokenReplaceBuffer, |
| 207 |
(2 * (strlen (AslGbl_MacroTokenBuffer)))); |
| 208 |
|
| 209 |
strcpy (macro_sep, "~,() {}!*/%+-<>=&^|\"\t\n"); |
| 210 |
|
| 211 |
|
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
if (Diff1 != 0) |
| 217 |
{ |
| 218 |
|
| 219 |
|
| 220 |
|
| 221 |
|
| 222 |
|
| 223 |
|
| 224 |
PrevOffset = Args->Offset[i]; |
| 225 |
temp = strstr (AslGbl_MacroTokenBuffer, Args->Name); |
| 226 |
if (temp == NULL) |
| 227 |
{ |
| 228 |
return; |
| 229 |
} |
| 230 |
|
| 231 |
ResetHere1: |
| 232 |
temp = strstr (temp, Args->Name); |
| 233 |
if (temp == NULL) |
| 234 |
{ |
| 235 |
return; |
| 236 |
} |
| 237 |
Args->Offset[i] = strlen (AslGbl_MacroTokenBuffer) - |
| 238 |
strlen (temp); |
| 239 |
if (Args->Offset[i] == 0) |
| 240 |
{ |
| 241 |
goto JumpHere1; |
| 242 |
} |
| 243 |
if ((strchr (macro_sep, AslGbl_MacroTokenBuffer[(Args->Offset[i] - 1)])) && |
| 244 |
(strchr (macro_sep, AslGbl_MacroTokenBuffer[(Args->Offset[i] + strlen (Args->Name))]))) |
| 245 |
{ |
| 246 |
Args->Offset[i] += 0; |
| 247 |
} |
| 248 |
else |
| 249 |
{ |
| 250 |
temp += strlen (Args->Name); |
| 251 |
goto ResetHere1; |
| 252 |
} |
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
|
| 259 |
JumpHere1: |
| 260 |
b = strlen (Token) + Args->Offset[i]; |
| 261 |
memset (&AslGbl_MacroTokenBuffer[b], ' ', Diff1); |
| 262 |
|
| 263 |
# if 0 |
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
char Buff[8192]; |
| 270 |
|
| 271 |
|
| 272 |
|
| 273 |
for (j = 0; j < strlen (AslGbl_MacroTokenBuffer); j++) |
| 274 |
{ |
| 275 |
Buff[j] = AslGbl_MacroTokenBuffer[j]; |
| 276 |
} |
| 277 |
Buff[strlen (AslGbl_MacroTokenBuffer)] = '\0'; |
| 278 |
|
| 279 |
|
| 280 |
UINT32 len = strlen (Buff); |
| 281 |
|
| 282 |
for (j = 0; j < len; j++) |
| 283 |
{ |
| 284 |
if (Buff[0] == ' ') |
| 285 |
{ |
| 286 |
for (j = 0; j < (len - 1); j++) |
| 287 |
{ |
| 288 |
Buff[j] = Buff[j + 1]; |
| 289 |
} |
| 290 |
Buff[j] = '\0'; |
| 291 |
len--; |
| 292 |
j = -1; |
| 293 |
continue; |
| 294 |
} |
| 295 |
|
| 296 |
if (Buff[j] == ' ' && Buff[j + 1] == ' ') |
| 297 |
{ |
| 298 |
for (k = 0; k < (len - 1); k++) |
| 299 |
{ |
| 300 |
Buff[j] = Buff[j + 1]; |
| 301 |
} |
| 302 |
Buff[j] = '\0'; |
| 303 |
len--; |
| 304 |
j--; |
| 305 |
} |
| 306 |
} |
| 307 |
|
| 308 |
|
| 309 |
for (k = 0; k < strlen (Buff); k++) |
| 310 |
{ |
| 311 |
AslGbl_MacroTokenBuffer[k] = Buff[k]; |
| 312 |
} |
| 313 |
#endif |
| 314 |
|
| 315 |
PrReplaceData ( |
| 316 |
&AslGbl_MacroTokenBuffer[Args->Offset[i]], |
| 317 |
strlen (Token), Token, strlen (Token)); |
| 318 |
|
| 319 |
temp = NULL; |
| 320 |
Args->Offset[i] = PrevOffset; |
| 321 |
} |
| 322 |
|
| 323 |
|
| 324 |
|
| 325 |
|
| 326 |
|
| 327 |
|
| 328 |
else if (Diff2 != 0) |
| 329 |
{ |
| 330 |
|
| 331 |
|
| 332 |
PrevOffset = Args->Offset[i]; |
| 333 |
temp = strstr (AslGbl_MacroTokenBuffer, Args->Name); |
| 334 |
if (temp == NULL) |
| 335 |
{ |
| 336 |
return; |
| 337 |
} |
| 338 |
|
| 339 |
ResetHere2: |
| 340 |
temp = strstr (temp, Args->Name); |
| 341 |
if (temp == NULL) |
| 342 |
{ |
| 343 |
return; |
| 344 |
} |
| 345 |
Args->Offset[i] = strlen (AslGbl_MacroTokenBuffer) - |
| 346 |
strlen (temp); |
| 347 |
if (Args->Offset[i] == 0) |
| 348 |
{ |
| 349 |
goto JumpHere2; |
| 350 |
} |
| 351 |
if ((strchr (macro_sep, AslGbl_MacroTokenBuffer[(Args->Offset[i] - 1)])) && |
| 352 |
(strchr (macro_sep, AslGbl_MacroTokenBuffer[(Args->Offset[i] + strlen (Args->Name))]))) |
| 353 |
{ |
| 354 |
Args->Offset[i] += 0; |
| 355 |
} |
| 356 |
else |
| 357 |
{ |
| 358 |
temp+= strlen (Args->Name); |
| 359 |
goto ResetHere2; |
| 360 |
} |
| 361 |
|
| 362 |
|
| 363 |
|
| 364 |
|
| 365 |
|
| 366 |
|
| 367 |
|
| 368 |
JumpHere2: |
| 369 |
memcpy (AslGbl_MacroTokenReplaceBuffer, AslGbl_MacroTokenBuffer, Args->Offset[i]); |
| 370 |
strcat (AslGbl_MacroTokenReplaceBuffer, Token); |
| 371 |
strcat (AslGbl_MacroTokenReplaceBuffer, (AslGbl_MacroTokenBuffer + |
| 372 |
(Args->Offset[i] + strlen (Args->Name)))); |
| 373 |
|
| 374 |
strcpy (AslGbl_MacroTokenBuffer, AslGbl_MacroTokenReplaceBuffer); |
| 375 |
|
| 376 |
temp = NULL; |
| 377 |
Args->Offset[i] = PrevOffset; |
| 378 |
} |
| 379 |
|
| 380 |
|
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
else |
| 386 |
{ |
| 387 |
|
| 388 |
|
| 389 |
|
| 390 |
|
| 391 |
|
| 392 |
|
| 393 |
PrevOffset = Args->Offset[i]; |
| 394 |
temp = strstr (AslGbl_MacroTokenBuffer, Args->Name); |
| 395 |
if (temp == NULL) |
| 396 |
{ |
| 397 |
return; |
| 398 |
} |
| 399 |
|
| 400 |
ResetHere3: |
| 401 |
temp = strstr (temp, Args->Name); |
| 402 |
if (temp == NULL) |
| 403 |
{ |
| 404 |
return; |
| 405 |
} |
| 406 |
Args->Offset[i] = strlen (AslGbl_MacroTokenBuffer) - |
| 407 |
strlen (temp); |
| 408 |
if (Args->Offset[i] == 0) |
| 409 |
{ |
| 410 |
goto JumpHere3; |
| 411 |
} |
| 412 |
if ((strchr (macro_sep, AslGbl_MacroTokenBuffer[(Args->Offset[i] - 1)])) && |
| 413 |
(strchr (macro_sep, AslGbl_MacroTokenBuffer[(Args->Offset[i] + strlen (Args->Name))]))) |
| 414 |
{ |
| 415 |
Args->Offset[i] += 0; |
| 416 |
} |
| 417 |
else |
| 418 |
{ |
| 419 |
temp += strlen (Args->Name); |
| 420 |
goto ResetHere3; |
| 421 |
} |
| 422 |
|
| 423 |
JumpHere3: |
| 424 |
PrReplaceData ( |
| 425 |
&AslGbl_MacroTokenBuffer[Args->Offset[i]], |
| 426 |
strlen (Args->Name), Token, strlen (Token)); |
| 427 |
temp = NULL; |
| 428 |
Args->Offset[i] = PrevOffset; |
| 429 |
} |
| 430 |
} |
| 431 |
|
| 432 |
|
| 433 |
|
| 434 |
|
| 435 |
|
| 436 |
|
| 437 |
|
| 438 |
|
| 439 |
|
| 440 |
|
| 441 |
|
| 442 |
|
| 443 |
|
| 444 |
|
| 445 |
|
| 446 |
|
| 447 |
|
| 448 |
char * |
| 449 |
PrReplaceData ( |
| 450 |
char *Buffer, |
| 451 |
UINT32 LengthToRemove, |
| 452 |
char *BufferToAdd, |
| 453 |
UINT32 LengthToAdd) |
| 454 |
{ |
| 455 |
UINT32 BufferLength; |
| 456 |
|
| 457 |
|
| 458 |
|
| 459 |
|
| 460 |
BufferLength = strlen (Buffer) + 1; |
| 461 |
|
| 462 |
if (LengthToRemove != LengthToAdd) |
| 463 |
{ |
| 464 |
|
| 465 |
|
| 466 |
|
| 467 |
|
| 468 |
|
| 469 |
if (LengthToRemove > 0) |
| 470 |
{ |
| 471 |
memmove ((Buffer + LengthToAdd), (Buffer + LengthToRemove), |
| 472 |
(BufferLength - LengthToRemove)); |
| 473 |
} |
| 474 |
} |
| 475 |
|
| 476 |
|
| 477 |
|
| 478 |
|
| 479 |
if (LengthToAdd > 0) |
| 480 |
{ |
| 481 |
memmove (Buffer, BufferToAdd, LengthToAdd); |
| 482 |
} |
| 483 |
return (Buffer + LengthToAdd); |
| 484 |
} |
| 485 |
|
| 486 |
|
| 487 |
|
| 488 |
|
| 489 |
|
| 490 |
|
| 491 |
|
| 492 |
|
| 493 |
|
| 494 |
|
| 495 |
|
| 496 |
|
| 497 |
|
| 498 |
|
| 499 |
FILE * |
| 500 |
PrOpenIncludeFile ( |
| 501 |
char *Filename, |
| 502 |
char *OpenMode, |
| 503 |
char **FullPathname) |
| 504 |
{ |
| 505 |
FILE *IncludeFile; |
| 506 |
ASL_INCLUDE_DIR *NextDir; |
| 507 |
|
| 508 |
|
| 509 |
|
| 510 |
|
| 511 |
AslGbl_CurrentLineOffset++; |
| 512 |
|
| 513 |
|
| 514 |
|
| 515 |
|
| 516 |
if ((Filename[0] == '/') || |
| 517 |
(Filename[0] == '\\') || |
| 518 |
(Filename[1] == ':')) |
| 519 |
{ |
| 520 |
IncludeFile = PrOpenIncludeWithPrefix ( |
| 521 |
"", Filename, OpenMode, FullPathname); |
| 522 |
if (!IncludeFile) |
| 523 |
{ |
| 524 |
goto ErrorExit; |
| 525 |
} |
| 526 |
return (IncludeFile); |
| 527 |
} |
| 528 |
|
| 529 |
|
| 530 |
|
| 531 |
|
| 532 |
|
| 533 |
|
| 534 |
|
| 535 |
|
| 536 |
|
| 537 |
IncludeFile = PrOpenIncludeWithPrefix ( |
| 538 |
AslGbl_DirectoryPath, Filename, OpenMode, FullPathname); |
| 539 |
if (IncludeFile) |
| 540 |
{ |
| 541 |
return (IncludeFile); |
| 542 |
} |
| 543 |
|
| 544 |
|
| 545 |
|
| 546 |
|
| 547 |
|
| 548 |
NextDir = AslGbl_IncludeDirList; |
| 549 |
while (NextDir) |
| 550 |
{ |
| 551 |
IncludeFile = PrOpenIncludeWithPrefix ( |
| 552 |
NextDir->Dir, Filename, OpenMode, FullPathname); |
| 553 |
if (IncludeFile) |
| 554 |
{ |
| 555 |
return (IncludeFile); |
| 556 |
} |
| 557 |
|
| 558 |
NextDir = NextDir->Next; |
| 559 |
} |
| 560 |
|
| 561 |
|
| 562 |
|
| 563 |
ErrorExit: |
| 564 |
sprintf (AslGbl_MainTokenBuffer, "%s, %s", Filename, strerror (errno)); |
| 565 |
PrError (ASL_ERROR, ASL_MSG_INCLUDE_FILE_OPEN, 0); |
| 566 |
return (NULL); |
| 567 |
} |
| 568 |
|
| 569 |
|
| 570 |
|
| 571 |
|
| 572 |
|
| 573 |
|
| 574 |
|
| 575 |
|
| 576 |
|
| 577 |
|
| 578 |
|
| 579 |
|
| 580 |
|
| 581 |
|
| 582 |
|
| 583 |
|
| 584 |
FILE * |
| 585 |
PrOpenIncludeWithPrefix ( |
| 586 |
char *PrefixDir, |
| 587 |
char *Filename, |
| 588 |
char *OpenMode, |
| 589 |
char **FullPathname) |
| 590 |
{ |
| 591 |
FILE *IncludeFile; |
| 592 |
char *Pathname; |
| 593 |
|
| 594 |
|
| 595 |
|
| 596 |
|
| 597 |
Pathname = FlMergePathnames (PrefixDir, Filename); |
| 598 |
|
| 599 |
DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID |
| 600 |
"Include: Opening file - \"%s\"\n", |
| 601 |
AslGbl_CurrentLineNumber, Pathname); |
| 602 |
|
| 603 |
|
| 604 |
|
| 605 |
IncludeFile = fopen (Pathname, OpenMode); |
| 606 |
if (!IncludeFile) |
| 607 |
{ |
| 608 |
return (NULL); |
| 609 |
} |
| 610 |
|
| 611 |
|
| 612 |
|
| 613 |
PrPushInputFileStack (IncludeFile, Pathname); |
| 614 |
*FullPathname = Pathname; |
| 615 |
return (IncludeFile); |
| 616 |
} |
| 617 |
|
| 618 |
|
| 619 |
|
| 620 |
|
| 621 |
|
| 622 |
|
| 623 |
|
| 624 |
|
| 625 |
|
| 626 |
|
| 627 |
|
| 628 |
|
| 629 |
|
| 630 |
|
| 631 |
|
| 632 |
|
| 633 |
|
| 634 |
void |
| 635 |
PrPushInputFileStack ( |
| 636 |
FILE *InputFile, |
| 637 |
char *Filename) |
| 638 |
{ |
| 639 |
PR_FILE_NODE *Fnode; |
| 640 |
|
| 641 |
|
| 642 |
AslGbl_HasIncludeFiles = TRUE; |
| 643 |
|
| 644 |
|
| 645 |
|
| 646 |
Fnode = UtLocalCalloc (sizeof (PR_FILE_NODE)); |
| 647 |
|
| 648 |
Fnode->File = AslGbl_Files[ASL_FILE_INPUT].Handle; |
| 649 |
Fnode->Next = AslGbl_InputFileList; |
| 650 |
Fnode->Filename = AslGbl_Files[ASL_FILE_INPUT].Filename; |
| 651 |
Fnode->CurrentLineNumber = AslGbl_CurrentLineNumber; |
| 652 |
|
| 653 |
|
| 654 |
|
| 655 |
AslGbl_InputFileList = Fnode; |
| 656 |
|
| 657 |
DbgPrint (ASL_PARSE_OUTPUT, PR_PREFIX_ID |
| 658 |
"Push InputFile Stack: handle %p\n\n", |
| 659 |
AslGbl_CurrentLineNumber, InputFile); |
| 660 |
|
| 661 |
|
| 662 |
|
| 663 |
AslGbl_Files[ASL_FILE_INPUT].Filename = |
| 664 |
UtLocalCacheCalloc (strlen (Filename) + 1); |
| 665 |
strcpy (AslGbl_Files[ASL_FILE_INPUT].Filename, Filename); |
| 666 |
|
| 667 |
AslGbl_Files[ASL_FILE_INPUT].Handle = InputFile; |
| 668 |
AslGbl_CurrentLineNumber = 1; |
| 669 |
|
| 670 |
|
| 671 |
|
| 672 |
FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", 1, Filename); |
| 673 |
} |
| 674 |
|
| 675 |
|
| 676 |
|
| 677 |
|
| 678 |
|
| 679 |
|
| 680 |
|
| 681 |
|
| 682 |
|
| 683 |
|
| 684 |
|
| 685 |
|
| 686 |
|
| 687 |
|
| 688 |
|
| 689 |
|
| 690 |
|
| 691 |
BOOLEAN |
| 692 |
PrPopInputFileStack ( |
| 693 |
void) |
| 694 |
{ |
| 695 |
PR_FILE_NODE *Fnode; |
| 696 |
|
| 697 |
|
| 698 |
Fnode = AslGbl_InputFileList; |
| 699 |
DbgPrint (ASL_PARSE_OUTPUT, "\n" PR_PREFIX_ID |
| 700 |
"Pop InputFile Stack, Fnode %p\n\n", |
| 701 |
AslGbl_CurrentLineNumber, Fnode); |
| 702 |
|
| 703 |
if (!Fnode) |
| 704 |
{ |
| 705 |
return (FALSE); |
| 706 |
} |
| 707 |
|
| 708 |
|
| 709 |
|
| 710 |
fclose (AslGbl_Files[ASL_FILE_INPUT].Handle); |
| 711 |
|
| 712 |
|
| 713 |
|
| 714 |
AslGbl_InputFileList = Fnode->Next; |
| 715 |
|
| 716 |
|
| 717 |
|
| 718 |
AslGbl_Files[ASL_FILE_INPUT].Filename = Fnode->Filename; |
| 719 |
AslGbl_Files[ASL_FILE_INPUT].Handle = Fnode->File; |
| 720 |
AslGbl_CurrentLineNumber = Fnode->CurrentLineNumber; |
| 721 |
|
| 722 |
|
| 723 |
|
| 724 |
FlPrintFile (ASL_FILE_PREPROCESSOR, "#line %u \"%s\"\n", |
| 725 |
AslGbl_CurrentLineNumber, Fnode->Filename); |
| 726 |
|
| 727 |
|
| 728 |
|
| 729 |
ACPI_FREE (Fnode); |
| 730 |
return (TRUE); |
| 731 |
} |