aboutsummaryrefslogtreecommitdiff
path: root/winsup/utils/setmetamode.c
blob: 65bd02b78ab664c723c2d446f88046f734556e55 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/* setmetamode.c

   Copyright 2006 Red Hat Inc.

   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. */

#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <cygwin/kd.h>

static const char version[] = "$Revision$";
static char *prog_name;

static void
usage (void)
{
  fprintf (stderr, "Usage: %s [metabit|escprefix]\n"
	   "  Without argument, it shows the current meta key mode.\n"
	   "  metabit|meta|bit     The meta key sets the top bit of the character.\n"
	   "  escprefix|esc|prefix The meta key sends an escape prefix.\n",
	   prog_name);
}

static void
error (void)
{
  fprintf (stderr,
	   "%s: The standard input isn't a console device.\n",
	   prog_name);
}

int
main (int ac, char *av[])
{
  int param;

  prog_name = strrchr (av[0], '/');
  if (!prog_name)
    prog_name = strrchr (av[0], '\\');
  if (!prog_name)
    prog_name = av[0];
  else
    prog_name++;

  if (ac < 2)
    {
      if (ioctl (0, KDGKBMETA, &param) < 0)
	{
	  error ();
	  return 1;
	}
      if (param == 0x03)
	puts ("metabit");
      else
	puts ("escprefix");
      return 0;
    }
  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
    {
      usage ();
      return 1;
    }
  if (ioctl (0, KDSKBMETA, param) < 0)
    {
      error ();
      return 1;
    }
  return 0;
}