60
61
62 #define MAXID 128 // Max length of identifier
63 #define MAXSTR 1024 // Max length of string
64 #define MAXTABLES 255 // Max Number of tables in a single stream
65 #define MAXINCLUDE 20 // Max number of nested includes
66
67 #define DEFAULT_DBL_FORMAT "%.10g" // Double formatting
68
69 #ifdef CMS_IS_WINDOWS_
70 # include <io.h>
71 # define DIR_CHAR '\\'
72 #else
73 # define DIR_CHAR '/'
74 #endif
75
76
77 // Symbols
78 typedef enum {
79
80 SNONE,
81 SINUM, // Integer
82 SDNUM, // Real
83 SIDENT, // Identifier
84 SSTRING, // string
85 SCOMMENT, // comment
86 SEOLN, // End of line
87 SEOF, // End of stream
88 SSYNERROR, // Syntax error found on stream
89
90 // Keywords
91
92 SBEGIN_DATA,
93 SBEGIN_DATA_FORMAT,
94 SEND_DATA,
95 SEND_DATA_FORMAT,
96 SKEYWORD,
97 SDATA_FORMAT_ID,
98 SINCLUDE
99
100 } SYMBOL;
533 }
534
535
536 // Try to see if current identifier is a keyword, if so return the referred symbol
537 static
538 SYMBOL BinSrchKey(const char *id)
539 {
540 int l = 1;
541 int r = NUMKEYS;
542 int x, res;
543
544 while (r >= l)
545 {
546 x = (l+r)/2;
547 res = cmsstrcasecmp(id, TabKeys[x-1].id);
548 if (res == 0) return TabKeys[x-1].sy;
549 if (res < 0) r = x - 1;
550 else l = x + 1;
551 }
552
553 return SNONE;
554 }
555
556
557 // 10 ^n
558 static
559 cmsFloat64Number xpow10(int n)
560 {
561 return pow(10, (cmsFloat64Number) n);
562 }
563
564
565 // Reads a Real number, tries to follow from integer number
566 static
567 void ReadReal(cmsIT8* it8, int inum)
568 {
569 it8->dnum = (cmsFloat64Number) inum;
570
571 while (isdigit(it8->ch)) {
572
573 it8->dnum = it8->dnum * 10.0 + (it8->ch - '0');
718 while (isseparator(it8->ch))
719 NextCh(it8);
720
721 if (isfirstidchar(it8->ch)) { // Identifier
722
723 k = 0;
724 idptr = it8->id;
725
726 do {
727
728 if (++k < MAXID) *idptr++ = (char) it8->ch;
729
730 NextCh(it8);
731
732 } while (isidchar(it8->ch));
733
734 *idptr = '\0';
735
736
737 key = BinSrchKey(it8->id);
738 if (key == SNONE) it8->sy = SIDENT;
739 else it8->sy = key;
740
741 }
742 else // Is a number?
743 if (isdigit(it8->ch) || it8->ch == '.' || it8->ch == '-' || it8->ch == '+')
744 {
745 int sign = 1;
746
747 if (it8->ch == '-') {
748 sign = -1;
749 NextCh(it8);
750 }
751
752 it8->inum = 0;
753 it8->sy = SINUM;
754
755 if (it8->ch == '0') { // 0xnnnn (Hexa) or 0bnnnn (Binary)
756
757 NextCh(it8);
758 if (toupper(it8->ch) == 'X') {
1309 cmsUInt32Number i;
1310
1311 it8 = (cmsIT8*) _cmsMallocZero(ContextID, sizeof(cmsIT8));
1312 if (it8 == NULL) return NULL;
1313
1314 AllocTable(it8);
1315
1316 it8->MemoryBlock = NULL;
1317 it8->MemorySink = NULL;
1318
1319 it8 ->nTable = 0;
1320
1321 it8->ContextID = ContextID;
1322 it8->Allocator.Used = 0;
1323 it8->Allocator.Block = NULL;
1324 it8->Allocator.BlockSize = 0;
1325
1326 it8->ValidKeywords = NULL;
1327 it8->ValidSampleID = NULL;
1328
1329 it8 -> sy = SNONE;
1330 it8 -> ch = ' ';
1331 it8 -> Source = NULL;
1332 it8 -> inum = 0;
1333 it8 -> dnum = 0.0;
1334
1335 it8->FileStack[0] = (FILECTX*)AllocChunk(it8, sizeof(FILECTX));
1336 it8->IncludeSP = 0;
1337 it8 -> lineno = 1;
1338
1339 strcpy(it8->DoubleFormatter, DEFAULT_DBL_FORMAT);
1340 cmsIT8SetSheetType((cmsHANDLE) it8, "CGATS.17");
1341
1342 // Initialize predefined properties & data
1343
1344 for (i=0; i < NUMPREDEFINEDPROPS; i++)
1345 AddAvailableProperty(it8, PredefinedProperties[i].id, PredefinedProperties[i].as);
1346
1347 for (i=0; i < NUMPREDEFINEDSAMPLEID; i++)
1348 AddAvailableSampleID(it8, PredefinedSampleID[i]);
1349
|
60
61
62 #define MAXID 128 // Max length of identifier
63 #define MAXSTR 1024 // Max length of string
64 #define MAXTABLES 255 // Max Number of tables in a single stream
65 #define MAXINCLUDE 20 // Max number of nested includes
66
67 #define DEFAULT_DBL_FORMAT "%.10g" // Double formatting
68
69 #ifdef CMS_IS_WINDOWS_
70 # include <io.h>
71 # define DIR_CHAR '\\'
72 #else
73 # define DIR_CHAR '/'
74 #endif
75
76
77 // Symbols
78 typedef enum {
79
80 SUNDEFINED,
81 SINUM, // Integer
82 SDNUM, // Real
83 SIDENT, // Identifier
84 SSTRING, // string
85 SCOMMENT, // comment
86 SEOLN, // End of line
87 SEOF, // End of stream
88 SSYNERROR, // Syntax error found on stream
89
90 // Keywords
91
92 SBEGIN_DATA,
93 SBEGIN_DATA_FORMAT,
94 SEND_DATA,
95 SEND_DATA_FORMAT,
96 SKEYWORD,
97 SDATA_FORMAT_ID,
98 SINCLUDE
99
100 } SYMBOL;
533 }
534
535
536 // Try to see if current identifier is a keyword, if so return the referred symbol
537 static
538 SYMBOL BinSrchKey(const char *id)
539 {
540 int l = 1;
541 int r = NUMKEYS;
542 int x, res;
543
544 while (r >= l)
545 {
546 x = (l+r)/2;
547 res = cmsstrcasecmp(id, TabKeys[x-1].id);
548 if (res == 0) return TabKeys[x-1].sy;
549 if (res < 0) r = x - 1;
550 else l = x + 1;
551 }
552
553 return SUNDEFINED;
554 }
555
556
557 // 10 ^n
558 static
559 cmsFloat64Number xpow10(int n)
560 {
561 return pow(10, (cmsFloat64Number) n);
562 }
563
564
565 // Reads a Real number, tries to follow from integer number
566 static
567 void ReadReal(cmsIT8* it8, int inum)
568 {
569 it8->dnum = (cmsFloat64Number) inum;
570
571 while (isdigit(it8->ch)) {
572
573 it8->dnum = it8->dnum * 10.0 + (it8->ch - '0');
718 while (isseparator(it8->ch))
719 NextCh(it8);
720
721 if (isfirstidchar(it8->ch)) { // Identifier
722
723 k = 0;
724 idptr = it8->id;
725
726 do {
727
728 if (++k < MAXID) *idptr++ = (char) it8->ch;
729
730 NextCh(it8);
731
732 } while (isidchar(it8->ch));
733
734 *idptr = '\0';
735
736
737 key = BinSrchKey(it8->id);
738 if (key == SUNDEFINED) it8->sy = SIDENT;
739 else it8->sy = key;
740
741 }
742 else // Is a number?
743 if (isdigit(it8->ch) || it8->ch == '.' || it8->ch == '-' || it8->ch == '+')
744 {
745 int sign = 1;
746
747 if (it8->ch == '-') {
748 sign = -1;
749 NextCh(it8);
750 }
751
752 it8->inum = 0;
753 it8->sy = SINUM;
754
755 if (it8->ch == '0') { // 0xnnnn (Hexa) or 0bnnnn (Binary)
756
757 NextCh(it8);
758 if (toupper(it8->ch) == 'X') {
1309 cmsUInt32Number i;
1310
1311 it8 = (cmsIT8*) _cmsMallocZero(ContextID, sizeof(cmsIT8));
1312 if (it8 == NULL) return NULL;
1313
1314 AllocTable(it8);
1315
1316 it8->MemoryBlock = NULL;
1317 it8->MemorySink = NULL;
1318
1319 it8 ->nTable = 0;
1320
1321 it8->ContextID = ContextID;
1322 it8->Allocator.Used = 0;
1323 it8->Allocator.Block = NULL;
1324 it8->Allocator.BlockSize = 0;
1325
1326 it8->ValidKeywords = NULL;
1327 it8->ValidSampleID = NULL;
1328
1329 it8 -> sy = SUNDEFINED;
1330 it8 -> ch = ' ';
1331 it8 -> Source = NULL;
1332 it8 -> inum = 0;
1333 it8 -> dnum = 0.0;
1334
1335 it8->FileStack[0] = (FILECTX*)AllocChunk(it8, sizeof(FILECTX));
1336 it8->IncludeSP = 0;
1337 it8 -> lineno = 1;
1338
1339 strcpy(it8->DoubleFormatter, DEFAULT_DBL_FORMAT);
1340 cmsIT8SetSheetType((cmsHANDLE) it8, "CGATS.17");
1341
1342 // Initialize predefined properties & data
1343
1344 for (i=0; i < NUMPREDEFINEDPROPS; i++)
1345 AddAvailableProperty(it8, PredefinedProperties[i].id, PredefinedProperties[i].as);
1346
1347 for (i=0; i < NUMPREDEFINEDSAMPLEID; i++)
1348 AddAvailableSampleID(it8, PredefinedSampleID[i]);
1349
|