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