annotate src/ui_fileops.c @ 654:6dcfac4b356f

Get rid of vflist_pop_menu() col_idx parameter, use new Viewfile field named clicked_mark. Marks numbering is now consistent with menus (starting at 1, 0 is an invalid mark), assertions were modified accordingly.
author zas_
date Tue, 13 May 2008 19:32:25 +0000
parents 651ae2be1031
children 8268cbe682f1
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
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 545
diff changeset
508 void string_list_free(GList *list)
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 g_list_foreach(list, (GFunc)g_free, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
511 g_list_free(list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
512 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
513
576
9dc0513837b5 dropped path_list functions, use filelist functions everywhere
nadvornik
parents: 545
diff changeset
514 GList *string_list_copy(GList *list)
9
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 GList *new_list = NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
517 GList *work;
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 work = list;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
520 while (work)
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 gchar *path;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
523
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
524 path = work->data;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
525 work = work->next;
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
526
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
527 new_list = g_list_prepend(new_list, g_strdup(path));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
528 }
442
4b2d7f9af171 Big whitespaces cleanup:
zas_
parents: 435
diff changeset
529
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
530 return g_list_reverse(new_list);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
531 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
532
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
533 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
534 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
535 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
536 gint n = 1;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
537
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
538 if (!ext) ext = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
539 if (!divider) divider = "";
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
540
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
541 unique = g_strconcat(path, ext, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
542 while (isname(unique))
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
543 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
544 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
545 if (pad)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
546 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
547 unique = g_strdup_printf("%s%s%03d%s", path, divider, n, ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
548 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
549 else
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
550 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
551 unique = g_strdup_printf("%s%s%d%s", path, divider, n, ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
552 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
553 n++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
554 if (n > 999)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
555 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
556 /* well, we tried */
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
557 g_free(unique);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
558 return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
559 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
560 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
561
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
562 return unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
563 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
564
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
565 gchar *unique_filename_simple(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
566 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
567 gchar *unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
568 const gchar *name;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
569 const gchar *ext;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
570
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
571 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
572
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
573 name = filename_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
574 if (!name) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
575
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
576 ext = extension_from_path(name);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
577
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
578 if (!ext)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
579 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
580 unique = unique_filename(path, NULL, "_", TRUE);
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 else
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 gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
585
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
586 base = remove_extension_from_path(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
587 unique = unique_filename(base, ext, "_", TRUE);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
588 g_free(base);
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
591 return unique;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
592 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
593
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
594 const gchar *filename_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
595 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
596 const gchar *base;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
597
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
598 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
599
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
600 base = strrchr(path, '/');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
601 if (base) return base + 1;
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 return path;
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 gchar *remove_level_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
607 {
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
608 gint p = 0, n = -1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
609
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
610 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
611
543
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
612 while (path[p])
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
613 {
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
614 if (path[p] == '/') n = p;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
615 p++;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
616 }
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
617 if (n <= 0) n++;
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
618
b68fd1eb3243 remove_level_from_path() was simplified.
zas_
parents: 516
diff changeset
619 return g_strndup(path, (gsize) n);
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
620 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
621
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
622 gchar *concat_dir_and_file(const gchar *base, const gchar *name)
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 if (!base || !name) return NULL;
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 if (strcmp(base, "/") == 0) return g_strconcat(base, name, NULL);
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 return g_strconcat(base, "/", name, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
629 }
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 const gchar *extension_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
632 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
633 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
634 return strrchr(path, '.');
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
635 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
636
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
637 gint file_extension_match(const gchar *path, const gchar *ext)
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 gint p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
640 gint e;
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 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
643 if (!ext) return TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
644
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
645 p = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
646 e = strlen(ext);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
647
605
651ae2be1031 Use g_ascii_strncasecmp() instead of strncasecmp() where applicable.
zas_
parents: 576
diff changeset
648 /* FIXME: utf8 */
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
649 return (p > e && strncasecmp(path + p - e, ext, e) == 0);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
650 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
651
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
652 gchar *remove_extension_from_path(const gchar *path)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
653 {
544
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
654 gint p = 0, n = -1;
9
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
655
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
656 if (!path) return NULL;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
657
544
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
658 while (path[p])
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
659 {
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
660 if (path[p] == '.') n = p;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
661 p++;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
662 }
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
663 if (n < 0) n = p;
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
664
8de7cdde59dd Simplify remove_extension_from_path().
zas_
parents: 543
diff changeset
665 return g_strndup(path, (gsize) n);
9
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
668 void parse_out_relatives(gchar *path)
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 gint s, t;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
671
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
672 if (!path) return;
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 s = t = 0;
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 while (path[s] != '\0')
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 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
679 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
680 s += 2;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
681 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
682 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
683 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
684 s += 3;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
685 if (t > 0) t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
686 while (path[t] != '/' && t > 0) t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
687 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
688 else
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 if (s != t) path[t] = path[s];
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
691 t++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
692 s++;
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 }
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
695 if (t == 0 && path[t] == '/') t++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
696 if (t > 1 && path[t-1] == '/') t--;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
697 path[t] = '\0';
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
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
700 gint file_in_path(const gchar *name)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
701 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
702 gchar *path;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
703 gchar *namel;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
704 gint p, l;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
705 gint ret = FALSE;
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 if (!name) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
708 path = g_strdup(getenv("PATH"));
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
709 if (!path) return FALSE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
710 namel = path_from_utf8(name);
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 p = 0;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
713 l = strlen(path);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
714 while (p < l && !ret)
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
715 {
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
716 gchar *f;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
717 gint e = p;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
718 while (path[e] != ':' && path[e] != '\0') e++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
719 path[e] = '\0';
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
720 e++;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
721 f = g_strconcat(path + p, "/", namel, NULL);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
722 if (isfile(f)) ret = TRUE;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
723 g_free(f);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
724 p = e;
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 g_free(namel);
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
727 g_free(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 return ret;
d907d608745f Sync to GQview 1.5.9 release.
gqview
parents:
diff changeset
730 }