Skip to content

Commit

Permalink
Reading a file from the command-line should not use include paths
Browse files Browse the repository at this point in the history
  • Loading branch information
simon-ess committed Nov 5, 2024
1 parent be2c890 commit 8eb52a5
Showing 1 changed file with 14 additions and 12 deletions.
26 changes: 14 additions & 12 deletions modules/database/src/ioc/dbtemplate/msi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ typedef struct inputData inputData;
static void inputConstruct(inputData **ppvt);
static void inputDestruct(inputData * const pvt);
static void inputAddPath(inputData * const pvt, const char * const pval);
static void inputBegin(inputData * const pvt, const char * const fileName);
static void inputBegin(inputData * const pvt, const char * const fileName, int fromCmdLine);
static char *inputNextLine(inputData * const pvt);
static void inputNewIncludeFile(inputData * const pvt, const char * const name);
static void inputErrPrint(const inputData * const pvt);
Expand All @@ -87,7 +87,8 @@ static void addMacroReplacements(MAC_HANDLE * const macPvt,
const char * const pval);
static void makeSubstitutions(inputData * const inputPvt,
MAC_HANDLE * const macPvt,
const char * const templateName);
const char * const templateName,
int fromCmdLine);

/*Global variables */
static int opt_V = 0;
Expand Down Expand Up @@ -175,7 +176,7 @@ int main(int argc,char **argv)

if (substitutionName.empty()) {
STEP("Single template+substitutions file");
makeSubstitutions(inputPvt, macPvt, templateName);
makeSubstitutions(inputPvt, macPvt, templateName, TRUE);
}
else {
subInfo *substitutePvt;
Expand Down Expand Up @@ -207,7 +208,7 @@ int main(int argc,char **argv)
macPushScope(macPvt);

addMacroReplacements(macPvt, macStr);
makeSubstitutions(inputPvt, macPvt, filename);
makeSubstitutions(inputPvt, macPvt, filename, FALSE);

if (localScope)
macPopScope(macPvt);
Expand Down Expand Up @@ -280,14 +281,15 @@ static const char *cmdNames[] = {"include","substitute"};

static void makeSubstitutions(inputData * const inputPvt,
MAC_HANDLE * const macPvt,
const char * const templateName)
const char * const templateName,
int fromCmdLine)
{
char *input;
static char buffer[MAX_BUFFER_SIZE];
int n;

ENTER;
inputBegin(inputPvt, templateName);
inputBegin(inputPvt, templateName, fromCmdLine);
while ((input = inputNextLine(inputPvt))) {
int expand=1;
char *p;
Expand Down Expand Up @@ -382,7 +384,7 @@ struct inputData {
inputData() { memset(inputBuffer, 0, sizeof(inputBuffer) * sizeof(inputBuffer[0])); };
};

static void inputOpenFile(inputData *pinputData, const char * const filename);
static void inputOpenFile(inputData *pinputData, const char * const filename, int fromCmdLine);
static void inputCloseFile(inputData *pinputData);
static void inputCloseAllFiles(inputData *pinputData);

Expand Down Expand Up @@ -435,11 +437,11 @@ static void inputAddPath(inputData * const pinputData, const char * const path)
EXIT;
}

static void inputBegin(inputData * const pinputData, const char * const fileName)
static void inputBegin(inputData * const pinputData, const char * const fileName, int fromCmdLine)
{
ENTER;
inputCloseAllFiles(pinputData);
inputOpenFile(pinputData, fileName);
inputOpenFile(pinputData, fileName, fromCmdLine);
EXIT;
}

Expand All @@ -466,7 +468,7 @@ static void inputNewIncludeFile(inputData * const pinputData,
const char * const name)
{
ENTER;
inputOpenFile(pinputData,name);
inputOpenFile(pinputData, name, FALSE);
EXIT;
}

Expand Down Expand Up @@ -505,7 +507,7 @@ static int isPathRelative(const char * const path) {
#endif
}

static void inputOpenFile(inputData *pinputData, const char * const filename)
static void inputOpenFile(inputData *pinputData, const char * const filename, int fromCmdLine)
{
std::list<std::string>& pathList = pinputData->pathList;
std::list<std::string>::iterator pathIt = pathList.end();
Expand All @@ -517,7 +519,7 @@ static void inputOpenFile(inputData *pinputData, const char * const filename)
STEP("Using stdin");
fp = stdin;
}
else if (pathList.empty() || !isPathRelative(filename)){
else if (fromCmdLine || pathList.empty() || !isPathRelative(filename)){
STEPS("Opening ", filename);
fp = fopen(filename, "r");
}
Expand Down

0 comments on commit 8eb52a5

Please sign in to comment.