Where in the code do the flaps get managed...?

I’m trawling through the code to figure out how the flap control works but I can’t find a mention of it anywhere despite my lousiest of grep searches. Can anyone wiser than me point it out please?

Grateful from Gateshead.

Thanks @peterbarker! Clearly my grepping needs a polish!