Yeah I was trying to abstract away the details and ask about a general
pattern (since that's what I'm interested in), but maybe the code
example was not illustrative enough.
For the subsequent translation scenario I tried to describe, the caller
is responsible for getting a single input character 'ic'. However they
do it should be opaque to the translating function, 'bar'. The caller
calls 'bar' to translate 'ic' to '*oc'.
extern return_type bar(state_type state, char ic, char * oc);
'bar' might not emit any output character '*oc' if it's not yet ready.
In that case, the caller shouldn't work with '*oc'; shouldn't send it
wherever output is going.
'bar' might emit '*oc' and have nothing more to emit until processing
the next 'ic' or beyond.
'bar' might emit '*oc' and inform the caller that there are more output
characters pending, so the caller should call 'bar' again until they've
been consumed. In this case, 'ic' is ignored for subsequent calls to
'bar' as 'bar' already knows what sequence it wishes to emit based on
the 'ic' that triggered it.
'foo' was really just a place-holder for "something the caller does with
the results of 'bar'". This might be to put the output characters in a
buffer or to send them to a stream.
I'm interested in general C patterns for this kind of scenario without
getting too distracted by this particular example of "translating
characters". Having said that, maybe working with this example scenario
is a better idea.