annotate toys/other/chvt.c @ 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. The actual code should be the same afterward, this is just cosmetic refactoring.
author Rob Landley <rob@landley.net>
date Tue, 13 Nov 2012 17:14:08 -0600
parents 6df4ccc0acbe
children bfe79fc710da
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
244
e6273440c9c0 Comment and whitespace cleanups by Charlie Shepherd (code's the same).
Rob Landley <rob@landley.net>
parents: 234
diff changeset
22 /* Note: get_console_fb() will need to be moved into a seperate lib section */
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
23 int get_console_fd()
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
24 {
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
25 int fd;
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
26 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
27
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
28 cc = consoles;
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
29 while (*cc) {
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
30 fd = open(*cc++, O_RDWR);
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 if (fd >= 0) return fd;
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
32 }
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
33
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
34 return -1;
229
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
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
37 void chvt_main(void)
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
38 {
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
39 int vtnum, fd;
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
40
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
41 vtnum=atoi(*toys.optargs);
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
42
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
43 fd=get_console_fd();
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
44 // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h
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
45 if (fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum))
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
46 perror_exit(NULL);
229
87390c3700c1 Add chvt from David Anders.
Rob Landley <rob@landley.net>
parents:
diff changeset
47 }