X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fdots_mvcur.c;h=4812282ecebfdf57949fe6c156cd9e7578d662b9;hb=a4dac84af1b18fb24d56d6251deeb3c61c437158;hp=558683d56fdb822d5bf22da94ab549996833b082;hpb=52aa842907b31bb56fb5133da3f023b45bd4355f;p=ncurses.git diff --git a/test/dots_mvcur.c b/test/dots_mvcur.c index 558683d5..4812282e 100644 --- a/test/dots_mvcur.c +++ b/test/dots_mvcur.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2007-2008,2009 Free Software Foundation, Inc. * + * Copyright (c) 2007-2013,2017 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 * @@ -29,7 +29,7 @@ /* * Author: Thomas E. Dickey - 2007 * - * $Id: dots_mvcur.c,v 1.6 2010/11/14 01:00:44 tom Exp $ + * $Id: dots_mvcur.c,v 1.11 2017/06/17 18:25:30 tom Exp $ * * A simple demo of the terminfo interface, and mvcur. */ @@ -46,24 +46,24 @@ static bool interrupted = FALSE; static long total_chars = 0; static time_t started; -static int -outc(TPUTS_ARG c) +static +TPUTS_PROTO(outc, c) { int rc = c; if (interrupted) { char tmp = (char) c; - if (write(STDOUT_FILENO, &tmp, 1) == -1) + if (write(STDOUT_FILENO, &tmp, (size_t) 1) == -1) rc = EOF; } else { if (putc(c, stdout) == EOF) rc = EOF; } - return rc; + TPUTS_RETURN(rc); } static bool -outs(char *s) +outs(const char *s) { if (valid(s)) { tputs(s, 1, outc); @@ -108,19 +108,24 @@ main(int argc GCC_UNUSED, double r; double c; SCREEN *sp; + int my_colors; CATCHALL(onsig); srand((unsigned) time(0)); - sp = newterm((char *) 0, stdout, stdin); + if ((sp = newterm((char *) 0, stdout, stdin)) == 0) { + fprintf(stderr, "Cannot initialize terminal\n"); + ExitProgram(EXIT_FAILURE); + } outs(clear_screen); outs(cursor_home); outs(cursor_invisible); - if (max_colors > 1) { + my_colors = max_colors; + if (my_colors > 1) { if (!valid(set_a_foreground) || !valid(set_a_background) || (!valid(orig_colors) && !valid(orig_pair))) - max_colors = -1; + my_colors = -1; } r = (double) (lines - 4); @@ -137,8 +142,8 @@ main(int argc GCC_UNUSED, y0 = y; } - if (max_colors > 0) { - z = (int) (ranf() * max_colors); + if (my_colors > 0) { + z = (int) (ranf() * my_colors); if (ranf() > 0.01) { tputs(tparm2(set_a_foreground, z), 1, outc); } else { @@ -155,6 +160,7 @@ main(int argc GCC_UNUSED, } } outc(p); + ++x0; fflush(stdout); ++total_chars; }