1 #include <../../nrnconf.h>
17 #include "utils/logger.hpp"
24 extern double chkarg(
int,
double low,
double high);
32 if (sym && sym->
extra) {
53 for (cp =
buf; *cp; ++cp) {
64 if (sym && *cp ==
'\0') {
67 }
else if (sym && sym->
type == TEMPLATE && *cp !=
'\0') {
92 "Cannot find the symbol associated with the pointer when called from Python.",
93 "Use a string instead of pointer argument");
119 return (
double)
limits[0];
120 }
else if (val >
limits[1]) {
121 return (
double)
limits[1];
156 *
units =
const_cast<char*
>(
"on");
158 *
units =
const_cast<char*
>(
"off");
171 "Cannot find the symbol associated with the pointer when called from Python.",
172 "Use a string instead of pointer argument");
181 if (*
units == (
char*) 0) {
182 *
units =
const_cast<char*
>(
"");
194 extern void hoc_forward2back();
251 char *pf, *format, errbuf[100];
253 int n = 0, iarg,
i, islong, convert, sawnum;
265 for (
i = 0;
i < 20; ++
i) {
266 arglist[
i] =
nullptr;
271 for (pf = format; *pf; ++pf) {
285 if (convert && iarg >= 19) {
288 while (isdigit(*pf)) {
311 arg[iarg].type =
'l';
312 arglist[iarg] = (
void*) &arg[iarg].u.l;
314 arg[iarg].type =
'i';
315 arglist[iarg] = (
void*) &arg[iarg].u.i;
322 arg[iarg].type =
'd';
323 arglist[iarg] = (
void*) &arg[iarg].u.d;
325 arg[iarg].type =
'f';
326 arglist[iarg] = (
void*) &arg[iarg].u.f;
338 if (!((
i == 1) || ((
i == 2) && (pf[-1] ==
'^')))) {
349 arg[iarg].type =
's';
350 arg[iarg].u.s =
static_cast<char*
>(
emalloc(strlen(
buf) + 1));
351 arglist[iarg] = (
void*) arg[iarg].u.s;
354 if (islong || sawnum) {
357 arg[iarg].type =
'c';
358 arglist[iarg] = (
void*) &arg[iarg].u.c;
366 if (!
ifarg(iarg + 2)) {
369 switch (arg[iarg - 1].
type) {
372 Sprintf(errbuf,
"arg %d must be a string", iarg + 2);
378 Sprintf(errbuf,
"arg %d must be a pointer to a number", iarg + 2);
388 n = sscanf(
buf, format, arglist[0], arglist[1], arglist[2]);
389 }
else if (iarg < 13) {
409 for (
i = 0;
i <
n; ++
i) {
410 switch (arg[
i].
type) {
433 Sprintf(errbuf,
"incomplete format specifier for arg %d", iarg + 3);
436 Sprintf(errbuf,
"unknown conversion specifier for arg %d", iarg + 3);
439 Sprintf(errbuf,
"missing arg %d", iarg + 2);
444 Sprintf(errbuf,
"too many ( > %d) args", iarg + 2);
447 for (
i = 0;
i < iarg; ++
i) {
448 if (arg[
i].
type ==
's') {
460 static char stdoutfile[] =
"/systmp.tmp";
467 n = strlen(
gargstr(1)) + strlen(stdoutfile);
469 std::snprintf(st->
buf, st->
size + 1,
"%s > %s",
gargstr(1), stdoutfile);
470 d = (double) system(st->
buf);
472 if ((
fp = fopen(stdoutfile,
"r")) == (FILE*) 0) {
473 hoc_execerror(
"Internal error in System(): can't open", stdoutfile);
475 while (fgets(st->
buf, 255,
fp) == st->
buf) {
480 IGNORE(unlink(stdoutfile));
481 }
else if (
ifarg(2)) {
495 i += strlen(line->
buf);
502 d = (double) pclose(
fp);
506 d = (double) system(
gargstr(1));
525 }
type_sym[] = {{
"Builtins", BLTIN},
526 {
"Other Builtins", FUN_BLTIN},
528 {
"Procedures", PROCEDURE},
529 {
"Undefined", UNDEF},
537 Printf(
"\n\nSymbol list %s\n\n",
s);
554 Printf(
"ARRAY USERDOUBLE");
626 double chkarg(
int arg,
double low,
double high)
631 if (val > high || val < low) {
632 hoc_execerror(
"Arg out of range in user function", (
char*) 0);
659 if (strlen(str) > BUFSIZ - 20) {
662 std::snprintf(
s->buf,
s->size + 1,
"hoc_ac_ = %s\n", str);
691 if (strlen(str) > BUFSIZ - 10) {
694 std::snprintf(
s->buf,
s->size + 1,
"{%s}\n", str);
716 constexpr std::string_view
prefix{
"{hoc_pointer_(&"},
suffix{
")}\n"};
751 x = (
s->type == OBJECTVAR) ? 2 : x;
752 x = (
s->type == SECTION) ? 3 : x;
753 x = (
s->type ==
STRING) ? 4 : x;
754 x = (
s->type == VAR) ? 5 : x;
755 if (x == 5 && arg2 == 2) {
756 x = (
s->arayinfo) ? 6 : x;
757 x = (
s->subtype ==
USERINT) ? 7 : x;
void setneuronhome(const char *)
float * hoc_sym_domain(Symbol *sym)
Symlist * hoc_top_level_symlist
void hoc_Symbol_limits(void)
neuron::container::data_handle< double > hoc_varhandle
Executing hoc_pointer(&var) will put the address of the variable in this location.
static void symdebug(const char *s, Symlist *list)
void hoc_symbol_tolerance(Symbol *sym, double tol)
Symbol * hoc_table_lookup(const char *, Symlist *)
void hoc_neuronhome(void)
char * neuronhome_forward(void)
Symbol * hoc_name2sym(const char *name)
char * hoc_back2forward(char *)
void hoc_name_declared(void)
static int hoc_vsscanf(const char *buf)
Symlist * hoc_built_in_symlist
static struct @38 type_sym[]
void hoc_Symbol_units(void)
char ** hoc_pgargstr(int)
Symbol * hoc_get_last_pointer_symbol()
static HocParmLimits limits[]
void hoc_plprint(const char *)
void hoc_run_stmt(Symbol *sym)
void sym_extra_alloc(Symbol *)
void hoc_pushstr(char **d)
HocSymExtension * hoc_var_extra(const char *name)
double chkarg(int, double low, double high)
neuron::container::data_handle< double > hoc_val_handle(std::string_view s)
double hoc_xred(const char *, double, double, double)
double check_domain_limits(float *limits, double val)
Symbol * hoc_install(const char *, int, double, Symlist **)
int hoc_is_str_arg(int narg)
void hoc_assign_str(char **cpp, const char *buf)
double * hoc_val_pointer(const char *s)
Symbol * hoc_parse_expr(const char *str, Symlist **psymlist)
int hoc_oc(const char *buf)
double hoc_run_expr(Symbol *sym)
char * hoc_symbol_units(Symbol *sym, const char *units)
int hoc_is_double_arg(int narg)
char ** hoc_temp_charptr(void)
int hoc_xopen_run(Symbol *sp, const char *str)
void hoc_symbol_limits(Symbol *sym, float low, float high)
double * hoc_pgetarg(int narg)
Symbol * hoc_lookup(const char *)
int hoc_is_pdouble_arg(int narg)
Symbol * hoc_parse_stmt(const char *str, Symlist **psymlist)
char * fgets_unlimited(HocStr *s, NrnFILEWrap *f)
HocStr * hocstr_create(size_t size)
void hocstr_resize(HocStr *hs, size_t n)
void hocstr_delete(HocStr *hs)
bool is_array(const Symbol &sym)
void hoc_execerror(const char *s1, const char *s2)
static void * emalloc(size_t size)
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
#define nrn_fw_delete(fw)
int const size_t const size_t n
int Printf(const char *fmt, Args... args)