home *** CD-ROM | disk | FTP | other *** search
- {Turbo version of UCSD 'scan' function}
- program tscan;
- const alpha:array[0..25] of char=
- ('a','b','c','d','e','f','g','h','i','j','k','l','m',
- 'n','o','p','q','r','s','t','u','v','w','x','y','z');
-
- function scan(count,match:integer;var where):integer;
- {scans until match test is true}
- {returns count of bytes scanned, with sign indicating direction}
- var result,ans:integer;
- equal,up:boolean;
- begin
- equal:=hi(match)=0;
- up:=count>=0;
- if not up then count:=-count;
- if not equal then match:=not match;
- if up then
- if equal then
- Inline($C4/$7E/<where/ {les di,where[bp]}
- $8B/$4E/<count/ {mov cx,count[bp]}
- $8A/$46/<match/ {mov al,match[bp]}
- $FC/ {cld}
- $F2/$AE/ {repne scasb}
- $89/$4E/<result) {mov result,cx}
- else
- Inline($C4/$7E/<where/ {les di,where[bp]}
- $8B/$4E/<count/ {mov cx,count[bp]}
- $FC/ {cld}
- $8A/$46/<match/ {mov al,match[bp]}
- $F3/$AE/ {rep scasb}
- $89/$4E/<result) {mov result,cx}
- else {not up}
- if equal then
- Inline($C4/$7E/<where/ {les di,where[bp]}
- $8B/$4E/<count/ {mov cx,count[bp]}
- $8A/$46/<match/ {mov al,match[bp]}
- $FD/ {std}
- $F2/$AE/ {repne scasb}
- $89/$4E/<result) {mov result,cx}
- else
- Inline($C4/$7E/<where/ {les di,where[bp]}
- $8B/$4E/<count/ {mov cx,count[bp]}
- $FD/ {std}
- $8A/$46/<match/ {mov al,match[bp]}
- $F3/$AE/ {rep scasb}
- $89/$4E/<result); {mov result,cx}
- if up then
- if result=0 then ans:= count else ans:=pred(count-result)
- else
- if result=0 then ans:=result-count else ans:=succ(result-count);
- scan:=ans;
- if result=0 then
- if (mem[seg(where):ofs(where)+ans]<>match) xor equal then
- if up then scan:=pred(ans) else scan:=succ(ans)
- end;
-
- begin
- writeln('"',alpha,'"');
- writeln('scan(26,ord(''h''),alpha) = ',scan(26,ord('h'),alpha));
- writeln('scan(-26,ord(''t''),alpha[25]) = ',scan(-26,ord('t'),alpha[25]));
- writeln('scan(26,ord(''?''),alpha) = ',scan(26,ord('?'),alpha));
- writeln('scan(-26,ord(''?''),alpha[25]) = ',scan(-26,ord('?'),alpha[25]));
- writeln('scan(26,ord(''a''),alpha) = ',scan(26,ord('a'),alpha));
- writeln('scan(-26,ord(''z''),alpha[25]) = ',scan(-26,ord('z'),alpha[25]));
- fillchar(alpha,25,'a');writeln('"',alpha,'"');
- writeln('scan(26,not ord(''a''),alpha) = ',scan(26,not ord('a'),alpha));
- writeln('scan(26,not ord(''z''),alpha) = ',scan(26,not ord('z'),alpha));
- fillchar(alpha[1],25,'z');writeln('"',alpha,'"');
- writeln('scan(-26,not ord(''z''),alpha[25]) = ',scan(-26,not ord('z'),alpha[25]
- ));
- writeln('scan(-6,not ord(''z''),alpha[5]) = ',scan(-6,not ord('z'),alpha[5]));
- readln
- end.
-