Debian Codegraph @

texk/web2c/otps/otp2ocp.c

raw
1 /* otp2ocp.c: Main program for transforming OTP files into OCP files.
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 Copyright (c) 2002 Behdad Esfahbod
8 Copyright (C) 2002, 2005, 2006 Roozbeh Pournader
9
10 Omega is free software; you can redistribute it and/or modify
11 it under the terms of the GNU General Public License as published by
12 the Free Software Foundation; either version 2 of the License, or
13 (at your option) any later version.
14
15 Omega is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with Omega; if not, write to the Free Software Foundation, Inc.,
22 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
23
24 */
25
26 #include <kpathsea/config.h>
27 #include <kpathsea/types.h>
28 #include <kpathsea/c-std.h>
29 #include <kpathsea/c-fopen.h>
30 #include <kpathsea/tex-file.h>
31 #include "routines.h"
32
33 extern FILE *yyin;
34 int
35 yywrap(void)
36 {
37 return 1;
38 }
39
40 static void
41 output(FILE *output_file, int i)
42 {
43 /* make sure output is in big-endian form */
44 char j;
45 int k;
46 k = i;
47 j = k >> 24;
48 fwrite (&j, 1, 1, output_file);
49 k = k & 0xffffff;
50 j = k >> 16;
51 fwrite (&j, 1, 1, output_file);
52 k = k & 0xffff;
53 j = k >> 8;
54 fwrite (&j, 1, 1, output_file);
55 j = k & 0xff;
56 fwrite (&j, 1, 1, output_file);
57 }
58
59 static void
60 otp_read(string input_name, string output_name)
61 {
62 int i, j, len, no_words;
63 int *table, *instrs;
64 FILE *input_file, *output_file;
65
66 input_file = xfopen (input_name, FOPEN_R_MODE);
67 store_state ("INITIAL");
68 yyin = input_file;
69 if (yyparse ())
70 exit (EXIT_FAILURE);
71 output_file = xfopen (output_name, FOPEN_WBIN_MODE);
72 room_for_tables = 0;
73 for (i = 0; i < no_tables; i++)
74 {
75 room_for_tables = room_for_tables + tables[i].length;
76 }
77 room_for_states = 0;
78 for (i = 0; i < no_states; i++)
79 {
80 room_for_states = room_for_states + states[i].length;
81 }
82 no_words = no_tables + room_for_tables + no_states + room_for_states + 7;
83 output (output_file, no_words);
84 output (output_file, input_bytes);
85 output (output_file, output_bytes);
86 output (output_file, no_tables);
87 output (output_file, room_for_tables);
88 output (output_file, no_states);
89 output (output_file, room_for_states);
90 for (i = 0; i < no_tables; i++)
91 {
92 len = tables[i].length;
93 output (output_file, len);
94 }
95 for (i = 0; i < no_tables; i++)
96 {
97 len = tables[i].length;
98 table = tables[i].table;
99 for (j = 0; j < len; j++)
100 {
101 output (output_file, table[j]);
102 }
103 }
104 for (i = 0; i < no_states; i++)
105 {
106 len = states[i].length;
107 output (output_file, len);
108 }
109 for (i = 0; i < no_states; i++)
110 {
111 len = states[i].length;
112 instrs = states[i].instrs;
113 for (j = 0; j < len; j++)
114 {
115 output (output_file, instrs[j]);
116 }
117 }
118 }
119
120 int
121 main(int argc, string *argv)
122 {
123 string input_name, full_input_name;
124 string output_name;
125
126 kpse_set_program_name (argv[0], "otp2ocp");
127 switch (argc)
128 {
129 case 1:
130 FATAL ("No command line arguments given");
131 case 2:
132 input_name = argv[1];
133 output_name = make_suffix (xbasename (input_name), "ocp");
134 break;
135 case 3:
136 input_name = argv[1];
137 output_name = argv[2];
138 break;
139 default:
140 FATAL ("Too many command line arguments");
141 }
142 full_input_name = kpse_find_file (input_name, kpse_otp_format, true);
143 if (!full_input_name)
144 {
145 FATAL1 ("File '%s' not found", input_name);
146 }
147
148 otp_read (full_input_name, output_name);
149
150 return EXIT_SUCCESS;
151 }