X-Git-Url: http://winboard.nl/cgi-bin?a=blobdiff_plain;f=winboard%2Fwclipbrd.c;h=6f546a423eaa171edb892faa8b59ee359588bca5;hb=ca99bd4de57d0b079024cbdf5435de1ae61d5fd9;hp=d04ce9a181970eae25753a9b1ccbdd30e431eb73;hpb=29df666d997ad990de5376c962b154b26eb73f2f;p=xboard.git diff --git a/winboard/wclipbrd.c b/winboard/wclipbrd.c index d04ce9a..6f546a4 100644 --- a/winboard/wclipbrd.c +++ b/winboard/wclipbrd.c @@ -1,25 +1,27 @@ /* * wclipbrd.c -- Clipboard routines for WinBoard - * $Id: wclipbrd.c,v 2.1 2003/10/27 19:21:02 mann Exp $ * - * Copyright 2000 Free Software Foundation, Inc. + * Copyright 2000,2009 Free Software Foundation, Inc. + * + * Enhancements Copyright 2005 Alessandro Scotti * * ------------------------------------------------------------------------ - * This program is free software; you can redistribute it and/or modify + * + * GNU XBoard is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. + * the Free Software Foundation, either version 3 of the License, or (at + * your option) any later version. * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. + * GNU XBoard is distributed in the hope that it will be useful, but + * WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - * ------------------------------------------------------------------------ - */ + * along with this program. If not, see http://www.gnu.org/licenses/. * + * + *------------------------------------------------------------------------ + ** See the file ChangeLog for a revision history. */ #include "config.h" @@ -37,6 +39,7 @@ /* Imports from winboard.c */ extern HWND hwndMain; +Boolean ParseFEN(Board b, int *stm, char *FEN); /* File globals */ static char *copyTemp; @@ -47,7 +50,7 @@ CopyFENToClipboard() { char *fen = NULL; - fen = PositionToFEN(currentMove,1); + fen = PositionToFEN(currentMove, NULL); if (!fen) { DisplayError("Unable to convert position to FEN.", 0); return; @@ -57,38 +60,38 @@ CopyFENToClipboard() free(fen); } -/* [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] */ +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 ); + } + } +} VOID CopyGameToClipboard() @@ -197,7 +200,7 @@ CopyTextToClipboard(char *text) locked = !((err == NO_ERROR) || (err == ERROR_NOT_LOCKED)); if (appData.debugMode) { fprintf(debugFP, - "CopyTextToClipboard(): err %d locked %d\n", err, locked); + "CopyTextToClipboard(): err %d locked %d\n", (int)err, locked); } } if (locked) { @@ -226,16 +229,16 @@ CopyTextToClipboard(char *text) return TRUE; } -/* [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 */ + +VOID PasteFENFromString( char * fen ) +{ + if (appData.debugMode) { + fprintf(debugFP, "PasteFenFromString(): fen '%s'\n", fen); + } + EditPositionPasteFEN(fen); /* call into backend */ + free(fen); +} VOID @@ -246,10 +249,10 @@ PasteFENFromClipboard() DisplayError("Unable to paste FEN from clipboard.", 0); return; } - PasteFENFromString( fen ); + PasteFENFromString( fen ); } -VOID PasteGameFromString( char * buf ) +VOID PasteGameFromString( char * buf ) { FILE *f; size_t len; @@ -259,55 +262,52 @@ VOID PasteGameFromString( char * buf ) f = fopen(pasteTemp, "w"); if (!f) { DisplayError("Unable to create temporary file.", 0); - free(buf); /* [AS] */ + free(buf); /* [AS] */ return; } len = fwrite(buf, sizeof(char), strlen(buf), f); fclose(f); if (len != strlen(buf)) { DisplayError("Error writing to temporary file.", 0); - free(buf); /* [AS] */ + free(buf); /* [AS] */ return; } LoadGameFromFile(pasteTemp, 0, "Clipboard", TRUE); - 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] */ +} + + +VOID +PasteGameFromClipboard() +{ + /* Write the clipboard to a temp file, then let LoadGameFromFile() + * do all the work. */ + char *buf; + if (!PasteTextFromClipboard(&buf)) { + return; + } + PasteGameFromString( buf ); } -/* [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 */ +VOID PasteGameOrFENFromClipboard() +{ + char *buf; +// char *tmp; + Board dummyBoard; int dummy; // [HGM] paste any + + if (!PasteTextFromClipboard(&buf)) { + return; + } + + // [HGM] paste any: make still smarter, to allow pasting of games without tags, recognize FEN in stead + if(!ParseFEN(dummyBoard, &dummy, buf) ) { + PasteGameFromString( buf ); + } + else { + PasteFENFromString( buf ); + } +} int PasteTextFromClipboard(char **text) @@ -349,15 +349,11 @@ PasteTextFromClipboard(char **text) fprintf(debugFP, "PasteTextFromClipboard(): lock count %d\n", lockCount); } SetLastError(NO_ERROR); -#if 1 /*suggested by Wilkin Ng*/ lockCount = GlobalFlags(hClipMem) & GMEM_LOCKCOUNT; if (lockCount) { locked = GlobalUnlock(hClipMem); } -#else - locked = GlobalUnlock(hClipMem); -#endif err = GetLastError(); if (appData.debugMode) { lockCount = GlobalFlags(hClipMem) & GMEM_LOCKCOUNT; @@ -367,7 +363,7 @@ PasteTextFromClipboard(char **text) locked = !((err == NO_ERROR) || (err == ERROR_NOT_LOCKED)); if (appData.debugMode) { fprintf(debugFP, - "PasteTextFromClipboard(): err %d locked %d\n", err, locked); + "PasteTextFromClipboard(): err %d locked %d\n", (int)err, locked); } } if (locked)