cpftobdf.c 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282
  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: cpftobdf.c /main/6 1996/11/08 02:02:03 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 <signal.h>
  32. #include <string.h>
  33. #include <stdlib.h>
  34. #include <unistd.h>
  35. #include "bdfgpf.h"
  36. #include "udcutil.h"
  37. static void put_error(struct ptobhead *head, int er_no, char *prog_name);
  38. static void put_help(char *prog_name);
  39. static void Usage(char *prog_name);
  40. static int CnvGPFtoBDF(struct ptobhead *head) ;
  41. static void sigint_out(void) ;
  42. static struct ptobhead Head;
  43. static void
  44. sigint_out(void)
  45. {
  46. if ( Head.out_file ) {
  47. unlink( Head.out_file );
  48. }
  49. exit( 0 );
  50. }
  51. int main( int argc, char *argv[])
  52. {
  53. int rtn, i;
  54. char *GetTmpPath();
  55. char *spacing ;
  56. char *xlfdname ;
  57. for ( i = 1; i < argc; i++ ) {
  58. if ( !strcmp( argv[i], "-help" ) ) {
  59. put_help( argv[0] );
  60. exit( 0 );
  61. }
  62. }
  63. if ( !( argc % 2 ) ) {
  64. Usage(argv[0]);
  65. }
  66. spacing = xlfdname = NULL ;
  67. Head.in_file = Head.bdf_file = Head.snf_file = Head.out_file = NULL;
  68. Head.start_code = MIN_CODE ;
  69. Head.end_code = MAX_CODE ;
  70. Head.code_category = ALL_CODE;
  71. if (!( bdftopcf = get_cmd_path( getenv( "PATH"), BDFTOPCF_CMD ))){
  72. bdftopcf = BDFTOPCF;
  73. }
  74. if (!( oakgtobdf = get_cmd_path( getenv( "PATH"), SNFTOBDF_CMD ))) {
  75. oakgtobdf = SNFTOBDF;
  76. }
  77. for ( i = 1; i < argc; i+=2 ) {
  78. if ( !strcmp( argv[i], "-bdf" ) ) {
  79. Head.bdf_file = argv[ i+1 ];
  80. } else if ( !strcmp( argv[i], "-p" ) ) {
  81. Head.in_file = argv[i+1];
  82. } else if ( !strcmp( argv[i], "-g" ) ) {
  83. Head.snf_file = argv[i+1];
  84. } else {
  85. Usage( argv[0] );
  86. }
  87. }
  88. if ( Head.in_file == NULL ) {
  89. Head.input = stdin;
  90. } else {
  91. if ( ( Head.input = fopen( Head.in_file, "r" ) ) == NULL ) {
  92. USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n", argv[0], Head.in_file );
  93. exit( GPF_OPEN * (-1) );
  94. }
  95. }
  96. signal( SIGHUP, (void(*)())sigint_out );
  97. signal( SIGINT, (void(*)())sigint_out );
  98. signal( SIGQUIT, (void(*)())sigint_out );
  99. signal( SIGTERM, (void(*)())sigint_out );
  100. if ( Head.bdf_file == NULL ) {
  101. if ( Head.snf_file == NULL ) {
  102. USAGE1("%s: If the output is stdout, the user defined font file name cannot be omitted.\n", argv[0]);
  103. exit(PARAM_ERROR * (-1));
  104. }
  105. Head.output = stdout;
  106. } else {
  107. if ( ! ( Head.out_file = GetTmpPath( Head.bdf_file ) ) ) {
  108. exit( FATAL_ERROR * ( -1 ) );
  109. }
  110. if ( ( Head.output = fopen( Head.out_file, "w" ) ) == NULL ) {
  111. USAGE2("%s: The work file for the output cannot be opened. \"%s\"\n", argv[0], Head.out_file );
  112. exit( BDF_OPEN * (-1) );
  113. }
  114. }
  115. /* refuse proportional fonts */
  116. if ( GetUdcFontName( Head.snf_file, Head.bdf_file, &xlfdname ) ) {
  117. USAGE1("%s : This font cannot get XLFD. Terminates abnormally.\n", argv[0]);
  118. if ( Head.in_file != NULL ) {
  119. fclose( Head.input );
  120. }
  121. if ( Head.out_file != NULL ) {
  122. fclose( Head.output );
  123. unlink( Head.out_file );
  124. }
  125. exit( 1 );
  126. }
  127. GETSPACINGSTR( spacing, xlfdname ) ;
  128. if ( !strcmp( "p", spacing ) || !strcmp( "P", spacing ) ) {
  129. USAGE2("%s cannot edit proportional fonts.(SPACING \"%s\")\n", argv[0], spacing );
  130. if ( Head.in_file != NULL ) {
  131. fclose( Head.input );
  132. }
  133. if ( Head.out_file != NULL ) {
  134. fclose( Head.output );
  135. unlink( Head.out_file );
  136. }
  137. exit( 1 );
  138. }
  139. if ( ( rtn = CnvGPFtoBDF( &Head ) ) ) {
  140. if ( Head.in_file != NULL ) {
  141. fclose( Head.input );
  142. }
  143. if ( Head.out_file != NULL ) {
  144. fclose( Head.output );
  145. unlink( Head.out_file );
  146. }
  147. put_error( &Head, rtn, argv[0] );
  148. exit( rtn * (-1) );
  149. }
  150. if ( Head.in_file != NULL ) {
  151. fclose( Head.input );
  152. }
  153. if ( Head.out_file != NULL ) {
  154. fclose( Head.output );
  155. signal( SIGHUP, SIG_IGN );
  156. signal( SIGINT, SIG_IGN );
  157. signal( SIGQUIT, SIG_IGN );
  158. signal( SIGTERM, SIG_IGN );
  159. if ( Head.bdf_file != NULL ) {
  160. Link_NewFile( Head.out_file, Head.bdf_file );
  161. unlink( Head.out_file );
  162. }
  163. }
  164. exit( 0 );
  165. }
  166. static
  167. CnvGPFtoBDF(struct ptobhead *head)
  168. {
  169. char textbuf[BUFSIZE] ;
  170. int rtn ;
  171. if ( ( rtn = ReadGpfHeader( head, textbuf ) ) ) {
  172. return rtn;
  173. }
  174. if ( ( rtn = WriteBdfHeader( head ) ) ) {
  175. return rtn;
  176. }
  177. if ( ( head->p_width != head->bdf_width )
  178. || ( head->p_height != head->bdf_height )
  179. ) {
  180. head->zoomf = 1;
  181. } else {
  182. head->zoomf = 0;
  183. }
  184. if ( ( head->code = (int *)malloc( sizeof(int) * head->num_chars ) ) == NULL ) {
  185. return FATAL_ERROR;
  186. }
  187. if ( ( head->ptn = (char **)malloc( sizeof( char * ) * head->num_chars ) ) == NULL ) {
  188. return FATAL_ERROR;
  189. }
  190. if ( ( rtn = ReadGpfToMemory( head, textbuf ) ) ) {
  191. return rtn;
  192. }
  193. if ( ( rtn = WritePtnToBdf( head ) ) ) {
  194. return rtn;
  195. }
  196. return 0;
  197. }
  198. static void
  199. put_error(struct ptobhead *head, int er_no, char *prog_name)
  200. {
  201. switch( er_no ) {
  202. case FATAL_ERROR:
  203. USAGE1("%s: Failed convert.\n", prog_name );
  204. break;
  205. case BDF_OPEN:
  206. USAGE2("%s: The BDF file cannot be opened. \"%s\"\n", prog_name, head->bdf_file );
  207. break;
  208. case BDF_READ:
  209. USAGE2("%s: The BDF file cannot be read. \"%s\"\n", prog_name, head->bdf_file );
  210. break;
  211. case BDF_WRITE:
  212. USAGE2("%s: It is not possible to write to the BDF file. \"%s\"\n", prog_name, head->out_file );
  213. break;
  214. case BDF_INVAL:
  215. if ( head->snf_file ) {
  216. USAGE2("%s: The information from the font file cannot be obtained.\"%s\"\n", prog_name, head->snf_file );
  217. } else {
  218. USAGE2("%s: The format of the BDF file is illegal. \"%s\"\n", prog_name, head->bdf_file );
  219. }
  220. break;
  221. case GPF_OPEN:
  222. USAGE2("%s: The character pattern file cannot be opened. \"%s\"\n", prog_name, head->in_file );
  223. break;
  224. case GPF_READ:
  225. USAGE2("%s: The character pattern file cannot be read. \"%s\"\n", prog_name, head->in_file );
  226. break;
  227. case GPF_INVAL:
  228. USAGE2("%s: The format of the character pattern file is illegal. \"%s\"\n", prog_name, head->in_file );
  229. break;
  230. default:
  231. break;
  232. }
  233. }
  234. static void
  235. put_help( char *prog_name)
  236. {
  237. USAGE1("Usage: %s [-bdf BDF_file_name] [-p chracter_pattern_file_name]\n", prog_name);
  238. USAGE("\t\t[-g user_defined_character_file_name] [-help]\n");
  239. }
  240. static void
  241. Usage( char *prog_name)
  242. {
  243. put_help( prog_name );
  244. exit( PARAM_ERROR * (-1) );
  245. }