2 * Copyright (c) 1992, 1993, 1994 by Hellmuth Michaelis
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. All advertising materials mentioning features or use of this software
15 * must display the following acknowledgement:
16 * This product includes software developed by Hellmuth Michaelis.
17 * 4. The name of the developer may not be used to endorse or promote
18 * products derived from this software without specific prior written
21 * THIS SOFTWARE IS PROVIDED BY THE DEVELOPER ``AS IS'' AND ANY EXPRESS OR
22 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 * IN NO EVENT SHALL THE DEVELOPERS BE LIABLE FOR ANY DIRECT, INDIRECT,
25 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32 * misc.c, 3.00, last edit-date: [Sun Jan 2 20:09:21 1994]
35 /*---------------------------------------------------------------------------
37 * misc.c font editor misc routines
38 * -----------------------------------------
40 * written by Hellmuth Michaelis, hm@hcshh.hcs.de
42 * -hm first public release
43 * -hm writefont routine
45 *---------------------------------------------------------------------------*/
51 #include <sys/types.h>
54 static unsigned char *fonttab; /* ptr to font in core memory */
56 static char *bitmask[] = {
75 static char lfilename[1024]; /* current filename */
76 static unsigned int lfilesize; /* current filename's size */
78 /*---------------------------------------------------------------------------*
79 * read fontfile into memory
80 *---------------------------------------------------------------------------*/
81 void readfont(char *filename)
84 struct stat sbuf, *sbp;
90 if((in = fopen(filename, "r")) == NULL)
92 sprintf(buffer, "cannot open file %s for reading", filename);
97 if((fstat(fileno(in), sbp)) != 0)
99 sprintf(buffer, "cannot fstat file %s", filename);
107 ch_height = HEIGHT8X8;
112 ch_height = HEIGHT8X10;
117 ch_height = HEIGHT8X14;
122 ch_height = HEIGHT8X16;
127 ch_height = HEIGHT16X16;
132 fprintf(stderr,"error, file %s is no valid font file, size=%d\n",filename,sbp->st_size);
136 if((fonttab = (unsigned char *)malloc((size_t)sbp->st_size)) == NULL)
138 fprintf(stderr,"error, malloc failed\n");
142 strcpy(lfilename, filename); /* save for write */
143 lfilesize = sbp->st_size; /* save for write */
145 if((ret = fread(fonttab, sizeof(*fonttab), sbp->st_size, in)) != sbp->st_size)
147 sprintf(buffer,"error reading file %s, size = %d, ret = %d\n",filename,sbp->st_size, ret);
153 /*---------------------------------------------------------------------------*
154 * write fontfile to disk
155 *---------------------------------------------------------------------------*/
162 if((in = fopen(lfilename, "r")) != NULL)
167 strcpy(wfn, lfilename);
169 if((out = fopen(wfn, "w")) == NULL)
171 sprintf(buffer, "cannot open file %s for writing", wfn);
176 while(( c = fgetc(in) ) != EOF )
183 if((out = fopen(lfilename, "w")) == NULL)
185 sprintf(buffer, "cannot open file %s for writing", lfilename);
190 if((ret = fwrite(fonttab, sizeof(*fonttab), lfilesize, out)) != lfilesize)
192 sprintf(buffer,"error writing file %s, size=%d, ret=%d\n",lfilename,lfilesize, ret);
198 /*---------------------------------------------------------------------------*
200 *---------------------------------------------------------------------------*/
201 void dis_cmd(char *strg)
209 /*---------------------------------------------------------------------------*
210 * clear a command string
211 *---------------------------------------------------------------------------*/
219 /*---------------------------------------------------------------------------*
220 * move char from src to dest
221 *---------------------------------------------------------------------------*/
222 void move_ch(int src, int dst)
224 unsigned char *s, *d;
227 if(ch_width == WIDTH16)
232 s = &(fonttab[ch_height * offset * src]);
233 d = &(fonttab[ch_height * offset * dst]);
235 bcopy(s, d, (ch_height*offset)); /* src -> dst */
238 /*---------------------------------------------------------------------------*
239 * exchange char's src and dest
240 *---------------------------------------------------------------------------*/
241 void xchg_ch(int src, int dst)
243 unsigned char *s, *d;
244 unsigned char buf[32];
247 if(ch_width == WIDTH16)
252 s = &(fonttab[ch_height * offset * src]);
253 d = &(fonttab[ch_height * offset * dst]);
255 bcopy(s, buf, (ch_height*offset)); /* src -> tmp */
256 bcopy(d, s, (ch_height*offset)); /* dst -> src */
257 bcopy(buf, d, (ch_height*offset)); /* tmp -> dst */
260 /*---------------------------------------------------------------------------*
261 * display the current selected character
262 *---------------------------------------------------------------------------*/
265 unsigned char *fontchar;
268 unsigned char hibyte;
269 unsigned char lobyte;
277 if(ch_width == WIDTH16)
278 fontchar = &(fonttab[ch_height * 2 * no]);
280 fontchar = &(fonttab[ch_height * no]);
282 for (ln_no = 0; ln_no < ch_height; ln_no++)
284 hibyte = *(fontchar + (offset++));
286 if(ch_width == WIDTH16)
288 lobyte = *(fontchar + offset++);
291 strcpy(line,bitmask[(int)((hibyte >> 4) & 0x0f)]);
292 strcat(line,bitmask[(int)(hibyte & 0x0f)]);
294 if(ch_width == WIDTH16)
296 strcat(line,bitmask[(int)((lobyte >> 4) & 0x0f)]);
297 strcat(line,bitmask[(int)(lobyte & 0x0f)]);
298 mvwprintw(ch_win, r, 1, "%16.16s", line);
302 mvwprintw(ch_win, r, 1, "%8.8s", line);
310 /*---------------------------------------------------------------------------*
312 *---------------------------------------------------------------------------*/
319 unsigned short shift;
321 if(ch_width == WIDTH16)
326 s = &(fonttab[ch_height * offset * curchar]);
330 while(r <= ch_height)
341 if(mvwinch(ch_win, r, c) == BLACK)
343 shift = (shift >> 1);
351 /*---------------------------------- E O F ----------------------------------*/