|
@@ -7,7 +7,7 @@ extern "C" {
|
7
|
7
|
|
8
|
8
|
/*
|
9
|
9
|
TODO:
|
10
|
|
- 0) Figure out a error handling scheme that does not rely on
|
|
10
|
+ 0) Figure out an error handling scheme that does not rely on
|
11
|
11
|
a global errno. This is not useful in multi-thread environments.
|
12
|
12
|
It might be ok to go with an 'all errors are fatal' model
|
13
|
13
|
(except in the var-args functions).
|
|
@@ -55,6 +55,10 @@ extern "C" {
|
55
|
55
|
kCvtErrDtRC,
|
56
|
56
|
kInvalidContDtRC,
|
57
|
57
|
kInvalidTypeDtRC,
|
|
58
|
+ kMissingFieldDtRC,
|
|
59
|
+ kLexFailDtRC,
|
|
60
|
+ kParseStackFailDtRC,
|
|
61
|
+ kSyntaxErrDtRC,
|
58
|
62
|
kEolDtRC
|
59
|
63
|
};
|
60
|
64
|
|
|
@@ -76,7 +80,9 @@ extern "C" {
|
76
|
80
|
kDoubleDtId, // 11
|
77
|
81
|
kStrDtId, // 12 zero terminated string
|
78
|
82
|
kBlobDtId, // 13 application defined raw memory object
|
79
|
|
- kStructDtId // 14 node is a pair,list, or recd
|
|
83
|
+ kStructDtId, // 14 node is a pair,list, or recd
|
|
84
|
+
|
|
85
|
+ kOptArgDtFl = 0x10000000
|
80
|
86
|
} cmDataTypeId_t;
|
81
|
87
|
|
82
|
88
|
|
|
@@ -119,6 +125,19 @@ extern "C" {
|
119
|
125
|
|
120
|
126
|
};
|
121
|
127
|
|
|
128
|
+ // The kInvalidDtXXX constants are used to indicate an error when returned
|
|
129
|
+ // from the cmDtXXX() functions below.
|
|
130
|
+#define kInvalidDtFloat FLT_MAX
|
|
131
|
+#define kInvalidDtDouble DBL_MAX
|
|
132
|
+
|
|
133
|
+ enum
|
|
134
|
+ {
|
|
135
|
+ kInvalidDtChar = 0xff,
|
|
136
|
+ kInvalidDtShort = 0xffff,
|
|
137
|
+ kInvalidDtInt = 0xffffffff,
|
|
138
|
+ kInvalidDtLong = kInvalidDtInt,
|
|
139
|
+ };
|
|
140
|
+
|
122
|
141
|
|
123
|
142
|
typedef struct cmData_str
|
124
|
143
|
{
|
|
@@ -146,19 +165,6 @@ extern "C" {
|
146
|
165
|
|
147
|
166
|
void* vp;
|
148
|
167
|
|
149
|
|
- /*
|
150
|
|
- char* cp;
|
151
|
|
- unsigned char* ucp;
|
152
|
|
- short* sp;
|
153
|
|
- unsigned short* usp;
|
154
|
|
- int* ip;
|
155
|
|
- unsigned int* uip;
|
156
|
|
- long* lp;
|
157
|
|
- unsigned long* ulp;
|
158
|
|
- float* fp;
|
159
|
|
- double* dp;
|
160
|
|
- */
|
161
|
|
-
|
162
|
168
|
struct cmData_str* child; // first child (list,record,pair)
|
163
|
169
|
} u;
|
164
|
170
|
|
|
@@ -266,8 +272,30 @@ extern "C" {
|
266
|
272
|
cmDtRC_t cmDataDouble( const cmData_t* p, double* v );
|
267
|
273
|
cmDtRC_t cmDataStr( const cmData_t* p, cmChar_t** v );
|
268
|
274
|
cmDtRC_t cmDataConstStr( const cmData_t* p, const cmChar_t** v );
|
269
|
|
- cmDtRC_t cmDataBlob( const cmData_t* p, cmChar_t** v, unsigned* byteCntRef );
|
270
|
|
- cmDtRC_t cmDataConstBlob( const cmData_t* p, const cmChar_t** v, unsigned* byteCntRef );
|
|
275
|
+ cmDtRC_t cmDataBlob( const cmData_t* p, void** v, unsigned* byteCntRef );
|
|
276
|
+ cmDtRC_t cmDataConstBlob( const cmData_t* p, const void** v, unsigned* byteCntRef );
|
|
277
|
+
|
|
278
|
+ // Functions in this group which return pointers will return NULL
|
|
279
|
+ // on error. The other function indicate an error by returning
|
|
280
|
+ // kInvalidDtXXX depending on their type.
|
|
281
|
+ // Note that there is no guarantee, except as determined by the
|
|
282
|
+ // application, that one of the kInvalidDtXXX is not in fact a legal return value.
|
|
283
|
+ // These function are simple wrappers around calls to cmDataXXX() and
|
|
284
|
+ // therefore do NOT do any type conversion.
|
|
285
|
+ char cmDtChar( const cmData_t* p );
|
|
286
|
+ unsigned char cmDtUChar( const cmData_t* p );
|
|
287
|
+ short cmDtShort( const cmData_t* p );
|
|
288
|
+ unsigned short cmDtUShort( const cmData_t* p );
|
|
289
|
+ int cmDtInt( const cmData_t* p );
|
|
290
|
+ unsigned cmDtUInt( const cmData_t* p );
|
|
291
|
+ long cmDtLong( const cmData_t* p );
|
|
292
|
+ unsigned long cmDtULong( const cmData_t* p );
|
|
293
|
+ float cmDtFloat( const cmData_t* p );
|
|
294
|
+ double cmDtDouble( const cmData_t* p );
|
|
295
|
+ char* cmDtStr( const cmData_t* p );
|
|
296
|
+ const char* cmDtConstStr( const cmData_t* p );
|
|
297
|
+ void* cmDtBlob( const cmData_t* p, unsigned* byteCntRef );
|
|
298
|
+ const void* cmDtConstBlob( const cmData_t* p, unsigned* byteCntRef );
|
271
|
299
|
|
272
|
300
|
// Get the value of an object with conversion.
|
273
|
301
|
cmDtRC_t cmDataGetChar( const cmData_t* p, char* v );
|
|
@@ -281,6 +309,23 @@ extern "C" {
|
281
|
309
|
cmDtRC_t cmDataGetFloat( const cmData_t* p, float* v );
|
282
|
310
|
cmDtRC_t cmDataGetDouble( const cmData_t* p, double* v );
|
283
|
311
|
|
|
312
|
+ // Functions in this group which return pointers will return NULL
|
|
313
|
+ // on error. The other function indicate an error by returning
|
|
314
|
+ // kInvalidDtXXX depending on their type.
|
|
315
|
+ // Note that there is no guarantee, except as determined by the
|
|
316
|
+ // application that one of the kInvalidDtXXX is not in fact a legal return value.
|
|
317
|
+ // These function are simple wrappers around calls to cmDataGetXXX() and
|
|
318
|
+ // therefore do type conversion.
|
|
319
|
+ char cmDtGetChar( const cmData_t* p );
|
|
320
|
+ unsigned char cmDtGetUChar( const cmData_t* p );
|
|
321
|
+ short cmDtGetShort( const cmData_t* p );
|
|
322
|
+ unsigned short cmDtGetUShort( const cmData_t* p );
|
|
323
|
+ int cmDtGetInt( const cmData_t* p );
|
|
324
|
+ unsigned cmDtGetUInt( const cmData_t* p );
|
|
325
|
+ long cmDtGetLong( const cmData_t* p );
|
|
326
|
+ unsigned long cmDtGetULong( const cmData_t* p );
|
|
327
|
+ float cmDtGetFloat( const cmData_t* p );
|
|
328
|
+ double cmDtGetDouble( const cmData_t* p );
|
284
|
329
|
|
285
|
330
|
//----------------------------------------------------------------------------
|
286
|
331
|
// Array related functions
|
|
@@ -368,8 +413,19 @@ extern "C" {
|
368
|
413
|
cmDtRC_t cmDataULongArray( const cmData_t* d, unsigned long** v );
|
369
|
414
|
cmDtRC_t cmDataFloatArray( const cmData_t* d, float** v );
|
370
|
415
|
cmDtRC_t cmDataDoubleArray( const cmData_t* d, double** v );
|
371
|
|
- cmDtRC_t cmDataStrArray( const cmData_t* d, cmChar_t*** v );
|
372
|
|
- cmDtRC_t cmDataConstStrArray( const cmData_t* d, const cmChar_t*** v );
|
|
416
|
+
|
|
417
|
+ // This group of functions is a wrapper around calls to the same named
|
|
418
|
+ // cmDataXXXArray() functions above. On error they return NULL.
|
|
419
|
+ char* cmDtCharArray( const cmData_t* d );
|
|
420
|
+ unsigned char* cmDtUCharArray( const cmData_t* d );
|
|
421
|
+ short* cmDtShortArray( const cmData_t* d );
|
|
422
|
+ unsigned short* cmDtUShortArray( const cmData_t* d );
|
|
423
|
+ int* cmDtIntArray( const cmData_t* d );
|
|
424
|
+ unsigned* cmDtUIntArray( const cmData_t* d );
|
|
425
|
+ long* cmDtLongArray( const cmData_t* d );
|
|
426
|
+ unsigned long* cmDtULongArray( const cmData_t* d );
|
|
427
|
+ float* cmDtFloatArray( const cmData_t* d );
|
|
428
|
+ double* cmDtDoubleArray( const cmData_t* d );
|
373
|
429
|
|
374
|
430
|
//----------------------------------------------------------------------------
|
375
|
431
|
// Structure related functions
|
|
@@ -454,17 +510,17 @@ extern "C" {
|
454
|
510
|
// Create a pair value by assigning a key and value to 'p'.
|
455
|
511
|
// 'p' is unlinked and freed prior to the key value assignment.
|
456
|
512
|
// 'key' and 'value' are simply linked in they are not duplicated or reallocated.
|
457
|
|
- cmData_t* cmDataMakePair( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
|
|
513
|
+ cmData_t* cmDataPairMake( cmData_t* parent, cmData_t* p, cmData_t* key, cmData_t* value );
|
458
|
514
|
|
459
|
515
|
// Dynamically allocate a pair node. Both the key and value nodes are reallocated.
|
460
|
|
- cmData_t* cmDataAllocPair( cmData_t* parent, const cmData_t* key, const cmData_t* value );
|
|
516
|
+ cmData_t* cmDataPairAlloc( cmData_t* parent, const cmData_t* key, const cmData_t* value );
|
461
|
517
|
|
462
|
518
|
// Dynamically allocate the id but link (w/o realloc) the value.
|
463
|
|
- cmData_t* cmDataAllocPairId( cmData_t* parent, unsigned keyId, cmData_t* value );
|
|
519
|
+ cmData_t* cmDataPairAllocId( cmData_t* parent, unsigned keyId, cmData_t* value );
|
464
|
520
|
|
465
|
521
|
// Dynamically allocate the label but link (w/o realloc) the value.
|
466
|
|
- cmData_t* cmDataAllocPairLabelN(cmData_t* parent, const cmChar_t* label, unsigned charCnt, cmData_t* value);
|
467
|
|
- cmData_t* cmDataAllocPairLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
|
|
522
|
+ cmData_t* cmDataPairAllocLabelN(cmData_t* parent, const cmChar_t* label, unsigned charCnt, cmData_t* value);
|
|
523
|
+ cmData_t* cmDataPairAllocLabel( cmData_t* parent, const cmChar_t* label, cmData_t* value );
|
468
|
524
|
|
469
|
525
|
//----------------------------------------------------------------------------
|
470
|
526
|
// List related functions
|
|
@@ -476,6 +532,7 @@ extern "C" {
|
476
|
532
|
// Return the ith element in the list.
|
477
|
533
|
cmData_t* cmDataListEle( cmData_t* p, unsigned index );
|
478
|
534
|
|
|
535
|
+ //
|
479
|
536
|
cmData_t* cmDataListMake( cmData_t* parent, cmData_t* p );
|
480
|
537
|
cmData_t* cmDataListAlloc( cmData_t* parent);
|
481
|
538
|
|
|
@@ -544,9 +601,14 @@ extern "C" {
|
544
|
601
|
cmData_t* cmDataRecdAllocIdA( cmData_t* parent, ... );
|
545
|
602
|
|
546
|
603
|
// Extract the data in a record to C variables.
|
|
604
|
+ // Var-args format:
|
|
605
|
+ // (label | id) <cid> <typeId> <ptr> {cnt_ptr}
|
547
|
606
|
// The var-args list must be NULL terminated.
|
548
|
607
|
// The <'id' | 'label'> identify a pair.
|
|
608
|
+ // The <cid> indicates the type of the target container.
|
549
|
609
|
// The <typeId> indicates the C type of 'pointer'.
|
|
610
|
+ // If <cid> is kArrayDtId then the <cnt_ptr} must be include to receive the
|
|
611
|
+ // count of elements in the array.
|
550
|
612
|
// The actual field type must be convertable into this pointer type or the
|
551
|
613
|
// function will fail.
|
552
|
614
|
// 'err' is an application supplied error object to be used if a required
|
|
@@ -565,7 +627,7 @@ extern "C" {
|
565
|
627
|
|
566
|
628
|
//-----------------------------------------------------------------------------
|
567
|
629
|
typedef cmHandle_t cmDataParserH_t;
|
568
|
|
- //static cmDataParserH_t cmDataParserNullHandle;
|
|
630
|
+ extern cmDataParserH_t cmDataParserNullHandle;
|
569
|
631
|
|
570
|
632
|
cmDtRC_t cmDataParserCreate( cmCtx_t* ctx, cmDataParserH_t* hp );
|
571
|
633
|
cmDtRC_t cmDataParserDestroy( cmDataParserH_t* hp );
|