ASCII File Parser

Anyone know where I can get my hands on some public domain source code for a
generic ASCII file parser for files in the general format below

[context1]
parameter1=parametervalue
parameter2=parametervalue

[context2]
parameter1=parametervalue



It wouldn’t be too hard to write one, but I’m looking for every possible
development time saving I can get on this project.

Chris Rose wrote:

Anyone know where I can get my hands on some public domain source code for a
generic ASCII file parser for files in the general format below

[context1]
parameter1=parametervalue
parameter2=parametervalue

[context2]
parameter1=parametervalue

Built into the photon libs. See PxConfig* in the online help

Rennie

I have a rather slick C++ class library for read/writing tag files.


Bill Caroselli – 1(626) 824-7983
Q-TPS Consulting
QTPS@EarthLink.net


“Chris Rose” <rose_chris@excite.com> wrote in message
news:a78sp9$mhs$1@inn.qnx.com

Anyone know where I can get my hands on some public domain source code for
a
generic ASCII file parser for files in the general format below

[context1]
parameter1=parametervalue
parameter2=parametervalue

[context2]
parameter1=parametervalue



It wouldn’t be too hard to write one, but I’m looking for every possible
development time saving I can get on this project.

Hi Chris,

Don’t know if you still need some code to parse such file, but I join a
a func for it.
Today, I have no English doc but it’s quite simple and allow to analyse
indexed sections but not indexed keys such as parameter1, parameter2.

this done like that:

[GLOBAL]
number of context = 3

[CONTEXT#1]
a parameter = 1
another parameter = YES
a third parameter = 1.0

[CONTEXT#2]
a parameter = 2
another parameter = NO
a third parameter = 1.0

[CONTEXT#1]
a parameter = 1000
another parameter = NONE
a third parameter = 1.5


To declare the sections and parameters analysis, feel these structure:
const char *yes_no_enum[3] = {
“YES”,
“NO”,
“NONE”
};

// table of sections
const struct misc_cfg_section_datas
context_section_table[CONTEXT_SECTION_TABLE_SIZ] = {
{“GLOBAL”, GLOBAL_SECTION_SIZ, (struct misc_cfg_param_datas
*)global_table},
{“CONTEXT#”, CONTEXT_SECTION_SIZ, (struct misc_cfg_param_datas
*)context_table},
};

// table of GLOBAL keys
const struct misc_cfg_param_datas global_table[] = { // parameters tab
for the global section
{“number of context”, T_INT, (union misc_cfg_data_element)(-1),
(union misc_cfg_data_element *)&globalstruct.context_number, 0, (char
**)NULL, 0},
};

// table of CONTEXT keys
struct misc_cfg_param_datas context_table[] = { // parameters tab for
the motor section
{“a parameter”, T_INT, (union misc_cfg_data_element)(-1), (union
misc_cfg_data_element *)NULL, sizeof(context_t), (char **)NULL, 0},
{“a second parameter”, T_ENUM, (union misc_cfg_data_element)(2),
(union misc_cfg_data_element *)NULL, sizeof(context_t), (char
**)yes_no_enum, 3},
{“a third parameter”, T_DOUBLE, (union misc_cfg_data_element)(1.0),
(union misc_cfg_data_element *)NULL, sizeof(context_t), (char **)NULL, 0},
};

In your code, do:
misc_analyseGLOBAL((char *)configfile, (struct
misc_cfg_section_datas context_section_table(int)CONTEXT_SECTION_TABLE_SIZ);

After you need to allocate some memory space depending on the number of
sections you have.
ptr = calloc(globalstruct.context_number, sizeof(context_t));

and initialyse the correct storage pointer.
context_table[0].psave = (union misc_cfg_data_element
*)&(context_struct[0].first_field);
context_table[1].psave = (union misc_cfg_data_element
*)&(context_struct[0].second_field);
context_table[2].psave = (union misc_cfg_data_element
*)&(context_struct[0].last_field);

then you can analyse all the sections like that:
misc_configFileAnalyse((char *)configfile, (struct
misc_cfg_section_datas *)context_section_table,
(int)CONTEXT_SECTION_TABLE_SIZ);


I hope that I didn’t do to many errors in this email as I wrote it very
quickly.
I can give you more precise infos if you are interested.

cheers,
Alain.
Chris Rose wrote:

Anyone know where I can get my hands on some public domain source code for a
generic ASCII file parser for files in the general format below

[context1]
parameter1=parametervalue
parameter2=parametervalue

[context2]
parameter1=parametervalue



It wouldn’t be too hard to write one, but I’m looking for every possible
development time saving I can get on this project.