void be_init() /* Main routine for Interpreter back end */ { char *p; EuConsole = (getenv("EUCONS") != NULL && atoi(getenv("EUCONS")) == 1); clocks_per_sec = CLOCKS_PER_SEC; #ifdef CLK_TCK clk_tck = CLK_TCK; #else clk_tck = sysconf(_SC_CLK_TCK); #endif #define TempErrName_len (30) TempErrName = (char *)EMalloc(TempErrName_len); copy_string(TempErrName, "ex.err", TempErrName_len); // can change eudir = getenv("EUDIR"); if (eudir == NULL) { #ifdef EUNIX // should check search PATH for euphoria/bin ? eudir = getenv("HOME"); if (eudir == NULL) { eudir = "euphoria"; } else { int p_size = strlen(eudir) + 12; p = (char *)EMalloc(p_size + 1); snprintf(p, p_size+1, "%s/euphoria", eudir); p[p_size] = 0; // ensure NULL eudir = p; } #else // EUNIX eudir = "\\EUPHORIA"; #endif // EUNIX } #if defined(EUNIX) || defined(EMINGW) copy_string(main_path, file_name[1], PATH_MAX); // FOR NOW! #else (void)_fullpath(main_path, file_name[1], PATH_MAX+1); #endif for (p = main_path+strlen(main_path)-1; *p != '\\' && *p != '/' && p >= main_path; p--) ; *(p+1) = '\0'; /* keep the path, truncate off the final name */ InitExecute(); InitDebug(); InitTraceWindow(); }
static int e_path_open(char *name, int mode) /* follow the search path, if necessary to open the main file */ { int src_file, fn; char *path; char *full_name; char *p; file_name[1] = name; src_file = long_open(name, mode); if (src_file > -1) { return src_file; } /* first make sure that name is a simple name without '\' in it */ for (p = name; *p != 0; p++) { if (*p == '\\' || *p == '/') // should add ':' too - but doesn't matter return -1; } path = getenv("PATH"); if (path == NULL) return -1; full_name = EMalloc(PATH_MAX+1); fn = 0; for (p = path; ; p++) { if (*p == ' ' || *p == '\t') continue; else if (*p == PATH_SEPARATOR || *p == '\0') { /* end of a directory */ if (fn > 0) { full_name[fn++] = SLASH; strcpy(full_name + fn, name); src_file = long_open(full_name, mode); if (src_file > -1) { file_name[1] = full_name; return src_file; } else { fn = 0; } } if (*p == '\0') break; } else { full_name[fn++] = *p; } } return -1; }
symtab_ptr tmp_alloc() /* return pointer to space for a temporary var/literal constant */ { return (symtab_ptr)EMalloc(sizeof(struct temp_entry)); }