class Appl: changed command from required to not-required.
This commit is contained in:
+9
-17
@@ -107,25 +107,17 @@ void Appl::parseArgs(int argc, char* argv[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
// check command
|
// check command
|
||||||
if (m_needCommand == true) {
|
for (int i = 1; i < argc; i++) {
|
||||||
for (int i = 1; i < argc; i++) {
|
|
||||||
|
|
||||||
if (_argv[i].rfind("-", 0) != string::npos) {
|
if (_argv[i].rfind("-", 0) != string::npos) {
|
||||||
i++;
|
i++;
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
if (m_command.size() == 0)
|
|
||||||
m_command = _argv[i];
|
|
||||||
else
|
|
||||||
m_arguments.push_back(_argv[i]);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m_command.size() == 0) {
|
|
||||||
cerr << endl << "command needed" << endl;
|
|
||||||
printHelp();
|
|
||||||
}
|
}
|
||||||
|
if (m_command.size() == 0)
|
||||||
|
m_command = _argv[i];
|
||||||
|
else
|
||||||
|
m_arguments.push_back(_argv[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Appl::checkOption(const string& option, const string& value)
|
bool Appl::checkOption(const string& option, const string& value)
|
||||||
@@ -196,7 +188,7 @@ void Appl::printHelp()
|
|||||||
cerr << endl << "Usage:" << endl << " "
|
cerr << endl << "Usage:" << endl << " "
|
||||||
<< m_argv[0].substr(m_argv[0].find_last_of("/\\") + 1) << " [OPTIONS...]" ;
|
<< m_argv[0].substr(m_argv[0].find_last_of("/\\") + 1) << " [OPTIONS...]" ;
|
||||||
|
|
||||||
if (m_needCommand == true)
|
if (m_withCommand == true)
|
||||||
if (m_withArgument == true)
|
if (m_withArgument == true)
|
||||||
cerr << " COMMAND {ARGS...}" << endl << endl;
|
cerr << " COMMAND {ARGS...}" << endl << endl;
|
||||||
else
|
else
|
||||||
|
|||||||
+13
-8
@@ -175,6 +175,12 @@ public:
|
|||||||
* @return number of commands and arguments.
|
* @return number of commands and arguments.
|
||||||
*/
|
*/
|
||||||
int numArgs() const { return m_arguments.size(); }
|
int numArgs() const { return m_arguments.size(); }
|
||||||
|
/**
|
||||||
|
* @brief returns the string of an interested argument.
|
||||||
|
* @param num number of interested argument.
|
||||||
|
* @return the argument string.
|
||||||
|
*/
|
||||||
|
string getArg(const int num) const { return m_arguments[num]; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief returns the string of given command.
|
* @brief returns the string of given command.
|
||||||
@@ -183,11 +189,10 @@ public:
|
|||||||
string getCommand() const { return m_command; }
|
string getCommand() const { return m_command; }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief returns the string of an interested argument.
|
* @brief returns the string of given command.
|
||||||
* @param num number of interested argument.
|
* @return the command string.
|
||||||
* @return the argument string.
|
|
||||||
*/
|
*/
|
||||||
string getArg(const int num) const { return m_arguments[num]; }
|
bool missingCommand() const { return (m_command.size() == 0 ? true : false); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** private constructor - singleton pattern */
|
/** private constructor - singleton pattern */
|
||||||
@@ -197,7 +202,7 @@ private:
|
|||||||
* @param argument is true if command could have an argument.
|
* @param argument is true if command could have an argument.
|
||||||
*/
|
*/
|
||||||
Appl(const bool command, const bool argument)
|
Appl(const bool command, const bool argument)
|
||||||
: m_needCommand(command), m_withArgument(argument) {}
|
: m_withCommand(command), m_withArgument(argument) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief private copy construtor.
|
* @brief private copy construtor.
|
||||||
@@ -229,10 +234,10 @@ private:
|
|||||||
/** application version string */
|
/** application version string */
|
||||||
const char* m_version;
|
const char* m_version;
|
||||||
|
|
||||||
/** true if the application need a command */
|
/** true if the application could have a command */
|
||||||
bool m_needCommand;
|
bool m_withCommand;
|
||||||
|
|
||||||
/** true if the needed command could have an argument */
|
/** true if the command could have an argument */
|
||||||
bool m_withArgument;
|
bool m_withArgument;
|
||||||
|
|
||||||
/** command (argument 0 = command) string */
|
/** command (argument 0 = command) string */
|
||||||
|
|||||||
@@ -22,13 +22,9 @@
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
#include "appl.h"
|
#include "appl.h"
|
||||||
#include "port.h"
|
|
||||||
#include "decode.h"
|
|
||||||
#include "tcpsocket.h"
|
#include "tcpsocket.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <cstdlib>
|
||||||
#include <iomanip>
|
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -58,6 +54,11 @@ int main(int argc, char* argv[])
|
|||||||
// parse arguments
|
// parse arguments
|
||||||
A.parseArgs(argc, argv);
|
A.parseArgs(argc, argv);
|
||||||
|
|
||||||
|
if (A.missingCommand() == true) {
|
||||||
|
cout << "interactive mode started." << endl;
|
||||||
|
exit(EXIT_FAILURE);
|
||||||
|
}
|
||||||
|
|
||||||
TCPClient* client = new TCPClient();
|
TCPClient* client = new TCPClient();
|
||||||
TCPSocket* socket = client->connect(A.getOptVal<const char*>("server"), A.getOptVal<int>("port"));
|
TCPSocket* socket = client->connect(A.getOptVal<const char*>("server"), A.getOptVal<int>("port"));
|
||||||
|
|
||||||
@@ -87,6 +88,6 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
delete client;
|
delete client;
|
||||||
|
|
||||||
return 0;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -23,12 +23,10 @@
|
|||||||
|
|
||||||
#include "appl.h"
|
#include "appl.h"
|
||||||
#include "port.h"
|
#include "port.h"
|
||||||
#include "decode.h"
|
|
||||||
#include "tcpsocket.h"
|
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include <cstdlib>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@@ -96,6 +94,6 @@ int main(int argc, char* argv[])
|
|||||||
cout << "error opening device " << A.getOptVal<const char*>("device") << endl;
|
cout << "error opening device " << A.getOptVal<const char*>("device") << endl;
|
||||||
|
|
||||||
|
|
||||||
return 0;
|
exit(EXIT_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user