X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fhanoi.c;h=bd0fb10e1f8e9a3aaca0067f3aca82357921ae4e;hp=a763dce8eb2cec0f27042c4846788e3bc56dcc79;hb=26522e4669dbf45cba32138b5d81c6c292e88e60;hpb=027ae42953e3186daed8f3882da73de48291b606 diff --git a/test/hanoi.c b/test/hanoi.c index a763dce8..bd0fb10e 100644 --- a/test/hanoi.c +++ b/test/hanoi.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 1998-2002,2006 Free Software Foundation, Inc. * + * Copyright (c) 1998-2006,2008 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -41,7 +41,7 @@ * * Date: 05.Nov.90 * - * $Id: hanoi.c,v 1.25 2006/04/22 22:41:22 tom Exp $ + * $Id: hanoi.c,v 1.27 2008/08/04 10:57:59 tom Exp $ */ #include @@ -81,6 +81,7 @@ static int TileColour[] = COLOR_RED, /* Length 19 */ }; static int NMoves = 0; +static bool AutoFlag = FALSE; static void InitTiles(int NTiles); static void DisplayTiles(void); @@ -95,7 +96,6 @@ int main(int argc, char **argv) { int NTiles, FromCol, ToCol; - bool AutoFlag = 0; setlocale(LC_ALL, ""); @@ -246,15 +246,18 @@ DisplayTiles(void) /* Draw tiles */ for (peg = 0; peg < NPEGS; peg++) { for (SlotNo = 0; SlotNo < Pegs[peg].Count; SlotNo++) { - memset(TileBuf, ' ', Pegs[peg].Length[SlotNo]); - TileBuf[Pegs[peg].Length[SlotNo]] = '\0'; - if (has_colors()) - attrset(COLOR_PAIR(LENTOIND(Pegs[peg].Length[SlotNo]))); - else - attrset(A_REVERSE); - mvaddstr(BASELINE - (SlotNo + 1), - (int) (PegPos[peg] - Pegs[peg].Length[SlotNo] / 2), - TileBuf); + unsigned len = Pegs[peg].Length[SlotNo]; + if (len < sizeof(TileBuf) - 1 && len < (unsigned) PegPos[peg]) { + memset(TileBuf, ' ', len); + TileBuf[len] = '\0'; + if (has_colors()) + attrset(COLOR_PAIR(LENTOIND(len))); + else + attrset(A_REVERSE); + mvaddstr(BASELINE - (SlotNo + 1), + (int) (PegPos[peg] - len / 2), + TileBuf); + } } } attrset(A_NORMAL); @@ -278,7 +281,8 @@ GetMove(int *From, int *To) return TRUE; *To -= ('0' + 1); refresh(); - napms(500); + if (!AutoFlag) + napms(500); move(STATUSLINE, 0); clrtoeol();