@@ -335,12 +335,12 @@ unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
335335}
336336
337337/**
338- * aa_dfa_next_state - traverse @dfa to find state @str stops at
338+ * aa_dfa_match - traverse @dfa to find state @str stops at
339339 * @dfa: the dfa to match @str against (NOT NULL)
340340 * @start: the state of the dfa to start matching in
341341 * @str: the null terminated string of bytes to match against the dfa (NOT NULL)
342342 *
343- * aa_dfa_next_state will match @str against the dfa and return the state it
343+ * aa_dfa_match will match @str against the dfa and return the state it
344344 * finished matching in. The final state can be used to look up the accepting
345345 * label, or as the start state of a continuing match.
346346 *
@@ -349,5 +349,79 @@ unsigned int aa_dfa_match_len(struct aa_dfa *dfa, unsigned int start,
349349unsigned int aa_dfa_match (struct aa_dfa * dfa , unsigned int start ,
350350 const char * str )
351351{
352- return aa_dfa_match_len (dfa , start , str , strlen (str ));
352+ u16 * def = DEFAULT_TABLE (dfa );
353+ u32 * base = BASE_TABLE (dfa );
354+ u16 * next = NEXT_TABLE (dfa );
355+ u16 * check = CHECK_TABLE (dfa );
356+ unsigned int state = start , pos ;
357+
358+ if (state == 0 )
359+ return 0 ;
360+
361+ /* current state is <state>, matching character *str */
362+ if (dfa -> tables [YYTD_ID_EC ]) {
363+ /* Equivalence class table defined */
364+ u8 * equiv = EQUIV_TABLE (dfa );
365+ /* default is direct to next state */
366+ while (* str ) {
367+ pos = base [state ] + equiv [(u8 ) * str ++ ];
368+ if (check [pos ] == state )
369+ state = next [pos ];
370+ else
371+ state = def [state ];
372+ }
373+ } else {
374+ /* default is direct to next state */
375+ while (* str ) {
376+ pos = base [state ] + (u8 ) * str ++ ;
377+ if (check [pos ] == state )
378+ state = next [pos ];
379+ else
380+ state = def [state ];
381+ }
382+ }
383+
384+ return state ;
385+ }
386+
387+ /**
388+ * aa_dfa_next - step one character to the next state in the dfa
389+ * @dfa: the dfa to tranverse (NOT NULL)
390+ * @state: the state to start in
391+ * @c: the input character to transition on
392+ *
393+ * aa_dfa_match will step through the dfa by one input character @c
394+ *
395+ * Returns: state reach after input @c
396+ */
397+ unsigned int aa_dfa_next (struct aa_dfa * dfa , unsigned int state ,
398+ const char c )
399+ {
400+ u16 * def = DEFAULT_TABLE (dfa );
401+ u32 * base = BASE_TABLE (dfa );
402+ u16 * next = NEXT_TABLE (dfa );
403+ u16 * check = CHECK_TABLE (dfa );
404+ unsigned int pos ;
405+
406+ /* current state is <state>, matching character *str */
407+ if (dfa -> tables [YYTD_ID_EC ]) {
408+ /* Equivalence class table defined */
409+ u8 * equiv = EQUIV_TABLE (dfa );
410+ /* default is direct to next state */
411+
412+ pos = base [state ] + equiv [(u8 ) c ];
413+ if (check [pos ] == state )
414+ state = next [pos ];
415+ else
416+ state = def [state ];
417+ } else {
418+ /* default is direct to next state */
419+ pos = base [state ] + (u8 ) c ;
420+ if (check [pos ] == state )
421+ state = next [pos ];
422+ else
423+ state = def [state ];
424+ }
425+
426+ return state ;
353427}
0 commit comments