This is a rewrite of the code by droftarts to see whether structuring a library like this using a cleaner separation of data and code and a functional approach (no global variables) would help in understanding and reusing the code. This work is offered in all humility as a product of my own attempts to learn openscad. I have only tried this on a few simple cases and not printed from it.
May 2014 - code updated slighly to OpenSCAD version 2014-03
Unlike its ancestor, this is an opencad library, not a single parameterised object. Objects are constructed by writing a main script which composes the final object from parameterised components.
In this version
v1.01 - fix to simple spacing and factoring teeth_spacing from diameter calulation