(this describes the implementation of my fork extension for XFree86)
the program is a simulation of a 'machine'. The machine can be thought of as a Mealy (deterministic) finite state automaton.
The state of the automaton is a composition (i.e. product) of a 'state' (of the machine), a (top-bound limited) queue of undecided events and (upper bound limited) time. It's the time since the first event on the queue. This is the event we want to decide if it is meant to be forked (as a modifier), or not.
The machine accepts (one at a time) events, possibly changes the state, enqueues the event, and virtually increases the time, and sometimes outputs an event decided to be either unchanged or forked. The event is always the first in the queue.
When we output a Release, we have to output that of the forked ...
i implemented it in C++, so i could finally start to understand that langauge. I like its stricter type checking wrt C (compilers).
Here some bookmarks on implementing FSA in C++: