From ba006345ce90fae4a93fcc375281d903884fead0 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 22 Apr 2006 12:23:15 -0400 Subject: [PATCH] libchess: Removed pgn_config_get(). pgn_config_set() has changed. The value for the flag is set to the next variable argument. If the value is invalid E_PGN_INVALID is returned. If the flag is invalid E_PGN_ERR and E_PGN_OK otherwise. --- libchess/chess.h | 22 +++++++-------- libchess/pgn.c | 81 ++++++++++++++++++++++++++------------------------------ 2 files changed, 47 insertions(+), 56 deletions(-) diff --git a/libchess/chess.h b/libchess/chess.h index 50355a1..5a06719 100644 --- a/libchess/chess.h +++ b/libchess/chess.h @@ -144,13 +144,14 @@ typedef enum { /* * When pgn_write() is called to write a game, write reduced PGN format. * This will only write the seven tag roster and move text skipping any - * annotation. + * annotation. The type for this flag is an int. */ PGN_REDUCED, /* * The number of full moves to write per line. If 0 then pgn_write() will - * write as many as possible within 80 columns. + * write as many as possible within 80 columns. The type for this flag + * is an int. */ PGN_MPL, @@ -158,13 +159,14 @@ typedef enum { * Normally when a parse error occurs in a game the game is flagged with * GF_PERROR and the rest of the game is discarded and processing of the * next game is done. When set and a parse error occurs the rest of the - * entire file will be discarded. + * entire file will be discarded. The type for this flag is an int. */ PGN_STOP_ON_ERROR, /* * After PGN_PROGRESS amount of bytes have been read from a file, call - * PGN_PROGRESS_FUNC. + * PGN_PROGRESS_FUNC. The type for PGN_PROGRESS is a long. + * PGN_PROGRESS_FUNC is of type pgn_progress. */ PGN_PROGRESS, PGN_PROGRESS_FUNC, @@ -176,15 +178,11 @@ typedef enum { typedef void (pgn_progress)(long size, long offset); /* - * Sets config flag 'f' to 'val'. Returns E_PGN_OK on success or E_PGN_ERR if - * 'f' is an invalid flag or 'val' is an invalid value. + * Sets config flag 'f' to the next argument. Returns E_PGN_OK on success or + * E_PGN_ERR if 'f' is an invalid flag or E_PGN_INVALID if 'val' is an invalid + * flag value. */ -int pgn_config_set(pgn_config_flag f, void *); - -/* - * Returns the value accociated with 'f' or NULL if 'f' is invalid. - */ -void *pgn_config_get(pgn_config_flag f); +int pgn_config_set(pgn_config_flag f, ...); /* * Returns E_PGN_OK if 'filename' is a recognized compressed filetype or diff --git a/libchess/pgn.c b/libchess/pgn.c index f25b5da..8f157b5 100644 --- a/libchess/pgn.c +++ b/libchess/pgn.c @@ -30,6 +30,7 @@ #include #include #include +#include #ifdef HAVE_CONFIG_H #include @@ -1973,71 +1974,63 @@ int pgn_is_compressed(const char *filename) } /* - * Sets config flag 'f' to 'val'. Returns E_PGN_OK on success or E_PGN_ERR if - * 'f' is an invalid flag or 'val' is an invalid value. + * Sets config flag 'f' to the next argument. Returns E_PGN_OK on success or + * E_PGN_ERR if 'f' is an invalid flag or E_PGN_INVALID if 'val' is an invalid + * flag value. */ -int pgn_config_set(pgn_config_flag f, void *val) +int pgn_config_set(pgn_config_flag f, ...) { + va_list ap; int n; + int ret = E_PGN_OK; + + va_start(ap, f); switch (f) { case PGN_REDUCED: - n = (int)val; + n = va_arg(ap, int); - if (n == 1) - pgn_config.reduced = 1; - else if (n == 0) - pgn_config.reduced = 0; - else - return E_PGN_ERR; + if (n != 1 && n != 0) { + ret = E_PGN_INVALID; + break; + } + + pgn_config.reduced = n; break; case PGN_MPL: - pgn_config.mpl = (int)val; + n = va_arg(ap, int); + + if (n < 0) { + ret = E_PGN_INVALID; + break; + } + + pgn_config.mpl = n; break; case PGN_STOP_ON_ERROR: - n = (int)val; + n = va_arg(ap, int); - if (n == 1) - pgn_config.stop = 1; - else if (n == 0) - pgn_config.stop = 0; - else - return E_PGN_ERR; + if (n != 1 && n != 0) { + ret = E_PGN_INVALID; + break; + } + + pgn_config.stop = n; break; case PGN_PROGRESS: - pgn_config.progress = (long)val; + n = va_arg(ap, long); + pgn_config.progress = n; break; case PGN_PROGRESS_FUNC: - pgn_config.pfunc = (pgn_progress*)val; + pgn_config.pfunc = va_arg(ap, pgn_progress *); break; default: - return E_PGN_ERR; - } - - return E_PGN_OK; -} - -/* - * Returns the value accociated with 'f' or NULL if 'f' is invalid. - */ -void *pgn_config_get(pgn_config_flag f) -{ - switch (f) { - case PGN_REDUCED: - return (int *)pgn_config.reduced; - case PGN_STOP_ON_ERROR: - return (int *)pgn_config.stop; - case PGN_MPL: - return (int *)pgn_config.mpl; - case PGN_PROGRESS: - return (long *)pgn_config.progress; - case PGN_PROGRESS_FUNC: - return (pgn_progress *)pgn_config.pfunc; - default: + ret = E_PGN_ERR; break; } - return NULL; + va_end(ap); + return ret; } /* -- 2.11.4.GIT