Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site unc.unc.UUCP Path: utzoo!linus!decvax!mcnc!unc!rentsch From: rentsch@unc.UUCP (Tim Rentsch) Newsgroups: net.lang.st80 Subject: Filename expansion goodie -- makes "file lists" useful Message-ID: <976@unc.unc.UUCP> Date: Tue, 11-Feb-86 18:43:42 EST Article-I.D.: unc.976 Posted: Tue Feb 11 18:43:42 1986 Date-Received: Thu, 13-Feb-86 19:13:56 EST References: <1@randvax.UUCP> Reply-To: rentsch@unc.UUCP (Tim Rentsch) Distribution: net Organization: CS Dept, U. of N. Carolina, Chapel Hill Lines: 69 Summary: Here is a Smalltalk goodie ("hack" might be a better word) to do filename expansion. (Ever been frustrated by not being able to type a general file spec into a file list? Well, in the interpreter we have here it doesn't work.) Note: although this code is kind of crocky, it does have the pleasant attribute that it makes "file lists" accept file specifications rather than just names. ============================CUT HERE==================================== 'From Smalltalk-80, version 2, of April 1, 1983 on 12 January 1986 at 10:26:33 pm'! !String reorganize! ('comparing' < <= > >= hash hashMappedBy: match: sameAs: spellAgainst:) ('accessing' at: at:put: basicAt: basicAt:put: findString:startingAt: replaceFrom:to:with:startingAt: replaceFrom:to:withByteArray:startingAt: size string) ('enumerating' lexemesDo:) ('copying' copyUpTo: deepCopy) ('printing' isLiteral printOn: storeOn:) ('converting' asDisplayText asFileName asLowercase asNumber asParagraph asString asSymbol asText asUnixCommand asUppercase contractTo: oldRunDecodeOn: oldRunEncoded withCRs) ('displaying' displayAt: displayOn:at:) ('private' compare: primReplaceFrom:to:with:startingAt: stringhash) ('primitive' system) ! !String methodsFor: 'enumerating'! lexemesDo: aBlock "do aBlock for each lexeme I contain. Preliminary version -- 'lexemes' are between blanks. Done January 12, 1986 by Tim Rentsch" | sz bl pos nextBlank | sz _ self size. bl _ $ . pos _ 1. [ pos < sz & ( ( self at: pos ) = bl ) ] whileTrue: [ pos _ pos + 1 ]. [ pos < sz ] whileTrue: [ nextBlank _ self findString: ' ' startingAt: pos. nextBlank = 0 ifTrue: [ nextBlank _ sz + 1 ]. aBlock value: ( self copyFrom: pos to: nextBlank - 1 ). pos _ nextBlank. [ pos < sz & ( ( self at: pos ) = bl ) ] whileTrue: [ pos _ pos + 1 ]. ].! ! !UnixFileDirectory methodsFor: 'file accessing'! filesMatching: pattern "Answer an Array of the names of files that match the string, pattern. Needs de-crocking. January 12, 1986 by Tim Rentsch" | names name namesString dirPre | names _ WriteStream on: (Array new: 10). dirPre _ directoryName = '.' ifTrue: [ '' ] ifFalse: [ directoryName , '/' ]. namesString _ ( 'echo ' , dirPre , pattern ) asUnixCommand unixIt. namesString = 'echo: No match. ' ifFalse: [ namesString lexemesDo: [ :word | names nextPut: word ] ]. ^names contents! !