lsgpf.c 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926
  1. /*
  2. * CDE - Common Desktop Environment
  3. *
  4. * Copyright (c) 1993-2012, The Open Group. All rights reserved.
  5. *
  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)
  10. * any later version.
  11. *
  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
  16. * details.
  17. *
  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
  22. */
  23. /* $XConsortium: lsgpf.c /main/7 1996/11/08 02:05:57 cde-fuj $ */
  24. /*
  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
  29. */
  30. #include <stdio.h>
  31. #include <errno.h>
  32. #include <locale.h>
  33. #include <string.h>
  34. #include "FaLib.h"
  35. #include "falfont.h"
  36. #include "bdfgpf.h"
  37. #include "udcutil.h"
  38. static char *utillocale;
  39. static char *fontdir;
  40. static char *command_name;
  41. typedef struct {
  42. int num;
  43. struct {
  44. int start;
  45. int end;
  46. }entry[BUFSIZE];
  47. }MISS_ENTRY;
  48. /* request for sort */
  49. #define REQ_STYLE (1<<1)
  50. #define REQ_CHARSIZE (1<<2)
  51. #define REQ_LETTER (1<<3)
  52. #define REQ_DELEQUAL (1<<16)
  53. /* error flag */
  54. #define NO_FONT (1<<1)
  55. #define SAME_FONT (1<<2)
  56. #define REDEFINED_FONT (1<<3)
  57. /* request flag */
  58. #define A_OPT (1<<1)
  59. #define L_OPT (1<<2)
  60. #define X_OPT (1<<3)
  61. #define C_OPT (1<<4)
  62. static void dsp_info_list(char *com,
  63. int dspopt,
  64. FalFontDataList *lst,
  65. MISS_ENTRY *unknown_file_lst,
  66. int *errflg);
  67. static void dsp_title(FILE *fp, int dspopt);
  68. static void dspinfo_1line(FalFontData data,
  69. FILE *fp,
  70. MISS_ENTRY *unknown_file_lst,
  71. int offset,
  72. int *errflg,
  73. int dspopt);
  74. static void disp_no_fontslist(int dspopt);
  75. static void sort_offset_list(FalFontDataList *flist,
  76. int mask,
  77. int **sort_list,
  78. int *data_cnt);
  79. static int sort_fontlist(FalFontDataList *lst);
  80. static void dsp_error_title(char *com, int *errflg, int dspopt);
  81. static int dsp_error_files(FalFontDataList *lst, MISS_ENTRY *unknown);
  82. static void put_help(char *prog_name);
  83. static int search_fontfile_name(FalFontData data,
  84. char *fname,
  85. MISS_ENTRY *unknown_file_lst,
  86. int offset,
  87. int *errflg);
  88. static int get_new_target(FalFontData *target, FalFontData *choose);
  89. int
  90. main( int argc, char *argv[] )
  91. {
  92. FalFontDataList *lst_m; /* font information list struct */
  93. FalFontData key; /* font reference information creation struct */
  94. MISS_ENTRY unknown_m ; /* error */
  95. int i, j;
  96. int code_sw; /* code set flag */
  97. int mask;
  98. int code_set ;
  99. int errflg ;
  100. int dsp_opt ;
  101. /* initialize */
  102. command_name = argv[0] ;
  103. errflg = 0 ;
  104. unknown_m.num = 0;
  105. code_sw = 0;
  106. dsp_opt = 0 ;
  107. /* get locale strings */
  108. if( (utillocale = (char *)getenv( "LANG" )) == NULL ){
  109. utillocale = "C" ;
  110. }
  111. if( (fontdir = (char *)getenv( "DTUDCFONTS" )) == (char *)NULL ) {
  112. fontdir = DTUDCFONTSLISTDIR ;
  113. }
  114. /*
  115. * dtlsgpf check on which options are required.
  116. */
  117. for (i=1 ; i < argc ; i++) {
  118. if (!strcmp(argv[i], "-help")) {
  119. put_help(argv[0]);
  120. exit(0);
  121. }
  122. if (*argv[i] != '-') {
  123. put_help(argv[0]);
  124. exit(1);
  125. }
  126. if ( !strcmp( argv[i], "-codeset" ) ) {
  127. char *cbuf ;
  128. if ( (i+1) >= argc ){
  129. put_help( argv[0] );
  130. exit( 1 );
  131. }
  132. i++;
  133. code_set = (int)strtol( argv[i], &cbuf, 10 ) ;
  134. if( argv[i] == cbuf ) {
  135. put_help( argv[0] );
  136. exit( 1 );
  137. }
  138. code_sw = 1 ;
  139. }
  140. for (j=1; argv[i][j] != '\0' ; j++) {
  141. char req ;
  142. req = argv[i][j] ;
  143. if ( req == 'l') dsp_opt |= L_OPT ;
  144. else if ( req == 'a') dsp_opt |= A_OPT ;
  145. else if ( req == 'x') dsp_opt |= X_OPT ;
  146. else if ( req == 'C') dsp_opt |= C_OPT ;
  147. else {
  148. put_help(argv[0]);
  149. exit( 1 );
  150. }
  151. }
  152. }
  153. /* "-ax" -> "-a" */
  154. if( dsp_opt == ( A_OPT | X_OPT ) ) dsp_opt = A_OPT ;
  155. /*
  156. * display information list of UDC code region
  157. */
  158. if( dsp_opt & C_OPT ){
  159. fprintf(stdout ,"codeset\t\tcode area\n");
  160. fprintf(stdout ,"--------------------------------------------\n");
  161. if ( DispUdcCpArea( stdout ) == -1 ){
  162. ErrMsgTable_FalGetFontList( argv[0], fal_utyerror, fal_utyderror );
  163. exit( 1 );
  164. }
  165. exit( 0 );
  166. }
  167. /*
  168. * get an information list of UDC fonts
  169. */
  170. mask = 0;
  171. mask = FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_DEFINED ;
  172. if( code_sw ) {
  173. mask |= FAL_FONT_MASK_CODE_SET ;
  174. key.cd_set = FALGETFALCODESET( code_set ) ;
  175. }
  176. /* get font information list */
  177. if ( FalGetFontList( &key, mask, &lst_m ) == FAL_ERROR ){
  178. ErrMsgTable_FalGetFontList( argv[0], fal_utyerror, fal_utyderror );
  179. exit( 1 );
  180. }
  181. /* sort element of font infomation list */
  182. if( sort_fontlist( lst_m ) == FAL_ERROR ) {
  183. FalFreeFontList( lst_m );
  184. return FAL_ERROR ;
  185. }
  186. /*
  187. * dtlsgpf shows UDC informations as user's request.
  188. */
  189. dsp_title( stdout, dsp_opt );
  190. if ( lst_m->num == 0) {
  191. disp_no_fontslist( dsp_opt ) ;
  192. } else {
  193. dsp_info_list( argv[0], dsp_opt, lst_m, &unknown_m, &errflg );
  194. if (unknown_m.num != 0) {
  195. if( dsp_opt & L_OPT ) {
  196. dsp_error_title(argv[0], &errflg, dsp_opt );
  197. if( dsp_error_files( lst_m, &unknown_m ) ) {
  198. exit( 1 );
  199. }
  200. }
  201. }
  202. }
  203. FalFreeFontList( lst_m );
  204. exit( 0 );
  205. }
  206. static void
  207. dsp_info_list(
  208. char *com,
  209. int dspopt,
  210. FalFontDataList *lst,
  211. MISS_ENTRY *unknown_file_lst,
  212. int *errflg)
  213. {
  214. FalFontDataList srt_lst;
  215. int i, j ;
  216. int entry, entry_end;
  217. int ret;
  218. char *filename; /* file base's name */
  219. char fname[BUFSIZE];
  220. char tmpfname[BUFSIZE];
  221. int srt_cnt, *sort_list, cnt, mask ;
  222. if( lst->num == 0 ){
  223. return ;
  224. }
  225. srt_lst.num = lst->num ;
  226. srt_lst.list = (FalFontData *)malloc( sizeof(FalFontData) * lst->num ) ;
  227. if( srt_lst.list == NULL ) {
  228. USAGE("dtlsgpf : malloc error.\n" ) ;
  229. exit(1) ;
  230. }
  231. for (i=0, srt_cnt=0 ; i < lst->num ; i++) {
  232. int letter_cmp;
  233. entry = entry_end = i;
  234. for (j=i ;
  235. (j < lst->num) &&
  236. !strcmp(lst->list[j].style.name, lst->list[entry].style.name) &&
  237. (lst->list[j].size.h == lst->list[entry].size.h ) ;
  238. j++)
  239. {
  240. if( (lst->list[j].letter.h == 0) ||
  241. (lst->list[j].letter.w == 0) ) break ;
  242. entry_end = j;
  243. }
  244. if ( entry == entry_end ) {
  245. if ( dspopt & L_OPT || dspopt & X_OPT )
  246. dspinfo_1line( lst->list[entry], stdout,
  247. unknown_file_lst, entry,
  248. errflg, dspopt );
  249. else memmove( &(srt_lst.list[srt_cnt++]),
  250. &(lst->list[entry]),
  251. sizeof(FalFontData) );
  252. continue;
  253. }
  254. letter_cmp = lst->list[entry].letter.h;
  255. for (j=entry ; j <= entry_end ; j++) {
  256. if (lst->list[j].letter.h != letter_cmp) {
  257. break;
  258. }
  259. }
  260. if (j > entry_end) {
  261. ret = GetDefaultFile( lst->list[entry].size.h,
  262. lst->list[entry].style.name, fname);
  263. if ( ret < 0 ) {
  264. fname[0]='\0';
  265. for ( j = entry; j <= entry_end; j++ ) {
  266. if ( dspopt & L_OPT || dspopt & X_OPT )
  267. dspinfo_1line( lst->list[j], stdout,
  268. unknown_file_lst, j,
  269. errflg, dspopt );
  270. else memmove(
  271. &(srt_lst.list[srt_cnt++]),
  272. &(lst->list[j]),
  273. sizeof(FalFontData) );
  274. }
  275. i = entry_end;
  276. continue ;
  277. }
  278. for( j = entry; j <= entry_end; j++ ) {
  279. ret = search_fontfile_name(
  280. lst->list[j], tmpfname,
  281. unknown_file_lst, j, errflg
  282. ) ;
  283. if( ret == -1 ) continue ;
  284. else if( ret == -2 ) exit(1) ;
  285. filename = falcom_get_base_name( tmpfname ) ;
  286. if ( !strcmp( filename, fname ) ){
  287. if ( dspopt & L_OPT || dspopt & X_OPT )
  288. dspinfo_1line( lst->list[j], stdout,
  289. unknown_file_lst, j,
  290. errflg, dspopt );
  291. else memmove(
  292. &(srt_lst.list[srt_cnt++]),
  293. &(lst->list[j]),
  294. sizeof(FalFontData) );
  295. break;
  296. }
  297. }
  298. i = entry_end;
  299. continue;
  300. }
  301. ret = GetDefaultFile(
  302. lst->list[entry].size.h,
  303. lst->list[entry].style.name,
  304. fname
  305. );
  306. if( ret ) {
  307. switch ( ret ) {
  308. case -1:
  309. for ( j = entry; j <= entry_end; j++ ) {
  310. if ( dspopt & L_OPT || dspopt & X_OPT )
  311. dspinfo_1line(
  312. lst->list[j], stdout,
  313. unknown_file_lst, j,
  314. errflg, dspopt );
  315. else memmove(
  316. &(srt_lst.list[srt_cnt++]),
  317. &(lst->list[j]),
  318. sizeof(FalFontData) );
  319. }
  320. break ;
  321. case -2:
  322. unknown_file_lst->entry[ unknown_file_lst->num ].start = entry;
  323. unknown_file_lst->entry[ unknown_file_lst->num ].end = entry_end;
  324. unknown_file_lst->num++;
  325. *errflg |= REDEFINED_FONT ;
  326. break ;
  327. case -3:
  328. USAGE4("%s : The user defined character information file cannot be read.\"%s/%s/%s \"\n\n",
  329. com, fontdir, utillocale, UDFLIST_DEF );
  330. exit(1) ;
  331. case -4:
  332. USAGE4("%s : The mistake is found in the description of the user defined character information file.\"%s/%s/%s \"\n\n",
  333. com, utillocale, fontdir, UDFLIST_DEF );
  334. for ( j = entry; j <= entry_end; j++ ) {
  335. if ( dspopt & L_OPT || dspopt & X_OPT )
  336. dspinfo_1line( lst->list[j], stdout,
  337. unknown_file_lst, j,
  338. errflg, dspopt );
  339. else memmove(
  340. &(srt_lst.list[srt_cnt++]),
  341. &(lst->list[j]),
  342. sizeof(FalFontData) );
  343. }
  344. break ;
  345. }
  346. i = entry_end;
  347. continue;
  348. }
  349. for ( j = entry; j <= entry_end; j++ ) {
  350. ret = search_fontfile_name(
  351. lst->list[j], tmpfname,
  352. unknown_file_lst, j, errflg
  353. ) ;
  354. if( ret == -1 ) continue ;
  355. else if( ret == -2 ) exit(1) ;
  356. filename = falcom_get_base_name( tmpfname ) ;
  357. if ( !strcmp( filename, fname ) ){
  358. if ( dspopt & L_OPT || dspopt & X_OPT )
  359. dspinfo_1line( lst->list[j], stdout,
  360. unknown_file_lst, j,
  361. errflg, dspopt );
  362. else memmove(
  363. &(srt_lst.list[srt_cnt++]),
  364. &(lst->list[j]),
  365. sizeof(FalFontData) );
  366. break;
  367. }
  368. }
  369. if ( j > entry_end ) {
  370. unknown_file_lst->entry[ unknown_file_lst->num ].start = entry;
  371. unknown_file_lst->entry[ unknown_file_lst->num ].end = entry_end;
  372. unknown_file_lst->num++;
  373. *errflg |= REDEFINED_FONT ;
  374. }
  375. i = entry_end;
  376. }
  377. /*
  378. * dtlsgpf displays the infomations of user defined characters.
  379. */
  380. if ( !(dspopt & L_OPT) ) { /* display character size and style */
  381. srt_lst.num = srt_cnt ;
  382. if ( dspopt & A_OPT )
  383. mask = REQ_STYLE | REQ_CHARSIZE | REQ_LETTER | REQ_DELEQUAL ;
  384. else
  385. mask = REQ_CHARSIZE | REQ_DELEQUAL ;
  386. sort_offset_list( &srt_lst, mask, &sort_list, &cnt ) ;
  387. for (i=0 ; i<cnt; i++)
  388. dspinfo_1line( srt_lst.list[sort_list[i]], stdout,
  389. unknown_file_lst, sort_list[i],
  390. errflg, dspopt );
  391. free( sort_list ) ;
  392. free( srt_lst.list ) ;
  393. }
  394. }
  395. static void
  396. dsp_error_title(char *com, int *errflg, int dspopt)
  397. {
  398. USAGE("\n\n" );
  399. if( dspopt & A_OPT ) {
  400. if( *errflg & SAME_FONT )
  401. 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);
  402. USAGE("Please inquire of the system manager.\n\n");
  403. } else {
  404. if( *errflg & NO_FONT )
  405. USAGE1("\n%s : Mistake is found in the name of user defined character fonts \nfollowing character size and style.\n\n", com);
  406. if( *errflg & REDEFINED_FONT )
  407. USAGE3(" Please describe the following file name in the user defined character \ninformation file(%s/%s/%s).\n\n",
  408. fontdir, utillocale, UDFLIST_DEF );
  409. }
  410. }
  411. static int
  412. dsp_error_files( FalFontDataList *lst, MISS_ENTRY *unknown )
  413. {
  414. int i,j;
  415. int entry_start, entry_end;
  416. char *filename;
  417. char tmp_fname[BUFSIZE];
  418. int ret ;
  419. if ( unknown->num == 0 ){
  420. return 0;
  421. }
  422. for (i=0 ; i<unknown->num ; i++) {
  423. entry_start = unknown->entry[i].start;
  424. entry_end = unknown->entry[i].end;
  425. USAGE1("\tcode set \t%d \n",
  426. FALCODESETTONUM( lst->list[entry_start].cd_set ) ) ;
  427. USAGE1("\tcharacter_size \t%d\n",
  428. lst->list[entry_start].size.h ) ;
  429. USAGE1("\tstyle \t\t%s \n", lst->list[entry_start].style.name ) ;
  430. USAGE("\n" );
  431. for ( j = entry_start; j <= entry_end; j++ ) {
  432. ret = search_fontfile_name( lst->list[j], tmp_fname, NULL, 0, 0 ) ;
  433. if( ret == -1 ){
  434. USAGE("\t\tThere is no font file that is required." );
  435. USAGE1("\t%s\n", lst->list[j].xlfdname );
  436. continue ;
  437. } else if( ret == -2 ){
  438. return -1 ;
  439. }
  440. filename = tmp_fname ;
  441. USAGE1("\t\t%s", filename );
  442. USAGE1("\t%s\n", lst->list[j].xlfdname );
  443. }
  444. USAGE("\n" );
  445. }
  446. USAGE("\n" );
  447. return 0;
  448. }
  449. #define SORTOFFSETNUM {\
  450. offset = size_offset_list[j] ;\
  451. size_offset_list[j] = size_offset_list[i] ;\
  452. size_offset_list[i] = offset ;\
  453. }
  454. static void
  455. sort_offset_list(
  456. FalFontDataList *flist,
  457. int mask,
  458. int **sort_list,
  459. int *data_cnt)
  460. {
  461. int *size_offset_list ;
  462. int cnt, i, j ;
  463. int offset ;
  464. int exist ;
  465. if( flist->num == 0 ){
  466. return ;
  467. }
  468. if( (size_offset_list = (int *)malloc( flist->num * sizeof(int) )) == NULL )
  469. {
  470. USAGE("dtlsgpf: malloc error.\n" );
  471. exit(1) ;
  472. }
  473. for( i=0 ; i < flist->num; i++ ) size_offset_list[i] = -1 ;
  474. for( i=0, cnt=0; i < flist->num; i++ ) {
  475. if( mask & REQ_DELEQUAL ) {
  476. exist = REQ_DELEQUAL ;
  477. for( j=0; j<cnt; j++ ) {
  478. if( size_offset_list[j] == -1 ) break ;
  479. if( (mask & REQ_CHARSIZE) &&
  480. (flist->list[size_offset_list[j]].size.h == flist->list[i].size.h)
  481. ) {
  482. exist |= REQ_CHARSIZE ;
  483. }
  484. if( (mask & REQ_LETTER) &&
  485. (flist->list[size_offset_list[j]].letter.h == flist->list[i].letter.h)
  486. ) {
  487. exist |= REQ_LETTER ;
  488. }
  489. if( (mask & REQ_STYLE) &&
  490. !strcmp(flist->list[size_offset_list[j]].style.name, flist->list[i].style.name)
  491. ) {
  492. exist |= REQ_STYLE ;
  493. }
  494. if( exist == mask ) break ;
  495. else exist = REQ_DELEQUAL ;
  496. } /* size_offset_list */
  497. if( exist == mask ) continue ;
  498. } /* REQ_DELEQUAL */
  499. size_offset_list[cnt++] = i ;
  500. } /* flist */
  501. /* sort data */
  502. for( i=0; i<cnt-1; i++ ) {
  503. for( j=i+1; j<cnt; j++ ) {
  504. if( mask & REQ_LETTER ) {
  505. if( flist->list[size_offset_list[i]].letter.h >
  506. flist->list[size_offset_list[j]].letter.h)
  507. {
  508. SORTOFFSETNUM ;
  509. }
  510. }
  511. if( mask & REQ_CHARSIZE ) {
  512. if( flist->list[size_offset_list[i]].size.h >
  513. flist->list[size_offset_list[j]].size.h)
  514. {
  515. SORTOFFSETNUM ;
  516. }
  517. }
  518. if( mask & REQ_STYLE ) {
  519. if( strcoll(flist->list[size_offset_list[i]].style.name,
  520. flist->list[size_offset_list[j]].style.name) > 0 )
  521. {
  522. SORTOFFSETNUM ;
  523. }
  524. }
  525. }
  526. }
  527. *sort_list = size_offset_list ;
  528. *data_cnt = cnt ;
  529. }
  530. static void
  531. dsp_title( FILE *fp, int dspopt )
  532. {
  533. if( dspopt & L_OPT || dspopt & X_OPT ) {
  534. fprintf(fp, "\n" ) ;
  535. if( dspopt & X_OPT ) fprintf(fp, " code set" );
  536. if( dspopt & L_OPT ) fprintf(fp, "\tfilename\t" );
  537. if( (dspopt != X_OPT) && (dspopt != (L_OPT | X_OPT)) )
  538. fprintf(fp, "character size\t" );
  539. COMM_DSP_LETTER_T ;
  540. if( dspopt & A_OPT ) fprintf(fp, "style \t" );
  541. COMM_DSP_PRM ;
  542. if( dspopt != X_OPT ) fprintf(fp, "\n" ) ;
  543. if( dspopt & X_OPT ) fprintf(fp, "\tXLFD\n" );
  544. fprintf(fp ,"-----------------------------------------------------------------------------\n");
  545. }
  546. }
  547. static void
  548. dspinfo_1line(
  549. FalFontData data,
  550. FILE *fp,
  551. MISS_ENTRY *unknown_file_lst,
  552. int offset,
  553. int *errflg,
  554. int dspopt)
  555. {
  556. int dsp_on ;
  557. char *namep;
  558. char tmp_fname[BUFSIZE];
  559. int ret ;
  560. dsp_on = 0;
  561. /* get font informations */
  562. ret = search_fontfile_name( data, tmp_fname, unknown_file_lst, offset, errflg ) ;
  563. if( ret == -1 ) return ;
  564. else if( ret == -2 ) exit(1) ;
  565. namep = tmp_fname ;
  566. /* display font informations */
  567. if( dspopt & X_OPT ) fprintf( fp, "%d \t", FALCODESETTONUM( data.cd_set ) );
  568. if( dspopt & L_OPT ) fprintf( fp, "%s\t", namep );
  569. if( (dspopt != X_OPT) &&
  570. (dspopt != (L_OPT | X_OPT))
  571. ) {
  572. fprintf( fp, "%d", data.size.h );
  573. }
  574. if( dspopt & A_OPT ) {
  575. if( data.letter.h ) {
  576. if( !(dspopt & L_OPT) )
  577. fprintf( fp, ".%d", data.letter.h );
  578. else
  579. fprintf( fp, "\t%4d", data.letter.h );
  580. }
  581. fprintf( fp, "\t" );
  582. fprintf( fp, "%s", data.style.name );
  583. }
  584. if( dspopt & L_OPT ) {
  585. fprintf( fp, "\t" );
  586. if( data.prm & FAL_FONT_DISPLAY ) {
  587. fprintf( fp, "display");
  588. dsp_on = 1;
  589. }
  590. if( data.prm & FAL_FONT_PRINTER ) {
  591. if( dsp_on ) {
  592. fprintf( fp, " & ");
  593. }
  594. fprintf( fp, "printer");
  595. }
  596. }
  597. if( dspopt != X_OPT ){
  598. fprintf( fp, "\n");
  599. if( dspopt & X_OPT ) fprintf( fp, "\t" );
  600. }
  601. if( dspopt & X_OPT ) fprintf( fp, "%s\n", data.xlfdname );
  602. if( dspopt != X_OPT ){
  603. if( dspopt & X_OPT ) fprintf( fp, "\n" );
  604. }
  605. }
  606. static void
  607. disp_no_fontslist( int dspopt )
  608. {
  609. fprintf( stdout, "\nThere are no fonts that are used for user defined character.\n" ) ;
  610. }
  611. static void
  612. put_help( char *prog_name )
  613. {
  614. USAGE1("Usage : %s [-lax][-la][-lx][-C][-codeset number][-help]\n", prog_name);
  615. USAGE("\t-l : display of file name and character size\n");
  616. USAGE("\t-a : display of style(FAMILY_NAME) information\n");
  617. USAGE("\t-x : display of XLFD information\n");
  618. USAGE("\t-C : display of code area informations\n");
  619. USAGE("\t-codeset : specification of the codeset\n");
  620. USAGE("\t-help : display of of the command parameter informations\n");
  621. USAGE(" (If the option is not specified, only the character size are displayed.)\n");
  622. }
  623. static int
  624. search_fontfile_name(
  625. FalFontData data,
  626. char *fname,
  627. MISS_ENTRY *unknown_file_lst,
  628. int offset,
  629. int *errflg)
  630. {
  631. FalFontID fid ;
  632. FalFontDataList *flist ;
  633. int mask ;
  634. char *tmp_fname ;
  635. mask =
  636. FAL_FONT_MASK_UNDEFINED | FAL_FONT_MASK_DEFINED |
  637. FAL_FONT_MASK_XLFDNAME |
  638. FAL_FONT_MASK_SIZE_H |
  639. FAL_FONT_MASK_STYLE_NAME | FAL_FONT_MASK_CODE_SET
  640. ;
  641. if( data.size.w >= 0 ) mask |= FAL_FONT_MASK_SIZE_W ;
  642. if( data.letter.w ) mask |= FAL_FONT_MASK_LETTER_W ;
  643. if( data.letter.h ) mask |= FAL_FONT_MASK_LETTER_H ;
  644. if( data.letter.x ) mask |= FAL_FONT_MASK_LETTER_X ;
  645. if( data.letter.y ) mask |= FAL_FONT_MASK_LETTER_Y ;
  646. if( data.style.def ) mask |= FAL_FONT_MASK_STYLE_DEF ;
  647. if( data.shape.name ) mask |= FAL_FONT_MASK_SHAPE_NAME ;
  648. if( data.shape.def ) mask |= FAL_FONT_MASK_SHAPE_DEF ;
  649. COMM_SBCHR_SETFONTDATA( data, mask ) ;
  650. if( data.prm ) mask |= FAL_FONT_MASK_PERMISSION ;
  651. fid = FalOpenSysFont( &data, mask, &flist ) ;
  652. if( fid == 0 ) {
  653. memset( fname, '\0', sizeof(fname) ) ;
  654. if( flist ){
  655. FalFreeFontList( flist ) ;
  656. if( unknown_file_lst ) {
  657. unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ;
  658. unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ;
  659. unknown_file_lst->num++;
  660. *errflg |= SAME_FONT ;
  661. }
  662. return(-1);
  663. } else {
  664. switch( fal_utyerror ) {
  665. case _FAL_OPEN_ER :
  666. case _FAL_READ_ER :
  667. case _FAL_STAT_ER :
  668. switch( fal_utyderror ) {
  669. case EACCES :
  670. case ENOENT :
  671. if( unknown_file_lst ) {
  672. unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ;
  673. unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ;
  674. unknown_file_lst->num++;
  675. *errflg |= NO_FONT ;
  676. }
  677. return(-1) ;
  678. default :
  679. USAGE2("System call error occurred. fal_utyerror = %d fal_utyderror = %d\n", fal_utyerror, fal_utyderror ) ;
  680. return(-2) ;
  681. }
  682. case _FAL_FONT_ER :
  683. if( unknown_file_lst ) {
  684. unknown_file_lst->entry[ unknown_file_lst->num ].start = offset ;
  685. unknown_file_lst->entry[ unknown_file_lst->num ].end = offset ;
  686. unknown_file_lst->num++;
  687. *errflg |= NO_FONT ;
  688. }
  689. return(-1) ;
  690. case _FAL_MALOC_ER :
  691. USAGE("malloc error occurred.\n" ) ;
  692. return(-2) ;
  693. default :
  694. USAGE1("%s : cannot get font information list.\n", command_name ) ;
  695. return(-2) ;
  696. }
  697. }
  698. }
  699. if( FalFontIDToFileName( fid, &tmp_fname ) == FAL_ERROR ) {
  700. USAGE1("%s : cannot get file name.\n", command_name ) ;
  701. FalCloseFont( fid ) ;
  702. return(-2) ;
  703. }
  704. strcpy( fname, tmp_fname ) ;
  705. FalFree( tmp_fname ) ;
  706. FalCloseFont( fid ) ;
  707. return(0) ;
  708. }
  709. static int
  710. sort_fontlist( FalFontDataList *lst )
  711. {
  712. int i,j;
  713. FalFontDataList srt;
  714. FalFontData target;
  715. int target_entry;
  716. if( lst->num == 0 ){
  717. return(0) ;
  718. }
  719. srt.num = lst->num;
  720. if (( srt.list = (FalFontData *)malloc(sizeof(FalFontData) * srt.num)) == NULL) {
  721. return FAL_ERROR;
  722. }
  723. memmove (srt.list, lst->list, sizeof(FalFontData) * srt.num);
  724. /* start to sort */
  725. for ( i=0 ; i < srt.num -1 ; i++ ) {
  726. memmove( &target, &(srt.list[i]), sizeof(FalFontData));
  727. target_entry = i;
  728. for ( j=i+1 ; j < srt.num ; j++ ) {
  729. if ( get_new_target( &target, &(srt.list[j]) ) ) {
  730. memmove( &target, &(srt.list[j]), sizeof(FalFontData));
  731. target_entry = j;
  732. }
  733. }
  734. if (target_entry != i) {
  735. memmove( &target, &(srt.list[target_entry]),
  736. sizeof(FalFontData)
  737. );
  738. memmove( &(srt.list[i+1]), &(srt.list[i]),
  739. sizeof(FalFontData)*(target_entry -i)
  740. );
  741. memmove( &(srt.list[i]), &target,
  742. sizeof(FalFontData)
  743. );
  744. }
  745. }
  746. free(lst->list);
  747. lst->list = srt.list;
  748. return(0);
  749. }
  750. /* sort flag */
  751. /* return data ¡§ sort ... 1 */
  752. /* no sort ... 0 */
  753. static int
  754. get_new_target( FalFontData *target, FalFontData *choose )
  755. {
  756. FalFontData diff;
  757. DEF_STR_CHK ;
  758. DEF_STR_SET ;
  759. diff.style.def = choose->style.def - target->style.def;
  760. str_chk.style = strcmp( choose->style.name, target->style.name ) ;
  761. NEW_TARGET_SET( diff, choose, target, str_chk ) ;
  762. diff.shape.def = choose->shape.def - target->shape.def;
  763. if( (choose->shape.name != NULL) && (target->shape.name != NULL) ) {
  764. str_chk.shape = strcmp( choose->shape.name, target->shape.name ) ;
  765. }
  766. diff.cd_set = choose->cd_set - target->cd_set;
  767. diff.size.h = choose->size.h - target->size.h;
  768. diff.size.w = choose->size.w - target->size.w;
  769. diff.letter.h = choose->letter.h - target->letter.h;
  770. diff.letter.w = choose->letter.w - target->letter.w;
  771. /* codeset */
  772. if ( diff.cd_set < 0 ) return 1;
  773. if ( diff.cd_set > 0 ) return 0;
  774. /* character size height */
  775. if ( diff.size.h < 0 ) return 1;
  776. if ( diff.size.h > 0 ) return 0;
  777. /* letter size height */
  778. if ( diff.letter.h < 0 ) return 1;
  779. if ( diff.letter.h > 0 ) return 0;
  780. /* character size wide */
  781. if ( diff.size.w < 0 ) return 1;
  782. if ( diff.size.w > 0 ) return 0;
  783. /* letter size wide */
  784. if ( diff.letter.w < 0 ) return 1;
  785. if ( diff.letter.w > 0 ) return 0;
  786. /* style */
  787. if ( target->style.def == FAL_FONT_UNKNOWN ) {
  788. if ( choose->style.def > 0 ) return 1;
  789. /* style is FAL_FONT_UNKNOWN both "target" and "choose" */
  790. if ( str_chk.style < 0 ) return 1;
  791. if ( str_chk.style > 0) return 0;
  792. } else if ( choose->style.def == FAL_FONT_UNKNOWN ) {
  793. return 0;
  794. }
  795. /* target->style.def and choose->style.def is not FAL_FONT_UNKNOWN */
  796. if ( diff.style.def < 0 ) return 1;
  797. if ( diff.style.def > 0 ) return 0;
  798. NEW_TARGET_CHK( diff, choose, target, str_chk ) ;
  799. /* character style */
  800. if ( target->shape.def == FAL_FONT_UNKNOWN ) {
  801. if ( choose->shape.def > 0 ) return 1;
  802. if ( str_chk.shape < 0 ) return 1;
  803. if ( str_chk.shape > 0 ) return 0;
  804. } else if (choose->shape.def == FAL_FONT_UNKNOWN ) {
  805. return 0;
  806. }
  807. if ( diff.shape.def < 0 ) return 1;
  808. if ( diff.shape.def > 0 ) return 0;
  809. return 0;
  810. }