Skip to content

Commit

Permalink
Merge pull request #16 from meeh420/master
Browse files Browse the repository at this point in the history
Adding lightweight option parser
  • Loading branch information
orignal committed Jan 30, 2014
2 parents 611ab9c + 3b3f5d0 commit 3ad76e2
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ CC = g++
CFLAGS = -g -Wall -std=c++0x
OBJECTS = i2p.o base64.o NTCPSession.o RouterInfo.o Transports.o RouterContext.o \
NetDb.o LeaseSet.o Tunnel.o TunnelEndpoint.o TunnelGateway.o TransitTunnel.o \
I2NPProtocol.o Log.o Garlic.o HTTPServer.o Streaming.o Identity.o SSU.o
I2NPProtocol.o Log.o Garlic.o HTTPServer.o Streaming.o Identity.o SSU.o util.o
INCFLAGS =
LDFLAGS = -Wl,-rpath,/usr/local/lib -lcryptopp -lboost_system -lboost_filesystem -lpthread
LIBS =
Expand Down
1 change: 1 addition & 0 deletions RouterContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <cryptopp/dsa.h>
#include "CryptoConst.h"
#include "RouterContext.h"
#include "util.h"

namespace i2p
{
Expand Down
9 changes: 6 additions & 3 deletions i2p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,21 @@
#include "Tunnel.h"
#include "NetDb.h"
#include "HTTPServer.h"
#include "util.h"

int main( int, char** )
int main( int argc, char* argv[] )
{

i2p::util::ParseArguments(argc,argv);
#ifdef _WIN32
setlocale(LC_CTYPE, "");
SetConsoleCP(1251);
SetConsoleOutputCP(1251);
setlocale(LC_ALL, "Russian");
#endif

i2p::util::HTTPServer httpServer (7070);
int httpport = i2p::util::GetIntArg("--httpport", 7070);

i2p::util::HTTPServer httpServer (httpport);

httpServer.Start ();
i2p::data::netdb.Start ();
Expand Down
45 changes: 45 additions & 0 deletions util.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
#include "util.h"

namespace i2p
{
namespace util
{
std::map<std::string, std::string> mapArgs;

void ParseArguments(int argc, const char* const argv[])
{
mapArgs.clear();
for (int i = 1; i < argc; i++)
{
std::string strKey (argv[i]);
std::string strValue;
size_t has_data = strKey.find('=');
if (has_data != std::string::npos)
{
strValue = strKey.substr(has_data+1);
strKey = strKey.substr(0, has_data);
}
if (strKey[0] != '-')
break;

mapArgs[strKey] = strValue;
}
}

int GetIntArg(const std::string& strArg, int nDefault)
{
if (mapArgs.count(strArg))
return atoi(mapArgs[strArg].c_str());
return nDefault;
}

std::string GetStringArg(const std::string& strArg, std::string nDefault)
{
if (mapArgs.count(strArg))
return mapArgs[strArg];
return nDefault;
}


} // Namespace end
}
19 changes: 19 additions & 0 deletions util.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#ifndef UTIL_H
#define UTIL_H

#include <map>
#include <string>

namespace i2p
{
namespace util
{
extern std::map<std::string, std::string> mapArgs;
void ParseArguments(int argc, const char* const argv[]);
int GetIntArg(const std::string& strArg, int nDefault);

}
}


#endif

0 comments on commit 3ad76e2

Please sign in to comment.