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 "config.h"
20 #include <stdio.h>
21 #ifdef HAVE_ERRNO_H
22 #include <errno.h>
23 #endif
24 #include "cnvshell.h"
25 #include "cpi.h"
26
27 static char helpbuf[2048];
28 static int inter = 1;
29
30 /* Program name */
31 char *cnv_progname = "CPICOMP";
32
33 /* ddash = 1 if option started with a double-dash; else 0 */
34 /* Return NULL if OK, else error string */
cnv_set_option(int ddash,char * variable,char * value)35 char *cnv_set_option(int ddash, char *variable, char *value)
36 {
37 if (!stricmp(variable, "nointer")) { inter = 0; return NULL; }
38 if (strlen(variable) > 2000) variable[2000] = 0;
39 sprintf(helpbuf, "Unknown option: %s\n", variable);
40 return helpbuf;
41 }
42
43
44 /* Return help string */
cnv_help(void)45 char *cnv_help(void)
46 {
47 sprintf(helpbuf, "Compresses a CPI file into DRFONT format\n"
48 "Syntax: %s cpifile cpifile { options }\n\n", cnv_progname);
49 strcat (helpbuf, "Options: \n"
50 " --nointer Don't interleave headers and data in output file\n"
51 " (not recommended!)\n");
52
53 return helpbuf;
54 }
55
56
57 /* Convert a normal .CPI font into a DRFONT.
58 */
59
cnv_execute(FILE * infile,FILE * outfile)60 char *cnv_execute(FILE *infile, FILE *outfile)
61 {
62 CPI_FILE f;
63 int err;
64
65 cpi_new(&f, CPI_FONT);
66 err = cpi_loadfile(&f, infile);
67 if (!err && !strcmp(f.format, "DRFONT "))
68 {
69 fprintf(stderr, "Warning: File is already DRFONT - will not compress.\n");
70 }
71 if (!err) err = cpi_crush(&f);
72 if (!err)
73 {
74 err = cpi_savefile(&f, outfile, inter);
75 }
76 cpi_delete(&f);
77
78 switch(err)
79 {
80 case CPI_ERR_OK: return NULL;
81 case CPI_ERR_NOMEM: return "Out of memory";
82 case CPI_ERR_BADFMT: return "Input file is not a suitable CPI file";
83 case CPI_ERR_ERRNO: return strerror(errno);
84 case CPI_ERR_EMPTY: return "Input file is empty";
85 default: return "Unknown error";
86 }
87 }
88