-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcl_dump_data_csv.c
108 lines (95 loc) · 2.93 KB
/
cl_dump_data_csv.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*
* cldump - Dumps Clarion databases to text, SQL and CSV formats
*
* Copyright (C) 2004-2006 Julien BLACHE <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* $Id: cl_dump_data_csv.c 65 2010-11-27 10:20:08Z julien $
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdint.h>
#include <endian.h>
#include <byteswap.h>
#include "cldump.h"
void
clarion_dump_data_csv (ClarionHandle *cl)
{
int nrecs, nflds;
FILE *fp = cl->data;
ClarionHeader *clh = cl->clm.clh;
ClarionFieldDesc *clfd = cl->clm.clfd;
ClarionRecordHeader clrh;
uint8_t *buf;
buf = (uint8_t *) malloc(clh->reclen * sizeof(uint8_t));
for (nrecs = 0; nrecs < clh->numrecs; nrecs++)
{
fread(&clrh.rhd, 1, 1, fp);
fread(&clrh.rptr, 4, 1, fp);
if ((clrh.rhd & CL_RECORD_DELETED) && (cl->opts & CL_OPT_DUMP_ACTIVE))
{
fseek(cl->data, (clh->reclen - 5), SEEK_CUR);
continue;
}
for (nflds = 0; nflds < clh->numflds; nflds++)
{
/*
* A field with type CL_FIELD_GROUP is a pseudo-field
* used to indicate that the next clfd[i].length fields
* are grouped together.
*/
if (clfd[nflds].fldtype == CL_FIELD_GROUP)
{
continue;
}
if (nflds > 0)
fprintf(stdout, "%c", cl->fsep);
switch (clfd[nflds].fldtype)
{
case CL_FIELD_LONG:
clarion_dump_field_long(buf, &clfd[nflds], cl->data, NULL);
break;
case CL_FIELD_REAL:
clarion_dump_field_real(buf, &clfd[nflds], cl->data, NULL);
break;
case CL_FIELD_STRING:
case CL_FIELD_STRING_PIC_TOK:
clarion_dump_field_string(buf, &clfd[nflds], cl->data, NULL, cl->charset);
break;
case CL_FIELD_BYTE:
clarion_dump_field_byte(buf, &clfd[nflds], cl->data, NULL);
break;
case CL_FIELD_SHORT:
clarion_dump_field_short(buf, &clfd[nflds], cl->data, NULL);
break;
case CL_FIELD_DECIMAL:
clarion_dump_field_decimal(buf, &clfd[nflds], cl->data, NULL);
break;
default:
fprintf(stderr, "Unknown field type %d\n", clfd[nflds].fldtype);
break;
}
}
if ((clh->sfatr & CL_MEMO_FILE_EXISTS) && (!(cl->opts & CL_OPT_NO_MEMO)))
{
fprintf(stdout, "%c", cl->fsep);
clarion_dump_memo_entry(&clrh, cl->memo, NULL, cl->charset);
}
fprintf(stdout, "\n");
fflush(stdout);
}
free(buf);
}