]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - 6/usr.sbin/pcvt/cursor/cursor.c
Clone Kip's Xen on stable/6 tree so that I can work on improving FreeBSD/amd64
[FreeBSD/FreeBSD.git] / 6 / usr.sbin / pcvt / cursor / cursor.c
1 /*
2  * Copyright (c) 1992, 1995 Hellmuth Michaelis
3  *
4  * Copyright (c) 1992, 1994 Brian Dunford-Shore
5  *
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *      This product includes software developed by
19  *      Hellmuth Michaelis and Brian Dunford-Shore
20  * 4. The name authors may not be used to endorse or promote products
21  *    derived from this software without specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
24  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33  *
34  */
35
36 static char *id =
37         "@(#)cursor.c, 3.20, Last Edit-Date: [Tue Apr  4 12:27:54 1995]\n$FreeBSD$";
38
39 /*---------------------------------------------------------------------------*
40  *
41  *      history:
42  *
43  *      -hm     adding option -d <device>
44  *
45  *---------------------------------------------------------------------------*/
46
47 #include <stdio.h>
48 #include <err.h>
49 #include <fcntl.h>
50 #include <sys/stat.h>
51 #include <machine/pcvt_ioctl.h>
52 #include <unistd.h>
53 #include <paths.h>
54
55 #define DEFAULTFD 0
56
57 main(argc,argv)
58 int argc;
59 char *argv[];
60 {
61         struct cursorshape cursorshape;
62         int fd;
63         int c;
64         int screen = -1;
65         int start = -1;
66         int end = -1;
67         int dflag = -1;
68         char *device;
69
70         while( (c = getopt(argc, argv, "d:n:s:e:")) != -1)
71         {
72                 switch(c)
73                 {
74                         case 'd':
75                                 device = optarg;
76                                 dflag = 1;
77                                 break;
78
79                         case 'n':
80                                 screen = atoi(optarg);
81                                 break;
82
83                         case 's':
84                                 start = atoi(optarg);
85                                 break;
86
87                         case 'e':
88                                 end = atoi(optarg);
89                                 break;
90
91                         case '?':
92                         default:
93                                 usage();
94                                 break;
95                 }
96         }
97
98         if(start == -1 || end == -1)
99                 usage();
100
101         if(dflag == -1)
102         {
103                 fd = DEFAULTFD;
104         }
105         else if((fd = open(device, O_RDWR)) == -1)
106                 err(1, "ERROR opening %s", device);
107
108         if(screen == -1)
109         {
110                 struct stat stat;
111
112                 if((fstat(fd, &stat)) == -1)
113                         err(1, "ERROR opening %s", device);
114                 screen = minor(stat.st_rdev);
115         }
116
117         cursorshape.start = start;
118         cursorshape.end = end;
119         cursorshape.screen_no = screen;
120
121         if(ioctl(fd, VGACURSOR, &cursorshape) == -1)
122                 err(1, "cursor - ioctl VGACURSOR failed, error");
123         else
124                 exit(0);
125 }
126
127 usage()
128 {
129         fprintf(stderr,"\ncursor - set cursor shape for pcvt video driver\n");
130         fprintf(stderr,"usage: cursor -d [device] -n [no] -s [line] -e [line]\n");
131         fprintf(stderr,"       -d <device>   device to use (%svX), default current\n", _PATH_TTY);
132         fprintf(stderr,"       -n <no>       screen no if specified, else current screen\n");
133         fprintf(stderr,"       -s <line>     start scan line (topmost scan line)\n");
134         fprintf(stderr,"       -e <line>     ending scan line (bottom scan line)\n\n");
135         exit(1);
136 }
137