annotate src/ui_fileops.c @ 545:e421326e8b43

Remove unused checksum_simple() function.
author zas_
date Fri, 02 May 2008 20:56:59 +0000
parents 8de7cdde59dd
children 9dc0513837b5
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
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
32 #include "debug.h"
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
33 #include "ui_utildlg.h" /* for locale warning dialog */
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 *-----------------------------------------------------------------------------
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
37 * generic file information and manipulation routines (public)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
38 *-----------------------------------------------------------------------------
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
39 */
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
43 void print_term(const gchar *text_utf8)
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 gchar *text_l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
46
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
47 text_l = g_locale_from_utf8(text_utf8, -1, NULL, NULL, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
48 printf((text_l) ? text_l : text_utf8);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
49 g_free(text_l);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
52 static void encoding_dialog(const gchar *path);
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 static gint encoding_dialog_idle(gpointer 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 gchar *path = data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
57
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
58 encoding_dialog(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
59 g_free(path);
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 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
64 static gint encoding_dialog_delay(gpointer 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 g_idle_add(encoding_dialog_idle, data);
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 return 0;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
71 static void encoding_dialog(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
72 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
73 static gint warned_user = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
74 GenericDialog *gd;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
75 GString *string;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
76 const gchar *lc;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
77 const gchar *bf;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
78
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
79 /* check that gtk is initialized (loop is level > 0) */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
80 if (gtk_main_level() == 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
81 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
82 /* gtk not initialized */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
83 gtk_init_add(encoding_dialog_delay, g_strdup(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
84 return;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
87 if (warned_user) return;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
88 warned_user = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
89
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
90 lc = getenv("LANG");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
91 bf = getenv("G_BROKEN_FILENAMES");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
92 warned_user = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
93
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
94 string = g_string_new("");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
95 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
96 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
97 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
98 g_string_append(string, "the environment variable G_BROKEN_FILENAMES=1\n");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
99 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
100 (bf) ? "set to " : "not set.", (bf) ? bf : "");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
101 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
102 if (lc && (strstr(lc, "UTF-8") || strstr(lc, "utf-8")))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
103 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
104 gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
105 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
106 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
107 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
108 (name) ? name : "[name not displayable]",
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
109 (g_utf8_validate(path, -1, NULL)) ? "is": "is NOT");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
110 g_free(name);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
113 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
114 GQ_WMCLASS, "locale warning", NULL, TRUE, NULL, NULL);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
115 generic_dialog_add_button(gd, GTK_STOCK_CLOSE, NULL, NULL, TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
116
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
117 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_WARNING,
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
118 "Filename encoding locale mismatch", string->str);
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 gtk_widget_show(gd->dialog);
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 g_string_free(string, TRUE);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
125 gchar *path_to_utf8(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
126 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
127 gchar *utf8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
128 GError *error = 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 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
131
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
132 utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
133 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
134 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
135 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
136 g_error_free(error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
137 encoding_dialog(path);
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 if (!utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
140 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
141 /* just let it through, but bad things may happen */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
142 utf8 = g_strdup(path);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
145 return utf8;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
148 gchar *path_from_utf8(const gchar *utf8)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
149 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
150 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
151 GError *error = 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 if (!utf8) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
154
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
155 path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
156 if (error)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
157 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
158 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
159 g_error_free(error);
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 (!path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
162 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
163 /* 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
164 path = g_strdup(utf8);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
167 return path;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
170 /* 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
171 const gchar *homedir(void)
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 static gchar *home = NULL;
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 if (!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 home = path_to_utf8(getenv("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 if (!home)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
180 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
181 struct passwd *pw = getpwuid(getuid());
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
182 if (pw) home = path_to_utf8(pw->pw_dir);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
185 return home;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
188 gint stat_utf8(const gchar *s, struct stat *st)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
189 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
190 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
191 gint ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
192
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
193 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
194 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
195 ret = (stat(sl, st) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
196 g_free(sl);
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 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
199 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
200
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
201 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
202 {
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
203 gchar *sl;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
204 gint ret;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
205
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
206 if (!s) return FALSE;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
207 sl = path_from_utf8(s);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
208 ret = (lstat(sl, st) == 0);
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
209 g_free(sl);
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 return ret;
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
212 }
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
213
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
214 gint isname(const gchar *s)
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 struct stat 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 return stat_utf8(s, &st);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
221 gint isfile(const gchar *s)
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 struct stat st;
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 return (stat_utf8(s, &st) && S_ISREG(st.st_mode));
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
228 gint isdir(const gchar *s)
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 struct stat st;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
231
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
232 return (stat_utf8(s ,&st) && S_ISDIR(st.st_mode));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
233 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
234
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
235 gint islink(const gchar *s)
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 struct stat st;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
238
40
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
239 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
240 }
dcc04a6a58bf Sat Apr 16 12:29:42 2005 John Ellis <johne@verizon.net>
gqview
parents: 9
diff changeset
241
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
242 gint64 filesize(const gchar *s)
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 struct stat st;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
245
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
246 if (!stat_utf8(s, &st)) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
247 return (gint)st.st_size;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
250 time_t filetime(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
251 {
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
252 struct stat st;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
253
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
254 if (!stat_utf8(s, &st)) return 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
255 return st.st_mtime;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
258 gint filetime_set(const gchar *s, time_t tval)
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 gint ret = FALSE;
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 if (tval > 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
263 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
264 struct utimbuf ut;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
265 gchar *sl;
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 ut.actime = ut.modtime = tval;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
268
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
269 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
270 ret = (utime(sl, &ut) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
271 g_free(sl);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
274 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
277 gint access_file(const gchar *s, int mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
278 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
279 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
280 gint ret;
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 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
283
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
284 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
285 ret = (access(sl, mode) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
286 g_free(sl);
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 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
291 gint unlink_file(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
292 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
293 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
294 gint ret;
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 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
297
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
298 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
299 ret = (unlink(sl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
300 g_free(sl);
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 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
305 gint symlink_utf8(const gchar *source, const gchar *target)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
306 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
307 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
308 gchar *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
309 gint ret;
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 if (!source || !target) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
312
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
313 sl = path_from_utf8(source);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
314 tl = path_from_utf8(target);
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 ret = (symlink(sl, tl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
317
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
318 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
319 g_free(tl);
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 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
324 gint mkdir_utf8(const gchar *s, int mode)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
325 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
326 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
327 gint ret;
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 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
330
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
331 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
332 ret = (mkdir(sl, mode) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
333 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
334 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
337 gint rmdir_utf8(const gchar *s)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
338 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
339 gchar *sl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
340 gint ret;
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 if (!s) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
343
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
344 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
345 ret = (rmdir(sl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
346 g_free(sl);
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 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
351 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
352 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
353 struct stat st;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
354 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
355 gint ret = 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 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
358
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
359 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
360 tl = path_from_utf8(t);
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 if (stat(sl, &st) == 0)
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 struct utimbuf tb;
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 ret = TRUE;
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 /* set the dest file attributes to that of source (ignoring errors) */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
369
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
370 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
371 if (perms && chmod(tl, st.st_mode) < 0) ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
372
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
373 tb.actime = st.st_atime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
374 tb.modtime = st.st_mtime;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
375 if (mtime && utime(tl, &tb) < 0) ret = FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
378 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
379 g_free(tl);
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 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
384 /* paths are in filesystem encoding */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
385 static gint hard_linked(const gchar *a, const gchar *b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
386 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
387 struct stat sta;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
388 struct stat stb;
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 if (stat(a, &sta) != 0 || stat(b, &stb) != 0) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
391
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
392 return (sta.st_dev == stb.st_dev &&
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
393 sta.st_ino == stb.st_ino);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
396 gint copy_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
397 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
398 FILE *fi = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
399 FILE *fo = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
400 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
401 gchar buf[4096];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
402 gint b;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
403
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
404 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
405 tl = path_from_utf8(t);
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 if (hard_linked(sl, tl))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
408 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
409 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
410 g_free(tl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
411 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
414 fi = fopen(sl, "rb");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
415 if (fi)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
416 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
417 fo = fopen(tl, "wb");
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
418 if (!fo)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
419 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
420 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
421 fi = NULL;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
425 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
426 g_free(tl);
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 if (!fi || !fo) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
429
516
b7e99bfeadc9 Convert the minority of while() to while ().
zas_
parents: 475
diff changeset
430 while ((b = fread(buf, sizeof(char), sizeof(buf), fi)) && b != 0)
9
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 if (fwrite(buf, sizeof(char), b, fo) != b)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
433 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
434 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
435 fclose(fo);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
436 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
440 fclose(fi);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
441 fclose(fo);
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 copy_file_attributes(s, t, TRUE, 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 return TRUE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
448 gint move_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
449 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
450 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
451 gint ret = TRUE;
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 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
454
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
455 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
456 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
457 if (rename(sl, tl) < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
458 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
459 /* this may have failed because moving a file across filesystems
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
460 was attempted, so try copy and delete instead */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
461 if (copy_file(s, t))
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 if (unlink(sl) < 0)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
464 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
465 /* err, now we can't delete the source file so return FALSE */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
466 ret = FALSE;
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
469 else
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 ret = FALSE;
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
474 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
475 g_free(tl);
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 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
480 gint rename_file(const gchar *s, const gchar *t)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
481 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
482 gchar *sl, *tl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
483 gint ret;
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 if (!s || !t) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
486
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
487 sl = path_from_utf8(s);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
488 tl = path_from_utf8(t);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
489 ret = (rename(sl, tl) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
490 g_free(sl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
491 g_free(tl);
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 return ret;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
496 gchar *get_current_dir(void)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
497 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
498 gchar *pathl;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
499 gchar *path8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
500
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
501 pathl = g_get_current_dir();
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
502 path8 = path_to_utf8(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
503 g_free(pathl);
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 return path8;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
506 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
507
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
508 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
509 gint follow_links)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
510 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 DIR *dp;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 struct dirent *dir;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513 GList *f_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
514 GList *d_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
515 gchar *pathl;
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 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
518
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
519 pathl = path_from_utf8(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 dp = opendir(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
521 if (!dp)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
522 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
523 /* dir not found */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 return FALSE;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 /* root dir fix */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
529 if (pathl[0] == '/' && pathl[1] == '\0')
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532 pathl = g_strdup("");
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 while ((dir = readdir(dp)) != NULL)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 {
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
537 struct stat st_buf;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
538 gchar *name;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
539 gchar *filepath;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
540 gint result;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
541
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
542 name = dir->d_name;
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
543 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
544
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
545 if (follow_links)
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 result = stat(filepath, &st_buf);
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 else
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 result = lstat(filepath, &st_buf);
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
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
554 if (result == 0)
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 {
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
556 gchar *path8;
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
557 gchar *name8;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
559 name8 = path_to_utf8(name);
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
560 path8 = g_strconcat(path, "/", name8, NULL);
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
561 g_free(name8);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
563 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
564 !(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
565 {
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
566 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
567 path8 = NULL;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 }
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
569 else if (files &&
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
570 (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
571 {
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
572 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
573 path8 = NULL;
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
574 }
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
575 g_free(path8);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 }
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
577
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
578 g_free(filepath);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 }
69
31759d770628 Fri Oct 13 10:27:22 2006 John Ellis <johne@verizon.net>
gqview
parents: 40
diff changeset
580
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
581 closedir(dp);
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 g_free(pathl);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
584
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585 if (dirs) *dirs = g_list_reverse(d_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 if (files) *files = g_list_reverse(f_list);
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 return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
589 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
590
112
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
591 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
592 {
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
593 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
594 }
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 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
597 {
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
598 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
599 }
b15d4c18168f Fri Nov 17 19:06:19 2006 John Ellis <johne@verizon.net>
gqview
parents: 69
diff changeset
600
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 void path_list_free(GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
602 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
603 g_list_foreach(list, (GFunc)g_free, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
604 g_list_free(list);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 GList *path_list_copy(GList *list)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
608 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609 GList *new_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 GList *work;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
612 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
613 while (work)
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 gchar *path;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
616
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
617 path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
618 work = work->next;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
619
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 new_list = g_list_prepend(new_list, g_strdup(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
622
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
623 return g_list_reverse(new_list);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
626 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
627 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
628 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 gint n = 1;
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 if (!ext) ext = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 if (!divider) divider = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 unique = g_strconcat(path, ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 while (isname(unique))
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 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
638 if (pad)
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 unique = g_strdup_printf("%s%s%03d%s", path, divider, n, ext);
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 else
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 unique = g_strdup_printf("%s%s%d%s", path, divider, n, ext);
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 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647 if (n > 999)
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 /* well, we tried */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651 return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 }
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655 return 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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
658 gchar *unique_filename_simple(const gchar *path)
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 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
661 const gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
662 const gchar *ext;
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 if (!path) return NULL;
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 name = filename_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
667 if (!name) return NULL;
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 ext = extension_from_path(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
670
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671 if (!ext)
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 unique = unique_filename(path, NULL, "_", TRUE);
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 else
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 gchar *base;
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 base = remove_extension_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 unique = unique_filename(base, ext, "_", TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 g_free(base);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 }
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 return unique;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 const gchar *filename_from_path(const gchar *path)
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 const gchar *base;
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 (!path) return NULL;
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 base = strrchr(path, '/');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
694 if (base) return base + 1;
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 return path;
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
699 gchar *remove_level_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 {
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
701 gint p = 0, n = -1;
9
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 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
705 while (path[p])
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
706 {
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
707 if (path[p] == '/') n = p;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
708 p++;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
709 }
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
710 if (n <= 0) n++;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
711
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
712 return g_strndup(path, (gsize) n);
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 gchar *concat_dir_and_file(const gchar *base, const gchar *name)
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 if (!base || !name) return NULL;
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 if (strcmp(base, "/") == 0) return g_strconcat(base, name, NULL);
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 return g_strconcat(base, "/", name, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 const gchar *extension_from_path(const gchar *path)
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 return strrchr(path, '.');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
728 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
729
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 gint file_extension_match(const gchar *path, const gchar *ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
731 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
732 gint p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
733 gint e;
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 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
736 if (!ext) return TRUE;
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 p = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
739 e = strlen(ext);
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 (p > e && strncasecmp(path + p - e, ext, e) == 0);
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 gchar *remove_extension_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
745 {
544
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
746 gint p = 0, n = -1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
747
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
748 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
749
544
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
750 while (path[p])
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
751 {
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
752 if (path[p] == '.') n = p;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
753 p++;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
754 }
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
755 if (n < 0) n = p;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
756
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
757 return g_strndup(path, (gsize) n);
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
760 void parse_out_relatives(gchar *path)
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 gint s, t;
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 if (!path) return;
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 s = t = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
767
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
768 while (path[s] != '\0')
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[s] == '/' && path[s+1] == '.' && (path[s+2] == '/' || path[s+2] == '\0') )
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
771 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
772 s += 2;
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 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
775 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
776 s += 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
777 if (t > 0) t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
778 while (path[t] != '/' && t > 0) t--;
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 else
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 if (s != t) path[t] = path[s];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
783 t++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
784 s++;
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
787 if (t == 0 && path[t] == '/') t++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
788 if (t > 1 && path[t-1] == '/') t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
789 path[t] = '\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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
792 gint file_in_path(const gchar *name)
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 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
795 gchar *namel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
796 gint p, l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
797 gint ret = FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
798
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
799 if (!name) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
800 path = g_strdup(getenv("PATH"));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
801 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
802 namel = path_from_utf8(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
803
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
804 p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
805 l = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
806 while (p < l && !ret)
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 gchar *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
809 gint e = p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
810 while (path[e] != ':' && path[e] != '\0') e++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
811 path[e] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
812 e++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
813 f = g_strconcat(path + p, "/", namel, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
814 if (isfile(f)) ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
815 g_free(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
816 p = e;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
817 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
818 g_free(namel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
819 g_free(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
820
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
821 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
822 }