1 #include <../../nrnconf.h>
31 #include <CLI/CLI.hpp>
40 namespace fs = std::filesystem;
68 static void openfiles(
const char* given_filename,
const char* output_dir);
71 std::string output_dir{};
72 std::string inputfile{};
74 CLI::App app{
"Source to source compiler from NMODL to C++"};
75 app.add_option(
"-o,--outdir", output_dir,
"directory where output files will be written");
76 app.set_version_flag(
"-v,--version",
nmodl_version_,
"print version number");
77 app.set_help_flag(
"-h,--help",
"print this message");
78 app.add_option(
"Inputfile", inputfile)->required();
83 if (!app.remaining().empty()) {
85 "%s: Warning several input files specified on command line but only one will be "
95 std::strcpy(
finname, inputfile.c_str());
97 output_dir.empty() ?
nullptr : output_dir.c_str());
130 #if !defined NMODL_TEXT
137 FILE* f = fopen(
"temp.txt",
"w");
151 "\n#if NMODL_TEXT\nstatic void register_nmodl_text_and_filename(int mech_type) {\n");
152 #if !defined(NRN_AVOID_ABSOLUTE_PATHS)
153 fprintf(
fcout,
" const char* nmodl_filename = \"%s\";\n", fs::absolute(
finname).c_str());
156 " const char* nmodl_filename = \"%s\";\n",
157 fs::path(
finname).filename().c_str());
159 fprintf(
fcout,
" const char* nmodl_file_text = \n");
163 fprintf(
fcout,
" \"");
165 for (cp =
s; *cp; ++cp) {
166 if (*cp ==
'"' || *cp ==
'\\') {
167 fprintf(
fcout,
"\\");
170 fprintf(
fcout,
"\\n\"");
175 fprintf(
fcout,
" ;\n");
176 fprintf(
fcout,
" hoc_reg_nmodl_filename(mech_type, nmodl_filename);\n");
177 fprintf(
fcout,
" hoc_reg_nmodl_text(mech_type, nmodl_file_text);\n");
178 fprintf(
fcout,
"}\n");
179 fprintf(
fcout,
"#endif\n");
186 Fprintf(stderr,
"Thread Safe\n");
190 "Derivatives of STATE array variables are not translated correctly and compile "
191 "time errors will be generated.\n");
192 fprintf(stderr,
"The %s.cpp file may be manually edited to fix these errors.\n",
modprefix);
197 extern int yytchar, yylineno;
211 static void openfiles(
const char* given_filename,
const char* output_dir) {
218 char* first_ext_char = strrchr(
modprefix,
'.');
219 if (strrchr(
modprefix,
'/') > first_ext_char) {
220 first_ext_char =
NULL;
223 Sprintf(input_filename,
"%s", given_filename);
226 *first_ext_char =
'\0';
228 if ((
fin = fopen(input_filename,
"r")) == (FILE*) 0) {
229 Sprintf(input_filename,
"%s.mod", given_filename);
233 if ((
fin = fopen(input_filename,
"r")) == (FILE*) 0) {
234 diag(
"Can't open input file: ", input_filename);
239 fs::create_directories(output_dir);
241 fprintf(stderr,
"Can't create output directory %s\n", output_dir);
244 char* basename = strrchr(
modprefix,
'/');
246 Sprintf(output_filename,
"%s%s.cpp", output_dir, basename);
254 if ((
fcout = fopen(output_filename,
"w")) == (FILE*) 0) {
255 diag(
"Can't create C file: ", output_filename);
257 Fprintf(stderr,
"Translating %s into %s\n", input_filename, output_filename);
void verbatim_adjust(char *q)
char finname[NRN_BUFSIZE]
#define ITERATE(itm, lst)
int main(int argc, char **argv)
const char * nmodl_version_
static void openfiles(const char *given_filename, const char *output_dir)
List * newlist()
The following routines support the concept of a list.
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
void check_useion_variables()
NMODL parser global flags / functions.
int Fprintf(FILE *stream, const char *fmt, Args... args)