| 1 |
#!/usr/bin/perl |
| 2 |
die "Usage: gri2html file.gri file.html" if ($#ARGV !=1); |
| 3 |
$filename_gri = $ARGV[0]; |
| 4 |
$filename_html = $ARGV[1]; |
| 5 |
open(IN, "$filename_gri") || die "Can't open `$filename_gri' for input\n"; |
| 6 |
open(OUT, ">$filename_html") || die "Can't open `$filename_html' for output\n"; |
| 7 |
|
| 8 |
print OUT "<html>\n"; |
| 9 |
print OUT "<head>\n"; |
| 10 |
print OUT "<title>$ARGV[0]</title>\n"; |
| 11 |
print OUT "</head>\n"; |
| 12 |
print OUT "<body bgcolor=\"#FFFFFF\">\n"; |
| 13 |
print OUT "<i># This html document was prepared by gri2html based on the Gri script named</i>\n"; |
| 14 |
print OUT "<br><i># <a href=\"$ARGV[0]\">$ARGV[0]</a></i>\n"; |
| 15 |
print OUT "<br># <i>Gri is available for free at <a href=\"http://gri.sourceforge.net\">http://gri.sourceforge.net</a></i>\n"; |
| 16 |
print OUT "<pre>\n"; |
| 17 |
|
| 18 |
while(<IN>) { |
| 19 |
s,<,<,g; |
| 20 |
s,>,>,g; |
| 21 |
s,//(.*),<i>//$1</i>,; |
| 22 |
|
| 23 |
if (/^[ ]*\#/) { |
| 24 |
s,(\#.*),<font color=\#B22222>$1</font>,; |
| 25 |
print OUT "$_"; |
| 26 |
next; |
| 27 |
} |
| 28 |
# #Comments |
| 29 |
s,(\#.*),<font color=\#B22222>$1</font>,; |
| 30 |
|
| 31 |
# \.factor. = |
| 32 |
s,(\\\.[^.]+\. [\+\*/^-]?=),<font color=\#0000EE>$1</font>,; |
| 33 |
# .gulf_emphasisGSL. = |
| 34 |
s,(\.[^.]+\. [\+\*/^-]?=),<font color=\#0000EE>$1</font>,; |
| 35 |
# \xl = |
| 36 |
s,(\\[^\\]+ [\+\*/^-]?=),<font color=\#0000EE>$1</font>,; |
| 37 |
|
| 38 |
# \.factor. |
| 39 |
s,(\\\.[^ .]+\.),<font color=\#CDAD00>$1</font>,g; |
| 40 |
# .factor. |
| 41 |
s,( \.[^ .]+\.),<font color=\#CDAD00>$1</font>,g; |
| 42 |
# ..ysize.. |
| 43 |
s,(\.\.[^ .]+\.\.),<font color=\#006400>$1</font>,g; |
| 44 |
# \xl |
| 45 |
s,( \\[^\ ]+),<font color=\#0000EE>$1</font>,g; |
| 46 |
|
| 47 |
# `newcommand' |
| 48 |
s,^(\`.*\')$,<font color=\#0000EE>$1</font>,; |
| 49 |
|
| 50 |
# system stuff |
| 51 |
s,system (.*),<font color=\#9400D3>system</font> <font color=\#FF0000>$1</font>,; |
| 52 |
# "strings" |
| 53 |
s,(".*"),<font color=\#2F4F4F>$1</font>,g; |
| 54 |
|
| 55 |
s,\b(quit|return|if|else( if)?|end (if|while)|break|while|rpn)\b,<font color=\#9400D3>$1</font>,g; |
| 56 |
|
| 57 |
# s,"(.*)",<u>"$1"</u>,g; |
| 58 |
print OUT "$_"; |
| 59 |
} |
| 60 |
print OUT "</pre>\n"; |
| 61 |
print OUT "</body>\n"; |
| 62 |
print OUT "</html>\n"; |