[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[gnugo-devel] printsgf - in gtp
From: |
Douglas Ridgway |
Subject: |
[gnugo-devel] printsgf - in gtp |
Date: |
Mon, 20 Sep 2004 09:38:24 -0600 (MDT) |
At the moment, "printsgf -" doesn't work in gtp mode. This fixes it, and
also make "-" the default if no filename is provided.
doug.
----
Index: interface/play_gtp.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/interface/play_gtp.c,v
retrieving revision 1.153
diff -u -r1.153 play_gtp.c
--- interface/play_gtp.c 19 Jul 2004 12:23:09 -0000 1.153
+++ interface/play_gtp.c 20 Sep 2004 15:32:25 -0000
@@ -4208,10 +4208,11 @@
}
-/* Function: Dump the current position as a static sgf file
- * Arguments: filename
- * Fails: missing filename
- * Returns: nothing
+/* Function: Dump the current position as a static sgf file to filename,
+ * or as output if filename is missing or "-"
+ * Arguments: optional filename
+ * Fails: never
+ * Returns: nothing if filename, otherwise the sgf
*/
static int
gtp_printsgf(char *s)
@@ -4220,17 +4221,26 @@
int nread;
int next;
- nread = sscanf(s, "%s", filename);
- if (nread < 1)
- return gtp_failure("missing filename");
-
if (get_last_player() == EMPTY)
next = BLACK;
else
next = OTHER_COLOR(get_last_player());
- sgffile_printsgf(next, filename);
- return gtp_success("");
+ nread = sscanf(s, "%s", filename);
+
+ if (nread < 1) {
+ gg_snprintf(filename, GTP_BUFSIZE, "%s", "-");
+ }
+
+ if (strcmp(filename, "-") == 0) {
+ gtp_start_response(GTP_SUCCESS);
+ sgffile_printsgf(next, filename);
+ gtp_printf("\n");
+ return GTP_OK;
+ } else {
+ sgffile_printsgf(next, filename);
+ return gtp_success("");
+ }
}
Index: sgf/sgfnode.c
===================================================================
RCS file: /cvsroot/gnugo/gnugo/sgf/sgfnode.c,v
retrieving revision 1.27
diff -u -r1.27 sgfnode.c
--- sgf/sgfnode.c 25 Jan 2004 21:38:49 -0000 1.27
+++ sgf/sgfnode.c 20 Sep 2004 15:32:25 -0000
@@ -1502,7 +1502,7 @@
sgf_column = 0;
unparse_game(outfile, root, 1);
- fclose(outfile);
+ if (outfile != stdout) fclose(outfile);
/* Remove "printed" marks so that the tree can be written multiple
* times.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [gnugo-devel] printsgf - in gtp,
Douglas Ridgway <=