MCPcopy Create free account
hub / github.com/CloverHackyColor/CloverBootloader / PreProcess

Method PreProcess

BaseTools/Source/C/VfrCompile/VfrCompiler.cpp:592–656  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

590}
591
592VOID
593CVfrCompiler::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
647Out:
648 SET_RUN_STATUS (STATUS_PREPROCESSED);
649 return;

Callers 1

mainFunction · 0.45

Calls 6

fopenFunction · 0.85
fcloseFunction · 0.85
strcatFunction · 0.85
LongFilePathFunction · 0.50
strlenFunction · 0.50
strcpyFunction · 0.50

Tested by

no test coverage detected