-
Notifications
You must be signed in to change notification settings - Fork 4
/
timetest.cpp
198 lines (163 loc) · 6.96 KB
/
timetest.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/* ****************************************************************************
* $Id: timetest.cpp,v 1.2 1999/11/18 19:03:04 warmerda Exp $
*
* Project: SDTS Translator
* Purpose: Example program dumping data in 8211 data to stdout.
* Author: Frank Warmerdam, [email protected]
*
******************************************************************************
* Copyright (c) 1999, Frank Warmerdam
*
* Permission is hereby granted, free of charge, to any person obtaining a
* copy of this software and associated documentation files (the "Software"),
* to deal in the Software without restriction, including without limitation
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
* and/or sell copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
* DEALINGS IN THE SOFTWARE.
******************************************************************************
*
* $Log: timetest.cpp,v $
* Revision 1.2 1999/11/18 19:03:04 warmerda
* expanded tabs
*
* Revision 1.1 1999/05/06 14:26:33 warmerda
* New
*
* Revision 1.2 1999/04/28 05:16:47 warmerda
* added usage
*
* Revision 1.1 1999/04/27 22:09:30 warmerda
* New
*
*/
#include <stdio.h>
#include "iso8211.h"
static void ViewRecordField( DDFField * poField );
static int ViewSubfield( DDFSubfieldDefn *poSFDefn,
const char * pachFieldData,
int nBytesRemaining );
/* **********************************************************************/
/* main() */
/* **********************************************************************/
int main( int nArgc, char ** papszArgv )
{
DDFModule oModule;
const char *pszFilename;
int i;
if( nArgc > 1 )
pszFilename = papszArgv[1];
else
{
printf( "Usage: 8211view filename\n" );
exit( 1 );
}
for( i = 0; i < 40; i++ )
{
/* -------------------------------------------------------------------- */
/* Open the file. Note that by default errors are reported to */
/* stderr, so we don't bother doing it ourselves. */
/* -------------------------------------------------------------------- */
if( !oModule.Open( pszFilename ) )
{
exit( 1 );
}
/* -------------------------------------------------------------------- */
/* Loop reading records till there are none left. */
/* -------------------------------------------------------------------- */
DDFRecord *poRecord;
int nRecordCount = 0;
int nFieldCount = 0;
while( (poRecord = oModule.ReadRecord()) != NULL )
{
/* ------------------------------------------------------------ */
/* Loop over each field in this particular record. */
/* ------------------------------------------------------------ */
for( int iField = 0; iField < poRecord->GetFieldCount(); iField++ )
{
DDFField *poField = poRecord->GetField( iField );
ViewRecordField( poField );
nFieldCount++;
}
nRecordCount++;
}
oModule.Close();
printf( "Read %d records, %d fields.\n", nRecordCount, nFieldCount );
}
}
/* **********************************************************************/
/* ViewRecordField() */
/* */
/* Dump the contents of a field instance in a record. */
/* **********************************************************************/
static void ViewRecordField( DDFField * poField )
{
int nBytesRemaining;
const char *pachFieldData;
DDFFieldDefn *poFieldDefn = poField->GetFieldDefn();
// Get pointer to this fields raw data. We will move through
// it consuming data as we report subfield values.
pachFieldData = poField->GetData();
nBytesRemaining = poField->GetDataSize();
/* -------------------------------------------------------- */
/* Loop over the repeat count for this fields */
/* subfields. The repeat count will almost */
/* always be one. */
/* -------------------------------------------------------- */
int iRepeat, nRepeatCount;
nRepeatCount = poField->GetRepeatCount();
for( iRepeat = 0; iRepeat < nRepeatCount; iRepeat++ )
{
/* -------------------------------------------------------- */
/* Loop over all the subfields of this field, advancing */
/* the data pointer as we consume data. */
/* -------------------------------------------------------- */
int iSF;
for( iSF = 0; iSF < poFieldDefn->GetSubfieldCount(); iSF++ )
{
DDFSubfieldDefn *poSFDefn = poFieldDefn->GetSubfield( iSF );
int nBytesConsumed;
nBytesConsumed = ViewSubfield( poSFDefn, pachFieldData,
nBytesRemaining );
nBytesRemaining -= nBytesConsumed;
pachFieldData += nBytesConsumed;
}
}
}
/* **********************************************************************/
/* ViewSubfield() */
/* **********************************************************************/
static int ViewSubfield( DDFSubfieldDefn *poSFDefn,
const char * pachFieldData,
int nBytesRemaining )
{
int nBytesConsumed = 0;
switch( poSFDefn->GetType() )
{
case DDFInt:
poSFDefn->ExtractIntData( pachFieldData, nBytesRemaining,
&nBytesConsumed );
break;
case DDFFloat:
poSFDefn->ExtractFloatData( pachFieldData, nBytesRemaining,
&nBytesConsumed );
break;
case DDFString:
poSFDefn->ExtractStringData( pachFieldData, nBytesRemaining,
&nBytesConsumed );
break;
default:
break;
}
return nBytesConsumed;
}