1 #include <../../nmodlconf.h> 71 extern int mkdir_p(
const char*);
73 #if NMODL && VECTORIZE 77 extern int usederivstatearray;
86 {
"version", no_argument, 0,
'v'},
87 {
"help", no_argument, 0,
'h'},
88 {
"outdir", required_argument, 0,
'o'},
93 fprintf(stderr,
"Source to source compiler from NMODL to C\n");
94 fprintf(stderr,
"Usage: %s [options] Inputfile\n", argv[0]);
96 fprintf(stderr,
"\t-o | --outdir <OUTPUT_DIRECTORY> directory where output files will be written\n");
97 fprintf(stderr,
"\t-h | --help print this message\n");
98 fprintf(stderr,
"\t-v | --version print version number\n");
101 static void openfiles(
char* given_filename,
char* output_dir);
105 int option_index = 0;
106 char* output_dir =
NULL;
113 while ( (option = getopt_long (argc, argv,
":vho:",
long_options, &option_index)) != -1) {
120 output_dir = strdup(optarg);
128 fprintf(stderr,
"%s: option '-%c' requires an argument\n", argv[0], optopt);
133 fprintf(stderr,
"%s: invalid option `-%c' \n", argv[0], optopt);
137 if ((argc - optind) > 1) {
138 fprintf(stderr,
"%s: Warning several input files specified on command line but only one will be processed\n", argv[0]);
144 SIOUXSettings.asktosaveonclose =
false;
186 #if 0 && !_CRAY && NMODL && VECTORIZE 208 #if !defined NMODL_TEXT 211 #if NMODL && NMODL_TEXT 215 FILE* f =
fopen(
"temp.txt",
"w");
228 #if HAVE_REALPATH && !defined(NRN_AVOID_ABSOLUTE_PATHS) 231 fprintf(
fcout,
"\n#if NMODL_TEXT\nstatic const char* nmodl_filename = \"%s\";\nstatic const char* nmodl_file_text = \n", pf ? pf :
finname);
232 if (pf) { free(pf); }
238 for (cp = s; *cp; ++cp) {
239 if (*cp ==
'"' || *cp ==
'\\' ) {
254 #if NMODL && VECTORIZE 256 Fprintf(stderr,
"Thread Safe\n");
258 if (usederivstatearray) {
259 fprintf(stderr,
"Derivatives of STATE array variables are not translated correctly and compile time errors will be generated.\n");
260 fprintf(stderr,
"The %s.c file may be manually edited to fix these errors.\n",
modprefix);
266 extern int yytchar, yylineno;
278 SIOUXSettings.autocloseonquit =
true;
284 static void openfiles(
char* given_filename,
char* output_dir) {
293 char* first_ext_char = strrchr(
modprefix,
'.');
294 if (strrchr(
modprefix,
'/') > first_ext_char) {
295 first_ext_char =
NULL;
298 Sprintf(input_filename,
"%s", given_filename);
300 if(first_ext_char) *first_ext_char =
'\0';
301 if ((
fin =
fopen(input_filename,
"r")) == (FILE *) 0) {
302 Sprintf(input_filename,
"%s.mod", given_filename);
304 if ((
fin =
fopen(input_filename,
"r")) == (FILE *) 0) {
305 diag(
"Can't open input file: ", input_filename);
310 fprintf(stderr,
"Can't create output directory %s\n", output_dir);
315 Sprintf(output_filename,
"%s%s.c", output_dir, basename);
323 if ((
fcout =
fopen(output_filename,
"w")) == (FILE *) 0) {
324 diag(
"Can't create C file: ", output_filename);
326 Fprintf(stderr,
"Translating %s into %s\n", input_filename, output_filename);
332 diag(
"Can't create variable file: ", s);
337 if ((fctlout =
fopen(s,
"w")) == (FILE *) 0) {
338 diag(
"Can't create variable file: ", s);
341 if ((fnumout =
fopen(s,
"w")) == (FILE *) 0) {
342 diag(
"Can't create C file: ", s);
347 static std::string
str_replace(std::string str,
const std::string& search_str,
const std::string& replace_str)
349 if (search_str.empty()) {
354 while ( (pos = str.find(search_str)) != std::string::npos ) {
355 str.replace(pos, search_str.size(), replace_str);
364 const std::string repl =
str_replace(q,
"u.template",
"u.ctemplate");
static void openfiles(char *given_filename, char *output_dir)
#define ITERATE(itm, lst)
fprintf(stderr, "Don't know the location of params at %p\, pp)
int mkdir_p(const char *)
NMODL parser global flags / functions.
static std::string str_replace(std::string str, const std::string &search_str, const std::string &replace_str)
void verbatim_adjust(char *q)
static void show_options(char **argv)
static struct option long_options[]
int main(int argc, char **argv)