|
|
1.1 root 1: /*%cc -go # %
2: * Tom Duff, U of Toronto 1976, BTL 1984
3: */
4: #include <stdio.h>
5: int blankcount;
6: /*
7: * Simulated <jerq.h>, <font.h>
8: * The jerq font format is not very portable. Neither is this code.
9: */
10: struct font{
11: short n;
12: char height, ascent;
13: long unused;
14: }head;
15: struct fontchar{
16: short x;
17: unsigned char top, bottom;
18: char left;
19: unsigned char width;
20: short slack;
21: }info[257];
22: int width;
23: int *bits;
24: getfont(fname)
25: char *fname;
26: {
27: register font, size, i, j, v;
28: char *malloc();
29: if((font=open(fname, 0))<0){
30: chdir("/usr/jerq/font");
31: if((font=open(fname,0))<0)
32: err("Font open error");
33: }
34: read(font, &head, sizeof head);
35: head.n=((head.n&255)<<8)|((head.n>>8)&255);
36: if(head.n>256)
37: err("Font too big");
38: read(font, info, sizeof info[0]*(head.n+1));
39: for(i=0;i<=head.n;i++)
40: info[i].x=((info[i].x&255)<<8)|((info[i].x>>8)&255);
41: width=(info[head.n].x+31)/32;
42: size=width*head.height*sizeof(int);
43: if((bits=(int *)malloc(size))==NULL)
44: err("Can't alloc");
45: if(read(font, bits, size)!=size)
46: err("Bad font");
47: size/=sizeof(int);
48: for(i=0;i!=size;i++){
49: v=0;
50: for(j=0;j!=4;j++){
51: v=(v<<8)|(bits[i]&255);
52: bits[i]>>=8;
53: }
54: bits[i]=v;
55: }
56: close(font);
57: }
58: main(argc, argv)
59: char *argv[];
60: {
61: register i;
62: register char *k;
63: char buf[BUFSIZ];
64: --argc;
65: argv++;
66: if(argc>1 && **argv=='-'){
67: getfont(*argv+1);
68: --argc;
69: argv++;
70: }
71: else
72: getfont("tiny");
73: setbuf(stdout, buf);
74: while(argc){
75: for(i=0;i!=head.height;i++){
76: for(k = *argv;*k;k++)
77: scanchar(*k, i);
78: blankcount=0;
79: putchar('\n');
80: }
81: if(--argc!=0)
82: putchar('\n');
83: argv++;
84: }
85: exit(0);
86: }
87: scanchar(c, line){
88: register char *bitp;
89: register i;
90: register x=info[c].x;
91: register dx=info[c+1].x-x;
92: register w=info[c].width;
93: register l=info[c].left;
94: for(i=0;i!=w;i++){
95: if(i<l || dx+l<=i)
96: blankcount++;
97: else if(fontbit(x+i-l, line)){
98: while(blankcount){
99: putchar(' ');
100: --blankcount;
101: }
102: putchar('#');
103: }
104: else
105: blankcount++;
106: }
107: }
108: fontbit(x, y){
109: return(bits[y*width+x/32]&(1<<(31-(x&31))));
110: }
111: err(m){
112: fprintf(stderr, "%s.\n", m);
113: exit(1);
114: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.