1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #ifndef lint 14 char copyright[] = 15 "@(#) Copyright (c) 1983 Regents of the University of California.\n\ 16 All rights reserved.\n"; 17 #endif /* not lint */ 18 19 #ifndef lint 20 static char sccsid[] = "@(#)railmag.c 5.2 (Berkeley) 03/08/88"; 21 #endif /* not lint */ 22 23 /* 24 * tell vcat which fonts are loaded on the "typesetter" 25 */ 26 27 #define MAGIC_NUMBER 0436 28 #define RAILMAG_FILE "/usr/lib/vfont/railmag" 29 30 char *concat(); 31 int rmfd; 32 char *rm[4]; 33 char tbuf[256]; 34 35 main(argc, argv) 36 int argc; 37 char *argv[]; 38 { 39 register int fnum; 40 char cbuf[4][50]; 41 42 readrm(); 43 if (argc <= 1) { 44 printrm(); 45 exit(0); 46 } 47 while (--argc) { 48 argv++; 49 fnum = argv[0][0] - '0'; 50 if (fnum < 1 || fnum > 4) 51 error("Invalid font number"); 52 checkfont(argv[1]); 53 if (argv[1][0] == '/') 54 rm[fnum-1] = argv[1]; 55 else 56 rm[fnum-1] = concat(cbuf[fnum-1], "/usr/lib/vfont/", argv[1]); 57 argv++; argc--; 58 } 59 writerm(); 60 } 61 62 error(str) 63 char *str; 64 { 65 write(2, "Railmag: ", 9); 66 write(2, str, strlen(str)); 67 write(2, "\n", 1); 68 exit(); 69 } 70 71 checkfont(file) 72 char *file; 73 { 74 register int fd; 75 char cbuf[80]; 76 char cbuf2[80]; 77 short word; 78 79 if ((fd = open(concat(cbuf, file, ".10"), 0)) < 0) 80 if ((fd = open(concat(cbuf2, "/usr/lib/vfont/", cbuf), 0)) < 0) 81 error("cant open font"); 82 if (read(fd, &word, 2) != 2) 83 error("cant read font"); 84 if (word != MAGIC_NUMBER) 85 error("font has no magic number"); 86 close(fd); 87 } 88 89 readrm() 90 { 91 register int i; 92 register char *cp; 93 char c; 94 95 if ((rmfd = open(RAILMAG_FILE, 0)) < 0) 96 error("No railmag file"); 97 cp = tbuf; 98 for (i = 0; i < 4; i++) { 99 rm[i] = cp; 100 while (read(rmfd, &c, 1) == 1 && c != '\n') 101 *cp++ = c; 102 *cp++ = '\0'; 103 } 104 } 105 106 printrm() 107 { 108 register int i; 109 110 for (i = 0; i < 4; i++) 111 printf("%s on %d\n", rm[i], i+1); 112 } 113 114 writerm() 115 { 116 register int i; 117 register char *cp; 118 119 unlink(RAILMAG_FILE); 120 if ((rmfd = creat(RAILMAG_FILE, 0644)) < 0) 121 error("cant recreate railmag file"); 122 for (i = 0; i < 4; i++) { 123 cp = rm[i]; 124 while (*cp != '\0') 125 write(rmfd, cp++, 1); 126 write(rmfd, "\n", 1); 127 } 128 } 129 130 char * 131 concat(outbuf, in1, in2) 132 register char *outbuf, *in1, *in2; 133 { 134 char *save; 135 136 save = outbuf; 137 while (*in1) 138 *outbuf++ = *in1++; 139 while (*in2) 140 *outbuf++ = *in2++; 141 return(save); 142 } 143