2006-07-04 00:00:58 +08:00
|
|
|
/* setmetamode.c
|
|
|
|
|
|
|
|
Written by Kazuhiro Fujieda <fujieda@jaist.ac.jp>
|
|
|
|
|
|
|
|
This file is part of Cygwin.
|
|
|
|
|
|
|
|
This software is a copyrighted work licensed under the terms of the
|
|
|
|
Cygwin license. Please consult the file "CYGWIN_LICENSE" for
|
|
|
|
details. */
|
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
#include <errno.h>
|
2006-07-04 00:00:58 +08:00
|
|
|
#include <stdio.h>
|
2020-08-07 19:29:43 +08:00
|
|
|
#include <stdlib.h>
|
2006-07-04 00:00:58 +08:00
|
|
|
#include <string.h>
|
2011-10-10 22:57:48 +08:00
|
|
|
#include <getopt.h>
|
2006-07-04 00:00:58 +08:00
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <cygwin/kd.h>
|
2011-10-10 22:57:48 +08:00
|
|
|
#include <cygwin/version.h>
|
2006-07-04 00:00:58 +08:00
|
|
|
|
2020-08-07 19:29:43 +08:00
|
|
|
static void __attribute__ ((__noreturn__))
|
|
|
|
usage (FILE *stream)
|
2006-07-04 00:00:58 +08:00
|
|
|
{
|
2020-08-07 19:29:43 +08:00
|
|
|
fprintf (stream, "Usage: %s [metabit|escprefix]\n"
|
2011-10-10 22:57:48 +08:00
|
|
|
"\n"
|
|
|
|
"Get or set keyboard meta mode\n"
|
|
|
|
"\n"
|
2006-07-04 00:00:58 +08:00
|
|
|
" Without argument, it shows the current meta key mode.\n"
|
|
|
|
" metabit|meta|bit The meta key sets the top bit of the character.\n"
|
2011-10-10 22:57:48 +08:00
|
|
|
" escprefix|esc|prefix The meta key sends an escape prefix.\n"
|
|
|
|
"\n"
|
|
|
|
"Other options:\n"
|
|
|
|
"\n"
|
|
|
|
" -h, --help This text\n"
|
|
|
|
" -V, --version Print program version and exit\n\n",
|
|
|
|
program_invocation_short_name);
|
2020-08-07 19:29:43 +08:00
|
|
|
exit (stream == stdout ? 0 : 1);
|
2006-07-04 00:00:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
error (void)
|
|
|
|
{
|
|
|
|
fprintf (stderr,
|
|
|
|
"%s: The standard input isn't a console device.\n",
|
2011-10-10 22:57:48 +08:00
|
|
|
program_invocation_short_name);
|
2006-07-04 00:00:58 +08:00
|
|
|
}
|
|
|
|
|
2011-10-10 22:57:48 +08:00
|
|
|
void
|
|
|
|
print_version ()
|
|
|
|
{
|
|
|
|
printf ("setmetamode (cygwin) %d.%d.%d\n"
|
2011-12-18 07:39:47 +08:00
|
|
|
"Get or set keyboard meta mode\n"
|
2016-05-24 17:16:39 +08:00
|
|
|
"Copyright (C) 2006 - %s Cygwin Authors\n"
|
2011-12-18 07:39:47 +08:00
|
|
|
"This is free software; see the source for copying conditions. There is NO\n"
|
2011-10-10 22:57:48 +08:00
|
|
|
"warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\n",
|
2011-12-18 07:39:47 +08:00
|
|
|
CYGWIN_VERSION_DLL_MAJOR / 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MAJOR % 1000,
|
|
|
|
CYGWIN_VERSION_DLL_MINOR,
|
|
|
|
strrchr (__DATE__, ' ') + 1);
|
2011-10-10 22:57:48 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct option longopts[] = {
|
|
|
|
{"help", no_argument, NULL, 'h'},
|
|
|
|
{"version", no_argument, NULL, 'V'},
|
|
|
|
{0, no_argument, NULL, 0}
|
|
|
|
};
|
|
|
|
const char *opts = "hV";
|
|
|
|
|
2006-07-04 00:00:58 +08:00
|
|
|
int
|
|
|
|
main (int ac, char *av[])
|
|
|
|
{
|
|
|
|
int param;
|
2011-10-10 22:57:48 +08:00
|
|
|
int opt;
|
2006-07-04 00:00:58 +08:00
|
|
|
|
|
|
|
if (ac < 2)
|
|
|
|
{
|
|
|
|
if (ioctl (0, KDGKBMETA, ¶m) < 0)
|
|
|
|
{
|
|
|
|
error ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
if (param == 0x03)
|
|
|
|
puts ("metabit");
|
|
|
|
else
|
|
|
|
puts ("escprefix");
|
|
|
|
return 0;
|
|
|
|
}
|
2011-10-10 22:57:48 +08:00
|
|
|
|
|
|
|
while ((opt = getopt_long (ac, av, opts, longopts, NULL)) != -1)
|
|
|
|
switch (opt)
|
|
|
|
{
|
|
|
|
case 'h':
|
2020-08-07 19:29:43 +08:00
|
|
|
usage (stdout);
|
2011-10-10 22:57:48 +08:00
|
|
|
case 'V':
|
|
|
|
print_version ();
|
|
|
|
return 0;
|
|
|
|
default:
|
|
|
|
fprintf (stderr, "Try `%s --help' for more information.\n",
|
|
|
|
program_invocation_short_name);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2006-07-04 00:00:58 +08:00
|
|
|
if (!strcmp ("meta", av[1]) || !strcmp ("bit", av[1])
|
|
|
|
|| !strcmp ("metabit", av[1]))
|
|
|
|
param = 0x03;
|
|
|
|
else if (!strcmp ("esc", av[1]) || !strcmp ("prefix", av[1])
|
|
|
|
|| !strcmp ("escprefix", av[1]))
|
|
|
|
param = 0x04;
|
|
|
|
else
|
2020-08-07 19:29:43 +08:00
|
|
|
usage (stderr);
|
2006-07-04 00:00:58 +08:00
|
|
|
if (ioctl (0, KDSKBMETA, param) < 0)
|
|
|
|
{
|
|
|
|
error ();
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|