-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
75 lines (63 loc) · 1.78 KB
/
main.cpp
File metadata and controls
75 lines (63 loc) · 1.78 KB
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
/*
* Copyright 2017 Sinodun Internet Technologies Ltd.
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, you can obtain one at https://mozilla.org/MPL/2.0/.
*/
#include "stubbymanager.h"
#include <QApplication>
#include "msgdefs.h"
bool debugFlags[eNoOfDebugMsgTypes];
static void InitMsgFlags(int argc, char * argv[]);
static void SetAllMsgFlags(const bool on);
static void SetMsgFlag(const DebugMsgType type, const bool on);
static bool EnableIfNumber(QString sArg);
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
InitMsgFlags(argc, argv);
StubbyManager w;
w.show();
return a.exec();
}
static void InitMsgFlags(int argc, char *argv[])
{
SetAllMsgFlags(false);
bool bFlagWithoutVals = false;
int i = 0;
while (i < argc) {
if (strcmp(argv[i++], "-debug") == 0) {
bFlagWithoutVals = true;
while ((i < argc) && (EnableIfNumber(argv[i]))) {
bFlagWithoutVals = false;
i++;
}
}
}
if (bFlagWithoutVals) SetAllMsgFlags(true);
}
static void SetAllMsgFlags(const bool on)
{
for (int i = 0; i < eNoOfDebugMsgTypes; i++) {
SetMsgFlag((DebugMsgType)i, on);
}
}
static void SetMsgFlag(const DebugMsgType type, const bool on)
{
if ((type >= 0) && (type < eNoOfDebugMsgTypes)) {
debugFlags[type] = on;
if (on) {
SMInfo("%s %s", "Debug messages enabled: ", DebugTypeText().text(type));
}
}
}
static bool EnableIfNumber(QString sArg)
{
bool isNumber;
int iFlag = sArg.toInt(&isNumber);
if (isNumber && (iFlag < eNoOfDebugMsgTypes)) {
SetMsgFlag((DebugMsgType)iFlag, true);
}
return isNumber;
}