This is Unofficial EPICS BASE Doxygen Site
msi.cpp File Reference
#include <string>
#include <list>
#include <stdlib.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <errno.h>
#include <dbDefs.h>
#include <macLib.h>
#include <errlog.h>
#include <epicsString.h>
#include <osiFileName.h>
#include <osiUnistd.h>
+ Include dependency graph for msi.cpp:

Go to the source code of this file.

Classes

struct  inputFile
 
struct  inputData
 
struct  subFile
 
struct  subInfo
 

Macros

#define MAX_BUFFER_SIZE   4096
 
#define MAX_DEPS   1024
 
#define ENTER
 
#define STEP(s)
 
#define STEPS(s, v)
 
#define STEPD(s, v)
 
#define EXIT
 
#define EXITD(r)
 
#define EXITS(r)
 

Typedefs

typedef struct inputData inputData
 
typedef struct subInfo subInfo
 
typedef struct inputFile inputFile
 
typedef struct subFile subFile
 

Enumerations

enum  cmdType { cmdInclude, cmdSubstitute }
 
enum  tokenType {
  tokenLBrace, tokenRBrace, tokenSeparator, tokenString,
  tokenEOF
}
 

Functions

int main (int argc, char **argv)
 

Macro Definition Documentation

#define ENTER

Definition at line 45 of file msi.cpp.

#define EXIT

Definition at line 51 of file msi.cpp.

#define EXITD (   r)

Definition at line 52 of file msi.cpp.

#define EXITS (   r)

Definition at line 53 of file msi.cpp.

#define MAX_BUFFER_SIZE   4096

Definition at line 29 of file msi.cpp.

#define MAX_DEPS   1024

Definition at line 30 of file msi.cpp.

#define STEP (   s)

Definition at line 47 of file msi.cpp.

#define STEPD (   s,
 
)

Definition at line 49 of file msi.cpp.

#define STEPS (   s,
 
)

Definition at line 48 of file msi.cpp.

Typedef Documentation

typedef struct inputData inputData

Definition at line 58 of file msi.cpp.

typedef struct inputFile inputFile
typedef struct subFile subFile
typedef struct subInfo subInfo

Definition at line 69 of file msi.cpp.

Enumeration Type Documentation

enum cmdType
Enumerator
cmdInclude 
cmdSubstitute 

Definition at line 273 of file msi.cpp.

enum tokenType
Enumerator
tokenLBrace 
tokenRBrace 
tokenSeparator 
tokenString 
tokenEOF 

Definition at line 596 of file msi.cpp.

Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 95 of file msi.cpp.

96 {
97  inputData *inputPvt;
98  MAC_HANDLE *macPvt;
99  char *pval;
100  std::string substitutionName;
101  char *templateName = 0;
102  bool localScope = true;
103 
104  inputConstruct(&inputPvt);
105  macCreateHandle(&macPvt, 0);
106  while ((argc > 1) && (argv[1][0] == '-')) {
107  int narg = (strlen(argv[1]) == 2) ? 2 : 1;
108  pval = (narg == 1) ? (argv[1] + 2) : argv[2];
109 
110  if (strncmp(argv[1], "-I", 2) == 0) {
111  inputAddPath(inputPvt, pval);
112  }
113  else if (strcmp(argv[1], "-D") == 0) {
114  opt_D = true;
115  narg = 1; /* no argument for this option */
116  }
117  else if(strncmp(argv[1], "-o", 2) == 0) {
118  outFile = epicsStrDup(pval);
119  }
120  else if(strncmp(argv[1], "-M", 2) == 0) {
121  addMacroReplacements(macPvt, pval);
122  }
123  else if(strncmp(argv[1], "-S", 2) == 0) {
124  substitutionName = pval;
125  }
126  else if (strcmp(argv[1], "-V") == 0) {
127  opt_V = 1;
128  narg = 1; /* no argument for this option */
129  }
130  else if (strcmp(argv[1], "-g") == 0) {
131  localScope = false;
132  narg = 1; /* no argument for this option */
133  }
134  else if (strcmp(argv[1], "-h") == 0) {
135  usageExit(0);
136  }
137  else {
138  fprintf(stderr, "msi: Bad argument \"%s\"\n", argv[1]);
139  usageExit(1);
140  }
141 
142  argc -= narg;
143  for (int i = 1; i < argc; i++)
144  argv[i] = argv[i + narg];
145  }
146 
147  if (!opt_V)
148  macSuppressWarning(macPvt, 1);
149 
150  if (argc > 2) {
151  fprintf(stderr, "msi: Too many arguments\n");
152  usageExit(1);
153  }
154 
155  if (opt_D) {
156  if (!outFile) {
157  fprintf(stderr, "msi: Option -D requires -o for Makefile target\n");
158  exit(1);
159  }
160  printf("%s:", outFile);
161  }
162  else if (outFile && freopen(outFile, "w", stdout) == NULL) {
163  fprintf(stderr, "msi: Can't open %s for writing: %s\n",
164  outFile, strerror(errno));
165  exit(1);
166  }
167 
168  if (argc == 2)
169  templateName = epicsStrDup(argv[1]);
170 
171  if (substitutionName.empty()) {
172  STEP("Single template+substitutions file");
173  makeSubstitutions(inputPvt, macPvt, templateName);
174  }
175  else {
176  subInfo *substitutePvt;
177  char *filename = 0;
178  bool isGlobal, isFile;
179 
180  STEPS("Substitutions from file", substitutionName.c_str());
181  substituteOpen(&substitutePvt, substitutionName);
182  do {
183  isGlobal = substituteGetGlobalSet(substitutePvt);
184  if (isGlobal) {
185  STEP("Handling global macros");
186  const char *macStr = substituteGetGlobalReplacements(substitutePvt);
187  if (macStr)
188  addMacroReplacements(macPvt, macStr);
189  }
190  else if ((isFile = substituteGetNextSet(substitutePvt, &filename))) {
191  if (templateName)
192  filename = templateName;
193  if (!filename) {
194  fprintf(stderr, "msi: No template file\n");
195  usageExit(1);
196  }
197 
198  STEPS("Handling template file", filename);
199  const char *macStr;
200  while ((macStr = substituteGetReplacements(substitutePvt))) {
201  if (localScope)
202  macPushScope(macPvt);
203 
204  addMacroReplacements(macPvt, macStr);
205  makeSubstitutions(inputPvt, macPvt, filename);
206 
207  if (localScope)
208  macPopScope(macPvt);
209  }
210  }
211  } while (isGlobal || isFile);
212  substituteDestruct(substitutePvt);
213  }
214  macDeleteHandle(macPvt);
215  errlogFlush(); // macLib calls errlogPrintf()
216  inputDestruct(inputPvt);
217  if (opt_D) {
218  printf("\n");
219  }
220  fflush(stdout);
221  free(templateName);
222  return opt_V & 2;
223 }
#define STEPS(s, v)
Definition: msi.cpp:48
void errlogFlush(void)
Definition: errlog.c:529
int i
Definition: scan.c:967
#define printf
Definition: epicsStdio.h:41
#define NULL
Definition: catime.c:38
#define STEP(s)
Definition: msi.cpp:47
Macro substitution context, for use by macLib routines only.
Definition: macLib.h:42
void epicsStdCall macSuppressWarning(MAC_HANDLE *handle, int suppress)
Disable or enable warning messages.
Definition: macCore.c:154
#define stdout
Definition: epicsStdio.h:30
Definition: msi.cpp:610
char * epicsStrDup(const char *s)
Definition: epicsString.c:233
long epicsStdCall macDeleteHandle(MAC_HANDLE *handle)
Marks a handle invalid, and frees all storage associated with it.
Definition: macCore.c:360
long epicsStdCall macPopScope(MAC_HANDLE *handle)
Retrieve the last pushed scope (like stack operations)
Definition: macCore.c:427
long epicsStdCall macCreateHandle(MAC_HANDLE **pHandle, const char *pairs[])
Creates a new macro substitution context.
Definition: macCore.c:100
#define stderr
Definition: epicsStdio.h:32
long epicsStdCall macPushScope(MAC_HANDLE *handle)
Marks the start of a new scoping level.
Definition: macCore.c:392