Mercurial > hg > toybox
comparison 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 |
comparison
equal
deleted
inserted
replaced
693:4a5a250e0633 | 694:786841fdb1e0 |
---|---|
1 /* vi: set sw=4 ts=4: | 1 /* chvt.c - switch virtual terminals |
2 * | |
3 * chvt.c - switch virtual terminals | |
4 * | 2 * |
5 * Copyright (C) 2008 David Anders <danders@amltd.com> | 3 * Copyright (C) 2008 David Anders <danders@amltd.com> |
6 | 4 |
7 USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_SBIN)) | 5 USE_CHVT(NEWTOY(chvt, "<1", TOYFLAG_USR|TOYFLAG_SBIN)) |
8 | 6 |
9 config CHVT | 7 config CHVT |
10 bool "chvt" | 8 bool "chvt" |
11 default y | 9 default y |
12 help | 10 help |
13 usage: chvt N | 11 usage: chvt N |
14 | 12 |
15 Change to virtual terminal number N. (This only works in text mode.) | 13 Change to virtual terminal number N. (This only works in text mode.) |
16 | 14 |
17 Virtual terminals are the Linux VGA text mode displays, ordinarily | 15 Virtual terminals are the Linux VGA text mode displays, ordinarily |
18 switched between via alt-F1, alt-F2, etc. Use ctrl-alt-F1 to switch | 16 switched between via alt-F1, alt-F2, etc. Use ctrl-alt-F1 to switch |
19 from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back. | 17 from X to a virtual terminal, and alt-F6 (or F7, or F8) to get back. |
20 */ | 18 */ |
21 | 19 |
22 #include "toys.h" | 20 #include "toys.h" |
23 | 21 |
24 /* Note: get_console_fb() will need to be moved into a seperate lib section */ | 22 /* Note: get_console_fb() will need to be moved into a seperate lib section */ |
25 int get_console_fd() | 23 int get_console_fd() |
26 { | 24 { |
27 int fd; | 25 int fd; |
28 char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc; | 26 char *consoles[]={"/dev/console", "/dev/vc/0", "/dev/tty", NULL}, **cc; |
29 | 27 |
30 cc = consoles; | 28 cc = consoles; |
31 while (*cc) { | 29 while (*cc) { |
32 fd = open(*cc++, O_RDWR); | 30 fd = open(*cc++, O_RDWR); |
33 if (fd >= 0) return fd; | 31 if (fd >= 0) return fd; |
34 } | 32 } |
35 | 33 |
36 return -1; | 34 return -1; |
37 } | 35 } |
38 | 36 |
39 void chvt_main(void) | 37 void chvt_main(void) |
40 { | 38 { |
41 int vtnum, fd; | 39 int vtnum, fd; |
42 | 40 |
43 vtnum=atoi(*toys.optargs); | 41 vtnum=atoi(*toys.optargs); |
44 | 42 |
45 fd=get_console_fd(); | 43 fd=get_console_fd(); |
46 // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h | 44 // These numbers are VT_ACTIVATE and VT_WAITACTIVE from linux/vt.h |
47 if (fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum)) | 45 if (fd < 0 || ioctl(fd, 0x5606, vtnum) || ioctl(fd, 0x5607, vtnum)) |
48 perror_exit(NULL); | 46 perror_exit(NULL); |
49 } | 47 } |