f = fopen(fullname, "r");
if (f != NULL) {
if (addr != NULL) {
- *addr = strdup(fullname);
+ ASSIGN(*addr, fullname);
}
ParseArgs(FileGet, f);
fclose(f);
case ArgString:
case ArgFilename:
- *(char **) ad->argLoc = strdup(argValue);
+ ASSIGN(*(char **) ad->argLoc, argValue);
break;
case ArgSettingsFilename:
case ArgString:
case ArgFilename:
case ArgSettingsFilename:
- *(char **) argDescriptors[i].argLoc = (char *)argDescriptors[i].defaultValue;
+ if((char *)argDescriptors[i].defaultValue)
+ *(char **) argDescriptors[i].argLoc = strdup((char *)argDescriptors[i].defaultValue);
break;
case ArgBoardSize:
*(int *) argDescriptors[i].argLoc = (int)(intptr_t)argDescriptors[i].defaultValue;
char *settingsFileName;\r
Boolean saveSettingsOnExit;\r
char installDir[MSG_SIZ];\r
+char homeDir[MSG_SIZ];\r
int errorExitStatus;\r
\r
BoardSize boardSize;\r
} else {\r
GetCurrentDirectory(MSG_SIZ, installDir);\r
}\r
+ safeStrCpy(homeDir, installDir, MSG_SIZ);\r
gameInfo.boardWidth = gameInfo.boardHeight = 8; // [HGM] won't have open window otherwise\r
screenWidth = screenHeight = 1000; // [HGM] placement: kludge to allow calling EnsureOnScreen from InitAppData\r
InitAppData(lpCmdLine); /* Get run-time parameters */\r
VOID SetSaveOptionEnables(HWND hDlg);\r
VOID SetTimeControlEnables(HWND hDlg);\r
\r
+char *\r
+InterpretFileName(char *buf, char *homeDir)\r
+{ // [HGM] file name relative to homeDir. (Taken out of SafeOptionsDialog, because it is generally useful)\r
+ char *result = NULL;\r
+ if ((isalpha(buf[0]) && buf[1] == ':') ||\r
+ (buf[0] == '\\' && buf[1] == '\\')) {\r
+ return strdup(buf);\r
+ } else {\r
+ char buf2[MSG_SIZ], buf3[MSG_SIZ];\r
+ char *dummy;\r
+ GetCurrentDirectory(MSG_SIZ, buf3);\r
+ SetCurrentDirectory(homeDir);\r
+ if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {\r
+ result = strdup(buf2);\r
+ } else {\r
+ result = strdup(buf);\r
+ }\r
+ SetCurrentDirectory(buf3);\r
+ }\r
+ return result;\r
+}\r
+\r
/*---------------------------------------------------------------------------*\\r
*\r
* General Options Dialog functions\r
if (IsDlgButtonChecked(hDlg, OPT_Autosave)) {\r
appData.autoSaveGames = TRUE;\r
if (IsDlgButtonChecked(hDlg, OPT_AVPrompt)) {\r
- appData.saveGameFile = "";\r
+ ASSIGN(appData.saveGameFile, ""); // [HGM] make sure value is ALWAYS in allocated memory\r
} else /*if (IsDlgButtonChecked(hDlg, OPT_AVToFile))*/ {\r
GetDlgItemText(hDlg, OPT_AVFilename, buf, MSG_SIZ);\r
if (*buf == NULLCHAR) {\r
_("Option Error"), MB_OK|MB_ICONEXCLAMATION);\r
return FALSE;\r
}\r
- if ((isalpha(buf[0]) && buf[1] == ':') ||\r
- (buf[0] == '\\' && buf[1] == '\\')) {\r
- appData.saveGameFile = strdup(buf);\r
- } else {\r
- char buf2[MSG_SIZ], buf3[MSG_SIZ];\r
- char *dummy;\r
- GetCurrentDirectory(MSG_SIZ, buf3);\r
- SetCurrentDirectory(installDir);\r
- if (GetFullPathName(buf, MSG_SIZ, buf2, &dummy)) {\r
- appData.saveGameFile = strdup(buf2);\r
- } else {\r
- appData.saveGameFile = strdup(buf);\r
- }\r
- SetCurrentDirectory(buf3);\r
- }\r
+ FREE(appData.saveGameFile);\r
+ appData.saveGameFile = InterpretFileName(buf, homeDir);\r
}\r
} else {\r
appData.autoSaveGames = FALSE;\r
- appData.saveGameFile = "";\r
+ ASSIGN(appData.saveGameFile, "");\r
}\r
appData.oldSaveStyle = IsDlgButtonChecked(hDlg, OPT_Old);\r
appData.saveOutOfBookInfo = IsDlgButtonChecked( hDlg, OPT_OutOfBookInfo );\r