/*\r
* wclipbrd.c -- Clipboard routines for WinBoard\r
- * $Id: wclipbrd.c,v 2.1 2003/10/27 19:21:02 mann Exp $
*\r
- * Copyright 2000 Free Software Foundation, Inc.\r
+ * Copyright 2000,2009 Free Software Foundation, Inc.\r
+ *\r
+ * Enhancements Copyright 2005 Alessandro Scotti\r
*\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., 675 Mass Ave, Cambridge, MA 02139, USA.\r
- * ------------------------------------------------------------------------\r
- */\r
+ * along with this program. If not, see http://www.gnu.org/licenses/. *\r
+ *\r
+ *------------------------------------------------------------------------\r
+ ** See the file ChangeLog for a revision history. */\r
\r
#include "config.h"\r
\r
\r
/* Imports from winboard.c */\r
extern HWND hwndMain;\r
+Boolean ParseFEN(Board b, int *stm, char *FEN);\r
\r
/* File globals */\r
static char *copyTemp;\r
{\r
char *fen = NULL;\r
\r
- fen = PositionToFEN(currentMove,1);
+ fen = PositionToFEN(currentMove, NULL);\r
if (!fen) {\r
DisplayError("Unable to convert position to FEN.", 0);\r
return;\r
free(fen);\r
}\r
\r
-/* [AS] */
-HGLOBAL ExportGameListAsText();
-
-VOID CopyGameListToClipboard()
-{
- HGLOBAL hMem = ExportGameListAsText();
-
- if( hMem != NULL ) {
- /* Assign memory block to clipboard */
- BOOL ok = OpenClipboard( hwndMain );
-
- if( ok ) {
- ok = EmptyClipboard();
-
- if( ok ) {
- if( hMem != SetClipboardData( CF_TEXT, hMem ) ) {
- ok = FALSE;
- }
- }
-
- CloseClipboard();
-
- if( ! ok ) {
- GlobalFree( hMem );
- }
- }
-
- if( ! ok ) {
- DisplayError( "Cannot copy list to clipboard.", 0 );
- }
- }
-}
+/* [AS] */\r
+HGLOBAL ExportGameListAsText();\r
+\r
+VOID CopyGameListToClipboard()\r
+{\r
+ HGLOBAL hMem = ExportGameListAsText();\r
+ \r
+ if( hMem != NULL ) {\r
+ /* Assign memory block to clipboard */\r
+ BOOL ok = OpenClipboard( hwndMain );\r
+\r
+ if( ok ) {\r
+ ok = EmptyClipboard();\r
+\r
+ if( ok ) {\r
+ if( hMem != SetClipboardData( CF_TEXT, hMem ) ) {\r
+ ok = FALSE;\r
+ }\r
+ }\r
+\r
+ CloseClipboard();\r
+\r
+ if( ! ok ) {\r
+ GlobalFree( hMem );\r
+ }\r
+ }\r
+\r
+ if( ! ok ) {\r
+ DisplayError( "Cannot copy list to clipboard.", 0 );\r
+ }\r
+ }\r
+}\r
\r
VOID\r
CopyGameToClipboard()\r
locked = !((err == NO_ERROR) || (err == ERROR_NOT_LOCKED));\r
if (appData.debugMode) {\r
fprintf(debugFP, \r
- "CopyTextToClipboard(): err %d locked %d\n", err, locked);\r
+ "CopyTextToClipboard(): err %d locked %d\n", (int)err, locked);\r
}\r
}\r
if (locked) {\r
return TRUE;\r
}\r
\r
-/* [AS] Reworked paste functions so they can work with strings too */
-
-VOID PasteFENFromString( char * fen )
-{
- if (appData.debugMode) {
- fprintf(debugFP, "PasteFenFromString(): fen '%s'\n", fen);
- }
- EditPositionPasteFEN(fen); /* call into backend */
- free(fen);
-}
+/* [AS] Reworked paste functions so they can work with strings too */\r
+\r
+VOID PasteFENFromString( char * fen )\r
+{\r
+ if (appData.debugMode) {\r
+ fprintf(debugFP, "PasteFenFromString(): fen '%s'\n", fen);\r
+ }\r
+ EditPositionPasteFEN(fen); /* call into backend */\r
+ free(fen);\r
+}\r
\r
\r
VOID\r
DisplayError("Unable to paste FEN from clipboard.", 0);\r
return;\r
}\r
- PasteFENFromString( fen );
+ PasteFENFromString( fen );\r
}\r
\r
-VOID PasteGameFromString( char * buf )
+VOID PasteGameFromString( char * buf )\r
{\r
FILE *f;\r
size_t len;\r
f = fopen(pasteTemp, "w");\r
if (!f) {\r
DisplayError("Unable to create temporary file.", 0);\r
- free(buf); /* [AS] */
+ free(buf); /* [AS] */\r
return;\r
}\r
len = fwrite(buf, sizeof(char), strlen(buf), f);\r
fclose(f);\r
if (len != strlen(buf)) {\r
DisplayError("Error writing to temporary file.", 0);\r
- free(buf); /* [AS] */
+ free(buf); /* [AS] */\r
return;\r
}\r
LoadGameFromFile(pasteTemp, 0, "Clipboard", TRUE);\r
- free( buf ); /* [AS] */
-}
-
-
-VOID
-PasteGameFromClipboard()
-{
- /* Write the clipboard to a temp file, then let LoadGameFromFile()
- * do all the work. */
- char *buf;
- if (!PasteTextFromClipboard(&buf)) {
- return;
- }
- PasteGameFromString( buf );
+ free( buf ); /* [AS] */\r
+}\r
+\r
+\r
+VOID\r
+PasteGameFromClipboard()\r
+{\r
+ /* Write the clipboard to a temp file, then let LoadGameFromFile()\r
+ * do all the work. */\r
+ char *buf;\r
+ if (!PasteTextFromClipboard(&buf)) {\r
+ return;\r
+ }\r
+ PasteGameFromString( buf );\r
}\r
\r
-/* [AS] Try to detect whether the clipboard contains FEN or PGN data */
-VOID PasteGameOrFENFromClipboard()
-{
- char *buf;
- char *tmp;
-
- if (!PasteTextFromClipboard(&buf)) {
- return;
- }
-
- tmp = buf;
- while( *tmp == ' ' || *tmp == '\t' || *tmp == '\r' || *tmp == '\n' ) {
- tmp++;
- }
-
- if( *tmp == '[' ) {
- PasteGameFromString( buf );
- }
- else {
- PasteFENFromString( buf );
- }
-}
+/* [AS] Try to detect whether the clipboard contains FEN or PGN data */\r
+VOID PasteGameOrFENFromClipboard()\r
+{\r
+ char *buf;\r
+// char *tmp;\r
+ Board dummyBoard; int dummy; // [HGM] paste any\r
+\r
+ if (!PasteTextFromClipboard(&buf)) {\r
+ return;\r
+ }\r
+\r
+ // [HGM] paste any: make still smarter, to allow pasting of games without tags, recognize FEN in stead\r
+ if(!ParseFEN(dummyBoard, &dummy, buf) ) {\r
+ PasteGameFromString( buf );\r
+ }\r
+ else {\r
+ PasteFENFromString( buf );\r
+ }\r
+}\r
\r
int \r
PasteTextFromClipboard(char **text)\r
fprintf(debugFP, "PasteTextFromClipboard(): lock count %d\n", lockCount);\r
}\r
SetLastError(NO_ERROR);\r
-#if 1\r
/*suggested by Wilkin Ng*/\r
lockCount = GlobalFlags(hClipMem) & GMEM_LOCKCOUNT;\r
if (lockCount) {\r
locked = GlobalUnlock(hClipMem);\r
}\r
-#else\r
- locked = GlobalUnlock(hClipMem);\r
-#endif\r
err = GetLastError();\r
if (appData.debugMode) {\r
lockCount = GlobalFlags(hClipMem) & GMEM_LOCKCOUNT;\r
locked = !((err == NO_ERROR) || (err == ERROR_NOT_LOCKED));\r
if (appData.debugMode) {\r
fprintf(debugFP, \r
- "PasteTextFromClipboard(): err %d locked %d\n", err, locked);\r
+ "PasteTextFromClipboard(): err %d locked %d\n", (int)err, locked);\r
}\r
}\r
if (locked) \r