1 #include <../../nmodlconf.h>
70 extern int mkdir_p(
const char*);
72 #if NMODL && VECTORIZE
76 extern int usederivstatearray;
84 static struct option
long_options[] = {{
"version", no_argument, 0,
'v'},
85 {
"help", no_argument, 0,
'h'},
86 {
"outdir", required_argument, 0,
'o'},
90 fprintf(stderr,
"Source to source compiler from NMODL to C\n");
91 fprintf(stderr,
"Usage: %s [options] Inputfile\n",
argv[0]);
94 "\t-o | --outdir <OUTPUT_DIRECTORY> directory where output files will be written\n");
95 fprintf(stderr,
"\t-h | --help print this message\n");
96 fprintf(stderr,
"\t-v | --version print version number\n");
99 static void openfiles(
char* given_filename,
char* output_dir);
103 int option_index = 0;
104 char* output_dir =
NULL;
118 output_dir = strdup(optarg);
126 fprintf(stderr,
"%s: option '-%c' requires an argument\n",
argv[0], optopt);
131 fprintf(stderr,
"%s: invalid option `-%c' \n",
argv[0], optopt);
135 if ((
argc - optind) > 1) {
137 "%s: Warning several input files specified on command line but only one will be "
145 SIOUXSettings.asktosaveonclose =
false;
185 #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)
232 "\n#if NMODL_TEXT\nstatic const char* nmodl_filename = \"%s\";\nstatic const char* "
233 "nmodl_file_text = \n",
243 for (cp = s; *cp; ++cp) {
244 if (*cp ==
'"' || *cp ==
'\\') {
259 #if NMODL && VECTORIZE
261 Fprintf(stderr,
"Thread Safe\n");
263 if (usederivstatearray) {
265 "Derivatives of STATE array variables are not translated correctly and compile "
266 "time errors will be generated.\n");
267 fprintf(stderr,
"The %s.c file may be manually edited to fix these errors.\n",
modprefix);
273 extern int yytchar, yylineno;
285 SIOUXSettings.autocloseonquit =
true;
291 static void openfiles(
char* given_filename,
char* output_dir) {
300 char* first_ext_char = strrchr(
modprefix,
'.');
301 if (strrchr(
modprefix,
'/') > first_ext_char) {
302 first_ext_char =
NULL;
305 Sprintf(input_filename,
"%s", given_filename);
308 *first_ext_char =
'\0';
310 if ((
fin =
fopen(input_filename,
"r")) == (FILE*) 0) {
311 Sprintf(input_filename,
"%s.mod", given_filename);
315 if ((
fin =
fopen(input_filename,
"r")) == (FILE*) 0) {
316 diag(
"Can't open input file: ", input_filename);
320 if (
mkdir_p(output_dir) != 0) {
321 fprintf(stderr,
"Can't create output directory %s\n", output_dir);
324 char* basename = strrchr(
modprefix,
'/');
326 Sprintf(output_filename,
"%s%s.c", output_dir, basename);
334 if ((
fcout =
fopen(output_filename,
"w")) == (FILE*) 0) {
335 diag(
"Can't create C file: ", output_filename);
337 Fprintf(stderr,
"Translating %s into %s\n", input_filename, output_filename);
343 diag(
"Can't create variable file: ", s);
348 if ((fctlout =
fopen(s,
"w")) == (FILE*) 0) {
349 diag(
"Can't create variable file: ", s);
352 if ((fnumout =
fopen(s,
"w")) == (FILE*) 0) {
353 diag(
"Can't create C file: ", s);
359 const std::string& search_str,
360 const std::string& replace_str) {
361 if (search_str.empty()) {
366 while ((pos = str.find(search_str)) != std::string::npos) {
367 str.replace(pos, search_str.size(), replace_str);
376 const std::string repl =
str_replace(
q,
"u.template",
"u.ctemplate");
void verbatim_adjust(char *q)
#define ITERATE(itm, lst)
static void show_options(char **argv)
int main(int argc, char **argv)
int mkdir_p(const char *)
static std::string str_replace(std::string str, const std::string &search_str, const std::string &replace_str)
static void openfiles(char *given_filename, char *output_dir)
static struct option long_options[]
NMODL parser global flags / functions.