2 * CDE - Common Desktop Environment
4 * Copyright (c) 1993-2012, The Open Group. All rights reserved.
6 * These libraries and programs are free software; you can
7 * redistribute them and/or modify them under the terms of the GNU
8 * Lesser General Public License as published by the Free Software
9 * Foundation; either version 2 of the License, or (at your option)
12 * These libraries and programs are distributed in the hope that
13 * they will be useful, but WITHOUT ANY WARRANTY; without even the
14 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15 * PURPOSE. See the GNU Lesser General Public License for more
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with these librararies and programs; if not, write
20 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
21 * Floor, Boston, MA 02110-1301 USA
23 /* $XConsortium: bdftocpf.c /main/6 1996/11/08 02:01:17 cde-fuj $ */
25 * (c) Copyright 1995 FUJITSU LIMITED
26 * This is source code modified by FUJITSU LIMITED under the Joint
27 * Development Agreement for the CDEnext PST.
28 * This is unpublished proprietary source code of FUJITSU LIMITED
34 #include <sys/types.h>
42 static void put_error();
43 static void put_help() ;
45 static void sigint_out() ;
46 static int CnvBDFtoGPF() ;
48 static struct btophead Head;
54 unlink(Head.out_file);
67 for (i=1; i<argc; i++) {
68 if (!strcmp(argv[i], "-help")) {
78 Head.in_file = Head.out_file = Head.text_file = NULL;
79 Head.p_width = Head.p_height = USE_ORG_SIZE;
82 Head.start_code = MIN_CODE ;
83 Head.end_code = MAX_CODE ;
84 Head.code_category = ALL_CODE;
86 for (i=1; i<argc; i+=2) {
87 if (!strcmp(argv[i], "-p")) {
88 Head.out_file = argv[i+1];
89 } else if (!strcmp(argv[i], "-bdf")) {
90 Head.in_file = argv[i+1];
91 } else if (!strcmp(argv[i], "-width")) {
92 Head.p_width = atoi(argv[i+1]);
93 if ((Head.p_width > MAX_FONT_WIDTH) ||
94 (Head.p_width < MIN_FONT_WIDTH)) {
95 USAGE2("%s: The specification of the character width is improper.\"%s\"\n",
97 exit(PARAM_ERROR * (-1));
99 } else if (!strcmp(argv[i], "-height")) {
100 Head.p_height = atoi(argv[i+1]);
101 if ((Head.p_height > MAX_FONT_HEIGHT) ||
102 (Head.p_height < MIN_FONT_HEIGHT)) {
103 USAGE2("%s: The specification of the character height is improper.\"%s\"\n",
105 exit(PARAM_ERROR * (-1));
112 if (Head.in_file == NULL) {
117 spacing = xlfdname = NULL ;
118 /* refuse proportional fonts */
119 if ( GetUdcFontName( NULL, Head.in_file, &xlfdname ) ) {
120 USAGE1("%s : This font cannot get XLFD. Terminates abnormally.\n", argv[0]);
123 GETSPACINGSTR( spacing, xlfdname ) ;
124 if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) {
125 USAGE2("%s cannot edit proportional fonts.(SPACING \"%s\")\n", argv[0], spacing );
128 if ((Head.input = fopen(Head.in_file, "r")) == NULL) {
129 USAGE2("%s: The BDF file cannot be opened.\"%s\"\n",
130 argv[0], Head.in_file);
131 exit(BDF_OPEN * (-1));
135 signal(SIGHUP, (void(*)())sigint_out);
136 signal(SIGINT, (void(*)())sigint_out);
137 signal(SIGQUIT, (void(*)())sigint_out);
138 signal(SIGTERM, (void(*)())sigint_out);
140 if (Head.out_file == NULL) {
141 Head.output = stdout;
143 if (stat(Head.out_file, &st) != 0) {
144 if ((Head.output = fopen(Head.out_file, "w")) == NULL) {
145 USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n",
146 argv[0], Head.out_file);
147 exit(GPF_OPEN *(-1));
150 Head.text_file = Head.out_file;
151 if ((Head.out_file = GetTmpPath( Head.out_file )) == NULL) {
152 USAGE1("%s: Failed convert.\n", argv[0]);
153 exit(FATAL_ERROR * (-1));
155 if ((Head.output = fopen(Head.out_file, "w")) == NULL) {
156 USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n",
157 argv[0], Head.out_file);
158 exit(GPF_OPEN * (-1));
163 if ((rtn = CnvBDFtoGPF(&Head))) {
164 if (Head.in_file != NULL) {
167 if (Head.out_file != NULL) {
169 unlink(Head.out_file);
171 put_error(&Head, rtn, argv[0]);
175 if (Head.in_file != NULL) {
178 if (Head.out_file != NULL) {
180 signal(SIGHUP, SIG_IGN);
181 signal(SIGINT, SIG_IGN);
182 signal(SIGQUIT, SIG_IGN);
183 signal(SIGTERM, SIG_IGN);
184 if (Head.text_file != NULL) {
185 Link_NewFile(Head.out_file, Head.text_file);
186 unlink(Head.out_file);
194 struct btophead *head;
196 char bdfbuf[BUFSIZE];
199 if ((rtn = ReadBdfHeader(head, bdfbuf)) < 0) {
203 if (head->p_width == USE_ORG_SIZE) {
204 head->p_width = head->bdf_width;
206 if (head->p_height == USE_ORG_SIZE) {
207 head->p_height = head->bdf_height;
209 if ((head->p_width != head->bdf_width) ||
210 (head->p_height != head->bdf_height)) {
216 if ((head->code = (int *)malloc(sizeof(int)*head->num_chars)) == NULL) {
220 if ((head->ptn = (char **)malloc(sizeof(char *)*head->num_chars)) == NULL) {
224 if ((rtn = ReadBdfToMemory(head, bdfbuf))) {
228 WriteGpfHeader(head);
230 if ((rtn = WritePtnToGpf(head))) {
238 put_error(head, er_no, prog_name)
239 struct btophead *head;
245 USAGE1("%s: Failed convert.\n", prog_name);
249 USAGE2("%s: The BDF file cannot be opened. \"%s\"\n",
250 prog_name, head->in_file);
254 USAGE2("%s: The BDF file cannot be read. \"%s\"\n",
255 prog_name, head->in_file);
259 USAGE2("%s: The format of the BDF file is illegal. \"%s\"\n",
260 prog_name, head->in_file);
264 USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n",
265 prog_name, head->out_file);
269 USAGE2("%s: It is not possible to write to the character pattern file. \"%s\"\n",
270 prog_name, head->out_file);
282 USAGE1("Usage: %s [-p character_pattern_file_name] [-bdf BDF_file_name]\n", prog_name);
283 USAGE("\t\t[-width character_width] [-height character_height] [-help]\n\n");
291 exit(PARAM_ERROR * (-1));