| 590 | } |
| 591 | |
| 592 | VOID |
| 593 | CVfrCompiler::PreProcess ( |
| 594 | VOID |
| 595 | ) |
| 596 | { |
| 597 | FILE *pVfrFile = NULL; |
| 598 | UINT32 CmdLen = 0; |
| 599 | CHAR8 *PreProcessCmd = NULL; |
| 600 | |
| 601 | if (!IS_RUN_STATUS(STATUS_INITIALIZED)) { |
| 602 | goto Fail; |
| 603 | } |
| 604 | |
| 605 | if (mOptions.SkipCPreprocessor == TRUE) { |
| 606 | goto Out; |
| 607 | } |
| 608 | |
| 609 | if ((pVfrFile = fopen (LongFilePath (mOptions.VfrFileName), "r")) == NULL) { |
| 610 | DebugError (NULL, 0, 0001, "Error opening the input VFR file", "%s", mOptions.VfrFileName); |
| 611 | goto Fail; |
| 612 | } |
| 613 | fclose (pVfrFile); |
| 614 | |
| 615 | CmdLen = strlen (mPreProcessCmd) + strlen (mPreProcessOpt) + |
| 616 | strlen (mOptions.VfrFileName) + strlen (mOptions.PreprocessorOutputFileName); |
| 617 | if (mOptions.CPreprocessorOptions != NULL) { |
| 618 | CmdLen += strlen (mOptions.CPreprocessorOptions); |
| 619 | } |
| 620 | if (mOptions.IncludePaths != NULL) { |
| 621 | CmdLen += strlen (mOptions.IncludePaths); |
| 622 | } |
| 623 | |
| 624 | PreProcessCmd = new CHAR8[CmdLen + 10]; |
| 625 | if (PreProcessCmd == NULL) { |
| 626 | DebugError (NULL, 0, 4001, "Resource: memory can't be allocated", NULL); |
| 627 | goto Fail; |
| 628 | } |
| 629 | strcpy (PreProcessCmd, mPreProcessCmd), strcat (PreProcessCmd, " "); |
| 630 | strcat (PreProcessCmd, mPreProcessOpt), strcat (PreProcessCmd, " "); |
| 631 | if (mOptions.IncludePaths != NULL) { |
| 632 | strcat (PreProcessCmd, mOptions.IncludePaths), strcat (PreProcessCmd, " "); |
| 633 | } |
| 634 | if (mOptions.CPreprocessorOptions != NULL) { |
| 635 | strcat (PreProcessCmd, mOptions.CPreprocessorOptions), strcat (PreProcessCmd, " "); |
| 636 | } |
| 637 | strcat (PreProcessCmd, mOptions.VfrFileName), strcat (PreProcessCmd, " > "); |
| 638 | strcat (PreProcessCmd, mOptions.PreprocessorOutputFileName); |
| 639 | |
| 640 | if (system (PreProcessCmd) != 0) { |
| 641 | DebugError (NULL, 0, 0003, "Error parsing file", "failed to spawn C preprocessor on VFR file %s\n", PreProcessCmd); |
| 642 | goto Fail; |
| 643 | } |
| 644 | |
| 645 | delete[] PreProcessCmd; |
| 646 | |
| 647 | Out: |
| 648 | SET_RUN_STATUS (STATUS_PREPROCESSED); |
| 649 | return; |