I don't know if this topic fits in here or not, but lets get cracking...

Okay, I have this file called config.cfg that is 'kinda like windows inf/ini files. It stores all the user settings(stuff like, username, password, privlages, date last accessed etc). This file can not be edited by users.

Now the problem is, I need to parse the file for a spesific value, like the value 'username=root'. I need to search for "username=" and then get its value.

I can read a value from that file into a variable by reading the first line of the file by doing "volReadFile(&fname,<variable name>, 16);". This reads the first line of the file into a c++ variable, but the file then only contains the term "root" - wich is what i want, but what about multiple values.

It is recommended to read the entire file into a buffer and parse it using more traditional methods. Then we can write a function similar to GetProfileString() that would look through the buffer watching for matching tokens to locate where a section starts and a matching key name within that section. With a basic lexer the actual parsing becomes much easier. This would allow you to call a single routine to obtain any setting from the configuration file.

Sorry I did not look at it this way. It would be very kind of you to give an example!

That code I used, was basically just to see if I can read text from a file into a variable and use it in the rest of the kernel as a conditional. But now that I go through the code again, I saw that it is already being done(read text file into buffer variable).

So then the file would be similar to an XML file? That would be cool! It will also make it a lot easier storing multiple variables.

Thanx again!!!!

Regards.

The Anti-Microsoft revolution has begun, and soon Apple will take over the universe. The world is primed for war - someone should just take the first blow.

I recommend writing the parser in a user mode environment first so you can utilize better debuggers. You do not technically need a lexer, but it does help out.

The goal of the lexer is to convert a buffer of data into tokens that can be easily parsed by the syntax analyzer. For example, the lexer can accept the buffer as input and output an array of tokens. (The lexer can also skip comments and whitespace.) A token can look something like this:

Your current lexer source looks alright so far. In order to continue, you need to keep track of your current position in the buffer and loop through each character, skipping whitespace. The loop will also need to look at the characters it encounters to see what type of token it is. For example, if the token is a 'a' we can assume its a CHAR token. If its a '1' we can assume its a INT token. This is a simplification though because it does not take into consideration cases like "ab12". This is easy to fix though by just looking at the following character after the current one being looked at.

Sorry, I have not had the time to work on a working example yet. If it is still requested, Ill see about providing it this weekend.

Thanks mike, that was very helpful and it made a few thinks more clear. I will start working on it as soon as possible and give updates, although I would still like a working example if it is not too much work. And I am in no rush so, take your time.

Again, thanks!Jean-Pierre:

The Anti-Microsoft revolution has begun, and soon Apple will take over the universe. The world is primed for war - someone should just take the first blow.