Skip to content

Instantly share code, notes, and snippets.

@JakubOboza
Created December 7, 2008 09:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JakubOboza/33072 to your computer and use it in GitHub Desktop.
Save JakubOboza/33072 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <pcrecpp.h>
#include <string>
#include <map>
#include <fstream>
#define LINE_SIZE 256
typedef std::map<std::string,std::string> Hash;
int main(int argc,char** argv){
if(argc != 2)
{
std::cout<<"Usage: configlol <configfile>"<<std::endl;
return -1;
}
std::string filename(argv[1]);
std::fstream file(filename.c_str());
std::string var, val;
pcrecpp::RE re("(\\w+):\\s+(.+)");
Hash config;
while( !file.eof() ){
char line[LINE_SIZE] = "" ;
file.getline(line,LINE_SIZE);
re.FullMatch( line , &var, &val);
config[var] = val ;
}
// config["name"]
for(Hash::iterator p = config.begin() ; p != config.end(); p++)
{
std::cout << p->first << " : " << p->second << std::endl;
}
return 1;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment