Path: utzoo!mnetor!uunet!husc6!bu-cs!madd From: madd@bu-cs.BU.EDU (Jim Frost) Newsgroups: comp.sys.ibm.pc Subject: Re: looking for strings for msdos Message-ID: <17591@bu-cs.BU.EDU> Date: 17 Dec 87 01:05:51 GMT References: <1149@gvax.cs.cornell.edu> <11250013@hpldoma.HP.COM> Reply-To: madd@buita.UUCP (Jim Frost) Organization: Boston University Distributed Systems Group Lines: 61 In article <11250013@hpldoma.HP.COM> toddg@hpldoma.HP.COM (Todd Goin) writes: >/ hpldoma:comp.sys.ibm.pc / haim@gvax.cs.cornell.edu (Haim Shvaytser) / 6:54 pm Dec 11, 1987 / > >Does somebody have an equivalent to the unix "strings" program >that runs under ms-dos? There are a variety of them. I wrote one myself in only a couple of minutes. The code below is a simple one that I just wrote. I haven't a compiler here so I can't test it but its operation is obvious so if there are problems you should be able to debug it in seconds. Note that under MS-DOS there is no guarantee that strings will be null-terminated as they are in UNIX. This is why "minlength" is used. Five is a reasonable length. Hope this is useful, jim frost madd@bu-it.bu.edu -- cut -- { simple UNIX-like "strings" program. } program strings; {$i-,g128,p128} const minlength = 5; var f : file of byte; b : byte; s : string[255]; begin if paramcount <> 1 then begin { make sure they gave a filename } writeln('Usage: strings filename'); halt end; assign(f,paramstr(1)); { assign name to file variable } reset(f); { open file } if ioresult <> 0 then begin { error opening file } writeln(paramstr(1),': could not open file'); halt end; s:= ''; { clear string } while not eof(f) do begin { loop for whole file } read(f,b); { get a byte from file } if (b >= ord(' ')) and (b <= 127) then { is a char } s:= s+chr(b) { add to string } else begin { not char } if length(s) >= minlength then { if string is long enough, } writeln(s); { print it } s:= ''; { clear string } end; if (length(s) = 255) then begin { make sure no overflow } writeln(s); s:= '' end end; close(f); { all done } end.