Click here to Skip to main content
13,298,451 members (55,575 online)
Click here to Skip to main content

Stats

76.6K views
1.3K downloads
44 bookmarked
Posted 3 Jan 2006

INI file reader using the spirit library

, 3 Jan 2006
A simple implementation of an INI file reader using the boost::spirit framework
#pragma warning (disable : 4786)
#include <string>
#include <vector>
using namespace std;
#include "ini_file.h"

void usage(char ** argv)
{
	printf("\nUsage : %s ini_file\n", argv[0]);
}

void PrintIniFile(CIniFile &ifile)
{
	int i;
	for (i=0;i<ifile.GetNumCategories();i++)
	{
		ifile.SetCategory(i);
		printf("Cat %d = [%s]\n", i, ifile.GetCategoryName().c_str());
		int j;
		for (j=0;j<ifile.GetNumEntries();j++)
		{
			ifile.SetEntry(j);
			printf("Entry %d [%s]=[%s]\n", j, ifile.GetEntryName().c_str(), ifile.GetEntryValue().c_str());
		}
		printf("\n");
	}
}

int main(int argc, char ** argv)
{
	if (argc != 2)
	{
		usage(argv);
	}
	else
	{
		CIniFile ifile;
		ifile.LoadFile(argv[1]);

		switch (ifile.m_status)
		{
		case 0:
			PrintIniFile(ifile);
			break;
		case 1:
			printf("Cannot open input file !\n");
			break;
		case 2:
			printf("Some error occured while parsing input file !\n");
			PrintIniFile(ifile);
			break;
		default:
			break;
		}
	}

	return 0;
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Silviu Simen
Software Developer
Canada Canada
No Biography provided

You may also be interested in...

Pro
Pro
Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 3 Jan 2006
Article Copyright 2006 by Silviu Simen
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid