Created program with params
This commit is contained in:
66
server/cardnet.cpp
Normal file
66
server/cardnet.cpp
Normal file
@@ -0,0 +1,66 @@
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include "argh.h"
|
||||
|
||||
void exampleMessage();
|
||||
|
||||
int main (int argc, char* argv[])
|
||||
{
|
||||
std::string file, check;
|
||||
//std::string check = "" ;
|
||||
int port = 0;
|
||||
|
||||
argh::parser cmdl;
|
||||
cmdl.parse(argc, argv, argh::parser::PREFER_PARAM_FOR_UNREG_OPTION);
|
||||
|
||||
if(cmdl["-h"]) // help
|
||||
{
|
||||
exampleMessage();
|
||||
}
|
||||
|
||||
for(auto& param: cmdl.params())
|
||||
{
|
||||
if(!param.first.compare("f")) // card0 file
|
||||
{
|
||||
file = param.second;
|
||||
}
|
||||
if(!param.first.compare("c")) // checker file
|
||||
{
|
||||
check = param.second;
|
||||
}
|
||||
if(!param.first.compare("p")) // port
|
||||
{
|
||||
try
|
||||
{
|
||||
port = stoi(param.second); // convert to int
|
||||
if (port < 1 || port > 65535) // validate port number
|
||||
exampleMessage();
|
||||
}
|
||||
catch (std::invalid_argument)
|
||||
{
|
||||
exampleMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(file == "" || check == "" || port == 0)
|
||||
exampleMessage();
|
||||
|
||||
std::cout << "File:\t" << file << std::endl;
|
||||
std::cout << "Check:\t" << check << std::endl;
|
||||
std::cout << "Port:\t" << port << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void exampleMessage()
|
||||
{
|
||||
std::cout << "Availble options:" << std::endl;
|
||||
std::cout << " -f\tLocation of card0.txt file" << std::endl;
|
||||
std::cout << " -c\tLocation of check file" << std::endl;
|
||||
std::cout << " -p\tPort number to listen on (1-65535)" << std::endl;
|
||||
std::cout << std::endl << "Example usage: cardnet.exe -f G:\\card0.txt -c G:\\check.txt -p 4500" << std::endl;
|
||||
exit(0);
|
||||
|
||||
}
|
Reference in New Issue
Block a user