/****************************************************************************
- * 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 *
/*
* Author: Thomas E. Dickey
*
- * $Id: demo_termcap.c,v 1.11 2009/08/02 00:02:53 tom Exp $
+ * $Id: demo_termcap.c,v 1.17 2012/03/01 01:09:30 tom Exp $
*
* A simple demo of the termcap interface.
*/
#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)
{
} 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");
}
cap[2] = 0;
for (c1 = 0; c1 < 256; ++c1) {
- cap[0] = c1;
+ cap[0] = (char) c1;
if (isCapName(c1)) {
for (c2 = 0; c2 < 256; ++c2) {
- cap[1] = c2;
+ cap[1] = (char) c2;
if (isCapName(c2)) {
dumpit(cap);
}
#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) {
{
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.",
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);
}