00001 /* Copyright (c) 1985 Ceriel J.H. Jacobs */ 00002 00003 /* $Header$ */ 00004 00005 # ifndef _MACHINE_ 00006 # define PUBLIC extern 00007 # else 00008 # define PUBLIC 00009 # endif 00010 00011 /* 00012 * Simple minded finite state machine implementation to recognize 00013 * strings. 00014 */ 00015 00016 struct state { 00017 char s_char; /* character to match with */ 00018 char s_endstate; /* flag, 1 if this state is an endstate */ 00019 struct state *s_match; /* new state if matched */ 00020 struct state *s_next; /* other characters to match with */ 00021 short s_cnt; /* if an endstate, this field is filled with 00022 * some info, dependant on the machine. 00023 */ 00024 }; 00025 00026 # define FSM_OKE 0 00027 # define FSM_ISPREFIX -1 /* Must be < 0 */ 00028 # define FSM_HASPREFIX 1 00029 00030 int addstring(); 00031 /* 00032 * int addstring(str,cnt,mach) 00033 * char *str; The string to be recognized 00034 * int cnt; Attribute of the string. 00035 * struct state **mach; The finite state machine 00036 * 00037 * This routine adds a string to a finite state automaton. 00038 * It returns FSM_ISPREFIX if the added string is a prefix of a string already 00039 * in the automaton, FSM_HASPREFIX if a string, already recognized by the 00040 * automaton, is a prefix of the added string. 00041 * Otherwise it returns FSM_OKE. 00042 */ 00043 00044 int match(); 00045 /* 00046 * int match(str,p_int,mach) 00047 * char *str; pointer to string 00048 * int *p_int; Pointer to an integer 00049 * struct state *mach; The finite state machine 00050 * 00051 * A match of the string indicated by "str" is tried. If a head of "str" 00052 * is recognized by the finite state automaton, a machine dependant number 00053 * is put in the integer pointed to by "p_int". 00054 * The number of characters that match is returned, so a return value of 0 00055 * means no match. 00056 * A return value of FSM_PREFIX means that the string "str" was a prefix of a 00057 * matched string. 00058 */ 00059 00060 # undef PUBLIC
1.5.8