OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gen_or1k_isa/] [sources/] [chop_html.c] - Blame information for rev 87

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 87 lampret
#include <stdio.h>
2
#include <string.h>
3
 
4
int section = 0;
5
int table = 0;
6
int tableend = 0;
7
int bq = 0;
8
int bqend = 0;
9
int did_main2start;
10
 
11
#define MAIN1_FILE "tmp/main1.html"
12
#define MAIN2_FILE "tmp/main2.html"
13
#define HF_FILE "tmp/hf.html"
14
#define ISAHTMLSRC_FILE "tmp/isa.html"
15
 
16
/* Which tables go into header? */
17
#define HSTART 1
18
#define HEND 2
19
 
20
/* Which tables go into footer? */
21
#define FSTART 3
22
#define FEND 3
23
 
24
void do_main1()
25
{
26
        FILE *f;
27
 
28
        f = fopen(MAIN1_FILE, "a");
29
        if (!f) {
30
                perror("do_main1()/fopen:");
31
                exit(1);
32
        }
33
 
34
        fprintf(f, "@page ISA%d\n", section);
35
        fprintf(f, "\t{size:8.5in 11.0in;\n");
36
        fprintf(f, "\tmargin:1.0in 1.25in 1.0in 1.25in;\n");
37
        fprintf(f, "\tmso-header-margin:.5in;\n");
38
        fprintf(f, "\tmso-footer-margin:.5in;\n");
39
        fprintf(f, "\tmso-header:url(\"./hf.html\") ISA%dh;\n", section);
40
        fprintf(f, "\tmso-footer:url(\"./hf.html\") ISA%df;\n", section);
41
        fprintf(f, "\tmso-paper-source:0;}\n");
42
        fprintf(f, "div.ISA%d\n", section);
43
        fprintf(f, "\t{page:ISA%d;}\n", section);
44
        fclose(f);
45
}
46
 
47
void do_main2start()
48
{
49
        FILE *f;
50
 
51
        f = fopen(MAIN2_FILE, "a");
52
        if (!f) {
53
                perror("do_main2start()/fopen:");
54
                exit(1);
55
        }
56
 
57
        did_main2start = 1;
58
        fprintf(f, "<div class=ISA%d style='text-align:justify'><br><br>\n", section);
59
        fclose(f);
60
}
61
 
62
void do_main2end()
63
{
64
        FILE *f;
65
 
66
        f = fopen(MAIN2_FILE, "a");
67
        if (!f) {
68
                perror("do_main2end()/fopen:");
69
                exit(1);
70
        }
71
 
72
        if (did_main2start) {
73
                fprintf(f, "</div>\n");
74
                fprintf(f, "<span><br clear=all style='page-break-before:always;mso-break-type:section-break'>\n");
75
                fprintf(f, "</span>\n");
76
                did_main2start = 0;
77
        }
78
        fclose(f);
79
}
80
 
81
void do_main2(char *line)
82
{
83
        FILE *f;
84
 
85
        f = fopen(MAIN2_FILE, "a");
86
        if (!f) {
87
                perror("do_main2()/fopen:");
88
                exit(1);
89
        }
90
 
91
        fprintf(f, "%s\n", line);
92
        fclose(f);
93
}
94
 
95
void create_main2()
96
{
97
        FILE *f;
98
 
99
        f = fopen(MAIN2_FILE, "w");
100
        if (!f) {
101
                perror("create_main2()/fopen:");
102
                exit(1);
103
        }
104
 
105
        fprintf(f, "-->\n");
106
        fprintf(f, "</style>\n");
107
        fprintf(f, "</head>\n");
108
        fprintf(f, "<body lang=EN-US style='tab-interval:.5in'>\n");
109
        fclose(f);
110
}
111
 
112
void finish_main2()
113
{
114
        FILE *f;
115
 
116
        f = fopen(MAIN2_FILE, "a");
117
        if (!f) {
118
                perror("finish_main2()/fopen:");
119
                exit(1);
120
        }
121
 
122
        fprintf(f, "</body>\n");
123
        fprintf(f, "</html>\n");
124
        fclose(f);
125
}
126
 
127
void create_hf()
128
{
129
        FILE *f;
130
 
131
        f = fopen(HF_FILE, "w");
132
        if (!f) {
133
                perror("create_hf()/fopen:");
134
                exit(1);
135
        }
136
 
137
        fprintf(f, "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"\n");
138
        fprintf(f, "xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n");
139
        fprintf(f, "xmlns:w=\"urn:schemas-microsoft-com:office:word\"\n");
140
        fprintf(f, "xmlns=\"http://www.w3.org/TR/REC-html40\">\n\n");
141
 
142
        fprintf(f, "<head>\n");
143
        fprintf(f, "<meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n");
144
        fprintf(f, "<link id=Main-File rel=Main-File href=\"or1k_isa.html\">\n");
145
        fprintf(f, "</head>\n\n");
146
 
147
        fprintf(f, "<body lang=EN-US>\n\n");
148
        fclose(f);
149
}
150
 
151
void finish_hf()
152
{
153
        FILE *f;
154
 
155
        f = fopen(HF_FILE, "a");
156
        if (!f) {
157
                perror("finish_hf()/fopen:");
158
                exit(1);
159
        }
160
 
161
        fprintf(f, "</body>\n");
162
        fprintf(f, "</html>\n");
163
        fclose(f);
164
}
165
 
166
void do_hstart()
167
{
168
        FILE *f;
169
 
170
        f = fopen(HF_FILE, "a");
171
        if (!f) {
172
                perror("do_hstart()/fopen:");
173
                exit(1);
174
        }
175
 
176
        fprintf(f, "<div style='mso-element:header' id=ISA%dh><p class=MsoHeader>\n", section);
177
        fclose(f);
178
}
179
 
180
void do_fstart()
181
{
182
        FILE *f;
183
 
184
        f = fopen(HF_FILE, "a");
185
        if (!f) {
186
                perror("do_fstart()/fopen:");
187
                exit(1);
188
        }
189
 
190
        fprintf(f, "<div style='mso-element:footer' id=ISA%df><p class=MsoFooter>\n", section);
191
        fclose(f);
192
}
193
 
194
void do_hfend()
195
{
196
        FILE *f;
197
 
198
        f = fopen(HF_FILE, "a");
199
        if (!f) {
200
                perror("do_hfend()/fopen:");
201
                exit(1);
202
        }
203
 
204
        fprintf(f, "</p></div>\n");
205
        fclose(f);
206
}
207
 
208
void do_hf(char * line)
209
{
210
        FILE *f;
211
 
212
        f = fopen(HF_FILE, "a");
213
        if (!f) {
214
                perror("do_hf()/fopen:");
215
                exit(1);
216
        }
217
 
218
        fprintf(f, "%s\n", line);
219
        fclose(f);
220
}
221
 
222
void processline(char *line)
223
{
224
        if (strstr(line, "<hr")) {
225
                do_main2end();
226
                section++;
227
                table = 0;
228
                tableend = 0;
229
                do_main1();
230
                do_main2start();
231
                bq = 0;
232
                bqend = 0;
233
        }
234
 
235
        if (strstr(line, "<table")) {
236
                table++;
237
                if (table == HSTART) {
238
                        do_hstart();
239
                }
240
                if (table == FSTART) {
241
                        do_fstart();
242
                }
243
        }
244
 
245
        if (strstr(line, "</table>")) {
246
                tableend++;
247
                if (tableend == HEND) {
248
                        do_hf(line);
249
                        do_hfend();
250
                }
251
                if (tableend == FEND) {
252
                        do_hf(line);
253
                        do_hfend();
254
                }
255
        } else
256
        if ((tableend == HEND) && (table == HEND)) {
257
                char *bqp;
258
                char *bqendp;
259
 
260
                bqp = strstr(line, "<blockquote>");
261
                bqendp = strstr(line, "</blockquote>");
262
 
263
                if (bqp)
264
                        bq++;
265
                if (bqendp)
266
                        bqend++;
267
 
268
                if ((bq > 2) && bqp) {
269
                        *bqp = '\0';
270
                        do_main2(line);
271
                        do_main2("<left>");
272
                        *bqp = '<';
273
                        do_main2(bqp);
274
                } else
275
                if ((bqend > 2) && bqendp) {
276
                        *bqendp = '\0';
277
                        do_main2(line);
278
                        do_main2("</left>");
279
                        *bqendp = '<';
280
                        do_main2(bqendp);
281
                }
282
                else
283
                        do_main2(line);
284
        }
285
 
286
        if (((table == HSTART) || (table == HEND)) && (tableend < HEND))
287
                do_hf(line);
288
 
289
        if (table == FSTART)
290
                do_hf(line);
291
}
292
 
293
void readsrc(char *filename)
294
{
295
        FILE *f;
296
        char line[4000];
297
 
298
        f = fopen(filename, "r");
299
        if (!f) {
300
                perror("readsrc()/fopen:");
301
                exit(1);
302
        }
303
 
304
        create_main2();
305
        create_hf();
306
 
307
        while (!feof(f)) {
308
                fscanf(f, "%s", line);
309
                processline(line);
310
        /*      printf("%s\n", line); */
311
        }
312
        fclose(f);
313
 
314
        finish_main2();
315
        finish_hf();
316
}
317
 
318
void main()
319
{
320
        readsrc(ISAHTMLSRC_FILE);
321
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.