X-Git-Url: https://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Ftest_mouse.c;h=d6013c7404b13393cd8305d6f88d260d3ceef071;hb=9e084820c3f396f861b2cb74fbd5fc15aa10b6bc;hp=b24903d541454cbd0c9a895af5fcdbaea548d0e6;hpb=1ddfa997c0965852dbdc738aa6d92c0cd0975f3b;p=ncurses.git diff --git a/test/test_mouse.c b/test/test_mouse.c index b24903d5..d6013c74 100644 --- a/test/test_mouse.c +++ b/test/test_mouse.c @@ -1,6 +1,6 @@ /**************************************************************************** + * Copyright 2022,2023 Thomas E. Dickey * * Copyright 2022 Leonid S. Usov * - * Copyright 2022 Thomas E. Dickey * * * * Permission is hereby granted, free of charge, to any person obtaining a * * copy of this software and associated documentation files (the * @@ -22,7 +22,7 @@ * THE USE OR OTHER DEALINGS IN THE SOFTWARE. * ****************************************************************************/ /* - * $Id: test_mouse.c,v 1.19 2022/05/15 16:41:20 tom Exp $ + * $Id: test_mouse.c,v 1.27 2023/01/07 17:22:42 tom Exp $ * * Author: Leonid S Usov * @@ -43,7 +43,18 @@ raw_loop(void) char *xtermcap; tcgetattr(0, &old); +#if HAVE_CFMAKERAW cfmakeraw(&tty); +#else + tty = old; + tty.c_iflag &= (unsigned) (~(IGNBRK | BRKINT | PARMRK | ISTRIP + | INLCR | IGNCR | ICRNL | IXON)); + tty.c_oflag &= (unsigned) (~OPOST); + tty.c_lflag &= (unsigned) (~(ECHO | ECHONL | ICANON | ISIG | IEXTEN)); + tty.c_cflag &= (unsigned) (~(CSIZE | PARENB)); + tty.c_cflag |= CS8; + tcsetattr(0, TCSANOW, &tty); +#endif setupterm(NULL, 0, 0); xtermcap = tigetstr("XM"); @@ -57,7 +68,7 @@ raw_loop(void) tcsetattr(0, TCSANOW, &tty); - while (true) { + while (1) { int c = getc(stdin); const char *pretty; @@ -86,11 +97,13 @@ static void logw(const char *fmt, ...) { int row = getcury(stdscr); - va_list args; + va_start(args, fmt); wmove(stdscr, row++, 0); vw_printw(stdscr, fmt, args); + va_end(args); + clrtoeol(); row %= (getmaxy(stdscr) - logoffset); @@ -104,45 +117,46 @@ logw(const char *fmt, ...) } static void -usage(void) +usage(int ok) { static const char *msg[] = { - "Usage: test_mouse [options]", - "", - "Test mouse events. These examples for $TERM demonstrate xterm" - "features:", - " xterm", - " xterm-1002", - " xterm-1003", - "", - "Options:", - " -r show raw input stream, injecting a new line before every ESC", - " -i n set mouse interval to n; default is 0 (no double-clicks)", - " -h show this message", - " -T term use terminal description other than $TERM" + "Usage: test_mouse [options]" + ,"" + ,"Test mouse events. These examples for $TERM demonstrate xterm" + ,"features:" + ," xterm" + ," xterm-1002" + ," xterm-1003" + ,"" + ,USAGE_COMMON + ,"Options:" + ," -r show raw input stream, injecting a new line before every ESC" + ," -i n set mouse interval to n; default is 0 (no double-clicks)" + ," -T term use terminal description other than $TERM" }; unsigned n; for (n = 0; n < sizeof(msg) / sizeof(char *); ++n) { fprintf(stderr, "%s\n", msg[n]); } + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); } +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ int main(int argc, char *argv[]) { bool rawmode = FALSE; int interval = 0; - int c; + int ch; MEVENT event; char *my_environ = NULL; const char *term_format = "TERM=%s"; - while ((c = getopt(argc, argv, "hi:rT:")) != -1) { - switch (c) { - case 'h': - usage(); - ExitProgram(EXIT_SUCCESS); + while ((ch = getopt(argc, argv, OPTS_COMMON "i:rT:")) != -1) { + switch (ch) { case 'i': interval = atoi(optarg); break; @@ -151,16 +165,21 @@ main(int argc, char *argv[]) break; case 'T': my_environ = malloc(strlen(term_format) + strlen(optarg)); - sprintf(my_environ, term_format, optarg); - putenv(my_environ); + if (my_environ != NULL) { + sprintf(my_environ, term_format, optarg); + putenv(my_environ); + } break; + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); default: - usage(); - ExitProgram(EXIT_FAILURE); + usage(ch == OPTS_USAGE); + /* NOTREACHED */ } } if (optind < argc) { - usage(); + usage(FALSE); ExitProgram(EXIT_FAILURE); } @@ -186,7 +205,7 @@ main(int argc, char *argv[]) logoffset = getcury(stdscr); while (1) { - c = getch(); + int c = getch(); switch (c) { case KEY_MOUSE: