Expand ~~/ to bundle path (OSX)
[xboard.git] / args.h
diff --git a/args.h b/args.h
index f6e755b..a6a0a9b 100644 (file)
--- a/args.h
+++ b/args.h
@@ -60,7 +60,7 @@
 typedef enum {
   ArgString, ArgInt, ArgFloat, ArgBoolean, ArgTrue, ArgFalse, ArgNone,
   ArgColor, ArgAttribs, ArgFilename, ArgBoardSize, ArgFont, ArgCommSettings,
-  ArgSettingsFilename, ArgTwo,
+  ArgSettingsFilename, ArgBackupSettingsFile, ArgTwo,
   ArgX, ArgY, ArgZ // [HGM] placement: for window-placement options stored relative to main window
 } ArgType;
 
@@ -490,6 +490,7 @@ ArgDescriptor argDescriptors[] = {
   { "at", ArgSettingsFilename, (void *) NULL, FALSE, INVALID },
   { "opt", ArgSettingsFilename, (void *) NULL, FALSE, INVALID },
   { "saveSettingsFile", ArgFilename, (void *) &settingsFileName, FALSE, INVALID },
+  { "backupSettingsFile", ArgBackupSettingsFile, (void *) &settingsFileName, FALSE, INVALID },
   { "saveSettingsOnExit", ArgBoolean, (void *) &saveSettingsOnExit, TRUE, (ArgIniType) TRUE },
   { "chessProgram", ArgBoolean, (void *) &chessProgram, FALSE, (ArgIniType) FALSE },
   { "cp", ArgTrue, (void *) &chessProgram, FALSE, INVALID },
@@ -906,7 +907,7 @@ ParseArgs(GetFunc get, void *cl)
       ch = get(cl);
       while (ch != '\n' && ch != NULLCHAR) ch = get(cl);
       continue;
-    } else if (ch == '/' || ch == '-') {
+    } else if (ch == SLASH || ch == '-') {
       /* Switch */
       q = argName;
       while (ch != ' ' && ch != '=' && ch != ':' && ch != NULLCHAR &&
@@ -918,8 +919,10 @@ ParseArgs(GetFunc get, void *cl)
       for (ad = argDescriptors; ad->argName != NULL; ad++)
        if (strcmp(ad->argName, argName + 1) == 0) break;
       if (ad->argName == NULL) {
+       char endChar = (ch && ch != '\n' && (ch = get(cl)) == '{' ? '}' : '\n');
        ExitArgError(_("Unrecognized argument %s"), argName, get != &FileGet); // [HGM] make unknown argument non-fatal
-       while (ch != '\n' && ch != NULLCHAR) ch = get(cl); // but skip rest of line it is on
+       while (ch != endChar && ch != NULLCHAR) ch = get(cl); // but skip rest of line it is on (or until closing '}' )
+       if(ch == '}') ch = get(cl);
        continue; // so that when it is in a settings file, it is the only setting that will be purged from it
       }
     } else if (ch == '@') {
@@ -1102,9 +1105,17 @@ ParseArgs(GetFunc get, void *cl)
 
     case ArgString:
     case ArgFilename:
+      if(argValue[0] == '~' && argValue[1] == '~') {
+        char buf[4*MSG_SIZ]; // expand ~~
+        snprintf(buf, 4*MSG_SIZ, "%s%s", DATADIR, argValue+2);
+        ASSIGN(*(char **) ad->argLoc, buf);
+        break;
+      }
       ASSIGN(*(char **) ad->argLoc, argValue);
       break;
 
+    case ArgBackupSettingsFile: // no-op if non-default settings-file already successfully read
+       if(strcmp(*(char**)ad->argLoc, SETTINGS_FILE)) break;
     case ArgSettingsFilename:
       {
        if (ParseSettingsFile(argValue, (char**)ad->argLoc)) {
@@ -1537,6 +1548,7 @@ SaveSettings(char* name)
       PrintCommPortSettings(f, ad->argName);
     case ArgTwo:
     case ArgNone:
+    case ArgBackupSettingsFile:
     case ArgSettingsFilename: ;
     }
   }