annotate toys/chvt.c @ 233:d4176f3f3835

Zap toys/Config.in and instead create generated/Config.in from contents of toys/*.c. Move relevant info into comment at the top of each toys/*.c. Also convert more of Makefile into a thin wrapper around shell scripts that actually do the work. (Makefile is only still there for the user interface.)
author Rob Landley <rob@landley.net>
date Sat, 19 Jan 2008 17:08:39 -0600
parents 87390c3700c1
children 163498bf547b
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
1 /* vi: set sw=4 ts=4:
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
2 *
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * chvt.c switch virtual terminals
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
4 *
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
5 * Copyright (C) 2008 David Anders <danders@amltd.com>
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
6 *
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
7 * Not in SUSv3.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
8
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
9 config CHVT
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
10 bool "chvt"
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
11 default y
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
12 help
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
13 usage: chvt N
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
14
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
15 Change to virtual terminal number N. (This only works in text mode.)
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
16
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
17 Virtual terminals are the Linux VGA text mode displays, ordinarily
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
18 switched between via alt-F1, alt-F2, etc. Use ctrl-alt-F1 to switch
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
19 from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back.
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
20 */
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
21
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
22 #include "toys.h"
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
23
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 #define VT_ACTIVATE 0x5606
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
25 #define VT_WAITACTIVE 0x5607
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
26
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
27 /* note get_console_fb() will need to be moved into a seperate lib section */
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
28 int get_console_fd()
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
29 {
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
30 int fd;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
31
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
32 fd = open("/dev/console", O_RDWR);
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
33 if (fd >= 0)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 return fd;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
35
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
36 fd = open("/dev/vc/0", O_RDWR);
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 if (fd >= 0)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 return fd;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
39
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
40 fd = open("/dev/tty", O_RDWR);
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
41 if (fd >= 0)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
42 return fd;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
43
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
44 return -1;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
45 }
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
46
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 void chvt_main(void)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
48 {
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
49 int vtnum,fd;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
50
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
51
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
52 if(!*toys.optargs)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
53 return;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
54
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
55 vtnum=atoi(*toys.optargs);
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
56
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
57 fd=get_console_fd();
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
58 if (fd < 0)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
59 return;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
60
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
61 if (ioctl(fd,VT_ACTIVATE,vtnum))
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
62 return;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
63
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
64 if (ioctl(fd,VT_WAITACTIVE,vtnum))
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
65 return;
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
66
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
67 }