[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mgp-users 01272] mgp2html patch



Hi,

I didn't find a mail adress of those who maintain MagicPoint, so I send this patch to this list. This patch fixes some things in mgp2html:

- the HTML code correct contains a doc type header now
- all opening tags which *should* have a closing tag are closed now
- if the charset is given in the mgp file this is also put in a html meta tag.
- <, > and & are encoded in the corresponding html entity now

Please apply that patch to the upstram MagicPoint distribution.

Ciao
Bjoern
--- mgp2html.pl.in	1999-08-30 10:20:15.000000000 +0200
+++ mgp2html.pl.in	2003-07-09 08:56:47.232575760 +0200
@@ -59,6 +59,7 @@
 $filtermode = 0;
 $filtercmd = "";
 $filterinput = "";
+my @mainoutput;
 
 while ($_ = $ARGV[0], /^-/) {
 	shift;
@@ -77,12 +78,13 @@
 $mgpfontsize = $mgpdefaultfontsize;
 $| = 1;
 
-&prologue;
 while (<>) {
 	s/\n$//;
 
 	$_ = '' if (/^#/o);
-
+	s/&/&amp;/g;	# this first! :)
+	s/</&lt;/g;
+	s/>/&gt;/g;
 	if ($_ eq '' || $_ =~ /^[^%]/) {
 		$line++;
 		$cont = 0 if ($cont == 2);
@@ -106,9 +108,18 @@
 	&cmds($_);
 }
 &pageepilogue;
+&alignreset;
 &epilogue;
+
+&prologue;	# the only function writing directly to stdout, the
+		# rest unshifts into @mainoutput ...
+print for reverse (@mainoutput);
 exit 0;
 
+sub printit {	# we need to parse for charset, and put that into the html
+		# header, so print out most stuff in the end and store first
+	unshift @mainoutput, shift;
+}
 
 sub cmds {
 	local($_) = @_;
@@ -117,7 +128,6 @@
 	if (/^%page/i) {
 		&fontreset;
 		if ($page != -1) {
-			&alignreset;
 			&pageepilogue;
 		} else {
 			$page = 0;
@@ -152,20 +162,19 @@
 			if (!$doimage) {
 				# don't use images
 			} elsif (scalar(@dir) == 2 || scalar(@dir) == 3) {
-				print "<IMG SRC=\"$dir[1]\" ALT=\"$dir[1]\">\n";
+				printit "<img src=\"$dir[1]\" ALT=\"$dir[1]\">\n";
 			} elsif (scalar(@dir) == 4) {
 				# interpretation wrong
-				print "<IMG SRC=\"$dir[1]\" WIDTH=$dir[3]% HEIGHT=$dir[3]% ALT=\"$dir[1]\">\n";
+				printit "<img src=\"$dir[1]\" width=$dir[3]% height=$dir[3]% ALT=\"$dir[1]\">\n";
 			} elsif (scalar(@dir) >= 5) {
 				# interpretation wrong
-				print "<IMG SRC=\"$dir[1]\" WIDTH=$dir[3]% HEIGHT=$dir[4]% ALT=\"$dir[1]\">\n";
+				printit "<img src=\"$dir[1]\" width=$dir[3]% height=$dir[4]% alt=\"$dir[1]\">\n";
 			}
 		} elsif ($dir[0] eq 'nodefault') {
 			$nodefault++;
 		} elsif ($dir[0] =~ /^(left|leftfill|right|center)$/) {
 			$dir[0] =~ tr/A-Z/a-z/;
 			&fontreset;
-			&alignreset;
 			&alignmode($dir[0]);
 			&fontchange;
 		} elsif ($dir[0] =~ /^filter$/) {
@@ -182,6 +191,9 @@
 			$dir[1] =~ s/\"//g;
 			$mgpfontsize = $dir[1];
 			&fontchange;
+		} elsif ($dir[0] =~ /^charset$/) {
+			$dir[1] =~ s/\"//g;
+			$charset = $dir[1];
 		} elsif (grep($dir[0] eq $_, @keywords)) {
 			# unsupported directive with 1 parameter
 		} else {
@@ -191,7 +203,12 @@
 }
 
 sub prologue {
+	print "<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\"\n";
+	print "  \"http://www.w3.org/TR/html4/loose.dtd\";>\n";
 	print "<HTML>\n";
+	print "<head>";
+	print "<meta http-equiv=\"Content-Type\" content=\"text/html; charset=$charset\">\n" if ($charset);
+	print "</head>\n";
 	print "<BODY";
 	print " TEXT=" . $colortext    if ($colortext ne '');
 	print " BGCOLOR=" . $colorbg   if ($colorbg ne '');
@@ -207,17 +224,17 @@
 
 sub epilogue {
 	if ($htmldefaultfontsize > 0){
-		print "</FONT>\n";
+		printit "</font>\n";
 	}
-	print <<EOF;
+	printit <<EOF;
 </BODY>
 </HTML>
 EOF
 }
 
 sub pageprologue {
-	print <<EOF
-<HR>
+	printit <<EOF
+<hr />
 EOF
 }
 
@@ -225,8 +242,8 @@
 	&output_eol;
 	$page++;
 	&doindent(0);
-	print <<EOF
-(page $page)<BR>
+	printit <<EOF
+<div align=center>(page $page)</div><br />
 EOF
 }
 
@@ -244,28 +261,28 @@
 		if (length($str)) {
 			$str =~ s/http:\/\/\S*/<A HREF=$&>$&<\/A>/g;
 			if ($indent) {
-				print "\t" x $indent . "<LI>" . $str;
+				printit "\t" x $indent . "<li>" . $str . "</li>";
 				$endline = "\n";
 			} else {
-				print $str;
-				$endline = "<BR>\n";
+				printit $str;
+				$endline = "<br />\n";
 			}
 			$outputsomething++;
 		} else {
-			$endline = "<BR>\n";
+			$endline = "<br />\n";
 		}
 	} else {
 		$endline = "";
 		if (length($str)) {
 			$str =~ s/http:\/\/\S*/<A HREF=$&>$&<\/A>/g;
-			print $str;
+			printit $str;
 			$outputsomething++;
 		}
 	}
 }
 
 sub output_eol {
-	print $endline;
+	printit $endline;
 	$endline = "";
 }
 
@@ -274,13 +291,13 @@
 
 	if ($indent > $level) {
 		while ($indent > $level) {
-			print "\t" x $indent . "</UL>\n";
+			printit "\t" x $indent . "</ul>\n";
 			$indent--;
 		}
 	} else {
 		while ($indent < $level) {
 			$indent++;
-			print "\t" x $indent . "<UL>\n";
+			printit "\t" x $indent . "<ul>\n";
 		}
 	}
 }
@@ -289,13 +306,13 @@
 	return if ($alignmode eq '');
 
 	if ($alignmode eq 'left') {
-		print "</DIV>\n";
+		printit "</div>\n";
 	} elsif ($alignmode eq 'leftfill') {
-		print "</DIV>\n";
+		printit "</div>\n";
 	} elsif ($alignmode eq 'right') {
-		print "</DIV>\n";
+		printit "</div>\n";
 	} elsif ($alignmode eq 'center') {
-		print "</DIV>\n";
+		printit "</div>\n";
 	} else {
 		die "unknown alignment $alignmode\n";
 	}
@@ -305,15 +322,16 @@
 sub alignmode {
 	local($mode) = @_;
 
+	&alignreset;
 	$alignmode = $mode;
 	if ($alignmode eq 'left') {
-		print "<DIV ALIGN=LEFT>\n";
+		printit "<div align=left>\n";
 	} elsif ($alignmode eq 'leftfill') {
-		print "<DIV ALIGN=LEFT>\n";
+		printit "<div align=left>\n";
 	} elsif ($alignmode eq 'right') {
-		print "<DIV ALIGN=RIGHT>\n";
+		printit "<div align=right>\n";
 	} elsif ($alignmode eq 'center') {
-		print "<DIV ALIGN=CENTER>\n";
+		printit "<div align=center>\n";
 	} else {
 		die "unknown alignment $mode\n";
 	}
@@ -345,9 +363,9 @@
 				. " | " . $filtercmd;
 	}
 	&output_eol;
-	print "<PRE>\n";
+	printit "<pre>\n";
 	system($filtercmd);
-	print "</PRE>\n";
+	printit "</pre>\n";
 	$filterinput = "";
 	$filtermode = 0;
 }
@@ -366,17 +384,17 @@
 		$fs = $htmlfontsizemax if ($fsh > $htmlfontsizemax);
 	}
 	if (($fs != 0) || (($colormode == 1) && ($colorlast ne $htmlfontcol))){
-		print "<FONT";
+		printit "<font";
 		if ($fs != 0) {
-			print " SIZE=";
-			print "+" if ($fs >= 0);
-			print $fs;
+			printit " size=";
+			printit "+" if ($fs >= 0);
+			printit $fs;
 		}
 		if (($colormode == 1) && ($colorlast ne $htmlfontcol)) {
-			print " COLOR=\"" . $htmlfontcol . "\"";
+			printit " color=\"" . $htmlfontcol . "\"";
 			$colorlast = $htmlfontcol;
 		}
-		print ">";
+		printit ">";
 		$infont = 1;
 	}
 }
@@ -384,7 +402,7 @@
 sub fontreset {
 	$colorlast = "";
 	if ($infont == 1) {
-		print "</FONT>";
+		printit "</font>";
 	}
 	$infont = 0;
 }

Attachment: pgp0l04mAu31N.pgp
Description: PGP signature