fixed crash in history window
[xboard.git] / xhistory.c
index 6fe5b92..c247acb 100644 (file)
@@ -2,28 +2,24 @@
  * xhistory.c -- Move list window, part of X front end for XBoard\r
  * $Id$\r
  *\r
- * Copyright 2000 Free Software Foundation, Inc.\r
- *\r
- * The following terms apply to the enhanced version of XBoard distributed\r
- * by the Free Software Foundation:\r
+ * Copyright 2000,2009 Free Software Foundation, Inc.\r
  * ------------------------------------------------------------------------\r
- * This program is free software; you can redistribute it and/or modify\r
+ *\r
+ * GNU XBoard is free software: you can redistribute it and/or modify\r
  * it under the terms of the GNU General Public License as published by\r
- * the Free Software Foundation; either version 2 of the License, or\r
- * (at your option) any later version.\r
+ * the Free Software Foundation, either version 3 of the License, or (at\r
+ * your option) any later version.\r
  *\r
- * This program is distributed in the hope that it will be useful,\r
- * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
- * GNU General Public License for more details.\r
+ * GNU XBoard is distributed in the hope that it will be useful, but\r
+ * WITHOUT ANY WARRANTY; without even the implied warranty of\r
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU\r
+ * General Public License for more details.\r
  *\r
  * You should have received a copy of the GNU General Public License\r
- * along with this program; if not, write to the Free Software\r
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\r
- * ------------------------------------------------------------------------\r
+ * along with this program. If not, see http://www.gnu.org/licenses/.  *\r
  *\r
- * See the file ChangeLog for a revision history.\r
- */\r
+ *------------------------------------------------------------------------\r
+ ** See the file ChangeLog for a revision history.  */\r
 \r
 #include "config.h"\r
 \r
@@ -91,7 +87,7 @@ extern char *layoutName;
 \r
 struct History{\r
   String *Nr,*white,*black;\r
-  int     aNr;  /* space actually alocated */  \r
+  int     aNr;  /* space actually alocated */\r
   Widget mvn,mvw,mvb,vbox,viewport,sh;\r
   char Up;\r
 };\r
@@ -119,7 +115,7 @@ HistoryPopDown(w, client_data, call_data)
   }\r
   j=0;\r
   XtSetArg(args[j], XtNleftBitmap, None); j++;\r
-  XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move List"),\r
+  XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),\r
                args, j);\r
 }\r
 \r
@@ -144,13 +140,13 @@ void HistoryAlloc(int len){
     free(hist->Nr);free(hist->white);free(hist->black);\r
   }\r
   else{\r
-    hist=(struct History*)malloc(sizeof(struct History)); \r
+    hist=(struct History*)malloc(sizeof(struct History));\r
   }\r
     hist->aNr=len;\r
     hist->Nr=(String*)malloc(hist->aNr*sizeof(String*));\r
     hist->white=(String*)malloc(hist->aNr*sizeof(String*));\r
     hist->black=(String*)malloc(hist->aNr*sizeof(String*));\r
-    \r
+\r
     hist->Nr[0]=(String)malloc(hist->aNr*6);\r
     hist->white[0]=(String)malloc(hist->aNr*MOVE_LEN);\r
     hist->black[0]=(String)malloc(hist->aNr*MOVE_LEN);\r
@@ -201,7 +197,7 @@ HistoryFill()
   } else {\r
     extra = extra/2;\r
   }\r
\r
+\r
   j = 0;\r
   XtSetArg(args[j], XtNwidth, &w);  j++;\r
   XtGetValues(hist->mvw, args, j);\r
@@ -276,7 +272,7 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
   if(hist){\r
     if(last >= hist->aNr) HistoryAlloc(last+_LL_);\r
     for(i=0;i<last;i++) {\r
-      if((i%2)==0) { \r
+      if((i%2)==0) {\r
        if(movelist[i][0]) {\r
          char* p = strchr(movelist[i], ' ');\r
          if (p) {\r
@@ -284,7 +280,7 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
            hist->white[i/2+1][p-movelist[i]] = NULLCHAR;\r
          } else {\r
            strcpy(hist->white[i/2+1],movelist[i]);\r
-         }         \r
+         }\r
        } else {\r
          strcpy(hist->white[i/2+1],dots);\r
        }\r
@@ -296,7 +292,7 @@ void HistorySet(char movelist[][2*MOVE_LEN],int first,int last,int current){
            hist->black[i/2+1][p-movelist[i]] = NULLCHAR;\r
          } else {\r
            strcpy(hist->black[i/2+1],movelist[i]);\r
-         }         \r
+         }\r
        } else {\r
          strcpy(hist->black[i/2+1],"");\r
        }\r
@@ -340,11 +336,11 @@ Widget HistoryCreate()
              <Key>Right: ForwardProc() \n";\r
     /*--- allocate memory for move-strings ---*/\r
     HistoryAlloc(_LL_);\r
-   \r
+\r
     /*-------- create the widgets ---------------*/\r
     j = 0;\r
     XtSetArg(args[j], XtNresizable, True);  j++;\r
-    XtSetArg(args[j], XtNallowShellResize, True);  j++;   \r
+    XtSetArg(args[j], XtNallowShellResize, True);  j++;\r
 #if TOPLEVEL\r
     hist->sh =\r
       XtCreatePopupShell(_("Move list"), topLevelShellWidgetClass,\r
@@ -353,18 +349,18 @@ Widget HistoryCreate()
     hist->sh =\r
       XtCreatePopupShell(_("Move list"), transientShellWidgetClass,\r
                         shellWidget, args, j);\r
-#endif        \r
+#endif\r
     j = 0;\r
     XtSetArg(args[j], XtNborderWidth, 0); j++;\r
     XtSetArg(args[j], XtNdefaultDistance, 0);  j++;\r
       layout =\r
       XtCreateManagedWidget(layoutName, formWidgetClass, hist->sh,\r
                            args, j);\r
-    \r
+\r
     j = 0;\r
     XtSetArg(args[j], XtNborderWidth, 0); j++;\r
     XtSetArg(args[j], XtNresizable, True);  j++;\r
-  \r
+\r
     form =\r
       XtCreateManagedWidget("form", formWidgetClass, layout, args, j);\r
      j=0;\r
@@ -390,13 +386,13 @@ Widget HistoryCreate()
     XtSetArg(args[j], XtNorientation,XtorientHorizontal);j++;\r
     hist->vbox =\r
       XtCreateManagedWidget("vbox", formWidgetClass, hist->viewport, args, j);\r
-    \r
+\r
     j=0;\r
     XtSetArg(args[j], XtNtop, XtChainTop);  j++;\r
     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;\r
     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;\r
-    XtSetArg(args[j], XtNright, XtChainLeft);  j++;    \r
-     \r
+    XtSetArg(args[j], XtNright, XtChainLeft);  j++;\r
+\r
     XtSetArg(args[j], XtNdefaultColumns, 1);  j++;\r
     XtSetArg(args[j], XtNforceColumns, True);  j++;\r
     XtSetArg(args[j], XtNverticalList, True);  j++;\r
@@ -411,8 +407,8 @@ Widget HistoryCreate()
     XtSetArg(args[j], XtNtop, XtChainTop);  j++;\r
     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;\r
     XtSetArg(args[j], XtNleft, XtChainLeft);  j++;\r
-    XtSetArg(args[j], XtNright, XtRubber);  j++;    \r
-    \r
+    XtSetArg(args[j], XtNright, XtRubber);  j++;\r
+\r
     XtSetArg(args[j], XtNdefaultColumns, 1);  j++;\r
     XtSetArg(args[j], XtNforceColumns, True);  j++;\r
     XtSetArg(args[j], XtNverticalList, True);  j++;\r
@@ -428,7 +424,7 @@ Widget HistoryCreate()
     XtSetArg(args[j], XtNbottom, XtChainTop);  j++;\r
     XtSetArg(args[j], XtNleft, XtRubber);  j++;\r
     XtSetArg(args[j], XtNright,  XtRubber);  j++;\r
-    \r
+\r
     XtSetArg(args[j], XtNdefaultColumns, 1);  j++;\r
     XtSetArg(args[j], XtNforceColumns, True);  j++;\r
     XtSetArg(args[j], XtNverticalList, True);  j++;\r
@@ -446,10 +442,10 @@ Widget HistoryCreate()
     XtSetArg(args[j], XtNright, XtChainLeft);  j++;\r
     XtSetArg(args[j], XtNfromVert, hist->viewport);  j++;\r
     b_close= XtCreateManagedWidget(_("Close"), commandWidgetClass,\r
-                                  form, args, j);   \r
+                                  form, args, j);\r
     XtAddCallback(b_close, XtNcallback, HistoryPopDown, (XtPointer) 0);\r
 \r
-    XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr)); \r
+    XtAugmentTranslations(hist->sh,XtParseTranslationTable (trstr));\r
 \r
     XtRealizeWidget(hist->sh);\r
     CatchDeleteWindow(hist->sh, "HistoryPopDown");\r
@@ -458,7 +454,7 @@ Widget HistoryCreate()
       strcpy(hist->white[i],dots);\r
       strcpy(hist->black[i],"");\r
      }\r
-   \r
+\r
     return hist->sh;\r
 }\r
 \r
@@ -469,6 +465,7 @@ HistoryPopUp()
   int j;\r
 \r
   if(!hist) HistoryCreate();\r
+\r
   XtPopup(hist->sh, XtGrabNone);\r
 \r
   // [HGM] restore old position\r
@@ -479,12 +476,12 @@ HistoryPopUp()
 \r
   j=0;\r
   XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;\r
-  XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move List"),\r
+  XtSetValues(XtNameToWidget(menuBarWidget, "menuMode.Show Move History"),\r
                args, j);\r
   hist->Up=True;\r
 }\r
 \r
\r
+\r
 void\r
 HistoryShowProc(w, event, prms, nprms)\r
      Widget w;\r
@@ -502,4 +499,4 @@ HistoryShowProc(w, event, prms, nprms)
   }\r
   ToNrEvent(currentMove);\r
 }\r
\r
+\r