Linux port

Port this code to linux.

The code is really a mass of **, seems only copy the snippets from here and there, without formatting.
I used some dirty-but-work hacks on it to maintain the clearness of the original file (see also changeset).
Seems to work on Linux, but not much tested because a server down of ypool.net.