Merge from vendor branch BINUTILS:
[dragonfly.git] / 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  * @(#)cursor.c, 3.20, Last Edit-Date: [Tue Apr  4 12:27:54 1995]
35  * $FreeBSD: src/usr.sbin/pcvt/cursor/cursor.c,v 1.7.6.2 2001/05/12 10:11:41 kris Exp $
36  * $DragonFly: src/usr.sbin/pcvt/cursor/Attic/cursor.c,v 1.2 2003/06/17 04:29:59 dillon Exp $
37  */
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 <paths.h>
53
54 #define DEFAULTFD 0
55
56 main(argc,argv)
57 int argc;
58 char *argv[];
59 {
60         extern int optind;
61         extern int opterr;
62         extern char *optarg;
63
64         struct cursorshape cursorshape;
65         int fd;
66         int c;
67         int screen = -1;
68         int start = -1;
69         int end = -1;
70         int dflag = -1;
71         char *device;
72
73         while( (c = getopt(argc, argv, "d:n:s:e:")) != -1)
74         {
75                 switch(c)
76                 {
77                         case 'd':
78                                 device = optarg;
79                                 dflag = 1;
80                                 break;
81
82                         case 'n':
83                                 screen = atoi(optarg);
84                                 break;
85
86                         case 's':
87                                 start = atoi(optarg);
88                                 break;
89
90                         case 'e':
91                                 end = atoi(optarg);
92                                 break;
93
94                         case '?':
95                         default:
96                                 usage();
97                                 break;
98                 }
99         }
100
101         if(start == -1 || end == -1)
102                 usage();
103
104         if(dflag == -1)
105         {
106                 fd = DEFAULTFD;
107         }
108         else if((fd = open(device, O_RDWR)) == -1)
109                 err(1, "ERROR opening %s", device);
110
111         if(screen == -1)
112         {
113                 struct stat stat;
114
115                 if((fstat(fd, &stat)) == -1)
116                         err(1, "ERROR opening %s", device);
117                 screen = minor(stat.st_rdev);
118         }
119
120         cursorshape.start = start;
121         cursorshape.end = end;
122         cursorshape.screen_no = screen;
123
124         if(ioctl(fd, VGACURSOR, &cursorshape) == -1)
125                 err(1, "cursor - ioctl VGACURSOR failed, error");
126         else
127                 exit(0);
128 }
129
130 usage()
131 {
132         fprintf(stderr,"\ncursor - set cursor shape for pcvt video driver\n");
133         fprintf(stderr,"usage: cursor -d [device] -n [no] -s [line] -e [line]\n");
134         fprintf(stderr,"       -d <device>   device to use (%svX), default current\n", _PATH_TTY);
135         fprintf(stderr,"       -n <no>       screen no if specified, else current screen\n");
136         fprintf(stderr,"       -s <line>     start scan line (topmost scan line)\n");
137         fprintf(stderr,"       -e <line>     ending scan line (bottom scan line)\n\n");
138         exit(1);
139 }
140