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 1778

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

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

powered by: WebSVN 2.1.0

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