UnixOperatingSystem.st
changeset 24015 4f944b150c9a
parent 24001 d0293bbca0af
child 24546 c98d4357a191
equal deleted inserted replaced
24014:c8573fb77f5a 24015:4f944b150c9a
  3703 pathOfCommand:aCommand
  3703 pathOfCommand:aCommand
  3704     "find where aCommand's executable file would be searched for if executed by a shell.
  3704     "find where aCommand's executable file would be searched for if executed by a shell.
  3705      Return nil if aCommand is either absolute, or relative and not executable,
  3705      Return nil if aCommand is either absolute, or relative and not executable,
  3706      or not executable is found along the PATH."
  3706      or not executable is found along the PATH."
  3707 
  3707 
  3708     |path f fExt commandFilename|
  3708     |path f fExt commandFilename exeExtensions|
  3709 
  3709 
  3710     commandFilename := aCommand asFilename.
  3710     commandFilename := aCommand asFilename.
  3711     commandFilename isAbsolute ifTrue:[
  3711     commandFilename isAbsolute ifTrue:[
  3712 	"/ something like "/foo/...", tried path is it
  3712         "/ something like "/foo/...", tried path is it
  3713 	commandFilename isExecutable ifFalse:[^ nil].
  3713         commandFilename isExecutable ifFalse:[^ nil].
  3714 	^ commandFilename pathName
  3714         ^ commandFilename pathName
  3715     ].
  3715     ].
  3716     commandFilename isExplicitRelative ifTrue:[
  3716     commandFilename isExplicitRelative ifTrue:[
  3717 	"/ something like "../foo/...", tried path resolved relative to the current directory
  3717         "/ something like "../foo/...", tried path resolved relative to the current directory
  3718 	commandFilename isExecutable ifFalse:[^ nil].
  3718         commandFilename isExecutable ifFalse:[^ nil].
  3719 	 ^ commandFilename pathName
  3719          ^ commandFilename pathName
  3720     ].
  3720     ].
  3721     (aCommand includes:$/) ifTrue:[
  3721     (aCommand includes:$/) ifTrue:[
  3722 	"/ something like "smalltalk/stx", tried path is relative to the current directory
  3722         "/ something like "smalltalk/stx", tried path is relative to the current directory
  3723 	(f := ('./',aCommand) asFilename) isExecutable ifTrue:[
  3723         (f := ('./',aCommand) asFilename) isExecutable ifTrue:[
  3724 	    ^ f pathName
  3724             ^ f pathName
  3725 	].
  3725         ].
  3726 	^ nil
  3726         ^ nil
  3727     ].
  3727     ].
  3728 
  3728 
  3729     "/ command is a single word, not relative and not absolute.
  3729     "/ command is a single word, not relative and not absolute.
  3730     "/ search along PATH environment variable to see what a shell would do.
  3730     "/ search along PATH environment variable to see what a shell would do.
       
  3731     exeExtensions := self executableFileExtensions.
  3731     path := self getEnvironment:'PATH'.
  3732     path := self getEnvironment:'PATH'.
  3732     path notEmptyOrNil ifTrue:[
  3733     path notEmptyOrNil ifTrue:[
  3733 	(path asCollectionOfSubstringsSeparatedBy:self pathSeparator) do:[:eachPathComponent |
  3734         (path asCollectionOfSubstringsSeparatedBy:self pathSeparator) do:[:eachPathComponent |
  3734 	    eachPathComponent isEmpty ifTrue:[
  3735             eachPathComponent isEmpty ifTrue:[
  3735 		f := commandFilename
  3736                 f := commandFilename
  3736 	    ] ifFalse:[
  3737             ] ifFalse:[
  3737 		f := eachPathComponent asFilename construct:aCommand.
  3738                 f := eachPathComponent asFilename construct:aCommand.
  3738 	    ].
  3739             ].
  3739 	    self executableFileExtensions do:[:eachExtension |
  3740             exeExtensions do:[:eachExtension |
  3740 		eachExtension notEmpty ifTrue:[
  3741                 fExt := f addSuffix:eachExtension.
  3741 		    fExt := f addSuffix:eachExtension.
  3742                 fExt isExecutable ifTrue:[
  3742 		] ifFalse:[
  3743                     ^ fExt pathName
  3743 		    fExt := f.
  3744                 ].
  3744 		].
  3745             ].
  3745 		fExt isExecutable ifTrue:[
  3746         ].
  3746 		    ^ fExt pathName
       
  3747 		].
       
  3748 	    ].
       
  3749 	].
       
  3750     ].
  3747     ].
  3751     ^ nil
  3748     ^ nil
  3752 
  3749 
  3753     "unix:
  3750     "unix:
  3754 
  3751