X-Git-Url: https://ncurses.scripts.mit.edu/?p=ncurses.git;a=blobdiff_plain;f=test%2Fdemo_termcap.c;h=b14454de0249eed9ec18f660b7975e26770a457a;hp=4289de0540e3cfba1a008300646cbc4bafad9992;hb=ceaf3464e98d7984ed377f023abf63d69b7b8045;hpb=59108c98bda25ae50b3a319e2bcb7f4b9a174024 diff --git a/test/demo_termcap.c b/test/demo_termcap.c index 4289de05..b14454de 100644 --- a/test/demo_termcap.c +++ b/test/demo_termcap.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright (c) 2005-2008,2009 Free Software Foundation, Inc. * + * Copyright (c) 2005-2011,2012 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 * - * $Id: demo_termcap.c,v 1.12 2009/10/10 16:01:41 tom Exp $ + * $Id: demo_termcap.c,v 1.17 2012/03/01 01:09:30 tom Exp $ * * A simple demo of the termcap interface. */ @@ -55,6 +55,28 @@ static bool s_opt = FALSE; #define isCapName(c) (isgraph(c) && strchr("^#=:\\", c) == 0) +#if NO_LEAKS && USE_CODE_LISTS + +#define MYSCR struct _myscr +MYSCR { + MYSCR *next; + TERMINAL *term; +}; + +static MYSCR *my_screens; + +static void +save_screen(void) +{ + MYSCR *obj = malloc(sizeof(MYSCR)); + obj->next = my_screens; + obj->term = cur_term; + my_screens = obj; +} +#else +#define save_screen() /* nothing */ +#endif + static void dumpit(NCURSES_CONST char *cap) { @@ -125,7 +147,7 @@ dumpit(NCURSES_CONST char *cap) } else if ((num = tgetnum(cap)) >= 0) { printf(FNAME(num), cap); printf(" %d\n", num); - } else if ((num = tgetflag(cap)) > 0) { + } else if (tgetflag(cap) > 0) { printf(FNAME(flg), cap); printf("%s\n", "true"); } @@ -159,13 +181,18 @@ brute_force(const char *name) #if USE_CODE_LISTS static void -demo_terminfo(NCURSES_CONST char *name) +demo_termcap(NCURSES_CONST char *name) { unsigned n; NCURSES_CONST char *cap; printf("Terminal type \"%s\"\n", name); +#if HAVE_SETUPTERM setupterm(name, 1, (int *) 0); +#else + setterm(name); +#endif + save_screen(); if (b_opt) { for (n = 0;; ++n) { @@ -200,7 +227,7 @@ usage(void) { static const char *msg[] = { - "Usage: demo_terminfo [options] [terminal]", + "Usage: demo_termcap [options] [terminal]", "", "If no options are given, print all (boolean, numeric, string)", "capabilities for the given terminal, using short names.", @@ -281,17 +308,31 @@ main(int argc, char *argv[]) for (repeat = 0; repeat < r_opt; ++repeat) { if (optind < argc) { for (n = optind; n < argc; ++n) { - demo_terminfo(argv[n]); + demo_termcap(argv[n]); } } else if ((name = getenv("TERM")) != 0) { - demo_terminfo(name); + demo_termcap(name); } else { static char dumb[] = "dumb"; - demo_terminfo(dumb); + demo_termcap(dumb); } } - } +#if NO_LEAKS + /* + * ncurses' tgetent() interface caches some entries and its no-leaks + * code discards those. The calls to setupterm() on the other hand + * are not cached, and each call allocates a chunk of memory, even + * if the same terminal type is requested repeatedly. + */ + while (my_screens != 0) { + MYSCR *next = my_screens->next; + del_curterm(my_screens->term); + free(my_screens); + my_screens = next; + } #endif + } +#endif /* USE_CODE_LISTS */ ExitProgram(EXIT_SUCCESS); }