28 changes: 16 additions & 12 deletions test/cardfile.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 1999-2016,2017 Free Software Foundation, Inc. *
* Copyright (c) 1999-2017,2019 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 *
Expand Down Expand Up @@ -29,7 +29,7 @@
/*
* Author: Thomas E. Dickey
*
* $Id: cardfile.c,v 1.45 2017/10/19 21:14:25 tom Exp $
* $Id: cardfile.c,v 1.46 2019/08/17 21:49:40 tom Exp $
*
* File format: text beginning in column 1 is a title; other text is content.
*/
Expand Down Expand Up @@ -125,10 +125,12 @@ add_title(const char *title)
static void
add_content(CARD * card, const char *content)
{
size_t total, offset;
size_t total;

content = skip(content);
if ((total = strlen(content)) != 0) {
size_t offset;

if (card->content != 0 && (offset = strlen(card->content)) != 0) {
total += 1 + offset;
card->content = typeRealloc(char, total + 1, card->content);
Expand Down Expand Up @@ -173,10 +175,11 @@ static void
read_data(char *fname)
{
FILE *fp;
CARD *card = 0;
char buffer[BUFSIZ];

if ((fp = fopen(fname, "r")) != 0) {
CARD *card = 0;
char buffer[BUFSIZ];

while (fgets(buffer, sizeof(buffer), fp)) {
trim(buffer);
if (isspace(UChar(*buffer))) {
Expand All @@ -197,15 +200,17 @@ static void
write_data(const char *fname)
{
FILE *fp;
CARD *p = 0;
int n;

if (!strcmp(fname, default_name))
fname = "cardfile.out";

if ((fp = fopen(fname, "w")) != 0) {
CARD *p = 0;

for (p = all_cards; p != 0; p = p->link) {
FIELD **f = form_fields(p->form);
int n;

for (n = 0; f[n] != 0; n++) {
char *s = field_buffer(f[n], 0);
if (s != 0
Expand Down Expand Up @@ -365,7 +370,7 @@ show_legend(void)

#if (defined(KEY_RESIZE) && HAVE_WRESIZE) || NO_LEAKS
static void
free_form_fields(FIELD ** f)
free_form_fields(FIELD **f)
{
int n;

Expand All @@ -391,7 +396,6 @@ cardfile(char *fname)
int form_high;
int y;
int x;
int ch = ERR;
int finished = FALSE;

show_legend();
Expand Down Expand Up @@ -432,6 +436,8 @@ cardfile(char *fname)
order_cards(top_card, visible_cards);

while (!finished) {
int ch = ERR;

update_panels();
doupdate();

Expand Down Expand Up @@ -522,13 +528,11 @@ cardfile(char *fname)
}
#if NO_LEAKS
while (all_cards != 0) {
FIELD **f;

p = all_cards;
all_cards = all_cards->link;

if (isVisible(p)) {
f = form_fields(p->form);
FIELD **f = form_fields(p->form);

unpost_form(p->form); /* ...so we can free it */
free_form(p->form); /* this also disconnects the fields */
Expand Down
7 changes: 4 additions & 3 deletions test/chgat.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 2006-2012,2017 Free Software Foundation, Inc. *
* Copyright (c) 2006-2017,2019 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 *
Expand All @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: chgat.c,v 1.17 2017/09/28 23:04:14 tom Exp $
* $Id: chgat.c,v 1.18 2019/08/17 21:49:19 tom Exp $
*
* test-driver for chgat/wchgat/mvchgat/mvwchgat
*/
Expand Down Expand Up @@ -75,10 +75,11 @@ color_params(size_t state, short *pair)
};
/* *INDENT-ON* */

static bool first = TRUE;
const char *result = 0;

if (has_colors()) {
static bool first = TRUE;

if (first) {
size_t n;

Expand Down
9 changes: 5 additions & 4 deletions test/clip_printw.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 2008-2016,2017 Free Software Foundation, Inc. *
* Copyright (c) 2008-2017,2019 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 *
Expand All @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: clip_printw.c,v 1.15 2017/09/28 23:07:23 tom Exp $
* $Id: clip_printw.c,v 1.16 2019/08/17 21:49:40 tom Exp $
*
* demonstrate how to use printw without wrapping.
*/
Expand Down Expand Up @@ -56,7 +56,7 @@ typedef struct {
} STATUS;

static int
clip_wprintw(WINDOW *win, NCURSES_CONST char *fmt,...)
clip_wprintw(WINDOW *win, NCURSES_CONST char *fmt, ...)
{
int y0, x0, y1, x1, width;
WINDOW *sub;
Expand Down Expand Up @@ -103,10 +103,11 @@ color_params(unsigned state, int *pair)
};
/* *INDENT-ON* */

static bool first = TRUE;
const char *result = 0;

if (has_colors()) {
static bool first = TRUE;

if (first) {
unsigned n;

Expand Down
4 changes: 2 additions & 2 deletions test/color_content.c
Expand Up @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: color_content.c,v 1.10 2019/01/21 01:05:44 tom Exp $
* $Id: color_content.c,v 1.11 2019/08/17 21:29:13 tom Exp $
*/

#define NEED_TIME_H
Expand Down Expand Up @@ -251,7 +251,6 @@ int
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
int i;
int repeat;

while ((i = getopt(argc, argv, "f:il:npr:sx")) != -1) {
switch (i) {
Expand Down Expand Up @@ -305,6 +304,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
}
}
} else {
int repeat;

for (repeat = 0; repeat < r_opt; ++repeat) {
run_test();
Expand Down
7 changes: 4 additions & 3 deletions test/color_set.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 2003-2012,2014 Free Software Foundation, Inc. *
* Copyright (c) 2003-2014,2019 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 *
Expand All @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: color_set.c,v 1.8 2014/02/01 22:10:42 tom Exp $
* $Id: color_set.c,v 1.9 2019/08/17 21:49:19 tom Exp $
*/

#include <test.priv.h>
Expand All @@ -39,13 +39,14 @@ int
main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
{
NCURSES_COLOR_T f, b;
int i;

initscr();
cbreak();
noecho();

if (has_colors()) {
int i;

start_color();

(void) pair_content(0, &f, &b);
Expand Down
16 changes: 9 additions & 7 deletions test/demo_altkeys.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 2005-2017,2018 Free Software Foundation, Inc. *
* Copyright (c) 2005-2018,2019 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 *
Expand All @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: demo_altkeys.c,v 1.12 2018/12/29 17:52:53 tom Exp $
* $Id: demo_altkeys.c,v 1.13 2019/08/17 21:49:40 tom Exp $
*
* Demonstrate the define_key() function.
* Thomas Dickey - 2005/10/22
Expand All @@ -47,11 +47,12 @@ static void
log_last_line(WINDOW *win)
{
FILE *fp;
int y, x, n;
char temp[256];

if ((fp = fopen(MY_LOGFILE, "a")) != 0) {
char temp[256];
int y, x, n;
int need = sizeof(temp) - 1;

if (need > COLS)
need = COLS;
getyx(win, y, x);
Expand All @@ -75,8 +76,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
int n;
int ch;
#if HAVE_GETTIMEOFDAY
int secs, msecs;
struct timeval current, previous;
struct timeval previous;
#endif

unlink(MY_LOGFILE);
Expand Down Expand Up @@ -119,8 +119,10 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
while ((ch = getch()) != ERR) {
bool escaped = (ch >= MY_KEYS);
const char *name = keyname(escaped ? (ch - MY_KEYS) : ch);

#if HAVE_GETTIMEOFDAY
int secs, msecs;
struct timeval current;

gettimeofday(&current, 0);
secs = (int) (current.tv_sec - previous.tv_sec);
msecs = (int) ((current.tv_usec - previous.tv_usec) / 1000);
Expand Down
17 changes: 9 additions & 8 deletions test/demo_defkey.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 2002-2017,2018 Free Software Foundation, Inc. *
* Copyright (c) 2002-2018,2019 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 *
Expand All @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: demo_defkey.c,v 1.28 2018/02/12 09:57:31 tom Exp $
* $Id: demo_defkey.c,v 1.29 2019/08/17 21:49:19 tom Exp $
*
* Demonstrate the define_key() function.
* Thomas Dickey - 2002/11/23
Expand All @@ -45,10 +45,10 @@ static void
log_last_line(WINDOW *win)
{
FILE *fp;
int y, x, n;
char temp[256];

if ((fp = fopen(MY_LOGFILE, "a")) != 0) {
char temp[256];
int y, x, n;
int need = sizeof(temp) - 1;
if (need > COLS)
need = COLS;
Expand Down Expand Up @@ -98,11 +98,12 @@ static char *
visible(const char *string)
{
char *result = 0;
size_t need = 1;
int pass;
int n;

if (string != 0 && *string != '\0') {
int pass;
int n;
size_t need = 1;

for (pass = 0; pass < 2; ++pass) {
for (n = 0; string[n] != '\0'; ++n) {
char temp[80];
Expand Down Expand Up @@ -185,14 +186,14 @@ duplicate(WINDOW *win, NCURSES_CONST char *name, int code)

if (value != 0) {
const char *prefix = 0;
char temp[BUFSIZ];

if (!(strncmp) (value, "\033[", (size_t) 2)) {
prefix = "\033O";
} else if (!(strncmp) (value, "\033O", (size_t) 2)) {
prefix = "\033[";
}
if (prefix != 0) {
char temp[BUFSIZ];
_nc_SPRINTF(temp, _nc_SLIMIT(sizeof(temp))
"%s%s", prefix, value + 2);
really_define_key(win, temp, code);
Expand Down
19 changes: 11 additions & 8 deletions test/demo_forms.c
@@ -1,5 +1,5 @@
/****************************************************************************
* Copyright (c) 2003-2017,2018 Free Software Foundation, Inc. *
* Copyright (c) 2003-2018,2019 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 *
Expand All @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: demo_forms.c,v 1.55 2018/07/14 23:26:02 tom Exp $
* $Id: demo_forms.c,v 1.56 2019/08/17 21:49:19 tom Exp $
*
* Demonstrate a variety of functions from the form library.
* Thomas Dickey - 2003/4/26
Expand Down Expand Up @@ -338,9 +338,6 @@ static void
show_current_field(WINDOW *win, FORM *form)
{
FIELD *field;
FIELDTYPE *type;
char *buffer;
int nbuf;
int field_rows, field_cols, field_max;
int currow, curcol;

Expand All @@ -355,7 +352,11 @@ show_current_field(WINDOW *win, FORM *form)
if (data_behind(form))
waddstr(win, " behind");
waddch(win, '\n');

if ((field = current_field(form)) != 0) {
FIELDTYPE *type;
int nbuf;

wprintw(win, "Page %d%s, Field %d/%d%s:",
form_page(form),
new_page(field) ? "*" : "",
Expand Down Expand Up @@ -411,6 +412,7 @@ show_current_field(WINDOW *win, FORM *form)

waddstr(win, "\n");
for (nbuf = 0; nbuf <= 2; ++nbuf) {
char *buffer;
if ((buffer = field_buffer(field, nbuf)) != 0) {
wprintw(win, "buffer %d:", nbuf);
(void) wattrset(win, A_REVERSE);
Expand All @@ -430,13 +432,11 @@ show_current_field(WINDOW *win, FORM *form)
static void
demo_forms(void)
{
WINDOW *w;
FORM *form;
FIELD *f[100]; /* will memset to zero */
int finished = 0, c;
int c;
unsigned n = 0;
int pg;
WINDOW *also;
const char *fname;
static const char *my_enum[] =
{"first", "second", "third", 0};
Expand Down Expand Up @@ -544,6 +544,9 @@ demo_forms(void)
f[n] = (FIELD *) 0;

if ((form = new_form(f)) != 0) {
WINDOW *w;
WINDOW *also;
int finished = 0;

display_form(form);

Expand Down
10 changes: 4 additions & 6 deletions test/demo_menus.c
Expand Up @@ -26,7 +26,7 @@
* authorization. *
****************************************************************************/
/*
* $Id: demo_menus.c,v 1.67 2019/08/10 19:25:27 tom Exp $
* $Id: demo_menus.c,v 1.68 2019/08/17 21:45:32 tom Exp $
*
* Demonstrate a variety of functions from the menu library.
* Thomas Dickey - 2005/4/9
Expand Down Expand Up @@ -309,12 +309,11 @@ menu_create(ITEM ** items, int count, int ncols, MenuNo number)
static void
menu_destroy(MENU * m)
{
int count;

Trace(("menu_destroy %p", (void *) m));
if (m != 0) {
ITEM **items = menu_items(m);
const char *blob = 0;
int count;

count = item_count(m);
Trace(("menu_destroy %p count %d", (void *) m, count));
Expand Down Expand Up @@ -429,7 +428,6 @@ build_select_menu(MenuNo number, char *filename)
&& (sb.st_mode & S_IFMT) == S_IFREG
&& sb.st_size != 0) {
size_t size = (size_t) sb.st_size;
unsigned j, k;
char *blob = typeMalloc(char, size + 1);
MENU_DATA *list = typeCalloc(MENU_DATA, size + 1);

Expand All @@ -442,6 +440,7 @@ build_select_menu(MenuNo number, char *filename)
if (fp != 0) {
if (fread(blob, sizeof(char), size, fp) == size) {
bool mark = TRUE;
unsigned j, k;
for (j = k = 0; j < size; ++j) {
if (mark) {
list[k++].name = blob + j;
Expand Down Expand Up @@ -609,7 +608,6 @@ perform_trace_menu(int cmd)
/* interactively set the trace level */
{
ITEM **ip;
unsigned newtrace;
int result;

for (ip = menu_items(mpTrace); *ip; ip++) {
Expand All @@ -625,7 +623,7 @@ perform_trace_menu(int cmd)

if (result == E_OK) {
if (update_trace_menu(mpTrace) || cmd == REQ_TOGGLE_ITEM) {
newtrace = 0;
unsigned newtrace = 0;
for (ip = menu_items(mpTrace); *ip; ip++) {
if (item_value(*ip)) {
MENU_DATA *td = (MENU_DATA *) item_userptr(*ip);
Expand Down
4 changes: 2 additions & 2 deletions test/test_sgr.c
Expand Up @@ -29,7 +29,7 @@
/*
* Author: Thomas E. Dickey
*
* $Id: test_sgr.c,v 1.13 2019/07/28 18:13:39 tom Exp $
* $Id: test_sgr.c,v 1.14 2019/08/17 21:36:44 tom Exp $
*
* A simple demo of the sgr/sgr0 terminal capabilities.
*/
Expand Down Expand Up @@ -147,7 +147,7 @@ dumpit(unsigned bits, unsigned ignore, const char *sgr, const char *sgr0)
static char params[] = "SURBDBIPA";
unsigned n;

printf("%4d ", bits);
printf("%4u ", bits);
bits &= ~ignore;
for (n = 0; n < MAXPAR; ++n) {
putchar((int) ((bits & (unsigned) (1 << n)) ? params[n] : '-'));
Expand Down