Logo
~Sockets~
~Examples~
~Contact~


config.cpp File Reference

#include <stdio.h>
#include "Parse.h"
#include "config.h"

Include dependency graph for config.cpp:

Go to the source code of this file.


Defines

#define C   slask[strlen(slask) - 1]

Functions

static void read_config (const std::string &filename)
void write_config ()
void parse_config (int argc, char *argv[], const std::string &filename)

Variables

config_m config
static std::string config_filename

Define Documentation

#define C   slask[strlen(slask) - 1]

Definition at line 28 of file config.cpp.

Referenced by read_config().


Function Documentation

void parse_config ( int  argc,
char *  argv[],
const std::string &  filename 
)

Definition at line 80 of file config.cpp.

References config, read_config(), and write_config().

Referenced by main().

00081 {
00082         read_config( filename );
00083         for (int i = 1; i < argc; i++)
00084                 if (argv[i][0] == '-' && i < argc - 1)
00085                 {
00086                         config[argv[i] + 1] = argv[i + 1];
00087                         i++;
00088                 }
00089         write_config(); // filename );
00090 }

static void read_config ( const std::string &  filename  )  [static]

Definition at line 37 of file config.cpp.

References C, config, and config_filename.

Referenced by parse_config().

00038 {
00039         FILE *fil = fopen(filename.c_str(),"rt");
00040         config_filename = filename;
00041         if (fil)
00042         {
00043                 char slask[1000];
00044                 std::string key;
00045                 std::string value;
00046                 fgets(slask,1000,fil);
00047                 while (!feof(fil))
00048                 {
00049                         while (strlen(slask) && (C == 13 || C == 10))
00050                                 C = 0;
00051                         Parse pa(slask);
00052                         pa.getword(key);
00053                         pa.getrest(value);
00054                         config[key] = value;
00055                         //
00056                         fgets(slask,1000,fil);
00057                 }
00058                 fclose(fil);
00059         }
00060 }

void write_config (  ) 

Definition at line 63 of file config.cpp.

References config, and config_filename.

Referenced by parse_config().

00064 {
00065         FILE *fil = fopen(config_filename.c_str(),"wt");
00066         if (fil)
00067         {
00068                 for (config_m::iterator it = config.begin(); it != config.end(); it++)
00069                 {
00070                         std::string key = (*it).first;
00071                         std::string value = (*it).second;
00072                         if (key[0] != '.')
00073                                 fprintf(fil,"%s %s\n",key.c_str(),value.c_str());
00074                 }
00075                 fclose(fil);
00076         }
00077 }


Variable Documentation

Definition at line 33 of file config.cpp.

Referenced by parse_config(), read_config(), and write_config().

std::string config_filename [static]

Definition at line 34 of file config.cpp.

Referenced by read_config(), and write_config().

Page, code, and content Copyright (C) 2006 by Anders Hedström
Generated on Mon Aug 29 20:21:47 2005 for C++ Sockets by  doxygen 1.4.4