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

Subversion Repositories or1k

[/] [or1k/] [trunk/] [gen_or1k_isa/] [sources/] [chop_html.c] - Rev 1772

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

/*
 * $Log: not supported by cvs2svn $
 */
#include <stdio.h>
#include <string.h>
 
int section = 0;
int table = 0;
int tableend = 0;
int bq = 0;
int bqend = 0;
int did_main2start;
int desc = 0;
 
#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:left'><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;
	char *bqp1, *bqp2;
	char tmpbuf[4100];
	char bq_str[50] = "<blockquote>";
	char justify_str[100] = " style='text-align:justify'";
 
	f = fopen(MAIN2_FILE, "a");
	if (!f) {
		perror("do_main2()/fopen:");
		exit(1);
	}
 
	if (strstr(line, "Description:"))
		desc = 1;
 
	if (desc && (bqp1 = strstr(line, bq_str))) {
		strcpy(tmpbuf, line);
		bqp2 = strstr(tmpbuf, bq_str);
		strcpy(bqp2 + strlen(bq_str) - 1, justify_str);
		strcpy(bqp2 + strlen(bq_str) + strlen(justify_str) - 1, bqp1 + strlen(bq_str) - 1);
		strcpy(line, tmpbuf);
		desc = 0;
	}
 
	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);
	fprintf(f, "OpenCores<span style='mso-tab-count:1'>      </span>\n");
	fprintf(f, "OpenRISC 1000 Architecture Manual<span style='mso-tab-count:1'>   </span>\n");
	fprintf(f, "<!--[if supportFields]><span style='mso-element:field-begin'>\n");
	fprintf(f, "</span> TIME \\@ &quot;MMMM d, yyyy&quot; <span style='mso-element:field-separator'>\n");
	fprintf(f, "</span><![endif]-->July 2, 2001<!--[if supportFields]><span\n");
	fprintf(f, "style='mso-element:field-end'></span><![endif]--><br><br>\n");
 
	fclose(f);
}
 
void do_bottomline()
{
	FILE *f;
 
	f = fopen(HF_FILE, "a");
	if (!f) {
		perror("do_bottomline()/fopen:");
		exit(1);
	}
 
	fprintf(f, "<br><a href=\"http://www.opencores.org/\">www.opencores.org</a><span\n");
	fprintf(f, "style='mso-tab-count:\n");
	fprintf(f, "1'>     </span>Rev 1.0 <span\n");
	fprintf(f, "style='mso-tab-count:1'>   </span><!--[if supportFields]><span\n");
	fprintf(f, "class=MsoPageNumber><span style='mso-element:field-begin'></span><span\n");
	fprintf(f, "style=\"mso-spacerun: yes\"> </span>PAGE <span \n");
	fprintf(f, "style='mso-element:field-separator'></span></span><![endif]--><span\n");
	fprintf(f, "class=MsoPageNumber>1</span><!--[if supportFields]><span class=MsoPageNumber><span\n");
	fprintf(f, "style='mso-element:field-end'></span></span><![endif]--><span\n");
	fprintf(f, "class=MsoPageNumber> of </span><!--[if supportFields]><span\n");
	fprintf(f, "class=MsoPageNumber><span style='mso-element:field-begin'></span><span\n");
	fprintf(f, "style=\"mso-spacerun: yes\"> </span>NUMPAGES <span\n");
	fprintf(f, "style='mso-element:field-separator'></span></span><![endif]--><span\n");
	fprintf(f, "class=MsoPageNumber>2</span><!--[if supportFields]><span class=MsoPageNumber><span\n");
	fprintf(f, "style='mso-element:field-end'></span></span><![endif]-->\n");
 
	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, int type)
{
	FILE *f;
	char *tbp1, *tbp2;
	char tmpbuf[4100];
	char tb_str[50] = "<table";
	char ins_str[100] = " width=100%";
 
	f = fopen(HF_FILE, "a");
	if (!f) {
		perror("do_hf()/fopen:");
		exit(1);
	}
 
	if ((table < 3) && (tbp1 = strstr(line, tb_str))) {
		strcpy(tmpbuf, line);
		tbp2 = strstr(tmpbuf, tb_str);
		strcpy(tbp2 + strlen(tb_str), ins_str);
		strcpy(tbp2 + strlen(tb_str) + strlen(ins_str), tbp1 + strlen(tb_str));
		strcpy(line, tmpbuf);
	}
 
	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, table);
			do_hfend();
		}
		if (tableend == FEND) {
			do_hf(line, table);
			do_bottomline();
			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, table);
 
	if (table == FSTART)
		do_hf(line, table);
 
}
 
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();
}
 
int main()
{
	readsrc(ISAHTMLSRC_FILE);
	return 0;
}
 

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

powered by: WebSVN 2.1.0

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