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: oakfuty.c /main/12 1996/11/11 10:55:57 drk $ */
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
32 #include <sys/types.h>
39 #include <sys/resource.h>
64 char *bdftosnf = BDFTOSNF;
67 static int put_file_create_err_msg = 0;
75 #if NeedFunctionPrototypes
77 struct btophead *head,
81 ReadBdfHeader( head, buf )
82 struct btophead *head;
87 unsigned int getstat = 0;
89 fgets(buf, BUFSIZE, head->input);
93 if (strncmp(p, STARTFONT, STARTFONTsz)) {
98 if (fgets(buf, BUFSIZE, head->input) == NULL) {
103 if (!strncmp(p, SIZE, SIZEsz)) {
104 if ((sscanf(p, "SIZE %f%d",
105 &(head->bdf_point), &(head->bdf_xdpi))) != 2) {
109 } else if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) {
110 if (sscanf(p, "FONTBOUNDINGBOX %d%d%d%d",
111 &(head->bdf_width), &(head->bdf_height),
112 &(head->bdf_x), &(head->bdf_y)) != 4) {
117 } else if (!strncmp(p, CHARS, CHARSsz)) {
118 if ((sscanf(p, "CHARS %d", &(head->num_chars))) != 1) {
122 } else if (!strncmp(p, STARTCHAR, STARTCHARsz)) {
127 if (getstat != 0x07) {
135 #if NeedFunctionPrototypes
137 struct ptobhead *head,
141 ReadGpfHeader(head, buf)
142 struct ptobhead *head;
147 unsigned int getstat = 0;
150 if (getstat == 0x07) break;
152 if (fgets(buf, BUFSIZE, head->input) == NULL) {
158 if (!strncmp(p, NUMFONTS, NUMFONTSsz)) {
159 if (sscanf(p, "numfonts:%d", &(head->num_chars)) != 1) {
163 } else if (!strncmp(p, WIDTH, WIDTHsz)) {
164 if (sscanf(p, "width:%d", &(head->p_width)) != 1) {
168 } else if (!strncmp(p, HEIGHT, HEIGHTsz)) {
169 if (sscanf(p, "height:%d", &(head->p_height)) != 1) {
180 #if NeedFunctionPrototypes
181 WriteBdfHeader( struct ptobhead *head )
184 struct ptobhead *head;
189 unsigned int getstat;
190 char buf[BUFSIZE], *p;
193 #if defined( SVR4 ) || defined( SYSV )
196 union wait chld_stat ;
200 if (head->snf_file != NULL) {
204 switch (chld_pid = fork()) {
212 execl( oakgtobdf, oakgtobdf, head->snf_file, 0);
223 if((fp = (FILE *)fdopen(fd[0], "r")) == NULL) {
225 kill( chld_pid, SIGKILL );
226 WaitID( chld_pid, chld_stat ) ;
230 if ((fp = fopen(head->bdf_file, "r")) == NULL) {
231 return(BDF_OPEN_HEAD);
238 if (fgets(buf, BUFSIZE, fp) == NULL) {
240 if (head->snf_file != NULL) {
241 kill( chld_pid, SIGKILL );
242 WaitID( chld_pid, chld_stat ) ;
249 if (!strncmp(p, CHARS, CHARSsz)) {
251 if (head->snf_file != NULL) {
252 kill( chld_pid, SIGKILL );
253 WaitID( chld_pid, chld_stat ) ;
258 fprintf(head->output, "%s", buf);
260 if (!strncmp(p, SIZE, SIZEsz)) {
261 if ((sscanf(p, "SIZE %f%d",
262 &(head->bdf_point), &(head->bdf_xdpi))) != 2) {
264 if (head->snf_file != NULL) {
265 kill( chld_pid, SIGKILL );
266 WaitID( chld_pid, chld_stat ) ;
273 if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) {
274 if ( sscanf( p, "FONTBOUNDINGBOX %d%d%d%d",
281 if (head->snf_file != NULL) {
282 kill( chld_pid, SIGKILL );
283 WaitID( chld_pid, chld_stat ) ;
290 get_charset_registry(head, p) ;
294 if (getstat != 0x03) {
303 #if NeedFunctionPrototypes
304 WriteGpfHeader( struct btophead *head )
307 struct btophead *head;
310 fprintf(head->output, "numfonts:%d\n", head->num_chars);
311 fprintf(head->output, "width:%d\n", head->p_width );
312 fprintf(head->output, "height:%d\n", head->p_height );
319 #if NeedFunctionPrototypes
320 WritePtnToBdf( struct ptobhead *head )
323 struct ptobhead *head;
326 int msize, swidth, rtn, i, nchar;
328 int bbw, bbh, bbx, bby, dw ;
329 char glyph_name[BUFSIZE] ;
331 nchar = head->num_chars;
332 put_default_chars(head, nchar, rtn) ;
335 msize = ((head->bdf_width + 7) / 8) * head->bdf_height;
336 if ((zoomptn = (char *)malloc(msize)) == NULL) {
337 return(MALLOC_ERROR);
341 for (i=0; i<head->num_chars; i++) {
342 sprintf( glyph_name, "%x", head->code[i]);
343 swidth = (head->bdf_width * 72270)/((int)(head->bdf_point * (float)head->bdf_xdpi));
344 dw = head->bdf_width ;
345 bbw = head->bdf_width ;
346 bbh = head->bdf_height ;
350 fprintf(head->output, "STARTCHAR %s\n", glyph_name );
351 fprintf(head->output, "ENCODING %d\n", head->code[i]);
352 fprintf(head->output, "SWIDTH %d 0\n", swidth );
353 fprintf(head->output, "DWIDTH %d 0\n", dw );
354 fprintf(head->output, "BBX %d %d %d %d\n", bbw, bbh, bbx, bby );
355 fprintf(head->output, "BITMAP\n");
358 if ((rtn = PtnZoom(zoomptn, head->ptn[i], head->p_width,
359 head->p_height, head->bdf_width, head->bdf_height))) {
362 if( (rtn = PutBdfPtn(zoomptn, head->bdf_width,
363 head->bdf_height, head->output))) {
367 if( (rtn = PutBdfPtn(head->ptn[i],
368 head->bdf_width, head->bdf_height, head->output))) {
372 fprintf(head->output, "ENDCHAR\n");
375 fprintf(head->output, "ENDFONT\n");
383 #if NeedFunctionPrototypes
384 putDefaultChars( struct ptobhead *head )
386 putDefaultChars(head )
387 struct ptobhead *head;
390 int swidth, bytew, i, j;
391 unsigned int posbit ;
392 unsigned char *ptnbuf, *ptnbuf2 ;
395 put_default_encode( head ) ;
396 swidth = (head->bdf_width * 72270)/((int)(head->bdf_point * (float)head->bdf_xdpi));
397 fprintf(head->output, "SWIDTH %d 0\n", swidth);
398 fprintf(head->output, "DWIDTH %d 0\n", head->bdf_width);
399 fprintf( head->output, "BBX %d %d %d %d\n", head->bdf_width, head->bdf_height, head->bdf_x, head->bdf_y );
400 fprintf(head->output, "BITMAP\n");
402 bytew = (head->bdf_width + 7) / 8;
403 if ((ptnbuf = (unsigned char *)malloc(bytew * 2)) == NULL) {
404 return(MALLOC_ERROR);
406 put_default_bitmap(head, bytew, posbit, i, j, ptnbuf, ptnbuf2, tmp) ;
408 fprintf(head->output, "ENDCHAR\n");
415 #if NeedFunctionPrototypes
416 WritePtnToGpf( struct btophead *head )
419 struct btophead *head;
427 msize = ((head->p_width + 7) / 8) * head->p_height;
428 if ((zoomptn = (char *)malloc(msize)) == NULL) {
429 return(MALLOC_ERROR);
433 for (i=0; i<head->num_chars; i++) {
435 if ( head->code[i] > 0xff ) {
436 fprintf(head->output, "code:0x%x\n", SHIFT_ON(head->code[i]) );
438 fprintf(head->output, "code:0x%x\n", head->code[i]);
441 if ((rtn = PtnZoom(zoomptn, head->ptn[i], head->bdf_width,
442 head->bdf_height, head->p_width, head->p_height))) {
445 if ((rtn = PutGpfPtn(zoomptn, head->p_width,
446 head->p_height, head->output))) {
450 if ((rtn = PutGpfPtn(head->ptn[i],
451 head->bdf_width, head->bdf_height, head->output))) {
457 fprintf(head->output, "enddata\n");
463 #if NeedFunctionPrototypes
465 struct btophead *head,
469 ReadBdfToMemory(head, buf)
470 struct btophead *head;
474 int code, mwidth, num_char, bsize, rtn;
478 mwidth = (head->bdf_width + 7) / 8;
479 bsize = mwidth * head->bdf_height;
481 if ((rtn = GetBdfCode(head, buf, &code)) < 0) {
482 return(rtn); /* contain BDF_INVAL */
483 } else if (rtn == FILE_END) {
484 head->num_chars = num_char;
488 if ( ( code > head->end_code )
489 || ( code < head->start_code )
490 || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) )
491 || COMM_ISDEFAULTCHAR( code )
495 head->code[num_char] = code;
496 if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) {
497 return(MALLOC_ERROR);
500 if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) {
509 #if NeedFunctionPrototypes
510 ReadBdfToMemory_with_init(
511 struct btophead *head,
517 ReadBdfToMemory_with_init(head, init_start, init_end, buf)
518 struct btophead *head;
524 int code, mwidth, num_char, bsize, rtn;
528 mwidth = (head->bdf_width + 7) / 8;
529 bsize = mwidth * head->bdf_height;
531 if ((rtn = GetBdfCode(head, buf, &code)) < 0) {
532 return(rtn); /* contain BDF_INVAL */
533 } else if (rtn == FILE_END) {
534 head->num_chars = num_char;
538 if ( ( code > head->end_code )
539 || ( code < head->start_code )
540 || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) )
541 || ( ( code >= init_start ) && ( code <= init_end ) )
542 || COMM_ISDEFAULTCHAR( code )
547 head->code[num_char] = code;
548 if ((ptn = head->ptn[num_char++] =
549 (char *)malloc(bsize)) == NULL) {
550 return(MALLOC_ERROR);
553 if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) {
562 #if NeedFunctionPrototypes
564 struct btophead *head,
569 GetBdfCode(head, buf, code)
570 struct btophead *head;
578 if (fgets(buf, BUFSIZE, head->input) == NULL) {
583 if (!strncmp(p, ENDFONT, ENDFONTsz)) {
587 if (!strncmp(p, ENCODING, ENCODINGsz)) {
588 if ((sscanf(p, "ENCODING %d", code)) != 1) {
599 #if NeedFunctionPrototypes
601 struct btophead *head,
608 GetBdfPtn(head, buf, ptn, mwidth, bsize)
609 struct btophead *head;
620 if (fgets(buf, BUFSIZE, head->input) == NULL) {
625 if (!strncmp(p, BITMAP, BITMAPsz)) {
630 ptn[bsize - 1] = NULL;
632 for (i=0, skip=0; i<head->bdf_height; i++) {
634 for(j=0; j<mwidth; j++) {
640 if (fgets(buf, BUFSIZE, head->input) == NULL) {
645 if (!strncmp(p, ENDCHAR, ENDCHARsz)) {
647 for(j=0; j<mwidth; j++) {
653 GetBdfLinePtn(ptn, buf, head->bdf_width);
661 #if NeedFunctionPrototypes
663 struct ptobhead *head,
667 ReadGpfToMemory(head, buf)
668 struct ptobhead *head;
672 int code, mwidth, num_char, bsize, rtn;
676 mwidth = (head->p_width + 7) / 8;
677 bsize = mwidth * head->p_height;
679 if ((rtn = GetGpfCode(head, buf, &code)) < 0) {
680 return(rtn); /* contain GPF_INVAL */
681 } else if (rtn == FILE_END) {
682 head->num_chars = num_char;
685 if ( ( code > head->end_code )
686 || (code < head->start_code )
687 || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) )
688 || COMM_ISDEFAULTCHAR( code )
692 head->code[num_char] = code;
693 if ((ptn = head->ptn[num_char++] =
694 (char *)malloc(bsize)) == NULL) {
695 return(MALLOC_ERROR);
698 if ((rtn = GetGpfPtn(head, buf, ptn, mwidth, bsize)) != 0) {
707 #if NeedFunctionPrototypes
709 struct ptobhead *head,
714 GetGpfCode(head, buf, code)
715 struct ptobhead *head;
726 if (!strncmp(p, ENDDATA, ENDDATAsz)) {
729 if (!strncmp(p, CODE, CODEsz)) {
730 *code = (int)strtol(buf+CODEsz, NULL, 0);
731 CONVGLYPHINDEX( *code ) ;
735 if (fgets(buf, BUFSIZE, head->input) == NULL) {
744 #if NeedFunctionPrototypes
746 struct ptobhead *head,
753 GetGpfPtn(head, buf, ptn, mwidth, bsize)
754 struct ptobhead *head;
764 for (i=0, skip=0; i<head->p_height; i++) {
766 for (j=0; j<mwidth; j++) {
772 if (fgets(buf, BUFSIZE, head->input) == NULL) {
777 if ((!strncmp(p, CODE, CODEsz)) ||
778 (!strncmp(p, ENDDATA, ENDDATAsz))) {
780 for (j=0; j<mwidth; j++) {
787 GetGpfLinePtn(ptn, buf, head->p_width);
795 #if NeedFunctionPrototypes
802 GetBdfLinePtn(mem, buf, width)
815 iend = (width + 3) / 4;
817 if ((len = strlen(buf)) < iend) {
819 for (i=0; i<(iend-len); i++) {
825 for (i=0; i<iend/2; i++) {
828 *mem++ = (char)strtol(str, NULL, 16);
833 *mem = (char)strtol(str, NULL, 16) << 4;
838 #if NeedFunctionPrototypes
845 GetGpfLinePtn(mem, buf, width)
851 unsigned int skip, i, iend, j;
856 iend = (width + 7) / 8;
858 for (i=0, skip=0; i<iend; i++) {
863 for (j=0, ptn = NULL; j<8; j++) {
864 if ((*buf == '\n') || (*buf == NULL)) {
883 #if NeedFunctionPrototypes
891 PutBdfPtn(ptn, width, height, fp)
899 unsigned char *pbuf, x, c;
900 static unsigned char *buf=NULL;
903 buf = (unsigned char *)malloc(width*height+2);
905 return(MALLOC_ERROR);
908 nbyte = (width + 7) / 8;
911 for(i=0; i<height; i++) {
912 for (j=0 ; j<nbyte; j++) {
914 c = (x>=10)? 'a'-0xa : '0';
917 c = (x>=10)? 'a'-0xa : '0';
923 fprintf(fp, "%s", buf);
931 #if NeedFunctionPrototypes
939 PutGpfPtn(ptn, width, height, fp)
946 int i, j, k, nbyte, tw;
947 unsigned char p, *pbuf;
948 static unsigned char *buf=NULL;
951 buf = (unsigned char *)malloc(((width+1)*height)+1);
953 return(MALLOC_ERROR);
957 nbyte = (width + 7) / 8;
960 for(i=0; i<height; i++) {
961 for (j=0, tw=width; j<nbyte; j++) {
963 for (k=0; k<8 && tw>0; k++, tw--) {
975 fprintf(fp, "%s", buf);
981 #if NeedFunctionPrototypes
991 PtnZoom(dmem, smem, sw, sh, dw, dh)
1003 char *dbuf, *sp, *dp;
1005 swidth = (sw + 7) / 8;
1006 dwidth = (dw + 7) / 8;
1008 if ((dbuf = (char *)malloc(dwidth)) == NULL) {
1009 return(MALLOC_ERROR);
1016 for(i=0; i < sh; i++) {
1019 exline(sp, dbuf, sw, dw);
1022 memcpy(dp, dbuf, dwidth);
1024 for (; lcnt >= sh; lcnt -= sh) {
1025 memcpy(dp, dbuf, dwidth);
1038 exline(sp, dbuf, sw, dw)
1044 unsigned int i, bit, sval, dval, dcnt, bcnt;
1049 for(i=0; i<sw; i++) {
1053 bit = ((sval & 0x80) ? 1 : 0);
1055 for (bcnt += dw; bcnt >= sw; bcnt -= sw) {
1056 dval = (dval << 1) | bit;
1058 *dbuf++ = (char)dval;
1072 #if NeedFunctionPrototypes
1073 GetTmpPath( char *path )
1079 char *p=NULL, *sp, *buf ;
1081 struct stat statbuf ;
1083 /* Get directory of temporary file */
1084 if( !(p = (char *)getenv( "TMPDIR" )) ){
1085 p = DEFAULT_TMPPATH ;
1087 /* Get memory for temporary file name */
1090 if( *(sp + len -1) == '/' ){
1091 len += (strlen( TEMPFILEKEY ) + 1) ;
1093 len += (strlen( TEMPFILEKEY ) +1 + 1) ;
1095 if ((buf = (char *)malloc( len )) == NULL) {
1098 /* Get temporary file path */
1100 sp = buf + strlen(buf) -1 ;
1101 if( *sp == '/' ) *sp-- = '\0' ;
1102 sprintf( sp+1, "/%s", TEMPFILEKEY ) ;
1103 /* Get temporary file name */
1104 return mktemp( buf ) ;
1109 #if NeedFunctionPrototypes
1110 Link_NewFile( char *rd_file, char *wr_file )
1112 Link_NewFile( rd_file, wr_file )
1120 struct stat statbuf ;
1121 unsigned char bufc ;
1125 if( stat( wr_file, &statbuf ) == -1 ){
1126 if( (wfd = open( wr_file, O_CREAT | O_WRONLY, 0644 )) == -1 ){
1130 if( (wfd = open( wr_file, O_WRONLY | O_TRUNC )) == -1 ){
1134 if( stat( rd_file, &statbuf ) == -1 ){
1138 if( (rfd = open( rd_file, O_RDONLY )) == -1 ){
1144 if( (buf = (char *)mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, rfd, 0)) == (char *)-1 ){
1146 if( !(buf = (char *)malloc(statbuf.st_size)) ){
1151 if( read(rfd, buf, statbuf.st_size) != statbuf.st_size ){
1164 if( write(wfd, buf, statbuf.st_size) != statbuf.st_size ){
1167 munmap(buf, statbuf.st_size) ;
1175 return (DEVICE_FAIL);
1179 munmap(buf, statbuf.st_size) ;
1193 #if NeedFunctionPrototypes
1194 ChkNumString( char *str )
1203 num = (int)strtol( str, &tmp, 10 );
1204 if ((num == 0)&&(tmp == str)) {
1207 if ((size_t)(tmp - str) != strlen(str)){
1215 #if NeedFunctionPrototypes
1216 ErrMsgTable_AndExit(
1226 ErrMsgTable_AndExit(er_no, snf_in, snf_out, gpf_in, gpf_out, bdf_in, prog_name)
1241 USAGE2("%s : The input font file cannot be opened.\"%s\"¡¥\n", prog_name, (snf_in != NULL)? snf_in : "\0" );
1246 USAGE2("%s : The output font file cannot be opened.\"%s\"¡¥\n", prog_name, (snf_out != NULL)? snf_out : "\0" );
1252 USAGE2("%s : Information from the font file cannot be extracted.\"%s\"¡¥ \n", prog_name, (snf_in != NULL) ? snf_in : "\0" );
1257 USAGE2("%s : It is not possible to write to the font file.\"%s\"¡¥\n", prog_name, (snf_out != NULL) ? snf_out : "\0" );
1262 USAGE2("%s : The format of the font file is illegal.\"%s\"¡¥ \n", prog_name, (snf_in != NULL) ? snf_in : "\0" );
1266 case BDF_OPEN_HEAD :
1267 USAGE2("%s : The BDF file cannot be opened.\"%s\"¡¥\n", prog_name, (bdf_in != NULL)? bdf_in : "\0" );
1271 case BDF_READ_HEAD :
1272 USAGE2("%s : Information of the BDF file cannot be extracted.\"%s\"¡¥ \n", prog_name, (bdf_in != NULL) ? bdf_in : "\0" );
1277 USAGE2("%s : The input character pattern file cannot be opened.\"%s\"¡¥\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" );
1282 USAGE2("%s : The output character pattern file cannot be opened.\"%s\"¡¥\n", prog_name, (gpf_out != NULL) ? gpf_out : "\0" );
1287 USAGE2("%s : The character pattern file cannot be read.\"%s\"¡¥\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" );
1292 USAGE2("%s : It is not possible to write to the character pattern file.\"%s\"¡¥\n", prog_name, (gpf_out != NULL) ? gpf_out : "\0" );
1297 USAGE2("%s : The format of the character pattern file is illegal.\"%s\"¡¥\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" );
1302 fatal_err_msg( er_no, prog_name );
1311 #if NeedFunctionPrototypes
1317 fatal_err_msg( er_no, prog_name )
1322 USAGE1("%s : The font file failed to be converted. ", prog_name);
1325 USAGE("There is no memory any more.\n");
1328 USAGE("The child process cannot be created.\n" );
1331 USAGE("Cannot execute dtgpftobdf.\n" );
1334 USAGE("The pipe buffer cannot be open.\n" );
1337 USAGE("The file descripter cannot be duplicated.\n" );
1340 USAGE("The X font compiler cannot be executed.\n" );
1343 USAGE("The pipe buffer cannot be close.\n" );
1346 USAGE("The file descripter cannot be got.\n" );
1349 USAGE("The status of font cannot be got.\n" );
1352 USAGE("The temporally file cannot be got.\n" );
1354 case PCFFONTC_ERROR:
1355 USAGE("Cannot execute bdftopcf.\n" );
1357 case SNFFONTC_ERROR:
1358 USAGE("Cannot execute bdftosnf.\n" );
1361 USAGE1("Terminates abnormally. ( err_code(%d) )\n", er_no);
1369 static int sig_flg=0;
1371 #define GPF_BUCK_UP_FAIL 1
1372 #define GPF_MODIFY_FAIL 2
1373 #define RESTORE_FAIL 3
1374 #define CATCH_SIGNAL 10
1383 #if NeedFunctionPrototypes
1384 Put_File_Create_Err_Msg(
1392 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name, save_name, com )
1400 switch( msg_level ) {
1401 case GPF_BUCK_UP_FAIL:
1402 USAGE1("%s : Failed to write temporary file. Terminates abnormally.\n", com );
1403 put_file_create_err_msg = DEVICE_FAIL ;
1406 case GPF_MODIFY_FAIL:
1407 USAGE1("%s : Failed in the renewal of the font file. Terminates abnormally.\n", com );
1408 put_file_create_err_msg = WRITE_FAIL ;
1412 USAGE3("%s : The file before updating cannot be changed to former file name.\tPlease execute the following command after the inquiry the system manager.\n\t mv %s %s\n",
1413 com, save_name, org_name);
1414 put_file_create_err_msg = WRITE_FAIL ;
1418 USAGE1("%s : The signal was received. Terminates abnormally.\n", com);
1419 put_file_create_err_msg = 1 ;
1425 #if NeedFunctionPrototypes
1435 Make_NewFefFile( org_name, tmp_name, mode, owner, group, com )
1444 struct stat statbuf;
1445 char *save_name = NULL;
1451 signal( SIGHUP , (void(*)())ChatchSig);
1452 signal( SIGINT , (void(*)())ChatchSig);
1453 signal( SIGQUIT, (void(*)())ChatchSig);
1454 signal( SIGTERM, (void(*)())ChatchSig);
1456 sigset( SIGHUP , (void(*)())ChatchSig);
1457 sigset( SIGINT , (void(*)())ChatchSig);
1458 sigset( SIGQUIT, (void(*)())ChatchSig);
1459 sigset( SIGTERM, (void(*)())ChatchSig);
1463 if (sig_flg || ((save_name = GetTmpPath( org_name )) == NULL)) {
1464 msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_BUCK_UP_FAIL;
1465 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name,
1466 (char *)NULL, com );
1467 Unlink_Tmpfile ( tmp_name, com );
1468 return(put_file_create_err_msg);
1471 if (sig_flg || ((rtn=Link_NewFile( org_name, save_name )) != 0)) {
1472 msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_BUCK_UP_FAIL;
1473 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name,
1475 Unlink_Tmpfile ( save_name, com );
1476 Unlink_Tmpfile ( tmp_name, com );
1477 return( (put_file_create_err_msg == DEVICE_FAIL)?
1478 put_file_create_err_msg : rtn );
1481 if (sig_flg || ((rtn=Link_NewFile( tmp_name, org_name )) != 0)) {
1482 msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_MODIFY_FAIL;
1483 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name,
1485 if ( (rtn=Link_NewFile( save_name, org_name )) != 0 ) {
1486 Put_File_Create_Err_Msg( RESTORE_FAIL, org_name,
1487 tmp_name, save_name, com );
1488 Unlink_Tmpfile ( tmp_name, com );
1490 Unlink_Tmpfile ( tmp_name, com );
1491 Unlink_Tmpfile ( save_name, com );
1493 return( (put_file_create_err_msg == DEVICE_FAIL)?
1494 put_file_create_err_msg : rtn );
1498 ret_val += Unlink_Tmpfile ( tmp_name, com );
1499 ret_val += Unlink_Tmpfile ( save_name, com );
1501 return( (ret_val)? 1 : 0 );
1506 #if NeedFunctionPrototypes
1512 Unlink_Tmpfile( file, com )
1518 if ( unlink( file ) != 0 ) {
1519 USAGE2("%s : The work file cannot be deleted. Please unlink the following files\tafter the inquiry the system manager.\"%s\" \n", com, file );
1527 #if NeedFunctionPrototypes
1534 Chmod_File ( fname, mode, com )
1541 if ( mode == 0 ) return( 0 ) ;
1542 if ( chmod (fname, mode) != 0) {
1543 USAGE3("%s : Failed in the mode change of the following files. Please change the mode to %o\tafter the inquiry the system manager.\"%s\" \n", com, (int)mode, fname );
1551 #if NeedFunctionPrototypes
1559 Chown_File ( fname, owner, group, com )
1567 if ( chown (fname, owner, group) != 0) {
1568 USAGE2("%s : Failed in setteing of the owner and the group of the following files. \tPlease change to the file of the owner and the group of following ID \tafter the inquiry the system manager.\"%s\"\n", com, fname );
1569 USAGE1("\t\t Owner ID ¡§%d\n", (int)owner);
1570 USAGE1("\t\t Group ID ¡§%d\n", (int)group);
1580 #if NeedFunctionPrototypes
1581 ChkPcfFontFile( char *filename )
1583 ChkPcfFontFile( filename )
1592 suffix = ( char * )strrchr( filename, '.' );
1597 return strcmp( PCFSUFFIX, suffix );
1602 #if NeedFunctionPrototypes
1603 ChkSnfFontFile( char *filename )
1605 ChkSnfFontFile( filename )
1614 suffix = ( char * )strrchr( filename, '.' );
1619 return strcmp( SNFSUFFIX, suffix );
1624 #if NeedFunctionPrototypes
1630 get_cmd_path( path, cmd )
1640 if ( !path || !cmd ) {
1644 for ( ; end = ( char * )strchr( path, ':' ); path = end + 1 ) {
1647 AllocString( cmd_path, path, NULL ) ;
1650 AddString( cmd_path, "/", NULL ) ;
1651 AddString( cmd_path, cmd, NULL ) ;
1653 if ( stat( cmd_path, &st ) == 0 ) {
1654 if( st.st_mode & S_IFREG ) {
1655 cmd_path = realloc( cmd_path, strlen( cmd_path ) + 1 );
1659 FreeString( cmd_path ) ;
1661 AllocString( cmd_path, path, NULL ) ;
1662 AddString( cmd_path, "/", NULL ) ;
1663 AddString( cmd_path, cmd, NULL ) ;
1664 if ( stat( cmd_path, &st ) == 0 ) {
1665 if( st.st_mode & S_IFREG ) {
1666 cmd_path = realloc( cmd_path, strlen( cmd_path ) + 1 );
1675 #if NeedFunctionPrototypes
1683 SetCmdPath( com, path, dflt_path, cmd )
1690 struct stat statbuf ;
1693 if( stat( dflt_path, &statbuf ) ){
1694 if( !( pbuf = (char *)get_cmd_path( getenv( "PATH" ), cmd )) ){
1695 USAGE2("%s: There is not \"%s\" command in \"PATH\".\n", com, cmd ) ;
1698 if( stat( pbuf, &statbuf ) ){
1699 USAGE2("%s: There is not \"%s\" command.\n", com, cmd ) ;
1702 if( !(statbuf.st_mode & S_IXUSR) ){
1703 USAGE2("%s: \"%s\" command don't have permission to execute.\n", com, cmd ) ;
1707 if( !(statbuf.st_mode & S_IXUSR) ){
1708 USAGE2("%s: \"%s\" command don't have permission to execute.\n", com, cmd ) ;
1717 /*****************************< end of oakfuty.c >************************/