1 #include <../../nrnconf.h> 3 #include "../nrnpython/nrnpython_config.h" 22 #include "../nrniv/backtrace_utils.h" 32 #if defined(USE_PYTHON) 33 int use_python_interpreter = 0;
41 #define use_rl_getc_function 44 #if carbon || defined(MINGW) 49 #if HAVE_FEENABLEEXCEPT 50 #define NRN_FLOAT_EXCEPTION 1 52 #define NRN_FLOAT_EXCEPTION 0 55 #if NRN_FLOAT_EXCEPTION 56 #if !defined(__USE_GNU) 60 #define FEEXCEPT (FE_DIVBYZERO | FE_INVALID | FE_OVERFLOW ) 61 static void matherr1(
void) {
63 switch(fegetexcept()) {
65 fprintf(stderr,
"Floating exception: Divide by zero\n");
68 fprintf(stderr,
"Floating exception: Invalid (no well defined result\n");
71 fprintf(stderr,
"Floating exception: Overflow\n");
84 #if NRN_FLOAT_EXCEPTION 86 result = fedisableexcept(FEEXCEPT);
88 result = feenableexcept(FEEXCEPT);
99 static unsigned long usec[30];
100 static unsigned long oldusec[30];
101 static struct timeval tp;
103 gettimeofday(&tp, 0);
104 oldusec[
i] = tp.tv_usec;
107 gettimeofday(&tp, 0);
108 if (tp.tv_usec > oldusec[i]) {
109 usec[
i] += tp.tv_usec - oldusec[
i];
114 for (i=0; i < 30; ++
i) {
116 printf(
"sec[%d]=%g\n", i, ((
double)usec[i])/1000000.);
140 extern char *
readline(
const char *prompt);
158 #define CHAR signed char 162 #define TMPBUFSIZE 512 176 #define EPS hoc_epsilon 188 #include <execinfo.h> 205 #if defined(WIN32) || MAC 214 static int follow(
int expect,
int ifyes,
int ifno);
221 printf(
"NEURON exiting abnormally, press return to quit\n");
229 int hoc_retreat_flag;
230 #define RETREAT_SIGNAL SIGHUP 235 if (hoc_retreat_flag++) {
239 if (!
lookup(
"linda_retreat")) {
240 hoc_retreat_flag = 0;
245 IGNORE(signal(RETREAT_SIGNAL, retreat_handler));
248 void hoc_retreat(
void) {
255 #if defined(WIN32) || defined(MAC) 256 #define HAS_SIGPIPE 0 258 #define HAS_SIGPIPE 1 263 fprintf(stderr,
"writing to a broken pipe\n");
273 while ((c=
Getc(
fin)) ==
' ' || c ==
'\t') {
283 #define YYNEEDMORE -3 288 static int lexstate = 0;
297 char*
s = buf + strlen(buf);
299 while (isdigit(c =
Getc(
fin)) && (s - buf) < 200) {
307 acterror(buf,
" not literal name[int]");
332 if (
c ==
'/' &&
follow(
'*', 1, 0))
339 acterror(
"comment not complete",
" in cbuf");
344 if (
c ==
'.' || isdigit(
c))
360 if (*npt ==
'.' && !isdigit(npt[1])) {
364 if (
c ==
'E' ||
c ==
'e') {
365 if (isdigit(
c =
Getc(
fin)) ||
c ==
'+' ||
c ==
'-') {
373 IGNORE(sscanf(npt,
"%lf", &d));
379 if (isalpha(
c) ||
c ==
'_')
382 char sbuf[256], *
p = sbuf;
385 if (p >= (sbuf + 255)) {
390 }
while ((
c=
Getc(
fin)) != EOF && (isalnum(
c) ||
c ==
'_'));
393 if (strncmp(sbuf,
"__nrnsec_0x", 11) == 0) {
395 return INTERNALSECTIONNAME;
405 if (strcmp(sbuf,
"_pysec") == 0) {
407 hoc_acterror(
"Must be of form _pysec.secname where secname is the literal result of nrn.Section.name() .",
NULL);
419 hoc_acterror(
"Must be of form _pysec.cellname.secname where cellname.secname is the literal result of nrn.Section.name() .",
NULL);
429 if ((s=
lookup(sbuf)) == 0)
432 return s->
type == UNDEF ? VAR : s->
type;
438 if (retval == ARG) retval =
follow(
's', STRINGARG, ARG);
439 if (retval == ARG) retval =
follow(
'&', ARGREF, ARG);
446 n = 10 * n +
c -
'0';
449 acterror(
"strange $...", (
char *)0);
464 if (n >= sbuf->
size - 1)
481 case '>':
return follow(
'=', GE, GT);
482 case '<':
return follow(
'=', LE, LT);
488 {
if (
follow(
'=', 1, 0)) {
497 if (
follow(
'=', EQ,
'=') == EQ) {
506 case '|':
return follow(
'|',
OR,
'|');
510 i =
follow(
'\n', 1000,
'\\');
516 case '\r':
return follow(
'\n',
'\n',
'\n');
517 case '\n':
return '\n';
518 case '/':
if (
follow(
'/', 1, 0)) {
523 }
else if (
follow(
'=', 1, 0)) {
534 static char transtab[] =
"b\bf\fn\nr\rt\t";
538 if (islower(c) && strchr(transtab, c))
539 return strchr(transtab, c)[1];
543 static int follow(
int expect,
int ifyes,
int ifno)
557 #if defined(__TURBOC__) 562 #if defined(__TURBOC__) 574 Fprintf(stderr,
"Not enough space for array %s\n", sp->
name);
578 #if defined(__TURBOC__) 584 double total, subscpt;
599 total = total*subscpt;
641 if (a->
a_varn != (
unsigned *) 0)
642 free((
char *)(a->
a_varn));
651 acterror(s,
"used outside definition");
700 #if defined(__GO32__) 703 hoc_outtext(
"Error:");
719 (*oc_jump_target_)();
730 #if defined(WIN32) && !defined(CYGWIN) 772 const size_t nframes = 12;
773 void *frames[nframes];
775 char** bt_strings =
NULL;
777 size_t funcname_size = 256;
779 char* symbol =
static_cast<char*
>(malloc(
sizeof(
char)*funcname_size));
781 char* funcname =
static_cast<char*
>(malloc(
sizeof(
char)*funcname_size));
783 char* offset =
static_cast<char*
>(malloc(
sizeof(
char)*10));
787 size = backtrace(frames, nframes);
790 Fprintf(stderr,
"Backtrace:\n");
792 bt_strings = backtrace_symbols(frames, size);
796 for(i = 2; i < size; ++
i) {
800 status =
cxx_demangle(symbol, &funcname, &funcname_size);
802 Fprintf(stderr,
"\t%s : %s+%s\n",
803 bt_strings[i], funcname, offset);
805 Fprintf(stderr,
"\t%s : %s()+%s\n",
806 bt_strings[i], symbol, offset);
809 Fprintf(stderr,
"\t%s\n", bt_strings[i]);
818 Fprintf(stderr,
"No backtrace info available.\n");
829 #if NRN_FLOAT_EXCEPTION 832 Fprintf(stderr,
"Floating point exception\n");
838 execerror(
"Floating point exception.", (
char *) 0);
844 Fprintf(stderr,
"Segmentation violation\n");
857 Fprintf(stderr,
"Bus error\n");
863 execerror(
"Aborting. ",
"See $NEURONHOME/lib/help/oc.help");
913 Fprintf(stderr,
"OC INTERPRETER %s %s\n",
916 "Copyright 1992 - Michael Hines, Neurobiology Dept., DUMC, Durham, NC. 27710\n");
928 #if defined(__GO32__) 938 hs->
buf =
static_cast<char*
>(
emalloc(size + 1));
963 strcpy(hs->
buf, buf);
982 init_parallel(&argc,argv);
989 signal(RETREAT_SIGNAL, retreat_handler);
1009 if ( argc > 2 && strcmp(argv[1],
"-bbs_nhost") == 0) {
1014 if (argc > 1 && argv[1][0] !=
'-') {
1036 static const char *stdinonly[] = {
"-" };
1038 static char *stdinonly[1];
1039 stdinonly[0] =
static_cast<char *
>(
emalloc(2*
sizeof(
char)));
1040 strcpy(stdinonly[0],
"-");
1060 #include <sys/select.h> 1061 static pthread_t* inputReady_;
1062 static pthread_mutex_t inputMutex_;
1063 static pthread_cond_t inputCond_;
1064 static int inputReadyFlag_;
1066 void* inputReadyThread(
void*
input) {
1073 FD_SET(fileno(stdin), &readfds);
1075 i = select(1, &readfds, 0, 0, 0);
1076 pthread_testcancel();
1077 if (FD_ISSET(fileno(stdin), &readfds)) {
1080 printf(
"Discarding input til Dialog is closed.\n");
1081 read(fileno(stdin), &c, 1);
1085 pthread_mutex_lock(&inputMutex_);
1086 pthread_cond_wait(&inputCond_, &inputMutex_);
1087 pthread_mutex_unlock(&inputMutex_);
1089 printf(
"inputReadyThread done\n");
1094 static pthread_t* inputReady_;
1095 static pthread_mutex_t inputMutex_;
1096 static pthread_cond_t inputCond_;
1097 static int inputReadyFlag_;
1098 static int inputReadyVal_;
1099 extern "C" int getch();
1101 void* inputReadyThread(
void*
input) {
1106 pthread_testcancel();
1111 printf(
"Discarding input til Dialog is closed.\n");
1112 read(fileno(stdin), &c, 1);
1119 pthread_mutex_lock(&inputMutex_);
1120 inputReadyFlag_ = 1;
1123 pthread_cond_wait(&inputCond_, &inputMutex_);
1124 pthread_mutex_unlock(&inputMutex_);
1126 printf(
"inputReadyThread done\n");
1132 #if defined(USE_PYTHON) 1143 if (winio_exists()) {
1148 #if READLINE && (!defined(WIN32) || defined(CYGWIN)) && !defined(MAC) 1155 buf =
static_cast<char*
>(malloc(strlen(
neuron_home) + 30));
1166 if (0 && inputReady_) {
1167 pthread_cancel(*inputReady_);
1168 pthread_kill(*inputReady_, SIGHUP);
1169 pthread_join(*inputReady_, 0);
1174 #if defined(USE_PYTHON) 1181 (*p_nrnpython_finalize)();
1188 static const char* double_at2space(
const char*
infile) {
1193 for (cp1 = infile; *cp1; ++cp1) {
1194 if (*cp1 ==
'@' && cp1[1] ==
'@') {
1202 buf =
static_cast<char *
>(
emalloc(strlen(infile) + 1));
1203 for (cp1=infile, cp2=buf; *cp1; ++cp1, ++cp2) {
1204 if (*cp1 ==
'@' && cp1[1] ==
'@') {
1225 if (!winio_exists()) {
1231 if (
gargc == 0 && cygonce == 0) {
1239 #if defined(USE_PYTHON) 1240 return use_python_interpreter ? 0 : 1;
1251 #if defined(USE_PYTHON) 1252 return use_python_interpreter ? 0 : 1;
1270 char* cp = strdup(
infile + 1);
1271 for (++cp; *cp; ++cp) {
1288 #if defined(USE_PYTHON) 1289 if (use_python_interpreter) {
1299 if (strcmp(
infile,
"-") == 0) {
1303 }
else if (strcmp(
infile,
"-parallel") == 0) {
1308 }
else if (strcmp(
infile,
"-c") == 0) {
1313 #if defined (CYGWIN) 1333 (*p_nrnpy_pyrun)(
infile);
1372 signals[0] = signal(SIGINT,
onintr);
1373 signals[1] = signal(SIGFPE,
fpecatch);
1375 signals[2] = signal(SIGSEGV, sigsegvcatch);
1378 signals[3] = signal(SIGBUS, sigbuscatch);
1383 signals[0] = signal(SIGINT, signals[0]);
1384 signals[1] = signal(SIGFPE, signals[1]);
1386 signals[2] = signal(SIGSEGV, signals[2]);
1389 signals[3] = signal(SIGBUS, signals[3]);
1400 if (setjmp(
begin)) {
1410 #if defined(WIN32) && !defined(CYGWIN) 1419 #if defined(WIN32) && !defined(CYGWIN) 1463 while (*nrn_inputbufptr) {
1464 *cp++ = *nrn_inputbufptr++;
1465 if (cp[-1] ==
'\n') {
1470 if (cp[-1] !=
'\n') {
1485 nrn_inputbufptr = i1;
1501 nrn_inputbufptr =
buf;
1513 nrn_inputbufptr = sav_inputbufptr;
1523 while (*
ctp || *nrn_inputbufptr) {
1537 nrn_inputbufptr = sav_inputbufptr;
1563 for (cp =
cbuf; cp < (
cbuf +
n); ++cp) {
1564 if (!isprint((
int)(*cp)) && !isspace((
int)(*cp))) {
1565 Fprintf(stderr,
"%scharacter \\%03o at position %ld is not printable\n",
id, ((
int)(*cp) & 0xff), cp-
cbuf);
1571 for (cp =
cbuf; cp !=
ctp; cp++) {
1605 if (c != EOF && c &&
ctp !=
cbuf) {
1637 if (hoc_in_yyparse) {
1651 }
while (i ==
'\n');
1655 #if defined(__GO32__) 1656 #define INTERVIEWS 1 1659 #define INTERVIEWS 1 1662 #define INTERVIEWS 1 1676 extern int (*rl_event_hook)(
void);
1677 static int event_hook(
void) {
1679 inputReady_ = (pthread_t*)
emalloc(
sizeof(pthread_t));
1680 pthread_mutex_init(&inputMutex_, 0);
1681 pthread_cond_init(&inputCond_, 0);
1682 pthread_create(inputReady_, 0, inputReadyThread, 0);
1684 pthread_mutex_unlock(&inputMutex_);
1688 pthread_mutex_lock(&inputMutex_);
1689 pthread_cond_signal(&inputCond_);
1694 extern int (*rl_getc_function)(
void);
1695 static int getc_hook(
void) {
1699 inputReady_ = (pthread_t*)
emalloc(
sizeof(pthread_t));
1700 pthread_mutex_init(&inputMutex_, 0);
1701 pthread_cond_init(&inputCond_, 0);
1702 pthread_create(inputReady_, 0, inputReadyThread, 0);
1704 pthread_mutex_unlock(&inputMutex_);
1707 while(!inputReadyFlag_) {
1711 inputReadyFlag_ = 0;
1713 pthread_mutex_lock(&inputMutex_);
1714 pthread_cond_signal(&inputCond_);
1720 #if defined(use_rl_getc_function) 1723 extern int iv_dialog_is_running;
1724 extern int (*rl_getc_function)(
void);
1725 static int getc_hook(
void) {
1733 if ((r =
read(0, &c,
sizeof(c))) ==
sizeof(c)) {
1746 if (
errno != EINTR) {
1755 extern int (*rl_event_hook)(
void);
1756 static int event_hook(
void) {
1790 if (nltrans) { nl1 = 26; nl2 = 4;}
else{nl1 = nl2 = EOF;}
1793 if (c == EOF || c == nl1 || c == nl2) {
1809 if (bufstr->
size <= i) {
1814 bufstr->
buf[i+1] =
'\0';
1825 hoc_execerror(
"Internal error:",
"Not finished with previous input line");
1842 if (
nrn_fw_wrap(
fin, stdin) && hoc_interviews && !hoc_in_yyparse) {
1845 extern CHAR* hoc_console_buffer;
1846 hoc_console_buffer =
cbuf;
1871 hoc_execerror(
"Internal error:",
"Not finished with previous input line");
1893 if (hoc_interviews && !hoc_in_yyparse) {
1894 rl_getc_function = getc_hook;
1897 rl_getc_function =
NULL;
1901 #if defined(use_rl_getc_function) 1902 if (hoc_interviews && !hoc_in_yyparse) {
1903 rl_getc_function = getc_hook;
1906 rl_getc_function =
NULL;
1909 if (hoc_interviews && !hoc_in_yyparse) {
1910 rl_event_hook = event_hook;
1913 rl_event_hook =
NULL;
1919 extern int hoc_notify_stop;
1922 #if defined(__GO32__) 1926 for (
int i=0; i <
n; ++
i) {
1927 if (!isascii(line[i])) {
1928 hoc_execerr_ext(
"Non-ASCII character value 0x%hhx at input position %d\n", (
unsigned)line[i], i);
1931 if (n >= hoc_cbufstr->
size - 3) {
1938 if (line && *line) {
1951 if (
nrn_fw_eq(
fin, stdin) && hoc_interviews && !hoc_in_yyparse) {
1981 if (hoc_interviews) {
1987 hoc_warning(
"Help only available from version with ivoc library", 0);
1993 #if defined(__GO32__) 1995 if (_go32_was_ctrl_break_hit()) {
int cxx_demangle(char *symbol, char **funcname, size_t *funcname_sz)
int nrn_mpiabort_on_error_
RETSIGTYPE onintr(int sig)
void hoc_oop_initaftererror(void)
struct Arrayinfo Arrayinfo
void * erealloc(void *ptr, size_t n)
void hoc_main1_init(const char *pname, const char **envp)
static void nrn_inputbuf_getline(void)
void save_parallel_envp(void)
void nrnmpi_abort(int errcode)
int hoc_ParseExec(int yystart)
#define nrn_fw_set_stdin()
int nrnmpi_numprocs_world
void hocstr_delete(HocStr *hs)
void oc_save_input_info(const char **i1, int *i2, int *i3, NrnFILEWrap **i4)
static void restore_signals(void)
const char * hoc_promptstr
size_t hoc_total_array(Symbol *s)
#define nrn_fw_eq(fw, ff)
static RETSIGTYPE sigpipe_handler(int sig)
void hoc_newobj1_err()
unref partially constructed objects controlled by current longjump handle
int(* p_nrnpy_pyrun)(const char *fname)
void hoc_free_val_array(double *, size_t)
RETSIGTYPE fpecatch(int sig)
sprintf(buf," if (secondorder) {\ " int _i;\" " for(_i=0;_i< %d;++_i) {\" " _p[_slist%d[_i]]+=dt *_p[_dlist%d[_i]];\" " }}\", numeqn, listnum, listnum)
int system(const char *s)
void ivoc_help(const char *)
int hoc_print_first_instance
static int control_jmpbuf
int hoc_execerror_messages
void hoc_execerror(const char *s, const char *t)
int hoc_strgets_need(void)
static void set_signals(void)
void hoc_execerr_ext(const char *fmt,...)
printf style specification of hoc_execerror message.
void(* p_nrnpython_finalize)()
int const size_t const size_t n
char * hoc_strgets(char *cbuf, int nc)
int(* p_nrnpython_start)(int)
int hoc_arayinfo_install(Symbol *sp, int nsub)
void hocstr_resize(HocStr *hs, size_t n)
HocStr * hocstr_create(size_t size)
void hoc_warning(const char *, const char *)
int hoc_errno_check(void)
int hoc_oc(const char *buf)
int read(int, void *, unsigned int)
static const char * fname(const char *name)
void * hoc_pysec_name2ptr(const char *s, int eflag)
static int backslash(int c)
int hoc_readcheckpoint(char *)
void rl_deprep_terminal(void)
void hoc_execerror_mes(const char *s, const char *t, int prnt)
void hoc_final_exit(void)
fprintf(stderr, "Don't know the location of params at %p\, pp)
char * fgets_unlimited(HocStr *s, NrnFILEWrap *f)
void free_arrayinfo(Arrayinfo *a)
CHAR * hoc_fgets_unlimited(HocStr *bufstr, NrnFILEWrap *f)
static void prnt(const TQItem *b, int level)
char * emalloc(unsigned n)
void add_history(const char *)
static jmp_buf hoc_oc_begin
void hoc_menu_cleanup(void)
static CHAR * fgets_unlimited_nltrans(HocStr *s, NrnFILEWrap *f, int nltrans)
static const char * nrn_inputbufptr
size_t hoc_xopen_file_size_
void * hoc_sec_internal_name2ptr(const char *s, int eflag)
void hocstr_copy(HocStr *hs, const char *buf)
static void hoc_run1(void)
static int follow(int expect, int ifyes, int ifno)
void warning(const char *s, const char *t)
static void unGetc(int c, NrnFILEWrap *fp)
void hoc_coredump_on_error(void)
void hoc_audit_from_hoc_main1(int argc, const char **argv, const char **envp)
void(* oc_jump_target_)()
int hoc_obj_run(const char *, Object *)
#define NOT_PARALLEL_SUB(c1)
static SignalType signals[4]
static int debug_message_
void hoc_audit_from_final_exit(void)
void hoc_show_errmess_always(void)
static char line[MAXLINE]
RETSIGTYPE(* SignalType)(int)
void hoc_set_unhandled_exception_filter()
void hoc_freearay(Symbol *sp)
#define input(prompt, fmt, var)
void nrn_err_dialog(const char *mes)
static const char ** pname(void *v)
void * nrn_get_hoc_jmp()
If one of the two jmp_buf is controlling the longjmp hoc_newobj1_err needs handle to know how much to...
void hoc_audit_command(const char *buf)
static int Getc(NrnFILEWrap *fp)
void * nrn_parsing_pysec_
static char * optarray(char *buf)
void nrn_feenableexcept()
void * hoc_Ecalloc(size_t nmemb, size_t size)
char * readline(const char *prompt)
double chkarg(int, double low, double high)
void hoc_acterror(const char *, const char *)
int hoc_main1(int argc, const char **argv, const char **envp)
void oc_restore_input_info(const char *i1, int i2, int i3, NrnFILEWrap *i4)
void defnonly(const char *s)
void hoc_check_intupt(int intupt)
#define nrn_fw_ungetc(c, fw)
void start_profile(int i)
int parse_bt_symbol(char *backtrace_line, void **addr, char *symbol, char *offset)
void save_parallel_argv(int, const char **)