1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
|
/*
* Copyright (c) 1992, 1993, 1994 by Hellmuth Michaelis
*
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by Hellmuth Michaelis.
* 4. The name of the developer may not be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* misc.c, 3.00, last edit-date: [Sun Jan 2 20:09:21 1994]
*/
/*---------------------------------------------------------------------------
*
* misc.c font editor misc routines
* -----------------------------------------
*
* written by Hellmuth Michaelis, hm@hcshh.hcs.de
*
* -hm first public release
* -hm writefont routine
*
*---------------------------------------------------------------------------*/
#include "fed.h"
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
static unsigned char *fonttab; /* ptr to font in core memory */
static char *bitmask[] = {
"....", /* 0 */
"...*", /* 1 */
"..*.", /* 2 */
"..**", /* 3 */
".*..", /* 4 */
".*.*", /* 5 */
".**.", /* 6 */
".***", /* 7 */
"*...", /* 8 */
"*..*", /* 9 */
"*.*.", /* A */
"*.**", /* B */
"**..", /* C */
"**.*", /* D */
"***.", /* E */
"****", /* F */
NULL };
static char lfilename[1024]; /* current filename */
static unsigned int lfilesize; /* current filename's size */
/*---------------------------------------------------------------------------*
* read fontfile into memory
*---------------------------------------------------------------------------*/
void readfont(char *filename)
{
FILE *in;
struct stat sbuf, *sbp;
int ret;
char buffer[1024];
sbp = &sbuf;
if((in = fopen(filename, "r")) == NULL)
{
sprintf(buffer, "cannot open file %s for reading", filename);
perror(buffer);
exit(1);
}
if((fstat(fileno(in), sbp)) != 0)
{
sprintf(buffer, "cannot fstat file %s", filename);
perror(buffer);
exit(1);
}
switch(sbp->st_size)
{
case FONT8X8:
ch_height = HEIGHT8X8;
ch_width = WIDTH8;
break;
case FONT8X10:
ch_height = HEIGHT8X10;
ch_width = WIDTH8;
break;
case FONT8X14:
ch_height = HEIGHT8X14;
ch_width = WIDTH8;
break;
case FONT8X16:
ch_height = HEIGHT8X16;
ch_width = WIDTH8;
break;
case FONT16X16:
ch_height = HEIGHT16X16;
ch_width = WIDTH16;
break;
default:
fprintf(stderr,"error, file %s is no valid font file, size=%d\n",filename,sbp->st_size);
exit(1);
}
if((fonttab = (unsigned char *)malloc((size_t)sbp->st_size)) == NULL)
{
fprintf(stderr,"error, malloc failed\n");
exit(1);
}
strcpy(lfilename, filename); /* save for write */
lfilesize = sbp->st_size; /* save for write */
if((ret = fread(fonttab, sizeof(*fonttab), sbp->st_size, in)) != sbp->st_size)
{
sprintf(buffer,"error reading file %s, size = %d, ret = %d\n",filename,sbp->st_size, ret);
perror(buffer);
exit(1);
}
}
/*---------------------------------------------------------------------------*
* write fontfile to disk
*---------------------------------------------------------------------------*/
void writefont()
{
FILE *in, *out;
int ret;
char buffer[1024];
if((in = fopen(lfilename, "r")) != NULL)
{
int c;
char wfn[1024];
strcpy(wfn, lfilename);
strcat(wfn, ".BAK");
if((out = fopen(wfn, "w")) == NULL)
{
sprintf(buffer, "cannot open file %s for writing", wfn);
perror(buffer);
exit(1);
}
while(( c = fgetc(in) ) != EOF )
fputc(c, out);
fclose(out);
fclose(in);
}
if((out = fopen(lfilename, "w")) == NULL)
{
sprintf(buffer, "cannot open file %s for writing", lfilename);
perror(buffer);
exit(1);
}
if((ret = fwrite(fonttab, sizeof(*fonttab), lfilesize, out)) != lfilesize)
{
sprintf(buffer,"error writing file %s, size=%d, ret=%d\n",lfilename,lfilesize, ret);
perror(buffer);
exit(1);
}
}
/*---------------------------------------------------------------------------*
* display a string
*---------------------------------------------------------------------------*/
void dis_cmd(char *strg)
{
move(22,0);
clrtoeol();
mvaddstr(22,0,strg);
refresh();
}
/*---------------------------------------------------------------------------*
* clear a command string
*---------------------------------------------------------------------------*/
void clr_cmd(void)
{
move(22,0);
clrtoeol();
refresh();
}
/*---------------------------------------------------------------------------*
* move char from src to dest
*---------------------------------------------------------------------------*/
void move_ch(int src, int dst)
{
unsigned char *s, *d;
int offset = 0;
if(ch_width == WIDTH16)
offset = 2;
else
offset = 1;
s = &(fonttab[ch_height * offset * src]);
d = &(fonttab[ch_height * offset * dst]);
bcopy(s, d, (ch_height*offset)); /* src -> dst */
}
/*---------------------------------------------------------------------------*
* exchange char's src and dest
*---------------------------------------------------------------------------*/
void xchg_ch(int src, int dst)
{
unsigned char *s, *d;
unsigned char buf[32];
int offset = 0;
if(ch_width == WIDTH16)
offset = 2;
else
offset = 1;
s = &(fonttab[ch_height * offset * src]);
d = &(fonttab[ch_height * offset * dst]);
bcopy(s, buf, (ch_height*offset)); /* src -> tmp */
bcopy(d, s, (ch_height*offset)); /* dst -> src */
bcopy(buf, d, (ch_height*offset)); /* tmp -> dst */
}
/*---------------------------------------------------------------------------*
* display the current selected character
*---------------------------------------------------------------------------*/
void display(int no)
{
unsigned char *fontchar;
char line[32];
int ln_no;
unsigned char hibyte;
unsigned char lobyte;
int offset;
int r;
offset = 0;
r = 1;
lobyte = 0;
if(ch_width == WIDTH16)
fontchar = &(fonttab[ch_height * 2 * no]);
else
fontchar = &(fonttab[ch_height * no]);
for (ln_no = 0; ln_no < ch_height; ln_no++)
{
hibyte = *(fontchar + (offset++));
if(ch_width == WIDTH16)
{
lobyte = *(fontchar + offset++);
}
strcpy(line,bitmask[(int)((hibyte >> 4) & 0x0f)]);
strcat(line,bitmask[(int)(hibyte & 0x0f)]);
if(ch_width == WIDTH16)
{
strcat(line,bitmask[(int)((lobyte >> 4) & 0x0f)]);
strcat(line,bitmask[(int)(lobyte & 0x0f)]);
mvwprintw(ch_win, r, 1, "%16.16s", line);
}
else
{
mvwprintw(ch_win, r, 1, "%8.8s", line);
}
r++;
}
wmove(ch_win, 1, 1);
wrefresh(ch_win);
}
/*---------------------------------------------------------------------------*
* save character
*---------------------------------------------------------------------------*/
void save_ch(void)
{
unsigned char *s;
int offset = 0;
int r, c;
unsigned short byte;
unsigned short shift;
if(ch_width == WIDTH16)
offset = 2;
else
offset = 1;
s = &(fonttab[ch_height * offset * curchar]);
r = 1;
while(r <= ch_height)
{
c = 1;
byte = 0;
if(offset == 2)
shift = 0x8000;
else
shift = 0x80;
while(c <= ch_width)
{
if(mvwinch(ch_win, r, c) == BLACK)
byte |= shift;
shift = (shift >> 1);
c++;
}
*s++ = byte;
r++;
}
}
/*---------------------------------- E O F ----------------------------------*/
|