From 829066d0befb18c484f2562ddf2299f97e623909 Mon Sep 17 00:00:00 2001 From: litvin Date: Fri, 4 Aug 2017 02:34:56 +0300 Subject: [PATCH 14/33] Make -include option processing as input before processing the regular C input file --- src/globals.c | 1 + src/main.c | 23 ++++++++++++++++++++--- src/proto.h | 1 + 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/src/globals.c b/src/globals.c index 777ba1e..b87dac0 100644 --- a/src/globals.c +++ b/src/globals.c @@ -312,6 +312,7 @@ S_options s_initOpt = { 0, // comment moving level NULL, // prune name NULL, // input files + NULL, // include files RC_ZERO, // continue refactoring 0, // completion case sensitive NULL, // xrefrc diff --git a/src/main.c b/src/main.c index 46d0d29..3ef299d 100644 --- a/src/main.c +++ b/src/main.c @@ -54,6 +54,7 @@ static void usage(char *s) { fprintf(stdout,"\t-javadocavailable= - packages for which javadoc is available\n"); fprintf(stdout,"\t-p - read options from section\n"); fprintf(stdout,"\t-I - search for includes in \n"); + fprintf(stdout,"\t-include - process as input before processing the regular C input file\n"); fprintf(stdout,"\t-D[=] - define macro with body \n"); fprintf(stdout,"\t-packages - allow packages as input files\n"); fprintf(stdout,"\t-sourcepath - set java sources paths\n"); @@ -757,7 +758,14 @@ static int processIOption(int *ii, int argc, char **argv) { mainAddStringListOption(&s_opt.includeDirs, argv[i]+2); } else if (strcmp(argv[i],"-include")==0) { - i = mainHandleIncludeOption(argc, argv, i); + /* process file as if #include "file" */ + i++; + if (i >= argc) { + sprintf(tmpBuff,"file name expected after -include\n"); + error(ERR_ST,tmpBuff); + usage(argv[0]); + } + mainAddStringListOption(&s_opt.includeFiles, argv[i]); } else return(0); *ii = i; @@ -2029,6 +2036,12 @@ static void fileTabInit() { /*///////////////////////// parsing /////////////////////////////////// */ static void mainParseInputFile() { + S_stringList *ll; + if (s_language == LAN_C || s_language == LAN_CCC) { + for (ll=s_opt.includeFiles; ll!=NULL; ll=ll->next) { + openInclude('<', ll->d, 0); + } + } if (s_language == LAN_JAVA) { uniyylval = & s_yygstate->gyylval; javayyparse(); @@ -2321,7 +2334,7 @@ static void mainFileProcessingInitialisations( struct stat dffstat; char *fileName; int lc; - S_stringList *tmpIncludeDirs; + S_stringList *tmpIncludeDirs,*tmpIncludeFiles; fileName = s_input_file_name; mainSetLanguage(fileName, outLanguage); @@ -2379,10 +2392,13 @@ static void mainFileProcessingInitialisations( reInitCwd(dffname, dffsect); tmpIncludeDirs = s_opt.includeDirs; s_opt.includeDirs = NULL; + tmpIncludeFiles = s_opt.includeFiles; + s_opt.includeFiles = NULL; getAndProcessXrefrcOptions(dffname, dffsect, dffsect); getAndProcessGccIncludeOptions(); getAndProcessGccDefineOptions(); LIST_APPEND(S_stringList, s_opt.includeDirs, tmpIncludeDirs); + LIST_APPEND(S_stringList, s_opt.includeFiles, tmpIncludeFiles); if (s_opt.taskRegime != RegimeEditServer && s_input_file_name == NULL) { *outInputIn = 0; goto fini; @@ -2516,6 +2532,7 @@ static void mainTotalTaskEntryInitialisations(int argc, char **argv) { DPRINTF("Initialisations.\n"); memset(&s_count, 0, sizeof(S_counters)); s_opt.includeDirs = NULL; + s_opt.includeFiles = NULL; SM_INIT(ftMemory); FT_ALLOCC(s_fileTab.tab, MAX_FILES, struct fileItem *);\ FILL_EXP_COMMAND();\ diff --git a/src/proto.h b/src/proto.h index c050502..94488b1 100644 --- a/src/proto.h +++ b/src/proto.h @@ -1622,6 +1622,7 @@ struct options { int commentMovingLevel; S_stringList *pruneNames; S_stringList *inputFiles; + S_stringList *includeFiles; int continueRefactoring; int completionCaseSensitive; char *xrefrc; -- 2.18.0