Click here to Skip to main content
12,630,137 members (23,075 online)
Click here to Skip to main content

Stats

70.9K views
1.2K downloads
43 bookmarked
Posted

INI file reader using the spirit library

, 3 Jan 2006 CPOL
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
| Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.161205.3 | Last Updated 3 Jan 2006
Article Copyright 2006 by Silviu Simen
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid