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: lsgpf.c /main/7 1996/11/08 02:05:57 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
43 static void dsp_info_list();
44 static void dsp_title();
45 static void dspinfo_1line();
46 static void disp_no_fontslist();
47 static void sort_offset_list() ;
48 static int sort_fontlist() ;
49 static void dsp_error_title() ;
50 static int dsp_error_files() ;
52 static void put_help();
53 static int search_fontfile_name() ;
54 static int get_new_target() ;
56 static char *utillocale ;
57 static char *fontdir ;
58 static char *command_name ;
68 /* request for sort */
69 #define REQ_STYLE (1<<1)
70 #define REQ_CHARSIZE (1<<2)
71 #define REQ_LETTER (1<<3)
72 #define REQ_DELEQUAL (1<<16)
75 #define NO_FONT (1<<1)
76 #define SAME_FONT (1<<2)
77 #define REDEFINED_FONT (1<<3)
90 FalFontDataList *lst_m; /* font information list struct */
91 FalFontData key; /* font reference information creation struct */
92 MISS_ENTRY unknown_m ; /* error */
94 int code_sw; /* code set flag */
102 command_name = argv[0] ;
108 /* get locale strings */
109 if( (utillocale = (char *)getenv( "LANG" )) == NULL ){
113 if( (fontdir = (char *)getenv( "DTUDCFONTS" )) == (char *)NULL ) {
114 fontdir = DTUDCFONTSLISTDIR ;
118 * dtlsgpf check on which options are required.
120 for (i=1 ; i < argc ; i++) {
122 if (!strcmp(argv[i], "-help")) {
126 if (*argv[i] != '-') {
131 if ( !strcmp( argv[i], "-codeset" ) ) {
133 if ( (i+1) >= argc ){
138 code_set = (int)strtol( argv[i], &cbuf, 10 ) ;
139 if( argv[i] == cbuf ) {
146 for (j=1; argv[i][j] != '\0' ; j++) {
149 if ( req == 'l') dsp_opt |= L_OPT ;
150 else if ( req == 'a') dsp_opt |= A_OPT ;
151 else if ( req == 'x') dsp_opt |= X_OPT ;
152 else if ( req == 'C') dsp_opt |= C_OPT ;
161 if( dsp_opt == ( A_OPT | X_OPT ) ) dsp_opt = A_OPT ;
164 * display information list of UDC code region
166 if( dsp_opt & C_OPT ){
167 fprintf(stdout ,"codeset\t\tcode area\n");
168 fprintf(stdout ,"--------------------------------------------\n");
169 if ( DispUdcCpArea( stdout ) == -1 ){
170 ErrMsgTable_FalGetFontList( argv[0], fal_utyerror, fal_utyderror );
177 * get an information list of UDC fonts
180 mask = FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_DEFINED ;
182 mask |= FAL_FONT_MASK_CODE_SET ;
183 key.cd_set = FALGETFALCODESET( code_set ) ;
186 /* get font information list */
187 if ( FalGetFontList( &key, mask, &lst_m ) == FAL_ERROR ){
188 ErrMsgTable_FalGetFontList( argv[0], fal_utyerror, fal_utyderror );
192 /* sort element of font infomation list */
193 if( sort_fontlist( lst_m ) == FAL_ERROR ) {
194 FalFreeFontList( lst_m );
199 * dtlsgpf shows UDC informations as user's request.
201 dsp_title( stdout, dsp_opt );
202 if ( lst_m->num == 0) {
203 disp_no_fontslist( dsp_opt ) ;
205 dsp_info_list( argv[0], dsp_opt, lst_m, &unknown_m, &errflg );
206 if (unknown_m.num != 0) {
207 if( dsp_opt & L_OPT ) {
208 dsp_error_title(argv[0], &errflg, dsp_opt );
209 if( dsp_error_files( lst_m, &unknown_m ) ) {
216 FalFreeFontList( lst_m );
224 dsp_info_list( com, dspopt, lst, unknown_file_lst, errflg )
227 FalFontDataList *lst;
228 MISS_ENTRY *unknown_file_lst;
231 FalFontDataList srt_lst;
233 int entry, entry_end;
235 char *filename; /* file base's name */
237 char tmpfname[BUFSIZE];
238 int srt_cnt, *sort_list, cnt, mask ;
244 srt_lst.num = lst->num ;
245 srt_lst.list = (FalFontData *)malloc( sizeof(FalFontData) * lst->num ) ;
246 if( srt_lst.list == NULL ) {
247 USAGE("dtlsgpf : malloc error.\n" ) ;
251 for (i=0, srt_cnt=0 ; i < lst->num ; i++) {
254 entry = entry_end = i;
257 !strcmp(lst->list[j].style.name, lst->list[entry].style.name) &&
258 (lst->list[j].size.h == lst->list[entry].size.h ) ;
261 if( (lst->list[j].letter.h == 0) ||
262 (lst->list[j].letter.w == 0) ) break ;
266 if ( entry == entry_end ) {
267 if ( dspopt & L_OPT || dspopt & X_OPT )
268 dspinfo_1line( lst->list[entry], stdout,
269 unknown_file_lst, entry,
271 else memmove( &(srt_lst.list[srt_cnt++]),
273 sizeof(FalFontData) );
277 letter_cmp = lst->list[entry].letter.h;
278 for (j=entry ; j <= entry_end ; j++) {
279 if (lst->list[j].letter.h != letter_cmp) {
285 ret = GetDefaultFile( lst->list[entry].size.h,
286 lst->list[entry].style.name, fname);
289 for ( j = entry; j <= entry_end; j++ ) {
290 if ( dspopt & L_OPT || dspopt & X_OPT )
291 dspinfo_1line( lst->list[j], stdout,
295 &(srt_lst.list[srt_cnt++]),
297 sizeof(FalFontData) );
302 for( j = entry; j <= entry_end; j++ ) {
303 ret = search_fontfile_name(
304 lst->list[j], tmpfname,
305 unknown_file_lst, j, errflg
307 if( ret == -1 ) continue ;
308 else if( ret == -2 ) exit(1) ;
309 filename = falcom_get_base_name( tmpfname ) ;
310 if ( !strcmp( filename, fname ) ){
311 if ( dspopt & L_OPT || dspopt & X_OPT )
312 dspinfo_1line( lst->list[j], stdout,
316 &(srt_lst.list[srt_cnt++]),
318 sizeof(FalFontData) );
327 ret = GetDefaultFile(
328 lst->list[entry].size.h,
329 lst->list[entry].style.name,
335 for ( j = entry; j <= entry_end; j++ ) {
336 if ( dspopt & L_OPT || dspopt & X_OPT )
338 lst->list[j], stdout,
342 &(srt_lst.list[srt_cnt++]),
344 sizeof(FalFontData) );
348 unknown_file_lst->entry[ unknown_file_lst->num ].start = entry;
349 unknown_file_lst->entry[ unknown_file_lst->num ].end = entry_end;
350 unknown_file_lst->num++;
351 *errflg |= REDEFINED_FONT ;
354 USAGE4("%s : The user defined character information file cannot be read.\"%s/%s/%s \"\n\n",
355 com, fontdir, utillocale, UDFLIST_DEF );
358 USAGE4("%s : The mistake is found in the description of the user defined character information file.\"%s/%s/%s \"\n\n",
359 com, utillocale, fontdir, UDFLIST_DEF );
360 for ( j = entry; j <= entry_end; j++ ) {
361 if ( dspopt & L_OPT || dspopt & X_OPT )
362 dspinfo_1line( lst->list[j], stdout,
366 &(srt_lst.list[srt_cnt++]),
368 sizeof(FalFontData) );
376 for ( j = entry; j <= entry_end; j++ ) {
377 ret = search_fontfile_name(
378 lst->list[j], tmpfname,
379 unknown_file_lst, j, errflg
381 if( ret == -1 ) continue ;
382 else if( ret == -2 ) exit(1) ;
383 filename = falcom_get_base_name( tmpfname ) ;
384 if ( !strcmp( filename, fname ) ){
385 if ( dspopt & L_OPT || dspopt & X_OPT )
386 dspinfo_1line( lst->list[j], stdout,
390 &(srt_lst.list[srt_cnt++]),
392 sizeof(FalFontData) );
396 if ( j > entry_end ) {
397 unknown_file_lst->entry[ unknown_file_lst->num ].start = entry;
398 unknown_file_lst->entry[ unknown_file_lst->num ].end = entry_end;
399 unknown_file_lst->num++;
400 *errflg |= REDEFINED_FONT ;
406 * dtlsgpf displays the infomations of user defined characters.
408 if ( !(dspopt & L_OPT) ) { /* display character size and style */
409 srt_lst.num = srt_cnt ;
411 if ( dspopt & A_OPT )
412 mask = REQ_STYLE | REQ_CHARSIZE | REQ_LETTER | REQ_DELEQUAL ;
414 mask = REQ_CHARSIZE | REQ_DELEQUAL ;
416 sort_offset_list( &srt_lst, mask, &sort_list, &cnt ) ;
418 for (i=0 ; i<cnt; i++)
419 dspinfo_1line( srt_lst.list[sort_list[i]], stdout,
420 unknown_file_lst, sort_list[i],
423 free( srt_lst.list ) ;
431 dsp_error_title(com, errflg, dspopt )
437 if( dspopt & A_OPT ) {
438 if( *errflg & SAME_FONT )
439 USAGE1("%s : There are fonts that are same character size and have same style, \ncode set and XLFD. It is not possible to select user defined character fonts uniquely.\n\n", com);
440 USAGE("Please inquire of the system manager.\n\n");
442 if( *errflg & NO_FONT )
443 USAGE1("\n%s : Mistake is found in the name of user defined character fonts \nfollowing character size and style.\n\n", com);
444 if( *errflg & REDEFINED_FONT )
445 USAGE3(" Please describe the following file name in the user defined character \ninformation file(%s/%s/%s).\n\n",
446 fontdir, utillocale, UDFLIST_DEF );
455 dsp_error_files( lst, unknown )
456 FalFontDataList *lst;
460 int entry_start, entry_end;
462 char tmp_fname[BUFSIZE];
465 if ( unknown->num == 0 ){
468 for (i=0 ; i<unknown->num ; i++) {
469 entry_start = unknown->entry[i].start;
470 entry_end = unknown->entry[i].end;
472 USAGE1("\tcode set \t%d \n",
473 FALCODESETTONUM( lst->list[entry_start].cd_set ) ) ;
474 USAGE1("\tcharacter_size \t%d\n",
475 lst->list[entry_start].size.h ) ;
476 USAGE1("\tstyle \t\t%s \n", lst->list[entry_start].style.name ) ;
478 for ( j = entry_start; j <= entry_end; j++ ) {
479 ret = search_fontfile_name( lst->list[j], tmp_fname, NULL, 0, 0 ) ;
481 USAGE("\t\tThere is no font file that is required." );
482 USAGE1("\t%s\n", lst->list[j].xlfdname );
484 } else if( ret == -2 ){
487 filename = tmp_fname ;
488 USAGE1("\t\t%s", filename );
489 USAGE1("\t%s\n", lst->list[j].xlfdname );
499 #define SORTOFFSETNUM {\
500 offset = size_offset_list[j] ;\
501 size_offset_list[j] = size_offset_list[i] ;\
502 size_offset_list[i] = offset ;\
507 sort_offset_list( flist, mask, sort_list, data_cnt )
508 FalFontDataList *flist ;
513 int *size_offset_list ;
518 if( flist->num == 0 ){
522 if( (size_offset_list = (int *)malloc( flist->num * sizeof(int) )) == NULL )
524 USAGE("dtlsgpf: malloc error.\n" );
527 for( i=0 ; i < flist->num; i++ ) size_offset_list[i] = -1 ;
529 for( i=0, cnt=0; i < flist->num; i++ ) {
530 if( mask & REQ_DELEQUAL ) {
531 exist = REQ_DELEQUAL ;
532 for( j=0; j<cnt; j++ ) {
533 if( size_offset_list[j] == -1 ) break ;
534 if( (mask & REQ_CHARSIZE) &&
535 (flist->list[size_offset_list[j]].size.h == flist->list[i].size.h)
537 exist |= REQ_CHARSIZE ;
539 if( (mask & REQ_LETTER) &&
540 (flist->list[size_offset_list[j]].letter.h == flist->list[i].letter.h)
542 exist |= REQ_LETTER ;
544 if( (mask & REQ_STYLE) &&
545 !strcmp(flist->list[size_offset_list[j]].style.name, flist->list[i].style.name)
549 if( exist == mask ) break ;
550 else exist = REQ_DELEQUAL ;
551 } /* size_offset_list */
552 if( exist == mask ) continue ;
554 size_offset_list[cnt++] = i ;
557 for( i=0; i<cnt-1; i++ ) {
558 for( j=i+1; j<cnt; j++ ) {
559 if( mask & REQ_LETTER ) {
560 if( flist->list[size_offset_list[i]].letter.h >
561 flist->list[size_offset_list[j]].letter.h)
566 if( mask & REQ_CHARSIZE ) {
567 if( flist->list[size_offset_list[i]].size.h >
568 flist->list[size_offset_list[j]].size.h)
573 if( mask & REQ_STYLE ) {
574 if( strcoll(flist->list[size_offset_list[i]].style.name,
575 flist->list[size_offset_list[j]].style.name) > 0 )
582 *sort_list = size_offset_list ;
589 dsp_title( fp, dspopt )
593 if( dspopt & L_OPT || dspopt & X_OPT ) {
596 if( dspopt & X_OPT ) fprintf(fp, " code set" );
597 if( dspopt & L_OPT ) fprintf(fp, "\tfilename\t" );
598 if( (dspopt != X_OPT) && (dspopt != (L_OPT | X_OPT)) )
599 fprintf(fp, "character size\t" );
601 if( dspopt & A_OPT ) fprintf(fp, "style \t" );
603 if( dspopt != X_OPT ) fprintf(fp, "\n" ) ;
604 if( dspopt & X_OPT ) fprintf(fp, "\tXLFD\n" );
605 fprintf(fp ,"-----------------------------------------------------------------------------\n");
614 dspinfo_1line( data, fp, unknown_file_lst, offset, errflg, dspopt )
617 MISS_ENTRY *unknown_file_lst;
624 char tmp_fname[BUFSIZE];
629 /* get font informations */
630 ret = search_fontfile_name( data, tmp_fname, unknown_file_lst, offset, errflg ) ;
631 if( ret == -1 ) return ;
632 else if( ret == -2 ) exit(1) ;
635 /* display font informations */
636 if( dspopt & X_OPT ) fprintf( fp, "%d \t", FALCODESETTONUM( data.cd_set ) );
638 if( dspopt & L_OPT ) fprintf( fp, "%s\t", namep );
640 if( (dspopt != X_OPT) &&
641 (dspopt != (L_OPT | X_OPT))
643 fprintf( fp, "%d", data.size.h );
646 if( dspopt & A_OPT ) {
647 if( data.letter.h ) {
648 if( !(dspopt & L_OPT) )
649 fprintf( fp, ".%d", data.letter.h );
651 fprintf( fp, "\t%4d", data.letter.h );
654 fprintf( fp, "%s", data.style.name );
657 if( dspopt & L_OPT ) {
659 if( data.prm & FAL_FONT_DISPLAY ) {
660 fprintf( fp, "display");
663 if( data.prm & FAL_FONT_PRINTER ) {
667 fprintf( fp, "printer");
670 if( dspopt != X_OPT ){
672 if( dspopt & X_OPT ) fprintf( fp, "\t" );
674 if( dspopt & X_OPT ) fprintf( fp, "%s\n", data.xlfdname );
675 if( dspopt != X_OPT ){
676 if( dspopt & X_OPT ) fprintf( fp, "\n" );
685 disp_no_fontslist( dspopt )
688 fprintf( stdout, "\nThere are no fonts that are used for user defined character.\n" ) ;
693 put_help( prog_name )
696 USAGE1("Usage : %s [-lax][-la][-lx][-C][-codeset number][-help]\n", prog_name);
697 USAGE("\t-l : display of file name and character size\n");
698 USAGE("\t-a : display of style(FAMILY_NAME) information\n");
699 USAGE("\t-x : display of XLFD information\n");
700 USAGE("\t-C : display of code area informations\n");
701 USAGE("\t-codeset : specification of the codeset\n");
702 USAGE("\t-help : display of of the command parameter informations\n");
704 USAGE(" (If the option is not specified, only the character size are displayed.)\n");
710 search_fontfile_name( data, fname, unknown_file_lst, offset, errflg )
713 MISS_ENTRY *unknown_file_lst;
718 FalFontDataList *flist ;
723 FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_DEFINED |
724 FAL_FONT_MASK_XLFDNAME |
725 FAL_FONT_MASK_SIZE_H |
726 FAL_FONT_MASK_STYLE_NAME | FAL_FONT_MASK_CODE_SET
729 if( data.size.w >= 0 ) mask |= FAL_FONT_MASK_SIZE_W ;
730 if( data.letter.w ) mask |= FAL_FONT_MASK_LETTER_W ;
731 if( data.letter.h ) mask |= FAL_FONT_MASK_LETTER_H ;
732 if( data.letter.x ) mask |= FAL_FONT_MASK_LETTER_X ;
733 if( data.letter.y ) mask |= FAL_FONT_MASK_LETTER_Y ;
735 if( data.style.def ) mask |= FAL_FONT_MASK_STYLE_DEF ;
736 if( data.shape.name ) mask |= FAL_FONT_MASK_SHAPE_NAME ;
737 if( data.shape.def ) mask |= FAL_FONT_MASK_SHAPE_DEF ;
738 COMM_SBCHR_SETFONTDATA( data, mask ) ;
739 if( data.prm ) mask |= FAL_FONT_MASK_PERMISSION ;
741 fid = FalOpenSysFont( &data, mask, &flist ) ;
743 memset( fname, '\0', sizeof(fname) ) ;
745 FalFreeFontList( flist ) ;
746 if( unknown_file_lst ) {
747 unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ;
748 unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ;
749 unknown_file_lst->num++;
750 *errflg |= SAME_FONT ;
754 switch( fal_utyerror ) {
758 switch( fal_utyderror ) {
761 if( unknown_file_lst ) {
762 unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ;
763 unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ;
764 unknown_file_lst->num++;
769 USAGE2("System call error occurred. fal_utyerror = %d fal_utyderror = %d\n", fal_utyerror, fal_utyderror ) ;
773 if( unknown_file_lst ) {
774 unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ;
775 unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ;
776 unknown_file_lst->num++;
781 USAGE("malloc error occurred.\n" ) ;
784 USAGE1("%s : cannot get font information list.\n", command_name ) ;
789 if( FalFontIDToFileName( fid, &tmp_fname ) == FAL_ERROR ) {
790 USAGE1("%s : cannot get file name.\n", command_name ) ;
791 FalCloseFont( fid ) ;
794 strcpy( fname, tmp_fname ) ;
795 FalFree( tmp_fname ) ;
796 FalCloseFont( fid ) ;
804 FalFontDataList *lst;
817 if (( srt.list = (FalFontData *)malloc(sizeof(FalFontData) * srt.num)) == NULL) {
820 memmove (srt.list, lst->list, sizeof(FalFontData) * srt.num);
822 for ( i=0 ; i < srt.num -1 ; i++ ) {
824 memmove( &target, &(srt.list[i]), sizeof(FalFontData));
827 for ( j=i+1 ; j < srt.num ; j++ ) {
828 if ( get_new_target( &target, &(srt.list[j]) ) ) {
829 memmove( &target, &(srt.list[j]), sizeof(FalFontData));
833 if (target_entry != i) {
834 memmove( &target, &(srt.list[target_entry]),
837 memmove( &(srt.list[i+1]), &(srt.list[i]),
838 sizeof(FalFontData)*(target_entry -i)
840 memmove( &(srt.list[i]), &target,
846 lst->list = srt.list;
852 /* return data ¡§ sort ... 1 */
856 get_new_target( target, choose )
864 diff.style.def = choose->style.def - target->style.def;
865 str_chk.style = strcmp( choose->style.name, target->style.name ) ;
867 NEW_TARGET_SET( diff, choose, target, str_chk ) ;
869 diff.shape.def = choose->shape.def - target->shape.def;
870 if( (choose->shape.name != NULL) && (target->shape.name != NULL) ) {
871 str_chk.shape = strcmp( choose->shape.name, target->shape.name ) ;
874 diff.cd_set = choose->cd_set - target->cd_set;
875 diff.size.h = choose->size.h - target->size.h;
876 diff.size.w = choose->size.w - target->size.w;
877 diff.letter.h = choose->letter.h - target->letter.h;
878 diff.letter.w = choose->letter.w - target->letter.w;
881 if ( diff.cd_set < 0 ) return 1;
882 if ( diff.cd_set > 0 ) return 0;
884 /* character size height */
885 if ( diff.size.h < 0 ) return 1;
886 if ( diff.size.h > 0 ) return 0;
888 /* letter size height */
889 if ( diff.letter.h < 0 ) return 1;
890 if ( diff.letter.h > 0 ) return 0;
892 /* character size wide */
893 if ( diff.size.w < 0 ) return 1;
894 if ( diff.size.w > 0 ) return 0;
896 /* letter size wide */
897 if ( diff.letter.w < 0 ) return 1;
898 if ( diff.letter.w > 0 ) return 0;
901 if ( target->style.def == FAL_FONT_UNKNOWN ) {
902 if ( choose->style.def > 0 ) return 1;
903 /* style is FAL_FONT_UNKNOWN both "target" and "choose" */
904 if ( str_chk.style < 0 ) return 1;
905 if ( str_chk.style > 0) return 0;
906 } else if ( choose->style.def == FAL_FONT_UNKNOWN ) {
909 /* target->style.def and choose->style.def is not FAL_FONT_UNKNOWN */
910 if ( diff.style.def < 0 ) return 1;
911 if ( diff.style.def > 0 ) return 0;
913 NEW_TARGET_CHK( diff, choose, target, str_chk ) ;
915 /* character style */
916 if ( target->shape.def == FAL_FONT_UNKNOWN ) {
917 if ( choose->shape.def > 0 ) return 1;
918 if ( str_chk.shape < 0 ) return 1;
919 if ( str_chk.shape > 0 ) return 0;
920 } else if (choose->shape.def == FAL_FONT_UNKNOWN ) {
923 if ( diff.shape.def < 0 ) return 1;
924 if ( diff.shape.def > 0 ) return 0;