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