On any Dreamwidth system, the S2 source can be found in the s2 directory in the cvs directory. The integration of S2, and the implementation of most of the style system, happens here:
cgi-bin/LJ/S2.pm