bdftopcf.c 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  1. /*
  2. Copyright 1991, 1993, 1998 The Open Group
  3. Permission to use, copy, modify, distribute, and sell this software and its
  4. documentation for any purpose is hereby granted without fee, provided that
  5. the above copyright notice appear in all copies and that both that
  6. copyright notice and this permission notice appear in supporting
  7. documentation.
  8. The above copyright notice and this permission notice shall be included
  9. in all copies or substantial portions of the Software.
  10. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  11. OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  12. MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
  13. IN NO EVENT SHALL THE OPEN GROUP BE LIABLE FOR ANY CLAIM, DAMAGES OR
  14. OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  15. ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  16. OTHER DEALINGS IN THE SOFTWARE.
  17. Except as contained in this notice, the name of The Open Group shall
  18. not be used in advertising or otherwise to promote the sale, use or
  19. other dealings in this Software without prior written authorization
  20. from The Open Group.
  21. */
  22. #ifdef HAVE_CONFIG_H
  23. # include "config.h"
  24. #endif
  25. #include <X11/X.h>
  26. #include <X11/Xproto.h>
  27. #include <X11/fonts/fontmisc.h>
  28. #include <X11/fonts/fontstruct.h>
  29. #include <X11/fonts/fntfilio.h>
  30. #include <X11/fonts/fntfil.h>
  31. #include <X11/fonts/bdfint.h>
  32. #include <X11/fonts/pcf.h>
  33. #include <stdio.h>
  34. #include <X11/Xos.h>
  35. int
  36. main(int argc, char *argv[])
  37. {
  38. FontRec font = { 0 };
  39. FontFilePtr input, output;
  40. char *input_name = NULL, *output_name = NULL;
  41. char *program_name;
  42. int bit, byte, glyph, scan;
  43. FontDefaultFormat(&bit, &byte, &glyph, &scan);
  44. program_name = argv[0];
  45. argc--, argv++;
  46. while (argc-- > 0) {
  47. if (argv[0][0] == '-') {
  48. switch (argv[0][1]) {
  49. case 'p':
  50. switch (argv[0][2]) {
  51. case '1':
  52. case '2':
  53. case '4':
  54. case '8':
  55. if (argv[0][3] != '\0')
  56. goto usage;
  57. glyph = argv[0][2] - '0';
  58. break;
  59. default:
  60. goto usage;
  61. }
  62. break;
  63. case 'u':
  64. switch (argv[0][2]) {
  65. case '1':
  66. case '2':
  67. case '4':
  68. if (argv[0][3] != '\0')
  69. goto usage;
  70. scan = argv[0][2] - '0';
  71. break;
  72. default:
  73. goto usage;
  74. }
  75. break;
  76. case 'm':
  77. if (argv[0][2] != '\0')
  78. goto usage;
  79. bit = MSBFirst;
  80. break;
  81. case 'l':
  82. if (argv[0][2] != '\0')
  83. goto usage;
  84. bit = LSBFirst;
  85. break;
  86. case 'M':
  87. if (argv[0][2] != '\0')
  88. goto usage;
  89. byte = MSBFirst;
  90. break;
  91. case 'L':
  92. if (argv[0][2] != '\0')
  93. goto usage;
  94. byte = LSBFirst;
  95. break;
  96. case 't': /* attempt to make terminal fonts if possible */
  97. if (argv[0][2] != '\0')
  98. goto usage;
  99. break;
  100. case 'i': /* inhibit ink metric computation */
  101. if (argv[0][2] != '\0')
  102. goto usage;
  103. break;
  104. case 'o':
  105. if (argv[0][2])
  106. output_name = argv[0] + 2;
  107. else {
  108. if (!argv[1])
  109. goto usage;
  110. argv++;
  111. argc--;
  112. output_name = argv[0];
  113. }
  114. break;
  115. case 'v':
  116. printf("%s\n", PACKAGE_STRING);
  117. exit(0);
  118. default:
  119. goto usage;
  120. }
  121. }
  122. else {
  123. if (input_name) {
  124. usage:
  125. fprintf(stderr, "%s: invalid option '%s'\n",
  126. program_name, argv[0]);
  127. fprintf(stderr,
  128. "usage: %s [-p#] [-u#] [-m] [-l] [-M] [-L] [-t] [-i] [-o pcf file] [bdf file]\n"
  129. " where # for -p is 1, 2, 4, or 8\n"
  130. " and # for -u is 1, 2, or 4\n",
  131. program_name);
  132. exit(1);
  133. }
  134. input_name = argv[0];
  135. }
  136. argv++;
  137. }
  138. if (input_name) {
  139. input = FontFileOpen(input_name);
  140. if (!input) {
  141. fprintf(stderr, "%s: can't open bdf source file %s\n",
  142. program_name, input_name);
  143. exit(1);
  144. }
  145. }
  146. else
  147. input = FontFileOpenFd(STDIN_FILENO);
  148. if (bdfReadFont(&font, input, bit, byte, glyph, scan) != Successful) {
  149. fprintf(stderr, "%s: bdf input, %s, corrupt\n",
  150. program_name, input_name ? input_name : "<stdin>");
  151. exit(1);
  152. }
  153. if (output_name) {
  154. output = FontFileOpenWrite(output_name);
  155. if (!output) {
  156. fprintf(stderr, "%s: can't open pcf sink file %s\n",
  157. program_name, output_name);
  158. exit(1);
  159. }
  160. }
  161. else
  162. output = FontFileOpenWriteFd(STDOUT_FILENO);
  163. if (pcfWriteFont(&font, output) != Successful) {
  164. fprintf(stderr, "%s: can't write pcf file %s\n",
  165. program_name, output_name ? output_name : "<stdout>");
  166. if (output_name)
  167. remove(output_name);
  168. exit(1);
  169. }
  170. else
  171. FontFileClose(output);
  172. return (0);
  173. }