1 /* Copyright (c) 1985 Ceriel J.H. Jacobs */
12 * Simple minded finite state machine implementation to recognize
17 char s_char
; /* character to match with */
18 char s_endstate
; /* flag, 1 if this state is an endstate */
19 struct state
*s_match
; /* new state if matched */
20 struct state
*s_next
; /* other characters to match with */
21 short s_cnt
; /* if an endstate, this field is filled with
22 * some info, dependant on the machine.
27 # define FSM_ISPREFIX -1 /* Must be < 0 */
28 # define FSM_HASPREFIX 1
32 * int addstring(str,cnt,mach)
33 * char *str; The string to be recognized
34 * int cnt; Attribute of the string.
35 * struct state **mach; The finite state machine
37 * This routine adds a string to a finite state automaton.
38 * It returns FSM_ISPREFIX if the added string is a prefix of a string already
39 * in the automaton, FSM_HASPREFIX if a string, already recognized by the
40 * automaton, is a prefix of the added string.
41 * Otherwise it returns FSM_OKE.
46 * int match(str,p_int,mach)
47 * char *str; pointer to string
48 * int *p_int; Pointer to an integer
49 * struct state *mach; The finite state machine
51 * A match of the string indicated by "str" is tried. If a head of "str"
52 * is recognized by the finite state automaton, a machine dependant number
53 * is put in the integer pointed to by "p_int".
54 * The number of characters that match is returned, so a return value of 0
56 * A return value of FSM_PREFIX means that the string "str" was a prefix of a