X-Git-Url: http://ncurses.scripts.mit.edu/?a=blobdiff_plain;f=test%2Fdemo_defkey.c;h=44d60dc936730f4c5e412c04ed0be79b9d97b76e;hb=c11444e368f1d5964bd0f81e6e3b0f8c8ccd09cc;hp=ea6c5222d188b6dbd0b32d9cb103a39748e74082;hpb=47d2fb4537d9ad5bb14f4810561a327930ca4280;p=ncurses.git diff --git a/test/demo_defkey.c b/test/demo_defkey.c index ea6c5222..44d60dc9 100644 --- a/test/demo_defkey.c +++ b/test/demo_defkey.c @@ -1,5 +1,5 @@ /**************************************************************************** - * Copyright 2018-2019,2020 Thomas E. Dickey * + * Copyright 2018-2020,2022 Thomas E. Dickey * * Copyright 2002-2016,2017 Free Software Foundation, Inc. * * * * Permission is hereby granted, free of charge, to any person obtaining a * @@ -27,7 +27,7 @@ * authorization. * ****************************************************************************/ /* - * $Id: demo_defkey.c,v 1.30 2020/02/02 23:34:34 tom Exp $ + * $Id: demo_defkey.c,v 1.33 2022/12/10 23:31:31 tom Exp $ * * Demonstrate the define_key() function. * Thomas Dickey - 2002/11/23 @@ -74,7 +74,7 @@ log_last_line(WINDOW *win) static char * visichar(int ch) { - static char temp[10]; + static char temp[20]; ch = UChar(ch); assert(ch >= 0 && ch < 256); @@ -214,16 +214,50 @@ remove_definition(WINDOW *win, int code) really_define_key(win, 0, code); } +static void +usage(int ok) +{ + static const char *msg[] = + { + "Usage: demo_defkey [options]" + ,"" + ,USAGE_COMMON + }; + size_t n; + + for (n = 0; n < SIZEOF(msg); n++) + fprintf(stderr, "%s\n", msg[n]); + + ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE); +} +/* *INDENT-OFF* */ +VERSION_COMMON() +/* *INDENT-ON* */ + int -main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) +main(int argc, char *argv[]) { char *fkeys[12]; int n; int ch; WINDOW *win; + while ((ch = getopt(argc, argv, OPTS_COMMON)) != -1) { + switch (ch) { + case OPTS_VERSION: + show_version(argv); + ExitProgram(EXIT_SUCCESS); + default: + usage(ch == OPTS_USAGE); + /* NOTREACHED */ + } + } + if (optind < argc) + usage(FALSE); + unlink(MY_LOGFILE); + setlocale(LC_ALL, ""); initscr(); (void) cbreak(); /* take input chars one at a time, no wait for \n */ (void) noecho(); /* don't echo input */ @@ -242,7 +276,7 @@ main(int argc GCC_UNUSED, char *argv[]GCC_UNUSED) * keypad() initializes the corresponding data. */ for (n = 0; n < 12; ++n) { - char name[10]; + char name[20]; _nc_SPRINTF(name, _nc_SLIMIT(sizeof(name)) "kf%d", n + 1); fkeys[n] = tigetstr(name); }