Add --show-config special option
[xboard.git] / gtk / xboard.c
index 442b936..6769a19 100644 (file)
@@ -5,7 +5,7 @@
  * Massachusetts.
  *
  * Enhancements Copyright 1992-2001, 2002, 2003, 2004, 2005, 2006,
- * 2007, 2008, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+ * 2007, 2008, 2009, 2010, 2011, 2012, 2013, 2014 Free Software Foundation, Inc.
  *
  * The following terms apply to Digital Equipment Corporation's copyright
  * interest in XBoard:
@@ -167,16 +167,20 @@ extern char *getenv();
 #include "gettext.h"
 #include "draw.h"
 
-#ifdef OSX
-#  include "gtkmacintegration/gtkosxapplication.h"
-   // prevent pathname of positional file argument provided by OSx being be mistaken for option name
+#ifdef __APPLE__
+#  include <gtkmacintegration/gtkosxapplication.h>
+   // prevent pathname of positional file argument provided by OS X being be mistaken for option name
    // (price is that we won't recognize Windows option format anymore).
 #  define SLASH '-'
    // redefine some defaults
 #  undef ICS_LOGON
-#  undef SYSCONFDIR
+#  undef DATADIR
+#  undef SETTINGS_FILE
 #  define ICS_LOGON "Library/Preferences/XboardICS.conf"
-#  define SYSCONFDIR "../etc"
+#  define DATADIR dataDir
+#  define SETTINGS_FILE masterSettings
+   char dataDir[MSG_SIZ]; // for expanding ~~
+   char masterSettings[MSG_SIZ];
 #else
 #  define SLASH '/'
 #endif
@@ -726,7 +730,7 @@ SlaveResize (Option *opt)
   gtk_window_resize(GTK_WINDOW(shells[DummyDlg]), slaveW + opt->max, slaveH + opt->value);
 }
 
-#ifdef OSX
+#ifdef __APPLE__
 static char clickedFile[MSG_SIZ];
 static int suppress;
 
@@ -770,9 +774,12 @@ main (int argc, char **argv)
 
     /* set up GTK */
     gtk_init (&argc, &argv);
-#ifdef OSX
+#ifdef __APPLE__
     {   // prepare to catch OX OpenFile signal, which will tell us the clicked file
        GtkosxApplication *theApp = g_object_new(GTKOSX_TYPE_APPLICATION, NULL);
+       char *path = gtkosx_application_get_bundle_path();
+       strncpy(dataDir, path, MSG_SIZ);
+       snprintf(masterSettings, MSG_SIZ, "%s/../Resources/etc/xboard.conf", path);
        g_signal_connect(theApp, "NSApplicationOpenFile", G_CALLBACK(StartNewXBoard), NULL);
        // we must call application ready before we can get the signal,
        // and supply a (dummy) menu bar before that, to avoid problems with dual apples in it
@@ -793,6 +800,23 @@ main (int argc, char **argv)
     }
 #endif
 
+    if(argc > 1 && !strcmp(argv[1], "--show-config")) { // [HGM] install: called to print config info
+       typedef struct {char *name, *value; } Config;
+       static Config configList[] = {
+         { "Datadir", DATADIR },
+         { "Sysconfdir", SYSCONFDIR },
+         { NULL }
+       };
+       int i;
+
+       for(i=0; configList[i].name; i++) {
+           if(argc > 2 && strcmp(argv[2], configList[i].name)) continue;
+           if(argc > 2) printf("%s", configList[i].value);
+           else printf("%-12s: %s\n", configList[i].name, configList[i].value);
+       }
+       exit(0);
+    }
+
     /* set up keyboard accelerators group */
     GtkAccelerators = gtk_accel_group_new();
 
@@ -1782,7 +1806,7 @@ TempForwardProc (Widget w, XEvent *event, String *prms, Cardinal *nprms)
 void
 ManProc ()
 {   // called from menu
-#ifdef OSX
+#ifdef __APPLE__
     system("%s ./man.command", appData.sysOpen);
 #else
     system("xterm -e man xboard &");