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