1 #include <../../nrnconf.h>
32 df =
fopen(
"debugfile",
"w");
35 vfprintf(df,
format, args);
56 if (dup2(fileno(f1), 1) < 0) {
60 }
else if (
prev > -1) {
61 if (dup2(
prev, 1) < 0) {
68 pushx((
double) fileno(stdout));
132 for (cp1 = s, cp2 = hs->
buf +
begin; *cp1; ++cp1) {
133 if (*cp1 ==
'$' && cp1[1] ==
'(') {
137 for (cp3 =
buf; *cp1 && *cp1 !=
')'; ++cp1) {
143 if (strcmp(
buf,
"NEURONHOME") == 0) {
164 #if MAC && !defined(DARWIN)
166 for (cp1 = hs->
buf +
begin; *cp1; ++cp1) {
174 if (!strchr(s,
':') && !strchr(s,
'$')) {
182 for (cp1 = hs->
buf +
begin, cp2 = cp1; *cp1;) {
183 if (cp1[0] ==
':' && cp1[1] ==
'.') {
187 }
else if (cp1[2] ==
'.' && cp1[3] ==
':') {
211 int savpipflag, save_lineno;
217 if (rcs[0] !=
'\0') {
218 int sz = 2 * (strlen(rcs) + strlen(
name)) + 20;
239 while (errno == EINTR) {
319 d = (int) strlen(
buf);
344 if (fscanf(fi,
"%255s", fs) == EOF) {
347 if (fs[0] ==
'i' || fs[0] ==
'n' || fs[0] ==
'I' || fs[0] ==
'N') {
350 if (sscanf(fs,
"%lf", &d) == 1) {
352 if (fscanf(fi,
"\n")) {
369 if (fs[0] ==
'i' || fs[0] ==
'n' || fs[0] ==
'I' || fs[0] ==
'N') {
372 if (sscanf(fs,
"%lf", &d) == 1) {
409 word = (int)
chkarg(2, 0., 1.);
429 char *pbuf, *pfmt, *pfrag, frag[120];
430 int n, convflag, lflag, didit;
437 convflag = lflag = didit = 0;
443 for (pfmt = fmt; *pfmt; pfmt++) {
458 pfrag[0] = pfrag[-1];
503 }
else if (*pfmt ==
'%') {
505 }
else if (pfrag - frag > 100) {
538 #if defined(__TURBOC__) || defined(__GO32__) || defined(WIN32) || defined(MAC)
542 assert(strlen(cmd) + 20 < 1024);
544 if (system(
buf) != 0) {
546 }
else if ((
fp =
fopen(
"hocload.tmp",
"r")) == (FILE*) 0) {
554 unlink(
"hocload.tmp");
557 #define oc_popen popen
558 #define oc_pclose pclose
575 if (!sym || sym->
type == UNDEF) {
576 assert(strlen(stype) + strlen(s) + 50 < 1024);
577 sprintf(cmd,
"$NEURONHOME/lib/hocload.sh %s %s %d", stype, s,
hoc_pid());
580 f = fgets(file, 1024,
p);
582 f[strlen(f) - 1] =
'\0';
586 fprintf(stderr,
"Getting %s from %s\n", s, f);
589 fprintf(stderr,
"Couldn't find a file that declares %s\n", s);
618 i = (int)
chkarg(iarg, 0., 1.);
639 #define hoc_load_file_size_ 1024
676 if ((base = strrchr(
name,
'/')) !=
NULL) {
678 path[base -
name] =
'\0';
681 f = nrn_fw_readaccess(
name);
690 f = nrn_fw_readaccess(base);
692 f =
fopen(base,
"r");
697 hlp =
getenv(
"HOC_LIBRARY_PATH");
698 while (hlp && *hlp) {
699 char* cp = strchr(hlp,
':');
701 cp = strchr(hlp,
' ');
704 cp = hlp + strlen(hlp);
707 strncpy(path, hlp, cp - hlp);
708 path[cp - hlp] =
'\0';
732 sprintf(path,
"$(NEURONHOME)/lib/hoc");
748 #if USE_NRNFILEWRAP == 0
759 goback = (getcwd(old, 1000) != 0);
762 hoc_warning(
"Couldn't change directory to:", path);
774 "hoc_ac_ = execute1(\"{xopen(\\\"%s\\\")}\")\n",
780 if (path[0] && goback) {
782 hoc_warning(
"Couldn't change directory back to:", old);
798 hoc_execerror(
"getcwd failed. Perhaps the path length is > hoc_load_file_size_", (
char*) 0);
805 if (
buf[len - 1] !=
':') {
810 if (
buf[len - 1] !=
'/') {
820 #if !defined(__GO32__) && !defined(WIN32) && !defined(MAC)
825 gethostname(
buf, 20);
866 size = vfprintf(stream, fmt, ap);
873 #if defined(__GNUC__) || defined(__clang__)
874 #define va_copy(dest, src) __builtin_va_copy(dest, src)
876 #define va_copy(dest, src) (dest = src)
880 size = vsnprintf(
p, size, fmt, apc);
887 p =
static_cast<char*
>(malloc(size));
891 size = vsnprintf(
p, size, fmt, ap);
898 if (stream == stderr) {
899 for (
int i = 0;
p[
i] !=
'\0'; ++
i) {
900 if (!isascii((
unsigned char)
p[
i])) {
906 (*nrnpy_pr_stdoe_callback)((stream == stderr) ? 2 : 1,
p);
921 int Fprintf(FILE* stream,
const char* fmt, ...) {
937 size = vsnprintf(
NULL, 0, fmt, ap);
941 constexpr
size_t maxsize = 512;
944 size = vsnprintf(s, maxsize, fmt, ap);
sprintf(buf, " if (secondorder) {\n" " int _i;\n" " for (_i = 0; _i < %d; ++_i) {\n" " _p[_slist%d[_i]] += dt*_p[_dlist%d[_i]];\n" " }}\n", numeqn, listnum, listnum)
double chkarg(int, double low, double high)
static int vnrnpy_pr_stdoe(FILE *stream, const char *fmt, va_list ap)
void hoc_load_template(void)
static void hoc_load(const char *stype)
static int(* nrnpy_pass_callback)()
#define va_copy(dest, src)
double hoc_fw_scan(NrnFILEWrap *fi)
static int(* nrnpy_pr_stdoe_callback)(int, char *)
int nrn_is_python_extension
static int hoc_Load_file(int, const char *)
size_t hoc_xopen_file_size_
void hoc_machine_name(void)
char * hoc_back2forward(char *)
void nrnpy_set_pr_etal(int(*cbpr_stdoe)(int, char *), int(*cbpass)())
char * hoc_current_xopen(void)
#define hoc_load_file_size_
void hoc_execerror(const char *, const char *)
int hoc_xopen1(const char *name, const char *rcs)
int hoc_is_object_arg(int narg)
void hoc_xopen_from_audit(const char *fname)
void hoc_pushstr(char **d)
void hoc_execerr_ext(const char *fmt,...)
printf style specification of hoc_execerror message.
void hoc_audit_from_xopen1(const char *fname, const char *rcs)
void hoc_assign_str(char **cpp, const char *buf)
const char * expand_env_var(const char *s)
int hoc_oc(const char *buf)
void hoc_warning(const char *, const char *)
int hoc_is_double_arg(int narg)
int nrnpy_pr(const char *fmt,...)
int hoc_xopen_run(Symbol *sp, const char *str)
int hoc_chdir(const char *path)
int hoc_retrieving_audit(void)
char * hoc_object_name(Object *ob)
void hoc_sprint1(char **ppbuf, int argn)
Symbol * hoc_lookup(const char *)
int Fprintf(FILE *stream, const char *fmt,...)
double hoc_scan(FILE *fi)
char ** hoc_pgargstr(int narg)
char * fgets_unlimited(HocStr *s, NrnFILEWrap *f)
HocStr * hocstr_create(size_t size)
void hocstr_resize(HocStr *hs, size_t n)
void * erealloc(void *ptr, size_t n)
#define NOT_PARALLEL_SUB(c1)
hoc_Item * hoc_l_lappendstr(hoc_List *, const char *)
hoc_List * hoc_l_newlist()
Object ** hoc_objgetarg(int)
void debugfile(const char *,...)
char * getenv(const char *s)
#define ITERATE(itm, lst)
char * emalloc(unsigned n)
#define nrn_fw_eq(fw, ff)
#define nrn_fw_set_stdin()
int const size_t const size_t n
static const char * fname(const char *name)