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: cpftogpf.c /main/7 1996/11/08 02:02:48 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
36 #include <sys/types.h>
39 #include <sys/resource.h>
51 #include <X11/Xproto.h>
55 #include "snfstruct.h"
56 #include "fontstruct.h"
64 static void sigint_out() ;
65 static void put_error_and_exit();
66 static void put_help();
67 static int CnvGPFtoBDF() ;
69 static struct ptobhead Head;
71 static char *targ_file = NULL; /* UDC character filename */
72 static char *com = NULL; /* command name */
73 static char *spacing ;
74 static char *char_set ;
81 Unlink_Tmpfile(Head.out_file, com);
91 int help, no_infile, style_err, rtn, i;
93 char snf_file[BUFSIZE], buf[BUFSIZE];
94 int pfd[2], fd, snf_fd, permission;
96 char *style ; /* style */
99 #if defined( SVR4 ) || defined( SYSV ) || defined(CSRG_BASED) || defined(linux)
102 union wait chld_stat ;
104 int code_no, code_area ;
106 char *xlfdname, *cbuf, *ep ;
107 char *codeset = DEFAULT_CODESET ;
110 Head.in_file = Head.bdf_file = Head.snf_file = Head.out_file = NULL;
111 help = no_infile = style_err = 0;
113 COMM_SETDEFAULTSTYLE( style ) ;
114 memset( &key, '\0', sizeof(FalFontData) ) ;
115 xlfdname = cbuf = ep = '\0' ;
116 spacing = char_set = NULL ;
117 code_no = code_area = 0 ;
119 if (!( bdftopcf = get_cmd_path( getenv( "PATH" ), BDFTOPCF_CMD ))) {
122 if (!( oakgtobdf = get_cmd_path( getenv( "PATH" ), SNFTOBDF_CMD ))) {
123 oakgtobdf = SNFTOBDF;
125 if (!( bdftosnf = get_cmd_path( getenv( "PATH" ), BDFTOSNF_CMD ))) {
129 Head.code_category = ALL_CODE;
130 Head.start_code = MIN_CODE;
131 Head.end_code = MAX_CODE;
133 for (i=1; i<argc; i++) {
134 if ( !strcmp( argv[i], "-system" ) ) {
136 } else if ( !strcmp( argv[i], "-help" ) ) {
138 } else if ( !strcmp( argv[i], "-g" ) ) {
139 if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ) {
140 Head.snf_file = argv[++i];
142 } else if (!strcmp(argv[i], "-p")) {
143 if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ) {
144 Head.in_file = argv[++i];
148 } else if ( !strcmp(argv[i], "-style" ) ) {
149 if ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ){
155 } else if ( !strcmp( argv[i], "-codeset" ) ) {
157 ( ( i < argc-1 ) && ( *argv[i+1] != '-' ) ) &&
158 ( strlen( argv[i + 1] ) == 1 )
160 if ( *argv[i+1] == '1' ) code_area |= CDSET1 ;
161 codeset = argv[++i] ;
166 } else if ( !strcmp( argv[i], "-xlfd" ) ) {
168 xlfdname = argv[++i] ;
179 ep = (char *)strchr( codeset, '\0' ) ;
180 code_no = (int)strtol( codeset, &cbuf, 10 ) ;
181 if( cbuf == codeset || cbuf != ep ) {
182 USAGE1("%s : The code set number is not right.\n", argv[0] ) ;
192 USAGE1("%s : The input file name following -p option cannot be omitted.\n", argv[0] );
197 USAGE1("%s : The style is not specified.\n", argv[0] );
201 if ( Head.snf_file == NULL && xlfdname == NULL ) {
202 if ( code_area & SYSTM ) {
203 USAGE1("%s : The SNF output file name cannot be omitted.\n", argv[0] );
205 USAGE1("%s : The character size specification cannot be omitted.\n", argv[0] );
210 if ( !( code_area & SYSTM ) ) {
214 if( GetUdcFileName( com, code_no, xlfdname, snf_file ) ) {
215 USAGE1("%s : The font file name cannot be obtained. Terminates abnormally.\n", com );
218 Head.snf_file = snf_file;
220 switch ( GetFileName( argv[0], Head.snf_file, style, code_no, snf_file ) ) {
222 Head.snf_file = snf_file;
225 /* output GetFileName() */
228 USAGE1("%s : The font file name cannot be obtained. Terminates abnormally.\n", argv[0] );
235 * refuse proportional fonts
237 if ( GetUdcFontName( Head.snf_file, NULL, &xlfdname ) ) {
238 USAGE1("%s : This font cannot get XLFD. Terminates abnormally.\n", argv[0]);
241 GETSPACINGSTR( spacing, xlfdname ) ;
242 if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) {
243 USAGE2("%s cannot edit proportional fonts.(SPACING \"%s\")\n", argv[0], spacing );
246 GETCHARSETSTR( char_set, xlfdname ) ;
248 COMM_SET_CODECATEGORY( char_set, code_area, Head) ;
250 if ( ( targ_file = GetRealFileName( Head.snf_file ) ) == NULL ){
251 USAGE2("%s : It was not possible to refer to the substance of the font file. \"%s\"\n", argv[0], Head.snf_file );
256 if ( ( chk_fd = open( targ_file, O_RDWR ) ) < 0 ) {
257 USAGE2("%s : The font file of substance \"%s\" cannot be opened.\n", argv[0] , targ_file );
260 if ( isLock( chk_fd ) == 1 ) {
261 USAGE1("%s : Editing by other application.\n", argv[0] );
268 * open input file(CPF)
270 if ( Head.in_file == NULL ) {
273 if ( ( Head.input = fopen( Head.in_file, "r" ) ) == NULL ) {
274 put_error_and_exit( &Head, GPF_OPEN_IN, argv[0] );
281 if ( !( Head.out_file = GetTmpPath( targ_file ) ) ) {
282 put_error_and_exit( &Head, MKTMP_ERROR, argv[0] );
286 if ( ( snf_fd = open( Head.snf_file, O_RDONLY ) ) >= 0 ) {
287 if ( ChkPcfFontFile( Head.snf_file) ) {
289 COMM_SNF_FILEVERSION( snf_fd, finf, buf, permission ) ;
290 if( permission < 0 ) {
291 put_error_and_exit( &Head, BDF_INVAL, argv[0] );
299 put_error_and_exit( &Head, BDF_OPEN_IN, argv[0] );
303 if ( pipe( pfd ) != 0 ) {
304 put_error_and_exit( &Head, PIPE_ERROR, argv[0] );
307 signal( SIGHUP , (void(*)())sigint_out );
308 signal( SIGINT , (void(*)())sigint_out );
309 signal( SIGQUIT, (void(*)())sigint_out );
310 signal( SIGTERM, (void(*)())sigint_out );
312 switch ( chld_pid = fork() ) {
314 if ( ( fd = open( Head.out_file, O_WRONLY | O_CREAT, 0664 ) ) < 0 ) {
315 put_error_and_exit( &Head, BDF_OPEN_OUT, argv[0] );
318 if ( dup( pfd[0] ) < 0 ) {
319 put_error_and_exit( &Head, DUP_ERROR, argv[0] );
324 if ( dup( fd ) < 0 ) {
325 put_error_and_exit( &Head, DUP_ERROR, argv[0] );
329 if ( ChkPcfFontFile( Head.snf_file ) == 0 ) {
330 execl( bdftopcf, bdftopcf, 0 );
332 put_error_and_exit( &Head, PCFFONTC_ERROR, argv[0] );
335 COMM_SNF_EXECLBDFTOSNF( permission, buf, Head.snf_file ) ;
337 put_error_and_exit( &Head, SNFFONTC_ERROR, argv[0] );
341 put_error_and_exit( &Head, FORK_ERROR, argv[0] );
348 if ( ( Head.output = fdopen( pfd[1], "w" ) ) == NULL ) {
350 kill( chld_pid, SIGKILL );
351 WaitID( chld_pid, chld_stat ) ;
352 put_error_and_exit( &Head, FDOPEN_ERROR, argv[0] );
355 if ( ( rtn = CnvGPFtoBDF( &Head ) ) ) {
356 fclose( Head.input );
357 fclose( Head.output );
359 kill( chld_pid, SIGKILL );
360 WaitID( chld_pid, chld_stat ) ;
361 Unlink_Tmpfile( Head.out_file, argv[0] );
362 put_error_and_exit( &Head, rtn, argv[0] );
364 fclose( Head.output );
367 #if !defined( SVR4 ) && !defined( SYSV ) && !defined(__FreeBSD__)
368 if ( !WIFEXITED(exit_stat) ) {
370 if (! ( WIFEXITED(exit_stat) && !WEXITSTATUS(exit_stat) ) ) {
372 USAGE3("%s: The error occurred by %s (%08x).\n", argv[0], bdftopcf, exit_stat );
373 Unlink_Tmpfile( Head.out_file, argv[0] );
376 fclose( Head.input );
377 signal( SIGHUP , SIG_IGN );
378 signal( SIGINT , SIG_IGN );
379 signal( SIGQUIT, SIG_IGN );
380 signal( SIGTERM, SIG_IGN );
383 if ( (stat( Head.out_file,&statbuf ) ) ||
384 ( statbuf.st_size == 0 ) ) {
385 Unlink_Tmpfile( Head.out_file, argv[0] );
386 put_error_and_exit( &Head, BDF_WRITE, argv[0] );
388 if ( stat( targ_file, &statbuf ) ) {
389 Unlink_Tmpfile( Head.out_file, argv[0] );
390 put_error_and_exit( &Head, BDF_WRITE, argv[0] );
393 exit ( Make_NewFefFile( targ_file, Head.out_file,
394 FONT_FILE_PARM, (uid_t)statbuf.st_uid, (gid_t)statbuf.st_gid, argv[0]) );
400 struct ptobhead *head;
403 char textbuf[BUFSIZE];
405 if ( ( rtn = ReadGpfHeader( head, textbuf ) ) ) {
409 if ( ( rtn = WriteBdfHeader( head ) ) ) {
413 if ( ( head->p_width != head->bdf_width ) ||
414 ( head->p_height != head->bdf_height )
421 if ( ( head->code = (int *)malloc( sizeof(int) * head->num_chars ) ) == NULL ) {
425 if ( ( head->ptn = (char **)malloc( sizeof(char *)*head->num_chars ) ) == NULL ) {
429 if ( ( rtn = ReadGpfToMemory(head, textbuf ) ) ) {
433 if ( ( rtn = WritePtnToBdf( head ) ) ) {
442 put_error_and_exit( ptob, er_no, prog_name )
443 struct ptobhead *ptob;
447 ErrMsgTable_AndExit( er_no, ptob->snf_file, ptob->out_file,
457 put_help( prog_name )
460 USAGE1("Usage: %s -xlfd xlfd_name\n", prog_name);
461 USAGE("\t\t[-g character_size][-p character_pattern_file_name]\n" );
462 USAGE("\t\t [-style style] \n");
464 USAGE("The character size may be obtained using the dtlsgpf command.\n");