Browse Source

Add long arguments with getopt_long().

tags/v2.2.2
Andrew Belt 1 year ago
parent
commit
669a71cbd1
1 changed files with 18 additions and 3 deletions
  1. +18
    -3
      adapters/standalone.cpp

+ 18
- 3
adapters/standalone.cpp View File

@@ -24,13 +24,13 @@
#include <library.hpp>
#include <network.hpp>

#include <osdialog.h>
#include <thread>
#include <getopt.h>
#include <unistd.h> // for getopt
#include <signal.h> // for signal
#if defined ARCH_WIN
#include <windows.h> // for CreateMutex
#endif
#include <osdialog.h>

#if defined ARCH_MAC
#define GLFW_EXPOSE_NATIVE_COCOA
@@ -73,9 +73,20 @@ int main(int argc, char* argv[]) {
float screenshotZoom = 1.f;

// Parse command line arguments
static const struct option longOptions[] = {
{"safe", no_argument, NULL, 'a'},
{"dev", no_argument, NULL, 'd'},
{"headless", no_argument, NULL, 'h'},
{"screenshot", required_argument, NULL, 't'},
{"system", required_argument, NULL, 's'},
{"user", required_argument, NULL, 'u'},
{"version", no_argument, NULL, 'v'},
{NULL, 0, NULL, 0}
};
int c;
opterr = 0;
while ((c = getopt(argc, argv, "adht:s:u:p:")) != -1) {

while ((c = getopt_long(argc, argv, "adht:s:u:vp:", longOptions, NULL)) != -1) {
switch (c) {
case 'a': {
settings::safeMode = true;
@@ -96,6 +107,10 @@ int main(int argc, char* argv[]) {
case 'u': {
asset::userDir = optarg;
} break;
case 'v': {
std::fprintf(stderr, "%s %s %s %s\n", APP_NAME.c_str(), APP_EDITION_NAME.c_str(), APP_VERSION.c_str(), APP_ARCH.c_str());
return 0;
}
// Mac "app translocation" passes a nonsense -psn_... flag, so -p is reserved.
case 'p': break;
default: break;


Loading…
Cancel
Save