#!/usr/bin/ruby # bitty's itty bitty highlighter :D # c/c++ - colors comments, strs, brace blocks # my first ruby program so do not laugh :'( def usage puts "usage #{$0} [output.html]" exit(0) end ### 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 = "" html = "" mifile = ARGV.shift || usage() html << %q^ #{mifile} - BitRot
^

### main loop
### TMP TEST that just looks for lines starting with # and colors them
### except it does not work :'(
File.readlines(mifile).each do |line|
	prefix = ''
	suffix = ''
	if line =~ /^#/
		if(incomment + instring == 0)
			prefix = preprocess
			suffix = closefont
		end
	end
	
	html << prefix
	html << line.gsub('<', '<').gsub('>', '>').chomp 
	html << suffix + "\n"
end

html << %q^

	
^

$stdout.puts html