static UI_CALLBACK(change_working_directory) { char *wd; int len; len = ioutil_maxpathlen(); wd = lib_malloc(len); ioutil_getcwd(wd, len); vsync_suspend_speed_eval(); #ifdef USE_GNOMEUI if (ui_change_dir(_("VICE setting"), _("Change current working directory"), wd, len) == UI_BUTTON_OK) { if (ioutil_chdir(wd) < 0) ui_error(_("Directory not found")); } #else if (ui_input_string(_("VICE setting"), _("Change current working directory"), wd, len) == UI_BUTTON_OK) { if (ioutil_chdir(wd) < 0) ui_error(_("Directory not found")); } #endif lib_free(wd); }
static UI_CALLBACK(dump_keymap) { char *wd; int len; len = ioutil_maxpathlen(); wd = lib_malloc(len); ioutil_getcwd(wd, len); if (uilib_input_file(_("VICE setting"), _("Write to Keymap File:"), wd, len) == UI_BUTTON_OK) { if (keyboard_keymap_dump(wd) < 0) { ui_error(strerror(errno)); } } lib_free(wd); }
static UI_CALLBACK(events_select_dir) { char *wd; unsigned int i, is_dir; int len; len = ioutil_maxpathlen(); wd = lib_malloc(len); ioutil_getcwd(wd, len); vsync_suspend_speed_eval(); if (ui_input_string(_("VICE setting"), _("Select history directory"), wd, len) == UI_BUTTON_OK) { ioutil_stat(wd, &i, &is_dir); if (!is_dir) ui_error(_("Directory not found")); else resources_set_string("EventSnapshotDir", wd); } lib_free(wd); }
char *findpath(const char *cmd, const char *syspath, int mode) { char *pd = NULL; char *c, *buf; size_t maxpathlen; maxpathlen = (size_t)ioutil_maxpathlen(); buf = lib_malloc(maxpathlen); buf[0] = '\0'; /* this will (and needs to) stay '\0' */ if (strchr(cmd, FSDEV_DIR_SEP_CHR)) { size_t l; int state; const char *ps; if (archdep_path_is_relative(cmd)) { if (ioutil_getcwd(buf + 1, (int)maxpathlen - 128) == NULL) goto fail; l = strlen(buf + 1); } else { l = 0; } if (l + strlen(cmd) >= maxpathlen - 5) goto fail; ps = cmd; pd = buf + l; /* buf + 1 + l - 1 */ #if !defined (__MSDOS__) && !defined (WIN32) && !defined (__OS2__) if (*pd++ != '/') *pd++ = '/'; #else pd++; #endif state = 1; /* delete extra `/./', '/../' and '//':s from the path */ while (*ps) { switch (state) { case 0: if (*ps == '/') state = 1; else state = 0; break; case 1: if (*ps == '.') { state = 2; break; } if (*ps == '/') pd--; else state = 0; break; case 2: if (*ps == '/') { state = 1; pd -= 2; break; } if (*ps == '.') state = 3; else state = 0; break; case 3: if (*ps != '/') { state = 0; break; } state = 1; pd -= 4; while (*pd != '/' && *pd != '\0') pd--; if (*pd == '\0') pd++; state = 1; break; } *pd++ = *ps++; } *pd = '\0'; pd = buf + 1; } else { const char *path = syspath; const char *s; size_t cl = strlen(cmd) + 1; for (s = path; s; path = s + 1) { char * p; int l; s = strchr(path, ARCHDEP_FINDPATH_SEPARATOR_CHAR); l = s ? (int)(s - path) : (int)strlen(path); if (l + cl > maxpathlen - 5) continue; memcpy(buf + 1, path, l); p = buf + l; /* buf + 1 + l - 1 */ if (*p++ != '/') *p++ = '/'; memcpy(p, cmd, cl); for (c = buf + 1; *c != '\0'; c++) #if defined (__MSDOS__) || defined (WIN32) || defined (__OS2__) if (*c == '/') *c = '\\'; #else if (*c == '\\') *c ='/'; #endif if (ioutil_access(buf + 1, mode) == 0) { pd = p /* + cl*/ ; break; } } } if (pd) { char *tmpbuf; #if 0 do pd--; while (*pd != '/'); /* there is at least one '/' */ if (*(pd - 1) == '\0') pd++; *pd = '\0'; #endif tmpbuf = lib_stralloc(buf + 1); lib_free(buf); return tmpbuf; } fail: lib_free(buf); return NULL; }