]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - usr.sbin/pcvt/cursor/cursor.c
This commit was generated by cvs2svn to compensate for changes in r56944,
[FreeBSD/FreeBSD.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  */
35
36 static char *id =
37         "@(#)cursor.c, 3.20, Last Edit-Date: [Tue Apr  4 12:27:54 1995]";
38
39 /*---------------------------------------------------------------------------*
40  *
41  *      history:
42  *
43  *      -hm     adding option -d <device>
44  *
45  *---------------------------------------------------------------------------*/
46
47 #include <stdio.h>
48 #include <fcntl.h>
49 #include <sys/stat.h>
50 #include <machine/pcvt_ioctl.h>
51
52 #define DEFAULTFD 0
53
54 main(argc,argv)
55 int argc;
56 char *argv[];
57 {
58         extern int optind;
59         extern int opterr;
60         extern char *optarg;
61
62         struct cursorshape cursorshape;
63         int fd;
64         int c;
65         int screen = -1;
66         int start = -1;
67         int end = -1;
68         int dflag = -1;
69         char *device;
70
71         while( (c = getopt(argc, argv, "d:n:s:e:")) != -1)
72         {
73                 switch(c)
74                 {
75                         case 'd':
76                                 device = optarg;
77                                 dflag = 1;
78                                 break;
79
80                         case 'n':
81                                 screen = atoi(optarg);
82                                 break;
83
84                         case 's':
85                                 start = atoi(optarg);
86                                 break;
87
88                         case 'e':
89                                 end = atoi(optarg);
90                                 break;
91
92                         case '?':
93                         default:
94                                 usage();
95                                 break;
96                 }
97         }
98
99         if(start == -1 || end == -1)
100                 usage();
101
102         if(dflag == -1)
103         {
104                 fd = DEFAULTFD;
105         }
106         else
107         {
108                 if((fd = open(device, O_RDWR)) == -1)
109                 {
110                         char buffer[80];
111                         strcpy(buffer,"ERROR opening ");
112                         strcat(buffer,device);
113                         perror(buffer);
114                         exit(1);
115                 }
116         }
117
118         if(screen == -1)
119         {
120                 struct stat stat;
121
122                 if((fstat(fd, &stat)) == -1)
123                 {
124                         char buffer[80];
125                         strcpy(buffer,"ERROR opening ");
126                         strcat(buffer,device);
127                         perror(buffer);
128                         exit(1);
129                 }
130
131                 screen = minor(stat.st_rdev);
132         }
133
134         cursorshape.start = start;
135         cursorshape.end = end;
136         cursorshape.screen_no = screen;
137
138         if(ioctl(fd, VGACURSOR, &cursorshape) == -1)
139         {
140                 perror("cursor - ioctl VGACURSOR failed, error");
141                 exit(1);
142         }
143         else
144                 exit(0);
145 }
146
147 usage()
148 {
149         fprintf(stderr,"\ncursor - set cursor shape for pcvt video driver\n");
150         fprintf(stderr,"usage: cursor -d [device] -n [no] -s [line] -e [line]\n");
151         fprintf(stderr,"       -d <device>   device to use (/dev/ttyvX), default current\n");
152         fprintf(stderr,"       -n <no>       screen no if specified, else current screen\n");
153         fprintf(stderr,"       -s <line>     start scan line (topmost scan line)\n");
154         fprintf(stderr,"       -e <line>     ending scan line (bottom scan line)\n\n");
155         exit(1);
156 }
157