/* * strtrap.c -- display string trap routine DEX2000 (AT side) * * Copyright (C) 1997 by Sony Computer Entertainment * All rights Reserved */ #include #include #include #include #include "strtrap.h" static String_trap_element *top = NULL; String_trap_element * add_new_trap(char *trapstring, int (* action)(), void *actarg) { String_trap_element *new; new = malloc(sizeof(String_trap_element)); if( new == NULL ) return NULL; new->action = action; new->actarg = actarg; new->key = create_search_key(trapstring,strlen(trapstring)); if( new->key == NULL ) { free( new ); return NULL; } new->next = top; top = new; return new; } void delete_trap(String_trap_element *element) { String_trap_element **ep; for( ep = ⊤ *ep != NULL; ep = &((*ep)->next) ) { if( *ep == element ) { *ep = element->next; free(element); break; } } } void rewind_trap(void) { String_trap_element *ep; for( ep = top; ep != NULL; ep = ep->next ) reset_search_key(ep->key); } int trap_check(char *string, int strlen ) { String_trap_element *ep; for( ep = top; ep != NULL; ep = ep->next ) { search_key(string, strlen, ep->key); if( key_found_p(ep->key) ) { rewind_trap(); if( ep->action != NULL ) return (*(ep->action))(ep->actarg); else return 1; } } return 0; }