diff options
author | Russ Allbery <rra@debian.org> | 2013-07-21 13:49:36 -0700 |
---|---|---|
committer | Russ Allbery <rra@debian.org> | 2013-07-21 13:49:36 -0700 |
commit | 02afa49ca106bbd29895a61ce16c110d3d819b3d (patch) | |
tree | 5b1c86964e47ed31dca8c4f96fa9b88c48f28e0a /bearoffdump.c | |
parent | 71a137c6c77cadddd4ed628cf0dcc310fbb32a49 (diff) |
Imported Upstream version 1.01.003
Diffstat (limited to 'bearoffdump.c')
-rw-r--r-- | bearoffdump.c | 208 |
1 files changed, 94 insertions, 114 deletions
diff --git a/bearoffdump.c b/bearoffdump.c index 3dfa0dc..0d9c338 100644 --- a/bearoffdump.c +++ b/bearoffdump.c @@ -16,7 +16,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * - * $Id: bearoffdump.c,v 1.17 2010/11/07 21:31:51 plm Exp $ + * $Id: bearoffdump.c,v 1.20 2013/07/10 13:56:00 mdpetch Exp $ */ #include "config.h" @@ -30,122 +30,102 @@ #include "multithread.h" #include "backgammon.h" -#if USE_MULTITHREAD -extern int MT_GetThreadID(void) +extern void +MT_CloseThreads(void) { - return (0); + return; } -extern void MT_Release(void) -{ - return; -} -extern void MT_Exclusive(void) -{ - return; -} -#else -extern void CallbackProgress(void) -{ -} -#endif extern int -main( int argc, char **argv ) { - - char *filename, *szPosID = NULL; - int id = 0; - bearoffcontext *pbc; - char sz[ 4096 ]; - int n; - int nUs; - int nThem; - TanBoard anBoard; - - GOptionEntry ao[] = { - {"index", 'n', 0, G_OPTION_ARG_INT, &id, - "index", NULL}, - {"posid", 'p', 0, G_OPTION_ARG_STRING, &szPosID, - "Position ID", NULL}, - {NULL, 0, 0, 0, NULL, NULL, NULL} - }; - GError *error = NULL; - GOptionContext *context; - - context = g_option_context_new("file"); - g_option_context_add_main_entries(context, ao, PACKAGE); - g_option_context_parse(context, &argc, &argv, &error); - g_option_context_free(context); - if (error) { - g_printerr("%s\n", error->message); - exit(EXIT_FAILURE); - } - - if ((szPosID && id) || (!szPosID && !id)) - { - g_printerr("Either Position ID or index is required. Not Both.\n" - "For more help try `bearoffdump --help'\n"); - exit(EXIT_FAILURE); - } - - if (argc != 2) - { - g_printerr("A bearoff database file should be given as an argument\n" - "For more help try `bearoffdump --help'\n"); - exit(EXIT_FAILURE); - } - filename = argv[ 1 ]; - - printf( "Bearoff database: %s\n", filename ); - if ( !id ) { - printf( "Position ID : %s\n", szPosID ); - } - else { - printf( "Position number : %d\n", id ); - } - - if ( ! ( pbc = BearoffInit ( filename, BO_NONE, NULL ) ) ) { - printf( "Failed to initialise bearoff database %s\n", filename ); - exit(-1); - } - - /* information about bearoff database */ - - printf( "\n" - "Information about database:\n\n" ); - - *sz = 0; - BearoffStatus( pbc, sz ); - puts( sz ); - - /* set up board */ - - memset( anBoard, 0, sizeof anBoard ); - - if ( !id ) { - printf( "\n" - "Dump of position ID: %s\n\n", szPosID ); - - PositionFromID( anBoard, szPosID ); - } - else { - printf( "\n" - "Dump of position#: %d\n\n", id ); - - n = Combination ( pbc->nPoints + pbc->nChequers, pbc->nPoints ); - nUs = id / n; - nThem = id % n; - PositionFromBearoff( anBoard[ 0 ], nThem, pbc->nPoints, pbc->nChequers ); - PositionFromBearoff( anBoard[ 1 ], nUs, pbc->nPoints, pbc->nChequers ); - } - - /* dump req. position */ - - *sz = 0; - BearoffDump( pbc, (ConstTanBoard)anBoard, sz ); - puts( sz ); - - BearoffClose( pbc ); - - return 0; +main(int argc, char **argv) +{ + + char *filename, *szPosID = NULL; + int id = 0; + bearoffcontext *pbc; + char sz[4096]; + int n; + int nUs; + int nThem; + TanBoard anBoard; + + GOptionEntry ao[] = { + {"index", 'n', 0, G_OPTION_ARG_INT, &id, + "index", NULL}, + {"posid", 'p', 0, G_OPTION_ARG_STRING, &szPosID, + "Position ID", NULL}, + {NULL, 0, 0, 0, NULL, NULL, NULL} + }; + GError *error = NULL; + GOptionContext *context; + + context = g_option_context_new("file"); + g_option_context_add_main_entries(context, ao, PACKAGE); + g_option_context_parse(context, &argc, &argv, &error); + g_option_context_free(context); + if (error) { + g_printerr("%s\n", error->message); + exit(EXIT_FAILURE); + } + + if ((szPosID && id) || (!szPosID && !id)) { + g_printerr("Either Position ID or index is required. Not Both.\n" "For more help try `bearoffdump --help'\n"); + exit(EXIT_FAILURE); + } + + if (argc != 2) { + g_printerr("A bearoff database file should be given as an argument\n" + "For more help try `bearoffdump --help'\n"); + exit(EXIT_FAILURE); + } + filename = argv[1]; + + printf("Bearoff database: %s\n", filename); + if (!id) { + printf("Position ID : %s\n", szPosID); + } else { + printf("Position number : %d\n", id); + } + + if (!(pbc = BearoffInit(filename, BO_NONE, NULL))) { + printf("Failed to initialise bearoff database %s\n", filename); + exit(-1); + } + + /* information about bearoff database */ + + printf("\n" "Information about database:\n\n"); + + *sz = 0; + BearoffStatus(pbc, sz); + puts(sz); + + /* set up board */ + + memset(anBoard, 0, sizeof anBoard); + + if (!id) { + printf("\n" "Dump of position ID: %s\n\n", szPosID); + + PositionFromID(anBoard, szPosID); + } else { + printf("\n" "Dump of position#: %d\n\n", id); + + n = Combination(pbc->nPoints + pbc->nChequers, pbc->nPoints); + nUs = id / n; + nThem = id % n; + PositionFromBearoff(anBoard[0], nThem, pbc->nPoints, pbc->nChequers); + PositionFromBearoff(anBoard[1], nUs, pbc->nPoints, pbc->nChequers); + } + + /* dump req. position */ + + *sz = 0; + BearoffDump(pbc, (ConstTanBoard) anBoard, sz); + puts(sz); + + BearoffClose(pbc); + + return 0; } |