/* sorry for complexity (cm->done_list), but need it to remove empty dirs */ void cache_maintain_home (CacheType type, gint clear) { CMData *cm; GList *dlist = NULL; gchar *base; const gchar *msg; if (type == CACHE_THUMBS) base = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_THUMBS, NULL); else base = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_COMMENTS, NULL); if (!path_list (base, NULL, &dlist)) { g_free (base); return; } dlist = g_list_append (dlist, base); cm = g_new0 (CMData, 1); cm->list = dlist; cm->done_list = NULL; cm->clear = clear; cm->type = type; if (clear) { if (type == CACHE_THUMBS) msg = _("Clearing thumbnails..."); else msg = _("Clearing comments..."); } else { if (type == CACHE_THUMBS) msg = _("Purging old thumbnails..."); else msg = _("Purging old comments..."); } if (type == CACHE_THUMBS) cm->gd = generic_dialog_new (_("Purge thumbnails"), msg, "PornView", "purge_thumbnails", TRUE, cb_cache_maintain_home_cancel, cm); else cm->gd = generic_dialog_new (_("Purge comments"), msg, "PornView", "purge_comments", TRUE, cb_cache_maintain_home_cancel, cm); gtk_window_set_position (GTK_WINDOW (cm->gd->dialog), GTK_WIN_POS_CENTER); gtk_widget_set_usize (cm->gd->dialog, PURGE_DIALOG_WIDTH, -1); cm->entry = gtk_entry_new (); gtk_widget_set_sensitive (cm->entry, FALSE); gtk_box_pack_start (GTK_BOX (cm->gd->vbox), cm->entry, FALSE, FALSE, 5); gtk_widget_show (cm->entry); gtk_widget_show (cm->gd->dialog); cm->idle_id = gtk_idle_add (cb_cache_maintain_home, cm); }
gchar * cache_get_location (CacheType type, const gchar * source, gint include_name, const gchar * ext, mode_t * mode) { gchar *path = NULL; gchar *base; gchar *name = NULL; if (!source) return NULL; base = remove_level_from_path (source); if (include_name) { name = g_strconcat ("/", filename_from_path (source), NULL); } else { ext = NULL; } if (type == CACHE_THUMBS) { if (conf.enable_thumb_dirs && access (base, W_OK) == 0) { path = g_strconcat (base, "/", PORNVIEW_CACHE_DIR, name, ext, NULL); if (mode) *mode = 0775; } if (!path) { path = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_THUMBS, base, name, ext, NULL); if (mode) *mode = 0755; } } else { path = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_COMMENTS, base, name, ext, NULL); if (mode) *mode = 0755; } g_free (base); if (name) g_free (name); return path; }
static void quick_home_xy() { // Pretend the current position is 0,0 current_position[X_AXIS] = current_position[Y_AXIS] = 0.0; sync_plan_position(); const int x_axis_home_dir = #if ENABLED(DUAL_X_CARRIAGE) x_home_dir(active_extruder) #else home_dir(X_AXIS) #endif ; const float mlx = max_length(X_AXIS), mly = max_length(Y_AXIS), mlratio = mlx > mly ? mly / mlx : mlx / mly, fr_mm_s = MIN(homing_feedrate(X_AXIS), homing_feedrate(Y_AXIS)) * SQRT(sq(mlratio) + 1.0); #if ENABLED(SENSORLESS_HOMING) sensorless_t stealth_states { false, false, false, false, false, false, false }; stealth_states.x = tmc_enable_stallguard(stepperX); stealth_states.y = tmc_enable_stallguard(stepperY); #if AXIS_HAS_STALLGUARD(X2) stealth_states.x2 = tmc_enable_stallguard(stepperX2); #endif #if AXIS_HAS_STALLGUARD(Y2) stealth_states.y2 = tmc_enable_stallguard(stepperY2); #endif #endif do_blocking_move_to_xy(1.5 * mlx * x_axis_home_dir, 1.5 * mly * home_dir(Y_AXIS), fr_mm_s); endstops.validate_homing_move(); current_position[X_AXIS] = current_position[Y_AXIS] = 0.0; #if ENABLED(SENSORLESS_HOMING) tmc_disable_stallguard(stepperX, stealth_states.x); tmc_disable_stallguard(stepperY, stealth_states.y); #if AXIS_HAS_STALLGUARD(X2) tmc_disable_stallguard(stepperX2, stealth_states.x2); #endif #if AXIS_HAS_STALLGUARD(Y2) tmc_disable_stallguard(stepperY2, stealth_states.y2); #endif #endif }
PluginRegistry::PluginRegistry () : m_impl (new Impl) { visual_log (VISUAL_LOG_DEBUG, "Initializing plugin registry"); // Add the standard plugin paths add_path (VISUAL_PLUGIN_PATH "/actor"); add_path (VISUAL_PLUGIN_PATH "/input"); add_path (VISUAL_PLUGIN_PATH "/morph"); add_path (VISUAL_PLUGIN_PATH "/transform"); #if !defined(VISUAL_OS_WIN32) || defined(VISUAL_WITH_CYGWIN) // Add homedirectory plugin paths char const* home_env = std::getenv ("HOME"); if (home_env) { std::string home_dir (home_env); add_path (home_dir + "/.libvisual/actor"); add_path (home_dir + "/.libvisual/input"); add_path (home_dir + "/.libvisual/morph"); add_path (home_dir + "/.libvisual/transform"); } #endif }
std::string check_create_state_directory(const std::string& server) { // replaces : and / with _ std::string tmp(server); for (size_t i(0); i<server.size(); ++i) tmp[i] = (server[i]==':' || server[i]=='/')?'_':server[i]; std::string home_dir(getpwuid(getuid())->pw_dir); // create ~/.yadfs if it doesn't exist std::string yadfs_dir(home_dir + "/.yadfs"); int err=(mkdir(yadfs_dir.c_str(), S_IRWXU)?errno:0); if (EEXIST==err) { struct stat s; int err2=stat(yadfs_dir.c_str(), &s); if (!err2 && S_ISDIR(s.st_mode)) err=0; } if (err) { std::string error_message("Can't create ~/.yadfs directory: "); error_message += strerror(err); throw yadfs_exception(error_message); } // create state dir for server std::string state_dir(yadfs_dir + "/" + tmp); err=(mkdir(state_dir.c_str(), S_IRWXU)?errno:0); if (EEXIST==err) { struct stat s; int err2=stat(state_dir.c_str(), &s); if (!err2 && S_ISDIR(s.st_mode)) err=0; } if (err) { std::string error_message("Can't create state directory: "); error_message += strerror(err); throw yadfs_exception(error_message); } return state_dir; }
/* Return the path to the user's .wgetrc. This is either the value of `WGETRC' environment variable, or `$HOME/.wgetrc'. Additionally, for windows, look in the directory where wget.exe resides. */ char * wgetrc_file_name (void) { char *file = wgetrc_env_file_name (); if (file && *file) return file; file = wgetrc_user_file_name (); #ifdef WINDOWS /* Under Windows, if we still haven't found .wgetrc, look for the file `wget.ini' in the directory where `wget.exe' resides; we do this for backward compatibility with previous versions of Wget. SYSTEM_WGETRC should not be defined under WINDOWS. */ if (!file) { char *home = home_dir (); xfree_null (file); file = NULL; home = ws_mypath (); if (home) { file = aprintf ("%s/wget.ini", home); if (!file_exists_p (file)) { xfree (file); file = NULL; } xfree (home); } } #endif /* WINDOWS */ return file; }
/* Check for the existance of '$HOME/.wgetrc' and return it's path if it exists and is set. */ char * wgetrc_user_file_name (void) { char *home; char *file = NULL; /* If that failed, try $HOME/.wgetrc (or equivalent). */ #ifdef __VMS file = "SYS$LOGIN:.wgetrc"; #else /* def __VMS */ home = home_dir (); if (home) file = aprintf ("%s/.wgetrc", home); xfree_null (home); #endif /* def __VMS [else] */ if (!file) return NULL; if (!file_exists_p (file)) { xfree (file); return NULL; } return file; }
void Path::FillPlatformSpecificPaths() { agi::fs::path home = home_dir(); SetToken("?user", home/".aegisub"); SetToken("?local", home/".aegisub"); SetToken("?data", data_dir()); SetToken("?temp", boost::filesystem::temp_directory_path()); SetToken("?dictionary", "/usr/share/hunspell"); SetToken("?docs", P_DOC); }
/* ** Process the request for the right type ** @params self, env, request (for standard_request) ** @return t_bool success -> TRUE, failure -> FALSE */ t_bool cd_process_request(t_cd *self, t_env_manager *env, char *request) { if (self->request_type == PREVIOUS) return (previous_dir(self, env)); else if (self->request_type == EMPTY) return (home_dir(self, env)); else return (standard_request(self, env, request)); }
std::string config_dir() { const std::string home = home_dir(); if (!home.empty()) { const std::string result = home + "/LXiMediaServer"; _wmkdir(to_windows_path(result).c_str()); return result; } return std::string(); }
/* Return the path to the user's .wgetrc. This is either the value of `WGETRC' environment variable, or `$HOME/.wgetrc'. If the `WGETRC' variable exists but the file does not exist, the function will exit(). */ static char * wgetrc_file_name (void) { char *env, *home; char *file = NULL; /* Try the environment. */ env = getenv ("WGETRC"); if (env && *env) { if (!file_exists_p (env)) { fprintf (stderr, _("%s: WGETRC points to %s, which doesn't exist.\n"), exec_name, env); exit (1); } return xstrdup (env); } /* If that failed, try $HOME/.wgetrc. */ home = home_dir (); if (home) file = aprintf ("%s/.wgetrc", home); xfree_null (home); #ifdef WINDOWS /* Under Windows, if we still haven't found .wgetrc, look for the file `wget.ini' in the directory where `wget.exe' resides; we do this for backward compatibility with previous versions of Wget. SYSTEM_WGETRC should not be defined under WINDOWS. */ if (!file || !file_exists_p (file)) { xfree_null (file); file = NULL; home = ws_mypath (); if (home) file = aprintf ("%s/wget.ini", home); } #endif /* WINDOWS */ if (!file) return NULL; if (!file_exists_p (file)) { xfree (file); return NULL; } return file; }
void Path::FillPlatformSpecificPaths() { #ifndef __APPLE__ agi::fs::path home = home_dir(); SetToken("?user", home/".aegisub"); SetToken("?local", home/".aegisub"); SetToken("?data", P_DATA); #else agi::fs::path app_support = agi::util::GetApplicationSupportDirectory(); SetToken("?user", app_support/"Aegisub"); SetToken("?local", app_support/"Aegisub"); SetToken("?data", agi::util::GetBundleSharedSupportDirectory()); #endif SetToken("?temp", boost::filesystem::temp_directory_path()); SetToken("?dictionary", "/usr/share/hunspell"); SetToken("?docs", P_DOC); }
std::string config_dir() { const std::string home = home_dir(); if (!home.empty()) { const auto result = home + #if defined(__APPLE__) "/Library/Application Support/net.sf.lximediaserver"; #else "/.config/lximediaserver"; #endif mkdir(result.c_str(), S_IRWXU); return result; } return std::string(); }
int my_cd(t_mysh *ptr) { if (my_getenv("PWD", ptr) == 0) { my_printf("PWD not found, please check the environnement\n"); return (0); } if (ptr->param[1] == 0 || (my_strncmp(ptr->param[1], "~", 1) == 0 && ptr->param[1][1] == 0) || my_strncmp(ptr->param[1], "home", 4) == 0) { home_dir(ptr); return (1); } else if (ptr->param[1][0] == '~' && ptr->param[1][1] == '/') { home_and_next_dir(ptr); return (1); } else if (suite_command_cd(ptr) == 1) return (1); my_printf("%s : No such file or directory\n", ptr->param[1]); return (0); }
gchar * cache_find_location (CacheType type, const gchar * source, const gchar * ext) { gchar *path; const gchar *name; gchar *base; if (!source) return NULL; name = filename_from_path (source); base = remove_level_from_path (source); if (type == CACHE_THUMBS) { if (conf.enable_thumb_dirs) { path = g_strconcat (base, "/", PORNVIEW_CACHE_DIR, "/", name, ext, NULL); } else { path = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_THUMBS, source, ext, NULL); } } else { path = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_COMMENTS, source, ext, NULL); } if (!isfile (path)) { g_free (path); /* * try the opposite method if not found */ if (type == CACHE_THUMBS) { if (!conf.enable_thumb_dirs) { path = g_strconcat (base, "/", PORNVIEW_CACHE_DIR, "/", name, ext, NULL); } else { path = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_THUMBS, source, ext, NULL); } } else { path = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_COMMENTS, source, ext, NULL); } } if (!isfile (path)) { g_free (path); path = NULL; } g_free (base); return path; }
VALUE rb_file_expand_path_internal(VALUE fname, VALUE dname, int abs_mode, int long_name, VALUE result) { size_t size = 0, whome_len = 0; size_t buffer_len = 0; long wpath_len = 0, wdir_len = 0; char *fullpath = NULL; wchar_t *wfullpath = NULL, *wpath = NULL, *wpath_pos = NULL; wchar_t *wdir = NULL, *wdir_pos = NULL; wchar_t *whome = NULL, *buffer = NULL, *buffer_pos = NULL; UINT path_cp, cp; VALUE path = fname, dir = dname; wchar_t wfullpath_buffer[PATH_BUFFER_SIZE]; wchar_t path_drive = L'\0', dir_drive = L'\0'; int ignore_dir = 0; rb_encoding *path_encoding; int tainted = 0; /* tainted if path is tainted */ tainted = OBJ_TAINTED(path); /* get path encoding */ if (NIL_P(dir)) { path_encoding = rb_enc_get(path); } else { path_encoding = rb_enc_check(path, dir); } cp = path_cp = code_page(path_encoding); /* workaround invalid codepage */ if (path_cp == INVALID_CODE_PAGE) { cp = CP_UTF8; if (!NIL_P(path)) { path = fix_string_encoding(path, path_encoding); } } /* convert char * to wchar_t */ if (!NIL_P(path)) { wpath = mbstr_to_wstr(cp, RSTRING_PTR(path), (int)RSTRING_LEN(path), &wpath_len); wpath_pos = wpath; } /* determine if we need the user's home directory */ /* expand '~' only if NOT rb_file_absolute_path() where `abs_mode` is 1 */ if (abs_mode == 0 && wpath_len > 0 && wpath_pos[0] == L'~' && (wpath_len == 1 || IS_DIR_SEPARATOR_P(wpath_pos[1]))) { /* tainted if expanding '~' */ tainted = 1; whome = home_dir(); if (whome == NULL) { xfree(wpath); rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `~'"); } whome_len = wcslen(whome); if (PathIsRelativeW(whome) && !(whome_len >= 2 && IS_DIR_UNC_P(whome))) { xfree(wpath); xfree(whome); rb_raise(rb_eArgError, "non-absolute home"); } if (path_cp == INVALID_CODE_PAGE || rb_enc_str_asciionly_p(path)) { /* use filesystem encoding if expanding home dir */ path_encoding = rb_filesystem_encoding(); cp = path_cp = system_code_page(); } /* ignores dir since we are expanding home */ ignore_dir = 1; /* exclude ~ from the result */ wpath_pos++; wpath_len--; /* exclude separator if present */ if (wpath_len && IS_DIR_SEPARATOR_P(wpath_pos[0])) { wpath_pos++; wpath_len--; } } else if (wpath_len >= 2 && wpath_pos[1] == L':') { if (wpath_len >= 3 && IS_DIR_SEPARATOR_P(wpath_pos[2])) { /* ignore dir since path contains a drive letter and a root slash */ ignore_dir = 1; } else { /* determine if we ignore dir or not later */ path_drive = wpath_pos[0]; wpath_pos += 2; wpath_len -= 2; } } else if (abs_mode == 0 && wpath_len >= 2 && wpath_pos[0] == L'~') { result = rb_str_new_cstr("can't find user "); result = append_wstr(result, wpath_pos + 1, user_length_in_path(wpath_pos + 1, wpath_len - 1), cp, path_cp, path_encoding); if (wpath) xfree(wpath); rb_exc_raise(rb_exc_new_str(rb_eArgError, result)); } /* convert dir */ if (!ignore_dir && !NIL_P(dir)) { /* fix string encoding */ if (path_cp == INVALID_CODE_PAGE) { dir = fix_string_encoding(dir, path_encoding); } /* convert char * to wchar_t */ if (!NIL_P(dir)) { wdir = mbstr_to_wstr(cp, RSTRING_PTR(dir), (int)RSTRING_LEN(dir), &wdir_len); wdir_pos = wdir; } if (abs_mode == 0 && wdir_len > 0 && wdir_pos[0] == L'~' && (wdir_len == 1 || IS_DIR_SEPARATOR_P(wdir_pos[1]))) { /* tainted if expanding '~' */ tainted = 1; whome = home_dir(); if (whome == NULL) { free(wpath); free(wdir); rb_raise(rb_eArgError, "couldn't find HOME environment -- expanding `~'"); } whome_len = wcslen(whome); if (PathIsRelativeW(whome) && !(whome_len >= 2 && IS_DIR_UNC_P(whome))) { free(wpath); free(wdir); xfree(whome); rb_raise(rb_eArgError, "non-absolute home"); } /* exclude ~ from the result */ wdir_pos++; wdir_len--; /* exclude separator if present */ if (wdir_len && IS_DIR_SEPARATOR_P(wdir_pos[0])) { wdir_pos++; wdir_len--; } } else if (wdir_len >= 2 && wdir[1] == L':') { dir_drive = wdir[0]; if (wpath_len && IS_DIR_SEPARATOR_P(wpath_pos[0])) { wdir_len = 2; } } else if (wdir_len >= 2 && IS_DIR_UNC_P(wdir)) { /* UNC path */ if (wpath_len && IS_DIR_SEPARATOR_P(wpath_pos[0])) { /* cut the UNC path tail to '//host/share' */ long separators = 0; long pos = 2; while (pos < wdir_len && separators < 2) { if (IS_DIR_SEPARATOR_P(wdir[pos])) { separators++; } pos++; } if (separators == 2) wdir_len = pos - 1; } } else if (abs_mode == 0 && wdir_len >= 2 && wdir_pos[0] == L'~') { result = rb_str_new_cstr("can't find user "); result = append_wstr(result, wdir_pos + 1, user_length_in_path(wdir_pos + 1, wdir_len - 1), cp, path_cp, path_encoding); if (wpath) free(wpath); if (wdir) free(wdir); rb_exc_raise(rb_exc_new_str(rb_eArgError, result)); } } /* determine if we ignore dir or not */ if (!ignore_dir && path_drive && dir_drive) { if (towupper(path_drive) != towupper(dir_drive)) { /* ignore dir since path drive is different from dir drive */ ignore_dir = 1; wdir_len = 0; dir_drive = 0; } } if (!ignore_dir && wpath_len >= 2 && IS_DIR_UNC_P(wpath)) { /* ignore dir since path has UNC root */ ignore_dir = 1; wdir_len = 0; } else if (!ignore_dir && wpath_len >= 1 && IS_DIR_SEPARATOR_P(wpath[0]) && !dir_drive && !(wdir_len >= 2 && IS_DIR_UNC_P(wdir))) { /* ignore dir since path has root slash and dir doesn't have drive or UNC root */ ignore_dir = 1; wdir_len = 0; } buffer_len = wpath_len + 1 + wdir_len + 1 + whome_len + 1; buffer = buffer_pos = (wchar_t *)xmalloc((buffer_len + 1) * sizeof(wchar_t)); /* add home */ if (whome_len) { wcsncpy(buffer_pos, whome, whome_len); buffer_pos += whome_len; } /* Add separator if required */ if (whome_len && wcsrchr(L"\\/:", buffer_pos[-1]) == NULL) { buffer_pos[0] = L'\\'; buffer_pos++; } else if (!dir_drive && path_drive) { *buffer_pos++ = path_drive; *buffer_pos++ = L':'; } if (wdir_len) { /* tainted if dir is used and dir is tainted */ if (!tainted && OBJ_TAINTED(dir)) tainted = 1; wcsncpy(buffer_pos, wdir_pos, wdir_len); buffer_pos += wdir_len; } /* add separator if required */ if (wdir_len && wcsrchr(L"\\/:", buffer_pos[-1]) == NULL) { buffer_pos[0] = L'\\'; buffer_pos++; } /* now deal with path */ if (wpath_len) { wcsncpy(buffer_pos, wpath_pos, wpath_len); buffer_pos += wpath_len; } /* GetFullPathNameW requires at least "." to determine current directory */ if (wpath_len == 0) { buffer_pos[0] = L'.'; buffer_pos++; } /* Ensure buffer is NULL terminated */ buffer_pos[0] = L'\0'; /* tainted if path is relative */ if (!tainted && PathIsRelativeW(buffer) && !(buffer_len >= 2 && IS_DIR_UNC_P(buffer))) tainted = 1; /* FIXME: Make this more robust */ /* Determine require buffer size */ size = GetFullPathNameW(buffer, PATH_BUFFER_SIZE, wfullpath_buffer, NULL); if (size > PATH_BUFFER_SIZE) { /* allocate more memory than alloted originally by PATH_BUFFER_SIZE */ wfullpath = (wchar_t *)xmalloc(size * sizeof(wchar_t)); size = GetFullPathNameW(buffer, size, wfullpath, NULL); } else { wfullpath = wfullpath_buffer; } /* Remove any trailing slashes */ if (IS_DIR_SEPARATOR_P(wfullpath[size - 1]) && wfullpath[size - 2] != L':' && !(size == 2 && IS_DIR_UNC_P(wfullpath))) { size -= 1; wfullpath[size] = L'\0'; } /* Remove any trailing dot */ if (wfullpath[size - 1] == L'.') { size -= 1; wfullpath[size] = L'\0'; } /* removes trailing invalid ':$DATA' */ size = remove_invalid_alternative_data(wfullpath, size); /* Replace the trailing path to long name */ if (long_name) size = replace_to_long_name(&wfullpath, size, (wfullpath != wfullpath_buffer)); /* sanitize backslashes with forwardslashes */ replace_wchar(wfullpath, L'\\', L'/'); /* convert to VALUE and set the path encoding */ rb_str_set_len(result, 0); result = append_wstr(result, wfullpath, size, cp, path_cp, path_encoding); /* makes the result object tainted if expanding tainted strings or returning modified path */ if (tainted) OBJ_TAINT(result); /* TODO: better cleanup */ if (buffer) xfree(buffer); if (wpath) free(wpath); if (wdir) free(wdir); if (whome) xfree(whome); if (wfullpath != wfullpath_buffer) xfree(wfullpath); if (fullpath) xfree(fullpath); rb_enc_associate(result, path_encoding); return result; }
int cache_maintain_home_dir (CacheType type, const gchar * dir, gint recursive, gint clear) { gchar *base; gint base_length; GList *dlist = NULL; GList *flist = NULL; gint still_have_a_file = FALSE; if (type == CACHE_THUMBS) { base_length = strlen (home_dir ()) + strlen ("/") + strlen (PORNVIEW_RC_DIR_THUMBS); base = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_THUMBS, dir, NULL); } else { base_length = strlen (home_dir ()) + strlen ("/") + strlen (PORNVIEW_RC_DIR_COMMENTS); base = g_strconcat (home_dir (), "/", PORNVIEW_RC_DIR_COMMENTS, dir, NULL); } if (path_list (base, &flist, &dlist)) { GList *work; work = dlist; while (work) { gchar *path = work->data; if (recursive && strlen (path) > base_length && !cache_maintain_home_dir (type, path + base_length, recursive, clear)) { if (rmdir (path) < 0) { printf ("Unable to delete dir: %s\n", path); } } else { still_have_a_file = TRUE; } work = work->next; } work = flist; while (work) { gchar *path = work->data; gchar *dot; dot = extension_find_dot (path); if (dot) *dot = '\0'; if (clear || (strlen (path) > base_length && !isfile (path + base_length))) { if (dot) *dot = '.'; if (unlink (path) < 0) printf ("failed to delete:%s\n", path); } else { still_have_a_file = TRUE; } work = work->next; } } path_list_free (dlist); path_list_free (flist); g_free (base); return still_have_a_file; }
/* * Find the first occurrence of a file in the canonical search list: * the current directory * the home directory * vile's subdirectory of the home directory * the vile library-directory * * On Unix we look for file/directory names with a "." prefixed since that * hides them. */ static FILE * OpenKeywords(const char *table_name) { #define OPEN_IT(p) if ((fp = fopen(p, "r")) != 0) { \ VERBOSE(1,("Opened %s", p)); return fp; } else { \ VERBOSE(2,("..skip %s", p)); } #define FIND_IT(p) sprintf p; OPEN_IT(str_keyword_name) static char suffix[] = KEYFILE_SUFFIX; FILE *fp; const char *path; size_t need; char myLeaf[20]; need = sizeof(suffix) + strlen(table_name) + 2; str_keyword_file = do_alloc(str_keyword_file, need, &len_keyword_file); if (str_keyword_file == 0) { CannotAllocate("OpenKeywords"); return 0; } sprintf(str_keyword_file, "%s%s", table_name, suffix); if (strchr(str_keyword_file, PATHSEP) != 0) { OPEN_IT(str_keyword_file); } if ((path = home_dir()) == 0) path = ""; need = strlen(path) + strlen(str_keyword_file) + 20; str_keyword_name = do_alloc(str_keyword_name, need, &len_keyword_name); if (str_keyword_name == 0) { CannotAllocate("OpenKeywords"); return 0; } FIND_IT((str_keyword_name, "%s%c%s%s", PATHDOT, PATHSEP, DOT_TO_HIDE_IT, str_keyword_file)); FIND_IT((str_keyword_name, "%s%c%s%s", path, PATHSEP, DOT_TO_HIDE_IT, str_keyword_file)); sprintf(myLeaf, "%s%s%c", DOT_TO_HIDE_IT, MY_NAME, PATHSEP); FIND_IT((str_keyword_name, "%s%c%s%s", path, PATHSEP, myLeaf, str_keyword_file)); path = vile_getenv("VILE_STARTUP_PATH"); #ifdef VILE_STARTUP_PATH if (path == 0) path = VILE_STARTUP_PATH; #endif if (path != 0) { int n = 0, m; need = strlen(path) + strlen(str_keyword_file) + 2; str_keyword_name = do_alloc(str_keyword_name, need, &len_keyword_name); if (str_keyword_name == 0) { CannotAllocate("OpenKeywords"); return 0; } while (path[n] != 0) { for (m = n; path[m] != 0 && path[m] != PATHCHR; m++) /*LOOP */ ; FIND_IT((str_keyword_name, "%.*s%c%s", m - n, path + n, PATHSEP, str_keyword_file)); if (path[m]) n = m + 1; else n = m; } } return 0; }
static gint cb_cache_maintain_home (gpointer data) { CMData *cm = data; GList *dlist = NULL; GList *list = NULL; gchar *path; gint just_done = FALSE; gint still_have_a_file = TRUE; gint base_length; if (cm->type == CACHE_THUMBS) base_length = strlen (home_dir ()) + strlen ("/") + strlen (PORNVIEW_RC_DIR_THUMBS); else base_length = strlen (home_dir ()) + strlen ("/") + strlen (PORNVIEW_RC_DIR_COMMENTS); if (!cm->list) { cm->idle_id = -1; cache_maintain_home_close (cm); return FALSE; } path = cm->list->data; if (g_list_find (cm->done_list, path) == NULL) { cm->done_list = g_list_prepend (cm->done_list, path); if (path_list (path, &list, &dlist)) { GList *work; just_done = TRUE; still_have_a_file = FALSE; work = list; while (work) { gchar *path_buf = work->data; gchar *dot; dot = extension_find_dot (path_buf); if (dot) *dot = '\0'; if (cm->clear || (strlen (path_buf) > base_length && !isfile (path_buf + base_length))) { if (dot) *dot = '.'; if (unlink (path_buf) < 0) printf ("failed to delete:%s\n", path_buf); } else { still_have_a_file = TRUE; } work = work->next; } } } path_list_free (list); cm->list = g_list_concat (dlist, cm->list); if (cm->list && g_list_find (cm->done_list, cm->list->data) != NULL) { /* * check if the dir is empty */ if (cm->list->data == path && just_done) { if (!still_have_a_file && !dlist && cm->list->next && rmdir (path) < 0) { printf ("Unable to delete dir: %s\n", path); } } else { /* * must re-check for an empty dir */ path = cm->list->data; if (isempty (path) && cm->list->next && rmdir (path) < 0) { printf ("Unable to delete dir: %s\n", path); } } path = cm->list->data; cm->done_list = g_list_remove (cm->done_list, path); cm->list = g_list_remove (cm->list, path); g_free (path); } if (cm->list) { const gchar *buf; path = cm->list->data; if (strlen (path) > base_length) { buf = path + base_length; } else { buf = "..."; } gtk_entry_set_text (GTK_ENTRY (cm->entry), buf); } return TRUE; }