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 libraries 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: exportbdf.c /main/4 1996/04/10 13:49:20 ageorge $ */
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
30 * Authors: Seiya Miyazaki FUJITSU LIMITED
31 * Hiroyuki Chiba FUJITSU LIMITED
39 #include <sys/resource.h>
48 #include <sys/types.h>
53 static int writeBdfHeader();
54 static int readBdfToMemory();
55 static void sigint_out();
56 static char buf[BUFSIZE];
57 static struct ptobhead w_bdf ;
62 fclose(w_bdf.output) ;
63 fclose(w_bdf.input) ; /* stream */
68 expCheckCode( code, code_num, code_list )
75 if( code < MIN_CODE || code > MAX_CODE ) return -1 ;
76 for( i=0; i<code_num; i++ ){
77 if( code == code_list[i] ) return 0 ;
83 ExpGpftoBDF( gpf_name, bdf_name, code_num, code_list, comment_num, comment_list, make_all )
84 char *gpf_name ; /* pointer to GPF file name area */
85 char *bdf_name ; /* pointer to BDF file name area */
86 int code_num ; /* number of GPF code */
87 int *code_list ; /* pointer to GPF code lists */
88 int comment_num ; /* number comments */
89 char **comment_list ;/* pointer to the list of comments */
90 int make_all ; /* convert whole GPF fomat file to BDF */
93 struct btophead r_gpf ;
94 int rtn, i, num_chars ;
99 if( gpf_name == NULL || bdf_name == NULL ){
100 fprintf(stderr, "GPF or BDF file name is not specified.\n" ) ;
106 memset( &w_bdf, 0, sizeof(struct ptobhead) ) ;
107 memset( &r_gpf, 0, sizeof(struct btophead) ) ;
109 if ( stat( SNFTOBDF, &statbuf ) ) {
110 if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) {
111 fprintf( stderr, "There is not %s command.\n", SNFTOBDF_CMD ) ;
115 oakgtobdf = SNFTOBDF;
119 * export glyphs in BDF format
121 w_bdf.snf_file = gpf_name ;
122 if( (w_bdf.output = fopen( bdf_name, "w" )) == NULL ){
123 fprintf(stderr, "\"%s\" cannot open.\n", bdf_name ) ;
127 signal( SIGHUP , (void(*)())sigint_out );
128 signal( SIGINT , (void(*)())sigint_out );
129 signal( SIGQUIT, (void(*)())sigint_out );
130 signal( SIGTERM, (void(*)())sigint_out );
132 if( (rtn = writeBdfHeader(&w_bdf, comment_num, comment_list)) ){
133 fprintf(stderr, "\"%s\" cannot write header.\n", bdf_name ) ;
134 fclose(w_bdf.output) ;
135 fclose(w_bdf.input) ; /* stream */
139 r_gpf.bdf_width = w_bdf.bdf_width ;
140 r_gpf.bdf_height = w_bdf.bdf_height ;
141 r_gpf.input = w_bdf.input ;
143 num_chars = ((make_all) ? w_bdf.num_chars : code_num) ;
145 if( (r_gpf.code = (int *)malloc( sizeof(int) * num_chars)) == NULL ) {
146 fclose(w_bdf.output) ;
147 fclose(w_bdf.input) ;
148 return(MALLOC_ERROR);
151 if( (r_gpf.ptn = (char **)calloc( num_chars, sizeof(char *) )) == NULL ) {
152 fclose(w_bdf.output) ;
153 fclose(w_bdf.input) ;
154 return(MALLOC_ERROR);
157 if( (rtn = readBdfToMemory(&r_gpf, buf, code_num, code_list, make_all)) ){
158 fprintf(stderr, "\"%s\" cannot read glyph.\n", bdf_name ) ;
159 fclose(w_bdf.output) ;
160 fclose(w_bdf.input) ;
163 fclose(w_bdf.input) ;
167 w_bdf.num_chars = r_gpf.num_chars ;
168 w_bdf.code = r_gpf.code ;
169 w_bdf.ptn = r_gpf.ptn ;
171 if( (rtn = WritePtnToBdf( &w_bdf, buf )) ){
172 fprintf(stderr, "\"%s\" cannot write glyph.\n", bdf_name ) ;
173 fclose(w_bdf.output) ;
176 fclose(w_bdf.output) ;
178 signal( SIGHUP , SIG_IGN );
179 signal( SIGINT , SIG_IGN );
180 signal( SIGQUIT, SIG_IGN );
181 signal( SIGTERM, SIG_IGN );
187 for(i=0; i<r_gpf.num_chars; i++){
188 if(r_gpf.ptn[i]) free(r_gpf.ptn[i]) ;
196 writeBdfHeader(head, comment_num, comment_list)
197 struct ptobhead *head;
198 int comment_num ; /* number comments */
199 char **comment_list ;/* pointer to the list of comments */
203 unsigned int getstat;
204 char buf[BUFSIZE], *p;
209 #if defined( SVR4 ) || defined( SYSV ) || defined(CSRG_BASED) || defined(linux)
212 union wait chld_stat ;
215 if (head->snf_file != NULL) {
219 switch (chld_pid = fork()) {
227 execl( oakgtobdf, oakgtobdf, head->snf_file, 0);
235 if((fp = (FILE *)fdopen(fd[0], "r")) == NULL) {
237 kill( chld_pid, SIGKILL );
238 WaitID( chld_pid, chld_stat ) ;
242 return(BDF_OPEN_HEAD);
249 if (fgets(buf, BUFSIZE, fp) == NULL) {
251 if (head->snf_file != NULL) {
253 kill( chld_pid, SIGKILL );
254 WaitID( chld_pid, chld_stat ) ;
261 if (!strncmp(p, CHARS, CHARSsz)) {
262 if ((sscanf(p, "CHARS %d", &(head->num_chars))) != 1 ){
269 * write user comments
271 if ( !strncmp(p, "FONT", strlen("FONT"))
272 && comment_list && !comflg
275 for( i=0; i<comment_num; i++ ){
277 if( (ep = (char *)strchr( comment_list[i], '\n' )) != NULL )
279 if( comment_list[i] == '\0' ) continue ;
280 fprintf(head->output, "COMMENT %s\n", comment_list[i]);
282 fprintf(head->output, "COMMENT\n");
286 fprintf(head->output, "%s", buf);
288 if (!strncmp(p, SIZE, SIZEsz)) {
289 if ((sscanf(p, "SIZE %f%d",
290 &(head->bdf_point), &(head->bdf_xdpi))) != 2) {
292 if (head->snf_file != NULL) {
294 kill( chld_pid, SIGKILL );
295 WaitID( chld_pid, chld_stat ) ;
302 if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) {
303 if (( cnt = sscanf( p, "FONTBOUNDINGBOX %d%d%d%d",
304 &(head->bdf_width), &(head->bdf_height),
305 &(head->bdf_x), &(head->bdf_y))) != 4
308 if (head->snf_file != NULL) {
310 kill( chld_pid, SIGKILL );
311 WaitID( chld_pid, chld_stat ) ;
318 get_charset_registry(head, p) ;
321 if (getstat != 0x07) {
330 readBdfToMemory(head, buf, code_num, code_list, make_all)
331 struct btophead *head;
333 int code_num ; /* number of GPF code */
334 int *code_list ; /* pointer to GPF code lists */
335 int make_all ; /* convert whole GPF fomat file to BDF */
337 int code, mwidth, num_char, bsize, rtn;
341 mwidth = (head->bdf_width + 7) / 8;
342 bsize = mwidth * head->bdf_height;
344 if ((rtn = GetBdfCode(head, buf, &code)) < 0) {
345 return(rtn); /* contain BDF_INVAL */
346 } else if (rtn == FILE_END) {
347 head->num_chars = num_char;
351 if ( expCheckCode(code, code_num, code_list) ) {
356 head->code[num_char] = code;
357 if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) {
358 return(MALLOC_ERROR);
361 if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) {