Writing a File Parser

File parsers should be contained in a set of source and include files as follows, where XXX represents a mnemonic for the data format. For specific examples, see the sample ASCII filter files identified in the following table.

Generic file name
Contents
Sample ASCII filter file
VS_XXX.C
Code
VS_ASC.C
VSD_XXX.C
Data
VSD_ASC.C
VS_XXX.H
Type definitions
VS_ASC.H
VSP_XXX.H
Portability information
VSP_ASC.H

The portability information file makes porting of filters platforms easier. To allow file parsers to be used for content indexing, a set of include files is provided that will allow conditional compilations to yield executable DLLs for all of these needs from the same set of source files.

Your VSP_XXX.H file should look something like the following. (For further information, see the corresponding ASCII filter file.)

  • The structure type and name of the static data.

#define VwStreamStaticType ???
#define VwStreamStaticName ???

The parser must not change the contents of the structure, because it is shared among all instances of the parser.

  • The structure type and name of the dynamic data.

#define VwStreamDynamicType ???
#define VwStreamDynamicName ???

VwStreamDynamicName is for consistency and has no real use, because all dynamic data is accessed through the pseudonym Proc. Each instance of the parser has a separate copy of dynamic data.

  • The structure type and name of the save data.

#define VwStreamSaveType ???
#define VwStreamSaveName ???

VwStreamSaveName should reference an element in the VwStreamDynamicType structure. The data in this structure is saved after every call to VwStreamSectionFunc and VwStreamReadFunc and restored before every call to VwStreamReadFunc.

  • The structure type and name of the section data.

#define VwStreamSectionType ???
#define VwStreamSectionName ???

If neither of these is defined, the file parser is assumed to be single section only. VwStreamSectionName should reference an element in the VwStreamDynamicType structure. The data in this structure is saved after each call to VwStreamSectionFunc and is guaranteed to contain the current section's data on entry to VwStreamReadFunc.

This example shows the relationship of the various save areas to the dynamic data structure.

typedef struct {
...
} VwStreamSaveType;
typedef struct {
...
} VwStreamSectionType;
typedef struct {
...
VwStreamSectionType VwStreamSectionName; // multisection only
VwStreamSaveType VwStreamSaveName;
} VwStreamDynamicType;

  • The stream identifier name and count.

#define VwStreamIdName ???
#define VwStreamIdCount ???

VwStreamIdName is the name of the FILTER_DESC array in VSD_XXX.C, and VwStreamIdCount is the number of elements in this array. Like the static data, this data should never be changed by a parser.

  • The name of the include file. All the structure types used by the parser should be defined in this file.

#define VwInclude "vs_xxx.h"
#define VwStreamUserSaveType ???
#define VwStreamGenSeekName ???
#define VwStreamOpenFunc xxx_stream_open
#define VwStreamSeekFunc xxx_stream_seek
#define VwStreamTellFunc xxx_stream_tell
#define VwStreamReadFunc xxx_stream_read
#define VwStreamReadRecordFunc xxx_stream_readrecord
#define VwStreamSectionFunc xxx_stream_section
#define VwStreamCloseFunc xxx_stream_close
#define VwGetInfoFunc xxx_getinfo
#define VwGetRtnsFunc xxx_getrtns
#define VwGetDataFunc xxx_getdata
#define VwSetDataFunc xxx_setdata
#define VwAllocProcFunc xxx_alloc_proc
#define VwFreeProcFunc xxx_free_proc
#define VwLocalUpFunc xxx_local_up
#define VwLocalDownFunc xxx_local_down
#define VwGetSectionDataFunc xxx_getsectiondata
#define VwSetSectionDataFunc xxx_setsectiondata

  • The top of the VS_XXX.C file should look like this.

#include "VSP_XXX.H"
#include "VSCTOP.H"
#include "VS_XXX.PRO"

Software for developers
Delphi Components
.Net Components
Software for Android Developers
More information resources
MegaDetailed.Net
Unix Manual Pages
Delphi Examples
Databases for Amazon shops developers
Amazon Categories Database
Browse Nodes Database