| 1 |
/*************************************************************************** |
| 2 |
* Copyright (c) 2002 Jürgen Riegel <[email protected]> * |
| 3 |
* * |
| 4 |
* This file is part of the FreeCAD CAx development system. * |
| 5 |
* * |
| 6 |
* This program is free software; you can redistribute it and/or modify * |
| 7 |
* it under the terms of the GNU Library General Public License (LGPL) * |
| 8 |
* as published by the Free Software Foundation; either version 2 of * |
| 9 |
* the License, or (at your option) any later version. * |
| 10 |
* for detail see the LICENCE text file. * |
| 11 |
* * |
| 12 |
* FreeCAD is distributed in the hope that it will be useful, * |
| 13 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * |
| 14 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
| 15 |
* GNU Library General Public License for more details. * |
| 16 |
* * |
| 17 |
* You should have received a copy of the GNU Library General Public * |
| 18 |
* License along with FreeCAD; if not, write to the Free Software * |
| 19 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * |
| 20 |
* USA * |
| 21 |
* * |
| 22 |
***************************************************************************/ |
| 23 |
|
| 24 |
#ifndef PROGRAMOPTIONSUTILITIES_H |
| 25 |
#define PROGRAMOPTIONSUTILITIES_H |
| 26 |
|
| 27 |
#include <FCConfig.h> |
| 28 |
|
| 29 |
#include <algorithm> |
| 30 |
#include <array> |
| 31 |
#include <string> |
| 32 |
|
| 33 |
/** |
| 34 |
* @brief A namespace for utilities. |
| 35 |
* |
| 36 |
* Currently, this namespace contains functionality to define custom syntax to |
| 37 |
* parse command line options. |
| 38 |
*/ |
| 39 |
namespace App::Util |
| 40 |
{ |
| 41 |
|
| 42 |
std::pair<std::string, std::string> customSyntax(std::string_view strIn) |
| 43 |
{ |
| 44 |
if (strIn.size() < 2) { |
| 45 |
return {}; |
| 46 |
} |
| 47 |
|
| 48 |
char leadChr {strIn[0]}; |
| 49 |
std::string rest {strIn.substr(1)}; |
| 50 |
|
| 51 |
if (leadChr == '@') { |
| 52 |
return {"response-file", rest}; |
| 53 |
} |
| 54 |
|
| 55 |
if (leadChr != '-') { |
| 56 |
return {}; |
| 57 |
} |
| 58 |
|
| 59 |
#if defined(FC_OS_MACOSX) |
| 60 |
if (rest.find("psn_") == 0) { |
| 61 |
return {"psn", rest.substr(4)}; |
| 62 |
} |
| 63 |
#endif |
| 64 |
|
| 65 |
if (rest == "widgetcount") { |
| 66 |
return {rest, ""}; |
| 67 |
} |
| 68 |
|
| 69 |
constexpr std::array knowns {"display", |
| 70 |
"style", |
| 71 |
"graphicssystem", |
| 72 |
"geometry", |
| 73 |
"font", |
| 74 |
"fn", |
| 75 |
"background", |
| 76 |
"bg", |
| 77 |
"foreground", |
| 78 |
"fg", |
| 79 |
"button", |
| 80 |
"btn", |
| 81 |
"name", |
| 82 |
"title", |
| 83 |
"visual"}; |
| 84 |
|
| 85 |
if (std::ranges::find(knowns, rest) != knowns.end()) { |
| 86 |
return {rest, "null"}; |
| 87 |
} |
| 88 |
return {}; |
| 89 |
} |
| 90 |
|
| 91 |
} // namespace App::Util |
| 92 |
#endif // PROGRAMOPTIONSUTILITIES_H |