#!/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 ### 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 = "" html = "" ### this is the tricky part ### priority: preprocessor statements (handled in main loop), ### comments, strings, braces ### problem : unexpected kEND, remove them and get error : expecting kEND def scanline i = 0 while i < line.length ### could mess up if line[0] is a star and line[-1] is / if line[i]=="*" and line[i-1]=="/" and incomment+instring== 0 line = line[0,i-2] + comment + line[i-1,-1] incomment = 1 i++ end if line[i] == "*" and line[i+1] == "/" and incomment == 1 line = line[0,i+1] + closefont + line[i+2,-1] incomment = 0 i++ end i++ end end mifile = ARGV.shift # thanks to mr. hdm for some way cool code hacks html << %q^ #{mifile} - BitRot
^

### main loop
### TMP TEST that just looks for lines starting with # and colors them
File.readlines(mifile).each do |line|
	line = line.gsub('<', '<').gsub('>', '>').chomp	
	if line =~ /^#/
		if(incomment + instring == 0)
			line = preprocess + line + "\n" + closefont
		end
	### calls to scanline go here
	end
	
	html << line
end

html << %q^

	
^

#outp = ARGV.shift
#fd   = outp ? File.open(outp, "w") : $stdout
print html
end