/* This C language subroutine locates the first occurance of the string s2 that is located in the string s1. (Not including NULL) The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 4/30/90 Updated on 6/94 by AS Updated on 3/95 by AS - separated polymorphic functions #include
int strstr(const char *s1, const char *s2); */ #include "lib_glob.h" #include "str_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL ___strstrPP; ___strstrPP: strstr_core: R0=R4-1, R4=pma_i; pm_vs_pm: R0=R0+1, pm_ptr=R8; /* Point to s2 */ pma_i=R0; /*Point to s1 */ R2=PM(pma_i,0); /*Read *s1 */ R2=PASS R2, R1=PM(pm_ptr,1); /*Test for end of s1 */ IF EQ JUMP (PC, return_NULL); /*End of s1, return with NULL */ DO pm_pm UNTIL FOREVER; R1=PASS R1, R2=PM(pma_i,1); /*Test for end of s2 */ IF EQ JUMP (PC, restore_state) (LA); /*String s2 found at s1 */ COMP(R2,R1), R1=PM(pm_ptr,1); /*Test for *s1 == *s2 */ pm_pm: IF NE JUMP (PC, pm_vs_pm) (LA); /*Try again */ return_NULL: R0=R0-R0; restore_state: FETCH_RETURN pma_i=R4; RETURN (DB); RESTORE_STACK RESTORE_FRAME .ENDSEG;