-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb5-dump.c
68 lines (64 loc) · 1.56 KB
/
db5-dump.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <stdio.h>
#include <stdlib.h>
#include "dbase.h"
int main (int argc, char ** argv) {
dtable * table = NULL;
dtable_record * record = NULL;
dtable_field * field = NULL;
char datebuff[11];
if (argc < 2) { return 0; }
if (argc == 2) {
table = open_dtable(argv[1], NULL, DTABLE_OPT_NO_CHAR_TO_INT);
} else {
table = open_dtable(argv[1], argv[2], DTABLE_OPT_NO_CHAR_TO_INT);
}
if (!table) { return 0; }
dump_header(table->header);
while((record = get_next_record(table)) != NULL) {
field = record->first;
printf("%cRECORD <%d>\n", record->deleted ? '-' : '+', record->index);
while (field) {
printf("\t%s:", field->descriptor->name);
switch (field->descriptor->type) {
case DTYPE_DATE:
if (field->not_init) {
printf(" unset\n");
break;
}
strftime(datebuff, 11, "%Y-%m-%d", &(field->date));
printf(" %s\n", datebuff);
break;
case DTYPE_INTEGER:
printf(" %ld\n", field->integer);
break;
case DTYPE_FLOAT:
printf(" %.4f\n", field->number);
break;
case DTYPE_MEMO:
if (field->not_init) {
printf(" unset\n");
break;
}
printf(" @block %d [%s]\n", field->memo, field->text);
break;
case DTYPE_CHAR:
printf(" \"%s\"\n", field->text);
break;
case DTYPE_BOOL:
if (field->not_init) {
printf(" unset\n");
break;
}
printf(" %s\n", field->boolean ? "true" : "false");
break;
default:
printf(" ?\n");
break;
}
field = field->next;
}
free_record(record);
}
close_dtable(table);
return 0;
}