Reading a file from the command-line should not use include paths

This commit is contained in:
Simon Rose
2024-11-05 09:47:43 +01:00
committed by Michael Davidsaver
parent b90ab7de13
commit 0186836449
3 changed files with 50 additions and 12 deletions

View File

@ -37,6 +37,30 @@ because the message is not available over Channel Access.
Updating property fields now only post DBE_PROPERTY events if the
field actually changed.
### 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. That is, the
following will now find the file `bar.template` located at
`/some/path/rel/path/bar.template`
```
$ cat foo.substitutions
file rel/path/bar.template {
# contents
}
$ msi -I /some/path foo.substitutions
```
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

View File

@ -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);
@ -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;
@ -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;
@ -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);
@ -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;
@ -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);
@ -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;
}
@ -466,7 +468,7 @@ static void inputNewIncludeFile(inputData * const pinputData,
const char * const name)
{
ENTER;
inputOpenFile(pinputData,name);
inputOpenFile(pinputData, name, false);
EXIT;
}
@ -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();
@ -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");
}

View File

@ -60,6 +60,18 @@ Switches have the following meanings:
2. . (the current directory)
3. .. (the parent of the current directory)
Note that relative path searching is handled as
$ cat foo.substitutions
file rel/path/bar.template {
# contents
}
$ msi -I . -I /some/path foo.substitutions
which will try to find `bar.template` at the path `./rel/path/` followed by
`/some/path/rel/path`.
- **-M _substitutions_**
This parameter specifies macro values for the template instance.