MatchEng

MatchEng defines the facilities offered by the Grouse FSA to the rest of GGrep. It specifies how the match engine should be called, how match results are to be returned to the caller, and also specifies the action codes that may be used in the state tables. It also lays out how the table flags are to be formatted, so that the table type and options can be summarised by the flags.

MatchEng defines a structure to hold all the action entry points. This structure must be filled in by the match engine, and used in the construction of the state tables. References to this structure are hidden behind the macro names. This structure is virtually the only global variable in the program. Here's part of the structure:

typedef void *MatchEng_Action;

        MatchEng_Action pAgain;
        MatchEng_Action pAdvance;
        MatchEng_Action pStartMatchPush;
        MatchEng_Action pStartMatchPushAdvance;
        MatchEng_Action pAgainPushAdvance;
        MatchEng_Action pBackAndAdvance;
        MatchEng_Action pAdvancePushZero;
        MatchEng_Action pNoMatch;

MatchEng defines the actions implemented by the FSA, and provides macros to reference each action by name. In a (rare) break from the module style, these names are not prefixed by the module name, as they are so dominant in the overall structure of the program. An example of the macro definitions:

#define ADVANCE                         gMatchEngAct.pAdvance
#define START_MATCH_PUSH                gMatchEngAct.pStartMatchPush

#define START_MATCH_PUSH_ADVANCE        gMatchEngAct.pStartMatchPushAdvance

#define AGAIN_PUSH_ADVANCE              gMatchEngAct.pAgainPushAdvance

#define BACK_AND_ADVANCE                gMatchEngAct.pBackAndAdvance

#define ADVANCE_PUSH_ZERO               gMatchEngAct.pAdvancePushZero

#define NO_MATCH                        gMatchEngAct.pNoMatch

MatchEng also defines other components between the search control and the match engine. The buffer variables and state tables appear in a rather horribly large structure.

Finally, MatchEng defines the interface between the search control and the match reporting functions, including prototype definitions and output selection flags.