home *** CD-ROM | disk | FTP | other *** search
- // PARSE.C -- The code to parse .INF blocks into their respective
- // data strcutures
-
- /*****************************************************************************
-
- Functions:
- ------------------------------------------------------------------------------
-
- JunkCharacter Returns TRUE if this is a white space char.
-
- LoadLine Copies a single line from the cached .INF
- section into the Line array. Max 132 chars.
-
- ParseLine Takes the next DoubleQuote delimited token
- from the Line array.
-
- AddDiskInfo These routines fill the DiskInfo data structure
- FillDiskInfoStructures [disks]
-
- SetFlags These routines fill the FileInfo data structure
- AddFileInfo [apps]
- FillFileInfoStructures
-
- AddDirInfo These routines fill the DirInfo data structure
- FillDirInfoStructures [directories]
-
- AddProgmanInfo These routines fill the PManInfo data strcutures
- FillProgmanInfoStructures [progman]
-
- TokenValue These routines fill the miscelleneous data
- FillGlobalInfoStructures strucutres. [setup]
-
- *****************************************************************************/
-
-
- #include <windows.h>
- #include <stdio.h>
- #include "bincode.h"
-
- LPSTR szCurrentBuffer; // Points to the current line
- char Line[132]; // Holds the current line
-
- /********************************************************************/
- BOOL JunkCharacter ( char Letter )
- {
- // Returns TRUE if character is whitespace.
-
-
- switch ( Letter )
- {
- case ' ' :
- case '\t':
- case 10 :
- case 13 : return TRUE;
- default : return FALSE;
- }
- }
- /********************************************************************/
- BOOL LoadLine (void)
- {
- // returns TRUE if line loaded, FALSE if EOF
-
- BOOL ValidLine = TRUE;
- int LineIndex = 0;
-
- // This will load in the next non-comment line
-
- // First, skip the spaces and CR/LF's, and comments
-
- do
- {
- while (JunkCharacter(*szCurrentBuffer) && (*szCurrentBuffer)) szCurrentBuffer++;
-
- if (!(*szCurrentBuffer)) return FALSE;
-
- ValidLine = TRUE;
- if (';' == *szCurrentBuffer)
- {
- ValidLine = FALSE;
- while (*szCurrentBuffer != 13) szCurrentBuffer++; // skip to EOLN
- }
- }
- while (!ValidLine);
-
- do
- {
- Line[LineIndex] = *szCurrentBuffer;
- szCurrentBuffer++;
- LineIndex++;
- }
- while ((*szCurrentBuffer) && (*szCurrentBuffer != 13));
-
- // Even if this is EOF, nect call with return the false OK.
-
- Line[LineIndex] = 0;
-
- return TRUE;
- }
- /********************************************************************/
- void ParseLine ( char *DestBuffer, int *Index )
- {
- // This will grab the next QUOTED string
-
- *DestBuffer = 0;
-
- // Move to the first quote;
-
- while (( Line[*Index] ) && (Line[*Index] != '\"')) (*Index)++;
-
- if (!(Line[*Index])) return; // NULL String, item doesn't exist
-
- (*Index)++; // Start at next character
-
- while (( Line[*Index] ) && (Line[*Index] != '\"'))
- {
- *DestBuffer = Line[*Index];
- DestBuffer++;
- (*Index)++;
- }
-
- *DestBuffer = 0; // Add a terminating char
- if (*Index) (*Index)++; // Advance over ending quote if possible
- }
- /********************************************************************/
- void AddDiskInfo ( void )
- {
- // This will parse out whatever is in Line, and add it to
- // the DISKINFO structure...
-
- int LineIndex;
- char Item[80];
-
- LineIndex = 0;
-
- ParseLine ( Item, &LineIndex );
- DiskInfo[NumDisks].DiskNumber = *Item;
- ParseLine ( DiskInfo[NumDisks].szSrcDir, &LineIndex );
- ParseLine ( DiskInfo[NumDisks].szDiskTitle, &LineIndex );
- NumDisks++;
- }
- /********************************************************************/
- /* */
- /* FillDiskInfoStructures (void) */
- /* */
- /* This routine reads the [disks] section and fills the */
- /* structures appropriately. */
- /* */
- /********************************************************************/
- void FillDiskInfoStructures ( void )
- {
-
- NumDisks = 0;
-
- hBuffer = GlobalAlloc ( GMEM_MOVEABLE | GMEM_ZEROINIT, SECTIONSIZE+1 );
-
- PositionInfPointer ( (LPSTR)"disks" );
-
- szCurrentBuffer = GlobalLock ( hBuffer );
-
- while ( LoadLine()) AddDiskInfo (); // Fill the structrures
-
- GlobalUnlock ( hBuffer );
- GlobalFree ( hBuffer );
- }
- /********************************************************************/
- void SetFlags ( char *Item, int *ListBoxIndex )
- {
- // Defaults...
-
- #ifdef COMPLEXSETUP
- FileInfo[NumFiles].bSelected = FALSE;
- #endif
- #ifdef SIMPLESETUP
- FileInfo[NumFiles].bSelected = TRUE;
- #endif
- FileInfo[NumFiles].bInvisible = TRUE;
- FileInfo[NumFiles].bProgmanIcon = FALSE;
- FileInfo[NumFiles].ExtraFiles = 0;
- FileInfo[NumFiles].bCompressed = FALSE;
-
- while (*Item)
- {
- switch (toupper(*Item))
- {
- case 'R': FileInfo[NumFiles].bSelected = TRUE;
- Item++;
- break;
-
- case 'C': FileInfo[NumFiles].bCompressed = TRUE;
- Item++;
- break;
-
- case 'D': (*ListBoxIndex)++;
- FileInfo[NumFiles].bInvisible = FALSE;
- Item++;
- break;
-
- case 'I': FileInfo[NumFiles].bProgmanIcon = TRUE;
- Item++;
- FileInfo[NumFiles].ProgmanGroupNumber = *Item;
- Item++;
- break;
-
- case '0':
- case '1':
- case '2':
- case '3':
- case '4':
- case '5':
- case '6':
- case '7':
- case '8':
- case '9': FileInfo[NumFiles].ExtraFiles = ((*Item)-'0') * 10;
- Item++;
- FileInfo[NumFiles].ExtraFiles = ((*Item)-'0');
- Item++;
- break;
-
- default : Item++; break; // Skip over bogus flags
-
- } // switch
- } // while
- }
- /********************************************************************/
- void AddFileInfo ( int *ListBoxIndex )
- {
- // This will parse out whatever is in Line, and add it to
- // the FILEINFO structure...
-
- int LineIndex;
- char Item[80];
-
- LineIndex = 0;
-
- ParseLine ( Item, &LineIndex );
- FileInfo[NumFiles].DiskNumber = *Item;
-
- ParseLine ( Item, &LineIndex ); // Get the Flags
- SetFlags ( Item, ListBoxIndex ); // Go figure them out!
-
- FileInfo[NumFiles].Index = *ListBoxIndex;
-
- ParseLine ( Item, &LineIndex ); // Get the Flags
- FileInfo[NumFiles].DirectoryNumber = *Item;
-
- ParseLine ( FileInfo[NumFiles].szMasterSrcDir, &LineIndex );
- ParseLine ( FileInfo[NumFiles].szFileName, &LineIndex );
- ParseLine ( FileInfo[NumFiles].szProgManName, &LineIndex );
- ParseLine ( FileInfo[NumFiles].szDescription, &LineIndex );
-
- if ((!FileInfo[NumFiles].szDescription[0]) && (NumFiles))
- sprintf (FileInfo[NumFiles].szDescription,FileInfo[NumFiles-1].szDescription);
-
- ParseLine ( FileInfo[NumFiles].szComment, &LineIndex );
-
- ParseLine ( Item, &LineIndex ); // Get the Flags
- FileInfo[NumFiles].BytesRequired = (LONG)atoi(Item)*1024L;
-
- NumFiles++;
- }
- /********************************************************************/
- /* */
- /* FillFileInfoStructures (void) */
- /* */
- /* This routine reads the [apps] section and fills the FILEINFO */
- /* structures appropriately. */
- /* */
- /********************************************************************/
- void FillFileInfoStructures ( void )
- {
- int ListBoxIndex;
-
- NumFiles = 0;
- ListBoxIndex = -1;
-
- hBuffer = GlobalAlloc ( GMEM_MOVEABLE | GMEM_ZEROINIT, SECTIONSIZE+1 );
-
- PositionInfPointer ( (LPSTR)"apps" );
-
- szCurrentBuffer = GlobalLock ( hBuffer );
-
- while ( LoadLine()) AddFileInfo ( &ListBoxIndex ); // Fill the structures
-
- GlobalUnlock ( hBuffer );
- GlobalFree ( hBuffer );
- }
- /********************************************************************/
- void AddDirInfo ( void )
- {
- // This will parse out whatever is in Line, and add it to
- // the DIRINFO structure...
-
- // MEGA ASSUMTION!: We assume that the .INF file is set
- // up right, i.e. no gaps in the sequence
-
- int LineIndex;
- char Item[80];
- int DirNum;
-
- LineIndex = 0;
-
- ParseLine ( Item, &LineIndex );
-
- if ('0' == *Item)
- DirNum = 0;
- else
- DirNum = toupper(*Item) - 'A' + 1;
-
- NumDirs++;
-
- ParseLine ( DirInfo[DirNum].szDirectory, &LineIndex );
- ParseLine ( DirInfo[DirNum].szDescription, &LineIndex );
-
- }
- /********************************************************************/
- /* */
- /* FillDIrInfoStructures (void) */
- /* */
- /* This routine reads the [directories] section and fills the */
- /* DIRINFO structures appropriately. */
- /* */
- /********************************************************************/
- void FillDirInfoStructures ( void )
- {
- NumDirs = 0;
-
- hBuffer = GlobalAlloc ( GMEM_MOVEABLE | GMEM_ZEROINIT, SECTIONSIZE+1 );
-
- PositionInfPointer ( (LPSTR)"directories" );
-
- szCurrentBuffer = GlobalLock ( hBuffer );
-
- while ( LoadLine()) AddDirInfo ( ); // Fill the structures
-
- GlobalUnlock ( hBuffer );
- GlobalFree ( hBuffer );
- }
- /********************************************************************/
- void AddProgmanInfo ( void )
- {
- // This will parse out whatever is in Line, and add it to
- // the PMANINFO structure...
-
- // MEGA ASSUMTION!: We assume that the .INF file is set
- // up right, i.e. no gaps in the sequence
-
- int LineIndex;
- char Item[80];
- int GroupNum;
-
- LineIndex = 0;
-
- ParseLine ( Item, &LineIndex );
- GroupNum = toupper(*Item) - 'A';
-
- NumPManGroups++;
-
- ParseLine ( PManInfo[GroupNum].szCaption, &LineIndex );
- ParseLine ( PManInfo[GroupNum].szGroupFilename, &LineIndex );
- }
- /********************************************************************/
- /* */
- /* FillFileInfoStructures (void) */
- /* */
- /* This routine reads the [apps] section and fills the FILEINFO */
- /* structures appropriately. */
- /* */
- /********************************************************************/
- void FillProgmanInfoStructures ( void )
- {
- NumPManGroups = 0;
-
- hBuffer = GlobalAlloc ( GMEM_MOVEABLE | GMEM_ZEROINIT, SECTIONSIZE+1 );
-
- PositionInfPointer ( (LPSTR)"progman" );
-
- szCurrentBuffer = GlobalLock ( hBuffer );
-
- while ( LoadLine()) AddProgmanInfo ( ); // Fill the structures
-
- GlobalUnlock ( hBuffer );
- GlobalFree ( hBuffer );
- }
- /********************************************************************/
- int TokenValue ( char *Item )
- {
- if (!strcmp ( Item, "PACKAGENAME" )) return ID_PACKAGENAME;
- if (!strcmp ( Item, "CAPTIONNAME" )) return ID_CAPTIONNAME;
-
- return 0;
- }
- /********************************************************************/
- /* */
- /* FillGlobalInfoStructures (void) */
- /* */
- /* This routine reads the [setup] section and fills the global */
- /* structures appropriately. */
- /* */
- /********************************************************************/
- void FillGlobalInfoStructures ( void )
- {
- char Item[80];
- int LineIndex;
-
- NumPManGroups = 0;
-
- hBuffer = GlobalAlloc ( GMEM_MOVEABLE | GMEM_ZEROINIT, SECTIONSIZE+1 );
-
- PositionInfPointer ( (LPSTR)"setup" );
-
- szCurrentBuffer = GlobalLock ( hBuffer );
-
- while ( LoadLine())
- {
- LineIndex = 0;
-
- ParseLine ( Item, &LineIndex );
-
- switch ( TokenValue ( Item ))
- {
- case ID_PACKAGENAME : ParseLine (szPackageName, &LineIndex); break;
- case ID_CAPTIONNAME : ParseLine (szCaptionName, &LineIndex); break;
- default : break;
- }
- }
-
- GlobalUnlock ( hBuffer );
- GlobalFree ( hBuffer );
- }
-
-
-
-