Strangly enough, there isn't a lot of source code on the web which shows you how to do this.
Id Software has released the source code for Quake1 and Quake2, as well as for all of the BSP compiling tools.
I'd say there's a hell of a lot of source out there. :)