vidcontrol.c (80148) | vidcontrol.c (92460) |
---|---|
1/*- 2 * Copyright (c) 1994-1996 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef lint 30static const char rcsid[] = | 1/*- 2 * Copyright (c) 1994-1996 S�ren Schmidt 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright --- 14 unchanged lines hidden (view full) --- 23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 */ 28 29#ifndef lint 30static const char rcsid[] = |
31 "$FreeBSD: head/usr.sbin/vidcontrol/vidcontrol.c 80148 2001-07-22 13:30:32Z yokota $"; | 31 "$FreeBSD: head/usr.sbin/vidcontrol/vidcontrol.c 92460 2002-03-16 23:35:51Z sobomax $"; |
32#endif /* not lint */ 33 34#include <ctype.h> 35#include <err.h> 36#include <limits.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> --- 45 unchanged lines hidden (view full) --- 85{ 86 if (*indp < ac) 87 return(av[(*indp)++]); 88 if (strict != 0) 89 errx(1, "option requires two arguments -- %c", oc); 90 return(NULL); 91} 92 | 32#endif /* not lint */ 33 34#include <ctype.h> 35#include <err.h> 36#include <limits.h> 37#include <stdio.h> 38#include <stdlib.h> 39#include <string.h> --- 45 unchanged lines hidden (view full) --- 85{ 86 if (*indp < ac) 87 return(av[(*indp)++]); 88 if (strict != 0) 89 errx(1, "option requires two arguments -- %c", oc); 90 return(NULL); 91} 92 |
93char * 94mkfullname(const char *s1, const char *s2, const char *s3) | 93FILE * 94openguess(char *a[], char *b[], char *c[], char *d[], char **name) |
95{ | 95{ |
96 static char *buf = NULL; 97 static int bufl = 0; 98 int f; | 96 FILE *f; 97 int i, j, k, l; |
99 | 98 |
100 f = strlen(s1) + strlen(s2) + strlen(s3) + 1; 101 if (f > bufl) { 102 if (buf) 103 buf = (char *)realloc(buf, f); 104 else 105 buf = (char *)malloc(f); | 99 for (i = 0; a[i] != NULL; i++) { 100 for (j = 0; b[j] != NULL; j++) { 101 for (k = 0; c[k] != NULL; k++) { 102 for (l = 0; d[l] != NULL; l++) { 103 asprintf(name, "%s%s%s%s", a[i], b[j], 104 c[k], d[l]); 105 f = fopen(*name, "r"); 106 if (f != NULL) 107 return (f); 108 free(*name); 109 } 110 } 111 } |
106 } | 112 } |
107 if (!buf) { 108 bufl = 0; 109 return(NULL); 110 } 111 112 bufl = f; 113 strcpy(buf, s1); 114 strcat(buf, s2); 115 strcat(buf, s3); 116 return(buf); | 113 return (NULL); |
117} 118 119void 120load_scrnmap(char *filename) 121{ | 114} 115 116void 117load_scrnmap(char *filename) 118{ |
122 FILE *fd = 0; 123 int i, size; | 119 FILE *fd; 120 int size; |
124 char *name; 125 scrmap_t scrnmap; | 121 char *name; 122 scrmap_t scrnmap; |
126 char *prefix[] = {"", "", SCRNMAP_PATH, SCRNMAP_PATH, NULL}; 127 char *postfix[] = {"", ".scm", "", ".scm"}; | 123 char *a[] = {"", SCRNMAP_PATH, NULL}; 124 char *b[] = {filename, NULL}; 125 char *c[] = {"", ".scm", NULL}; 126 char *d[] = {"", NULL}; |
128 | 127 |
129 for (i=0; prefix[i]; i++) { 130 name = mkfullname(prefix[i], filename, postfix[i]); 131 fd = fopen(name, "r"); 132 if (fd) 133 break; 134 } | 128 fd = openguess(a, b, c, d, &name); |
135 if (fd == NULL) { 136 warn("screenmap file not found"); 137 return; 138 } 139 size = sizeof(scrnmap); 140 if (decode(fd, (char *)&scrnmap, size) != size) { 141 rewind(fd); 142 if (fread(&scrnmap, 1, size, fd) != size) { --- 52 unchanged lines hidden (view full) --- 195 return -1; 196} 197 198#define DATASIZE(x) ((x).w * (x).h * 256 / 8) 199 200void 201load_font(char *type, char *filename) 202{ | 129 if (fd == NULL) { 130 warn("screenmap file not found"); 131 return; 132 } 133 size = sizeof(scrnmap); 134 if (decode(fd, (char *)&scrnmap, size) != size) { 135 rewind(fd); 136 if (fread(&scrnmap, 1, size, fd) != size) { --- 52 unchanged lines hidden (view full) --- 189 return -1; 190} 191 192#define DATASIZE(x) ((x).w * (x).h * 256 / 8) 193 194void 195load_font(char *type, char *filename) 196{ |
203 FILE *fd = NULL; | 197 FILE *fd; |
204 int h, i, size, w; 205 unsigned long io = 0; /* silence stupid gcc(1) in the Wall mode */ | 198 int h, i, size, w; 199 unsigned long io = 0; /* silence stupid gcc(1) in the Wall mode */ |
206 char *name, *fontmap; 207 char *prefix[] = {"", "", FONT_PATH, FONT_PATH, NULL}; 208 char *postfix[] = {"", ".fnt", "", ".fnt"}; | 200 char *name, *fontmap, size_sufx[6]; 201 char *a[] = {"", FONT_PATH, NULL}; 202 char *b[] = {filename, NULL}; 203 char *c[] = {"", size_sufx, NULL}; 204 char *d[] = {"", ".fnt", NULL}; 205 vid_info_t info; |
209 210 struct sizeinfo { 211 int w; 212 int h; 213 unsigned long io; 214 } sizes[] = {{8, 16, PIO_FONT8x16}, 215 {8, 14, PIO_FONT8x14}, 216 {8, 8, PIO_FONT8x8}, 217 {0, 0, 0}}; 218 | 206 207 struct sizeinfo { 208 int w; 209 int h; 210 unsigned long io; 211 } sizes[] = {{8, 16, PIO_FONT8x16}, 212 {8, 14, PIO_FONT8x14}, 213 {8, 8, PIO_FONT8x8}, 214 {0, 0, 0}}; 215 |
219 for (i=0; prefix[i]; i++) { 220 name = mkfullname(prefix[i], filename, postfix[i]); 221 fd = fopen(name, "r"); 222 if (fd) 223 break; | 216 info.size = sizeof(info); 217 if (ioctl(0, CONS_GETINFO, &info) == -1) { 218 warn("failed to obtain current video mode parameters"); 219 return; |
224 } | 220 } |
221 snprintf(size_sufx, sizeof(size_sufx), "-8x%d", info.font_size); 222 fd = openguess(a, b, c, d, &name); |
|
225 if (fd == NULL) { 226 warn("%s: can't load font file", filename); 227 return; 228 } 229 if (type != NULL) { 230 size = 0; 231 if (sscanf(type, "%dx%d", &w, &h) == 2) 232 for (i = 0; sizes[i].w != 0; i++) --- 601 unchanged lines hidden --- | 223 if (fd == NULL) { 224 warn("%s: can't load font file", filename); 225 return; 226 } 227 if (type != NULL) { 228 size = 0; 229 if (sscanf(type, "%dx%d", &w, &h) == 2) 230 for (i = 0; sizes[i].w != 0; i++) --- 601 unchanged lines hidden --- |