]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/test_vid_puts.c
ncurses 6.0 - patch 20170729
[ncurses.git] / test / test_vid_puts.c
index 9896d1b6cc5c9f038796557046f1180d48d2f86d..81812322ac23d34a654bf7aecb230b2785d61b2c 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
- * Copyright (c) 2013,2014 Free Software Foundation, Inc.                   *
+ * Copyright (c) 2013-2014,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            *
@@ -26,7 +26,7 @@
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: test_vid_puts.c,v 1.6 2014/07/19 23:09:28 tom Exp $
+ * $Id: test_vid_puts.c,v 1.9 2017/06/24 17:48:04 tom Exp $
  *
  * Demonstrate the vid_puts and vid_attr functions.
  * Thomas Dickey - 2013/01/12
@@ -64,10 +64,12 @@ outs(const char *s)
 static void
 cleanup(void)
 {
-    outs(exit_attribute_mode);
-    if (!outs(orig_colors))
-       outs(orig_pair);
-    outs(cursor_normal);
+    if (cur_term != 0) {
+       outs(exit_attribute_mode);
+       if (!outs(orig_colors))
+           outs(orig_pair);
+       outs(cursor_normal);
+    }
 }
 
 static void
@@ -101,6 +103,7 @@ usage(void)
        ,""
        ,"Options:"
        ,"  -e      use stderr (default stdout)"
+       ,"  -n      do not initialize terminal"
        ,"  -p      use vid_puts (default vid_attr)"
     };
     unsigned n;
@@ -113,14 +116,18 @@ int
 main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
 {
     int ch;
+    bool no_init = FALSE;
 
     my_fp = stdout;
 
-    while ((ch = getopt(argc, argv, "ep")) != -1) {
+    while ((ch = getopt(argc, argv, "enp")) != -1) {
        switch (ch) {
        case 'e':
            my_fp = stderr;
            break;
+       case 'n':
+           no_init = TRUE;
+           break;
        case 'p':
            p_opt = TRUE;
            break;
@@ -132,7 +139,11 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
     if (optind < argc)
        usage();
 
-    setupterm((char *) 0, 1, (int *) 0);
+    if (no_init) {
+       START_TRACE();
+    } else {
+       setupterm((char *) 0, fileno(my_fp), (int *) 0);
+    }
     test_vid_puts();
     cleanup();
     ExitProgram(EXIT_SUCCESS);