-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
102 lines (95 loc) · 3.89 KB
/
main.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/***************************************************************************
main.cpp - description
-------------------
begin : aug 2021
copyright : (C) 2021 by Jaime Robles
user : jaime@robles.es
***************************************************************************/
/*****************************************************************************
* This file is part of KLogServer *
* *
* KLogsServer is free software: you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation, either version 3 of the License, or *
* (at your option) any later version. *
* *
* KLogserver is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
* GNU General Public License for more details. *
* *
* You should have received a copy of the GNU General Public License *
* along with KLogServer. If not, see <https://www.gnu.org/licenses/>. *
* *
*****************************************************************************/
#include <QCoreApplication>
#include <QCommandLineParser>
#include <QObject>
#include "mainclass.h"
void showHelp()
{
QTextStream cout(stdout);
cout << "Usage: klog [OPTION]...\n";
cout << "Options:\n" ;
cout << " -? Display this help\n" ;
cout << " -h Display this help\n";
cout << " --help Display this help\n";
cout << " -v Display program version\n";
cout << " -p port Defines the UDP port to listen (default 2237)\n";
cout << " -i interface Defines the Interface to listen (default localhost)\n";
}
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
app.setApplicationName(QString("KLogServer"));
app.setOrganizationName("EA4K");
app.setOrganizationDomain("klog.xyz");
app.setApplicationVersion(QString(APP_VERSION));
int port = 2237;
QString interface = QString();
QStringList arguments;
QTextStream cout(stdout);
arguments.clear();
arguments << app.arguments();
if (arguments.length()>1)
{
if ((arguments.contains("-h")) || (arguments.contains("-?")) || (arguments.contains("--help")))
{
showHelp();
}
else if (arguments.contains("-v"))
{
cout << "Version: KLogServer-" << app.applicationVersion() << QT_ENDL;
}
else
{
if (arguments.contains("-p"))
{
int pIndex = arguments.indexOf ("-p");
QString aux = arguments.at(pIndex+1);
if ( (aux.toInt()>0) && (aux.toInt()<65535) )
{
port = aux.toInt();
cout << "Detected Port: " << QString::number(port) << QT_ENDL;
}
}
if (arguments.contains("-i"))
{
int pIndex = arguments.indexOf ("-i");
interface = arguments.at(pIndex+1);
cout << "Detected Interface: " << interface << QT_ENDL;
}
}
app.quit();
return 0;
}
MainClass main;
if (port!=2237)
{
main.setPort (port);
}
if (interface.length ()>0)
{
}
return app.exec();
}