annotate src/ui_fileops.c @ 421:b8e663fab11f

Add missing _().
author zas_
date Sat, 19 Apr 2008 13:39:21 +0000
parents f9611a6cf0e2
children 6802aeeed196
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
1 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
2 * (SLIK) SimpLIstic sKin functions
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
3 * (C) 2006 John Ellis
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
4 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
5 * Author: John Ellis
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
6 *
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
7 * This software is released under the GNU General Public License (GNU GPL).
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
8 * Please read the included file COPYING for more information.
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
9 * This software comes with no warranty of any kind, use at your own risk!
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
10 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
11
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
12 #ifdef HAVE_CONFIG_H
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
13 # include "config.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
14 #endif
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
15
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
16 #include <pwd.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
17 #include <stdio.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
18 #include <stdlib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
19 #include <string.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
20 #include <unistd.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
21 #include <sys/param.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
22 #include <dirent.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
23 #include <utime.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
24
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
25 #include <glib.h>
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
26 #include <gtk/gtk.h> /* for locale warning dialog */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
27
281
9995c5fb202a gqview.h -> main.h
zas_
parents: 254
diff changeset
28 #include "main.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
29 #include "ui_fileops.h"
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
30
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
31 #include "ui_utildlg.h" /* for locale warning dialog */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
32
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 /*
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
34 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
35 * generic file information and manipulation routines (public)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
36 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
39
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
40
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
41 void print_term(const gchar *text_utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
42 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 gchar *text_l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
44
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
45 text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46 printf((text_l) ? text_l : text_utf8);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 g_free(text_l);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
50 static void encoding_dialog(const gchar *path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
51
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 static gint encoding_dialog_idle(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
53 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
54 gchar *path = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
55
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
56 encoding_dialog(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
60 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
61
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
62 static gint encoding_dialog_delay(gpointer data)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
63 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 g_idle_add(encoding_dialog_idle, data);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
65
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
66 return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
67 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
68
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
69 static void encoding_dialog(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
70 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 static gint warned_user = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 GenericDialog *gd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 GString *string;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 const gchar *lc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 const gchar *bf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 /* check that gtk is initialized (loop is level > 0) */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78 if (gtk_main_level() == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 /* gtk not initialized */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 gtk_init_add(encoding_dialog_delay, g_strdup(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
85 if (warned_user) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
86 warned_user = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 lc = getenv("LANG");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89 bf = getenv("G_BROKEN_FILENAMES");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 warned_user = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 string = g_string_new("");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93 g_string_append(string, "One or more filenames are not encoded with the preferred locale character set.\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 g_string_append_printf(string, "Operations on, and display of these files with %s may not succeed.\n\n", PACKAGE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 g_string_append(string, "If your filenames are not encoded in utf-8, try setting\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
96 g_string_append(string, "the environment variable G_BROKEN_FILENAMES=1\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
97 g_string_append_printf(string, "It appears G_BROKEN_FILENAMES is %s%s\n\n",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
98 (bf) ? "set to " : "not set.", (bf) ? bf : "");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 g_string_append_printf(string, "The locale appears to be set to \"%s\"\n(set by the LANG environment variable)\n", (lc) ? lc : "undefined");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
100 if (lc && (strstr(lc, "UTF-8") || strstr(lc, "utf-8")))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
102 gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 name = g_convert(path, -1, "UTF-8", "ISO-8859-1", NULL, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 string = g_string_append(string, "\nPreferred encoding appears to be UTF-8, however the file:\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 g_string_append_printf(string, "\"%s\"\n%s encoded in valid UTF-8.\n",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
106 (name) ? name : "[name not displayable]",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
107 (g_utf8_validate(path, -1, NULL)) ? "is": "is NOT");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
108 g_free(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
111 gd = generic_dialog_new("Filename encoding locale mismatch",
254
9faf34f047b1 Make the wmclass value unique among the code by defining
zas_
parents: 138
diff changeset
112 GQ_WMCLASS, "locale warning", NULL, TRUE, NULL, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
114
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116 "Filename encoding locale mismatch", string->str);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 gtk_widget_show(gd->dialog);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
119
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
120 g_string_free(string, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
121 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
122
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
123 gchar *path_to_utf8(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
124 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 gchar *utf8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 GError *error = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
129
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
130 utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 encoding_dialog(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
136 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 if (!utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
138 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
139 /* just let it through, but bad things may happen */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 utf8 = g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
143 return utf8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
144 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
146 gchar *path_from_utf8(const gchar *utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
147 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 GError *error = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 if (!utf8) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
152
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
153 path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
159 if (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
160 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
161 /* if invalid UTF-8, text probaby still in original form, so just copy it */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 path = g_strdup(utf8);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
164
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
165 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
166 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
168 /* first we try the HOME environment var, if that doesn't work, we try getpwuid(). */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
169 const gchar *homedir(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
171 static gchar *home = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
172
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
173 if (!home)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
174 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
175 home = path_to_utf8(getenv("HOME"));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
176 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
177 if (!home)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
178 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
179 struct passwd *pw = getpwuid(getuid());
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 if (pw) home = path_to_utf8(pw->pw_dir);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
183 return home;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
184 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
186 gint stat_utf8(const gchar *s, struct stat *st)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
187 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 ret = (stat(sl, st) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
197 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
198
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
199 gint lstat_utf8(const gchar *s, struct stat *st)
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
200 {
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
201 gchar *sl;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
202 gint ret;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
203
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
204 if (!s) return FALSE;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
205 sl = path_from_utf8(s);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
206 ret = (lstat(sl, st) == 0);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
207 g_free(sl);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
208
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
209 return ret;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
210 }
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
211
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
212 gint isname(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
213 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
215
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
216 return stat_utf8(s, &st);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
217 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
218
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
219 gint isfile(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
220 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
222
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
223 return (stat_utf8(s, &st) && S_ISREG(st.st_mode));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
224 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
225
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
226 gint isdir(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
227 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
229
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
230 return (stat_utf8(s ,&st) && S_ISDIR(st.st_mode));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
231 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
233 gint islink(const gchar *s)
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
234 {
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
235 struct stat st;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
236
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
237 return (lstat_utf8(s ,&st) && S_ISLNK(st.st_mode));
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
238 }
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
239
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
240 gint64 filesize(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
241 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
243
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
244 if (!stat_utf8(s, &st)) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
245 return (gint)st.st_size;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
248 time_t filetime(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
249 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
252 if (!stat_utf8(s, &st)) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253 return st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
256 gint filetime_set(const gchar *s, time_t tval)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
257 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
259
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
260 if (tval > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
261 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
262 struct utimbuf ut;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 ut.actime = ut.modtime = tval;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
266
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
267 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268 ret = (utime(sl, &ut) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
272 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
273 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
275 gint access_file(const gchar *s, int mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
276 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
281
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
282 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283 ret = (access(sl, mode) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
287 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
288
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
289 gint unlink_file(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
290 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
295
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
296 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297 ret = (unlink(sl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
301 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
302
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
303 gint symlink_utf8(const gchar *source, const gchar *target)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
304 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 gchar *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 if (!source || !target) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
310
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
311 sl = path_from_utf8(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312 tl = path_from_utf8(target);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 ret = (symlink(sl, tl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
315
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
316 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
320 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
321
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
322 gint mkdir_utf8(const gchar *s, int mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
323 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
328
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
329 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330 ret = (mkdir(sl, mode) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
335 gint rmdir_utf8(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
336 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
341
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
342 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343 ret = (rmdir(sl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
347 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
348
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
349 gint copy_file_attributes(const gchar *s, const gchar *t, gint perms, gint mtime)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
350 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
352 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
356
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
357 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 if (stat(sl, &st) == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
361 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
362 struct utimbuf tb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
363
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
364 ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
365
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
366 /* set the dest file attributes to that of source (ignoring errors) */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
367
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
368 if (perms && chown(tl, st.st_uid, st.st_gid) < 0) ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369 if (perms && chmod(tl, st.st_mode) < 0) ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
371 tb.actime = st.st_atime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372 tb.modtime = st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 if (mtime && utime(tl, &tb) < 0) ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
376 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
377 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
380 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
381
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
382 /* paths are in filesystem encoding */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
383 static gint hard_linked(const gchar *a, const gchar *b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 struct stat sta;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 struct stat stb;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 if (stat(a, &sta) != 0 || stat(b, &stb) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
389
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
390 return (sta.st_dev == stb.st_dev &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391 sta.st_ino == stb.st_ino);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
394 gint copy_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
395 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 FILE *fi = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 FILE *fo = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 gchar buf[4096];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 gint b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 if (hard_linked(sl, tl))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
406 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
407 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
412 fi = fopen(sl, "rb");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
413 if (fi)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 fo = fopen(tl, "wb");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 if (!fo)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 fi = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
422
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
423 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
424 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 if (!fi || !fo) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
427
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
428 while((b = fread(buf, sizeof(char), 4096, fi)) && b != 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
430 if (fwrite(buf, sizeof(char), b, fo) != b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
431 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
432 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 fclose(fo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
437
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
438 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
439 fclose(fo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 copy_file_attributes(s, t, TRUE, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
442
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
443 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
444 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
445
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
446 gint move_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
447 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 gint ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
452
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
453 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 if (rename(sl, tl) < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 /* this may have failed because moving a file across filesystems
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 was attempted, so try copy and delete instead */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 if (copy_file(s, t))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 if (unlink(sl) < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
462 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
463 /* err, now we can't delete the source file so return FALSE */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
467 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
468 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
470 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
471 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
472 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
473 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
476 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
477
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
478 gint rename_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
479 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
484
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
485 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 ret = (rename(sl, tl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
492 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
493
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
494 gchar *get_current_dir(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
495 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 gchar *path8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 pathl = g_get_current_dir();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500 path8 = path_to_utf8(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503 return path8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
504 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
505
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
506 static gint path_list_real(const gchar *path, GList **files, GList **dirs,
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
507 gint follow_links)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
508 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
509 DIR *dp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 struct dirent *dir;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 GList *f_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 GList *d_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
516
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518 dp = opendir(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 if (!dp)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 /* dir not found */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
526 /* root dir fix */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 if (pathl[0] == '/' && pathl[1] == '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 pathl = g_strdup("");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 while ((dir = readdir(dp)) != NULL)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
534 {
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
535 struct stat st_buf;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
536 gchar *name;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
537 gchar *filepath;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
538 gint result;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
539
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
540 name = dir->d_name;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
541 filepath = g_strconcat(pathl, "/", name, NULL);
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
542
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
543 if (follow_links)
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
544 {
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
545 result = stat(filepath, &st_buf);
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
546 }
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
547 else
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
548 {
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
549 result = lstat(filepath, &st_buf);
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
550 }
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
551
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
552 if (result == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 {
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
554 gchar *path8;
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
555 gchar *name8;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
557 name8 = path_to_utf8(name);
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
558 path8 = g_strconcat(path, "/", name8, NULL);
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
559 g_free(name8);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
561 if (dirs && S_ISDIR(st_buf.st_mode) &&
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
562 !(name[0] == '.' && (name[1] == '\0' || (name[1] == '.' && name[2] == '\0'))) )
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
563 {
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
564 d_list = g_list_prepend(d_list, path8);
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
565 path8 = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 }
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
567 else if (files &&
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
568 (S_ISREG(st_buf.st_mode) || (!follow_links && S_ISLNK(st_buf.st_mode))) )
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
569 {
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
570 f_list = g_list_prepend(f_list, path8);
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
571 path8 = NULL;
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
572 }
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
573 g_free(path8);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 }
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
575
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
576 g_free(filepath);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577 }
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
578
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 closedir(dp);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
582
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
583 if (dirs) *dirs = g_list_reverse(d_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584 if (files) *files = g_list_reverse(f_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
589 gint path_list(const gchar *path, GList **files, GList **dirs)
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
590 {
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
591 return path_list_real(path, files, dirs, TRUE);
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
592 }
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
593
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
594 gint path_list_lstat(const gchar *path, GList **files, GList **dirs)
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
595 {
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
596 return path_list_real(path, files, dirs, FALSE);
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
597 }
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
598
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599 void path_list_free(GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 g_list_foreach(list, (GFunc)g_free, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
605 GList *path_list_copy(GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
606 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 GList *new_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611 while (work)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
614
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
615 path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
616 work = work->next;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 new_list = g_list_prepend(new_list, g_strdup(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
619 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 return g_list_reverse(new_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
624 long checksum_simple(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
625 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 gchar *path8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
627 FILE *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 long sum = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 gint c;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
630
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
631 path8 = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 f = fopen(path8, "r");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 g_free(path8);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 if (!f) return -1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636 while((c = fgetc(f)) != EOF)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 sum += c;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
639 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
641 fclose(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
642
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 return sum;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 gchar *unique_filename(const gchar *path, const gchar *ext, const gchar *divider, gint pad)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
648 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 gint n = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 if (!ext) ext = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 if (!divider) divider = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
654 unique = g_strconcat(path, ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 while (isname(unique))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 if (pad)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
659 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
660 unique = g_strdup_printf("%s%s%03d%s", path, divider, n, ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
663 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
664 unique = g_strdup_printf("%s%s%d%s", path, divider, n, ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
665 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
666 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 if (n > 999)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
669 /* well, we tried */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
673 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
674
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
675 return unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
676 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
677
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
678 gchar *unique_filename_simple(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
679 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 const gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 const gchar *ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
683
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 name = filename_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 if (!name) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
689 ext = extension_from_path(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
690
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 if (!ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
693 unique = unique_filename(path, NULL, "_", TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
698
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 base = remove_extension_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 unique = unique_filename(base, ext, "_", TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 return unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
706
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
707 const gchar *filename_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 const gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
711 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
712
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 base = strrchr(path, '/');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 if (base) return base + 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 return path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 gchar *remove_level_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 gchar *new_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 const gchar *ptr = path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 gint p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
725 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
726
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 p = strlen(path) - 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 if (p < 0) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729 while(ptr[p] != '/' && p > 0) p--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 if (p == 0 && ptr[p] == '/') p++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 new_path = g_strndup(path, (guint)p);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 return new_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
734
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
735 gchar *concat_dir_and_file(const gchar *base, const gchar *name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
737 if (!base || !name) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
738
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 if (strcmp(base, "/") == 0) return g_strconcat(base, name, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
740
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
741 return g_strconcat(base, "/", name, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
742 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
743
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
744 const gchar *extension_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
746 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747 return strrchr(path, '.');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
750 gint file_extension_match(const gchar *path, const gchar *ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
751 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
752 gint p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
753 gint e;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
754
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
755 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
756 if (!ext) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
757
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
758 p = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
759 e = strlen(ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
761 return (p > e && strncasecmp(path + p - e, ext, e) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
762 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
763
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
764 gchar *remove_extension_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
765 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
766 gchar *new_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767 const gchar *ptr = path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 gint p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
769
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
770 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771 if (strlen(path) < 2) return g_strdup(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
773 p = strlen(path) - 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
774 while(ptr[p] != '.' && p > 0) p--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
775 if (p == 0) p = strlen(path) - 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
776 new_path = g_strndup(path, (guint)p);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777 return new_path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
778 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
779
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
780 void parse_out_relatives(gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
781 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
782 gint s, t;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
784 if (!path) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
785
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
786 s = t = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 while (path[s] != '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
790 if (path[s] == '/' && path[s+1] == '.' && (path[s+2] == '/' || path[s+2] == '\0') )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
791 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
792 s += 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
793 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
794 else if (path[s] == '/' && path[s+1] == '.' && path[s+2] == '.' && (path[s+3] == '/' || path[s+3] == '\0') )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
796 s += 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
797 if (t > 0) t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
798 while (path[t] != '/' && t > 0) t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
799 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
801 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
802 if (s != t) path[t] = path[s];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
803 t++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
804 s++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
805 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
806 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
807 if (t == 0 && path[t] == '/') t++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
808 if (t > 1 && path[t-1] == '/') t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
809 path[t] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
810 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
811
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812 gint file_in_path(const gchar *name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
813 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
814 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
815 gchar *namel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
816 gint p, l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
817 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
818
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
819 if (!name) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
820 path = g_strdup(getenv("PATH"));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
821 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
822 namel = path_from_utf8(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
823
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
824 p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
825 l = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
826 while (p < l && !ret)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
827 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
828 gchar *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
829 gint e = p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
830 while (path[e] != ':' && path[e] != '\0') e++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
831 path[e] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
832 e++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
833 f = g_strconcat(path + p, "/", namel, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
834 if (isfile(f)) ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
835 g_free(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
836 p = e;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
837 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
838 g_free(namel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
839 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
840
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
841 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
842 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
843