URL
https://opencores.org/ocsvn/or1k/or1k/trunk
Subversion Repositories or1k
[/] [or1k/] [trunk/] [gen_or1k_isa/] [sources/] [chop_html.c] - Rev 87
Go to most recent revision | Compare with Previous | Blame | View Log
#include <stdio.h> #include <string.h> int section = 0; int table = 0; int tableend = 0; int bq = 0; int bqend = 0; int did_main2start; #define MAIN1_FILE "tmp/main1.html" #define MAIN2_FILE "tmp/main2.html" #define HF_FILE "tmp/hf.html" #define ISAHTMLSRC_FILE "tmp/isa.html" /* Which tables go into header? */ #define HSTART 1 #define HEND 2 /* Which tables go into footer? */ #define FSTART 3 #define FEND 3 void do_main1() { FILE *f; f = fopen(MAIN1_FILE, "a"); if (!f) { perror("do_main1()/fopen:"); exit(1); } fprintf(f, "@page ISA%d\n", section); fprintf(f, "\t{size:8.5in 11.0in;\n"); fprintf(f, "\tmargin:1.0in 1.25in 1.0in 1.25in;\n"); fprintf(f, "\tmso-header-margin:.5in;\n"); fprintf(f, "\tmso-footer-margin:.5in;\n"); fprintf(f, "\tmso-header:url(\"./hf.html\") ISA%dh;\n", section); fprintf(f, "\tmso-footer:url(\"./hf.html\") ISA%df;\n", section); fprintf(f, "\tmso-paper-source:0;}\n"); fprintf(f, "div.ISA%d\n", section); fprintf(f, "\t{page:ISA%d;}\n", section); fclose(f); } void do_main2start() { FILE *f; f = fopen(MAIN2_FILE, "a"); if (!f) { perror("do_main2start()/fopen:"); exit(1); } did_main2start = 1; fprintf(f, "<div class=ISA%d style='text-align:justify'><br><br>\n", section); fclose(f); } void do_main2end() { FILE *f; f = fopen(MAIN2_FILE, "a"); if (!f) { perror("do_main2end()/fopen:"); exit(1); } if (did_main2start) { fprintf(f, "</div>\n"); fprintf(f, "<span><br clear=all style='page-break-before:always;mso-break-type:section-break'>\n"); fprintf(f, "</span>\n"); did_main2start = 0; } fclose(f); } void do_main2(char *line) { FILE *f; f = fopen(MAIN2_FILE, "a"); if (!f) { perror("do_main2()/fopen:"); exit(1); } fprintf(f, "%s\n", line); fclose(f); } void create_main2() { FILE *f; f = fopen(MAIN2_FILE, "w"); if (!f) { perror("create_main2()/fopen:"); exit(1); } fprintf(f, "-->\n"); fprintf(f, "</style>\n"); fprintf(f, "</head>\n"); fprintf(f, "<body lang=EN-US style='tab-interval:.5in'>\n"); fclose(f); } void finish_main2() { FILE *f; f = fopen(MAIN2_FILE, "a"); if (!f) { perror("finish_main2()/fopen:"); exit(1); } fprintf(f, "</body>\n"); fprintf(f, "</html>\n"); fclose(f); } void create_hf() { FILE *f; f = fopen(HF_FILE, "w"); if (!f) { perror("create_hf()/fopen:"); exit(1); } fprintf(f, "<html xmlns:v=\"urn:schemas-microsoft-com:vml\"\n"); fprintf(f, "xmlns:o=\"urn:schemas-microsoft-com:office:office\"\n"); fprintf(f, "xmlns:w=\"urn:schemas-microsoft-com:office:word\"\n"); fprintf(f, "xmlns=\"http://www.w3.org/TR/REC-html40\">\n\n"); fprintf(f, "<head>\n"); fprintf(f, "<meta http-equiv=Content-Type content=\"text/html; charset=windows-1252\">\n"); fprintf(f, "<link id=Main-File rel=Main-File href=\"or1k_isa.html\">\n"); fprintf(f, "</head>\n\n"); fprintf(f, "<body lang=EN-US>\n\n"); fclose(f); } void finish_hf() { FILE *f; f = fopen(HF_FILE, "a"); if (!f) { perror("finish_hf()/fopen:"); exit(1); } fprintf(f, "</body>\n"); fprintf(f, "</html>\n"); fclose(f); } void do_hstart() { FILE *f; f = fopen(HF_FILE, "a"); if (!f) { perror("do_hstart()/fopen:"); exit(1); } fprintf(f, "<div style='mso-element:header' id=ISA%dh><p class=MsoHeader>\n", section); fclose(f); } void do_fstart() { FILE *f; f = fopen(HF_FILE, "a"); if (!f) { perror("do_fstart()/fopen:"); exit(1); } fprintf(f, "<div style='mso-element:footer' id=ISA%df><p class=MsoFooter>\n", section); fclose(f); } void do_hfend() { FILE *f; f = fopen(HF_FILE, "a"); if (!f) { perror("do_hfend()/fopen:"); exit(1); } fprintf(f, "</p></div>\n"); fclose(f); } void do_hf(char * line) { FILE *f; f = fopen(HF_FILE, "a"); if (!f) { perror("do_hf()/fopen:"); exit(1); } fprintf(f, "%s\n", line); fclose(f); } void processline(char *line) { if (strstr(line, "<hr")) { do_main2end(); section++; table = 0; tableend = 0; do_main1(); do_main2start(); bq = 0; bqend = 0; } if (strstr(line, "<table")) { table++; if (table == HSTART) { do_hstart(); } if (table == FSTART) { do_fstart(); } } if (strstr(line, "</table>")) { tableend++; if (tableend == HEND) { do_hf(line); do_hfend(); } if (tableend == FEND) { do_hf(line); do_hfend(); } } else if ((tableend == HEND) && (table == HEND)) { char *bqp; char *bqendp; bqp = strstr(line, "<blockquote>"); bqendp = strstr(line, "</blockquote>"); if (bqp) bq++; if (bqendp) bqend++; if ((bq > 2) && bqp) { *bqp = '\0'; do_main2(line); do_main2("<left>"); *bqp = '<'; do_main2(bqp); } else if ((bqend > 2) && bqendp) { *bqendp = '\0'; do_main2(line); do_main2("</left>"); *bqendp = '<'; do_main2(bqendp); } else do_main2(line); } if (((table == HSTART) || (table == HEND)) && (tableend < HEND)) do_hf(line); if (table == FSTART) do_hf(line); } void readsrc(char *filename) { FILE *f; char line[4000]; f = fopen(filename, "r"); if (!f) { perror("readsrc()/fopen:"); exit(1); } create_main2(); create_hf(); while (!feof(f)) { fscanf(f, "%s", line); processline(line); /* printf("%s\n", line); */ } fclose(f); finish_main2(); finish_hf(); } void main() { readsrc(ISAHTMLSRC_FILE); }
Go to most recent revision | Compare with Previous | Blame | View Log