/****************************************************************************
- * Copyright 2018-2019,2020 Thomas E. Dickey *
+ * Copyright 2018-2022,2023 Thomas E. Dickey *
* Copyright 2013-2014,2017 Free Software Foundation, Inc. *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
/*
* Author: Thomas E. Dickey
*
- * $Id: dots_termcap.c,v 1.25 2020/08/29 16:22:03 juergen Exp $
+ * $Id: dots_termcap.c,v 1.32 2023/02/25 18:11:21 tom Exp $
*
* A simple demo of the termcap interface.
*/
return ((double) r / 32768.);
}
+/*
+ * napms is a curses function which happens to be usable without initializing
+ * the screen, but if this program happened to be build with a "real" termcap
+ * library, there is nothing like napms.
+ */
+#if HAVE_NAPMS
+#define my_napms(ms) napms(ms)
+#else
static void
my_napms(int ms)
{
if (ms > 0) {
-#if defined(_NC_WINDOWS) || !HAVE_GETTIMEOFDAY
- Sleep((DWORD) ms);
+#if defined(_NC_WINDOWS)
+ Sleep((unsigned int) ms);
#else
struct timeval data;
data.tv_sec = 0;
#endif
}
}
+#endif
static int
get_number(NCURSES_CONST char *cap, const char *env)
}
static void
-usage(void)
+usage(int ok)
{
static const char *msg[] =
{
"Usage: dots_termcap [options]"
,""
+ ,USAGE_COMMON
,"Options:"
," -T TERM override $TERM"
," -e allow environment $LINES / $COLUMNS"
for (n = 0; n < SIZEOF(msg); n++)
fprintf(stderr, "%s\n", msg[n]);
- ExitProgram(EXIT_FAILURE);
+ ExitProgram(ok ? EXIT_SUCCESS : EXIT_FAILURE);
}
+/* *INDENT-OFF* */
+VERSION_COMMON()
+/* *INDENT-ON* */
int
main(int argc, char *argv[])
size_t need;
char *my_env;
- while ((ch = getopt(argc, argv, "T:em:r:s:")) != -1) {
+ while ((ch = getopt(argc, argv, OPTS_COMMON "T:em:r:s:")) != -1) {
switch (ch) {
case 'T':
need = 6 + strlen(optarg);
- my_env = malloc(need);
- _nc_SPRINTF(my_env, _nc_SLIMIT(need) "TERM=%s", optarg);
- putenv(my_env);
+ if ((my_env = malloc(need)) != NULL) {
+ _nc_SPRINTF(my_env, _nc_SLIMIT(need) "TERM=%s", optarg);
+ putenv(my_env);
+ }
break;
case 'e':
e_option = 1;
case 's':
s_option = atoi(optarg);
break;
+ case OPTS_VERSION:
+ show_version(argv);
+ ExitProgram(EXIT_SUCCESS);
default:
- usage();
- break;
+ usage(ch == OPTS_USAGE);
+ /* NOTREACHED */
}
}
}
#else
int
-main(int argc GCC_UNUSED,
- char *argv[]GCC_UNUSED)
+main(void)
{
fprintf(stderr, "This program requires termcap\n");
exit(EXIT_FAILURE);