Index: ChangeLog =================================================================== RCS file: /cvsroot/gnugo/gnugo/ChangeLog,v retrieving revision 1.926 diff -u -r1.926 ChangeLog --- ChangeLog 30 Sep 2005 19:43:37 -0000 1.926 +++ ChangeLog 30 Sep 2005 22:21:21 -0000 @@ -2,6 +2,7 @@ -- ChangeLog ------------------------------------------------------------------------- +- patterns/transpat.c, patterns/patlib.c, and patterns/patlib.h removed - unused game records in regression/golois removed - makevcdist.pl updated and re-run - all Makefile.in regenerated Index: patterns/Makefile.am =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/Makefile.am,v retrieving revision 1.38 diff -u -r1.38 Makefile.am --- patterns/Makefile.am 28 Sep 2005 21:52:04 -0000 1.38 +++ patterns/Makefile.am 30 Sep 2005 22:21:22 -0000 @@ -1,5 +1,5 @@ noinst_PROGRAMS = mkpat joseki mkeyes uncompress_fuseki -EXTRA_PROGRAMS = extract_fuseki transpat compress_fuseki +EXTRA_PROGRAMS = extract_fuseki compress_fuseki DSP = dfa.dsp patterns.dsp joseki.dsp mkeyes.dsp mkpat.dsp fuseki.dsp DTR = aa_attackpats.dtr owl_attackpats.dtr owl_defendpats.dtr \ @@ -46,8 +46,6 @@ DFAFLAGS = endif -transpat_SOURCES = transpat.c patlib.c transform.c -transpat_LDADD = joseki_SOURCES = joseki.c joseki_LDADD = ../engine/libboard.a ../sgf/libsgf.a ../utils/libutils.a joseki_AM_CPPFLAGS = $(GNU_GO_WARNINGS) -I$(top_srcdir)/sgf @@ -64,7 +62,7 @@ uncompress_fuseki_LDADD = ../utils/libutils.a ../engine/libboard.a ../sgf/libsgf.a compress_fuseki_SOURCES = compress_fuseki.c -noinst_HEADERS = patterns.h eyes.h patlib.h dfa.h dfa-mkpat.h +noinst_HEADERS = patterns.h eyes.h dfa.h dfa-mkpat.h GGBUILTSOURCES = conn.c patterns.c apatterns.c dpatterns.c eyes.c\ influence.c barriers.c endgame.c aa_attackpat.c\ Index: patterns/Makefile.in =================================================================== RCS file: /cvsroot/gnugo/gnugo/patterns/Makefile.in,v retrieving revision 1.58 diff -u -r1.58 Makefile.in --- patterns/Makefile.in 28 Sep 2005 23:53:46 -0000 1.58 +++ patterns/Makefile.in 30 Sep 2005 22:21:22 -0000 @@ -76,7 +76,7 @@ install_sh = @install_sh@ noinst_PROGRAMS = mkpat joseki mkeyes uncompress_fuseki -EXTRA_PROGRAMS = extract_fuseki transpat compress_fuseki +EXTRA_PROGRAMS = extract_fuseki compress_fuseki DSP = dfa.dsp patterns.dsp joseki.dsp mkeyes.dsp mkpat.dsp fuseki.dsp DTR = aa_attackpats.dtr owl_attackpats.dtr owl_defendpats.dtr \ @@ -122,8 +122,6 @@ @DFA_ENABLED_TRUE@DFAFLAGS = -D -m @DFA_ENABLED_FALSE@DFAFLAGS = -transpat_SOURCES = transpat.c patlib.c transform.c -transpat_LDADD = joseki_SOURCES = joseki.c joseki_LDADD = ../engine/libboard.a ../sgf/libsgf.a ../utils/libutils.a joseki_AM_CPPFLAGS = $(GNU_GO_WARNINGS) -I$(top_srcdir)/sgf @@ -141,7 +139,7 @@ uncompress_fuseki_LDADD = ../utils/libutils.a ../engine/libboard.a ../sgf/libsgf.a compress_fuseki_SOURCES = compress_fuseki.c -noinst_HEADERS = patterns.h eyes.h patlib.h dfa.h dfa-mkpat.h +noinst_HEADERS = patterns.h eyes.h dfa.h dfa-mkpat.h GGBUILTSOURCES = conn.c patterns.c apatterns.c dpatterns.c eyes.c\ influence.c barriers.c endgame.c aa_attackpat.c\ @@ -203,7 +201,7 @@ fuseki19.$(OBJEXT) josekidb.$(OBJEXT) handipat.$(OBJEXT) \ oraclepat.$(OBJEXT) libpatterns_a_OBJECTS = $(am_libpatterns_a_OBJECTS) -EXTRA_PROGRAMS = extract_fuseki$(EXEEXT) transpat$(EXEEXT) \ +EXTRA_PROGRAMS = extract_fuseki$(EXEEXT) \ compress_fuseki$(EXEEXT) noinst_PROGRAMS = mkpat$(EXEEXT) joseki$(EXEEXT) mkeyes$(EXEEXT) \ uncompress_fuseki$(EXEEXT) @@ -233,11 +231,6 @@ mkpat_OBJECTS = $(am_mkpat_OBJECTS) mkpat_DEPENDENCIES = ../utils/libutils.a mkpat_LDFLAGS = -am_transpat_OBJECTS = transpat.$(OBJEXT) patlib.$(OBJEXT) \ - transform.$(OBJEXT) -transpat_OBJECTS = $(am_transpat_OBJECTS) -transpat_DEPENDENCIES = -transpat_LDFLAGS = am_uncompress_fuseki_OBJECTS = uncompress_fuseki.$(OBJEXT) uncompress_fuseki_OBJECTS = $(am_uncompress_fuseki_OBJECTS) uncompress_fuseki_DEPENDENCIES = ../utils/libutils.a \ @@ -263,9 +256,8 @@ @AMDEP_TRUE@ $(DEPDIR)/mkeyes.Po $(DEPDIR)/mkpat.Po \ @AMDEP_TRUE@ $(DEPDIR)/oraclepat.Po $(DEPDIR)/owl_attackpat.Po \ @AMDEP_TRUE@ $(DEPDIR)/owl_defendpat.Po \ -@AMDEP_TRUE@ $(DEPDIR)/owl_vital_apat.Po $(DEPDIR)/patlib.Po \ +@AMDEP_TRUE@ $(DEPDIR)/owl_vital_apat.Po \ @AMDEP_TRUE@ $(DEPDIR)/patterns.Po $(DEPDIR)/transform.Po \ -@AMDEP_TRUE@ $(DEPDIR)/transpat.Po \ @AMDEP_TRUE@ $(DEPDIR)/uncompress_fuseki.Po COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) @@ -274,12 +266,12 @@ CFLAGS = @CFLAGS@ DIST_SOURCES = $(libpatterns_a_SOURCES) $(compress_fuseki_SOURCES) \ $(extract_fuseki_SOURCES) $(joseki_SOURCES) $(mkeyes_SOURCES) \ - $(mkpat_SOURCES) $(transpat_SOURCES) \ + $(mkpat_SOURCES) \ $(uncompress_fuseki_SOURCES) HEADERS = $(noinst_HEADERS) DIST_COMMON = README $(noinst_HEADERS) Makefile.am Makefile.in -SOURCES = $(libpatterns_a_SOURCES) $(compress_fuseki_SOURCES) $(extract_fuseki_SOURCES) $(joseki_SOURCES) $(mkeyes_SOURCES) $(mkpat_SOURCES) $(transpat_SOURCES) $(uncompress_fuseki_SOURCES) +SOURCES = $(libpatterns_a_SOURCES) $(compress_fuseki_SOURCES) $(extract_fuseki_SOURCES) $(joseki_SOURCES) $(mkeyes_SOURCES) $(mkpat_SOURCES) $(uncompress_fuseki_SOURCES) all: all-am @@ -319,9 +311,6 @@ mkpat$(EXEEXT): $(mkpat_OBJECTS) $(mkpat_DEPENDENCIES) @rm -f mkpat$(EXEEXT) $(LINK) $(mkpat_LDFLAGS) $(mkpat_OBJECTS) $(mkpat_LDADD) $(LIBS) -transpat$(EXEEXT): $(transpat_OBJECTS) $(transpat_DEPENDENCIES) - @rm -f transpat$(EXEEXT) - $(LINK) $(transpat_LDFLAGS) $(transpat_OBJECTS) $(transpat_LDADD) $(LIBS) uncompress_fuseki$(EXEEXT): $(uncompress_fuseki_OBJECTS) $(uncompress_fuseki_DEPENDENCIES) @rm -f uncompress_fuseki$(EXEEXT) $(LINK) $(uncompress_fuseki_LDFLAGS) $(uncompress_fuseki_OBJECTS) $(uncompress_fuseki_LDADD) $(LIBS) @@ -358,10 +347,8 @@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/owl_attackpat.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/owl_defendpat.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/owl_vital_apat.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/patlib.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/patterns.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/transform.Po@am__quote@ -@AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/transpat.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@$(DEPDIR)/uncompress_fuseki.Po@am__quote@ distclean-depend: Index: patterns/patlib.c =================================================================== RCS file: patterns/patlib.c diff -N patterns/patlib.c --- patterns/patlib.c 12 Jun 2005 09:34:15 -0000 1.11 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,948 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ - * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see * - * http://www.gnu.org/software/gnugo/ for more information. * - * * - * Copyright 1999, 2000, 2001, 2002, 2003, 2004 and 2005 * - * by the Free Software Foundation. * - * * - * This program 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 - version 2 * - * * - * 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 in file COPYING 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., 51 Franklin Street, Fifth Floor, * - * Boston, MA 02111, USA. * -\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* patlib.c - * - * A collection of routines for handling patterns in text form. - */ - -/* See also patterns.h, and the *.db files. */ - - -#include -#include -#include -#include -#include -#include - -#include "liberty.h" -#include "gg_utils.h" -#include "patterns.h" -#include "patlib.h" - - -/* ================================================================ */ -/* Miscellaneous declarations */ -/* ================================================================ */ - - -/* valid characters that can appear in a pattern - * position in string is att value to store - */ -const char VALID_PATTERN_CHARS[] = ".XOxo,a!*?Q"; -const char VALID_EDGE_CHARS[] = "+-|"; -const char VALID_CONSTRAINT_LABELS[] = "abcdefghijklmnpqrstuvwyzABCDEFGHIJKLMNQRSTUVWYZ"; - - -/* The offsets into the list are the ATT_* defined in patterns.h. - * The following defns are for internal use only, and are not - * written out to the compiled pattern database. - */ - -#define ATT_star 8 -#define ATT_wild 9 -#define ATT_Q 10 - - - -/* ================================================================ */ -/* The textpattern structure */ -/* ================================================================ */ - - -void -textpattern_clear(Textpattern *tp) -{ - tp->name = NULL; - tp->comment = NULL; - tp->height = 0; - tp->width = 0; - tp->num_elements = 0; - tp->elements = NULL; - tp->edge_constraints = 0; - tp->explanation = NULL; - tp->comment2 = NULL; - - tp->entry_line = NULL; - tp->comment3 = NULL; - tp->num_constraint_elements = 0; - tp->constraint_elements = NULL; - tp->comment4 = NULL; - tp->constraint_lines_len = 0; - tp->constraint_lines = NULL; - tp->comment5 = NULL; - tp->action_lines_len = 0; - tp->action_lines = NULL; - tp->comment6 = NULL; -} - - -static void -textpattern_ns_edge_print(FILE *outfile, Textpattern *tp) -{ - int i; - - if (tp->edge_constraints & WEST_EDGE) - fputc('+', outfile); - for (i = 0; i < tp->width; ++i) - fputc('-', outfile); - if (tp->edge_constraints & EAST_EDGE) - fputc('+', outfile); - fputc('\n', outfile); -} - - -void -textpattern_print(FILE *outfile, Textpattern *tp) -{ - int i, j; - - /* Print the pattern line */ - fprintf(outfile, "Pattern %s\n", tp->name ? tp->name : ""); - - /* Print comment or similar. */ - if (tp->comment) - fprintf(outfile, tp->comment); - - /* Print the pattern diagram */ - if (tp->edge_constraints & NORTH_EDGE) - textpattern_ns_edge_print(outfile, tp); - - for (i = 0; i < tp->height; ++i) { - if (tp->edge_constraints & WEST_EDGE) - fputc('|', outfile); - for (j = 0; j < tp->width; ++j) - fputc(tp->elements[i*tp->width+j], outfile); - if (tp->edge_constraints & EAST_EDGE) - fputc('|', outfile); - - if (i == 0 && tp->explanation) - fprintf(outfile, "%s", tp->explanation); - - fputc('\n', outfile); - } - if (tp->edge_constraints & SOUTH_EDGE) - textpattern_ns_edge_print(outfile, tp); - if (tp->comment2) - fprintf(outfile, tp->comment2); - - fprintf(outfile, "%s", tp->entry_line); - if (tp->comment3) - fprintf(outfile, tp->comment3); - - /* Print the constraint diagram */ - if (tp->num_constraint_elements > 0) { - if (tp->edge_constraints & NORTH_EDGE) - textpattern_ns_edge_print(outfile, tp); - - for (i = 0; i < tp->height; ++i) { - if (tp->edge_constraints & WEST_EDGE) - fputc('|', outfile); - for (j = 0; j < tp->width; ++j) - fputc(tp->constraint_elements[i*tp->width+j], outfile); - if (tp->edge_constraints & EAST_EDGE) - fputc('|', outfile); - fputc('\n', outfile); - } - if (tp->edge_constraints & SOUTH_EDGE) - textpattern_ns_edge_print(outfile, tp); - - if (tp->comment4) - fprintf(outfile, tp->comment4); - } - - if (tp->constraint_lines_len > 0) - fprintf(outfile, "%s", tp->constraint_lines); - if (tp->comment5) - fprintf(outfile, tp->comment5); - - if (tp->action_lines_len > 0) - fprintf(outfile, "%s", tp->action_lines); - if (tp->comment6) - fprintf(outfile, tp->comment6); -} - - -/* ================================================================ */ -/* Parsing of textpatterns */ -/* ================================================================ */ - - -#define MAXTOKEN 20 -#define MAXBUFFER 50000 - - -char *infilename; -int current_line = 1; -FILE *infile; -int next_char; -int inttoken; -char strbuffer[MAXBUFFER]; -char whitespacebuffer[MAXBUFFER]; -int strbuffer_index; - - -static void parse_error(const char *format, ...); -static void parse_warning(const char *format, ...); -static int get_next_char(void); - -static void parse_away_whitespace(void); -static int parse_identifier(void); -static int parse_to_end_of_line(int cont); - -static int parse_pattern_line(Textpattern *tp); -static int parse_pattern_diagram(Textpattern *tp); -static int parse_entry_line(Textpattern *tp); -static int parse_constraint_diagram(Textpattern *tp); -static int parse_constraint_lines(Textpattern *tp); -static int parse_action_lines(Textpattern *tp); - - -void -parse_init(char *filename, FILE *file) -{ - infilename = strdup(filename); - infile = file; - - get_next_char(); -} - - -static void -parse_error(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - - fprintf(stderr, "%s:%d: error: ", infilename, current_line); - vfprintf(stderr, format, ap); - fputc('\n', stderr); - - va_end(ap); -} - - -static void -parse_warning(const char *format, ...) -{ - va_list ap; - va_start(ap, format); - - fprintf(stderr, "%s:%d: warning: ", infilename, current_line); - vfprintf(stderr, format, ap); - fputc('\n', stderr); - - va_end(ap); -} - - -static int -get_next_char() -{ - next_char = getc(infile); - if (next_char == '\n') - current_line++; - - return next_char; -} - - -int -parse_whitespace(int to_end_of_line_only) -{ - char *p = whitespacebuffer; - int is_comment; - - if (!isspace(next_char) - && next_char != '#') - return 0; - - is_comment = 0; - while ((isspace(next_char) - || is_comment - || next_char == '#') - && next_char != EOF) - { - /* Switch on of off comments */ - if (is_comment) { - if (next_char == '\n') - is_comment = 0; - } - else - if (next_char == '#') - is_comment = 1; - - if (to_end_of_line_only && next_char == '\n') { - get_next_char(); - break; - } - - if (p-whitespacebuffer < MAXBUFFER-1) - *p++ = next_char; - else - parse_warning("Whitespace too big (truncated)"); - - get_next_char(); - } - *p++ = '\0'; - - if (p == whitespacebuffer) - return 0; - - return 1; -} - - -char * -get_whitespace(void) -{ - return whitespacebuffer; -} - - -static void -parse_away_whitespace(void) -{ - while (isspace(next_char) && next_char != '\n') - get_next_char(); -} - - -#if 0 - -static int -parse_int(void) -{ - int val = 0; - - if (!isdigit(next_char)) - return 0; - - val = next_char - '0'; - while (isdigit(get_next_char())) - val = val * 10 + next_char; - inttoken = val; - - return 1; -} - -#endif - -static int -parse_identifier() -{ - if (!isalpha(next_char) && next_char != '_') - return 0; - - strbuffer_index = 0; - do { - strbuffer[strbuffer_index++] = next_char; - get_next_char(); - } while (strbuffer_index < MAXTOKEN - && (isalpha(next_char) - || isdigit(next_char) - || next_char == '_')); - strbuffer[strbuffer_index] = '\0'; - - if (strbuffer_index == MAXTOKEN) { - parse_error("Too long identifier: %s", strbuffer); - return 0; - } - - return 1; -} - - -static int -parse_to_end_of_line(int cont) -{ - if (!cont) - strbuffer_index = 0; - - do { - strbuffer[strbuffer_index++] = next_char; - get_next_char(); - } while (strbuffer_index < MAXBUFFER-1 - && next_char != '\n'); - strbuffer[strbuffer_index++] = '\n'; - strbuffer[strbuffer_index] = '\0'; - - if (strbuffer_index == MAXBUFFER) { - parse_error("Too long line"); - return 0; - } - else - get_next_char(); - - return 1; -} - - -/* ---------------------------------------------------------------- */ - - -static int -parse_pattern_line(Textpattern *tp) -{ - if (!parse_identifier()) - return 0; - - if (strcmp(strbuffer, "Pattern")) { - parse_error("Pattern expected"); - return 0; - } - - parse_away_whitespace(); - if (!parse_identifier()) - return 0; - tp->name = strdup(strbuffer); - parse_whitespace(1); - - return 1; -} - - -static int -parse_north_south_constraint(Textpattern *tp) -{ - int width; - - width = 0; - while (next_char == '-') { - width++; - get_next_char(); - } - - if (width == 0) { - parse_error("Error in north/south constraint"); - return 0; - } - - if (tp->width > 0) { - /* This has to be the south border */ - if (width != tp->width - || (next_char == '+' && (tp->edge_constraints & EAST_EDGE) == 0)) { - parse_error("Error in south constraint"); - return 0; - } - } - else { - /* North constraint -> set width. */ - tp->width = width; - if (next_char == '+') - tp->edge_constraints |= EAST_EDGE; - } - - /* Finish the line */ - if (next_char == '+') - get_next_char(); - parse_whitespace(1); - - return 1; -} - - -static int -parse_pattern_diagram(Textpattern *tp) -{ - int width; - - /* See if there is a north border constraint. */ - if (next_char == '+' || next_char == '-') { - tp->edge_constraints |= NORTH_EDGE; - if (next_char == '+') { - tp->edge_constraints |= WEST_EDGE; - get_next_char(); - } - if (parse_north_south_constraint(tp) == 0) - return 0; - } - - /* Read each line */ - strbuffer_index = 0; - while (next_char == '|' - || strchr(VALID_PATTERN_CHARS, next_char)) { - - /* Handle WEST_EDGE constraint. */ - if (next_char == '|') { - tp->edge_constraints |= WEST_EDGE; - get_next_char(); - } - else { - if (tp->edge_constraints & WEST_EDGE) { - parse_error("Missing west constraint"); - return 0; - } - } - - /* Handle the pattern itself. */ - width = 0; - while (strchr(VALID_PATTERN_CHARS, next_char)) { - strbuffer[strbuffer_index++] = next_char; - width++; - get_next_char(); - } - - /* In case this happens to be the first row */ - if (tp->height == 0) { - tp->width = width; - if (next_char == '|') - tp->edge_constraints |= EAST_EDGE; - } - - if (tp->width != width) { - parse_error("Error in pattern diagram"); - return 0; - } - tp->height++; - - /* Handle EAST_EDGE constraint. */ - if (next_char == '|') { - if (tp->edge_constraints & EAST_EDGE) - get_next_char(); - else { - parse_error("Unexpected east constraint"); - return 0; - } - } - else { - if (tp->edge_constraints & EAST_EDGE) { - parse_error("Missing east constraint"); - return 0; - } - } - - /* This strange sequence is because we don't want to destroy strbuffer. */ - { - /* FIXME: Only one row of explanation possible */ - /* FIXME: Check boundaries */ - char buf[1024]; - char *p = buf; - int only_spaces = 1; - - while (next_char != EOF && next_char != '\n') { - *p++ = next_char; - if (!isspace(next_char)) - only_spaces = 0; - get_next_char(); - } - - if (!only_spaces && tp->explanation == NULL) { - *p = '\0'; - tp->explanation = strdup(buf); - } - - get_next_char(); - } - } - - /* Store the pattern into the textpattern struct. */ - tp->num_elements = strbuffer_index; - strbuffer[strbuffer_index] = '\0'; - tp->elements = strdup(strbuffer); - - /* Check a possible south constraint. */ - if (tp->edge_constraints & WEST_EDGE) { - if (next_char == '+') { - tp->edge_constraints |= SOUTH_EDGE; - get_next_char(); - } - } - else { - if (next_char == '+') { - parse_error("Didn't expect '+' here"); - return 0; - } - else if (next_char == '-') - tp->edge_constraints |= SOUTH_EDGE; - } - - if (tp->edge_constraints & SOUTH_EDGE) { - if (parse_north_south_constraint(tp) == 0) - return 0; - } - - - if (next_char == '+' || next_char == '-') { - tp->edge_constraints |= SOUTH_EDGE; - if (next_char == '+') { - tp->edge_constraints |= WEST_EDGE; - get_next_char(); - } - if (parse_north_south_constraint(tp) == 0) - return 0; - } - - return 1; -} - - -static int -parse_entry_line(Textpattern *tp) -{ - if (next_char != ':') - return 0; - - /* FIXME: No syntax control is done on the entry line. */ - parse_to_end_of_line(0); - tp->entry_line = strdup(strbuffer); - - return 1; -} - -static int -parse_constraint_diagram(Textpattern *tp) -{ - int width; - - /* Constraint diagram is optional. */ - if (!strchr(VALID_PATTERN_CHARS, next_char) - && !strchr(VALID_EDGE_CHARS, next_char) - && !strchr(VALID_CONSTRAINT_LABELS, next_char)) - return 1; - - - /* See if there is a north border constraint. */ - if (next_char == '+') { - if ((tp->edge_constraints & NORTH_EDGE) == 0 - || (tp->edge_constraints & WEST_EDGE) == 0) { - parse_error("Edge error in constraint diagram"); - return 0; - - get_next_char(); - } - } - - if (next_char == '-') { - if ((tp->edge_constraints & WEST_EDGE) == 1) { - parse_error("Edge error in constraint diagram"); - return 0; - } - - if (parse_north_south_constraint(tp) == 0) - return 0; - } - - /* Read each line */ - strbuffer_index = 0; - while (next_char == '|' - || strchr(VALID_PATTERN_CHARS, next_char) - || strchr(VALID_CONSTRAINT_LABELS, next_char)) { - - /* Handle WEST_EDGE constraint. */ - if (next_char == '|') { - if ((tp->edge_constraints & WEST_EDGE) == 0) { - parse_error("Edge error in constraint diagram"); - return 0; - } - get_next_char(); - } - else { - if (tp->edge_constraints & WEST_EDGE) { - parse_error("Missing west constraint"); - return 0; - } - } - - /* Handle the pattern itself. */ - width = 0; - while (strchr(VALID_PATTERN_CHARS, next_char) - || strchr(VALID_CONSTRAINT_LABELS, next_char)) { - strbuffer[strbuffer_index++] = next_char; - width++; - get_next_char(); - } - - if (tp->width != width) { - parse_error("Error in constraint diagram"); - return 0; - } - - /* parse_whitespace() destroys strbuffer. */ - parse_away_whitespace(); - if (next_char != '\n') { - while (next_char != EOF && next_char != '\n') - get_next_char(); - } - get_next_char(); - } - - /* Store the constraint diagram into the textpattern struct. */ - tp->num_constraint_elements = strbuffer_index; - strbuffer[strbuffer_index] = '\0'; - tp->constraint_elements = strdup(strbuffer); - - /* Check a possible south constraint. */ - if (tp->edge_constraints & WEST_EDGE) { - if (next_char == '+') { - tp->edge_constraints |= SOUTH_EDGE; - get_next_char(); - } - } - else { - if (next_char == '+') { - parse_error("Didn't expect '+' here"); - return 0; - } - else if (next_char == '-') - tp->edge_constraints |= SOUTH_EDGE; - } - - if (tp->edge_constraints & SOUTH_EDGE) { - if (parse_north_south_constraint(tp) == 0) - return 0; - } - else { - if (next_char == '+' || next_char == '-') { - if (next_char == '+') - get_next_char(); - if (parse_north_south_constraint(tp) == 0) - return 0; - } - } - - return 1; -} - - -static int -parse_constraint_lines(Textpattern *tp) -{ - if (next_char != ';') { - if (tp->num_constraint_elements != 0) - parse_warning("constraint diagram but no constraint"); - - /* Constraint lines are optional */ - return 1; - } - - /* FIXME: No syntax control is done on the constraint lines. */ - parse_to_end_of_line(0); - while (next_char == ';') - parse_to_end_of_line(1); - tp->constraint_lines_len = strbuffer_index; - tp->constraint_lines = strdup(strbuffer); - - return 1; -} - - -static int -parse_action_lines(Textpattern *tp) -{ - if (next_char != '>') - /* Action lines are optional */ - return 1; - - /* FIXME: No syntax control is done on the action lines. */ - parse_to_end_of_line(0); - while (next_char == '>') - parse_to_end_of_line(1); - tp->action_lines_len = strbuffer_index; - tp->action_lines = strdup(strbuffer); - - return 1; -} - - -/* ---------------------------------------------------------------- */ -/* Old variables and defines. */ - - -#define MAXLINE 500 /* Max line length */ - - -static int pattern_type = NORMAL_PATTERNS; -static int fullboard = 0; -static int anchor_both = 0; -static int verbose = 0; - - - -int -textpattern_parse(FILE *parm_infile, - int parm_pattern_type, int parm_anchor_both, - int parm_fullboard, int parm_verbose, - Textpattern *tp) -{ - infile = parm_infile; - pattern_type = parm_pattern_type; - anchor_both = parm_anchor_both; - fullboard = parm_fullboard; - verbose = parm_verbose; - - /* Initialize pattern number and buffer for automatically generated - * helper code. - */ - - assert(tp != NULL); - textpattern_clear(tp); - - /* Get to the pattern itself */ - parse_whitespace(0); - - /* The line: Pattern XYZ */ - if (!parse_pattern_line(tp)) - return 0; - if (parse_whitespace(0)) - tp->comment = strdup(whitespacebuffer); - - /* The pattern diagram. */ - if (!parse_pattern_diagram(tp)) - return 0; - if (parse_whitespace(0)) - tp->comment2 = strdup(whitespacebuffer); - - /* The entry line. */ - if (!parse_entry_line(tp)) - return 0; - if (parse_whitespace(0)) - tp->comment3 = strdup(whitespacebuffer); - - - if (!parse_constraint_diagram(tp)) - return 0; - if (parse_whitespace(0)) - tp->comment4 = strdup(whitespacebuffer); - - if (!parse_constraint_lines(tp)) - return 0; - if (parse_whitespace(0)) - tp->comment5 = strdup(whitespacebuffer); - - if (!parse_action_lines(tp)) - return 0; - if (parse_whitespace(0)) - tp->comment6 = strdup(whitespacebuffer); - - return 1; -} - - -void -textpattern_transform(Textpattern *tp, int transform) -{ - int size, size2; - char *array1; - char *array2; - char *p1, *p2; - int mini, minj; - int maxi, maxj; - int r; - int newedge; - int i = 0, j = 0; - int i1, j1; - - assert(0 <= transform && transform < 8); - - /* Let size be twice the (maximum of width and height) plus 1. */ - size = tp->width; - if (tp->height > size) - size = tp->height; - size++; - size2 = size*2; - - array1 = malloc(size2 * size2); - array2 = malloc(size2 * size2); - - assert(array1 != NULL && array2 != NULL); - - newedge = 0; - for (r = 0; r < 4; ++r) { - switch (tp->edge_constraints & (1<edge_constraints = newedge; - - mini = 9999; - maxi = -9999; - minj = 9999; - maxj = -9999; - for (r = 0; r < tp->num_elements; ++r) { - i = r / tp->width; - j = r % tp->width; - TRANSFORM2(i, j, &i1, &j1, transform); - - array1[(i1+size)*size2 + j1+size] = tp->elements[r]; - if (tp->num_constraint_elements > 0) - array2[(i1+size)*size2 + j1+size] = tp->constraint_elements[r]; - if (i1 < mini) mini = i1; - if (i1 > maxi) maxi = i1; - if (j1 < minj) minj = j1; - if (j1 > maxj) maxj = j1; - } - - tp->height = maxi - mini + 1; - tp->width = maxj - minj + 1; - - p1 = tp->elements; - p2 = tp->constraint_elements; - for (i1 = mini; i1 <= maxi; ++i1) - for (j1 = minj; j1 <= maxj; ++j1) { - *p1++ = array1[(i1 + size) * size2 + size + j1]; - if (tp->num_constraint_elements > 0) - *p2++ = array2[(i1 + size) * size2 + size + j1]; - } - -#if 0 - /* Debug */ - for (i1 = mini; i1 <= maxi; ++i1) { - for (j1 = minj; j1 <= maxj; ++j1) - putchar(array[(i1 + size) * size * 2 + size + j1]); - putchar('\n'); - } -#endif - - free(array1); - free(array2); -} - - - -/* - * Local Variables: - * tab-width: 8 - * c-basic-offset: 2 - * End: - */ Index: patterns/patlib.h =================================================================== RCS file: patterns/patlib.h diff -N patterns/patlib.h --- patterns/patlib.h 12 Jun 2005 09:34:15 -0000 1.10 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,97 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ - * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see * - * http://www.gnu.org/software/gnugo/ for more information. * - * * - * Copyright 1999, 2000, 2001, 2002, 2003, 2004 and 2005 * - * by the Free Software Foundation. * - * * - * This program 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 - version 2 * - * * - * 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 in file COPYING 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., 51 Franklin Street, Fifth Floor, * - * Boston, MA 02111, USA. * -\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -/* This file describes the patterns as they appear in the - * various .db files. - */ - - -#include - -#include "patterns.h" - - -#define NORMAL_PATTERNS 0 -#define CONNECTION_PATTERNS 1 -#define ESCAPE_PATTERNS 2 - - - -typedef struct lblval { - int label; /* 0 - (MAXLABEL-1) */ - int x; - int y; -} Lblval; - - -typedef struct textpattern_t { - char *name; /* The name of the pattern */ - char *comment; /* The comment just below the name */ - int height; - int width; - - int num_elements; /* Number of elements in the pattern */ - char *elements; /* The elements */ - int edge_constraints; /* NORTH_EDGE | WEST_EDGE */ - /* | SOUTH_EDGE | EAST_EDGE */ - char *explanation; /* Optional explanation */ - char *comment2; - - char *entry_line; /* The line describing the pattern */ - char *comment3; - - int num_constraint_elements; /* Number of labels */ - char *constraint_elements; /* The labels */ - char *comment4; - - int constraint_lines_len; - char *constraint_lines; - char *comment5; - - int action_lines_len; - char *action_lines; - char *comment6; -} Textpattern; - -void textpattern_clear(Textpattern *tp); -void textpattern_print(FILE *outfile, Textpattern *tp); -void parse_init(char *filename, FILE *file); -int parse_whitespace(int to_end_of_line_only); -char *get_whitespace(void); -int textpattern_parse(FILE *infile, - int parm_pattern_type, int parm_anchor_both, - int parm_fullboard, int parm_verbose, - Textpattern *tp); -void textpattern_transform(Textpattern *tp, int transform); - - -extern const int transformations[8][2][2]; - - - -/* - * Local Variables: - * tab-width: 8 - - * c-basic-offset: 2 - * End: - */ Index: patterns/transpat.c =================================================================== RCS file: patterns/transpat.c diff -N patterns/transpat.c --- patterns/transpat.c 18 Sep 2005 12:56:49 -0000 1.13 +++ /dev/null 1 Jan 1970 00:00:00 -0000 @@ -1,190 +0,0 @@ -/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *\ - * This is GNU Go, a Go program. Contact gnugo@gnu.org, or see * - * http://www.gnu.org/software/gnugo/ for more information. * - * * - * Copyright 1999, 2000, 2001, 2002, 2003, 2004 and 2005 * - * by the Free Software Foundation. * - * * - * This program 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 - version 2 * - * * - * 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 in file COPYING 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., 51 Franklin Street, Fifth Floor, * - * Boston, MA 02111, USA. * -\* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ - -#include "patlib.h" -#include -#include - -/* - * The purpose of this program is to transform the patterns - * in a database into a canonical form. - * - * Usage is: - * - * transpat [patfile] - * - * where - * - * command is one of "flipleft" or "normalize" - * patnames is a standard glob pattern like "EE*" - * patfile is an optional file name. If no file name is given, - * transpat reads from stdin. - * - * If "flipleft" is given as a command, the appropriate patterns are - * flipped left-right, and if "normalize" is given the appropriate - * patterns are made lower-edge or lower-left-edge patterns if there are - * any edges at all. - * - * The transformations array have misleading comments. This is what the - * transformations really do: - * - * 0: identity transformation - * 1: rotation 270 degrees - * 2: rotation 180 degrees - * 3: rotation 90 degrees - * 4: rotation 90 degrees and flip left-right - * 5: flip up-down - * 6: rotation 90 degrees and flip up-down - * 7: flip left-right - * - * The reason for the mismatch is that the comments apply to an ordinary - * coordinate system, but the coordinate system here have the axises - * switched. - */ - - -static void flippat(Textpattern *tp); -static int match_name(Textpattern *tp, char *patnames); - - -/* - * Transform a pattern so that: - * - If there is 1 edge, make it the lower edge - * - If there is a corner, make it the lower left corner. - * - if there are 3 edges, make the middle edge the lower one. - * Otherwise don't do anything. - - */ - -static void -flippat(Textpattern *tp) -{ - int transno; - - switch (tp->edge_constraints) { - case 0: return; /* Nothing to do here */ - - case NORTH_EDGE: transno = 5; break; /* Flip up-down */ - case SOUTH_EDGE: return; /* Nothing to do here */ - case EAST_EDGE: transno = 1; break; /* Rotate 270 degrees */ - case WEST_EDGE: transno = 3; break; /* Rotate 90 degrees */ - - case NORTH_EDGE | SOUTH_EDGE: return; - case NORTH_EDGE | WEST_EDGE: transno = 3; break; - case NORTH_EDGE | EAST_EDGE: transno = 2; break; - case WEST_EDGE | EAST_EDGE: return; - case WEST_EDGE | SOUTH_EDGE: return; - case EAST_EDGE | SOUTH_EDGE: transno = 1; break; - - case NORTH_EDGE | WEST_EDGE | EAST_EDGE: transno = 2; break; - case NORTH_EDGE | WEST_EDGE | SOUTH_EDGE: transno = 3; break; - case NORTH_EDGE | EAST_EDGE | SOUTH_EDGE: transno = 1; break; - case WEST_EDGE | EAST_EDGE | SOUTH_EDGE: return; - - default: return; - } - - textpattern_transform(tp, transno); -} - - -/* - * Return 1 if the textpattern has a name that matches the pattern. - * Otherwise return 0. - */ - -static int -match_name(Textpattern *tp, char *patnames) -{ - return fnmatch(patnames, tp->name, FNM_NOESCAPE) == 0; -} - - -#define FLIPLEFT 1 -#define NORMALIZE 2 - - -int -main(int argc, char *argv[]) -{ - FILE *infile; - Textpattern tp; - int val; - char *patnames; - int command = 0; - - if (argc < 2 || argc > 4) { - fprintf(stderr, - "usage: %s command patnames [patfilename]\n\ -where\n\ - command is one of 'flipleft' or 'normalize'\n\ - patnames is a standard glob pattern (like EE*)\n\ - patfilename is an optional filename\n", argv[0]); - exit(EXIT_FAILURE); - } - - /* Get the command */ - if (strcmp(argv[1], "flipleft") == 0) - command = FLIPLEFT; - else if (strcmp(argv[1], "normalize") == 0) - command = NORMALIZE; - - /* Get the patterns we should work on. */ - patnames = argv[2]; - - /* Try to open infile. */ - if (argc == 4) { - if ((infile = fopen(argv[3], "r")) == 0) { - perror(argv[3]); - exit(EXIT_FAILURE); - } - } - else - infile = stdin; - - parse_init(argv[1], infile); - - /* Read and write initial whitespace and comments. */ - if (parse_whitespace(0)) - fprintf(stdout, get_whitespace()); - - /* Parse all the patterns, transform them appropriately and write them - out to file. */ - do { - val = textpattern_parse(infile, NORMAL_PATTERNS, 1, 0, 1, &tp); - if (val) { - if (match_name(&tp, patnames)) { - switch (command) { - case FLIPLEFT: textpattern_transform(&tp, 7); break; - case NORMALIZE: flippat(&tp); break; - } - } - textpattern_print(stdout, &tp); - } - else { - printf("error\n"); - exit(EXIT_FAILURE); - } - } while (val != 0 && !feof(infile)); - - exit(EXIT_SUCCESS); -}