Deriving H-table for Friedman test

#1
Hello there,
I'm currently writing a bit of general C-code to perform a Friedman test (http://faculty.vassar.edu/lowry/ch15a.html). When the values of N and k are "large" the computed value can be compared against a chi-squared distribution to obtain a P-value; fortunately, the GNU scientific library contains general chi-squared functions that I've been able to use. However, according to Sheskin [1] a table lookup should be done for "small" values of N and k (if I recall correctly, it's something like N < 13 and k < 5) since the chi-square is a poor approximation for lower N and k.

I come here to ask if anyone knows how to calculate the values for this table? Were I to find the table in a textbook, I can't just copy it over to my program as the table would undoubtably be copyright and it's my hope to share my code with others. So, I'm left with having to derive the table for myself; I just don't know how...

Thanks,
Daniel

[1] David Sheskin, "Handbook of Parametric and Nonparametric Statistical Procedures", 2004