OSDN Git Service

* utils.sgml (kill): Add SIGIO, SIGCLD, and SIGPWR.
[pf3gnuchains/pf3gnuchains4x.git] / winsup / utils / setmetamode.c
1 /* setmetamode.c
2
3    Copyright 2006 Red Hat Inc.
4
5    Written by Kazuhiro Fujieda <fujieda@jaist.ac.jp>
6
7 This file is part of Cygwin.
8
9 This software is a copyrighted work licensed under the terms of the
10 Cygwin license.  Please consult the file "CYGWIN_LICENSE" for
11 details. */
12
13 #include <stdio.h>
14 #include <string.h>
15 #include <sys/ioctl.h>
16 #include <cygwin/kd.h>
17
18 static const char version[] = "$Revision$";
19 static char *prog_name;
20
21 static void
22 usage (void)
23 {
24   fprintf (stderr, "Usage: %s [metabit|escprefix]\n"
25            "  Without argument, it shows the current meta key mode.\n"
26            "  metabit|meta|bit     The meta key sets the top bit of the character.\n"
27            "  escprefix|esc|prefix The meta key sends an escape prefix.\n",
28            prog_name);
29 }
30
31 static void
32 error (void)
33 {
34   fprintf (stderr,
35            "%s: The standard input isn't a console device.\n",
36            prog_name);
37 }
38
39 int
40 main (int ac, char *av[])
41 {
42   int param;
43
44   prog_name = strrchr (av[0], '/');
45   if (!prog_name)
46     prog_name = strrchr (av[0], '\\');
47   if (!prog_name)
48     prog_name = av[0];
49   else
50     prog_name++;
51
52   if (ac < 2)
53     {
54       if (ioctl (0, KDGKBMETA, &param) < 0)
55         {
56           error ();
57           return 1;
58         }
59       if (param == 0x03)
60         puts ("metabit");
61       else
62         puts ("escprefix");
63       return 0;
64     }
65   if (!strcmp ("meta", av[1]) || !strcmp ("bit", av[1])
66       || !strcmp ("metabit", av[1]))
67     param = 0x03;
68   else if (!strcmp ("esc", av[1]) || !strcmp ("prefix", av[1])
69            || !strcmp ("escprefix", av[1]))
70     param = 0x04;
71   else
72     {
73       usage ();
74       return 1;
75     }
76   if (ioctl (0, KDSKBMETA, param) < 0)
77     {
78       error ();
79       return 1;
80     }
81   return 0;
82 }