34 |
/* |
/* |
35 |
* fields to be stored in the flog file |
* fields to be stored in the flog file |
36 |
*/ |
*/ |
37 |
const gint qso_fields[] = { DATE, GMT, CALL, BAND, MODE, RST, MYRST, QSLOUT, QSLIN, REMARKS }; |
const gint qso_fields[] = |
38 |
|
{ DATE, GMT, CALL, BAND, MODE, RST, MYRST, QSLOUT, QSLIN, REMARKS }; |
39 |
const gint qso_widths[] = { 15, 8, 15, 15, 8, 15, 15, 8, 8, 80 }; |
const gint qso_widths[] = { 15, 8, 15, 15, 8, 15, 15, 8, 8, 80 }; |
40 |
const gint qso_field_nr = 10; |
const gint qso_field_nr = 10; |
41 |
|
|
47 |
extern const struct log_ops cabrillo_ops; |
extern const struct log_ops cabrillo_ops; |
48 |
extern const struct log_ops editest_ops; |
extern const struct log_ops editest_ops; |
49 |
|
|
50 |
LOGDB* log_file_open(const gchar *path, enum log_file_type type) |
LOGDB * |
51 |
|
log_file_open (const gchar * path, enum log_file_type type) |
52 |
{ |
{ |
53 |
LOGDB *handle; |
LOGDB *handle; |
54 |
|
|
55 |
handle = (LOGDB*)g_malloc(sizeof(LOGDB)); |
handle = (LOGDB *) g_malloc (sizeof (LOGDB)); |
56 |
if (!handle) return NULL; |
if (!handle) |
57 |
handle->type = type; |
return NULL; |
58 |
switch (type) { |
handle->type = type; |
59 |
case TYPE_FLOG: handle->ops = &flog_ops; break; |
switch (type) |
60 |
case TYPE_OLD_LOG: handle->ops = &old_log_ops; break; |
{ |
61 |
case TYPE_TWLOG: handle->ops = &twlog_ops; break; |
case TYPE_FLOG: |
62 |
case TYPE_ADIF: handle->ops = &adif_ops; break; |
handle->ops = &flog_ops; |
63 |
case TYPE_CABRILLO: handle->ops = &cabrillo_ops; break; |
break; |
64 |
case TYPE_EDITEST: handle->ops = &editest_ops; break; |
case TYPE_OLD_LOG: |
65 |
default: |
handle->ops = &old_log_ops; |
66 |
/* unsupported log file type */ |
break; |
67 |
g_free(handle); |
case TYPE_TWLOG: |
68 |
return NULL; |
handle->ops = &twlog_ops; |
69 |
} |
break; |
70 |
handle->path = g_strdup(path); |
case TYPE_ADIF: |
71 |
handle->column_nr = 0; |
handle->ops = &adif_ops; |
72 |
if (handle->ops->open(handle)) { |
break; |
73 |
g_free(handle->path); |
case TYPE_CABRILLO: |
74 |
g_free(handle); |
handle->ops = &cabrillo_ops; |
75 |
handle = NULL; |
break; |
76 |
} |
case TYPE_EDITEST: |
77 |
return handle; |
handle->ops = &editest_ops; |
78 |
} |
break; |
79 |
|
default: |
80 |
LOGDB *log_file_create(const gchar *path, enum log_file_type type, |
/* unsupported log file type */ |
81 |
gint columns, const gint column_fields[], const gint column_widths[]) |
g_free (handle); |
82 |
{ |
return NULL; |
83 |
LOGDB *handle; |
} |
84 |
|
handle->path = g_strdup (path); |
85 |
handle = (LOGDB*)g_malloc(sizeof(LOGDB)); |
handle->column_nr = 0; |
86 |
if (!handle) return NULL; |
if (handle->ops->open (handle)) |
87 |
handle->type = type; |
{ |
88 |
switch (type) { |
g_free (handle->path); |
89 |
case TYPE_FLOG: handle->ops = &flog_ops; break; |
g_free (handle); |
90 |
case TYPE_OLD_LOG: handle->ops = &old_log_ops; break; |
handle = NULL; |
91 |
case TYPE_TWLOG: handle->ops = &twlog_ops; break; |
} |
92 |
case TYPE_ADIF: handle->ops = &adif_ops; break; |
return handle; |
93 |
case TYPE_CABRILLO: handle->ops = &cabrillo_ops; break; |
} |
94 |
case TYPE_EDITEST: handle->ops = &editest_ops; break; |
|
95 |
default: |
LOGDB * |
96 |
/* unsupported log file type */ |
log_file_create (const gchar * path, enum log_file_type type, |
97 |
g_free(handle); |
gint columns, const gint column_fields[], |
98 |
return NULL; |
const gint column_widths[]) |
99 |
} |
{ |
100 |
handle->path = g_strdup(path); |
LOGDB *handle; |
101 |
handle->column_nr = columns; |
|
102 |
memcpy(handle->column_fields, column_fields, columns*sizeof(gint)); |
handle = (LOGDB *) g_malloc (sizeof (LOGDB)); |
103 |
memcpy(handle->column_widths, column_widths, columns*sizeof(gint)); |
if (!handle) |
104 |
|
return NULL; |
105 |
if (handle->ops->create(handle)) { |
handle->type = type; |
106 |
g_free(handle->path); |
switch (type) |
107 |
g_free(handle); |
{ |
108 |
handle = NULL; |
case TYPE_FLOG: |
109 |
} |
handle->ops = &flog_ops; |
110 |
return handle; |
break; |
111 |
} |
case TYPE_OLD_LOG: |
112 |
|
handle->ops = &old_log_ops; |
113 |
void log_file_close(LOGDB *handle) |
break; |
114 |
{ |
case TYPE_TWLOG: |
115 |
handle->ops->close(handle); |
handle->ops = &twlog_ops; |
116 |
g_free(handle->path); |
break; |
117 |
g_free(handle); |
case TYPE_ADIF: |
118 |
} |
handle->ops = &adif_ops; |
119 |
|
break; |
120 |
gint log_file_qso_append(LOGDB *handle, const qso_t *q) |
case TYPE_CABRILLO: |
121 |
{ |
handle->ops = &cabrillo_ops; |
122 |
return handle->ops->qso_append(handle, q); |
break; |
123 |
} |
case TYPE_EDITEST: |
124 |
|
handle->ops = &editest_ops; |
125 |
gint log_file_qso_foreach(LOGDB *handle, |
break; |
126 |
gint (*fn)(LOGDB*, qso_t*, gpointer arg), gpointer arg) |
default: |
127 |
|
/* unsupported log file type */ |
128 |
|
g_free (handle); |
129 |
|
return NULL; |
130 |
|
} |
131 |
|
handle->path = g_strdup (path); |
132 |
|
handle->column_nr = columns; |
133 |
|
memcpy (handle->column_fields, column_fields, columns * sizeof (gint)); |
134 |
|
memcpy (handle->column_widths, column_widths, columns * sizeof (gint)); |
135 |
|
|
136 |
|
if (handle->ops->create (handle)) |
137 |
|
{ |
138 |
|
g_free (handle->path); |
139 |
|
g_free (handle); |
140 |
|
handle = NULL; |
141 |
|
} |
142 |
|
return handle; |
143 |
|
} |
144 |
|
|
145 |
|
void |
146 |
|
log_file_close (LOGDB * handle) |
147 |
|
{ |
148 |
|
handle->ops->close (handle); |
149 |
|
g_free (handle->path); |
150 |
|
g_free (handle); |
151 |
|
} |
152 |
|
|
153 |
|
gint |
154 |
|
log_file_qso_append (LOGDB * handle, const qso_t * q) |
155 |
|
{ |
156 |
|
return handle->ops->qso_append (handle, q); |
157 |
|
} |
158 |
|
|
159 |
|
gint |
160 |
|
log_file_qso_foreach (LOGDB * handle, |
161 |
|
gint (*fn) (LOGDB *, qso_t *, gpointer arg), |
162 |
|
gpointer arg) |
163 |
{ |
{ |
164 |
return handle->ops->qso_foreach(handle, fn, arg); |
return handle->ops->qso_foreach (handle, fn, arg); |
165 |
} |
} |
166 |
|
|
167 |
#if 0 |
#if 0 |
168 |
/* this is for live surgery */ |
/* this is for live surgery */ |
169 |
gint log_file_add_column(LOGDB *handle, gint pos, gint field, gint width) |
gint |
170 |
|
log_file_add_column (LOGDB * handle, gint pos, gint field, gint width) |
171 |
{ |
{ |
172 |
g_array_insert_val(handle->column_widths, pos, width); |
g_array_insert_val (handle->column_widths, pos, width); |
173 |
g_array_insert_val(handle->column_fields, pos, field); |
g_array_insert_val (handle->column_fields, pos, field); |
174 |
return handle->ops->add_column(handle, pos, field, width); |
return handle->ops->add_column (handle, pos, field, width); |
175 |
} |
} |
176 |
|
|
177 |
gint log_file_delete_column(LOGDB *handle, gint pos) |
gint |
178 |
|
log_file_delete_column (LOGDB * handle, gint pos) |
179 |
{ |
{ |
180 |
g_array_remove_index(handle->column_widths, pos); |
g_array_remove_index (handle->column_widths, pos); |
181 |
g_array_remove_index(handle->column_fields, pos); |
g_array_remove_index (handle->column_fields, pos); |
182 |
return handle->ops->delete_column(handle, pos); |
return handle->ops->delete_column (handle, pos); |
183 |
} |
} |
184 |
#endif |
#endif |
185 |
|
|
187 |
/* |
/* |
188 |
* flog fields names |
* flog fields names |
189 |
*/ |
*/ |
190 |
static const gchar* field_strings[] = { |
static const gchar *field_strings[] = { |
191 |
"NR", "DATE", "GMT", "GMTEND", "CALL", "BAND", "MODE", "RST", "MYRST", |
"NR", "DATE", "GMT", "GMTEND", "CALL", "BAND", "MODE", "RST", "MYRST", |
192 |
"QSLOUT", "QSLIN", "POWER", "NAME", "QTH", "LOCATOR", "U1", "U2", "REMARKS" }; |
"QSLOUT", "QSLIN", "POWER", "NAME", "QTH", "LOCATOR", "U1", "U2", "REMARKS" |
193 |
|
}; |
194 |
|
|
195 |
|
|
196 |
static const gint field_widths[] = { |
static const gint field_widths[] = { |
197 |
8, 15, 8, 8, 15, 15, 8, 15, 15, 8, 8, 8, 30, 30, 8, 30, 30, 80 }; |
8, 15, 8, 8, 15, 15, 8, 15, 15, 8, 8, 8, 30, 30, 8, 30, 30, 80 |
198 |
|
}; |
199 |
|
|
200 |
gint parse_field_name(const gchar *s) |
gint |
201 |
|
parse_field_name (const gchar * s) |
202 |
{ |
{ |
203 |
gint i; |
gint i; |
204 |
for (i = 0; i < QSO_FIELDS; i++) { |
for (i = 0; i < QSO_FIELDS; i++) |
205 |
if (!strcmp(s, field_strings[i])) |
{ |
206 |
return i; |
if (!strcmp (s, field_strings[i])) |
207 |
} |
return i; |
208 |
return -1; |
} |
209 |
|
return -1; |
210 |
|
} |
211 |
|
|
212 |
|
gint |
213 |
|
parse_field_width (const gint field) |
214 |
|
{ |
215 |
|
/* better know what you're doing */ |
216 |
|
if (field >= QSO_FIELDS || field < 0) |
217 |
|
return 0; |
218 |
|
|
219 |
|
return field_widths[field]; |
220 |
} |
} |
221 |
|
|
222 |
gint parse_field_width(const gint field) |
const gchar * |
223 |
|
strfield (gint field) |
224 |
{ |
{ |
225 |
/* better know what you're doing */ |
/* better know what you're doing */ |
226 |
if (field >= QSO_FIELDS || field < 0) |
if (field >= QSO_FIELDS || field < 0) |
227 |
return 0; |
return NULL; |
228 |
|
|
229 |
return field_widths[field]; |
return field_strings[field]; |
|
} |
|
|
|
|
|
const gchar *strfield(gint field) |
|
|
{ |
|
|
/* better know what you're doing */ |
|
|
if (field >= QSO_FIELDS || field < 0) |
|
|
return NULL; |
|
|
|
|
|
return field_strings[field]; |
|
|
} |
|
|
|
|
|
|
|
|
size_t strftime(char *s, size_t max, const char *format, |
|
|
const struct tm *tm); |
|
|
|
|
|
gint scan_month(const gchar *s) |
|
|
{ |
|
|
int i; |
|
|
static gchar month_abv[12][4] = {"","","","","","","","","","","",""}; |
|
|
static struct tm timestruct = { 0, 0, 0, 1, 0, 0, 0, 0, 0 }; |
|
|
|
|
|
/* |
|
|
* get locale month abreviations |
|
|
*/ |
|
|
if (!month_abv[0]) { |
|
|
for (i = 0; i < 12; i++) { |
|
|
timestruct.tm_mon = i; |
|
|
strftime (month_abv[i], 3, "%b", ×truct); |
|
|
} |
|
|
} |
|
|
for (i = 0; i < 12; i++) { |
|
|
if (!strncasecmp(s, month_abv[i], 3)) |
|
|
return i+1; |
|
|
} |
|
|
|
|
|
/* fall back to english abreviations */ |
|
|
switch (tolower(s[0])) { |
|
|
case 'j': if (s[1] == 'a') |
|
|
return 1; |
|
|
else if (s[2] == 'n') |
|
|
return 6; |
|
|
else |
|
|
return 7; |
|
|
case 'f': return 2; |
|
|
case 'm': if (s[2] == 'r') |
|
|
return 3; |
|
|
else |
|
|
return 5; |
|
|
case 'a': if (s[2] == 'r') |
|
|
return 4; |
|
|
else |
|
|
return 8; |
|
|
case 's': return 9; |
|
|
case 'o': return 10; |
|
|
case 'n': return 11; |
|
|
case 'd': return 12; |
|
|
default: |
|
|
return 0; |
|
|
} |
|
230 |
} |
} |
231 |
|
|
232 |
|
|
233 |
|
size_t strftime (char *s, size_t max, const char *format, |
234 |
|
const struct tm * tm); |
235 |
|
|
236 |
|
gint |
237 |
|
scan_month (const gchar * s) |
238 |
|
{ |
239 |
|
int i; |
240 |
|
static gchar month_abv[12][4] = |
241 |
|
{ "", "", "", "", "", "", "", "", "", "", "", "" }; |
242 |
|
static struct tm timestruct = { 0, 0, 0, 1, 0, 0, 0, 0, 0 }; |
243 |
|
|
244 |
|
/* |
245 |
|
* get locale month abreviations |
246 |
|
*/ |
247 |
|
if (!month_abv[0]) |
248 |
|
{ |
249 |
|
for (i = 0; i < 12; i++) |
250 |
|
{ |
251 |
|
timestruct.tm_mon = i; |
252 |
|
strftime (month_abv[i], 3, "%b", ×truct); |
253 |
|
} |
254 |
|
} |
255 |
|
for (i = 0; i < 12; i++) |
256 |
|
{ |
257 |
|
if (!strncasecmp (s, month_abv[i], 3)) |
258 |
|
return i + 1; |
259 |
|
} |
260 |
|
|
261 |
|
/* fall back to english abreviations */ |
262 |
|
switch (tolower (s[0])) |
263 |
|
{ |
264 |
|
case 'j': |
265 |
|
if (s[1] == 'a') |
266 |
|
return 1; |
267 |
|
else if (s[2] == 'n') |
268 |
|
return 6; |
269 |
|
else |
270 |
|
return 7; |
271 |
|
case 'f': |
272 |
|
return 2; |
273 |
|
case 'm': |
274 |
|
if (s[2] == 'r') |
275 |
|
return 3; |
276 |
|
else |
277 |
|
return 5; |
278 |
|
case 'a': |
279 |
|
if (s[2] == 'r') |
280 |
|
return 4; |
281 |
|
else |
282 |
|
return 8; |
283 |
|
case 's': |
284 |
|
return 9; |
285 |
|
case 'o': |
286 |
|
return 10; |
287 |
|
case 'n': |
288 |
|
return 11; |
289 |
|
case 'd': |
290 |
|
return 12; |
291 |
|
default: |
292 |
|
return 0; |
293 |
|
} |
294 |
|
} |