exchanged some sprintf with snprintf
[xboard.git] / xboard.c
index a292a9f..b599a8d 100644 (file)
--- a/xboard.c
+++ b/xboard.c
@@ -1059,6 +1059,9 @@ XtResource clientResources[] = {
     { "zippyReplayTimeout", "zippyReplayTimeout", XtRInt, sizeof(int),
        XtOffset(AppDataPtr, zippyReplayTimeout), XtRImmediate,
         (XtPointer) ZIPPY_REPLAY_TIMEOUT },
+    { "zippyShortGame", "zippyShortGame", XtRInt, sizeof(int),
+       XtOffset(AppDataPtr, zippyShortGame), XtRImmediate,
+        (XtPointer) 0 },
 #endif
     { "flashCount", "flashCount", XtRInt, sizeof(int),
        XtOffset(AppDataPtr, flashCount), XtRImmediate,
@@ -1216,6 +1219,9 @@ XtResource clientResources[] = {
     { "defaultFrcPosition", "defaultFrcPositon", XtRInt,
        sizeof(int), XtOffset(AppDataPtr, defaultFrcPosition),
        XtRImmediate, (XtPointer) -1},
+    { "gameListTags", "gameListTags", XtRString,
+        sizeof(String), XtOffset(AppDataPtr, gameListTags),
+       XtRImmediate, (XtPointer) GLT_DEFAULT_TAGS },
 
     // [HGM] 4.3.xx options
     { "boardWidth", "boardWidth", XtRInt,
@@ -1332,6 +1338,12 @@ XtResource clientResources[] = {
     { "secondOptions", "secondOptions", XtRString,
         sizeof(String), XtOffset(AppDataPtr, secondOptions),
        XtRImmediate, (XtPointer) "" },
+    { "firstNeedsNoncompliantFEN", "firstNeedsNoncompliantFEN", XtRString,
+        sizeof(String), XtOffset(AppDataPtr, fenOverride1),
+       XtRImmediate, (XtPointer) 0 },
+    { "secondNeedsNoncompliantFEN", "secondNeedsNoncompliantFEN", XtRString,
+        sizeof(String), XtOffset(AppDataPtr, fenOverride2),
+       XtRImmediate, (XtPointer) 0 },
 
     // [HGM] Winboard_x UCI options
     { "firstIsUCI", "firstIsUCI", XtRBoolean,
@@ -1592,6 +1604,7 @@ XrmOptionDescRec shellOptions[] = {
     { "-zippyVariants", "zippyVariants", XrmoptionSepArg, NULL },
     { "-zippyMaxGames", "zippyMaxGames", XrmoptionSepArg, NULL },
     { "-zippyReplayTimeout", "zippyReplayTimeout", XrmoptionSepArg, NULL },
+    { "-zippyShortGame", "zippyShortGame", XrmoptionSepArg, NULL },
 #endif
     { "-flashCount", "flashCount", XrmoptionSepArg, NULL },
     { "-flash", "flashCount", XrmoptionNoArg, "3" },
@@ -1684,6 +1697,7 @@ XrmOptionDescRec shellOptions[] = {
     { "-defaultCacheSizeEGTB", "defaultCacheSizeEGTB", XrmoptionSepArg, NULL },
     { "-defaultPathEGTB", "defaultPathEGTB", XrmoptionSepArg, NULL },
     { "-defaultFrcPosition", "defaultFrcPosition", XrmoptionSepArg, NULL },
+    { "-gameListTags", "gameListTags", XrmoptionSepArg, NULL },
     // [HGM] I am sure AS added many more options, but we have to fish them out, from the list in winboard.c
 
     /* [HGM,HR] User-selectable board size */
@@ -1730,6 +1744,8 @@ XrmOptionDescRec shellOptions[] = {
     { "-noGUI", "noGUI", XrmoptionNoArg, "True" },
     { "-firstOptions", "firstOptions", XrmoptionSepArg, NULL },
     { "-secondOptions", "secondOptions", XrmoptionSepArg, NULL },
+    { "-firstNeedsNoncompliantFEN", "firstNeedsNoncompliantFEN", XrmoptionSepArg, NULL },
+    { "-secondNeedsNoncompliantFEN", "secondNeedsNoncompliantFEN", XrmoptionSepArg, NULL },
 };
 
 
@@ -2132,7 +2148,7 @@ CatchDeleteWindow(Widget w, String procname)
 {
   char buf[MSG_SIZ];
   XSetWMProtocols(xDisplay, XtWindow(w), &wm_delete_window, 1);
-  sprintf(buf, "<Message>WM_PROTOCOLS: %s() \n", procname);
+  snprintf(buf, sizeof(buf), "<Message>WM_PROTOCOLS: %s() \n", procname);
   XtAugmentTranslations(w, XtParseTranslationTable(buf));
 }
 
@@ -2322,8 +2338,8 @@ main(argc, argv)
     i = strlen(p) + strlen("/.xboardXXXXXx.pgn") + 1;
     gameCopyFilename = (char*) malloc(i);
     gamePasteFilename = (char*) malloc(i);
-    sprintf(gameCopyFilename, "%s/.xboard%05uc.pgn", p, getpid());
-    sprintf(gamePasteFilename, "%s/.xboard%05up.pgn", p, getpid());
+    snprintf(gameCopyFilename,i, "%s/.xboard%05uc.pgn", p, getpid());
+    snprintf(gamePasteFilename,i, "%s/.xboard%05up.pgn", p, getpid());
 
     XtGetApplicationResources(shellWidget, (XtPointer) &appData,
                              clientResources, XtNumber(clientResources),
@@ -3685,7 +3701,7 @@ void CreateXIMPieces()
            fprintf(stderr, "%d", piece+1);
            for (kind=0; kind<4; kind++) {
                fprintf(stderr, ".");
-               sprintf(buf, "%s/%c%s%u.xim",
+               snprintf(buf, sizeof(buf), "%s/%c%s%u.xim",
                        ExpandPathName(appData.pixmapDirectory),
                        ToLower(PieceToChar((ChessSquare)piece)),
                        ximkind[kind], ss);
@@ -3704,7 +3720,7 @@ void CreateXIMPieces()
        /* Load light and dark squares */
        /* If the LSQ and DSQ pieces don't exist, we will
           draw them with solid squares. */
-       sprintf(buf, "%s/lsq%u.xim", ExpandPathName(appData.pixmapDirectory), ss);
+       snprintf(buf,sizeof(buf), "%s/lsq%u.xim", ExpandPathName(appData.pixmapDirectory), ss);
        if (access(buf, 0) != 0) {
            useImageSqs = 0;
        } else {
@@ -3718,7 +3734,7 @@ void CreateXIMPieces()
 
            loadXIM(ximLightSquare, NULL, buf, &xpmLightSquare, NULL);
            fprintf(stderr, _("dark square "));
-           sprintf(buf, "%s/dsq%u.xim",
+           snprintf(buf,sizeof(buf), "%s/dsq%u.xim",
                    ExpandPathName(appData.pixmapDirectory), ss);
            if (appData.debugMode)
              fprintf(stderr, _("(File:%s:) "), buf);
@@ -3807,7 +3823,7 @@ void CreateXPMPieces()
        for (piece = (int) WhitePawn; piece <= (int) WhiteKing; piece++) {
            fprintf(stderr, "%d ", piece+1);
            for (kind=0; kind<4; kind++) {
-               sprintf(buf, "%s/%c%s%u.xpm",
+             snprintf(buf, sizeof(buf), "%s/%c%s%u.xpm",
                        ExpandPathName(appData.pixmapDirectory),
                        ToLower(PieceToChar((ChessSquare)piece)),
                        xpmkind[kind], ss);
@@ -3827,7 +3843,7 @@ void CreateXPMPieces()
        /* If the LSQ and DSQ pieces don't exist, we will
           draw them with solid squares. */
        fprintf(stderr, _("light square "));
-       sprintf(buf, "%s/lsq%u.xpm", ExpandPathName(appData.pixmapDirectory), ss);
+       snprintf(buf, sizeof(buf), "%s/lsq%u.xpm", ExpandPathName(appData.pixmapDirectory), ss);
        if (access(buf, 0) != 0) {
            useImageSqs = 0;
        } else {
@@ -3841,7 +3857,7 @@ void CreateXPMPieces()
                exit(1);
            }
            fprintf(stderr, _("dark square "));
-           sprintf(buf, "%s/dsq%u.xpm",
+           snprintf(buf, sizeof(buf), "%s/dsq%u.xpm",
                    ExpandPathName(appData.pixmapDirectory), ss);
            if (appData.debugMode) {
                fprintf(stderr, _("(File:%s:) "), buf);
@@ -3930,17 +3946,17 @@ void ReadBitmap(pm, name, bits, wreq, hreq)
        if (errcode != BitmapSuccess) {
            switch (errcode) {
              case BitmapOpenFailed:
-               sprintf(msg, _("Can't open bitmap file %s"), fullname);
+               snprintf(msg, sizeof(msg), _("Can't open bitmap file %s"), fullname);
                break;
              case BitmapFileInvalid:
-               sprintf(msg, _("Invalid bitmap in file %s"), fullname);
+               snprintf(msg, sizeof(msg), _("Invalid bitmap in file %s"), fullname);
                break;
              case BitmapNoMemory:
-               sprintf(msg, _("Ran out of memory reading bitmap file %s"),
+               snprintf(msg, sizeof(msg), _("Ran out of memory reading bitmap file %s"),
                        fullname);
                break;
              default:
-               sprintf(msg, _("Unknown XReadBitmapFile error %d on file %s"),
+               snprintf(msg, sizeof(msg), _("Unknown XReadBitmapFile error %d on file %s"),
                        errcode, fullname);
                break;
            }
@@ -4196,7 +4212,7 @@ void SetupDropMenu()
                                       && !appData.icsActive));
        count = 0;
        while (p && *p++ == dmEnables[i].piece) count++;
-       sprintf(label, "%s  %d", dmEnables[i].widget, count);
+       snprintf(label, sizeof(label), "%s  %d", dmEnables[i].widget, count);
        j = 0;
        XtSetArg(args[j], XtNlabel, label); j++;
        XtSetValues(entry, args, j);
@@ -6268,7 +6284,7 @@ void CopyPositionProc(w, event, prms, nprms)
     int ret;
 
     if (selected_fen_position) free(selected_fen_position);
-    selected_fen_position = (char *)PositionToFEN(currentMove,1);
+    selected_fen_position = (char *)PositionToFEN(currentMove, NULL);
     if (!selected_fen_position) return;
     ret = XtOwnSelection(menuBarWidget, XA_PRIMARY,
                         CurrentTime,
@@ -6459,7 +6475,7 @@ void AnalyzeModeProc(w, event, prms, nprms)
     char buf[MSG_SIZ];
 
     if (!first.analysisSupport) {
-      sprintf(buf, _("%s does not support analysis"), first.tidy);
+      snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy);
       DisplayError(buf, 0);
       return;
     }
@@ -6501,7 +6517,7 @@ void AnalyzeFileProc(w, event, prms, nprms)
 {
     if (!first.analysisSupport) {
       char buf[MSG_SIZ];
-      sprintf(buf, _("%s does not support analysis"), first.tidy);
+      snprintf(buf, sizeof(buf), _("%s does not support analysis"), first.tidy);
       DisplayError(buf, 0);
       return;
     }
@@ -7337,7 +7353,7 @@ void InfoProc(w, event, prms, nprms)
      Cardinal *nprms;
 {
     char buf[MSG_SIZ];
-    sprintf(buf, "xterm -e info --directory %s --directory . -f %s &",
+    snprintf(buf, sizeof(buf), "xterm -e info --directory %s --directory . -f %s &",
            INFODIR, INFOFILE);
     system(buf);
 }
@@ -7354,7 +7370,7 @@ void ManProc(w, event, prms, nprms)
       name = prms[0];
     else
       name = "xboard";
-    sprintf(buf, "xterm -e man %s &", name);
+    snprintf(buf, sizeof(buf), "xterm -e man %s &", name);
     system(buf);
 }
 
@@ -7388,12 +7404,11 @@ void AboutProc(w, event, prms, nprms)
 #else
     char *zippy = "";
 #endif
-    sprintf(buf, "%s%s\n\n%s\n%s\n%s\n%s\n\n%s%s\n%s",
+    snprintf(buf, sizeof(buf), "%s%s\n\n%s\n%s\n%s\n\n%s%s\n%s",
            programVersion, zippy,
            "Copyright 1991 Digital Equipment Corporation",
-           "Enhancements Copyright 1992-2001 Free Software Foundation",
+           "Enhancements Copyright 1992-2009 Free Software Foundation",
            "Enhancements Copyright 2005 Alessandro Scotti",
-           "Enhancements Copyright 2007-2008 H.G.Muller",
            PRODUCT, " is free software and carries NO WARRANTY;",
            "see the file COPYING for more information.");
     ErrorPopUp(_("About XBoard"), buf, FALSE);
@@ -7447,7 +7462,7 @@ void DisplayMessage(message, extMessage)
 
     if (extMessage) {
        if (*message) {
-           sprintf(buf, "%s  %s", message, extMessage);
+           snprintf(buf, sizeof(buf), "%s  %s", message, extMessage);
            message = buf;
        } else {
            message = extMessage;
@@ -7477,11 +7492,11 @@ void DisplayTitle(text)
        strcpy(icon, text);
        strcpy(title, text);
     } else if (appData.icsActive) {
-       sprintf(icon, "%s", appData.icsHost);
-       sprintf(title, "%s: %s", programName, appData.icsHost);
+        snprintf(icon, sizeof(icon), "%s", appData.icsHost);
+       snprintf(title, sizeof(title),"%s: %s", programName, appData.icsHost);
     } else if (appData.cmailGameName[0] != NULLCHAR) {
-       sprintf(icon, "%s", "CMail");
-       sprintf(title, "%s: %s", programName, "CMail");
+        snprintf(icon, sizeof(icon), "%s", "CMail");
+       snprintf(title,sizeof(title), "%s: %s", programName, "CMail");
 #ifdef GOTHIC
     // [HGM] license: This stuff should really be done in back-end, but WinBoard already had a pop-up for it
     } else if (gameInfo.variant == VariantGothic) {
@@ -7498,7 +7513,7 @@ void DisplayTitle(text)
        strcpy(title, programName);
     } else {
        strcpy(icon, first.tidy);
-       sprintf(title, "%s: %s", programName, first.tidy);
+       snprintf(title,sizeof(title), "%s: %s", programName, first.tidy);
     }
     i = 0;
     XtSetArg(args[i], XtNiconName, (XtArgVal) icon);    i++;
@@ -7522,7 +7537,7 @@ void DisplayError(message, error)
            fprintf(stderr, "%s: %s: %s\n",
                    programName, message, strerror(error));
        }
-       sprintf(buf, "%s: %s", message, strerror(error));
+       snprintf(buf,sizeof(buf), "%s: %s", message, strerror(error));
        message = buf;
     }
     ErrorPopUp(_("Error"), message, FALSE);
@@ -7558,7 +7573,7 @@ void DisplayFatalError(message, error, status)
     } else {
        fprintf(stderr, "%s: %s: %s\n",
                programName, message, strerror(error));
-       sprintf(buf, "%s: %s", message, strerror(error));
+       snprintf(buf, sizeof(buf), "%s: %s", message, strerror(error));
        message = buf;
     }
     if (appData.popupExitMessage && boardWidget && XtIsRealized(boardWidget)) {
@@ -7747,7 +7762,7 @@ PlaySound(name)
     putc(BELLCHAR, stderr);
   } else {
     char buf[2048];
-    sprintf(buf, "%s '%s' &", appData.soundProgram, name);
+    snprintf(buf, sizeof(buf), "%s '%s' &", appData.soundProgram, name);
     system(buf);
   }
 }
@@ -8266,9 +8281,9 @@ int OpenTelnet(host, port, pr)
     char cmdLine[MSG_SIZ];
 
     if (port[0] == NULLCHAR) {
-       sprintf(cmdLine, "%s %s", appData.telnetProgram, host);
+      snprintf(cmdLine, sizeof(cmdLine), "%s %s", appData.telnetProgram, host);
     } else {
-       sprintf(cmdLine, "%s %s %s", appData.telnetProgram, host, port);
+      snprintf(cmdLine,sizeof(cmdLine), "%s %s %s", appData.telnetProgram, host, port);
     }
     return StartChildProcess(cmdLine, "", pr);
 }