Revision: 78040
          http://sourceforge.net/p/brlcad/code/78040
Author:   starseeker
Date:     2021-01-05 20:04:53 +0000 (Tue, 05 Jan 2021)
Log Message:
-----------
Experiment with an option to set working dir.

Trying to get the MSI installer from WiX to change the working
directory for shortcuts has proven challenging.  An alternative
is to allow for the possibility of defining a shortcut that tells
the application itself to change the working directory - untested
as yet.

Modified Paths:
--------------
    brlcad/trunk/src/mged/mged.c

Modified: brlcad/trunk/src/mged/mged.c
===================================================================
--- brlcad/trunk/src/mged/mged.c        2021-01-04 14:55:54 UTC (rev 78039)
+++ brlcad/trunk/src/mged/mged.c        2021-01-05 20:04:53 UTC (rev 78040)
@@ -49,6 +49,10 @@
 #  include <poll.h>
 #endif
 
+#ifdef HAVE_WINDOWS_H
+#  include <direct.h> /* For chdir */
+#endif
+
 #include "bio.h"
 #include "bsocket.h"
 
@@ -1038,6 +1042,7 @@
 #endif
 
     char *attach = (char *)NULL;
+    char *wdir = (char *)NULL;
 
     setmode(fileno(stdin), O_BINARY);
     setmode(fileno(stdout), O_BINARY);
@@ -1062,7 +1067,7 @@
 #endif
 
     bu_optind = 1;
-    while ((c = bu_getopt(argc, argv, "a:d:hbicorx:X:v?")) != -1) {
+    while ((c = bu_getopt(argc, argv, "a:d:hbicorx:X:vW:?")) != -1) {
        if (bu_optopt == '?') c='h';
        switch (c) {
            case 'a':
@@ -1104,6 +1109,9 @@
                bu_log("WARNING: -o is a developer option and subject to 
change.  Do not use.\n");
                old_mged_gui = 0;
                break;
+           case 'W':
+               wdir = bu_optarg;
+               break;
            default:
                bu_log("Unrecognized option (%c)\n", bu_optopt);
                /* fall through */
@@ -1112,6 +1120,23 @@
        }
     }
 
+    /* Change the working directory, if the user specified one */
+    if (wdir) {
+       struct bu_vls wldir = BU_VLS_INIT_ZERO;
+       /* Make sure '~' is always interpreted as the home directory */
+       if (BU_STR_EQUAL(wdir, "~")) {
+           const char *homed = bu_dir(NULL, 0, BU_DIR_HOME, NULL);
+           bu_vls_sprintf(&wldir, "%s", homed);
+       } else {
+           bu_vls_sprintf(&wldir, "%s", wdir);
+       }
+       if (chdir(bu_vls_cstr(&wldir))) {
+           bu_vls_free(&wldir);
+           bu_exit(1, "Failed to change working directory to \"%s\" ", wdir);
+       }
+       bu_vls_free(&wldir);
+    }
+
     /* skip the args and invocation name */
     argc -= bu_optind;
     argv += bu_optind;

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.



_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to