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: 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
38 #include <sys/resource.h>
53 #include <sys/types.h>
58 static int writeBdfHeader();
59 static int readBdfToMemory();
60 static void sigint_out();
61 static char buf[BUFSIZE];
62 static struct ptobhead w_bdf ;
67 fclose(w_bdf.output) ;
68 fclose(w_bdf.input) ; /* stream */
73 expCheckCode( code, code_num, code_list )
80 if( code < MIN_CODE || code > MAX_CODE ) return -1 ;
81 for( i=0; i<code_num; i++ ){
82 if( code == code_list[i] ) return 0 ;
88 ExpGpftoBDF( gpf_name, bdf_name, code_num, code_list, comment_num, comment_list, make_all )
89 char *gpf_name ; /* pointer to GPF file name area */
90 char *bdf_name ; /* pointer to BDF file name area */
91 int code_num ; /* number of GPF code */
92 int *code_list ; /* pointer to GPF code lists */
93 int comment_num ; /* number comments */
94 char **comment_list ;/* pointer to the list of comments */
95 int make_all ; /* convert whole GPF fomat file to BDF */
98 struct btophead r_gpf ;
99 int rtn, i, num_chars ;
104 if( gpf_name == NULL || bdf_name == NULL ){
105 fprintf(stderr, "GPF or BDF file name is not specified.\n" ) ;
111 memset( &w_bdf, 0, sizeof(struct ptobhead) ) ;
112 memset( &r_gpf, 0, sizeof(struct btophead) ) ;
114 if ( stat( SNFTOBDF, &statbuf ) ) {
115 if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) {
116 fprintf( stderr, "There is not %s command.\n", SNFTOBDF_CMD ) ;
120 oakgtobdf = SNFTOBDF;
124 * export glyphs in BDF format
126 w_bdf.snf_file = gpf_name ;
127 if( (w_bdf.output = fopen( bdf_name, "w" )) == NULL ){
128 fprintf(stderr, "\"%s\" cannot open.\n", bdf_name ) ;
132 signal( SIGHUP , (void(*)())sigint_out );
133 signal( SIGINT , (void(*)())sigint_out );
134 signal( SIGQUIT, (void(*)())sigint_out );
135 signal( SIGTERM, (void(*)())sigint_out );
137 if( (rtn = writeBdfHeader(&w_bdf, comment_num, comment_list)) ){
138 fprintf(stderr, "\"%s\" cannot write header.\n", bdf_name ) ;
139 fclose(w_bdf.output) ;
140 fclose(w_bdf.input) ; /* stream */
144 r_gpf.bdf_width = w_bdf.bdf_width ;
145 r_gpf.bdf_height = w_bdf.bdf_height ;
146 r_gpf.input = w_bdf.input ;
148 num_chars = ((make_all) ? w_bdf.num_chars : code_num) ;
150 if( (r_gpf.code = (int *)malloc( sizeof(int) * num_chars)) == NULL ) {
151 fclose(w_bdf.output) ;
152 fclose(w_bdf.input) ;
153 return(MALLOC_ERROR);
156 if( (r_gpf.ptn = (char **)calloc( num_chars, sizeof(char *) )) == NULL ) {
157 fclose(w_bdf.output) ;
158 fclose(w_bdf.input) ;
159 return(MALLOC_ERROR);
162 if( (rtn = readBdfToMemory(&r_gpf, buf, code_num, code_list, make_all)) ){
163 fprintf(stderr, "\"%s\" cannot read glyph.\n", bdf_name ) ;
164 fclose(w_bdf.output) ;
165 fclose(w_bdf.input) ;
168 fclose(w_bdf.input) ;
172 w_bdf.num_chars = r_gpf.num_chars ;
173 w_bdf.code = r_gpf.code ;
174 w_bdf.ptn = r_gpf.ptn ;
176 if( (rtn = WritePtnToBdf( &w_bdf, buf )) ){
177 fprintf(stderr, "\"%s\" cannot write glyph.\n", bdf_name ) ;
178 fclose(w_bdf.output) ;
181 fclose(w_bdf.output) ;
183 signal( SIGHUP , SIG_IGN );
184 signal( SIGINT , SIG_IGN );
185 signal( SIGQUIT, SIG_IGN );
186 signal( SIGTERM, SIG_IGN );
192 for(i=0; i<r_gpf.num_chars; i++){
193 if(r_gpf.ptn[i]) free(r_gpf.ptn[i]) ;
201 writeBdfHeader(head, comment_num, comment_list)
202 struct ptobhead *head;
203 int comment_num ; /* number comments */
204 char **comment_list ;/* pointer to the list of comments */
208 unsigned int getstat;
209 char buf[BUFSIZE], *p;
214 #if defined( SVR4 ) || defined( SYSV ) || defined(__FreeBSD__)
217 union wait chld_stat ;
220 if (head->snf_file != NULL) {
224 switch (chld_pid = fork()) {
232 execl( oakgtobdf, oakgtobdf, head->snf_file, 0);
240 if((fp = (FILE *)fdopen(fd[0], "r")) == NULL) {
242 kill( chld_pid, SIGKILL );
243 WaitID( chld_pid, chld_stat ) ;
247 return(BDF_OPEN_HEAD);
254 if (fgets(buf, BUFSIZE, fp) == NULL) {
256 if (head->snf_file != NULL) {
258 kill( chld_pid, SIGKILL );
259 WaitID( chld_pid, chld_stat ) ;
266 if (!strncmp(p, CHARS, CHARSsz)) {
267 if ((sscanf(p, "CHARS %d", &(head->num_chars))) != 1 ){
274 * write user comments
276 if ( !strncmp(p, "FONT", strlen("FONT"))
277 && comment_list && !comflg
280 for( i=0; i<comment_num; i++ ){
282 if( (ep = (char *)strchr( comment_list[i], '\n' )) != NULL )
284 if( comment_list[i] == '\0' ) continue ;
285 fprintf(head->output, "COMMENT %s\n", comment_list[i]);
287 fprintf(head->output, "COMMENT\n");
291 fprintf(head->output, "%s", buf);
293 if (!strncmp(p, SIZE, SIZEsz)) {
294 if ((sscanf(p, "SIZE %f%d",
295 &(head->bdf_point), &(head->bdf_xdpi))) != 2) {
297 if (head->snf_file != NULL) {
299 kill( chld_pid, SIGKILL );
300 WaitID( chld_pid, chld_stat ) ;
307 if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) {
308 if (( cnt = sscanf( p, "FONTBOUNDINGBOX %d%d%d%d",
309 &(head->bdf_width), &(head->bdf_height),
310 &(head->bdf_x), &(head->bdf_y))) != 4
313 if (head->snf_file != NULL) {
315 kill( chld_pid, SIGKILL );
316 WaitID( chld_pid, chld_stat ) ;
323 get_charset_registry(head, p) ;
326 if (getstat != 0x07) {
335 readBdfToMemory(head, buf, code_num, code_list, make_all)
336 struct btophead *head;
338 int code_num ; /* number of GPF code */
339 int *code_list ; /* pointer to GPF code lists */
340 int make_all ; /* convert whole GPF fomat file to BDF */
342 int code, mwidth, num_char, bsize, rtn;
346 mwidth = (head->bdf_width + 7) / 8;
347 bsize = mwidth * head->bdf_height;
349 if ((rtn = GetBdfCode(head, buf, &code)) < 0) {
350 return(rtn); /* contain BDF_INVAL */
351 } else if (rtn == FILE_END) {
352 head->num_chars = num_char;
356 if ( expCheckCode(code, code_num, code_list) ) {
361 head->code[num_char] = code;
362 if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) {
363 return(MALLOC_ERROR);
366 if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) {