regularize application startup. use Qt's command line parser support
This commit is contained in:
@ -14,28 +14,42 @@
|
||||
#include "lammpsgui.h"
|
||||
|
||||
#include <QApplication>
|
||||
#include <QCommandLineOption>
|
||||
#include <QCommandLineParser>
|
||||
#include <QLocale>
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
#define stringify(x) myxstr(x)
|
||||
#define myxstr(x) #x
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
QApplication a(argc, argv);
|
||||
Q_INIT_RESOURCE(lammpsgui);
|
||||
QApplication app(argc, argv);
|
||||
// enforce using the plain ASCII C locale within the GUI.
|
||||
QLocale::setDefault(QLocale::c());
|
||||
QCoreApplication::setOrganizationName("The LAMMPS Developers");
|
||||
QCoreApplication::setOrganizationDomain("lammps.org");
|
||||
QCoreApplication::setApplicationName("LAMMPS-GUI - QT" stringify(QT_VERSION_MAJOR));
|
||||
QCoreApplication::setApplicationVersion(LAMMPS_GUI_VERSION);
|
||||
QCommandLineParser parser;
|
||||
parser.setApplicationDescription(
|
||||
"\nThis is LAMMPS-GUI v" LAMMPS_GUI_VERSION "\n"
|
||||
"\nA graphical editor for LAMMPS input files with syntax highlighting and\n"
|
||||
"auto-completion that can run LAMMPS directly. It has built-in capabilities\n"
|
||||
"for monitoring, visualization, plotting, and capturing console output.");
|
||||
parser.addHelpOption();
|
||||
parser.addVersionOption();
|
||||
parser.addPositionalArgument("file", "The LAMMPS input file to open (optional).");
|
||||
parser.process(app); // this removes known arguments
|
||||
|
||||
const char *infile = nullptr;
|
||||
if (argc > 1) {
|
||||
infile = argv[1];
|
||||
if ((strcmp(infile, "-help") == 0) || (strcmp(infile, "-h") == 0)) {
|
||||
printf("This is LAMMPS-GUI version " LAMMPS_GUI_VERSION
|
||||
" using Qt version " QT_VERSION_STR "\n");
|
||||
printf("Usage: %s [-h|-help|<inputfile>]\n", argv[0]);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (argc > 1) infile = argv[1];
|
||||
LammpsGui w(nullptr, infile);
|
||||
w.show();
|
||||
return QApplication::exec();
|
||||
return app.exec();
|
||||
}
|
||||
|
||||
// Local Variables:
|
||||
|
||||
Reference in New Issue
Block a user