ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
If you find the solution inadequate, I'd worry first about making the data format more sophisticated (for example, going to XML instead of flat file) before I'd worry about a more sophisticated library.
But from everything you've said: a flat file sounds fine, and fgets()/strcmp() is the ideal way to parse that flat file.
If you find the solution inadequate, I'd worry first about making the data format more sophisticated (for example, going to XML instead of flat file) before I'd worry about a more sophisticated library.
But from everything you've said: a flat file sounds fine, and fgets()/strcmp() is the ideal way to parse that flat file.
IMHO .. PSM
yeh id agree.. regex would be nice but is a bit of an overkill.. you already know the format of the file, so it should not be too hard to write a small lib that parses that format..
yeh id agree.. regex would be nice but is a bit of an overkill.. you already know the format of the file, so it should not be too hard to write a small lib that parses that format..
Unless the format is ridiculously simple, regex can not only aid in parsing the file, but also validate the token data, all in one fell swoop.
And did you consider what acceptable values 'name' can hold? Apps written to be robust and secure will not just swallow whatever external data fed to it. This is where regex is handy.
im not disputing anything about regexs.. i am simply suggesting that if the configuration file is simple, then it will may be easier to implement your own parsing without regex..
do you have an example of using regexs easily with C89? i mean you suggested boost, and then came back with nothing helpful in the way of C89? i know regexes are great and i use them all the time, well that is when they are actually going to save me time..
im not disputing anything about regexs.. i am simply suggesting that if the configuration file is simple, then it will may be easier to implement your own parsing without regex..
do you have an example of using regexs easily with C89? i mean you suggested boost, and then came back with nothing helpful in the way of C89? i know regexes are great and i use them all the time, well that is when they are actually going to save me time..
Read properly, I mentioned pcre. While not part of the std lib, it is widely ported on many platforms.
If C++ and boost is an option then I suggest boost.program_options library instead of boost.regex.
From boost.program_options documentation
Quote:
Introduction
The program_options library allows program developers to obtain program options, that is (name, value) pairs from the user, via conventional methods such as command line and config file.
Why would you use such a library, and why is it better than parsing your command line by straightforward hand-written code?
* It's easier. The syntax for declaring options is simple, and the library itself is small. Things like conversion of option values to desired type and storing into program variables are handled automatically.
* Error reporting is better. All the problems with the command line are reported, while hand-written code can just misparse the input. In addition, the usage message can be automatically generated, to avoid falling out of sync with the real list of options.
* Options can be read from anywhere. Sooner or later the command line will be not enough for your users, and you'll want config files or maybe even environment variables. These can be added without significant effort on your part.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.