bdftopcf.c revision 5dd2154e
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, 149 "usage: %s [-p#] [-u#] [-m] [-l] [-M] [-L] [-t] [-i] [-o pcf file] [bdf file]\n" 150 " where # for -p is 1, 2, 4, or 8\n" 151 " and # for -s is 1, 2, or 4\n", 152 program_name); 153 exit(1); 154 } 155 input_name = argv[0]; 156 } 157 argv++; 158 } 159 if (input_name) { 160 input = FontFileOpen(input_name); 161 if (!input) { 162 fprintf(stderr, "%s: can't open bdf source file %s\n", 163 program_name, input_name); 164 exit(1); 165 } 166 } 167 else 168 input = FontFileOpenFd(STDIN_FILENO); 169 if (bdfReadFont(&font, input, bit, byte, glyph, scan) != Successful) { 170 fprintf(stderr, "%s: bdf input, %s, corrupt\n", 171 program_name, input_name ? input_name : "<stdin>"); 172 exit(1); 173 } 174 if (output_name) { 175 output = FontFileOpenWrite(output_name); 176 if (!output) { 177 fprintf(stderr, "%s: can't open pcf sink file %s\n", 178 program_name, output_name); 179 exit(1); 180 } 181 } 182 else 183 output = FontFileOpenWriteFd(STDOUT_FILENO); 184 if (pcfWriteFont(&font, output) != Successful) { 185 fprintf(stderr, "%s: can't write pcf file %s\n", 186 program_name, output_name ? output_name : "<stdout>"); 187 if (output_name) 188 remove(output_name); 189 exit(1); 190 } 191 else 192 FontFileClose(output); 193 return (0); 194} 195