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 6, 2024
1 parent 2f015ea commit 0a85eca
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 12 deletions.
15 changes: 15 additions & 0 deletions documentation/RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,21 @@ should also be read to understand what has changed since earlier releases:

## Changes made on the 7.0 branch since 7.0.8.1

### Changes to msi related to include paths

There are two changes to `msi` included here.

`msi` now treats files included by .template or .substutiions files in a more
consistent way: for relative paths, it will always look relative to the current
working directory if no `-I` flags are passed, and if they are passed then it
will search for the _relative_ path from each of those flags.

Note that this does provide one change from previous behaviour: when opening a
file from the command line, `msi` will not use the `-I`-specified paths to
search for the file, but will only work relative to the current working
directory, consistent with most commandline utilities.


### Allow users to delete previously created records from the database

From this release, record instances and aliases that have already been loaded
Expand Down
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, bool 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,
bool 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,
bool 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, bool 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, bool 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, bool 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 0a85eca

Please sign in to comment.