Style(9) cleanup.
[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.3 2004/03/24 17:46:22 cpressey Exp $
37  */
38
39 /*---------------------------------------------------------------------------*
40  *
41  *      history:
42  *
43  *      -hm     adding option -d <device>
44  *
45  *---------------------------------------------------------------------------*/
46
47 #include <sys/stat.h>
48 #include <machine/pcvt_ioctl.h>
49
50 #include <stdio.h>
51 #include <err.h>
52 #include <fcntl.h>
53 #include <paths.h>
54
55 static void usage(void);
56
57 #define DEFAULTFD 0
58
59 main(int argc, char **argv)
60 {
61         extern int optind;
62         extern int opterr;
63         extern char *optarg;
64
65         struct cursorshape cursorshape;
66         int fd;
67         int c;
68         int screen = -1;
69         int start = -1;
70         int end = -1;
71         int dflag = -1;
72         char *device;
73
74         while( (c = getopt(argc, argv, "d:n:s:e:")) != -1)
75         {
76                 switch(c)
77                 {
78                         case 'd':
79                                 device = optarg;
80                                 dflag = 1;
81                                 break;
82
83                         case 'n':
84                                 screen = atoi(optarg);
85                                 break;
86
87                         case 's':
88                                 start = atoi(optarg);
89                                 break;
90
91                         case 'e':
92                                 end = atoi(optarg);
93                                 break;
94
95                         case '?':
96                         default:
97                                 usage();
98                                 break;
99                 }
100         }
101
102         if(start == -1 || end == -1)
103                 usage();
104
105         if(dflag == -1)
106         {
107                 fd = DEFAULTFD;
108         }
109         else if((fd = open(device, O_RDWR)) == -1)
110                 err(1, "ERROR opening %s", device);
111
112         if(screen == -1)
113         {
114                 struct stat stat;
115
116                 if((fstat(fd, &stat)) == -1)
117                         err(1, "ERROR opening %s", device);
118                 screen = minor(stat.st_rdev);
119         }
120
121         cursorshape.start = start;
122         cursorshape.end = end;
123         cursorshape.screen_no = screen;
124
125         if(ioctl(fd, VGACURSOR, &cursorshape) == -1)
126                 err(1, "cursor - ioctl VGACURSOR failed, error");
127         else
128                 exit(0);
129 }
130
131 void
132 usage(void)
133 {
134         fprintf(stderr,"\ncursor - set cursor shape for pcvt video driver\n");
135         fprintf(stderr,"usage: cursor -d [device] -n [no] -s [line] -e [line]\n");
136         fprintf(stderr,"       -d <device>   device to use (%svX), default current\n", _PATH_TTY);
137         fprintf(stderr,"       -n <no>       screen no if specified, else current screen\n");
138         fprintf(stderr,"       -s <line>     start scan line (topmost scan line)\n");
139         fprintf(stderr,"       -e <line>     ending scan line (bottom scan line)\n\n");
140         exit(1);
141 }
142