annotate src/ui_fileops.c @ 484:35991929975d

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