All pastes #424947 Raw Edit

Bitty

public ruby v1 · immutable
·published 2007-04-05 03:25 UTC
rendered paste body
#!/usr/bin/ruby# bitty's itty bitty highlighter :D# c/c++ - colors comments, strs, brace blocks# my first ruby program so do not laugh :'(### state tracking variablesbracedepth	= 0 			### nested {incomment	= 0			### in multi-line commentinstring	= 0			### in "..." stringbslash		= 0			### prev char is / ### syntax colorscolcc		= "blue"		### compiler instructionscolcom		= "green"		### commentscolstr		= "maroon"		### stringscolbr		= ["antiquewhite","aquamarine","thistle"]### the three brace colors cycle### common html strings### yeah <font> is deprecated but it makes my life easiercomment		= "<font color=" + colcom + ">"string		= "<font color=" + colstr + ">" preprocess	= "<font color=" + colcc + ">"brace		= "<span style=\"color:" + colbr[bracedepth] + ";\">"closespan	= "</span>"closefont	= "</font>"prefix		= ""postfix		= ""mifile		= "./mangle.c"		### tmp lolfile		= File.new(mifile,"r")code		= file.readlinesprint "<html><head><title>" + mifile + " - BitRot</title></head>"print "<body><style>body {background-color:lightgray;font-face:monaco,courier;font-size:10px; }</style><pre>"### main loop### TMP TEST that just looks for lines starting with # and colors them### except it does not work :'(code.each { |i|	if i[0] == "#"		if incomment + instring = 0			prefix = preprocess.dup;			postfix = closefont.dup;		end	end	i.sub!("<","&lt;")	i.sub!(">","&gt;")	print prefix + i + postfix + "<br>"	prefix = "".dup	postfix = "".dup}		p