annotate toys/other/chvt.c @ 1085:bfe79fc710da draft

Cleanup chvt
author Rob Landley <rob@landley.net>
date Tue, 08 Oct 2013 15:58:08 -0500
parents 786841fdb1e0
children 8b62561ce52a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
1 /* chvt.c - switch virtual terminals
244
e6273440c9c0 Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents: 234
diff changeset
2 *
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
3 * Copyright (C) 2008 David Anders <danders@amltd.com>
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
4
234
163498bf547b Move NEWTOY() list from end of toylist.h to generated/newtoys.h.
Rob Landley <rob@landley.net>
parents: 233
diff changeset
5 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
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 config CHVT
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
8 bool "chvt"
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
9 default y
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
10 help
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
11 usage: chvt N
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
12
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
13 Change to virtual terminal number N. (This only works in text mode.)
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
14
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
15 Virtual terminals are the Linux VGA text mode displays, ordinarily
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
16 switched between via alt-F1, alt-F2, etc. Use ctrl-alt-F1 to switch
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
17 from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back.
233
d4176f3f3835 Zap toys/Config.in and instead create generated/Config.in from contents of
Rob Landley <rob@landley.net>
parents: 229
diff changeset
18 */
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
19
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
20 #include "toys.h"
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 void chvt_main(void)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 {
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
24 int vtnum, fd;
1085
bfe79fc710da Cleanup chvt
Rob Landley <rob@landley.net>
parents: 694
diff changeset
25 char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc;
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
26
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
27 vtnum=atoi(*toys.optargs);
1085
bfe79fc710da Cleanup chvt
Rob Landley <rob@landley.net>
parents: 694
diff changeset
28 for (cc = consoles; *cc; cc++)
bfe79fc710da Cleanup chvt
Rob Landley <rob@landley.net>
parents: 694
diff changeset
29 if (-1 != (fd = open(*cc, O_RDWR))) break;
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
30
694
786841fdb1e0 Reindent to two spaces per level. Remove vi: directives that haven't worked right in years (ubuntu broke its' vim implementation). Remove trailing spaces. Add/remove blank lines. Re-wordwrap in places. Update documentation with new coding style.
Rob Landley <rob@landley.net>
parents: 656
diff changeset
31 // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h
1085
bfe79fc710da Cleanup chvt
Rob Landley <rob@landley.net>
parents: 694
diff changeset
32 if (!*cc || fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum))
bfe79fc710da Cleanup chvt
Rob Landley <rob@landley.net>
parents: 694
diff changeset
33 perror_exit(0);
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
34 }