X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fsavescreen.c;h=3d6f248cd42d6e7285c5a9209d69fb6f66b8d313;hp=09f328baf273d340eda9ede1e0e51fe30a8bc26b;hb=52aa842907b31bb56fb5133da3f023b45bd4355f;hpb=e70a86c3d48b8cbad0f6d1c33ba5b027a243834e diff --git a/test/savescreen.c b/test/savescreen.c index 09f328ba..3d6f248c 100644 --- a/test/savescreen.c +++ b/test/savescreen.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2007 Free Software Foundation, Inc. * + * Copyright (c) 2007-2009,2010 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 * @@ -26,7 +26,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: savescreen.c,v 1.10 2007/07/21 17:57:37 tom Exp $ + * $Id: savescreen.c,v 1.13 2010/11/13 21:18:00 tom Exp $ * * Demonstrate save/restore functions from the curses library. * Thomas Dickey - 2007/7/14 @@ -34,6 +34,9 @@ #include +#include +#include + #if TIME_WITH_SYS_TIME # include # include @@ -47,6 +50,13 @@ static bool use_init = FALSE; +static int +fexists(const char *name) +{ + struct stat sb; + return (stat(name, &sb) == 0 && (sb.st_mode & S_IFMT) == S_IFREG); +} + static void setup_next(void) { @@ -163,6 +173,14 @@ main(int argc, char *argv[]) } } + files = argv + optind; + last = argc - optind - 1; + + if (replaying) { + while (last >= 0 && !fexists(files[last])) + --last; + } + initscr(); cbreak(); noecho(); @@ -171,13 +189,11 @@ main(int argc, char *argv[]) if (has_colors()) { start_color(); for (ch = 0; ch < COLOR_PAIRS; ++ch) { - short pair = ch % COLOR_PAIRS; - init_pair(pair, COLOR_WHITE, ch % COLORS); + short pair = (short) (ch % COLOR_PAIRS); + init_pair(pair, COLOR_WHITE, (short) (ch % COLORS)); } } - files = argv + optind; - last = argc - optind - 1; if (replaying) { /* @@ -251,7 +267,7 @@ main(int argc, char *argv[]) getyx(stdscr, y, x); while (!done) { - switch (ch = get_command(which, last)) { + switch (get_command(which, last)) { case 'n': setup_next(); done = TRUE; @@ -273,8 +289,8 @@ main(int argc, char *argv[]) } ++which; if (has_colors()) { - short pair = which % COLOR_PAIRS; - bkgd(COLOR_PAIR(pair)); + short pair = (short) (which % COLOR_PAIRS); + bkgd((chtype) COLOR_PAIR(pair)); } } else { beep();