24 |
#include "logfile.h" |
#include "logfile.h" |
25 |
#include "types.h" |
#include "types.h" |
26 |
|
|
27 |
|
#ifdef ENABLE_NLS |
28 |
|
# include <libintl.h> |
29 |
|
# undef _ |
30 |
|
# define _(String) dgettext (PACKAGE, String) |
31 |
|
# ifdef gettext_noop |
32 |
|
# define N_(String) gettext_noop (String) |
33 |
|
# else |
34 |
|
# define N_(String) (String) |
35 |
|
# endif |
36 |
|
#else |
37 |
|
# define textdomain(String) (String) |
38 |
|
# define gettext(String) (String) |
39 |
|
# define dgettext(Domain,Message) (Message) |
40 |
|
# define dcgettext(Domain,Message,Type) (Message) |
41 |
|
# define bindtextdomain(Domain,Directory) (Domain) |
42 |
|
# define _(String) (String) |
43 |
|
# define N_(String) (String) |
44 |
|
#endif |
45 |
|
|
46 |
static gint flog_open (LOGDB *); |
static gint flog_open (LOGDB *); |
47 |
static void flog_close (LOGDB *); |
static void flog_close (LOGDB *); |
48 |
static gint flog_create (LOGDB *); |
static gint flog_create (LOGDB *); |
49 |
static gint flog_qso_append (LOGDB *, const qso_t *); |
static gint flog_qso_append (LOGDB *, const qso_t *); |
50 |
static gint flog_qso_foreach (LOGDB *, gint (*fn) (LOGDB *, qso_t *, gpointer arg), gpointer arg); |
static gint flog_qso_foreach |
51 |
|
(LOGDB *, gint (*fn) (LOGDB *, qso_t *, gpointer arg), gpointer arg); |
52 |
|
|
53 |
const struct log_ops flog_ops = { |
const struct log_ops flog_ops = { |
54 |
.open = flog_open, |
.open = flog_open, |
77 |
return -1; |
return -1; |
78 |
handle->priv = (gpointer) fp; |
handle->priv = (gpointer) fp; |
79 |
|
|
|
|
|
|
/* read header line |
|
|
* TODO: handle error cases |
|
|
*/ |
|
80 |
fgets (header_line, FLOG_MAX_LINE_SIZE, fp); |
fgets (header_line, FLOG_MAX_LINE_SIZE, fp); |
|
field_name = header_line; |
|
81 |
|
|
82 |
|
/* error handling */ |
83 |
|
if (strlen (header_line) < 82) |
84 |
|
{ |
85 |
|
g_warning (_("The header of log %s is corrupted."), handle->path); |
86 |
|
g_warning (_("It's length is smaller than 82.")); |
87 |
|
g_warning (_("This does not look like an xlog file.")); |
88 |
|
return 1; |
89 |
|
} |
90 |
|
if (strncmp (header_line, "DATE ", 5)) |
91 |
|
{ |
92 |
|
g_warning (_("The header of log %s is corrupted."), handle->path); |
93 |
|
g_warning (_("It does not start with DATE.")); |
94 |
|
g_warning (_("This does not look like an xlog file.")); |
95 |
|
return 1; |
96 |
|
} |
97 |
|
|
98 |
|
field_name = header_line; |
99 |
for (p = header_line; *p; p++) |
for (p = header_line; *p; p++) |
100 |
{ |
{ |
101 |
field_width++; |
field_width++; |
102 |
if (in_space_state) |
if (in_space_state) |
103 |
{ |
{ |
104 |
if (*p != ' ') |
if (*p != ' ') |
105 |
{ |
{ |
106 |
/* start of a new column */ |
/* start of a new column */ |
107 |
in_space_state = 0; |
in_space_state = 0; |
110 |
* add previous column, |
* add previous column, |
111 |
* now we know the column width |
* now we know the column width |
112 |
*/ |
*/ |
113 |
handle->column_fields[column_nr] = parse_field_name (field_name); |
handle->column_fields[column_nr] = |
114 |
|
parse_field_name (field_name); |
115 |
handle->column_widths[column_nr] = field_width; |
handle->column_widths[column_nr] = field_width; |
116 |
column_nr++; |
column_nr++; |
117 |
|
|
216 |
/* chop off EOL */ |
/* chop off EOL */ |
217 |
if (width > 0 && buffer[width - 1] == '\n') |
if (width > 0 && buffer[width - 1] == '\n') |
218 |
buffer[width - 1] = '\0'; |
buffer[width - 1] = '\0'; |
219 |
q[handle->column_fields[handle->column_nr - 1]] = g_strdup (g_strstrip (buffer)); |
q[handle->column_fields[handle->column_nr - 1]] = |
220 |
|
g_strdup (g_strstrip (buffer)); |
221 |
|
|
222 |
/* |
/* |
223 |
* populate fields not present in log file |
* populate fields not present in log file |