33
33
#include "fr-command.h"
34
34
#include "fr-command-lha.h"
37
36
static void fr_command_lha_class_init (FRCommandLhaClass *class);
39
static void fr_command_lha_init (FRCommand *afile);
41
static void fr_command_lha_destroy (GtkObject *object);
37
static void fr_command_lha_init (FRCommand *afile);
38
static void fr_command_lha_finalize (GObject *object);
52
mktime_from_string (char *month, char *mday, char *time_or_year)
48
mktime_from_string (char *month,
54
static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
55
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
52
static char *months[] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun",
53
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
97
eat_spaces (char *line)
99
while ((*line == ' ') && (*line != 0))
106
split_line (char *line, int n_fields)
95
split_line_lha (char *line)
109
char *scan, *field_end;
99
const char *scan, *field_end;
112
102
fields = g_new0 (char *, n_fields + 1);
113
fields[n_fields + 1] = NULL;
103
fields[n_fields] = NULL;
107
if (strncmp (line, "[MS-DOS]", 8) == 0) {
108
fields[i++] = g_strdup ("");
109
fields[i++] = g_strdup ("");
110
line += strlen ("[MS-DOS]");
112
} else if (strncmp (line, "[generic]", 9) == 0) {
113
fields[i++] = g_strdup ("");
114
fields[i++] = g_strdup ("");
115
line += strlen ("[generic]");
115
118
scan = eat_spaces (line);
116
for (i = 0; i < n_fields; i++) {
119
for (; i < n_fields; i++) {
117
120
field_end = strchr (scan, ' ');
118
fields[i] = g_strndup (scan, field_end - scan);
119
scan = eat_spaces (field_end);
121
if (field_end != NULL) {
122
fields[i] = g_strndup (scan, field_end - scan);
123
scan = eat_spaces (field_end);
127
get_last_field (char *line)
132
get_last_field_lha (char *line)
138
if (strncmp (line, "[MS-DOS]", 8) == 0)
141
if (strncmp (line, "[generic]", 9) == 0)
134
144
field = eat_spaces (line);
135
145
for (i = 0; i < n; i++) {
136
146
field = strchr (field, ' ');
145
process_line (char *line, gpointer data)
155
process_line (char *line,
148
FRCommand *comm = FR_COMMAND (data);
159
FRCommand *comm = FR_COMMAND (data);
161
const char *name_field;
152
163
g_return_if_fail (line != NULL);
154
165
fdata = file_data_new ();
156
fields = split_line (line, 7);
167
fields = split_line_lha (line);
157
168
fdata->size = atol (fields[2]);
158
169
fdata->modified = mktime_from_string (fields[4],
189
200
fr_command_lha_list (FRCommand *comm)
191
fr_process_clear (comm->process);
202
fr_process_set_out_line_func (FR_COMMAND (comm)->process,
192
206
fr_process_begin_command (comm->process, "lha");
193
207
fr_process_add_arg (comm->process, "lq");
194
208
fr_process_add_arg (comm->process, comm->e_filename);
195
209
fr_process_end_command (comm->process);
196
fr_process_start (comm->process, TRUE);
210
fr_process_start (comm->process);
201
fr_command_lha_add (FRCommand *comm,
215
fr_command_lha_add (FRCommand *comm,
217
const char *base_dir,
219
const char *password,
220
FRCompression compression)
208
224
fr_process_begin_command (comm->process, "lha");
210
225
if (base_dir != NULL)
211
226
fr_process_set_working_dir (comm->process, base_dir);
214
228
fr_process_add_arg (comm->process, "u");
216
230
fr_process_add_arg (comm->process, "a");
218
231
fr_process_add_arg (comm->process, comm->e_filename);
220
232
for (scan = file_list; scan; scan = scan->next)
221
233
fr_process_add_arg (comm->process, (gchar*) scan->data);
223
234
fr_process_end_command (comm->process);
228
239
fr_command_lha_delete (FRCommand *comm,
244
fr_command_lha_extract (FRCommand *comm,
255
fr_command_lha_extract (FRCommand *comm,
257
const char *dest_dir,
261
const char *password)
255
267
fr_process_begin_command (comm->process, "lha");
282
294
fr_command_lha_class_init (FRCommandLhaClass *class)
296
GObjectClass *gobject_class = G_OBJECT_CLASS (class);
284
297
FRCommandClass *afc;
285
GtkObjectClass *object_class;
287
parent_class = gtk_type_class (FR_COMMAND_TYPE);
288
object_class = (GtkObjectClass*) class;
299
parent_class = g_type_class_peek_parent (class);
289
300
afc = (FRCommandClass*) class;
291
object_class->destroy = fr_command_lha_destroy;
302
gobject_class->finalize = fr_command_lha_finalize;
293
304
afc->list = fr_command_lha_list;
294
305
afc->add = fr_command_lha_add;
305
316
comm->propExtractCanAvoidOverwrite = FALSE;
306
317
comm->propExtractCanSkipOlder = FALSE;
307
318
comm->propExtractCanJunkPaths = TRUE;
319
comm->propPassword = FALSE;
320
comm->propTest = FALSE;
312
fr_command_lha_destroy (GtkObject *object)
325
fr_command_lha_finalize (GObject *object)
314
327
g_return_if_fail (object != NULL);
315
g_return_if_fail (IS_FR_COMMAND_LHA (object));
328
g_return_if_fail (FR_IS_COMMAND_LHA (object));
318
if (GTK_OBJECT_CLASS (parent_class)->destroy)
319
(* GTK_OBJECT_CLASS (parent_class)->destroy) (object);
331
if (G_OBJECT_CLASS (parent_class)->finalize)
332
G_OBJECT_CLASS (parent_class)->finalize (object);
324
337
fr_command_lha_get_type ()
326
static guint fr_command_lha_type = 0;
328
if (!fr_command_lha_type) {
329
GtkTypeInfo fr_command_lha_info = {
331
sizeof (FRCommandLha),
332
sizeof (FRCommandLhaClass),
333
(GtkClassInitFunc) fr_command_lha_class_init,
334
(GtkObjectInitFunc) fr_command_lha_init,
335
/* reserved_1 */ NULL,
336
/* reserved_2 */ NULL,
337
(GtkClassInitFunc) NULL,
339
fr_command_lha_type = gtk_type_unique (fr_command_get_type(),
340
&fr_command_lha_info);
339
static GType type = 0;
342
GTypeInfo type_info = {
343
sizeof (FRCommandLhaClass),
346
(GClassInitFunc) fr_command_lha_class_init,
349
sizeof (FRCommandLha),
351
(GInstanceInitFunc) fr_command_lha_init
354
type = g_type_register_static (FR_TYPE_COMMAND,
343
return fr_command_lha_type;
348
fr_command_lha_new (FRProcess *process,
365
fr_command_lha_new (FRProcess *process,
366
const char *filename)
353
comm = FR_COMMAND (gtk_type_new (fr_command_lha_get_type ()));
370
comm = FR_COMMAND (g_object_new (FR_TYPE_COMMAND_LHA, NULL));
354
371
fr_command_construct (comm, process, filename);
355
fr_process_set_proc_line_func (FR_COMMAND (comm)->process,