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 1107

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 1107 lampret
int desc = 0;
11 87 lampret
 
12
#define MAIN1_FILE "tmp/main1.html"
13
#define MAIN2_FILE "tmp/main2.html"
14
#define HF_FILE "tmp/hf.html"
15
#define ISAHTMLSRC_FILE "tmp/isa.html"
16
 
17
/* Which tables go into header? */
18
#define HSTART 1
19
#define HEND 2
20
 
21
/* Which tables go into footer? */
22
#define FSTART 3
23
#define FEND 3
24
 
25
void do_main1()
26
{
27
        FILE *f;
28
 
29
        f = fopen(MAIN1_FILE, "a");
30
        if (!f) {
31
                perror("do_main1()/fopen:");
32
                exit(1);
33
        }
34
 
35
        fprintf(f, "@page ISA%d\n", section);
36
        fprintf(f, "\t{size:8.5in 11.0in;\n");
37
        fprintf(f, "\tmargin:1.0in 1.25in 1.0in 1.25in;\n");
38
        fprintf(f, "\tmso-header-margin:.5in;\n");
39
        fprintf(f, "\tmso-footer-margin:.5in;\n");
40
        fprintf(f, "\tmso-header:url(\"./hf.html\") ISA%dh;\n", section);
41
        fprintf(f, "\tmso-footer:url(\"./hf.html\") ISA%df;\n", section);
42
        fprintf(f, "\tmso-paper-source:0;}\n");
43
        fprintf(f, "div.ISA%d\n", section);
44
        fprintf(f, "\t{page:ISA%d;}\n", section);
45
        fclose(f);
46
}
47
 
48
void do_main2start()
49
{
50
        FILE *f;
51
 
52
        f = fopen(MAIN2_FILE, "a");
53
        if (!f) {
54
                perror("do_main2start()/fopen:");
55
                exit(1);
56
        }
57
 
58
        did_main2start = 1;
59 89 lampret
        fprintf(f, "<div class=ISA%d style='text-align:left'><br><br>\n", section);
60 87 lampret
        fclose(f);
61
}
62
 
63
void do_main2end()
64
{
65
        FILE *f;
66
 
67
        f = fopen(MAIN2_FILE, "a");
68
        if (!f) {
69
                perror("do_main2end()/fopen:");
70
                exit(1);
71
        }
72
 
73
        if (did_main2start) {
74
                fprintf(f, "</div>\n");
75
                fprintf(f, "<span><br clear=all style='page-break-before:always;mso-break-type:section-break'>\n");
76
                fprintf(f, "</span>\n");
77
                did_main2start = 0;
78
        }
79
        fclose(f);
80
}
81
 
82
void do_main2(char *line)
83
{
84
        FILE *f;
85 1107 lampret
        char *bqp1, *bqp2;
86
        char tmpbuf[4100];
87
        char bq_str[50] = "<blockquote>";
88
        char justify_str[100] = " style='text-align:justify'";
89 87 lampret
 
90
        f = fopen(MAIN2_FILE, "a");
91
        if (!f) {
92
                perror("do_main2()/fopen:");
93
                exit(1);
94
        }
95
 
96 1107 lampret
        if (strstr(line, "Description:"))
97
                desc = 1;
98
 
99
        if (desc && (bqp1 = strstr(line, bq_str))) {
100
                strcpy(tmpbuf, line);
101
                bqp2 = strstr(tmpbuf, bq_str);
102
                strcpy(bqp2 + strlen(bq_str) - 1, justify_str);
103
                strcpy(bqp2 + strlen(bq_str) + strlen(justify_str) - 1, bqp1 + strlen(bq_str) - 1);
104
                strcpy(line, tmpbuf);
105
                desc = 0;
106
        }
107
 
108 87 lampret
        fprintf(f, "%s\n", line);
109
        fclose(f);
110
}
111
 
112
void create_main2()
113
{
114
        FILE *f;
115
 
116
        f = fopen(MAIN2_FILE, "w");
117
        if (!f) {
118
                perror("create_main2()/fopen:");
119
                exit(1);
120
        }
121
 
122
        fprintf(f, "-->\n");
123
        fprintf(f, "</style>\n");
124
        fprintf(f, "</head>\n");
125
        fprintf(f, "<body lang=EN-US style='tab-interval:.5in'>\n");
126
        fclose(f);
127
}
128
 
129
void finish_main2()
130
{
131
        FILE *f;
132
 
133
        f = fopen(MAIN2_FILE, "a");
134
        if (!f) {
135
                perror("finish_main2()/fopen:");
136
                exit(1);
137
        }
138
 
139
        fprintf(f, "</body>\n");
140
        fprintf(f, "</html>\n");
141
        fclose(f);
142
}
143
 
144
void create_hf()
145
{
146
        FILE *f;
147
 
148
        f = fopen(HF_FILE, "w");
149
        if (!f) {
150
                perror("create_hf()/fopen:");
151
                exit(1);
152
        }
153
 
154
        fprintf(f, "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"\n");
155
        fprintf(f, "xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n");
156
        fprintf(f, "xmlns:w=\"urn:schemas-microsoft-com:office:word\"\n");
157
        fprintf(f, "xmlns=\"http://www.w3.org/TR/REC-html40\">\n\n");
158
 
159
        fprintf(f, "<head>\n");
160
        fprintf(f, "<meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n");
161
        fprintf(f, "<link id=Main-File rel=Main-File href=\"or1k_isa.html\">\n");
162
        fprintf(f, "</head>\n\n");
163
 
164
        fprintf(f, "<body lang=EN-US>\n\n");
165
        fclose(f);
166
}
167
 
168
void finish_hf()
169
{
170
        FILE *f;
171
 
172
        f = fopen(HF_FILE, "a");
173
        if (!f) {
174
                perror("finish_hf()/fopen:");
175
                exit(1);
176
        }
177
 
178
        fprintf(f, "</body>\n");
179
        fprintf(f, "</html>\n");
180
        fclose(f);
181
}
182
 
183
void do_hstart()
184
{
185
        FILE *f;
186
 
187
        f = fopen(HF_FILE, "a");
188
        if (!f) {
189
                perror("do_hstart()/fopen:");
190
                exit(1);
191
        }
192
 
193
        fprintf(f, "<div style='mso-element:header' id=ISA%dh><p class=MsoHeader>\n", section);
194 95 lampret
        fprintf(f, "OpenCores<span style='mso-tab-count:1'>      </span>\n");
195 1107 lampret
        fprintf(f, "OpenRISC 1000 Architecture Manual<span style='mso-tab-count:1'>   </span>\n");
196 95 lampret
        fprintf(f, "<!--[if supportFields]><span style='mso-element:field-begin'>\n");
197
        fprintf(f, "</span> TIME \\@ &quot;MMMM d, yyyy&quot; <span style='mso-element:field-separator'>\n");
198 155 simons
        fprintf(f, "</span><![endif]-->July 2, 2001<!--[if supportFields]><span\n");
199 95 lampret
        fprintf(f, "style='mso-element:field-end'></span><![endif]--><br><br>\n");
200
 
201 87 lampret
        fclose(f);
202
}
203
 
204 95 lampret
void do_bottomline()
205
{
206
        FILE *f;
207
 
208
        f = fopen(HF_FILE, "a");
209
        if (!f) {
210
                perror("do_bottomline()/fopen:");
211
                exit(1);
212
        }
213
 
214
        fprintf(f, "<br><a href=\"http://www.opencores.org/\">www.opencores.org</a><span\n");
215
        fprintf(f, "style='mso-tab-count:\n");
216 1107 lampret
        fprintf(f, "1'>     </span>Rev 1.0 <span\n");
217
        fprintf(f, "style='mso-tab-count:1'>   </span><!--[if supportFields]><span\n");
218 95 lampret
        fprintf(f, "class=MsoPageNumber><span style='mso-element:field-begin'></span><span\n");
219
        fprintf(f, "style=\"mso-spacerun: yes\"> </span>PAGE <span \n");
220
        fprintf(f, "style='mso-element:field-separator'></span></span><![endif]--><span\n");
221
        fprintf(f, "class=MsoPageNumber>1</span><!--[if supportFields]><span class=MsoPageNumber><span\n");
222
        fprintf(f, "style='mso-element:field-end'></span></span><![endif]--><span\n");
223
        fprintf(f, "class=MsoPageNumber> of </span><!--[if supportFields]><span\n");
224
        fprintf(f, "class=MsoPageNumber><span style='mso-element:field-begin'></span><span\n");
225
        fprintf(f, "style=\"mso-spacerun: yes\"> </span>NUMPAGES <span\n");
226
        fprintf(f, "style='mso-element:field-separator'></span></span><![endif]--><span\n");
227
        fprintf(f, "class=MsoPageNumber>2</span><!--[if supportFields]><span class=MsoPageNumber><span\n");
228
        fprintf(f, "style='mso-element:field-end'></span></span><![endif]-->\n");
229
 
230
        fclose(f);
231
}
232
 
233 87 lampret
void do_fstart()
234
{
235
        FILE *f;
236
 
237
        f = fopen(HF_FILE, "a");
238
        if (!f) {
239
                perror("do_fstart()/fopen:");
240
                exit(1);
241
        }
242
 
243
        fprintf(f, "<div style='mso-element:footer' id=ISA%df><p class=MsoFooter>\n", section);
244 95 lampret
 
245 87 lampret
        fclose(f);
246
}
247
 
248
void do_hfend()
249
{
250
        FILE *f;
251
 
252
        f = fopen(HF_FILE, "a");
253
        if (!f) {
254
                perror("do_hfend()/fopen:");
255
                exit(1);
256
        }
257
 
258
        fprintf(f, "</p></div>\n");
259
        fclose(f);
260
}
261
 
262 1107 lampret
void do_hf(char * line, int type)
263 87 lampret
{
264
        FILE *f;
265 1107 lampret
        char *tbp1, *tbp2;
266
        char tmpbuf[4100];
267
        char tb_str[50] = "<table";
268
        char ins_str[100] = " width=100%";
269 87 lampret
 
270
        f = fopen(HF_FILE, "a");
271
        if (!f) {
272
                perror("do_hf()/fopen:");
273
                exit(1);
274
        }
275
 
276 1107 lampret
        if ((table < 3) && (tbp1 = strstr(line, tb_str))) {
277
                strcpy(tmpbuf, line);
278
                tbp2 = strstr(tmpbuf, tb_str);
279
                strcpy(tbp2 + strlen(tb_str), ins_str);
280
                strcpy(tbp2 + strlen(tb_str) + strlen(ins_str), tbp1 + strlen(tb_str));
281
                strcpy(line, tmpbuf);
282
        }
283
 
284 87 lampret
        fprintf(f, "%s\n", line);
285
        fclose(f);
286
}
287
 
288
void processline(char *line)
289
{
290
        if (strstr(line, "<hr")) {
291
                do_main2end();
292
                section++;
293
                table = 0;
294
                tableend = 0;
295
                do_main1();
296
                do_main2start();
297
                bq = 0;
298
                bqend = 0;
299
        }
300
 
301
        if (strstr(line, "<table")) {
302
                table++;
303
                if (table == HSTART) {
304
                        do_hstart();
305
                }
306
                if (table == FSTART) {
307
                        do_fstart();
308
                }
309
        }
310
 
311
        if (strstr(line, "</table>")) {
312
                tableend++;
313
                if (tableend == HEND) {
314 1107 lampret
                        do_hf(line, table);
315 87 lampret
                        do_hfend();
316
                }
317
                if (tableend == FEND) {
318 1107 lampret
                        do_hf(line, table);
319 95 lampret
                        do_bottomline();
320 87 lampret
                        do_hfend();
321
                }
322
        } else
323
        if ((tableend == HEND) && (table == HEND)) {
324
                char *bqp;
325
                char *bqendp;
326
 
327
                bqp = strstr(line, "<blockquote>");
328
                bqendp = strstr(line, "</blockquote>");
329
 
330
                if (bqp)
331
                        bq++;
332
                if (bqendp)
333
                        bqend++;
334
 
335
                if ((bq > 2) && bqp) {
336
                        *bqp = '\0';
337
                        do_main2(line);
338
                        do_main2("<left>");
339
                        *bqp = '<';
340
                        do_main2(bqp);
341
                } else
342
                if ((bqend > 2) && bqendp) {
343
                        *bqendp = '\0';
344
                        do_main2(line);
345
                        do_main2("</left>");
346
                        *bqendp = '<';
347
                        do_main2(bqendp);
348
                }
349
                else
350
                        do_main2(line);
351
        }
352
 
353
        if (((table == HSTART) || (table == HEND)) && (tableend < HEND))
354 1107 lampret
                do_hf(line, table);
355 87 lampret
 
356
        if (table == FSTART)
357 1107 lampret
                do_hf(line, table);
358
 
359 87 lampret
}
360
 
361
void readsrc(char *filename)
362
{
363
        FILE *f;
364
        char line[4000];
365
 
366
        f = fopen(filename, "r");
367
        if (!f) {
368
                perror("readsrc()/fopen:");
369
                exit(1);
370
        }
371
 
372
        create_main2();
373
        create_hf();
374
 
375
        while (!feof(f)) {
376
                fscanf(f, "%s", line);
377
                processline(line);
378
        /*      printf("%s\n", line); */
379
        }
380
        fclose(f);
381
 
382
        finish_main2();
383
        finish_hf();
384
}
385
 
386 155 simons
int main()
387 87 lampret
{
388
        readsrc(ISAHTMLSRC_FILE);
389 155 simons
        return 0;
390 87 lampret
}

powered by: WebSVN 2.1.0

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