Skip to content

Commit

Permalink
Merge pull request #850 from argilo/qcommandlineparser
Browse files Browse the repository at this point in the history
Replace Boost.Program_options with QCommandLineParser
  • Loading branch information
argilo authored Nov 1, 2020
2 parents d20c7b4 + 1618247 commit 80e19c4
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 53 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ math(EXPR GNURADIO_BCD_VERSION
add_definitions(-DGNURADIO_VERSION=${GNURADIO_BCD_VERSION})

if(Gnuradio_VERSION VERSION_LESS "3.8")
find_package(Boost COMPONENTS system program_options REQUIRED)
find_package(Boost COMPONENTS system REQUIRED)
endif()

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
Expand Down
4 changes: 2 additions & 2 deletions gqrx.pro
Original file line number Diff line number Diff line change
Expand Up @@ -293,12 +293,12 @@ greaterThan(GNURADIO_VERSION_MINOR, 7) {
INCPATH += src/

unix:!macx {
LIBS += -lboost_system$$BOOST_SUFFIX -lboost_program_options$$BOOST_SUFFIX
LIBS += -lboost_system$$BOOST_SUFFIX
LIBS += -lrt # need to include on some distros
}

macx {
LIBS += -lboost_system-mt -lboost_program_options-mt
LIBS += -lboost_system-mt
}

OTHER_FILES += \
Expand Down
1 change: 1 addition & 0 deletions resources/news.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
2.13.3: In progress...

FIXED: Crash when waterfall height is set to 100%.
IMPROVED: Remove Boost.Program_options dependency.


2.13.2: Released October 24, 2020
Expand Down
71 changes: 21 additions & 50 deletions src/applications/gqrx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* Boston, MA 02110-1301, USA.
*/
#include <QApplication>
#include <QCommandLineParser>
#include <QDebug>
#include <QDesktopServices>
#include <QDir>
Expand All @@ -43,18 +44,13 @@
#include "gqrx.h"

#include <iostream>
#include <boost/program_options.hpp>
namespace po = boost::program_options;

static void reset_conf(const QString &file_name);
static void list_conf(void);

int main(int argc, char *argv[])
{
QString cfg_file;
std::string conf;
std::string style;
bool clierr = false;
bool edit_conf = false;
int return_code = 0;

Expand All @@ -72,47 +68,22 @@ int main(int argc, char *argv[])
else
qDebug() << "Failed to disable controlport";

// setup the program options
po::options_description desc("Command line options");
desc.add_options()
("help,h", "This help message")
("style,s", po::value<std::string>(&style), "Use the given style (fusion, windows)")
("list,l", "List existing configurations")
("conf,c", po::value<std::string>(&conf), "Start with this config file")
("edit,e", "Edit the config file before using it")
("reset,r", "Reset configuration file")
;

po::variables_map vm;
try
{
po::store(po::parse_command_line(argc, argv, desc), vm);
}
catch(const boost::program_options::invalid_command_line_syntax& ex)
{
/* happens if e.g. -c without file name */
clierr = true;
}
catch(const boost::program_options::unknown_option& ex)
{
/* happens if e.g. -c without file name */
clierr = true;
}

po::notify(vm);

// print the help message
if (vm.count("help") || clierr)
{
std::cout << "Gqrx software defined radio receiver " << VERSION << std::endl;
std::cout << desc << std::endl;
return 1;
}

if (vm.count("style"))
QApplication::setStyle(QString::fromStdString(style));

if (vm.count("list"))
QCommandLineParser parser;
parser.setApplicationDescription("Gqrx software defined radio receiver " VERSION);
parser.addHelpOption();
parser.addOptions({
{{"s", "style"}, "Use the given style (fusion, windows)", "style"},
{{"l", "list"}, "List existing configurations"},
{{"c", "conf"}, "Start with this config file", "file"},
{{"e", "edit"}, "Edit the config file before using it"},
{{"r", "reset"}, "Reset configuration file"},
});
parser.process(app);

if (parser.isSet("style"))
QApplication::setStyle(parser.value("style"));

if (parser.isSet("list"))
{
list_conf();
return 0;
Expand Down Expand Up @@ -153,9 +124,9 @@ int main(int argc, char *argv[])
#endif


if (!conf.empty())
if (parser.isSet("conf"))
{
cfg_file = QString::fromStdString(conf);
cfg_file = parser.value("conf");
qDebug() << "User specified config file:" << cfg_file;
}
else
Expand All @@ -164,9 +135,9 @@ int main(int argc, char *argv[])
qDebug() << "No user supplied config file. Using" << cfg_file;
}

if (vm.count("reset"))
if (parser.isSet("reset"))
reset_conf(cfg_file);
else if (vm.count("edit"))
else if (parser.isSet("edit"))
edit_conf = true;

try {
Expand Down

0 comments on commit 80e19c4

Please sign in to comment.