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 89

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 89 lampret
/*      fprintf(f, "<div class=ISA%d style='text-align:justify'><br><br>\n", section);*/
59
        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
 
86
        f = fopen(MAIN2_FILE, "a");
87
        if (!f) {
88
                perror("do_main2()/fopen:");
89
                exit(1);
90
        }
91
 
92
        fprintf(f, "%s\n", line);
93
        fclose(f);
94
}
95
 
96
void create_main2()
97
{
98
        FILE *f;
99
 
100
        f = fopen(MAIN2_FILE, "w");
101
        if (!f) {
102
                perror("create_main2()/fopen:");
103
                exit(1);
104
        }
105
 
106
        fprintf(f, "-->\n");
107
        fprintf(f, "</style>\n");
108
        fprintf(f, "</head>\n");
109
        fprintf(f, "<body lang=EN-US style='tab-interval:.5in'>\n");
110
        fclose(f);
111
}
112
 
113
void finish_main2()
114
{
115
        FILE *f;
116
 
117
        f = fopen(MAIN2_FILE, "a");
118
        if (!f) {
119
                perror("finish_main2()/fopen:");
120
                exit(1);
121
        }
122
 
123
        fprintf(f, "</body>\n");
124
        fprintf(f, "</html>\n");
125
        fclose(f);
126
}
127
 
128
void create_hf()
129
{
130
        FILE *f;
131
 
132
        f = fopen(HF_FILE, "w");
133
        if (!f) {
134
                perror("create_hf()/fopen:");
135
                exit(1);
136
        }
137
 
138
        fprintf(f, "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"\n");
139
        fprintf(f, "xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n");
140
        fprintf(f, "xmlns:w=\"urn:schemas-microsoft-com:office:word\"\n");
141
        fprintf(f, "xmlns=\"http://www.w3.org/TR/REC-html40\">\n\n");
142
 
143
        fprintf(f, "<head>\n");
144
        fprintf(f, "<meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n");
145
        fprintf(f, "<link id=Main-File rel=Main-File href=\"or1k_isa.html\">\n");
146
        fprintf(f, "</head>\n\n");
147
 
148
        fprintf(f, "<body lang=EN-US>\n\n");
149
        fclose(f);
150
}
151
 
152
void finish_hf()
153
{
154
        FILE *f;
155
 
156
        f = fopen(HF_FILE, "a");
157
        if (!f) {
158
                perror("finish_hf()/fopen:");
159
                exit(1);
160
        }
161
 
162
        fprintf(f, "</body>\n");
163
        fprintf(f, "</html>\n");
164
        fclose(f);
165
}
166
 
167
void do_hstart()
168
{
169
        FILE *f;
170
 
171
        f = fopen(HF_FILE, "a");
172
        if (!f) {
173
                perror("do_hstart()/fopen:");
174
                exit(1);
175
        }
176
 
177
        fprintf(f, "<div style='mso-element:header' id=ISA%dh><p class=MsoHeader>\n", section);
178
        fclose(f);
179
}
180
 
181
void do_fstart()
182
{
183
        FILE *f;
184
 
185
        f = fopen(HF_FILE, "a");
186
        if (!f) {
187
                perror("do_fstart()/fopen:");
188
                exit(1);
189
        }
190
 
191
        fprintf(f, "<div style='mso-element:footer' id=ISA%df><p class=MsoFooter>\n", section);
192
        fclose(f);
193
}
194
 
195
void do_hfend()
196
{
197
        FILE *f;
198
 
199
        f = fopen(HF_FILE, "a");
200
        if (!f) {
201
                perror("do_hfend()/fopen:");
202
                exit(1);
203
        }
204
 
205
        fprintf(f, "</p></div>\n");
206
        fclose(f);
207
}
208
 
209
void do_hf(char * line)
210
{
211
        FILE *f;
212
 
213
        f = fopen(HF_FILE, "a");
214
        if (!f) {
215
                perror("do_hf()/fopen:");
216
                exit(1);
217
        }
218
 
219
        fprintf(f, "%s\n", line);
220
        fclose(f);
221
}
222
 
223
void processline(char *line)
224
{
225
        if (strstr(line, "<hr")) {
226
                do_main2end();
227
                section++;
228
                table = 0;
229
                tableend = 0;
230
                do_main1();
231
                do_main2start();
232
                bq = 0;
233
                bqend = 0;
234
        }
235
 
236
        if (strstr(line, "<table")) {
237
                table++;
238
                if (table == HSTART) {
239
                        do_hstart();
240
                }
241
                if (table == FSTART) {
242
                        do_fstart();
243
                }
244
        }
245
 
246
        if (strstr(line, "</table>")) {
247
                tableend++;
248
                if (tableend == HEND) {
249
                        do_hf(line);
250
                        do_hfend();
251
                }
252
                if (tableend == FEND) {
253
                        do_hf(line);
254
                        do_hfend();
255
                }
256
        } else
257
        if ((tableend == HEND) && (table == HEND)) {
258
                char *bqp;
259
                char *bqendp;
260
 
261
                bqp = strstr(line, "<blockquote>");
262
                bqendp = strstr(line, "</blockquote>");
263
 
264
                if (bqp)
265
                        bq++;
266
                if (bqendp)
267
                        bqend++;
268
 
269
                if ((bq > 2) && bqp) {
270
                        *bqp = '\0';
271
                        do_main2(line);
272
                        do_main2("<left>");
273
                        *bqp = '<';
274
                        do_main2(bqp);
275
                } else
276
                if ((bqend > 2) && bqendp) {
277
                        *bqendp = '\0';
278
                        do_main2(line);
279
                        do_main2("</left>");
280
                        *bqendp = '<';
281
                        do_main2(bqendp);
282
                }
283
                else
284
                        do_main2(line);
285
        }
286
 
287
        if (((table == HSTART) || (table == HEND)) && (tableend < HEND))
288
                do_hf(line);
289
 
290
        if (table == FSTART)
291
                do_hf(line);
292
}
293
 
294
void readsrc(char *filename)
295
{
296
        FILE *f;
297
        char line[4000];
298
 
299
        f = fopen(filename, "r");
300
        if (!f) {
301
                perror("readsrc()/fopen:");
302
                exit(1);
303
        }
304
 
305
        create_main2();
306
        create_hf();
307
 
308
        while (!feof(f)) {
309
                fscanf(f, "%s", line);
310
                processline(line);
311
        /*      printf("%s\n", line); */
312
        }
313
        fclose(f);
314
 
315
        finish_main2();
316
        finish_hf();
317
}
318
 
319
void main()
320
{
321
        readsrc(ISAHTMLSRC_FILE);
322
}

powered by: WebSVN 2.1.0

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