Mercurial > hg > toybox
annotate toys/chvt.c @ 244:e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
author | Rob Landley <rob@landley.net> |
---|---|
date | Sat, 26 Jan 2008 23:18:08 -0600 |
parents | 163498bf547b |
children | d9ea4ca7ae8c |
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 * |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
3 * chvt.c - switch virtual terminals |
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
4 * |
229 | 5 * Copyright (C) 2008 David Anders <danders@amltd.com> |
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 |
234
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
9 USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_SBIN)) |
163498bf547b
Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents:
233
diff
changeset
|
10 |
233
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
11 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
|
12 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
|
13 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
|
14 help |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
15 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
|
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 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
|
18 |
d4176f3f3835
Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents:
229
diff
changeset
|
19 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
|
20 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
|
21 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
|
22 */ |
229 | 23 |
24 #include "toys.h" | |
25 | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
26 #define VT_ACTIVATE 0x5606 |
229 | 27 #define VT_WAITACTIVE 0x5607 |
28 | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
29 /* Note: get_console_fb() will need to be moved into a seperate lib section */ |
229 | 30 int get_console_fd() |
31 { | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
32 int fd; |
229 | 33 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
34 fd = open("/dev/console", O_RDWR); |
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
35 if (fd >= 0) return fd; |
229 | 36 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
37 fd = open("/dev/vc/0", O_RDWR); |
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
38 if (fd >= 0) return fd; |
229 | 39 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
40 fd = open("/dev/tty", O_RDWR); |
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
41 if (fd >= 0) return fd; |
229 | 42 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
43 return -1; |
229 | 44 } |
45 | |
46 void chvt_main(void) | |
47 { | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
48 int vtnum, fd; |
229 | 49 |
50 | |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
51 if(!*toys.optargs) return; |
229 | 52 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
53 vtnum=atoi(*toys.optargs); |
229 | 54 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
55 fd=get_console_fd(); |
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
56 if (fd < 0) return; |
229 | 57 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
58 if (ioctl(fd,VT_ACTIVATE,vtnum)) return; |
229 | 59 |
244
e6273440c9c0
Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents:
234
diff
changeset
|
60 if (ioctl(fd,VT_WAITACTIVE,vtnum)) return; |
229 | 61 } |