#!/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 variables bracedepth = 0 ### nested { incomment = 0 ### in multi-line comment instring = 0 ### in "..." string bslash = 0 ### prev char is / ### syntax colors colcc = "blue" ### compiler instructions colcom = "green" ### comments colstr = "maroon" ### strings colbr = ["antiquewhite","aquamarine","thistle"] ### the three brace colors cycle ### common html strings ### yeah is deprecated but it makes my life easier comment = "" string = "" preprocess = "" brace = "" closespan = "" closefont = "" prefix = "" postfix = "" mifile = "./mangle.c" ### tmp lol file = File.new(mifile,"r") code = file.readlines print "" + mifile + " - BitRot" print "
"

### 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!("<","<")
	i.sub!(">",">")
	print prefix + i + postfix + "
" prefix = "".dup postfix = "".dup } p