2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS cabinet manager
4 * FILE: tools/cabman/dfp.cpp
5 * PURPOSE: Directive file parser
6 * PROGRAMMERS: Casper S. Hornstrup (chorns@users.sourceforge.net)
7 * NOTES: The directive file format is similar to the
8 * directive file format used by Microsoft's MAKECAB
10 * CSH 21/03-2001 Created
11 * CSH 15/08-2003 Made it portable
21 CDFParser::CDFParser()
23 * FUNCTION: Default constructor
27 DontGenerateInf
= false;
33 CabinetCreated
= false;
35 FolderCreated
= false;
40 MaxDiskSizeAllSet
= false;
41 CabinetNameTemplateSet
= false;
42 DiskLabelTemplateSet
= false;
43 InfFileNameSet
= false;
45 InfModeEnabled
= false;
49 CDFParser::~CDFParser()
51 * FUNCTION: Default destructor
60 FreeMemory(FileBuffer
);
62 while (CNNext
!= NULL
) {
63 CNPrev
= CNNext
->Next
;
68 while (CNNext
!= NULL
) {
69 CNPrev
= CNNext
->Next
;
74 while (DNNext
!= NULL
) {
75 DNPrev
= DNNext
->Next
;
80 if (InfFileHandle
!= NULL
) {
81 CloseFile(InfFileHandle
);
85 void CDFParser::WriteInfLine(char* InfLine
)
91 unsigned long BytesWritten
;
94 if (DontGenerateInf
) {
98 if (InfFileHandle
== NULL
) {
99 if (!InfFileNameSet
) {
100 /* FIXME: Use cabinet name with extension .inf */
104 destpath
= GetDestinationPath();
105 if (strlen(destpath
) > 0) {
106 strcpy(buf
, destpath
);
107 strcat(buf
, InfFileName
);
109 strcpy(buf
, InfFileName
);
112 /* Create .inf file, overwrite if it already exists */
114 InfFileHandle
= CreateFile(buf
, // Create this file
115 GENERIC_WRITE
, // Open for writing
118 CREATE_ALWAYS
, // Create or overwrite
119 FILE_ATTRIBUTE_NORMAL
, // Normal file
120 NULL
); // No attribute template
121 if (InfFileHandle
== INVALID_HANDLE_VALUE
) {
122 DPRINT(MID_TRACE
, ("Error creating '%d'.\n", (unsigned int)GetLastError()));
126 InfFileHandle
= fopen(buf
, "wb");
127 if (InfFileHandle
== NULL
) {
128 DPRINT(MID_TRACE
, ("Error creating '%d'.\n", (unsigned int)errno
));
135 if (!WriteFile(InfFileHandle
, InfLine
, strlen(InfLine
), &BytesWritten
, NULL
)) {
136 DPRINT(MID_TRACE
, ("ERROR WRITING '%d'.\n", (unsigned int)GetLastError()));
140 if (fwrite(InfLine
, strlen(InfLine
), 1, InfFileHandle
) < 1)
148 if (!WriteFile(InfFileHandle
, eolbuf
, sizeof(eolbuf
), &BytesWritten
, NULL
)) {
149 DPRINT(MID_TRACE
, ("ERROR WRITING '%d'.\n", (unsigned int)GetLastError()));
153 if (fwrite(eolbuf
, 1, sizeof(eolbuf
), InfFileHandle
) < 1)
159 unsigned long CDFParser::Load(char* FileName
)
161 * FUNCTION: Loads a directive file into memory
163 * FileName = Pointer to name of directive file
165 * Status of operation
168 unsigned long BytesRead
;
172 return CAB_STATUS_SUCCESS
;
174 /* Create cabinet file, overwrite if it already exists */
176 FileHandle
= CreateFile(FileName
, // Create this file
177 GENERIC_READ
, // Open for reading
180 OPEN_EXISTING
, // Open the file
181 FILE_ATTRIBUTE_NORMAL
, // Normal file
182 NULL
); // No attribute template
183 if (FileHandle
== INVALID_HANDLE_VALUE
)
184 return CAB_STATUS_CANNOT_OPEN
;
186 FileHandle
= fopen(FileName
, "rb");
187 if (FileHandle
== NULL
) {
188 return CAB_STATUS_CANNOT_OPEN
;
192 FileSize
= GetSizeOfFile(FileHandle
);
193 if (FileSize
== (unsigned long)-1) {
194 CloseFile(FileHandle
);
195 return CAB_STATUS_CANNOT_OPEN
;
198 FileBufferSize
= (unsigned long)FileSize
;
200 FileBuffer
= (char*)AllocateMemory(FileBufferSize
);
202 CloseFile(FileHandle
);
203 return CAB_STATUS_NOMEMORY
;
206 if (!ReadFileData(FileHandle
, FileBuffer
, FileBufferSize
, &BytesRead
)) {
207 CloseFile(FileHandle
);
208 FreeMemory(FileBuffer
);
210 return CAB_STATUS_CANNOT_READ
;
213 CloseFile(FileHandle
);
217 DPRINT(MAX_TRACE
, ("File (%d bytes)\n", FileBufferSize
));
219 return CAB_STATUS_SUCCESS
;
223 unsigned long CDFParser::Parse()
225 * FUNCTION: Parses a loaded directive file
227 * Status of operation
231 unsigned long Status
;
234 return CAB_STATUS_NOFILE
;
239 if (InfModeEnabled
) {
240 bool WriteLine
= true;
241 while (CurrentToken
!= TokenEnd
) {
242 switch (CurrentToken
) {
243 case TokenIdentifier
:
246 Status
= PerformCommand();
247 if (Status
== CAB_STATUS_FAILURE
) {
250 if (!InfModeEnabled
) {
254 CurrentToken
= TokenEnd
;
258 CurrentToken
= TokenEnd
;
269 CurrentToken
= TokenEnd
;
278 while (CurrentToken
!= TokenEnd
) {
279 switch (CurrentToken
) {
281 sprintf(CurrentString
, "%d", CurrentInteger
);
282 case TokenIdentifier
:
285 Status
= PerformCommand();
287 if (Status
== CAB_STATUS_FAILURE
) {
288 printf("Directive file contains errors at line %d.\n", (unsigned int)CurrentLine
);
289 DPRINT(MID_TRACE
, ("Error while executing command.\n"));
292 if (Status
!= CAB_STATUS_SUCCESS
)
296 Status
= PerformFileCopy();
298 if (Status
== CAB_STATUS_FAILURE
) {
299 printf("Directive file contains errors at line %d.\n", (unsigned int)CurrentLine
);
300 DPRINT(MID_TRACE
, ("Error while copying file.\n"));
303 if (Status
!= CAB_STATUS_SUCCESS
)
310 CurrentToken
= TokenEnd
;
316 printf("Directive file contains errors at line %d.\n", (unsigned int)CurrentLine
);
317 DPRINT(MID_TRACE
, ("Token is (%d).\n", (unsigned int)CurrentToken
));
318 return CAB_STATUS_SUCCESS
;
326 printf("\nWriting cabinet. This may take a while...\n\n");
329 Status
= WriteDisk(false);
330 if (Status
== CAB_STATUS_SUCCESS
)
331 Status
= CloseDisk();
332 if (Status
!= CAB_STATUS_SUCCESS
) {
333 DPRINT(MIN_TRACE
, ("Cannot write disk (%d).\n", (unsigned int)Status
));
338 if (CabinetCreated
) {
339 Status
= CloseCabinet();
340 if (Status
!= CAB_STATUS_SUCCESS
) {
341 DPRINT(MIN_TRACE
, ("Cannot close cabinet (%d).\n", (unsigned int)Status
));
349 return CAB_STATUS_SUCCESS
;
353 bool CDFParser::OnDiskLabel(unsigned long Number
, char* Label
)
355 * FUNCTION: Called when a disk needs a label
357 * Number = Cabinet number that needs a label
358 * Label = Pointer to buffer to place label of disk
360 * true if a disk label was returned, false if not
369 DPRINT(MID_TRACE
, ("Giving disk (%d) a label...\n", (unsigned int)Number
));
371 if (GetDiskName(&DiskLabel
, Number
, Label
))
374 if (DiskLabelTemplateSet
) {
377 for (i
= 0; i
< strlen(DiskLabelTemplate
); i
++) {
378 ch
= DiskLabelTemplate
[i
];
380 sprintf(Buffer
, "%d", Number
);
381 strcat(Label
, Buffer
);
390 DPRINT(MID_TRACE
, ("Giving disk (%s) as a label...\n", Label
));
398 bool CDFParser::OnCabinetName(unsigned long Number
, char* Name
)
400 * FUNCTION: Called when a cabinet needs a name
402 * Number = Disk number that needs a name
403 * Name = Pointer to buffer to place name of cabinet
405 * true if a cabinet name was returned, false if not
408 char Buffer
[MAX_PATH
];
414 DPRINT(MID_TRACE
, ("Giving cabinet (%d) a name...\n", (unsigned int)Number
));
416 if (GetDiskName(&CabinetName
, Number
, Buffer
)) {
417 strcpy(Name
, GetDestinationPath());
418 strcat(Name
, Buffer
);
422 if (CabinetNameTemplateSet
) {
423 strcpy(Name
, GetDestinationPath());
425 for (i
= 0; i
< strlen(CabinetNameTemplate
); i
++) {
426 ch
= CabinetNameTemplate
[i
];
428 sprintf(Buffer
, "%d", Number
);
429 strcat(Name
, Buffer
);
438 DPRINT(MID_TRACE
, ("Giving cabinet (%s) as a name...\n", Name
));
446 bool CDFParser::SetDiskName(PCABINET_NAME
*List
, unsigned long Number
, char* String
)
448 * FUNCTION: Sets an entry in a list
450 * List = Address of pointer to list
451 * Number = Disk number
452 * String = Pointer to string
454 * false if there was not enough free memory available
461 if (CN
->DiskNumber
== Number
) {
462 strcpy(CN
->Name
, String
);
468 CN
= (PCABINET_NAME
)AllocateMemory(sizeof(CABINET_NAME
));
472 CN
->DiskNumber
= Number
;
473 strcpy(CN
->Name
, String
);
482 bool CDFParser::GetDiskName(PCABINET_NAME
*List
, unsigned long Number
, char* String
)
484 * FUNCTION: Returns an entry in a list
486 * List = Address of pointer to list
487 * Number = Disk number
488 * String = Address of buffer to copy string to
490 * false if there was not enough free memory available
497 if (CN
->DiskNumber
== Number
) {
498 strcpy(String
, CN
->Name
);
508 bool CDFParser::SetDiskNumber(PDISK_NUMBER
*List
, unsigned long Number
, unsigned long Value
)
510 * FUNCTION: Sets an entry in a list
512 * List = Address of pointer to list
513 * Number = Disk number
514 * Value = Value to set
516 * false if there was not enough free memory available
523 if (DN
->DiskNumber
== Number
) {
530 DN
= (PDISK_NUMBER
)AllocateMemory(sizeof(DISK_NUMBER
));
534 DN
->DiskNumber
= Number
;
544 bool CDFParser::GetDiskNumber(PDISK_NUMBER
*List
, unsigned long Number
, unsigned long* Value
)
546 * FUNCTION: Returns an entry in a list
548 * List = Address of pointer to list
549 * Number = Disk number
550 * Value = Address of buffer to place value
552 * true if the entry was found
559 if (DN
->DiskNumber
== Number
) {
570 bool CDFParser::DoDiskLabel(unsigned long Number
, char* Label
)
572 * FUNCTION: Sets the label of a disk
574 * Number = Disk number
575 * Label = Pointer to label of disk
577 * false if there was not enough free memory available
580 DPRINT(MID_TRACE
, ("Setting label of disk (%d) to '%s'\n", (unsigned int)Number
, Label
));
582 return SetDiskName(&DiskLabel
, Number
, Label
);
586 void CDFParser::DoDiskLabelTemplate(char* Template
)
588 * FUNCTION: Sets a disk label template to use
590 * Template = Pointer to disk label template
593 DPRINT(MID_TRACE
, ("Setting disk label template to '%s'\n", Template
));
595 strcpy(DiskLabelTemplate
, Template
);
596 DiskLabelTemplateSet
= true;
600 bool CDFParser::DoCabinetName(unsigned long Number
, char* Name
)
602 * FUNCTION: Sets the name of a cabinet
604 * Number = Disk number
605 * Name = Pointer to name of cabinet
607 * false if there was not enough free memory available
610 DPRINT(MID_TRACE
, ("Setting name of cabinet (%d) to '%s'\n", (unsigned int)Number
, Name
));
612 return SetDiskName(&CabinetName
, Number
, Name
);
616 void CDFParser::DoCabinetNameTemplate(char* Template
)
618 * FUNCTION: Sets a cabinet name template to use
620 * Template = Pointer to cabinet name template
623 DPRINT(MID_TRACE
, ("Setting cabinet name template to '%s'\n", Template
));
625 strcpy(CabinetNameTemplate
, Template
);
626 CabinetNameTemplateSet
= true;
630 unsigned long CDFParser::DoMaxDiskSize(bool NumberValid
, unsigned long Number
)
632 * FUNCTION: Sets the maximum disk size
634 * NumberValid = true if disk number is valid
635 * Number = Disk number
637 * Status of operation
639 * Standard sizes are 2.88M, 1.44M, 1.25M, 1.2M, 720K, 360K, and CDROM
642 unsigned long A
, B
, Value
;
644 if (IsNextToken(TokenInteger
, true)) {
648 if (IsNextToken(TokenPeriod
, false)) {
649 if (!IsNextToken(TokenInteger
, false))
650 return CAB_STATUS_FAILURE
;
657 if (CurrentToken
== TokenIdentifier
) {
658 switch (CurrentString
[0]) {
661 return CAB_STATUS_FAILURE
;
670 return CAB_STATUS_FAILURE
;
679 Value
= 1300000; // FIXME: Value?
684 return CAB_STATUS_FAILURE
;
690 return CAB_STATUS_FAILURE
;
692 return CAB_STATUS_FAILURE
;
695 DPRINT(MID_TRACE
, ("Bad suffix (%c)\n", CurrentString
[0]));
696 return CAB_STATUS_FAILURE
;
701 if ((CurrentToken
!= TokenString
) &&
702 (strcasecmp(CurrentString
, "CDROM") != 0))
703 return CAB_STATUS_FAILURE
;
705 Value
= 640*1024*1024; // FIXME: Correct size for CDROM?
709 return (SetDiskNumber(&MaxDiskSize
, Number
, Value
)?
710 CAB_STATUS_SUCCESS
: CAB_STATUS_FAILURE
);
712 MaxDiskSizeAll
= Value
;
713 MaxDiskSizeAllSet
= true;
715 SetMaxDiskSize(Value
);
717 return CAB_STATUS_SUCCESS
;
721 void CDFParser::DoInfFileName(char* FileName
)
723 * FUNCTION: Sets filename of the generated .inf file
725 * FileName = Pointer to .inf filename
728 DPRINT(MID_TRACE
, ("Setting .inf filename to '%s'\n", FileName
));
730 strcpy(InfFileName
, FileName
);
731 InfFileNameSet
= true;
734 unsigned long CDFParser::SetupNewDisk()
736 * FUNCTION: Sets up parameters for a new disk
738 * Status of operation
743 if (!GetDiskNumber(&MaxDiskSize
, GetCurrentDiskNumber(), &Value
)) {
744 if (MaxDiskSizeAllSet
)
745 Value
= MaxDiskSizeAll
;
749 SetMaxDiskSize(Value
);
751 return CAB_STATUS_SUCCESS
;
755 unsigned long CDFParser::PerformSetCommand()
757 * FUNCTION: Performs a set variable command
759 * Status of operation
763 bool NumberValid
= false;
764 unsigned long Number
= 0;
766 if (!IsNextToken(TokenIdentifier
, true))
767 return CAB_STATUS_FAILURE
;
769 if (strcasecmp(CurrentString
, "DiskLabel") == 0)
770 SetType
= stDiskLabel
;
771 else if (strcasecmp(CurrentString
, "DiskLabelTemplate") == 0)
772 SetType
= stDiskLabelTemplate
;
773 else if (strcasecmp(CurrentString
, "CabinetName") == 0)
774 SetType
= stCabinetName
;
775 else if (strcasecmp(CurrentString
, "CabinetNameTemplate") == 0)
776 SetType
= stCabinetNameTemplate
;
777 else if (strcasecmp(CurrentString
, "MaxDiskSize") == 0)
778 SetType
= stMaxDiskSize
;
779 else if (strcasecmp(CurrentString
, "InfFileName") == 0)
780 SetType
= stInfFileName
;
782 return CAB_STATUS_FAILURE
;
784 if ((SetType
== stDiskLabel
) || (SetType
== stCabinetName
)) {
785 if (!IsNextToken(TokenInteger
, false))
786 return CAB_STATUS_FAILURE
;
787 Number
= CurrentInteger
;
789 if (!IsNextToken(TokenEqual
, true))
790 return CAB_STATUS_FAILURE
;
791 } else if (SetType
== stMaxDiskSize
) {
792 if (IsNextToken(TokenInteger
, false)) {
794 Number
= CurrentInteger
;
797 while (CurrentToken
== TokenSpace
)
799 if (CurrentToken
!= TokenEqual
)
800 return CAB_STATUS_FAILURE
;
802 } else if (!IsNextToken(TokenEqual
, true))
803 return CAB_STATUS_FAILURE
;
805 if (SetType
!= stMaxDiskSize
) {
806 if (!IsNextToken(TokenString
, true))
807 return CAB_STATUS_FAILURE
;
812 if (!DoDiskLabel(Number
, CurrentString
))
813 DPRINT(MIN_TRACE
, ("Not enough available free memory.\n"));
814 return CAB_STATUS_SUCCESS
;
816 if (!DoCabinetName(Number
, CurrentString
))
817 DPRINT(MIN_TRACE
, ("Not enough available free memory.\n"));
818 return CAB_STATUS_SUCCESS
;
819 case stDiskLabelTemplate
:
820 DoDiskLabelTemplate(CurrentString
);
821 return CAB_STATUS_SUCCESS
;
822 case stCabinetNameTemplate
:
823 DoCabinetNameTemplate(CurrentString
);
824 return CAB_STATUS_SUCCESS
;
826 return DoMaxDiskSize(NumberValid
, Number
);
828 DoInfFileName(CurrentString
);
829 return CAB_STATUS_SUCCESS
;
831 return CAB_STATUS_FAILURE
;
836 unsigned long CDFParser::PerformNewCommand()
838 * FUNCTION: Performs a new disk|cabinet|folder command
840 * Status of operation
844 unsigned long Status
;
846 if (!IsNextToken(TokenIdentifier
, true))
847 return CAB_STATUS_FAILURE
;
849 if (strcasecmp(CurrentString
, "Disk") == 0)
851 else if (strcasecmp(CurrentString
, "Cabinet") == 0)
853 else if (strcasecmp(CurrentString
, "Folder") == 0)
856 return CAB_STATUS_FAILURE
;
861 Status
= WriteDisk(true);
862 if (Status
== CAB_STATUS_SUCCESS
)
863 Status
= CloseDisk();
864 if (Status
!= CAB_STATUS_SUCCESS
) {
865 DPRINT(MIN_TRACE
, ("Cannot write disk (%d).\n", (unsigned int)Status
));
866 return CAB_STATUS_SUCCESS
;
872 if (Status
!= CAB_STATUS_SUCCESS
) {
873 DPRINT(MIN_TRACE
, ("Cannot create disk (%d).\n", (unsigned int)Status
));
874 return CAB_STATUS_SUCCESS
;
878 return CAB_STATUS_SUCCESS
;
881 Status
= WriteDisk(true);
882 if (Status
== CAB_STATUS_SUCCESS
)
883 Status
= CloseDisk();
884 if (Status
!= CAB_STATUS_SUCCESS
) {
885 DPRINT(MIN_TRACE
, ("Cannot write disk (%d).\n", (unsigned int)Status
));
886 return CAB_STATUS_SUCCESS
;
891 Status
= NewCabinet();
892 if (Status
!= CAB_STATUS_SUCCESS
) {
893 DPRINT(MIN_TRACE
, ("Cannot create cabinet (%d).\n", (unsigned int)Status
));
894 return CAB_STATUS_SUCCESS
;
898 return CAB_STATUS_SUCCESS
;
900 Status
= NewFolder();
901 ASSERT(Status
== CAB_STATUS_SUCCESS
);
902 return CAB_STATUS_SUCCESS
;
904 return CAB_STATUS_FAILURE
;
909 unsigned long CDFParser::PerformInfBeginCommand()
911 * FUNCTION: Begins inf mode
913 * Status of operation
916 InfModeEnabled
= true;
917 return CAB_STATUS_SUCCESS
;
921 unsigned long CDFParser::PerformInfEndCommand()
923 * FUNCTION: Begins inf mode
925 * Status of operation
928 InfModeEnabled
= false;
929 return CAB_STATUS_SUCCESS
;
933 unsigned long CDFParser::PerformCommand()
935 * FUNCTION: Performs a command
937 * Status of operation
940 if (strcasecmp(CurrentString
, "Set") == 0)
941 return PerformSetCommand();
942 if (strcasecmp(CurrentString
, "New") == 0)
943 return PerformNewCommand();
944 if (strcasecmp(CurrentString
, "InfBegin") == 0)
945 return PerformInfBeginCommand();
946 if (strcasecmp(CurrentString
, "InfEnd") == 0)
947 return PerformInfEndCommand();
949 return CAB_STATUS_FAILURE
;
953 unsigned long CDFParser::PerformFileCopy()
955 * FUNCTION: Performs a file copy
957 * Status of operation
960 unsigned long Status
;
963 char SrcName
[MAX_PATH
];
964 char DstName
[MAX_PATH
];
965 char InfLine
[MAX_PATH
];
970 i
= strlen(CurrentString
);
971 while ((i
< LineLength
) &&
972 ((ch
= Line
[i
]) != ' ') &&
975 CurrentString
[i
] = ch
;
978 CurrentString
[i
] = '\0';
979 CurrentToken
= TokenString
;
981 strcpy(SrcName
, CurrentString
);
985 if (CurrentToken
!= TokenEnd
) {
986 j
= strlen(CurrentString
); i
= 0;
987 while ((CurrentChar
+ i
< LineLength
) &&
988 ((ch
= Line
[CurrentChar
+ i
]) != ' ') &&
991 CurrentString
[j
+ i
] = ch
;
994 CurrentString
[j
+ i
] = '\0';
995 CurrentToken
= TokenString
;
996 CurrentChar
+= i
+ 1;
997 strcpy(DstName
, CurrentString
);
1000 if (!CabinetCreated
) {
1002 DPRINT(MID_TRACE
, ("Creating cabinet.\n"));
1004 Status
= NewCabinet();
1005 if (Status
!= CAB_STATUS_SUCCESS
) {
1006 DPRINT(MIN_TRACE
, ("Cannot create cabinet (%d).\n", (unsigned int)Status
));
1007 printf("Cannot create cabinet.\n");
1008 return CAB_STATUS_FAILURE
;
1010 CabinetCreated
= true;
1012 DPRINT(MID_TRACE
, ("Creating disk.\n"));
1015 if (Status
!= CAB_STATUS_SUCCESS
) {
1016 DPRINT(MIN_TRACE
, ("Cannot create disk (%d).\n", (unsigned int)Status
));
1017 printf("Cannot create disk.\n");
1018 return CAB_STATUS_FAILURE
;
1024 DPRINT(MID_TRACE
, ("Adding file: '%s' destination: '%s'.\n", SrcName
, DstName
));
1026 sprintf(InfLine
, "%s=%s", GetFileName(SrcName
), DstName
);
1027 WriteInfLine(InfLine
);
1029 Status
= AddFile(SrcName
);
1030 if (Status
!= CAB_STATUS_SUCCESS
) {
1031 if (Status
== CAB_STATUS_CANNOT_OPEN
)
1032 printf("File does not exist: %s.\n", SrcName
);
1033 else if (Status
== CAB_STATUS_NOMEMORY
)
1034 printf("Insufficient memory to add file: %s.\n", SrcName
);
1036 printf("Cannot add file: %s (%d).\n", SrcName
, Status
);
1040 return CAB_STATUS_SUCCESS
;
1044 void CDFParser::SkipSpaces()
1046 * FUNCTION: Skips any spaces in the current line
1050 while (CurrentToken
== TokenSpace
)
1055 bool CDFParser::IsNextToken(TOKEN Token
, bool NoSpaces
)
1057 * FUNCTION: Checks if next token equals Token
1059 * Token = Token to compare with
1060 * SkipSp = true if spaces should be skipped
1062 * false if next token is diffrent from Token
1069 return (CurrentToken
== Token
);
1073 bool CDFParser::ReadLine()
1075 * FUNCTION: Reads the next line into the line buffer
1077 * true if there is a new line, false if not
1083 if (CurrentOffset
>= FileBufferSize
)
1087 while (((j
= CurrentOffset
+ i
) < FileBufferSize
) && (i
< 127) &&
1088 ((ch
= FileBuffer
[j
]) != 0x0D && (ch
= FileBuffer
[j
]) != 0x0A)) {
1096 if ((FileBuffer
[CurrentOffset
+ i
] == 0x0D) && (FileBuffer
[CurrentOffset
+ i
+ 1] == 0x0A))
1099 CurrentOffset
+= i
+ 1;
1111 void CDFParser::NextToken()
1113 * FUNCTION: Reads the next token from the current line
1119 if (CurrentChar
>= LineLength
) {
1120 CurrentToken
= TokenEnd
;
1124 switch (Line
[CurrentChar
]) {
1126 case 0x09: CurrentToken
= TokenSpace
;
1128 case ';': CurrentToken
= TokenSemi
;
1130 case '=': CurrentToken
= TokenEqual
;
1132 case '.': CurrentToken
= TokenPeriod
;
1134 case '\\': CurrentToken
= TokenBackslash
;
1138 while ((CurrentChar
+ i
+ 1 < LineLength
) &&
1139 ((ch
= Line
[CurrentChar
+ i
+ 1]) != '"')) {
1140 CurrentString
[i
] = ch
;
1143 CurrentString
[i
] = '\0';
1144 CurrentToken
= TokenString
;
1145 CurrentChar
+= i
+ 2;
1149 while ((CurrentChar
+ i
< LineLength
) &&
1150 ((ch
= Line
[CurrentChar
+ i
]) >= '0') && (ch
<= '9')) {
1151 CurrentString
[i
] = ch
;
1155 CurrentString
[i
] = '\0';
1156 CurrentInteger
= atoi((char*)CurrentString
);
1157 CurrentToken
= TokenInteger
;
1162 while (((CurrentChar
+ i
< LineLength
) &&
1163 (((ch
= Line
[CurrentChar
+ i
]) >= 'a') && (ch
<= 'z')) ||
1164 ((ch
>= 'A') && (ch
<= 'Z')) || (ch
== '_'))) {
1165 CurrentString
[i
] = ch
;
1169 CurrentString
[i
] = '\0';
1170 CurrentToken
= TokenIdentifier
;
1174 CurrentToken
= TokenEnd
;