/* vi: set tabstop=4 shiftwidth=4: */ /* * $Id: initlang.c,v 1.4 1996/12/28 22:11:13 schweikh Exp $ */ #include /* fopen */ #include /* strncmp */ #include /* malloc */ #include "chess.h" #include "error.h" #include "fgetline.h" #include "init.h" #include "initlang.h" #include "shutup.h" /* * PRIVATE */ static unsigned int missing = 0; static void Error (char *); static void Error (char *m) /* * Print an error message for missing entries and increment counter. */ { err_msg ("no entry for `%s'", m); ++missing; } void Initialize_language (char *language) /* * Read the language information from the file named by `language'. */ { FILE *in; char *l, *filename = language; in = fopen (filename, "r"); if (in == NULL) { filename = malloc (strlen (filename) + strlen (LIBDIR) + 2); check_sys (filename != NULL); Sprintf (filename, LIBDIR "/%s", language); in = fopen (filename, "r"); if (in == NULL) { err_msg ("can't read language information neither from"); err_quit ("`./%s' nor from `%s'", language, filename); } } Memset (&M, 0, sizeof M); while ((l = fgetline (in)) != NULL) { if (*l == '#') { free (l); continue; /* while */ } if (strncmp (l, "white:", 6) == 0) { M.white = l + 6; } else if (strncmp (l, "white1:", 7) == 0) { M.white1 = l[7]; free (l); } else if (strncmp (l, "black:", 6) == 0) { M.black = l + 6; } else if (strncmp (l, "black1:", 7) == 0) { M.black1 = l[7]; free (l); } else if (strncmp (l, "king:", 5) == 0) { M.King = l + 5; } else if (strncmp (l, "pawn:", 5) == 0) { M.Pawn = l + 5; } else if (strncmp (l, "move:", 5) == 0) { M.move = l + 5; } else if (strncmp (l, "moves:", 6) == 0) { M.moves = l + 6; } else if (strncmp (l, "impossible:", 11) == 0) { M.impossible = l + 11; } else if (strncmp (l, "error:", 6) == 0) { M.error = l + 6; } else if (strncmp (l, "errors:", 7) == 0) { M.errors = l + 7; } else if (strncmp (l, "no_w_king:", 10) == 0) { M.no_w_king = l + 10; } else if (strncmp (l, "no_b_king:", 10) == 0) { M.no_b_king = l + 10; } else if (strncmp (l, "no_w_pawn:", 10) == 0) { M.no_w_pawn = l + 10; } else if (strncmp (l, "no_b_pawn:", 10) == 0) { M.no_b_pawn = l + 10; } else if (strncmp (l, "cant_parse:", 11) == 0) { M.cant_parse = l + 11; } else if (strncmp (l, "not_free:", 9) == 0) { M.not_free = l + 9; } else if (strncmp (l, "ep:", 3) == 0) { M.ep = l + 3; } else if (strncmp (l, "allowed:", 8) == 0) { M.allowed = l + 8; } else if (strncmp (l, "disallowed:", 11) == 0) { M.disallowed = l + 11; } else if (strncmp (l, "can_ep:", 7) == 0) { M.can_ep = l + 7; } else if (strncmp (l, "cant_ep:", 8) == 0) { M.cant_ep = l + 8; } else if (strncmp (l, "solution:", 9) == 0) { M.solution = l + 9; } else if (strncmp (l, "no_solution:", 12) == 0) { M.no_solution = l + 12; } else if (strncmp (l, "mate:", 5) == 0) { M.mate = l + 5; } else if (strncmp (l, "stale:", 6) == 0) { M.stale = l + 6; } else if (strncmp (l, "to_move_w:", 10) == 0) { M.to_move_w = l + 10; } else if (strncmp (l, "to_move_b:", 10) == 0) { M.to_move_b = l + 10; } else if (strncmp (l, "castling:", 9) == 0) { M.castling = l + 9; } else if (strncmp (l, "w_short:", 8) == 0) { M.w_short = l + 8; } else if (strncmp (l, "b_short:", 8) == 0) { M.b_short = l + 8; } else if (strncmp (l, "w_long:", 7) == 0) { M.w_long = l + 7; } else if (strncmp (l, "b_long:", 7) == 0) { M.b_long = l + 7; } else if (strncmp (l, "mate_in:", 8) == 0) { M.mate_in = l + 8; } else if (strncmp (l, "n_mate:", 7) == 0) { M.n_mate = l + 7; } else if (strncmp (l, "more_rows:", 10) == 0) { M.more_rows = l + 10; } else if (strncmp (l, "not8:", 5) == 0) { M.not8 = l + 5; } else if (strncmp (l, "K:", 2) == 0) { M.K = l[2]; free (l); } else if (strncmp (l, "k:", 2) == 0) { M.k = l[2]; free (l); } else if (strncmp (l, "Q:", 2) == 0) { M.Q = l[2]; free (l); } else if (strncmp (l, "q:", 2) == 0) { M.q = l[2]; free (l); } else if (strncmp (l, "R:", 2) == 0) { M.R = l[2]; free (l); } else if (strncmp (l, "r:", 2) == 0) { M.r = l[2]; free (l); } else if (strncmp (l, "B:", 2) == 0) { M.B = l[2]; free (l); } else if (strncmp (l, "b:", 2) == 0) { M.b = l[2]; free (l); } else if (strncmp (l, "N:", 2) == 0) { M.N = l[2]; free (l); } else if (strncmp (l, "n:", 2) == 0) { M.n = l[2]; free (l); } else if (strncmp (l, "P:", 2) == 0) { M.P = l[2]; free (l); } else if (strncmp (l, "p:", 2) == 0) { M.p = l[2]; free (l); } else if (strncmp (l, "cp:", 3) == 0) { M.cp = l[3]; free (l); } else if (strncmp (l, "mv:", 3) == 0) { M.mv = l[3]; free (l); } else if (strncmp (l, "mt:", 3) == 0) { M.mt = l[3]; free (l); } else if (strncmp (l, "st:", 3) == 0) { M.st = l[3]; free (l); } else if (strncmp (l, "ch:", 3) == 0) { M.ch = l[3]; free (l); } else if (strncmp (l, "db:", 3) == 0) { M.db = l[3]; free (l); } else if (strncmp (l, "inv_piece:", 10) == 0) { M.inv_piece = l + 10; } else { err_msg ("ignored `%s' in language file `%s'", l, filename); } } if (M.white == NULL) Error ("white"); if (M.black == NULL) Error ("black"); if (M.King == NULL) Error ("king"); if (M.Pawn == NULL) Error ("pawn"); if (M.impossible == NULL) Error ("impossible"); if (M.error == NULL) Error ("error"); if (M.errors == NULL) Error ("errors"); if (M.no_w_king == NULL) Error ("no_w_king"); if (M.no_b_king == NULL) Error ("no_b_king"); if (M.no_w_pawn == NULL) Error ("no_w_pawn"); if (M.no_b_pawn == NULL) Error ("no_b_pawn"); if (M.cant_parse == NULL) Error ("cant_parse"); if (M.ep == NULL) Error ("ep"); if (M.allowed == NULL) Error ("allowed"); if (M.disallowed == NULL) Error ("disallowed"); if (M.can_ep == NULL) Error ("can_ep"); if (M.cant_ep == NULL) Error ("cant_ep"); if (M.solution == NULL) Error ("solution"); if (M.no_solution == NULL) Error ("no_solution"); if (M.mate == NULL) Error ("mate"); if (M.stale == NULL) Error ("stale"); if (M.move == NULL) Error ("move"); if (M.moves == NULL) Error ("moves"); if (M.to_move_w == NULL) Error ("to_move_w"); if (M.to_move_b == NULL) Error ("to_move_b"); if (M.castling == NULL) Error ("castling"); if (M.w_short == NULL) Error ("w_short"); if (M.b_short == NULL) Error ("b_short"); if (M.w_long == NULL) Error ("w_long"); if (M.b_long == NULL) Error ("b_long"); if (M.mate_in == NULL) Error ("mate_in"); if (M.n_mate == NULL) Error ("n_mate"); if (M.more_rows == NULL) Error ("more_rows"); if (M.not8 == NULL) Error ("not8"); if (M.white1 == '\0') Error ("white1"); if (M.black1 == '\0') Error ("black1"); if (M.K == 0) Error ("K"); if (M.k == 0) Error ("k"); if (M.Q == 0) Error ("Q"); if (M.q == 0) Error ("q"); if (M.R == 0) Error ("R"); if (M.r == 0) Error ("r"); if (M.B == 0) Error ("B"); if (M.b == 0) Error ("b"); if (M.N == 0) Error ("N"); if (M.n == 0) Error ("n"); if (M.P == 0) Error ("P"); if (M.p == 0) Error ("p"); if (M.inv_piece == NULL) Error ("inv_piece"); if (missing != 0) { err_quit ("%u entr%s missing in `%s'", missing, missing == 1 ? "y" : "ies", filename); } pchar[0] = 0; pchar[1] = M.P; pchar[2] = M.N; pchar[3] = M.B; pchar[4] = M.R; pchar[5] = M.Q; pchar[6] = M.K; check_sys (fclose (in) == 0); }