struct StringsBase *StringsBase=0L; /*#define RUN*/ #ifdef RUN char *StrChr(s,c) char *s; char c; { char *p=s,sc; do if( !(sc=*p++) || (c==sc) ) sc=0; while(sc); if( (!*--p) && c) p=0L; return p; } /* StrChr $VER:0.1 */ #endif long test(s,c) char *s,c; { long el=0; char *p,o[128]; sprintf(o,"<%s>",s); p=(char *)strchr(s,c); printf(" %8s ",o); sprintf(o,"<%c>",c); printf(" %3s %2x ",o,c); sprintf(o,"<%s>",p); printf(" %-10s ",o); printf("%ld %x\n",StrLen(p),p); return el; } #ifdef COMMENT char *StrChr1(char *s,char c) { char *p=s,sc; do if( !(sc=*p++) || (c==sc) ) sc=0; while(sc); return ((!*--p && c) ? (char *)0 : p); } /* StrChr $VER:0.1 */ #endif int main() { /* MAIN */ long el=0,l; char *s[1024],*cp,c; StringsBase=(struct StringsBase *)OpenLibrary("Strings.library",0); puts(" Input char/hex Output len ret.adr."); StrCpy(s,"strchr "); test(s,'s'); test(s,'t'); test(s,'a'); test(s,'h'); test(s,' '); test(s,'r'); test(s,0); if(StringsBase) CloseLibrary(StringsBase); return el; } /* END */ #ifdef COMMENT _StrChr: move.b (A0)+,D1 tst.b D1 beq StrChr15 cmp.b D0,D1 bne StrChr5 StrChr15: moveq.l #0,D1 ; sc=0 StrChr5: tst.b D1 bne _StrChr ;while (sc) tst.b -(A0) ; (!*--p) bne StrChr8 tst.b D0 beq StrChr8 suba.l A0,A0 ; p=0 StrChr8: move.l A0,D0 RTS Input char/hex Output len ret.adr. 73 7 2B9A9C 74 6 2B9A9D 61 <> 0 0 68
3 2B9AA0 < > 20 < > 1 2B9AA2 72 5 2B9A9E <> 0 <> 0 2B9AA3 #endif