Back to index

tetex-bin  3.0
omfonts.c
Go to the documentation of this file.
00001 /* omfonts.c: Main routine for ofm2opl, opl2ofm, ovf2ovp, ovp2ovf.
00002 
00003 This file is part of Omega,
00004 which is based on the web2c distribution of TeX,
00005 
00006 Copyright (c) 1994--2001 John Plaice and Yannis Haralambous
00007 
00008 Omega is free software; you can redistribute it and/or modify
00009 it under the terms of the GNU General Public License as published by
00010 the Free Software Foundation; either version 2 of the License, or
00011 (at your option) any later version.
00012 
00013 Omega is distributed in the hope that it will be useful,
00014 but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 GNU General Public License for more details.
00017 
00018 You should have received a copy of the GNU General Public License
00019 along with Omega; if not, write to the Free Software Foundation, Inc.,
00020 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
00021 
00022 */
00023 
00024 #define OFM2OPL
00025 #define OPL2OFM
00026 #define OVP2OVF
00027 #define OVF2OVP
00028 #include "cpascal.h"
00029 #include "parser.h"
00030 #include "manifests.h"
00031 #include "omfonts.h"
00032 #include "list_routines.h"
00033 #include "error_routines.h"
00034 #include "header_routines.h"
00035 #include "font_routines.h"
00036 #include "param_routines.h"
00037 #include "char_routines.h"
00038 #include "dimen_routines.h"
00039 #include "parse_ofm.h"
00040 
00041 #define PROG_MIN            0
00042 #define PROG_OFM2OPL 0
00043 #define PROG_OVF2OVP 1
00044 #define PROG_OPL2OFM 2
00045 #define PROG_OVP2OVF 3
00046 #define PROG_MAX            3
00047 
00048 extern FILE *yyin;
00049 
00050 #define cmdline(i) (argv[i])
00051 
00052 int verbose_option;
00053 int char_format = CHAR_CODE_NUM;
00054 int num_format  = NUM_CODE_HEX;
00055 int text_format = TEXT_CODE_MIXED;
00056 
00057 int program;
00058 
00059 string name_ofm = NULL;
00060 string name_opl = NULL;
00061 string name_ovp = NULL;
00062 string name_ovf = NULL;
00063 
00064 FILE *file_ofm = NULL;
00065 FILE *file_opl = NULL;
00066 FILE *file_ovp = NULL;
00067 FILE *file_ovf = NULL;
00068 FILE *file_output = NULL;
00069 
00070 unsigned char *ofm = NULL;
00071 unsigned char *ovf = NULL;
00072 
00073 unsigned length_ofm = 0;
00074 unsigned length_ovf = 0;
00075 
00076 const_string name_program;
00077 const_string *name_help;
00078 string name_msg;
00079 
00080 string name_empty = NULL;
00081 
00082 int no_files=0;
00083 string *files[3] = {NULL, NULL, NULL};
00084 string suffixes[3] = {NULL, NULL, NULL};
00085 string full_suffixes[3] = {NULL, NULL, NULL};
00086 
00087 static struct option long_options[] = {
00088     {"verbose", 0, &verbose_option, 1},
00089     {"char-format", 1, 0, 0},
00090     {"num-format", 1, 0, 0},
00091     {"text-format", 1, 0, 0},
00092     {"help", 0, 0, 0},
00093     {"version", 0, 0, 0},
00094     {0, 0, 0, 0}
00095 };
00096 
00097 int
00098 main (int argc, string *argv)
00099 {
00100     int getopt_return_val;
00101     int option_index = 0;
00102 
00103     name_program = xbasename(argv[0]);
00104     if (!strcmp(name_program, "ofm2opl") ||
00105         !strcmp(name_program, "OFM2OPL.EXE")) {
00106         program = PROG_OFM2OPL;
00107         name_help = OFM2OPLHELP;
00108        name_program = "ofm2opl";
00109         name_msg = "This is ofm2opl, Version 2.0";
00110         no_files = 2;
00111         files[0] = &name_ofm;
00112         files[1] = &name_opl;
00113         suffixes[0] = "ofm";
00114         suffixes[1] = "opl";
00115         full_suffixes[0] = ".ofm";
00116         full_suffixes[1] = ".opl";
00117     } else if (!strcmp(name_program, "opl2ofm") ||
00118                !strcmp(name_program, "OPL2OFM.EXE")) {
00119         program = PROG_OPL2OFM;
00120         name_help = OPL2OFMHELP;
00121        name_program = "opl2ofm";
00122         name_msg = "This is opl2ofm, Version 2.0";
00123         no_files = 2;
00124         files[0] = &name_opl;
00125         files[1] = &name_ofm;
00126         suffixes[0] = "opl";
00127         suffixes[1] = "ofm";
00128         full_suffixes[0] = ".opl";
00129         full_suffixes[1] = ".ofm";
00130     } else if (!strcmp(name_program, "ovp2ovf") ||
00131                !strcmp(name_program, "OVP2OVF.EXE")) {
00132         program = PROG_OVP2OVF;
00133         name_help = OVP2OVFHELP;
00134        name_program = "ovp2ovf";
00135         name_msg = "This is ovp2ovf, Version 2.0";
00136         no_files = 3;
00137         files[0] = &name_ovp;
00138         files[1] = &name_ovf;
00139         files[2] = &name_ofm;
00140         suffixes[0] = "ovp";
00141         suffixes[1] = "ovf";
00142         suffixes[2] = "ofm";
00143         full_suffixes[0] = ".ovp";
00144         full_suffixes[1] = ".ovf";
00145         full_suffixes[2] = ".ofm";
00146     } else if (!strcmp(name_program, "ovf2ovp") ||
00147                !strcmp(name_program, "OVF2OVP.EXE")) {
00148         program = PROG_OVF2OVP;
00149         name_help = OVF2OVPHELP;
00150        name_program = "ovf2ovp";
00151         name_msg = "This is ovf2ovp, Version 2.0";
00152         no_files = 3;
00153         files[0] = &name_ovf;
00154         files[1] = &name_ofm;
00155         files[2] = &name_ovp;
00156         suffixes[0] = "ovf";
00157         suffixes[1] = "ofm";
00158         suffixes[2] = "ovp";
00159         full_suffixes[0] = ".ovf";
00160         full_suffixes[1] = ".ofm";
00161         full_suffixes[2] = ".ovp";
00162     } else {
00163         fprintf(stderr , "Unrecognized program: %s\n", name_program);
00164         fprintf(stderr ,
00165         "This binary supports ofm2opl, opl2ofm, ovf2ovp, and ovp2ovf\n");
00166         exit(1);
00167     }
00168     kpse_set_program_name(name_program, NULL);
00169     kpse_init_prog(uppercasify(name_program), 0, nil, nil);
00170 
00171     do {
00172         getopt_return_val =
00173         getopt_long_only(argc, argv, "", long_options, &option_index) ;
00174         if (getopt_return_val == -1) { ; }
00175         else if ( getopt_return_val == 63 ) {
00176             usage (name_program);
00177         } else if (!strcmp(long_options[option_index].name, "help")) {
00178             usagehelp (name_help, NULL);
00179         } else if (!strcmp(long_options[option_index ].name, "version")) {
00180             printversionandexit(name_msg, nil,
00181                 "J. Plaice, Y. Haralambous, D.E. Knuth");
00182         } else if (!strcmp(long_options[option_index ].name, "char-format")) {
00183             if (!strcmp(optarg, "ascii")) char_format = CHAR_CODE_ASCII;
00184             else if (!strcmp(optarg, "num")) char_format = CHAR_CODE_NUM;
00185             else warning_s("Bad character code format (%s)", optarg);
00186         } else if (!strcmp(long_options[option_index ].name, "num-format")) {
00187             if (!strcmp(optarg, "hex")) num_format = NUM_CODE_HEX;
00188             else if (!strcmp(optarg, "octal")) num_format = NUM_CODE_OCTAL;
00189             else warning_s("Bad number code format (%s)", optarg);
00190         } else if (!strcmp(long_options[option_index ].name, "text-format")) {
00191             if (!strcmp(optarg, "upper")) text_format = TEXT_CODE_UPPER;
00192             else if (!strcmp(optarg, "mixed")) text_format = TEXT_CODE_MIXED;
00193             else warning_s("Bad text code format (%s)", optarg);
00194         }
00195     } while (getopt_return_val != -1);
00196     if (((argc-optind) > no_files) || ((argc-optind) < 1)) {
00197         fprintf(stderr , "%s: %s\n", name_program,
00198                 no_files == 2 ? "Need one or two file arguments."
00199                               : "Need one to three file arguments.");
00200         usage (name_program);
00201     }
00202     *(files[0]) = extend_filename(cmdline(optind) , suffixes[0]);
00203     if (optind+2 <= argc) {
00204         *(files[1]) = extend_filename(cmdline(optind+1) , suffixes[1]);
00205         if (no_files == 3) {
00206             if (optind+3 <= argc) {
00207                 *(files[2]) = extend_filename(cmdline(optind+2) , suffixes[2]);
00208             } else if (program == PROG_OVP2OVF) {
00209                 *(files[2]) = extend_filename(cmdline(optind+1), suffixes[2]);
00210             }
00211         }
00212     } else if (program != PROG_OFM2OPL) {
00213         *(files[1]) = basenamechangesuffix(*(files[0]),
00214                       full_suffixes[0], full_suffixes[1]);
00215         if ((no_files == 3) && (program == PROG_OVP2OVF)) {
00216             *(files[2]) = basenamechangesuffix(*(files[0]),
00217                       full_suffixes[0], full_suffixes[2]);
00218         }
00219     }
00220 
00221     switch(program) {
00222         case PROG_OFM2OPL: {
00223             file_ofm = kpse_open_file(name_ofm, kpse_ofm_format);
00224             read_in_whole(&ofm, &length_ofm, file_ofm, name_ofm);
00225             (void)fclose(file_ofm);
00226             if (name_opl==NULL) file_opl = stdout;
00227             else rewrite(file_opl, name_opl);
00228             file_output = file_opl;
00229             parse_ofm(FALSE);
00230             break;
00231         }
00232         case PROG_OVF2OVP: {
00233             file_ovf = kpse_open_file(name_ovf, kpse_ovf_format);
00234             read_in_whole(&ovf, &length_ovf, file_ovf, name_ovf);
00235             (void)fclose(file_ovf);
00236             file_ofm = kpse_open_file(name_ofm, kpse_ofm_format);
00237             read_in_whole(&ofm, &length_ofm, file_ofm, name_ofm);
00238             (void)fclose(file_ofm);
00239             if (name_ovp==NULL) file_ovp = stdout;
00240             else rewrite(file_ovp, name_ovp);
00241             file_output = file_ovp;
00242             parse_ofm(TRUE);
00243             break;
00244         }
00245         case PROG_OPL2OFM: {
00246             file_opl = kpse_open_file(name_opl, kpse_opl_format);
00247             rewritebin(file_ofm, name_ofm);
00248             init_tables();
00249             yyin = file_opl;
00250             (void)yyparse();
00251             output_ofm_file();
00252             (void)fclose(file_ofm);
00253             break;
00254         }
00255         case PROG_OVP2OVF: {
00256             file_ovp = kpse_open_file(name_ovp, kpse_ovp_format);
00257             rewritebin(file_ovf, name_ovf);
00258             rewritebin(file_ofm, name_ofm);
00259             init_tables();
00260             yyin = file_ovp;
00261             (void)yyparse();
00262             output_ofm_file();
00263             /*(void)fclose(file_ofm);*/
00264             output_ovf_file();
00265             (void)fclose(file_ovf);
00266             break;
00267         }
00268         default: {exit(1);}
00269     }
00270     exit(0);
00271 }
00272 
00273 #define BIG_BLOCK 0x20000
00274 #define LITTLE_BLOCK 0x1000
00275 
00276 void
00277 read_in_whole(unsigned char **contents_loc,
00278               unsigned *length_loc,
00279               FILE *file,
00280               string name)
00281 {
00282     unsigned no_read;
00283     unsigned no_total_read = 0;
00284     unsigned size = BIG_BLOCK;
00285     string where;
00286     string current_block;
00287 
00288     current_block = (char *) xmalloc(size);
00289     where = current_block;
00290 
00291     while (1) {
00292         no_read = fread(where, 1, LITTLE_BLOCK, file);
00293         no_total_read += no_read;
00294         if ((no_total_read+LITTLE_BLOCK) > size) {
00295             size *= 2;
00296             current_block = (char *) xrealloc(current_block, size);
00297         }
00298         where = current_block + no_total_read;
00299         if (ferror(file)) {
00300             fatal_error_s("Error while reading file %s", name);
00301         } else if (feof(file)) {
00302             break;
00303         }
00304     }
00305 
00306     *contents_loc = (unsigned char *) current_block;
00307     *length_loc = no_total_read;
00308 }
00309 
00310 void
00311 init_tables(void)
00312 {
00313     font_table_init(); /* subsidiary fonts in virtual fonts */
00314     init_header();
00315     init_planes();
00316     init_measures();
00317 }
00318 
00319 void
00320 output_text_file(FILE *dest)
00321 {
00322 }
00323