/* This C language subroutine breaks an input string into tokens seperated by a string of seperators. The Run Time Library for the C Language. Gordon A. Sterling (617) 461 - 3076 DSP Development Tools Engineering Created on 1/19/91 Updated on 5/94 by AS #include
char *strtok(char *s1, const char *s2); */ #include "lib_glob.h" #include "str_glob.h" .SEGMENT/CODE Code_Space_Name; .FILE RTL_FILENAME; .GLOBAL _strtok; .GLOBAL ___strtokDD, ___strtokDP, ___strtokPD, ___strtokPP; _strtok: ___strtokDD: JUMP (PC, strtok_core) (DB); pm_ptr=dm_vs_dm; pm_lnt=0; ___strtokDP: JUMP (PC, strtok_core) (DB); pm_ptr=dm_vs_pm; pm_lnt=0; ___strtokPD: JUMP (PC, strtok_core) (DB); pm_ptr=pm_vs_dm; pm_lnt=0; ___strtokPP: JUMP (PC, strtok_core) (DB); pm_ptr=pm_vs_pm; pm_lnt=0; strtok_core: put(R3); put(R6); put(R7); put(R9); put(R10); put(R11); R0=R0-R0, put(R13); R14=PASS R8, put(R14); R15=PASS R4, put(R15); IF NE JUMP (PC, setup_string) (DB); R1=dm_vs_dm; R2=pm_vs_dm; R15=ramvar(start_of_string); /*Fetch next string pointer*/ R0=ramvar(memory_type); /*Which memory holds old string?*/ R0=PASS R0; IF EQ JUMP (PC, hold_dags) (DB); R3=pm_ptr; COMP(R1,R3); /*Test for dm_vs_dm*/ IF EQ R4=R2; /*Should be pm_vs_dm*/ R1=dm_vs_pm; R2=pm_vs_pm; COMP(R1,R3); JUMP (PC, hold_dags) (DB); /*Test for dm_vs_pm*/ IF EQ R4=R2; /*Should be pm_vs_pm*/ pm_ptr=R4; /*Set proper function call*/ setup_string: R0=R0-R0, R3=pm_ptr; /*Check where first argument is located*/ COMP(R1,R3); IF EQ R0=R0-R0; COMP(R2,R3); IF EQ R0=R0+1; R1=pm_vs_dm; R2=dm_vs_pm; COMP(R1,R3); IF EQ R0=R0+1; COMP(R2,R3); IF EQ R0=R0-R0; ramvar(memory_type)=R0; /*Set memory type for next call*/ hold_dags: R11=dma_b; R10=dma_i; /*Hold dma_i, just in case*/ R9=dma_l; /*Hold dma_l, just in case*/ pma_b=pma_b; R7=pma_i; /*Hold pma_i, just in case*/ R6=pma_l; /*Hold pma_l, just in case*/ JUMP (pm_0, pm_ptr) (DB); dm_lnt=0; dm_mdf=0; return_NULL: R0=0; restore_state: FETCH_RETURN dma_l=R9; dma_i=R10; dma_b=R11; pma_l=R6; pma_i=R7; pma_b=R8; get(R15,1); get(R14,2); get(R13,3); get(R11,4); get(R10,5); get(R9,6); get(R7,7); get(R6,8); get(R3,9); RETURN (DB); RESTORE_STACK RESTORE_FRAME dm_vs_dm: CALL (PC, dm_len) (DB); /*Get length of s2 string*/ dm_ptr=R14; /*Point to s2*/ NOP; dm_ptr=R15; R13=PASS R0, dma_b=R14; /*Hold length, point to start of s2*/ R0=PASS R15, dma_l=R0; /*Set length for circular*/ R1=DM(dm_ptr,1); /*Read first char of s1*/ DO scan_dds1 UNTIL FOREVER; LCNTR=R13, DO scan_dds2 UNTIL LCE; R1=PASS R1, R2=DM(dma_i,1); IF EQ JUMP (PC, return_NULL) (LA); COMP(R1,R2); /*Check for equality*/ scan_dds2: IF NE JUMP (PC, ddtoken) (LA); /*Found the start of token*/ scan_dds1: R1=DM(dm_ptr,1); /*Read next char in s1*/ ddtoken: JUMP (PC, 3) (DB, LA); /* Clean off loop stack */ dma_b=R14; /*Point to start of s2*/ R1=DM(dm_ptr,1); /*Read next s1 char*/ DO finish_scan_dds1 UNTIL FOREVER; LCNTR=R13, DO find_end_dd UNTIL LCE; R1=PASS R1, R2=DM(dma_i,1); IF EQ JUMP (PC, mark_end_d) (LA); COMP(R1,R2); find_end_dd: IF EQ JUMP (PC, mark_end_d) (LA); finish_scan_dds1: R1=DM(dm_ptr,1); dm_vs_pm: CALL (PC, pm_len) (DB); /*Get length of s2 string*/ pm_ptr=R14; /*Point to s2*/ NOP; dm_ptr=R15; R13=PASS R0, pma_b=R14; /*Hold length, point to start of s2*/ R0=PASS R15, pma_l=R0; /*Set length for circular*/ R1=DM(dm_ptr,1); /*Read first char of s1*/ DO scan_dps1 UNTIL FOREVER; LCNTR=R13, DO scan_dps2 UNTIL LCE; R1=PASS R1, R2=PM(pma_i,1); IF EQ JUMP (PC, return_NULL) (LA); COMP(R1,R2); /*Check for equality*/ scan_dps2: IF NE JUMP (PC, dptoken) (LA); /*Found the start of token*/ scan_dps1: R1=DM(dm_ptr,1); /*Read next char in s1*/ dptoken: JUMP (PC, 3) (DB, LA); /* Clean off loop stack */ pma_b=R14; /*Point to start of s2*/ R1=DM(dm_ptr,1); /*Read next s1 char*/ DO finish_scan_dps1 UNTIL FOREVER; LCNTR=R13, DO find_end_dp UNTIL LCE; R1=PASS R1, R2=PM(pma_i,1); IF EQ JUMP (PC, mark_end_d) (LA); COMP(R1,R2); find_end_dp: IF EQ JUMP (PC, mark_end_d) (LA); finish_scan_dps1: R1=DM(dm_ptr,1); pm_vs_dm: CALL (PC, dm_len) (DB); /*Get length of s2 string*/ dm_ptr=R14; /*Point to s2*/ NOP; pm_ptr=R15; R13=PASS R0, dma_b=R14; /*Hold length, point to start of s2*/ R0=PASS R15, dma_l=R0; /*Set length for circular*/ R1=PM(pm_ptr,1); /*Read first char of s1*/ DO scan_pds1 UNTIL FOREVER; LCNTR=R13, DO scan_pds2 UNTIL LCE; R1=PASS R1, R2=DM(dma_i,1); IF EQ JUMP (PC, return_NULL) (LA); COMP(R1,R2); /*Check for equality*/ scan_pds2: IF NE JUMP (PC, pdtoken) (LA); /*Found the start of token*/ scan_pds1: R1=PM(pm_ptr,1); /*Read next char in s1*/ pdtoken: JUMP (PC, 3) (DB, LA); /* Clean off loop stack */ dma_b=R14; /*Point to start of s2*/ R1=PM(pm_ptr,1); /*Read next s1 char*/ DO finish_scan_pds1 UNTIL FOREVER; LCNTR=R13, DO find_end_pd UNTIL LCE; R1=PASS R1, R2=DM(dma_i,1); IF EQ JUMP (PC, mark_end_p) (LA); COMP(R1,R2); find_end_pd: IF EQ JUMP (PC, mark_end_p) (LA); finish_scan_pds1: R1=PM(pm_ptr,1); pm_vs_pm: CALL (PC, pm_len) (DB); /*Get length of s2 string*/ pm_ptr=R14; /*Point to s2*/ NOP; pm_ptr=R15; R13=PASS R0, pma_b=R14; /*Hold length, point to start of s2*/ R0=PASS R15, pma_l=R0; /*Set length for circular*/ R1=PM(pm_ptr,1); /*Read first char of s1*/ DO scan_pps1 UNTIL FOREVER; LCNTR=R13, DO scan_pps2 UNTIL LCE; R1=PASS R1, R2=PM(pma_i,1); IF EQ JUMP (PC, return_NULL) (LA); COMP(R1,R2); /*Check for equality*/ scan_pps2: IF NE JUMP (PC, pptoken) (LA); /*Found the start of token*/ scan_pps1: R1=PM(pm_ptr,1); /*Read next char in s1*/ pptoken: JUMP (PC, 3) (DB, LA); /* Clean off loop stack */ dma_b=R14; /*Point to start of s2*/ R1=PM(pm_ptr,1); /*Read next s1 char*/ DO finish_scan_pps1 UNTIL FOREVER; LCNTR=R13, DO find_end_pp UNTIL LCE; R1=PASS R1, R2=PM(pma_i,1); IF EQ JUMP (PC, mark_end_p) (LA); COMP(R1,R2); find_end_pp: IF EQ JUMP (PC, mark_end_p) (LA); finish_scan_pps1: R1=PM(pm_ptr,1); dm_len: dm_ptr=R14; /*Point to start*/ R0=R0-R0, R2=DM(dm_ptr,1); /*Clear count, read first sample*/ R2=PASS R2; /*Check for \0*/ DO find_dm_end UNTIL EQ; IF NE R0=R0+1, R2=DM(dm_ptr,1); /*Inc counter, read next*/ find_dm_end: R2=PASS R2; /*Check for \0*/ RTS; pm_len: pm_ptr=R14; /*Point to start*/ R0=R0-R0, R2=PM(pm_ptr,1); /*Clear count, read first sample*/ R2=PASS R2; /*Check for \0*/ DO find_pm_end UNTIL EQ; IF NE R0=R0+1, R2=PM(pm_ptr,1); /*Inc counter, read next*/ find_pm_end: R2=PASS R2; /*Check for \0*/ RTS; mark_end_d: R2=R2-R2, R4=DM(dm_M1, dm_ptr); R4=PASS R4, R1=dm_ptr; /* Test and see if at str end */ IF EQ R1=R1-1; /* If so, point last pointer to */ JUMP (PC, restore_state) (DB, LA); /* NULL */ DM(dm_M1,dm_ptr)=R2; ramvar(start_of_string)=R1; mark_end_p: R2=R2-R2, R4=PM(pm_M1, pm_ptr); R4=PASS R4, R1=pm_ptr; IF EQ R1=R1-1; JUMP (PC, restore_state) (DB, LA); PM(pm_M1,pm_ptr)=R2; ramvar(start_of_string)=R1; .ENDSEG; .SEGMENT/RAM_SPACE Ram_Space_Name; .VAR start_of_string; .VAR memory_type; .ENDSEG;