1 #include <../../nrnconf.h>
3 namespace fs = std::filesystem;
19 int isend(
char*,
char*);
27 #if SYSV || defined(MINGW)
38 if ((cp =
index(
buf,
'!')) != (
char*) 0) {
41 while (cp >=
buf && isspace(*cp)) {
45 for (cp =
buf; *cp !=
'\0' && isspace(*cp); cp++) {
62 if (cp == (
char*) 0) {
64 diag(
s,
"block goes to end of file");
70 q->itemtype = VERBATIM;
76 char *cp, word[256], *wp, test[256];
81 while (*cp ==
' ' || *cp ==
'\t')
84 for (wp = word; isalpha(*cp);) {
88 if (strcmp(test, word) == 0) {
107 for (
i = 0;
i < size; ++
i) {
109 if (
c == EOF ||
c == 26 ||
c == 4) {
125 if (c < 0 || c > 127) {
129 diag(
"Non-Ascii character in file:",
buf);
150 if (
ctp == (
char*) 0 || *
ctp ==
'\0') {
157 if (
ctp == (
char*) 0) {
178 diag(
"internal error in unGetc",
"");
188 while ((
c =
Getc()) != EOF &&
c !=
'\n') {
195 }
else if (
c == EOF) {
198 diag(
"internal error in Gets()",
"");
211 diag(
"internal error in unGets()",
"");
220 "at line %d in file %s:\\n%s",
222 #
if !defined(NRN_AVOID_ABSOLUTE_PATHS)
225 fs::absolute(
finname).filename().c_str(),
240 void diag(
const char* s1,
const char* s2) {
242 Fprintf(stderr,
"Error: %s", s1);
265 static Symbol *symq[20], **symhead = symq, **symtail = symq;
284 if (symhead >= symtail)
288 f = fopen(fname,
"r");
289 if (f == (FILE *) 0) {
290 diag(
"Can't open", fname);
318 return (
prefix[0] !=
'\0');
329 if (fname[0] ==
'/') {
330 return fopen(fname,
"r");
344 fprintf(stderr,
"Couldn't open: %s\n",
buf);
346 f = fopen(fname,
"r");
352 if ((f = fopen(
buf,
"r")) !=
NULL) {
359 fprintf(stderr,
"Couldn't open: %s\n", fname);
362 dirs = getenv(
"MODL_INCLUDE");
367 for (dirs = colon; *dirs; dirs = colon) {
369 for (; *colon; ++colon) {
376 buf2 =
static_cast<char*
>(
emalloc(strlen(dirs) + 2 + strlen(fname)));
380 f = fopen(buf2,
"r");
388 fprintf(stderr,
"Couldn't open: %s\n", buf2);
403 strcpy(fname,
STR(
q) + 1);
404 fname[strlen(fname) - 1] =
'\0';
417 diag(
"Couldn't open ", fname);
419 fprintf(stderr,
"INCLUDEing %s\n", fname);
427 Sprintf(
buf,
":::realpath %s\n", fs::absolute(fname).c_str());
429 }
catch (
const std::filesystem::filesystem_error&) {
char finname[NRN_BUFSIZE]
void diag(const char *s1, const char *s2)
struct FileStackItem FileStackItem
char * Fgets(char *buf, int size, FILE *f)
void include_file(Item *q)
char * stralloc(const char *buf, char *rel)
void replacstr(Item *q, const char *s)
Item * putintoken(const char *s, short type, short toktype)
Item * lappendsym(List *list, Symbol *sym)
Item * lappendstr(List *list, const char *str)
List * newlist()
The following routines support the concept of a list.
static void * emalloc(size_t size)
void SprintfAsrt(char(&buf)[N], const char *fmt, Args &&... args)
assert if the Sprintf format data does not fit into buf
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
void enquextern(Symbol *)
static int getprefix(char *prefix, char *s)
static FILE * include_open(char *fname, int err)
static char inlinebuf[2][NRN_BUFSIZE]
static int file_stack_empty()
int isend(char *, char *)
NMODL parser global flags / functions.
static double remove(void *v)
static struct prefix prefix[]
char finname[NRN_BUFSIZE]
int Fprintf(FILE *stream, const char *fmt, Args... args)