Filename.st
changeset 19670 113d38592c9b
parent 19665 d815a7ce4e57
child 19691 5e613f6255d9
child 19752 eba7ee9bb48c
equal deleted inserted replaced
19669:d8a7300a2382 19670:113d38592c9b
   980     "return the nameString, expanding any OS specific macros.
   980     "return the nameString, expanding any OS specific macros.
   981      Here, a ~/ or ~user/ prefix is expanded to the users home dir (as in csh)"
   981      Here, a ~/ or ~user/ prefix is expanded to the users home dir (as in csh)"
   982 
   982 
   983     |dir user cutIdx idx userInfo|
   983     |dir user cutIdx idx userInfo|
   984 
   984 
   985     (aString startsWith:'~') ifFalse:[
   985     (aString startsWith:$~) ifFalse:[
   986 	^ aString.
   986         ^ aString.
   987     ].
   987     ].
   988 
   988 
   989     aString size > 1 ifTrue:[
   989     aString size > 1 ifTrue:[
   990 	idx := aString indexOf:self separator.
   990         idx := aString indexOf:self separator.
   991 	idx == 0 ifTrue:[
   991         idx == 0 ifTrue:[
   992 	    "aString is '~user'"
   992             "aString is '~user'"
   993 	    user := aString copyFrom:2.
   993             user := aString copyFrom:2.
   994 	    cutIdx := aString size + 1.
   994             cutIdx := aString size + 1.
   995 	] ifFalse:[
   995         ] ifFalse:[
   996 	    "aString is '~user/something'"
   996             "aString is '~user/something'"
   997 	    user := aString copyFrom:2 to:(idx - 1).
   997             user := aString copyFrom:2 to:(idx - 1).
   998 	    cutIdx := idx.
   998             cutIdx := idx.
   999 	].
   999         ].
  1000 	user notEmpty ifTrue:[
  1000         user notEmpty ifTrue:[
  1001 	    userInfo := OperatingSystem userInfoOf:user.
  1001             userInfo := OperatingSystem userInfoOf:user.
  1002 	    userInfo notNil ifTrue:[
  1002             userInfo notNil ifTrue:[
  1003 		dir := userInfo at:#dir ifAbsent:nil.
  1003                 dir := userInfo at:#dir ifAbsent:nil.
  1004 	    ].
  1004             ].
  1005 	    dir isNil ifTrue:[
  1005             dir isNil ifTrue:[
  1006 "/                 ('Filename [info]: unknown user: ' , user) infoPrintCR.
  1006 "/                 ('Filename [info]: unknown user: ' , user) infoPrintCR.
  1007 		^ aString
  1007                 ^ aString
  1008 	    ].
  1008             ].
  1009 	].
  1009         ].
  1010     ].
  1010     ].
  1011     dir isNil ifTrue:[
  1011     dir isNil ifTrue:[
  1012 	"aString is '~' or '~/'"
  1012         "aString is '~' or '~/'"
  1013 	dir := OperatingSystem getHomeDirectory.
  1013         dir := OperatingSystem getHomeDirectory.
  1014 	cutIdx := 2.
  1014         cutIdx := 2.
  1015     ].
  1015     ].
  1016 
  1016 
  1017     ^ dir , (aString copyFrom:cutIdx)
  1017     ^ dir , (aString copyFrom:cutIdx)
  1018 
  1018 
  1019     "
  1019     "
  1047 possiblyQuotedPathname:aPath
  1047 possiblyQuotedPathname:aPath
  1048     "return a filename path usable as command line argument,
  1048     "return a filename path usable as command line argument,
  1049      by quoting in double quotes if there are any embedded special characters.
  1049      by quoting in double quotes if there are any embedded special characters.
  1050      On Unix systems, special characters might also be prefixed by a backslash character."
  1050      On Unix systems, special characters might also be prefixed by a backslash character."
  1051 
  1051 
  1052     (aPath startsWith:'"') ifFalse:[
  1052     (aPath startsWith:$") ifFalse:[
  1053 	(aPath includes:Character space) ifTrue:[
  1053         (aPath includes:Character space) ifTrue:[
  1054 	    ^ '"',aPath,'"'
  1054             ^ '"',aPath,'"'
  1055 	].
  1055         ].
  1056     ].
  1056     ].
  1057     ^ aPath
  1057     ^ aPath
  1058 
  1058 
  1059 
  1059 
  1060     "
  1060     "
  5074 
  5074 
  5075 isAbsolute
  5075 isAbsolute
  5076     "return true, if the receiver represents an absolute pathname
  5076     "return true, if the receiver represents an absolute pathname
  5077      (in contrast to one relative to the current directory)."
  5077      (in contrast to one relative to the current directory)."
  5078 
  5078 
  5079     ((nameString startsWith:self species separator) or:[nameString startsWith:'~']) ifTrue:[^ true].
  5079     ((nameString startsWith:self species separator) or:[nameString startsWith:$~]) ifTrue:[^ true].
  5080     ^ self isVolumeAbsolute
  5080     ^ self isVolumeAbsolute
  5081 
  5081 
  5082     "
  5082     "
  5083      '/foo/bar' asFilename isAbsolute
  5083      '/foo/bar' asFilename isAbsolute
  5084      '~/bla' asFilename isAbsolute
  5084      '~/bla' asFilename isAbsolute
  5877 
  5877 
  5878 osNameForFile
  5878 osNameForFile
  5879     "internal - return the OS's name for the receiver to
  5879     "internal - return the OS's name for the receiver to
  5880      access it as a file."
  5880      access it as a file."
  5881 
  5881 
  5882     (nameString startsWith:'~') ifFalse:[
  5882     (nameString startsWith:$~) ifFalse:[
  5883 	^ nameString.
  5883         ^ nameString.
  5884     ].
  5884     ].
  5885 
  5885 
  5886     ^ self species nameWithSpecialExpansions:nameString.
  5886     ^ self species nameWithSpecialExpansions:nameString.
  5887 ! !
  5887 ! !
  5888 
  5888