w32tex
About: TeX Live provides a comprehensive TeX system including all the major TeX-related programs, macro packages, and fonts that are free software. Windows sources.
  Fossies Dox: w32tex-src.tar.xz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

omfonts.c
Go to the documentation of this file.
1 /* omfonts.c: Main routine for ofm2opl, opl2ofm, ovf2ovp, ovp2ovf.
2 
3 This file is part of Omega,
4 which is based on the web2c distribution of TeX,
5 
6 Copyright (c) 1994--2001 John Plaice and Yannis Haralambous
7 
8 Omega is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version.
12 
13 Omega is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details.
17 
18 You should have received a copy of the GNU General Public License
19 along with Omega; if not, write to the Free Software Foundation, Inc.,
20 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
21 
22 */
23 
24 #define OMFONTS
25 #define OFM2OPL
26 #define OPL2OFM
27 #define OVP2OVF
28 #define OVF2OVP
29 #include "cpascal.h"
30 #include "parser.h"
31 #include "manifests.h"
32 #include "omfonts.h"
33 #include "list_routines.h"
34 #include "error_routines.h"
35 #include "header_routines.h"
36 #include "font_routines.h"
37 #include "param_routines.h"
38 #include "char_routines.h"
39 #include "dimen_routines.h"
40 #include "parse_ofm.h"
41 #include "out_ofm.h"
42 
43 #define PROG_MIN 0
44 #define PROG_OFM2OPL 0
45 #define PROG_OPL2OFM 1
46 #define PROG_OVF2OVP 2
47 #define PROG_OVP2OVF 3
48 #define PROG_OMFONTS 4
49 #define PROG_NUM 5
50 
51 #define cmdline(i) (argv[i])
52 
57 
58 int program;
59 
64 
70 
71 unsigned char *ofm = NULL;
72 unsigned char *ovf = NULL;
73 
74 unsigned length_ofm = 0;
75 unsigned length_ovf = 0;
76 
78 
80  "Usage: omfonts -ofm2opl [OPTION]... FILE...",
81  " omfonts -opl2ofm [OPTION]... FILE...",
82  " omfonts -ovf2ovp [OPTION]... FILE...",
83  " omfonts -ovp2ovf [OPTION]... FILE...",
84  "",
85  "be ofm2opl, opl2ofm, ovf2ovp, or ovp2ovf",
86  NULL
87 };
88 
90  { "ofm2opl", "opl2ofm", "ovf2ovp", "ovp2ovf", "omfonts" };
92  { OFM2OPLHELP, OPL2OFMHELP, OVF2OVPHELP, OVP2OVFHELP, OMFONTSHELP };
94  "This is ofm2opl, Version 2.1",
95  "This is opl2ofm, Version 2.1",
96  "This is ovf2ovp, Version 2.1",
97  "This is ovp2ovf, Version 2.1",
98  "This is omfonts, Version 2.1"
99 };
100 
101 int no_files=0;
105 
106 static struct option long_options[] = {
107  {"verbose", 0, &verbose_option, 1},
108  {"char-format", 1, 0, 0},
109  {"num-format", 1, 0, 0},
110  {"charcode-format", 1, 0, 0},
111  {"text-format", 1, 0, 0},
112  {"ofm2opl", 0, 0, 0},
113  {"opl2ofm", 0, 0, 0},
114  {"ovf2ovp", 0, 0, 0},
115  {"ovp2ovf", 0, 0, 0},
116  {"help", 0, 0, 0},
117  {"version", 0, 0, 0},
118  {0, 0, 0, 0}
119 };
120 
121 static void read_in_whole(unsigned char **, unsigned *, FILE *, const_string );
122 static void init_tables(void);
123 
124 int
125 main (int argc, string *argv)
126 {
127  int getopt_return_val;
128  int option_index = 0;
129 
131  if (FILESTRCASEEQ(name_program, "ofm2opl"))
133  else if (FILESTRCASEEQ(name_program, "opl2ofm"))
135  else if (FILESTRCASEEQ(name_program, "ovf2ovp"))
137  else if (FILESTRCASEEQ(name_program, "ovp2ovf"))
139  else
141 
142  do {
143  getopt_return_val =
145  if (getopt_return_val == -1) { ; }
146  else if ( getopt_return_val == '?' ) {
148  } else if (!strcmp(long_options[option_index].name, "help")) {
150  } else if (!strcmp(long_options[option_index ].name, "version")) {
152  "J. Plaice, Y. Haralambous, D.E. Knuth",
153  nil);
154  } else if (!strcmp(long_options[option_index ].name, "ofm2opl")) {
156  else usage (names_program[program]);
157  } else if (!strcmp(long_options[option_index ].name, "opl2ofm")) {
159  else usage (names_program[program]);
160  } else if (!strcmp(long_options[option_index ].name, "ovf2ovp")) {
162  else usage (names_program[program]);
163  } else if (!strcmp(long_options[option_index ].name, "ovp2ovf")) {
165  else usage (names_program[program]);
166  } else if (!strcmp(long_options[option_index ].name, "char-format")) {
167  if (!strcmp(optarg, "ascii")) char_format = CHAR_CODE_ASCII;
168  else if (!strcmp(optarg, "num")) char_format = CHAR_CODE_NUM;
169  else warning_s("Bad character code format (%s)", optarg);
170  } else if (!strcmp(long_options[option_index ].name, "num-format")) {
171  if (!strcmp(optarg, "hex")) num_format = NUM_CODE_HEX;
172  else if (!strcmp(optarg, "octal")) num_format = NUM_CODE_OCTAL;
173  else warning_s("Bad number code format (%s)", optarg);
174  } else if (!strcmp(long_options[option_index ].name, "charcode-format")) {
175  if (!strcmp(optarg, "ascii")) {
178  } else if (!strcmp(optarg, "hex")) {
181  } else if (!strcmp(optarg, "octal")) {
184  } else {
185  warning_s("Bad character code format (%s)", optarg);
186  }
187  } else if (!strcmp(long_options[option_index ].name, "text-format")) {
188  if (!strcmp(optarg, "upper")) text_format = TEXT_CODE_UPPER;
189  else if (!strcmp(optarg, "mixed")) text_format = TEXT_CODE_MIXED;
190  else warning_s("Bad text code format (%s)", optarg);
191  }
192  } while (getopt_return_val != -1);
193 
194  switch(program) {
195  case PROG_OFM2OPL: {
196  no_files = 2;
197  files[0] = &name_ofm;
198  files[1] = &name_opl;
199  suffixes[0] = "ofm";
200  suffixes[1] = "opl";
201  full_suffixes[0] = ".ofm";
202  full_suffixes[1] = ".opl";
203  break;
204  }
205  case PROG_OPL2OFM: {
206  no_files = 2;
207  files[0] = &name_opl;
208  files[1] = &name_ofm;
209  suffixes[0] = "opl";
210  suffixes[1] = "ofm";
211  full_suffixes[0] = ".opl";
212  full_suffixes[1] = ".ofm";
213  break;
214  }
215  case PROG_OVF2OVP: {
216  no_files = 3;
217  files[0] = &name_ovf;
218  files[1] = &name_ofm;
219  files[2] = &name_ovp;
220  suffixes[0] = "ovf";
221  suffixes[1] = "ofm";
222  suffixes[2] = "ovp";
223  full_suffixes[0] = ".ovf";
224  full_suffixes[1] = ".ofm";
225  full_suffixes[2] = ".ovp";
226  break;
227  }
228  case PROG_OVP2OVF: {
229  no_files = 3;
230  files[0] = &name_ovp;
231  files[1] = &name_ovf;
232  files[2] = &name_ofm;
233  suffixes[0] = "ovp";
234  suffixes[1] = "ovf";
235  suffixes[2] = "ofm";
236  full_suffixes[0] = ".ovp";
237  full_suffixes[1] = ".ovf";
238  full_suffixes[2] = ".ofm";
239  break;
240  }
241  default: {
242  fprintf(stderr , "Unrecognized program: %s\n", name_program);
243  fprintf(stderr ,
244  "This binary supports ofm2opl, opl2ofm, ovf2ovp, and ovp2ovf\n");
245  usage ("omfonts");
246  }
247  }
248 
250  kpse_set_program_name(argv[0], name_program);
251  kpse_init_prog(uppercasify(name_program), 0, nil, nil);
252 
253  if (((argc-optind) > no_files) || ((argc-optind) < 1)) {
254  fprintf(stderr , "%s: %s\n", name_program,
255  no_files == 2 ? "Need one or two file arguments."
256  : "Need one to three file arguments.");
258  }
260  if (optind+2 <= argc) {
261  *(files[1]) = extend_filename(cmdline(optind+1) , suffixes[1]);
262  if (no_files == 3) {
263  if (optind+3 <= argc) {
264  *(files[2]) = extend_filename(cmdline(optind+2) , suffixes[2]);
265  } else if (program == PROG_OVP2OVF) {
266  *(files[2]) = make_suffix(cmdline(optind+1), suffixes[2]);
267  }
268  }
269  } else if (program != PROG_OFM2OPL) {
270  *(files[1]) = basenamechangesuffix(*(files[0]),
272  if ((no_files == 3) && (program == PROG_OVP2OVF)) {
273  *(files[2]) = basenamechangesuffix(*(files[0]),
275  }
276  }
277 
278  switch(program) {
279  case PROG_OFM2OPL: {
280  file_ofm = kpse_open_file(name_ofm, kpse_ofm_format);
282  (void)fclose(file_ofm);
283  if (name_opl==NULL) file_opl = stdout;
284  else rewrite(file_opl, name_opl);
286  parse_ofm(FALSE);
287  break;
288  }
289  case PROG_OVF2OVP: {
290  file_ovf = kpse_open_file(name_ovf, kpse_ovf_format);
292  (void)fclose(file_ovf);
293  file_ofm = kpse_open_file(name_ofm, kpse_ofm_format);
295  (void)fclose(file_ofm);
296  if (name_ovp==NULL) file_ovp = stdout;
297  else rewrite(file_ovp, name_ovp);
299  parse_ofm(TRUE);
300  break;
301  }
302  case PROG_OPL2OFM: {
303  file_opl = kpse_open_file(name_opl, kpse_opl_format);
305  init_tables();
306  yyin = file_opl;
307  (void)yyparse();
308  output_ofm_file();
309  (void)fclose(file_ofm);
310  if (num_errors > 0) exit(1);
311  break;
312  }
313  case PROG_OVP2OVF: {
314  file_ovp = kpse_open_file(name_ovp, kpse_ovp_format);
317  init_tables();
318  yyin = file_ovp;
319  (void)yyparse();
320  output_ofm_file();
321  (void)fclose(file_ofm);
322  output_ovf_file();
323  (void)fclose(file_ovf);
324  if (num_errors > 0) exit(1);
325  break;
326  }
327  default: {exit(1);}
328  }
329  exit(0);
330 }
331 
332 #define BIG_BLOCK 0x20000
333 #define LITTLE_BLOCK 0x1000
334 
335 static void
336 read_in_whole(unsigned char **contents_loc,
337  unsigned *length_loc,
338  FILE *file,
340 {
341  unsigned no_read;
342  unsigned no_total_read = 0;
343  unsigned size = BIG_BLOCK;
344  string where;
345  string current_block;
346 
347  current_block = (char *) xmalloc(size);
348  where = current_block;
349 
350  while (1) {
351  no_read = fread(where, 1, LITTLE_BLOCK, file);
352  no_total_read += no_read;
353  if ((no_total_read+LITTLE_BLOCK) > size) {
354  size *= 2;
355  current_block = (char *) xrealloc(current_block, size);
356  }
357  where = current_block + no_total_read;
358  if (ferror(file)) {
359  fatal_error_s("Error while reading file %s", name);
360  } else if (feof(file)) {
361  break;
362  }
363  }
364 
365  *contents_loc = (unsigned char *) current_block;
366  *length_loc = no_total_read;
367 }
368 
369 static void
371 {
372  font_table_init(); /* subsidiary fonts in virtual fonts */
373  init_header();
374  init_planes();
375  init_measures();
376 }
377 
#define name
void init_planes(void)
Definition: char_routines.c:91
@ FALSE
Definition: dd.h:101
@ TRUE
Definition: dd.h:102
void init_measures(void)
#define fread
Definition: xxstdio.h:25
#define nil
Definition: dvi2tty.h:53
int strcmp()
Definition: coll.cpp:143
#define FILESTRCASEEQ
Definition: dvips.h:372
void fatal_error_s(const_string fmt, const_string item)
void warning_s(const_string fmt, const_string item)
int num_errors
void font_table_init(void)
Definition: font_routines.c:50
void output_ovf_file(void)
static void
Definition: fpif.c:118
#define yyin
#define yyparse
static char usage[]
Definition: giftopnm.c:59
static void * xrealloc(char *oldp, unsigned size)
Definition: gsftopk.c:643
void init_header(void)
void usagehelp(const_string *message, const_string bug_email)
Definition: jlib.c:16
void printversionandexit(const_string banner, const_string copyright_holder, const_string author, char *extra_info)
Definition: jlib.c:30
#define NULL
Definition: ftobjs.h:61
void exit()
int optind
Definition: getopt.c:39
char * optarg
Definition: getopt.c:42
int getopt_long_only()
#define xmalloc(size)
Definition: writet1.c:33
char * make_suffix(const char *s, const char *suffix)
Definition: utils.c:190
#define fclose
Definition: debug.h:100
const_string extend_filename(const_string name, const_string default_suffix)
Definition: extend-fname.c:22
KPSEDLL string uppercasify(const_string s)
Definition: uppercasify.c:24
string kpse_program_basename(const_string argv0)
Definition: progname.c:737
const char * const_string
Definition: simpletypes.h:59
@ kpse_opl_format
Definition: types.h:124
@ kpse_ovf_format
Definition: types.h:126
@ kpse_ofm_format
Definition: types.h:123
@ kpse_ovp_format
Definition: types.h:127
#define fprintf
Definition: mendex.h:64
#define rewrite(f, n)
Definition: cpascal.h:80
#define rewritebin(f, n)
Definition: cpascal.h:82
string basenamechangesuffix(const_string name, const_string old_suffix, const_string new_suffix)
Definition: basechsuffix.c:16
int option_index
Definition: getopt.c:147
int char_format
Definition: omfonts.c:54
#define BIG_BLOCK
Definition: omfonts.c:332
const_string name_ovf
Definition: omfonts.c:63
unsigned length_ovf
Definition: omfonts.c:75
FILE * file_opl
Definition: omfonts.c:66
#define PROG_OVF2OVP
Definition: omfonts.c:46
int program
Definition: omfonts.c:58
#define PROG_OVP2OVF
Definition: omfonts.c:47
#define PROG_OMFONTS
Definition: omfonts.c:48
#define PROG_OFM2OPL
Definition: omfonts.c:44
const_string name_program
Definition: omfonts.c:77
const_string suffixes[3]
Definition: omfonts.c:103
const_string * files[3]
Definition: omfonts.c:102
unsigned length_ofm
Definition: omfonts.c:74
static const_string names_msg[5]
Definition: omfonts.c:93
#define LITTLE_BLOCK
Definition: omfonts.c:333
FILE * file_ofm
Definition: omfonts.c:65
const_string name_opl
Definition: omfonts.c:61
#define PROG_OPL2OFM
Definition: omfonts.c:45
int num_format
Definition: omfonts.c:55
const_string OMFONTSHELP[]
Definition: omfonts.c:79
FILE * file_output
Definition: omfonts.c:69
const_string name_ofm
Definition: omfonts.c:60
FILE * file_ovp
Definition: omfonts.c:67
unsigned char * ofm
Definition: omfonts.c:71
int verbose_option
Definition: omfonts.c:53
static const_string names_program[5]
Definition: omfonts.c:89
static void init_tables(void)
Definition: omfonts.c:370
FILE * file_ovf
Definition: omfonts.c:68
static struct option long_options[]
Definition: omfonts.c:106
int main(int argc, string *argv)
Definition: omfonts.c:125
static const_string * names_help[5]
Definition: omfonts.c:91
#define cmdline(i)
Definition: omfonts.c:51
static void read_in_whole(unsigned char **, unsigned *, FILE *, const_string)
Definition: omfonts.c:336
int no_files
Definition: omfonts.c:101
const_string name_ovp
Definition: omfonts.c:62
int text_format
Definition: omfonts.c:56
unsigned char * ovf
Definition: omfonts.c:72
#define PROG_NUM
Definition: omfonts.c:49
const_string full_suffixes[3]
Definition: omfonts.c:104
#define CHAR_CODE_NUM
Definition: omfonts.h:24
#define NUM_CODE_OCTAL
Definition: omfonts.h:27
#define NUM_CODE_HEX
Definition: omfonts.h:26
#define TEXT_CODE_UPPER
Definition: omfonts.h:28
#define CHAR_CODE_ASCII
Definition: omfonts.h:25
#define TEXT_CODE_MIXED
Definition: omfonts.h:29
void output_ofm_file(void)
Definition: out_ofm.c:42
void parse_ofm(boolean read_ovf)
Definition: parse_ofm.c:93
static int size
Definition: ppmlabel.c:24
Definition: filedef.h:30
Definition: getopt.h:95
#define FILE
Definition: t1stdio.h:34
#define feof(f)
Definition: t1stdio.h:109
#define ferror(f)
Definition: t1stdio.h:110
#define argv
Definition: xmain.c:270
#define argc
Definition: xmain.c:269