1 #include <../../nrnconf.h>
4 #include "../utils/profile/profiler_interface.h"
10 int hoc_main1(
int,
const char**,
const char**);
19 #if !defined(__APPLE__)
20 extern char** environ;
22 #include <crt_externs.h>
26 namespace fs = std::filesystem;
30 #include <IV-Win/MWlib.h>
31 void iv_display_scale(
float);
37 #include <InterViews/style.h>
44 #if defined(HAVE_IV) && defined(IVX11_DYNAM)
45 #include <IV-X11/ivx11_dynam.h>
48 #include "utils/logger.hpp"
52 #define PR_PROFILE pr_profile();
59 static PropertyData properties[] = {{
"*gui",
"sgimotif"},
60 {
"*PopupWindow*overlay",
"true"},
61 {
"*PopupWindow*saveUnder",
"on"},
62 {
"*TransientWindow*saveUnder",
"on"},
63 {
"*background",
"#ffffff"},
64 {
"*brush_width",
"0"},
65 {
"*double_buffered",
"on"},
68 {
"*font",
"*Arial*bold*--12*"},
69 {
"*MenuBar*font",
"*Arial*bold*--12*"},
70 {
"*MenuItem*font",
"*Arial*bold*--12*"},
72 {
"*foreground",
"#000000"},
73 {
"*synchronous",
"off"},
74 {
"*malloc_debug",
"on"},
76 {
"*Scene_background",
"#ffffff"},
77 {
"*Scene_foreground",
"#000000"},
78 {
"*FieldEditor*background",
"#ffffff"},
80 {
"*default_brush",
"0"},
81 {
"*view_margin",
".25"},
82 {
"*pwm_dismiss_button",
"Iconify"},
83 {
"*dismiss_button",
"Close"},
84 {
"*use_transient_windows",
"yes"},
85 {
"*nrn_library",
" $(NEURONHOME)/lib"},
86 {
"*view_pick_epsilon",
"2"},
87 {
"*pwm_canvas_height",
"120"},
88 {
"*pwm_paper_height",
"11"},
89 {
"*pwm_paper_width",
"8.5"},
90 {
"*pwm_paper_resolution",
".5"},
91 {
"*pwm_pixel_resolution",
"0"},
92 {
"*window_manager_offset_x",
"5."},
93 {
"*window_manager_offset_y",
"26."},
94 {
"*pwm_print_file_filter",
"*.ps"},
95 {
"*pwm_idraw_file_filter",
"*.id"},
96 {
"*pwm_ascii_file_filter",
"*"},
97 {
"*pwm_save_file_filter",
"*.ses"},
98 {
"*pwm_idraw_prologue",
"$(NEURONHOME)/lib/prologue.id"},
99 {
"*pwm_postscript_filter",
"sed 's;/Adobe-;/;'"},
100 {
"*SlowSlider*autorepeatStart",
"0."},
101 {
"*scene_print_border",
"1"},
102 {
"*radioScale",
".9"},
103 {
"*stepper_size",
"20."},
104 {
"*xvalue_field_size_increase",
"10."},
105 {
"*xvalue_format",
"%.5g"},
106 {
"*graph_axis_default",
"0"},
107 {
"*shape_scale_file",
"$(NEURONHOME)/lib/shape.cm2"},
108 {
"*shape_quadedge",
"0"},
109 {
"*CBWidget_ncolor",
"10"},
110 {
"*CBWidget_nbrush",
"10"},
111 {
"*units_on_flag",
"on"},
114 {
"*Py_NoSiteFlag",
"0"},
116 {
"*nopython",
"off"},
117 {
"*err_dialog",
"off"},
122 static OptionDesc options[] = {{
"-dismissbutton",
"*dismiss_button", OptionValueImplicit,
"Close"},
123 {
"-extrapipeinput",
"*extrapipeinput", OptionValueNext},
124 {
"-dll",
"*nrnmechdll", OptionValueNext},
125 {
"-showwinio",
"*showwinio", OptionValueImplicit,
"on"},
126 {
"-hidewinio",
"*showwinio", OptionValueImplicit,
"off"},
127 {
"-isatty",
"*isatty", OptionValueImplicit,
"1"},
128 {
"-notatty",
"*isatty", OptionValueImplicit,
"-1"},
129 {
"-bbs_nhost",
"*bbs_nhost", OptionValueNext},
130 {
"-NSTACK",
"*NSTACK", OptionValueNext},
131 {
"-NFRAME",
"*NFRAME", OptionValueNext},
132 {
"--version",
"*print_nrn_version", OptionValueImplicit,
"on"},
133 {
"-python",
"*python", OptionValueImplicit,
"on"},
134 {
"-nopython",
"*nopython", OptionValueImplicit,
"on"},
135 {
"-pyexe",
"*pyexe", OptionValueNext},
136 {
"-Py_NoSiteFlag",
"*Py_NoSiteFlag", OptionValueImplicit,
"1"},
137 {
"-nobanner",
"*banner", OptionValueImplicit,
"off"},
139 {
"-mswin_scale",
"*mswin_scale", OptionValueNext},
149 #if (defined(NRNMECH_DLL_STYLE) || defined(WIN32))
152 #if defined(USE_PYTHON)
154 extern int use_python_interpreter;
169 static char* ocsmall_argv[] = {0,
"difus.hoc"};
171 #if defined(WIN32) && HAVE_IV
172 extern HWND hCurrWnd;
178 int hoc_xopen1(
const char* filename,
const char* rcs);
190 #if DARWIN || defined(__linux__)
203 const char* path_prefix_to_libnrniv() {
204 static char* path_prefix_to_libnrniv_ =
NULL;
205 if (!path_prefix_to_libnrniv_) {
210 if (
info.dli_fname) {
212 if (
info.dli_fname[0] ==
'/') {
213 size_t last_slash =
name.rfind(
"/");
214 path_prefix_to_libnrniv_ = strndup(
name.c_str(), last_slash + 1);
215 path_prefix_to_libnrniv_[last_slash + 1] =
'\0';
219 if (!path_prefix_to_libnrniv_) {
220 path_prefix_to_libnrniv_ = strdup(
"");
223 return path_prefix_to_libnrniv_;
227 int ivocmain(
int,
const char**,
const char**);
234 #if NRNMPI_DYNAMICLOAD
235 extern void nrnmpi_stubs();
236 extern std::string nrnmpi_load();
237 void nrnmpi_load_or_exit();
242 #include <sys/stat.h>
243 static bool isdir(
const char*
p) {
245 bool b = stat(
p, &st) == 0 && S_ISDIR(st.st_mode);
253 for (
int i = 0;
i < *pargc; ++
i) {
254 if (strcmp(opt,
argv[
i]) == 0) {
256 for (;
i < *pargc; ++
i) {
267 for (
int i = 0;
i < *pargc - 1; ++
i) {
268 if (strcmp(opt,
argv[
i]) == 0) {
269 const char* a =
argv[
i + 1];
271 for (;
i < *pargc; ++
i) {
292 void nrn_InitializeJavaVM();
298 #if NRNMPI_DYNAMICLOAD
300 auto const pmes = nrnmpi_load();
302 Printf(fmt::format(
"{}\n", pmes).c_str());
362 constexpr
auto nrniv_help = R
"(
363 nrniv [options] [fileargs]
365 -dll filename dynamically load the linked mod files.
366 -h print this help message
367 -help print this help message
368 -isatty unbuffered stdout, print prompt when waiting for stdin
369 -mpi launched by mpirun or mpiexec, in parallel environment
370 -mswin_scale float scales gui on screen
371 -music launched as a process of the MUlti SImulator Coordinator
372 -NSTACK integer size of stack (default 1000)
373 -NFRAME integer depth of function call nesting (default 200)
374 -nobanner do not print startup banner
375 -nogui do not send any gui info to screen
376 -notatty buffered stdout and no prompt
377 -python Python is the interpreter
378 -pyexe path Python to use if python (or python3 fallback) not right.
379 -nopython Do not initialize Python
380 -Py_NoSiteFlag Set Py_NoSiteFlag=1 before initializing Python
381 -realtime For hard real-time simulation for dynamic clamp
382 --version print version info and all InterViews and X11 options
383 fileargs: any number of following
384 - input from stdin til ^D (end of file)
385 -c "statement" execute next statement
386 filename execute contents of filename
400 for (
int i = 0;
i <
argc + 1; ++
i) {
439 for (
int i = 0;
i <
argc; ++
i) {
440 if ((strncmp(
"-p4", (
argv)[
i], 3) == 0) || (strcmp(
"-mpi", (
argv)[
i]) == 0)) {
442 "Warning: detected user attempt to enable MPI, but MPI support was disabled at "
451 #if defined(HAVE_IV) && defined(IVX11_DYNAM)
461 printf(
"Warning: attempt to enable MUSIC but MUSIC support was disabled at build time.\n");
470 const char** our_argv =
argv;
483 #if defined(HAVE_SETENV)
484 setenv(
"NEURONHOME", NEURON_DATA_DIR, 1);
487 #error "I don't know how to set environment variables."
500 #if defined(WIN32) && HAVE_IV
502 "No NEURONHOME environment variable.",
503 "NEURON Incomplete Installation",
508 "Warning: no NEURONHOME environment variable-- setting\
518 our_argv =
new char*[2];
519 our_argv[0] =
"Neuron";
520 our_argv[1] =
":lib:hoc:macload.hoc";
521 session =
new Session(
"NEURON", our_argc, our_argv, options, properties);
525 session =
new Session(
"NEURON", our_argc, (
char**) our_argv, options, properties);
529 if (getenv(
"DISPLAY")) {
530 session =
new Session(
"NEURON", our_argc, (
char**) our_argv, options, properties);
533 "Warning: no DISPLAY environment variable.\
534 \n--No graphics will be displayed.\n");
540 const auto nrn_def_path1 = fs::path(
neuron_home) /
"lib" /
"nrn.defaults";
541 const auto nrn_def_path2 = fs::path(
neuron_home) /
"lib" /
"nrn.def";
542 auto file_exists = [](
const auto& path) noexcept ->
bool {
545 return fs::is_regular_file(path, err);
548 if (file_exists(nrn_def_path1)) {
549 session->style()->load_file(String(nrn_def_path1.string().c_str()), -5);
550 }
else if (file_exists(nrn_def_path2)) {
551 session->style()->load_file(String(nrn_def_path2.string().c_str()), -5);
553 fmt::print(
"Can't load NEURON resources from {}[aults]\n", nrn_def_path1.string());
556 session->style()->load_file(String(nrn_def_path1.string().c_str()), -5);
558 char* h = getenv(
"HOME");
560 const auto nrn_def_path_dot = fs::path(h) /
".nrn.defaults";
561 if (file_exists(nrn_def_path_dot)) {
562 session->style()->load_file(String(nrn_def_path_dot.string().c_str()), -5);
570 session->style()->find_attribute(
"NSTACK",
hoc_nstack);
571 session->style()->find_attribute(
"NFRAME",
hoc_nframe);
573 if (session->style()->value_is_on(
"err_dialog")) {
584 #if defined(USE_PYTHON)
589 if (session->style()->value_is_on(
"nopython")) {
593 if (session->style()->find_attribute(
"pyexe", str)) {
602 if (
const char*
buf =
nrn_optarg(
"-pyexe", &our_argc, our_argv)) {
609 #if defined(WIN32) && HAVE_IV
612 int pw = GetSystemMetrics(SM_CXVIRTUALSCREEN);
614 scale = 1200. / double(pw);
616 session->style()->find_attribute(
"mswin_scale", scale);
617 iv_display_scale(
float(scale));
624 #if (defined(NRNMECH_DLL_STYLE) || defined(WIN32))
628 if (session->style()->find_attribute(
"nrnmechdll", str)) {
655 if (session->style()->find_attribute(
"isatty",
i)) {
671 if (session && session->style()->value_is_on(
"units_on_flag")) {
674 Oc oc(session, our_argv[0],
env);
680 nrn_InitializeJavaVM();
684 ocsmall_argv[0] = our_argv[0];
685 exit_status = oc.
run(2, ocsmall_argv);
688 #if defined(USE_PYTHON)
690 if (session && session->style()->value_is_on(
"python")) {
691 use_python_interpreter = 1;
695 use_python_interpreter = 1;
705 fprintf(stderr,
"Python not available\n");
711 exit_status = oc.
run(our_argc, our_argv);
719 #if defined(USE_PYTHON)
720 if (use_python_interpreter) {
771 #if defined(AUTO_DLOPEN_NRNMECH) && AUTO_DLOPEN_NRNMECH == 0
777 #if NRNMPI_DYNAMICLOAD
779 for (
int i = 1;
i <
argc; ++
i) {
780 if (strcmp(
"-mpi",
argv[
i]) == 0) {
781 nrnmpi_load_or_exit();
786 auto argv_ptr =
const_cast<char***
>(&
argv);
int run(int argc, const char **argv)
static Session * session_
static HandleStdin * handleStdin_
static std::ostream * idraw_stream
DLFCN_EXPORT int dladdr(const void *addr, Dl_info *info)
const char * nrn_mech_dll
int nrn_err_dialog_active_
void setneuronhome(const char *)
int ivocmain_session(int, const char **, const char **, int start_session)
This used to be ivocmain, the main entrypoint to the HOC interpreter.
static int nrn_optargint(const char *opt, int *pargc, const char **argv, int dflt)
int ivocmain(int, const char **, const char **)
Main entrypoint function into the HOC interpeter.
int hoc_obj_run(const char *, Object *)
const char ** nrn_global_argv
int hoc_print_first_instance
int nrn_is_python_extension
static const char * nrn_optarg(const char *opt, int *pargc, const char **argv)
void hoc_main1_init(const char *, const char **)
void hoc_single_event_run()
int hoc_main1(int, const char **, const char **)
double hoc_default_dll_loaded_
std::tuple< int, const char ** > nrn_mpi_setup(int argc, const char **argv)
A top-level initialization of MPI given argc and argv.
int hoc_xopen1(const char *filename, const char *rcs)
static bool nrn_optarg_on(const char *opt, int *pargc, const char **argv)
static void init_profile()
static void finalize_profile()
impl_ptrs methods
Collection of pointers to functions with python-version-specific implementations.
#define nrn_assert(x)
assert()-like macro, independent of NDEBUG status
int nrn_noauto_dlopen_nrnmech
void nrnmpi_init(int nrnmpi_under_nrncontrol, int *pargc, char ***pargv)
int(* interpreter_start)(int)
int Printf(const char *fmt, Args... args)