diff --git a/msi.c b/msi.c index 88d5ed506..82ae20aaf 100644 --- a/msi.c +++ b/msi.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include @@ -63,6 +64,11 @@ int main(int argc,char **argv) pval = (narg==1) ? (argv[1]+2) : argv[2]; if(strncmp(argv[1],"-I",2)==0) { inputAddPath(inputPvt,pval); + } else if(strncmp(argv[1],"-o",2)==0) { + if(freopen(pval,"w",stdout)==NULL) { + fprintf(stderr,"Can't open %s for writing: %s\n", pval, strerror(errno)); + exit(1); + } } else if(strncmp(argv[1],"-M",2)==0) { addMacroReplacements(macPvt,pval); } else if(strncmp(argv[1],"-S",2)==0) { @@ -113,7 +119,7 @@ int main(int argc,char **argv) void usageExit(void) { - fprintf(stderr,"usage: msi -V -Ipath ... -Msub ... -Ssubfile template\n"); + fprintf(stderr,"usage: msi -V -opath -Ipath ... -Msub ... -Ssubfile template\n"); fprintf(stderr," Specifying path will replace the default '.'\n"); fprintf(stderr," stdin is used if template is not given\n"); exit(1); @@ -547,8 +553,13 @@ static int substituteGetNextSet(void *pvt,char **filename) } freePattern(psubInfo); free((void *)psubInfo->filename); - psubInfo->filename = calloc(strlen(psubFile->string)+1,sizeof(char)); - strcpy(psubInfo->filename,psubFile->string); + if(psubFile->string[0]=='"'&&psubFile->string[strlen(psubFile->string)-1]=='"') { + psubFile->string[strlen(psubFile->string)-1]='\0'; + psubInfo->filename = macEnvExpand(psubFile->string+1); + } + else { + psubInfo->filename = macEnvExpand(psubFile->string); + } while(subGetNextToken(psubFile)==tokenSeparater); if(psubFile->token!=tokenLBrace) { subFileErrPrint(psubFile,"Expecting {"); diff --git a/msi.html b/msi.html index eb9a6a027..328e8f0f0 100644 --- a/msi.html +++ b/msi.html @@ -25,15 +25,18 @@ files accepted by dbLoadTemplate or subtool.

Command Syntax:

-
msi -V -Idir -Msub -Ssubfile template
+
msi -V -ofile -Idir -Msub -Ssubfile template
NOTE: All parameters are optional and a space is optional between  --I, -M, and -S  and the  associated value. Output is written -to stdout. +-o, -I, -M, and -S  and the  associated value. Output is written +to stdout unless the -o option is given.

Where:

-V

    If this parameter is specified then an undefined macro is considered an error. An error message is generated and the line containing the macro -is not written to stdout.
+is not written to the output. +-o file +
    Output will be written to the specifed file rather than to the standard output.
+ -I dir
    This parameter, which may be repeated, specifies a search path for include commands. For example:
@@ -71,7 +74,7 @@ $(c) or ${c} is replaced by cval template
    The input file. If no file is specified then input is taken from stdin, i.e. msi can be used as a filter. See below for a description of commands -that can be imbedded in the template file.
+that can be embedded in the template file. NOTE: It is not possible to display usage by just typing msi since executing the command with no arguments i s a valid command. To show usage specify an illegal switch, e.g. @@ -81,7 +84,7 @@ specify an illegal switch, e.g.

Template File Format

-This file contains the text to be read and written to stdout after macro +This file contains the text to be read and written to the output after macro substitution is performed. If no file is given then input is read from stdin. In addition the file can have lines containing include and substitute commands. The format of these commands are: @@ -99,7 +102,7 @@ and template is     include "includeFile"     substitute "first=Irma,family=Kraimer"     include "includeFile" -then the following is written to stdout. +then the following is written to the output.
    first name is Marty
     family name is Kraimer
     first name is Irma
@@ -150,10 +153,13 @@ dbTemplate Format
     pattern format or regular format
 }
-For thedbTemplate format, the command line template argument is optional. +For the template format, the command line template argument is optional. If it specified it is used, otherwise the file template is used. This format is an extension of the format accepted by dbLoadTemplate. It allows templates to be  expanded on the host rather via dbLoadTemplate. +The file name may appear inside double quotation marks; these are only required +if the name contains any environment variable macros of the form ${MOTOR} which +will be expanded before the file is opened.

Regular substitution example

Let the command be: @@ -164,7 +170,7 @@ Let the command be: substitute is
    {first=Marty,family=Kraimer}
     {first=Irma,family=Kraimer}
-The following is written to stdout. +The following is written to the output.
    first name is Marty
     family name is Kraimer
     first name is Irma
@@ -179,7 +185,7 @@ Let the command be:
     {Marty,Kraimer}
     {Irma,Kraimer}
template is the same as in the previous example. -

The following is written to stdout. +

The following is written to the output.

    first name is Marty
     family name is Kraimer
     first name is Irma
@@ -207,7 +213,7 @@ file template {
 }
template is the same as in the previous example.. -

The following is written to stdout +

The following is written to the output

first name is Marty
 family name is Kraimer
@@ -249,7 +255,7 @@ form:
 
        substitute "<substitutions>"
    White space is allowed before and after the command and after the quoted -string. If imbedded quotes are needed the \ character can be used as an +string. If embedded quotes are needed the \ character can be used as an escape character. For example:
        substitute "a=\"val\""
@@ -273,7 +279,7 @@ character of the comment line. is either white space or a comma. White space is any of the following: space, formfeed, newline, carriage return, tab, vertical tab.

Each item within braces can be an alphanumeric token or a quoted string. -The characters \" can be used for imbedded quotes. The rules for non quoted +The characters \" can be used for embedded quotes. The rules for non quoted strings are actually more relaxed but any item that is not an alphanumeric string should be given as a quoted string.

Thus