forked from deskflow/deskflow
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extracted platform specific argument parsing code.
- Loading branch information
Xinyu Hou
committed
Oct 22, 2014
1 parent
326901e
commit d2814a4
Showing
6 changed files
with
129 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
/* | ||
* synergy -- mouse and keyboard sharing utility | ||
* Copyright (C) 2014 Synergy Si, inc. | ||
* | ||
* This package is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* found in the file COPYING that should have accompanied this file. | ||
* | ||
* This package 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#include "synergy/ArgParser.h" | ||
|
||
#include "synergy/ArgsBase.h" | ||
#include "base/Log.h" | ||
|
||
CArgsBase* CArgParser::m_argsBase = NULL; | ||
|
||
bool | ||
CArgParser::parsePlatformArg(CArgsBase& argsBase, const int& argc, const char* const* argv, int& i) | ||
{ | ||
#if WINAPI_MSWINDOWS | ||
if (isArg(i, argc, argv, NULL, "--service")) { | ||
LOG((CLOG_WARN "obsolete argument --service, use synergyd instead.")); | ||
argsBase.m_shouldExit = true; | ||
} | ||
else if (isArg(i, argc, argv, NULL, "--exit-pause")) { | ||
argsBase.m_pauseOnExit = true; | ||
} | ||
else if (isArg(i, argc, argv, NULL, "--stop-on-desk-switch")) { | ||
argsBase.m_stopOnDeskSwitch = true; | ||
} | ||
else { | ||
// option not supported here | ||
return false; | ||
} | ||
|
||
return true; | ||
#elif WINAPI_XWINDOWS | ||
if (CArgumentParser::isArg(i, argc, argv, "-display", "--display", 1)) { | ||
// use alternative display | ||
argsBase.m_display = argv[++i]; | ||
} | ||
|
||
else if (CArgumentParser::isArg(i, argc, argv, NULL, "--no-xinitthreads")) { | ||
argsBase.m_disableXInitThreads = true; | ||
} | ||
|
||
else { | ||
// option not supported here | ||
return false; | ||
} | ||
|
||
return true; | ||
#elif WINAPI_CARBON | ||
// no options for carbon | ||
return false; | ||
#endif | ||
} | ||
|
||
bool | ||
CArgParser::isArg( | ||
int argi, int argc, const char* const* argv, | ||
const char* name1, const char* name2, | ||
int minRequiredParameters) | ||
{ | ||
if ((name1 != NULL && strcmp(argv[argi], name1) == 0) || | ||
(name2 != NULL && strcmp(argv[argi], name2) == 0)) { | ||
// match. check args left. | ||
if (argi + minRequiredParameters >= argc) { | ||
LOG((CLOG_PRINT "%s: missing arguments for `%s'" BYE, | ||
argsBase().m_pname, argv[argi], argsBase().m_pname)); | ||
argsBase().m_shouldExit = true; | ||
return false; | ||
} | ||
return true; | ||
} | ||
|
||
// no match | ||
return false; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* synergy -- mouse and keyboard sharing utility | ||
* Copyright (C) 2014 Synergy Si, Inc. | ||
* | ||
* This package is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* found in the file COPYING that should have accompanied this file. | ||
* | ||
* This package 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 this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
#pragma once | ||
|
||
#include "base/String.h" | ||
#include "common/stdvector.h" | ||
|
||
class CArgsBase; | ||
|
||
class CArgParser { | ||
|
||
public: | ||
bool parsePlatformArg(CArgsBase& argsBase, const int& argc, const char* const* argv, int& i); | ||
|
||
static bool isArg(int argi, int argc, const char* const* argv, | ||
const char* name1, const char* name2, | ||
int minRequiredParameters = 0); | ||
private: | ||
static CArgsBase& argsBase() { return *m_argsBase; } | ||
|
||
private: | ||
static CArgsBase* m_argsBase; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -46,4 +46,5 @@ class CArgsBase { | |
#if WINAPI_XWINDOWS | ||
bool m_disableXInitThreads; | ||
#endif | ||
bool m_shouldExit; | ||
}; |