1 /*	doublech.c	(Berkeley)	1.1	85/02/04
2  *
3  * Double size of fonts in character format.
4  *
5  *	Use:	doublech [ charfile1 ] > charfile2
6  *
7  *		Takes input from charfile1 (which must be in the format
8  *	written by one of the xxx2ch programs), scales by 2 and writes to
9  *	stdout.  If charfile1 is missing, stdin is read.
10  */
11 
12 #include <stdio.h>
13 
14 
15 #define MAXLINE		1024
16 
17 
18 int	width, length, code;
19 
20 FILE *	filep;
21 char	ibuff[MAXLINE];
22 char	ebuff[MAXLINE];
23 
24 
25 main(argc,argv)
26 int argc;
27 char **argv;
28 {
29     register int i;
30     register int j;
31     register char *chp;
32     float par;
33 
34     while (argc > 1 && argv[1][0] == '-') {
35 	switch(argv[1][1]) {
36 	default:
37 		error("%s, unknown option flag", argv[1]);
38 	}
39 	argc--; argv++;
40     }
41 
42     if (argc == 2) {
43 	if ((filep = fopen (argv[1], "r")) == NULL)
44 	    error("can't open file \"%s\"", argv[1]);
45     } else filep = stdin;
46 
47     fgets(ibuff, MAXLINE, filep);
48     if (strcmp(ibuff, "fontheader\n"))
49 	error("not a character font file");
50     printf("fontheader\n");
51 
52     while (fgets(ibuff, MAXLINE, filep) != NULL) {
53 	if (index(ibuff, '\n') == 0)
54 	    error("input line too long");
55 
56 	if (ibuff[0] != ':') {
57 	    sscanf (ibuff, "%s %f", ebuff, &par);
58 	    if (strcmp(ebuff, "mag") == 0)
59 		printf("mag %d\n", (int) (par * 2.0 + 0.1));
60 	    else if (strcmp(ebuff, "linesp") == 0)
61 		printf("linesp %.2f\n", par * 2.0 + 0.001);
62 	    else if (strcmp(ebuff, "wordsp") == 0)
63 		printf("wordsp %.2f\n", par * 2.0 + 0.001);
64 	    else
65 		printf("%s", ibuff);
66 	} else {
67 	    if (sscanf (ibuff, ":%d, width = %f", &code, &par) != 2)
68 		error("bad glyph header, %s", ibuff);
69 	    printf(":%d, width = %.2f\n", code, par * 2.0);
70 
71 	    if (fgets(ibuff, MAXLINE, filep) == NULL)
72 		error("unexpected end of input");
73 	    width = strlen(ibuff) - 1;
74 
75 	    for (length = 0; *(chp = ibuff) != '\n'; length++) {
76 		for (j = 0; j < width; j++, chp++) {
77 		    switch (*chp) {
78 			case '.':
79 			case 'x':
80 			case 'X':
81 			case '@':
82 				break;
83 			case 'a':
84 			case 'M':
85 			case '*':
86 				*chp = '@';
87 				break;
88 			default:
89 				error("illegal character '%c' in map.", *chp);
90 		    } /* switch */
91 		} /* for j */
92 							/* 1st line of double */
93 		for (chp = ibuff; *chp != '\n'; chp++) {
94 		    if (*chp == 'x') {	/* ignore reference points */
95 			putchar('.');
96 			putchar('.');
97 		    } else if (*chp == 'X') {
98 			putchar('@');
99 			putchar('@');
100 		    } else {
101 			putchar(*chp);
102 			putchar(*chp);
103 		    }
104 		}
105 		putchar('\n');			/* 2nd line of double */
106 		for (chp = ibuff; *chp != '\n'; chp++) {
107 		    if (*chp == 'x') {
108 			putchar('x');		/* reference points go only */
109 			putchar('.');		/*   on lower left of quad */
110 		    } else if (*chp == 'X') {
111 			putchar('X');
112 			putchar('@');
113 		    } else {
114 			putchar(*chp);
115 			putchar(*chp);
116 		    }
117 		}
118 		putchar('\n');
119 		if (fgets(ibuff, MAXLINE, filep) == NULL)
120 			error("unexpected end of input");
121 	    } /* for length */
122 	    putchar('\n');
123 	} /* else */
124     } /* while */
125     exit(0);
126 }
127 
128 
129 /*----------------------------------------------------------------------------*
130  | Routine:	error (format_string, argument1, argument2.... )
131  |
132  | Results:	fprints a message to standard error, then exits with error
133  |		code 1
134  |
135  | Side Efct:	This routine does NOT return
136  *----------------------------------------------------------------------------*/
137 
138 /*VARARGS1*/
139 error(string, a1, a2, a3, a4)
140 char *string;
141 {
142 	fprintf(stderr, "doublech: ");
143 	fprintf(stderr, string, a1, a2, a3, a4);
144 	fprintf(stderr, "\n");
145 	exit(1);
146 }
147