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: 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>
58 char *bdftosnf = BDFTOSNF;
61 static int put_file_create_err_msg = 0;
69 #if NeedFunctionPrototypes
71 struct btophead *head,
75 ReadBdfHeader( head, buf )
76 struct btophead *head;
81 unsigned int getstat = 0;
83 if (NULL == fgets(buf, BUFSIZE, head->input)) {
89 if (strncmp(p, STARTFONT, STARTFONTsz)) {
94 if (fgets(buf, BUFSIZE, head->input) == NULL) {
99 if (!strncmp(p, SIZE, SIZEsz)) {
100 if ((sscanf(p, "SIZE %f%d",
101 &(head->bdf_point), &(head->bdf_xdpi))) != 2) {
105 } else if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) {
106 if (sscanf(p, "FONTBOUNDINGBOX %d%d%d%d",
107 &(head->bdf_width), &(head->bdf_height),
108 &(head->bdf_x), &(head->bdf_y)) != 4) {
113 } else if (!strncmp(p, CHARS, CHARSsz)) {
114 if ((sscanf(p, "CHARS %d", &(head->num_chars))) != 1) {
118 } else if (!strncmp(p, STARTCHAR, STARTCHARsz)) {
123 if (getstat != 0x07) {
131 #if NeedFunctionPrototypes
133 struct ptobhead *head,
137 ReadGpfHeader(head, buf)
138 struct ptobhead *head;
143 unsigned int getstat = 0;
146 if (getstat == 0x07) break;
148 if (fgets(buf, BUFSIZE, head->input) == NULL) {
154 if (!strncmp(p, NUMFONTS, NUMFONTSsz)) {
155 if (sscanf(p, "numfonts:%d", &(head->num_chars)) != 1) {
159 } else if (!strncmp(p, WIDTH, WIDTHsz)) {
160 if (sscanf(p, "width:%d", &(head->p_width)) != 1) {
164 } else if (!strncmp(p, HEIGHT, HEIGHTsz)) {
165 if (sscanf(p, "height:%d", &(head->p_height)) != 1) {
176 #if NeedFunctionPrototypes
177 WriteBdfHeader( struct ptobhead *head )
180 struct ptobhead *head;
185 unsigned int getstat;
186 char buf[BUFSIZE], *p;
189 #if defined( SVR4 ) || defined( SYSV ) || defined(CSRG_BASED) || defined(__linux__)
192 union wait chld_stat ;
196 if (head->snf_file != NULL) {
200 switch (chld_pid = fork()) {
208 execl( oakgtobdf, oakgtobdf, head->snf_file, 0);
219 if((fp = (FILE *)fdopen(fd[0], "r")) == NULL) {
221 kill( chld_pid, SIGKILL );
222 WaitID( chld_pid, chld_stat ) ;
226 if ((fp = fopen(head->bdf_file, "r")) == NULL) {
227 return(BDF_OPEN_HEAD);
234 if (fgets(buf, BUFSIZE, fp) == NULL) {
236 if (head->snf_file != NULL) {
237 kill( chld_pid, SIGKILL );
238 WaitID( chld_pid, chld_stat ) ;
245 if (!strncmp(p, CHARS, CHARSsz)) {
247 if (head->snf_file != NULL) {
248 kill( chld_pid, SIGKILL );
249 WaitID( chld_pid, chld_stat ) ;
254 fprintf(head->output, "%s", buf);
256 if (!strncmp(p, SIZE, SIZEsz)) {
257 if ((sscanf(p, "SIZE %f%d",
258 &(head->bdf_point), &(head->bdf_xdpi))) != 2) {
260 if (head->snf_file != NULL) {
261 kill( chld_pid, SIGKILL );
262 WaitID( chld_pid, chld_stat ) ;
269 if (!strncmp(p, FONTBOUNDINGBOX, FONTBOUNDINGBOXsz)) {
270 if ( sscanf( p, "FONTBOUNDINGBOX %d%d%d%d",
277 if (head->snf_file != NULL) {
278 kill( chld_pid, SIGKILL );
279 WaitID( chld_pid, chld_stat ) ;
286 get_charset_registry(head, p) ;
290 if (getstat != 0x03) {
299 #if NeedFunctionPrototypes
300 WriteGpfHeader( struct btophead *head )
303 struct btophead *head;
306 fprintf(head->output, "numfonts:%d\n", head->num_chars);
307 fprintf(head->output, "width:%d\n", head->p_width );
308 fprintf(head->output, "height:%d\n", head->p_height );
315 #if NeedFunctionPrototypes
316 WritePtnToBdf( struct ptobhead *head )
319 struct ptobhead *head;
322 int msize, swidth, rtn, i, nchar;
324 int bbw, bbh, bbx, bby, dw ;
325 char glyph_name[BUFSIZE] ;
327 nchar = head->num_chars;
328 put_default_chars(head, nchar, rtn) ;
331 msize = ((head->bdf_width + 7) / 8) * head->bdf_height;
332 if ((zoomptn = (char *)malloc(msize)) == NULL) {
333 return(MALLOC_ERROR);
337 for (i=0; i<head->num_chars; i++) {
338 sprintf( glyph_name, "%x", head->code[i]);
339 swidth = (head->bdf_width * 72270)/((int)(head->bdf_point * (float)head->bdf_xdpi));
340 dw = head->bdf_width ;
341 bbw = head->bdf_width ;
342 bbh = head->bdf_height ;
346 fprintf(head->output, "STARTCHAR %s\n", glyph_name );
347 fprintf(head->output, "ENCODING %d\n", head->code[i]);
348 fprintf(head->output, "SWIDTH %d 0\n", swidth );
349 fprintf(head->output, "DWIDTH %d 0\n", dw );
350 fprintf(head->output, "BBX %d %d %d %d\n", bbw, bbh, bbx, bby );
351 fprintf(head->output, "BITMAP\n");
354 if ((rtn = PtnZoom(zoomptn, head->ptn[i], head->p_width,
355 head->p_height, head->bdf_width, head->bdf_height))) {
358 if( (rtn = PutBdfPtn(zoomptn, head->bdf_width,
359 head->bdf_height, head->output))) {
363 if( (rtn = PutBdfPtn(head->ptn[i],
364 head->bdf_width, head->bdf_height, head->output))) {
368 fprintf(head->output, "ENDCHAR\n");
371 fprintf(head->output, "ENDFONT\n");
379 #if NeedFunctionPrototypes
380 putDefaultChars( struct ptobhead *head )
382 putDefaultChars(head )
383 struct ptobhead *head;
386 int swidth, bytew, i, j;
387 unsigned int posbit ;
388 unsigned char *ptnbuf, *ptnbuf2 ;
391 put_default_encode( head ) ;
392 swidth = (head->bdf_width * 72270)/((int)(head->bdf_point * (float)head->bdf_xdpi));
393 fprintf(head->output, "SWIDTH %d 0\n", swidth);
394 fprintf(head->output, "DWIDTH %d 0\n", head->bdf_width);
395 fprintf( head->output, "BBX %d %d %d %d\n", head->bdf_width, head->bdf_height, head->bdf_x, head->bdf_y );
396 fprintf(head->output, "BITMAP\n");
398 bytew = (head->bdf_width + 7) / 8;
399 if ((ptnbuf = (unsigned char *)malloc(bytew * 2)) == NULL) {
400 return(MALLOC_ERROR);
402 put_default_bitmap(head, bytew, posbit, i, j, ptnbuf, ptnbuf2, tmp) ;
404 fprintf(head->output, "ENDCHAR\n");
411 #if NeedFunctionPrototypes
412 WritePtnToGpf( struct btophead *head )
415 struct btophead *head;
423 msize = ((head->p_width + 7) / 8) * head->p_height;
424 if ((zoomptn = (char *)malloc(msize)) == NULL) {
425 return(MALLOC_ERROR);
429 for (i=0; i<head->num_chars; i++) {
431 if ( head->code[i] > 0xff ) {
432 fprintf(head->output, "code:0x%x\n", SHIFT_ON(head->code[i]) );
434 fprintf(head->output, "code:0x%x\n", head->code[i]);
437 if ((rtn = PtnZoom(zoomptn, head->ptn[i], head->bdf_width,
438 head->bdf_height, head->p_width, head->p_height))) {
441 if ((rtn = PutGpfPtn(zoomptn, head->p_width,
442 head->p_height, head->output))) {
446 if ((rtn = PutGpfPtn(head->ptn[i],
447 head->bdf_width, head->bdf_height, head->output))) {
453 fprintf(head->output, "enddata\n");
459 #if NeedFunctionPrototypes
461 struct btophead *head,
465 ReadBdfToMemory(head, buf)
466 struct btophead *head;
470 int code, mwidth, num_char, bsize, rtn;
474 mwidth = (head->bdf_width + 7) / 8;
475 bsize = mwidth * head->bdf_height;
477 if ((rtn = GetBdfCode(head, buf, &code)) < 0) {
478 return(rtn); /* contain BDF_INVAL */
479 } else if (rtn == FILE_END) {
480 head->num_chars = num_char;
484 if ( ( code > head->end_code )
485 || ( code < head->start_code )
486 || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) )
487 || COMM_ISDEFAULTCHAR( code )
491 head->code[num_char] = code;
492 if ( ( ptn = head->ptn[num_char++] = (char *)malloc( bsize ) ) == NULL ) {
493 return(MALLOC_ERROR);
496 if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) {
505 #if NeedFunctionPrototypes
506 ReadBdfToMemory_with_init(
507 struct btophead *head,
513 ReadBdfToMemory_with_init(head, init_start, init_end, buf)
514 struct btophead *head;
520 int code, mwidth, num_char, bsize, rtn;
524 mwidth = (head->bdf_width + 7) / 8;
525 bsize = mwidth * head->bdf_height;
527 if ((rtn = GetBdfCode(head, buf, &code)) < 0) {
528 return(rtn); /* contain BDF_INVAL */
529 } else if (rtn == FILE_END) {
530 head->num_chars = num_char;
534 if ( ( code > head->end_code )
535 || ( code < head->start_code )
536 || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) )
537 || ( ( code >= init_start ) && ( code <= init_end ) )
538 || COMM_ISDEFAULTCHAR( code )
543 head->code[num_char] = code;
544 if ((ptn = head->ptn[num_char++] =
545 (char *)malloc(bsize)) == NULL) {
546 return(MALLOC_ERROR);
549 if ((rtn = GetBdfPtn(head, buf, ptn, mwidth, bsize)) != 0) {
558 #if NeedFunctionPrototypes
560 struct btophead *head,
565 GetBdfCode(head, buf, code)
566 struct btophead *head;
574 if (fgets(buf, BUFSIZE, head->input) == NULL) {
579 if (!strncmp(p, ENDFONT, ENDFONTsz)) {
583 if (!strncmp(p, ENCODING, ENCODINGsz)) {
584 if ((sscanf(p, "ENCODING %d", code)) != 1) {
595 #if NeedFunctionPrototypes
597 struct btophead *head,
604 GetBdfPtn(head, buf, ptn, mwidth, bsize)
605 struct btophead *head;
616 if (fgets(buf, BUFSIZE, head->input) == NULL) {
621 if (!strncmp(p, BITMAP, BITMAPsz)) {
628 for (i=0, skip=0; i<head->bdf_height; i++) {
630 for(j=0; j<mwidth; j++) {
636 if (fgets(buf, BUFSIZE, head->input) == NULL) {
641 if (!strncmp(p, ENDCHAR, ENDCHARsz)) {
643 for(j=0; j<mwidth; j++) {
649 GetBdfLinePtn(ptn, buf, head->bdf_width);
657 #if NeedFunctionPrototypes
659 struct ptobhead *head,
663 ReadGpfToMemory(head, buf)
664 struct ptobhead *head;
668 int code, mwidth, num_char, bsize, rtn;
672 mwidth = (head->p_width + 7) / 8;
673 bsize = mwidth * head->p_height;
675 if ((rtn = GetGpfCode(head, buf, &code)) < 0) {
676 return(rtn); /* contain GPF_INVAL */
677 } else if (rtn == FILE_END) {
678 head->num_chars = num_char;
681 if ( ( code > head->end_code )
682 || (code < head->start_code )
683 || ( !IN_CODE( head->code_category, SHIFT_ON( code ) ) )
684 || COMM_ISDEFAULTCHAR( code )
688 head->code[num_char] = code;
689 if ((ptn = head->ptn[num_char++] =
690 (char *)malloc(bsize)) == NULL) {
691 return(MALLOC_ERROR);
694 if ((rtn = GetGpfPtn(head, buf, ptn, mwidth, bsize)) != 0) {
703 #if NeedFunctionPrototypes
705 struct ptobhead *head,
710 GetGpfCode(head, buf, code)
711 struct ptobhead *head;
722 if (!strncmp(p, ENDDATA, ENDDATAsz)) {
725 if (!strncmp(p, CODE, CODEsz)) {
726 *code = (int)strtol(buf+CODEsz, NULL, 0);
727 CONVGLYPHINDEX( *code ) ;
731 if (fgets(buf, BUFSIZE, head->input) == NULL) {
740 #if NeedFunctionPrototypes
742 struct ptobhead *head,
749 GetGpfPtn(head, buf, ptn, mwidth, bsize)
750 struct ptobhead *head;
760 for (i=0, skip=0; i<head->p_height; i++) {
762 for (j=0; j<mwidth; j++) {
768 if (fgets(buf, BUFSIZE, head->input) == NULL) {
773 if ((!strncmp(p, CODE, CODEsz)) ||
774 (!strncmp(p, ENDDATA, ENDDATAsz))) {
776 for (j=0; j<mwidth; j++) {
783 GetGpfLinePtn(ptn, buf, head->p_width);
791 #if NeedFunctionPrototypes
798 GetBdfLinePtn(mem, buf, width)
811 iend = (width + 3) / 4;
813 if ((len = strlen(buf)) < iend) {
815 for (i=0; i<(iend-len); i++) {
821 for (i=0; i<iend/2; i++) {
824 *mem++ = (char)strtol(str, NULL, 16);
829 *mem = (char)strtol(str, NULL, 16) << 4;
834 #if NeedFunctionPrototypes
841 GetGpfLinePtn(mem, buf, width)
847 unsigned int skip, i, iend, j;
852 iend = (width + 7) / 8;
854 for (i=0, skip=0; i<iend; i++) {
859 for (j=0, ptn = 0; j<8; j++) {
860 if ((*buf == '\n') || (*buf == 0)) {
879 #if NeedFunctionPrototypes
887 PutBdfPtn(ptn, width, height, fp)
895 unsigned char *pbuf, x, c;
896 static unsigned char *buf=NULL;
899 buf = (unsigned char *)malloc(width*height+2);
901 return(MALLOC_ERROR);
904 nbyte = (width + 7) / 8;
907 for(i=0; i<height; i++) {
908 for (j=0 ; j<nbyte; j++) {
910 c = (x>=10)? 'a'-0xa : '0';
913 c = (x>=10)? 'a'-0xa : '0';
919 fprintf(fp, "%s", buf);
927 #if NeedFunctionPrototypes
935 PutGpfPtn(ptn, width, height, fp)
942 int i, j, k, nbyte, tw;
943 unsigned char p, *pbuf;
944 static unsigned char *buf=NULL;
947 buf = (unsigned char *)malloc(((width+1)*height)+1);
949 return(MALLOC_ERROR);
953 nbyte = (width + 7) / 8;
956 for(i=0; i<height; i++) {
957 for (j=0, tw=width; j<nbyte; j++) {
959 for (k=0; k<8 && tw>0; k++, tw--) {
971 fprintf(fp, "%s", buf);
977 #if NeedFunctionPrototypes
987 PtnZoom(dmem, smem, sw, sh, dw, dh)
999 char *dbuf, *sp, *dp;
1001 swidth = (sw + 7) / 8;
1002 dwidth = (dw + 7) / 8;
1004 if ((dbuf = (char *)malloc(dwidth)) == NULL) {
1005 return(MALLOC_ERROR);
1012 for(i=0; i < sh; i++) {
1015 exline(sp, dbuf, sw, dw);
1018 memcpy(dp, dbuf, dwidth);
1020 for (; lcnt >= sh; lcnt -= sh) {
1021 memcpy(dp, dbuf, dwidth);
1034 exline(sp, dbuf, sw, dw)
1040 unsigned int i, bit, sval, dval, dcnt, bcnt;
1045 for(i=0; i<sw; i++) {
1049 bit = ((sval & 0x80) ? 1 : 0);
1051 for (bcnt += dw; bcnt >= sw; bcnt -= sw) {
1052 dval = (dval << 1) | bit;
1054 *dbuf++ = (char)dval;
1068 #if NeedFunctionPrototypes
1069 GetTmpPath( char *path )
1075 char *p=NULL, *sp, *buf ;
1077 struct stat statbuf ;
1079 /* Get directory of temporary file */
1080 if( !(p = (char *)getenv( "TMPDIR" )) ){
1081 p = DEFAULT_TMPPATH ;
1083 /* Get memory for temporary file name */
1086 if( *(sp + len -1) == '/' ){
1087 len += (strlen( TEMPFILEKEY ) + 1) ;
1089 len += (strlen( TEMPFILEKEY ) +1 + 1) ;
1091 if ((buf = (char *)malloc( len )) == NULL) {
1094 /* Get temporary file path */
1096 sp = buf + strlen(buf) -1 ;
1097 if( *sp == '/' ) *sp-- = '\0' ;
1098 sprintf( sp+1, "/%s", TEMPFILEKEY ) ;
1099 /* Get temporary file name */
1100 return mktemp( buf ) ;
1105 #if NeedFunctionPrototypes
1106 Link_NewFile( char *rd_file, char *wr_file )
1108 Link_NewFile( rd_file, wr_file )
1116 struct stat statbuf ;
1117 unsigned char bufc ;
1121 if( stat( wr_file, &statbuf ) == -1 ){
1122 if( (wfd = open( wr_file, O_CREAT | O_WRONLY, 0644 )) == -1 ){
1126 if( (wfd = open( wr_file, O_WRONLY | O_TRUNC )) == -1 ){
1130 if( stat( rd_file, &statbuf ) == -1 ){
1134 if( (rfd = open( rd_file, O_RDONLY )) == -1 ){
1140 if( (buf = (char *)mmap(0, statbuf.st_size, PROT_READ, MAP_SHARED, rfd, 0)) == (char *)-1 ){
1142 if( !(buf = (char *)malloc(statbuf.st_size)) ){
1147 if( read(rfd, buf, statbuf.st_size) != statbuf.st_size ){
1161 if( write(wfd, buf, statbuf.st_size) != statbuf.st_size ){
1164 munmap(buf, statbuf.st_size) ;
1172 return (DEVICE_FAIL);
1176 munmap(buf, statbuf.st_size) ;
1190 #if NeedFunctionPrototypes
1191 ChkNumString( char *str )
1200 num = (int)strtol( str, &tmp, 10 );
1201 if ((num == 0)&&(tmp == str)) {
1204 if ((size_t)(tmp - str) != strlen(str)){
1212 #if NeedFunctionPrototypes
1213 ErrMsgTable_AndExit(
1223 ErrMsgTable_AndExit(er_no, snf_in, snf_out, gpf_in, gpf_out, bdf_in, prog_name)
1238 USAGE2("%s : The input font file cannot be opened.\"%s\"\A1\A5\n", prog_name, (snf_in != NULL)? snf_in : "\0" );
1243 USAGE2("%s : The output font file cannot be opened.\"%s\"\A1\A5\n", prog_name, (snf_out != NULL)? snf_out : "\0" );
1249 USAGE2("%s : Information from the font file cannot be extracted.\"%s\"\A1\A5 \n", prog_name, (snf_in != NULL) ? snf_in : "\0" );
1254 USAGE2("%s : It is not possible to write to the font file.\"%s\"\A1\A5\n", prog_name, (snf_out != NULL) ? snf_out : "\0" );
1259 USAGE2("%s : The format of the font file is illegal.\"%s\"\A1\A5 \n", prog_name, (snf_in != NULL) ? snf_in : "\0" );
1263 case BDF_OPEN_HEAD :
1264 USAGE2("%s : The BDF file cannot be opened.\"%s\"\A1\A5\n", prog_name, (bdf_in != NULL)? bdf_in : "\0" );
1268 case BDF_READ_HEAD :
1269 USAGE2("%s : Information of the BDF file cannot be extracted.\"%s\"\A1\A5 \n", prog_name, (bdf_in != NULL) ? bdf_in : "\0" );
1274 USAGE2("%s : The input character pattern file cannot be opened.\"%s\"\A1\A5\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" );
1279 USAGE2("%s : The output character pattern file cannot be opened.\"%s\"\A1\A5\n", prog_name, (gpf_out != NULL) ? gpf_out : "\0" );
1284 USAGE2("%s : The character pattern file cannot be read.\"%s\"\A1\A5\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" );
1289 USAGE2("%s : It is not possible to write to the character pattern file.\"%s\"\A1\A5\n", prog_name, (gpf_out != NULL) ? gpf_out : "\0" );
1294 USAGE2("%s : The format of the character pattern file is illegal.\"%s\"\A1\A5\n", prog_name, (gpf_in != NULL) ? gpf_in : "\0" );
1299 fatal_err_msg( er_no, prog_name );
1308 #if NeedFunctionPrototypes
1314 fatal_err_msg( er_no, prog_name )
1319 USAGE1("%s : The font file failed to be converted. ", prog_name);
1322 USAGE("There is no memory any more.\n");
1325 USAGE("The child process cannot be created.\n" );
1328 USAGE("Cannot execute dtgpftobdf.\n" );
1331 USAGE("The pipe buffer cannot be open.\n" );
1334 USAGE("The file descripter cannot be duplicated.\n" );
1337 USAGE("The X font compiler cannot be executed.\n" );
1340 USAGE("The pipe buffer cannot be close.\n" );
1343 USAGE("The file descripter cannot be got.\n" );
1346 USAGE("The status of font cannot be got.\n" );
1349 USAGE("The temporally file cannot be got.\n" );
1351 case PCFFONTC_ERROR:
1352 USAGE("Cannot execute bdftopcf.\n" );
1354 case SNFFONTC_ERROR:
1355 USAGE("Cannot execute bdftosnf.\n" );
1358 USAGE1("Terminates abnormally. ( err_code(%d) )\n", er_no);
1366 static int sig_flg=0;
1368 #define GPF_BUCK_UP_FAIL 1
1369 #define GPF_MODIFY_FAIL 2
1370 #define RESTORE_FAIL 3
1371 #define CATCH_SIGNAL 10
1380 #if NeedFunctionPrototypes
1381 Put_File_Create_Err_Msg(
1389 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name, save_name, com )
1397 switch( msg_level ) {
1398 case GPF_BUCK_UP_FAIL:
1399 USAGE1("%s : Failed to write temporary file. Terminates abnormally.\n", com );
1400 put_file_create_err_msg = DEVICE_FAIL ;
1403 case GPF_MODIFY_FAIL:
1404 USAGE1("%s : Failed in the renewal of the font file. Terminates abnormally.\n", com );
1405 put_file_create_err_msg = WRITE_FAIL ;
1409 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",
1410 com, save_name, org_name);
1411 put_file_create_err_msg = WRITE_FAIL ;
1415 USAGE1("%s : The signal was received. Terminates abnormally.\n", com);
1416 put_file_create_err_msg = 1 ;
1422 #if NeedFunctionPrototypes
1432 Make_NewFefFile( org_name, tmp_name, mode, owner, group, com )
1441 struct stat statbuf;
1442 char *save_name = NULL;
1448 signal( SIGHUP , (void(*)())ChatchSig);
1449 signal( SIGINT , (void(*)())ChatchSig);
1450 signal( SIGQUIT, (void(*)())ChatchSig);
1451 signal( SIGTERM, (void(*)())ChatchSig);
1453 sigset( SIGHUP , (void(*)())ChatchSig);
1454 sigset( SIGINT , (void(*)())ChatchSig);
1455 sigset( SIGQUIT, (void(*)())ChatchSig);
1456 sigset( SIGTERM, (void(*)())ChatchSig);
1460 if (sig_flg || ((save_name = GetTmpPath( org_name )) == NULL)) {
1461 msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_BUCK_UP_FAIL;
1462 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name,
1463 (char *)NULL, com );
1464 Unlink_Tmpfile ( tmp_name, com );
1465 return(put_file_create_err_msg);
1468 if (sig_flg || ((rtn=Link_NewFile( org_name, save_name )) != 0)) {
1469 msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_BUCK_UP_FAIL;
1470 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name,
1472 Unlink_Tmpfile ( save_name, com );
1473 Unlink_Tmpfile ( tmp_name, com );
1475 return( (put_file_create_err_msg == DEVICE_FAIL)?
1476 put_file_create_err_msg : rtn );
1479 if (sig_flg || ((rtn=Link_NewFile( tmp_name, org_name )) != 0)) {
1480 msg_level = (sig_flg) ? CATCH_SIGNAL : GPF_MODIFY_FAIL;
1481 Put_File_Create_Err_Msg( msg_level, org_name, tmp_name,
1483 if ( (rtn=Link_NewFile( save_name, org_name )) != 0 ) {
1484 Put_File_Create_Err_Msg( RESTORE_FAIL, org_name,
1485 tmp_name, save_name, com );
1486 Unlink_Tmpfile ( tmp_name, com );
1488 Unlink_Tmpfile ( tmp_name, com );
1489 Unlink_Tmpfile ( save_name, com );
1492 return( (put_file_create_err_msg == DEVICE_FAIL)?
1493 put_file_create_err_msg : rtn );
1497 ret_val += Unlink_Tmpfile ( tmp_name, com );
1498 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 \A1\A7%d\n", (int)owner);
1570 USAGE1("\t\t Group ID \A1\A7%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 )
1635 char *cmd_path = NULL;
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 ) ;
1662 AllocString( cmd_path, path, NULL ) ;
1663 AddString( cmd_path, "/", NULL ) ;
1664 AddString( cmd_path, cmd, NULL ) ;
1665 if ( stat( cmd_path, &st ) == 0 ) {
1666 if( st.st_mode & S_IFREG ) {
1667 cmd_path = realloc( cmd_path, strlen( cmd_path ) + 1 );
1676 #if NeedFunctionPrototypes
1684 SetCmdPath( com, path, dflt_path, cmd )
1691 struct stat statbuf ;
1694 if( stat( dflt_path, &statbuf ) ){
1695 if( !( pbuf = (char *)get_cmd_path( getenv( "PATH" ), cmd )) ){
1696 USAGE2("%s: There is not \"%s\" command in \"PATH\".\n", com, cmd ) ;
1699 if( stat( pbuf, &statbuf ) ){
1700 USAGE2("%s: There is not \"%s\" command.\n", com, cmd ) ;
1704 if( !(statbuf.st_mode & S_IXUSR) ){
1705 USAGE2("%s: \"%s\" command don't have permission to execute.\n", com, cmd ) ;
1710 if( !(statbuf.st_mode & S_IXUSR) ){
1711 USAGE2("%s: \"%s\" command don't have permission to execute.\n", com, cmd ) ;
1720 /*****************************< end of oakfuty.c >************************/