*
* string manipulation routines - file 3
*

 name C_str3

 text

* int strcspn(s1, s2)
*        char *s1;
*        char *s2;

 global _strcspn
_strcspn ldd #0
 pshs d,u
 ldx 6,s s1
 tst 0,x
 beq 3f
1 ldu 8,s s2
2 ldb 0,u+
 beq 4f
 cmpb 0,x
 bne 2b
3 puls d,u,pc
4 leax 1,x
 ldd 0,s
 addd #1
 std 0,s
 tst 0,x
 bne 1b
 puls d,u,pc

* char *strpbrk(s1, s2)
*        char *s1;
*        char *s2;

 global _strpbrk

_strpbrk pshs u
 ldx 4,s s1
 tst 0,x
 beq 5f
1 ldu 6,s
2 ldb 0,u+
 beq 4f
 cmpb 0,x
 bne 2b
 tfr x,d
 puls u,pc
4 leax 1,x
 tst 0,x
 bne 1b
5 ldd #0
 puls u,pc

* int strspn(s1, s2)
*        char *s1;
*        char *s2;

 global _strspn
_strspn ldd #0
 pshs d,u
 ldx 6,s s1
 tst 0,x
 beq 4f
1 ldu 8,s s2
2 ldb 0,u+
 beq 4f
 cmpb 0,x
 bne 2b
3 leax 1,x
 ldd 0,s
 addd #1
 std 0,s
 tst 0,x
 bne 1b
4 puls d,u,pc

* char *strtok(s1, s2)
*        char *s1;
*        char *s2;

 global _strtok

_strtok clr tokconf
 ldx 2,s s1
 bne 2f
 inc tokconf
 ldx tokcona
 bne 2f
 ldd #0
 rts
2 ldd 4,s s2
 pshs d,x
3 pshs x
 jsr _strcspn
 puls x
 tst tokconf
 bne 35f
 cmpd #0
 bne 35f
 ldx 2,s
 leax 1,x
 stx 2,s
 inc tokconf
 bra 3b
35 leas 2,s
 leax d,x
 tst 0,x
 beq 4f
 clr 0,x+
 bra 5f
4 ldx #0
5 stx tokcona
 puls d,pc

 data

tokcona fdb 0
tokconf fcb 0

 text

 end
