1 /*
2     psftools: Manipulate console fonts in the .PSF format
3     Copyright (C) 2005  John Elliott
4 
5     This program is free software; you can redistribute it and/or modify
6     it under the terms of the GNU General Public License as published by
7     the Free Software Foundation; either version 2 of the License, or
8     (at your option) any later version.
9 
10     This program is distributed in the hope that it will be useful,
11     but WITHOUT ANY WARRANTY; without even the implied warranty of
12     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13     GNU General Public License for more details.
14 
15     You should have received a copy of the GNU General Public License
16     along with this program; if not, write to the Free Software
17     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 */
19 #include <stdio.h>
20 #include "cnvshell.h"
21 #include "psflib.h"
22 
23 /* Convert a PSF file to a text format */
24 
25 char *cnv_progname = "PSF2TXT";
26 
27 
cnv_set_option(int ddash,char * variable,char * value)28 char *cnv_set_option(int ddash, char *variable, char *value)
29     {
30     return "This program does not have options.";
31     }
32 
cnv_help(void)33 char *cnv_help(void)
34     {
35     static char buf[150];
36 
37     sprintf(buf, "Syntax: %s psf_file txt_file\n", cnv_progname);
38     return buf;
39     }
40 
41 
42 
cnv_execute(FILE * fpin,FILE * fpout)43 char *cnv_execute(FILE *fpin, FILE *fpout)
44 {
45 	int rv;
46 	PSF_FILE psf;
47 	psf_dword ch;
48 	psf_byte pix;
49 	psf_dword x, y;
50 	char *ucs;
51 
52 	psf_file_new(&psf);
53 	rv = psf_file_read(&psf, fpin);
54 	if (rv != PSF_E_OK) return psf_error_string(rv);
55 
56 	fprintf(fpout, "%%PSF2\n");
57 	fprintf(fpout, "Version: %ld\n", psf.psf_version);
58 	fprintf(fpout, "Flags: %ld\n", psf.psf_flags);
59 	fprintf(fpout, "Length: %ld\n", psf.psf_length);
60 	fprintf(fpout, "Width: %ld\n", psf.psf_width);
61 	fprintf(fpout, "Height: %ld\n", psf.psf_height);
62 	rv = 0;
63 	for (ch = 0; ch < psf.psf_length; ch++)
64 	{
65 		fprintf(fpout, "%%\n// Character %ld\n", ch);
66 		for (y = 0; y < psf.psf_height; y++)
67 		{
68 			if (y == 0) fprintf(fpout, "Bitmap: ");
69 			else	    fprintf(fpout, "        ");
70 
71 			for (x = 0; x < psf.psf_width; x++)
72 			{
73 				rv = psf_get_pixel(&psf, ch, x, y, &pix);
74 				if (rv) break;
75 				if (pix) fputc('#', fpout);
76 				else	 fputc('-', fpout);
77 			}
78 			if (rv) break;
79 			if (y < psf.psf_height - 1) fprintf(fpout, " \\");
80 			fputc('\n', fpout);
81 		}
82 		if (rv) break;
83 		if (psf_is_unicode(&psf))
84 		{
85 			rv = psf_unicode_to_string(psf.psf_dirents_used[ch],
86 					&ucs);
87 			if (!rv)
88 			{
89 				fprintf(fpout, "Unicode: %s\n", ucs);
90 				free(ucs);
91 			}
92 
93 		}
94 		if (rv) break;
95 	}
96 
97 	psf_file_delete(&psf);
98 	return 0;
99 }
100 
101