char* dfsch_get_interpreter_home(){ HKEY hKey; DWORD size = 1024; char buf[1025]; LONG res; char* dfsch_home = NULL; dfsch_home = getenv("DFSCH_HOME"); if (!dfsch_home){ if (RegOpenKeyEx(HKEY_CURRENT_USER, "SOFTWARE\\dfsch\\" PACKAGE_VERSION, 0, KEY_READ, &hKey) == ERROR_SUCCESS){ if (RegQueryValueEx(hKey, "HomeDirectory", NULL, NULL, buf, &size) == ERROR_SUCCESS){ buf[size] = '\0'; dfsch_home = dfsch_stracpy(buf); } RegCloseKey(hKey); } } if (!dfsch_home){ if (RegOpenKeyEx(HKEY_LOCAL_MACHINE, "SOFTWARE\\dfsch\\" PACKAGE_VERSION, 0, KEY_READ, &hKey) == ERROR_SUCCESS){ if (RegQueryValueEx(hKey, "HomeDirectory", NULL, NULL, buf, &size) == ERROR_SUCCESS){ buf[size] = '\0'; dfsch_home = dfsch_stracpy(buf); } RegCloseKey(hKey); } } #ifdef DLL_EXPORT if (!dfsch_home){ dfsch_home = get_home_from_module_filename(); } #endif return dfsch_home; }
char* dfsch_tcl_eval(Tcl_Interp* interp, char* string){ if (Tcl_Eval(interp, string) == TCL_ERROR){ dfsch__thread_info_t* ti = dfsch__get_thread_info(); if (ti->throw_tag){ dfsch__continue_unwind(ti); } dfsch_tcl_error(interp); } return dfsch_stracpy(Tcl_GetStringResult(interp)); }
char* dfsch_realpath(char* path){ #ifdef __WIN32__ if (*path == '\\' || *path == '/' || (path[0] != '\0' && path[1]==':')){ return path; } else { return dfsch_saprintf("%s\\%s", dfsch_getcwd(), path); } #else char* rp = realpath(path, NULL); char* res = dfsch_stracpy(rp); free(rp); return res; #endif }
static char* get_home_from_module_filename(){ char* buf; char tmpbuf[1025]; DWORD len = GetModuleFileName(hDfschInterpreter, tmpbuf, 1025); size_t i; if (!len){ return NULL; } if (len > 1024){ buf = GC_MALLOC_ATOMIC(len+1); if (!GetModuleFileName(hDfschInterpreter, buf, len+1)){ return NULL; } } else { buf = dfsch_stracpy(tmpbuf); } i = strlen(buf); while (i && buf[i] != '\\' && buf[i] != '/'){ i--; } buf[i] = '\0'; while (i && buf[i] != '\\' && buf[i] != '/'){ i--; } buf[i] = '\0'; return buf; }