]> ncurses.scripts.mit.edu Git - ncurses.git/blobdiff - test/savescreen.c
ncurses 6.0 - patch 20170930
[ncurses.git] / test / savescreen.c
index 44d7d1ca1a6b4223b0f1b8faeb8c3ef27210f070..6cd4c60811f5fc3630cbbe2f88bd3f1ee66da3b8 100644 (file)
@@ -1,5 +1,5 @@
 /****************************************************************************
 /****************************************************************************
- * Copyright (c) 2007-2011,2015 Free Software Foundation, Inc.              *
+ * Copyright (c) 2007-2015,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            *
  *                                                                          *
  * Permission is hereby granted, free of charge, to any person obtaining a  *
  * copy of this software and associated documentation files (the            *
  * authorization.                                                           *
  ****************************************************************************/
 /*
  * authorization.                                                           *
  ****************************************************************************/
 /*
- * $Id: savescreen.c,v 1.21 2015/03/07 21:55:35 tom Exp $
+ * $Id: savescreen.c,v 1.35 2017/09/29 23:42:22 tom Exp $
  *
  * Demonstrate save/restore functions from the curses library.
  * Thomas Dickey - 2007/7/14
  */
 
 #include <test.priv.h>
  *
  * Demonstrate save/restore functions from the curses library.
  * Thomas Dickey - 2007/7/14
  */
 
 #include <test.priv.h>
+#include <popup_msg.h>
 
 #if HAVE_SCR_DUMP
 
 
 #if HAVE_SCR_DUMP
 
 # endif
 #endif
 
 # endif
 #endif
 
+#if defined(__hpux)
+#define MyMarker 'X'
+#else
+#define MyMarker ACS_DIAMOND
+#endif
+
 static bool use_init = FALSE;
 static bool use_init = FALSE;
+static bool keep_dumps = FALSE;
+
+#if USE_WIDEC_SUPPORT
+/* In HPUX curses, cchar_t is opaque; other implementations are not */
+static wchar_t
+BaseChar(cchar_t data)
+{
+    wchar_t my_wchar[sizeof(cchar_t)];
+    attr_t my_attr;
+    short my_pair;
+    getcchar(&data, my_wchar, &my_attr, &my_pair, NULL);
+    return my_wchar[0];
+}
+#endif
 
 static int
 fexists(const char *name)
 
 static int
 fexists(const char *name)
@@ -71,8 +92,10 @@ cleanup(char *files[])
 {
     int n;
 
 {
     int n;
 
-    for (n = 0; files[n] != 0; ++n) {
-       unlink(files[n]);
+    if (!keep_dumps) {
+       for (n = 0; files[n] != 0; ++n) {
+           unlink(files[n]);
+       }
     }
 }
 
     }
 }
 
@@ -145,24 +168,6 @@ get_command(int which, int last)
     return ch;
 }
 
     return ch;
 }
 
-static void
-show_help(const char **help)
-{
-    WINDOW *mywin = newwin(LINES, COLS, 0, 0);
-    int n;
-
-    box(mywin, 0, 0);
-    wmove(mywin, 1, 1);
-    for (n = 0; help[n] != 0; ++n) {
-       wmove(mywin, 1 + n, 2);
-       wprintw(mywin, "%.*s", COLS - 4, help[n]);
-    }
-    wgetch(mywin);
-    delwin(mywin);
-    touchwin(stdscr);
-    refresh();
-}
-
 static void
 editor_help(void)
 {
 static void
 editor_help(void)
 {
@@ -180,8 +185,9 @@ editor_help(void)
        "   a           toggle between '#' and graphic symbol for drawing",
        "   c           change color drawn by line to next in palette",
        "   h,j,k,l or arrows to move around the screen, drawing",
        "   a           toggle between '#' and graphic symbol for drawing",
        "   c           change color drawn by line to next in palette",
        "   h,j,k,l or arrows to move around the screen, drawing",
+       0
     };
     };
-    show_help(msgs);
+    popup_msg(stdscr, msgs);
 }
 
 static void
 }
 
 static void
@@ -196,8 +202,9 @@ replay_help(void)
        "   q           quit",
        "   <space>     load the next screen",
        "   <backspace> load the previous screen",
        "   q           quit",
        "   <space>     load the next screen",
        "   <backspace> load the previous screen",
+       0
     };
     };
-    show_help(msgs);
+    popup_msg(stdscr, msgs);
 }
 
 static void
 }
 
 static void
@@ -208,8 +215,10 @@ usage(void)
        "Usage: savescreen [-r] files",
        "",
        "Options:",
        "Usage: savescreen [-r] files",
        "",
        "Options:",
-       " -i  use scr_init/scr_restore rather than scr_set",
-       " -r  replay the screen-dump files"
+       " -f file  fill/initialize screen using text from this file",
+       " -i       use scr_init/scr_restore rather than scr_set",
+       " -k       keep the restored dump-files rather than removing them",
+       " -r       replay the screen-dump files"
     };
     unsigned n;
     for (n = 0; n < SIZEOF(msg); ++n) {
     };
     unsigned n;
     for (n = 0; n < SIZEOF(msg); ++n) {
@@ -227,12 +236,25 @@ main(int argc, char *argv[])
     bool replaying = FALSE;
     bool done = FALSE;
     char **files;
     bool replaying = FALSE;
     bool done = FALSE;
     char **files;
+    char *fill_by = 0;
+#if USE_WIDEC_SUPPORT
+    cchar_t mycc;
+    int myxx;
+#endif
+
+    setlocale(LC_ALL, "");
 
 
-    while ((ch = getopt(argc, argv, "ir")) != -1) {
+    while ((ch = getopt(argc, argv, "f:ikr")) != -1) {
        switch (ch) {
        switch (ch) {
+       case 'f':
+           fill_by = optarg;
+           break;
        case 'i':
            use_init = TRUE;
            break;
        case 'i':
            use_init = TRUE;
            break;
+       case 'k':
+           keep_dumps = TRUE;
+           break;
        case 'r':
            replaying = TRUE;
            break;
        case 'r':
            replaying = TRUE;
            break;
@@ -268,7 +290,32 @@ main(int argc, char *argv[])
         */
        for (pair = 0; pair < COLOR_PAIRS; ++pair) {
            color = (short) (pair % (COLORS - 1));
         */
        for (pair = 0; pair < COLOR_PAIRS; ++pair) {
            color = (short) (pair % (COLORS - 1));
-           init_pair(pair, COLOR_WHITE - color, color);
+           init_pair(pair, (short) (COLOR_WHITE - color), color);
+       }
+    }
+
+    if (fill_by != 0) {
+       FILE *fp = fopen(fill_by, "r");
+       if (fp != 0) {
+           bool filled = FALSE;
+           move(1, 0);
+           while ((ch = fgetc(fp)) != EOF) {
+               if (addch(UChar(ch)) == ERR) {
+                   filled = TRUE;
+                   break;
+               }
+           }
+           fclose(fp);
+           if (!filled) {
+               while (addch(' ') != ERR) {
+                   ;
+               }
+           }
+           move(0, 0);
+       } else {
+           exit_curses();
+           fprintf(stderr, "Cannot open \"%s\"\n", fill_by);
+           ExitProgram(EXIT_FAILURE);
        }
     }
 
        }
     }
 
@@ -278,14 +325,14 @@ main(int argc, char *argv[])
         * Use the last file as the initial/current screen.
         */
        if (last < 0) {
         * Use the last file as the initial/current screen.
         */
        if (last < 0) {
-           endwin();
+           exit_curses();
            printf("No screen-dumps given\n");
            ExitProgram(EXIT_FAILURE);
        }
 
        which = last;
        if (load_screen(files[which]) == ERR) {
            printf("No screen-dumps given\n");
            ExitProgram(EXIT_FAILURE);
        }
 
        which = last;
        if (load_screen(files[which]) == ERR) {
-           endwin();
+           exit_curses();
            printf("Cannot load screen-dump %s\n", files[which]);
            ExitProgram(EXIT_FAILURE);
        }
            printf("Cannot load screen-dump %s\n", files[which]);
            ExitProgram(EXIT_FAILURE);
        }
@@ -315,7 +362,7 @@ main(int argc, char *argv[])
                if (++which > last)
                    which = 0;
                break;
                if (++which > last)
                    which = 0;
                break;
-           case '?':
+           case HELP_KEY_1:
                replay_help();
                break;
            default:
                replay_help();
                break;
            default:
@@ -376,7 +423,17 @@ main(int argc, char *argv[])
                            for (cx = 0; cx < COLS; ++cx) {
                                wmove(curscr, cy, cx);
                                wmove(stdscr, cy, cx);
                            for (cx = 0; cx < COLS; ++cx) {
                                wmove(curscr, cy, cx);
                                wmove(stdscr, cy, cx);
+#if USE_WIDEC_SUPPORT
+                               if (win_wch(curscr, &mycc) != ERR) {
+                                   myxx = wcwidth(BaseChar(mycc));
+                                   if (myxx > 0) {
+                                       wadd_wchnstr(stdscr, &mycc, 1);
+                                       cx += (myxx - 1);
+                                   }
+                               }
+#else
                                waddch(stdscr, winch(curscr));
                                waddch(stdscr, winch(curscr));
+#endif
                            }
                        }
                    }
                            }
                        }
                    }
@@ -410,7 +467,7 @@ main(int argc, char *argv[])
            case 'c':
                color = (color + 1) % COLORS;
                break;
            case 'c':
                color = (color + 1) % COLORS;
                break;
-           case '?':
+           case HELP_KEY_1:
                editor_help();
                break;
            default:
                editor_help();
                break;
            default:
@@ -418,10 +475,10 @@ main(int argc, char *argv[])
                continue;
            }
            if (!done) {
                continue;
            }
            if (!done) {
-               attr_t attr = (A_REVERSE | COLOR_PAIR(color * COLORS));
-               chtype ch2 = (altchars ? ACS_DIAMOND : '#');
+               chtype attr = (A_REVERSE | (chtype) COLOR_PAIR(color * COLORS));
+               chtype ch2 = (altchars ? MyMarker : '#');
                move(y, x);
                move(y, x);
-               addch(ch2 | attr);
+               AddCh(ch2 | attr);
                move(y, x);
            }
        }
                move(y, x);
            }
        }
@@ -432,7 +489,7 @@ main(int argc, char *argv[])
 
 #else
 int
 
 #else
 int
-main(int argc, char *argv[])
+main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED)
 {
     printf("This program requires the screen-dump functions\n");
     ExitProgram(EXIT_FAILURE);
 {
     printf("This program requires the screen-dump functions\n");
     ExitProgram(EXIT_FAILURE);