Implement Grand Chess
[xboard.git] / xgamelist.c
index d458898..46200c5 100644 (file)
@@ -1,7 +1,7 @@
 /*
  * xgamelist.c -- Game list window, part of X front end for XBoard
  *
- * Copyright 1995, 2009, 2010 Free Software Foundation, Inc.
+ * Copyright 1995, 2009, 2010, 2011 Free Software Foundation, Inc.
  * ------------------------------------------------------------------------
  *
  * GNU XBoard is free software: you can redistribute it and/or modify
@@ -93,12 +93,6 @@ extern char *getenv();
 
 void SetFocus P((Widget w, XtPointer data, XEvent *event, Boolean *b));
 
-extern Widget formWidget, shellWidget, boardWidget, menuBarWidget, gameListShell;
-extern Display *xDisplay;
-extern int squareSize;
-extern Pixmap xMarkPixmap;
-extern char *layoutName;
-
 static Widget filterText;
 static char filterString[MSG_SIZ];
 static int listLength;
@@ -126,11 +120,6 @@ typedef struct {
 } GameListClosure;
 static GameListClosure *glc = NULL;
 
-static Arg layoutArgs[] = {
-    { XtNborderWidth, 0 },
-    { XtNdefaultDistance, 0 }
-};
-
 Widget
 GameListCreate(name, callback, client_data)
      char *name;
@@ -419,12 +408,16 @@ GameListCallback(w, client_data, call_data)
         if(GameListPrepare()) GameListReplace(); // crashes on empty list...
         return;
     }
+#if 0
     index = atoi(glc->strings[index])-1; // [HGM] filter: read true index from sequence nr of line
     if (cmailMsgLoaded) {
        CmailLoadGame(glc->fp, index + 1, glc->filename, True);
     } else {
        LoadGame(glc->fp, index + 1, glc->filename, True);
     }
+#else
+    printf("This code should have been unreachable. Please report bug!\n");
+#endif
 }
 
 void
@@ -516,6 +509,7 @@ ShowGameListProc(w, event, prms, nprms)
     XtSetArg(args[j], XtNleftBitmap, xMarkPixmap); j++;
     XtSetValues(XtNameToWidget(menuBarWidget, "menuView.Show Game List"),
                args, j);
+    GameListHighlight(lastLoadGameNumber);
 }
 
 void
@@ -618,6 +612,35 @@ GameListIsUp()
     return glc && glc->up;
 }
 
+int SaveGameListAsText(FILE *f)\r
+{\r
+    ListGame * lg = (ListGame *) gameList.head;\r
+    int nItem;\r
+\r
+    if( !glc || ((ListGame *) gameList.tailPred)->number <= 0 ) {\r
+        DisplayError("Game list not loaded or empty", 0);\r
+        return False;\r
+    }\r
+\r
+    /* Copy the list into the global memory block */\r
+    if( f != NULL ) {\r
+        lg = (ListGame *) gameList.head;\r
+\r
+        for (nItem = 0; nItem < ((ListGame *) gameList.tailPred)->number; nItem++){\r
+            char * st = GameListLineFull(lg->number, &lg->gameInfo);\r
+           char *line = GameListLine(lg->number, &lg->gameInfo);
+           if(filterString[0] == NULLCHAR || SearchPattern( line, filterString ) )
+                   fprintf( f, "%s\n", st );
+           free(st); free(line);\r
+            lg = (ListGame *) lg->node.succ;\r
+        }\r
+\r
+        fclose(f);
+       return True;\r
+    }
+    return False;\r
+}\r
 //--------------------------------- Game-List options dialog ------------------------------------------
 
 Widget gameListOptShell, listwidg;