summaryrefslogtreecommitdiff
path: root/src/fr-command-ar.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fr-command-ar.c')
-rw-r--r--src/fr-command-ar.c70
1 files changed, 13 insertions, 57 deletions
diff --git a/src/fr-command-ar.c b/src/fr-command-ar.c
index f72444a..3917ee8 100644
--- a/src/fr-command-ar.c
+++ b/src/fr-command-ar.c
@@ -43,48 +43,23 @@ static void fr_command_ar_finalize (GObject *object);
static FrCommandClass *parent_class = NULL;
-
/* -- list -- */
static time_t
-mktime_from_string (const char *time_s)
+mktime_from_string (const char *time_s,
+ int index,
+ char **end)
{
struct tm tm = {0, };
+ char *p;
+
tm.tm_isdst = -1;
- strptime (time_s, LS_AR_DATE_FORMAT, &tm);
+ p = strptime (time_s + index, LS_AR_DATE_FORMAT, &tm);
+ if (p != NULL)
+ *end = p + 1;
return mktime (&tm);
}
-static char*
-ar_get_last_field (const char *line,
- int start_from,
- int field_n)
-{
- const char *f_start, *f_end;
-
- line = line + start_from;
-
- f_start = line;
- while ((*f_start == ' ') && (*f_start != *line))
- f_start++;
- f_end = f_start;
-
- while ((field_n > 0) && (*f_end != 0)) {
- if (*f_end == ' ') {
- field_n--;
- if (field_n == 1)
- f_start = f_end;
- }
- f_end++;
- }
-
- if (*f_start == ' ')
- f_start++;
-
- return g_strdup (f_start);
-}
-
-
static void
process_line (char *line,
gpointer data)
@@ -93,8 +68,8 @@ process_line (char *line,
FrCommand *comm = FR_COMMAND (data);
char **fields;
int date_idx;
- char *field_date;
- char *field_size, *field_name;
+ char *field_size;
+ char *field_name = NULL;
g_return_if_fail (line != NULL);
@@ -106,19 +81,14 @@ process_line (char *line,
fdata->size = g_ascii_strtoull (field_size, NULL, 10);
g_free (field_size);
- field_date = g_strndup (line + date_idx, 17);
- fdata->modified = mktime_from_string (field_date);
- g_free (field_date);
+ fdata->modified = mktime_from_string (line, date_idx, &field_name);
/* Full path */
- field_name = ar_get_last_field (line, date_idx, 5);
-
fields = g_strsplit (field_name, " -> ", 2);
if (fields[0] == NULL) {
g_strfreev (fields);
- g_free (field_name);
file_data_free (fdata);
return;
}
@@ -139,7 +109,6 @@ process_line (char *line,
if (fields[1] != NULL)
fdata->link = g_strdup (fields[1]);
g_strfreev (fields);
- g_free (field_name);
fdata->name = g_strdup (file_name_from_path (fdata->full_path));
fdata->path = remove_level_from_path (fdata->full_path);
@@ -150,7 +119,6 @@ process_line (char *line,
fr_command_add_file (comm, fdata);
}
-
static void
fr_command_ar_list (FrCommand *comm)
{
@@ -163,7 +131,6 @@ fr_command_ar_list (FrCommand *comm)
fr_process_start (comm->process);
}
-
static void
fr_command_ar_add (FrCommand *comm,
const char *from_file,
@@ -192,7 +159,6 @@ fr_command_ar_add (FrCommand *comm,
fr_process_end_command (comm->process);
}
-
static void
fr_command_ar_delete (FrCommand *comm,
const char *from_file,
@@ -208,7 +174,6 @@ fr_command_ar_delete (FrCommand *comm,
fr_process_end_command (comm->process);
}
-
static void
fr_command_ar_extract (FrCommand *comm,
const char *from_file,
@@ -232,7 +197,6 @@ fr_command_ar_extract (FrCommand *comm,
fr_process_end_command (comm->process);
}
-
static void
fr_command_ar_handle_error (FrCommand *comm,
FrProcError *error)
@@ -240,25 +204,22 @@ fr_command_ar_handle_error (FrCommand *comm,
/* FIXME */
}
-
const char *ar_mime_type[] = { "application/x-archive",
"application/vnd.debian.binary-package",
NULL };
-
static const char **
fr_command_ar_get_mime_types (FrCommand *comm)
{
return ar_mime_type;
}
-
-static FrCommandCap
+static FrCommandCaps
fr_command_ar_get_capabilities (FrCommand *comm,
const char *mime_type,
gboolean check_command)
{
- FrCommandCap capabilities;
+ FrCommandCaps capabilities;
capabilities = FR_COMMAND_CAN_ARCHIVE_MANY_FILES;
if (is_program_available ("ar", check_command)) {
@@ -271,7 +232,6 @@ fr_command_ar_get_capabilities (FrCommand *comm,
return capabilities;
}
-
static const char *
fr_command_ar_get_packages (FrCommand *comm,
const char *mime_type)
@@ -279,7 +239,6 @@ fr_command_ar_get_packages (FrCommand *comm,
return PACKAGES ("binutils");
}
-
static void
fr_command_ar_class_init (FrCommandArClass *class)
{
@@ -301,7 +260,6 @@ fr_command_ar_class_init (FrCommandArClass *class)
afc->get_packages = fr_command_ar_get_packages;
}
-
static void
fr_command_ar_init (FrCommand *comm)
{
@@ -315,7 +273,6 @@ fr_command_ar_init (FrCommand *comm)
comm->propTest = FALSE;
}
-
static void
fr_command_ar_finalize (GObject *object)
{
@@ -327,7 +284,6 @@ fr_command_ar_finalize (GObject *object)
G_OBJECT_CLASS (parent_class)->finalize (object);
}
-
GType
fr_command_ar_get_type ()
{