Add pancyrillic font
[platform/upstream/kbd.git] / src / deallocvt.c
1 /*
2  * disalloc.c - aeb - 940501 - Disallocate virtual terminal(s)
3  * Renamed deallocvt.
4  */
5 #include <stdio.h>
6 #include <stdlib.h>
7 #include <fcntl.h>
8 #include <ctype.h>
9 #include <sys/types.h>
10 #include <sys/ioctl.h>
11 #include <linux/vt.h>
12 #include "getfd.h"
13 #include "nls.h"
14 #include "version.h"
15
16 int
17 main(int argc, char *argv[]) {
18         int fd, num, i;
19
20         if (argc < 1)           /* unlikely */
21                 exit(1);
22         set_progname(argv[0]);
23
24         setlocale(LC_ALL, "");
25         bindtextdomain(PACKAGE_NAME, LOCALEDIR);
26         textdomain(PACKAGE_NAME);
27
28         if (argc == 2 && !strcmp(argv[1], "-V"))
29                 print_version_and_exit();
30
31         for (i = 1; i < argc; i++) {
32                 if (!isdigit(argv[i][0])) {
33                         fprintf(stderr, _("%s: unknown option\n"), progname);
34                         exit(1);
35                 }
36         }
37
38         fd = getfd(NULL);
39
40         if (argc == 1) {
41                 /* deallocate all unused consoles */
42                 if (ioctl(fd,VT_DISALLOCATE,0)) {
43                         perror("VT_DISALLOCATE");
44                         fprintf(stderr,
45                                 _("%s: deallocating all unused consoles failed\n"),
46                                 progname);
47                         exit(1);
48                 }
49         } else for (i = 1; i < argc; i++) {
50                 num = atoi(argv[i]);
51                 if (num == 0) {
52                         fprintf(stderr,
53                                 _("%s: 0: illegal VT number\n"), progname);
54                         exit(1);
55                 } else if (num == 1) {
56                         fprintf(stderr,
57                                 _("%s: VT 1 is the console and cannot be deallocated\n"),
58                                 progname);
59                         exit(1);
60                 } else if (ioctl(fd,VT_DISALLOCATE,num)) {
61                         perror("VT_DISALLOCATE");
62                         fprintf(stderr,
63                                 _("%s: could not deallocate console %d\n"),
64                                 progname, num);
65                         exit(1);
66                 }
67         }
68         exit(0);
69 }