Win32OperatingSystem.st
changeset 7062 44e3fe28aea0
parent 6799 568d31641c88
child 7065 f4c4e4b2ffa1
--- a/Win32OperatingSystem.st	Tue Feb 25 19:24:13 2003 +0100
+++ b/Win32OperatingSystem.st	Tue Feb 25 19:43:55 2003 +0100
@@ -22,7 +22,7 @@
 
 Object subclass:#FileStatusInfo
 	instanceVariableNames:'type mode uid gid size id accessed modified created statusChanged
-		path alternativeName'
+		path fullName alternativeName'
 	classVariableNames:''
 	poolDictionaries:''
 	privateIn:Win32OperatingSystem
@@ -2587,51 +2587,51 @@
     "/ ...this will change in an upcoming version to include
     "/ command.com command-line parsing here (sigh).
 
-self isMSWINDOWSNTlike ifTrue:[
-    shell := self getEnvironment:'COMSPEC'.
-    shell isNil ifTrue:[
-	wDir := self getWindowsSystemDirectory asFilename.
-	shell := (wDir construct:'cmd.exe').
-	shell exists ifFalse:[
-	    shell := (wDir construct:'command.com').
-	    shell exists ifFalse:[
-		self error:'no command.com available'.
-	    ]
-	].
-	shell := shell pathName.
+    self isMSWINDOWSNTlike ifTrue:[
+        shell := self getEnvironment:'COMSPEC'.
+        shell isNil ifTrue:[
+            wDir := self getWindowsSystemDirectory asFilename.
+            shell := (wDir construct:'cmd.exe').
+            shell exists ifFalse:[
+                shell := (wDir construct:'command.com').
+                shell exists ifFalse:[
+                    self error:'no command.com available'.
+                ]
+            ].
+            shell := shell pathName.
+        ].
+        aCommandString isNil ifTrue:[
+            ^ Array with:nil with:shell
+        ].
+        ^ Array with:nil with:(shell , ' /c ' , aCommandString)
     ].
-    aCommandString isNil ifTrue:[
-	^ Array with:nil with:shell
-    ].
-    ^ Array with:nil with:(shell , ' /c ' , aCommandString)
-].
 
     hasRedirection := false.
     (aCommandString isNil or:[aCommandString includesAny:'<>|']) ifTrue:[
-	hasRedirection := true
+        hasRedirection := true
     ] ifFalse:[
-	words := aCommandString asCollectionOfSubstringsSeparatedBy:Character space.
-	args := ' '.
-	words from:2 to:(words size) do:[:s | 
-	    args := args , (s , ' ').
-	].
+        words := aCommandString asCollectionOfSubstringsSeparatedBy:Character space.
+        args := ' '.
+        words from:2 to:(words size) do:[:s | 
+            args := args , (s , ' ').
+        ].
     ].
 
     "/ I/O redirection is not yet handled directly
     "/ fallBack to command.com (below) to do it.
 
     hasRedirection ifFalse:[
-	path := self pathOfCommand:(words at:1).
-	path notNil ifTrue:[
-	    "/ execute the command directly -
-	    "/ without going through command.com
-
-	    self isMSWINDOWSNTlike ifTrue:[
-		args := path , args.
-	    ].
-
-	    ^ Array with:path with:args
-	].
+        path := self pathOfCommand:(words at:1).
+        path notNil ifTrue:[
+            "/ execute the command directly -
+            "/ without going through command.com
+
+            self isMSWINDOWSNTlike ifTrue:[
+                args := path , args.
+            ].
+
+            ^ Array with:path with:args
+        ].
     ].
 
     "/ windows-NT (where command.com works)
@@ -2639,18 +2639,18 @@
 
     shell := self getEnvironment:'COMSPEC'.
     shell isNil ifTrue:[
-	wDir := self getWindowsSystemDirectory asFilename.
-	shell := (wDir construct:'cmd.exe').
-	shell exists ifFalse:[
-	    shell := (wDir construct:'command.com').
-	    shell exists ifFalse:[
-		self error:'no command.com available'.
-	    ]
-	].
-	shell := shell pathName.
+        wDir := self getWindowsSystemDirectory asFilename.
+        shell := (wDir construct:'cmd.exe').
+        shell exists ifFalse:[
+            shell := (wDir construct:'command.com').
+            shell exists ifFalse:[
+                self error:'no command.com available'.
+            ]
+        ].
+        shell := shell pathName.
     ].
     aCommandString isNil ifTrue:[
-	^ Array with:shell with:shell
+        ^ Array with:shell with:shell
     ].
     ^ Array with:shell with:(shell , ' /c ' , aCommandString)
 
@@ -2658,6 +2658,69 @@
     "Modified: / 19.5.1999 / 10:01:24 / cg"
 !
 
+exec:aCommandPath withArguments:argString environment:environment fileDescriptors:fdArray closeDescriptors:closeFdArray fork:doFork newPgrp:newPgrp inDirectory:aDirectory
+    "Internal lowLevel entry for combined fork & exec for WIN32
+
+     If fork is false (chain a command):
+         execute the OS command specified by the argument, aCommandPath, with
+         arguments in argArray (no arguments, if nil).
+         If successful, this method does not return and smalltalk is gone.
+         If not successful, it does return.
+         Normal use is with forkForCommand.
+
+     If fork is true (subprocess command execution):
+        fork a child to do the above.
+        The process id of the child process is returned; nil if the fork failed.
+
+     fdArray contains the filedescriptors, to be used for the child (if fork is true).
+        fdArray[1] = 15 -> use fd 15 as stdin.
+        If an element of the array is set to nil, the corresponding filedescriptor
+        will be closed for the child.
+        fdArray[0] == StdIn for child
+        fdArray[1] == StdOut for child
+        fdArray[2] == StdErr for child
+        on VMS, these must be channels as returned by createMailBox.
+
+     closeFdArray contains descriptors that will be closed in the subprocess.
+        closeDescriptors are ignored in the WIN32 & VMS versions.
+
+     NOTE that in WIN32 the fds are HANDLES.
+
+     If newPgrp is true, the subprocess will be established in a new process group.
+        The processgroup will be equal to id.
+        newPgrp is not used on WIN32 and VMS systems."
+
+    |dirPath cmdPath cmdLine|
+
+    aDirectory notNil ifTrue:[
+        dirPath := aDirectory asFilename asAbsoluteFilename osNameForDirectory.
+        (dirPath endsWith:':') ifTrue:[
+            dirPath := dirPath , '\'.
+        ].
+    ].
+
+    self isMSWINDOWSNTlike ifTrue:[
+        cmdPath := aCommandPath.
+        cmdLine := argString
+    ] ifFalse:[
+        cmdPath := 'stxspawn.exe'.
+        cmdLine := 'stxspawn.exe ' , aCommandPath , ' ' , argString
+    ].
+
+    ^ self 
+        primExec:cmdPath 
+        commandLine:cmdLine 
+        fileDescriptors:fdArray 
+        closeDescriptors:closeFdArray 
+        fork:doFork 
+        newPgrp:newPgrp 
+        inPath:dirPath
+        createFlags:nil
+
+    "Modified: / 31.1.1998 / 10:54:24 / md"
+    "Modified: / 15.5.1999 / 18:07:51 / cg"
+!
+
 exec:aCommandPath withArguments:argString fileDescriptors:fdArray closeDescriptors:closeFdArray fork:doFork newPgrp:newPgrp inDirectory:aDirectory
     "Internal lowLevel entry for combined fork & exec for WIN32
 
@@ -3016,54 +3079,55 @@
     aCommandString isNil ifTrue:[^ nil].
 
     anExternalInStream notNil ifTrue:[
-	in := anExternalInStream fileDescriptor.
+        in := anExternalInStream fileDescriptor.
     ] ifFalse:[
-	self isMSWINDOWSNTlike ifTrue:[
-	    inStream := 'nul' asFilename readStream.
-	    inStream notNil ifTrue:[
-		in := inStream fileDescriptor.
-	    ]
-	]
+        self isMSWINDOWSNTlike ifTrue:[
+            inStream := 'nul' asFilename readStream.
+            inStream notNil ifTrue:[
+                in := inStream fileDescriptor.
+            ]
+        ]
     ].
     anExternalOutStream notNil ifTrue:[
-	out := anExternalOutStream fileDescriptor.
+        out := anExternalOutStream fileDescriptor.
     ] ifFalse:[
-	self isMSWINDOWSNTlike ifTrue:[
-	    outStream := 'nul' asFilename writeStream.
-	    outStream notNil ifTrue:[
-		out := outStream fileDescriptor.
-	    ]
-	]
+        self isMSWINDOWSNTlike ifTrue:[
+            outStream := 'nul' asFilename writeStream.
+            outStream notNil ifTrue:[
+                out := outStream fileDescriptor.
+            ]
+        ]
     ].
     anExternalErrStream notNil ifTrue:[
-	err := anExternalErrStream fileDescriptor.
+        err := anExternalErrStream fileDescriptor.
     ] ifFalse:[
-	self isMSWINDOWSNTlike ifTrue:[
-	    errStream := 'nul' asFilename writeStream.
-	    errStream notNil ifTrue:[
-		err := errStream fileDescriptor.
-	    ]
-	]
+        self isMSWINDOWSNTlike ifTrue:[
+            errStream := 'nul' asFilename writeStream.
+            errStream notNil ifTrue:[
+                err := errStream fileDescriptor.
+            ]
+        ]
     ].
 
     shellAndArgs := self commandAndArgsForOSCommand:aCommandString.
     ret := self
-	exec:(shellAndArgs at:1)
-	withArguments:(shellAndArgs at:2)
-	fileDescriptors:(Array with:in with:out with:err)
-	closeDescriptors:nil
-	fork:true
-	newPgrp:false
-	inDirectory:dirOrNil.
+        exec:(shellAndArgs at:1)
+        withArguments:(shellAndArgs at:2)
+        environment:nil
+        fileDescriptors:(Array with:in with:out with:err)
+        closeDescriptors:nil
+        fork:true
+        newPgrp:false
+        inDirectory:dirOrNil.
 
     inStream notNil ifTrue:[
-	inStream close
+        inStream close
     ].
     outStream notNil ifTrue:[
-	outStream close
+        outStream close
     ].
     errStream notNil ifTrue:[
-	errStream close
+        errStream close
     ].
     ^ ret
 
@@ -3818,12 +3882,14 @@
      aYr aMon aDay aHr aMin aSec aMS
      mYr mMon mDay mHr mMin mSec mMS
      cYr cMon cDay cHr cMin cSec cMS
-     name2|
+     fileName alternativeName|
 
 %{
     struct stat buf;
     int ret;
-    char nameBuffer[15];
+    char alternativeFileNameBuffer[15];
+    char fileNameBuffer[MAX_PATH+1];
+
     unsigned INT ino;
 
     if (__isString(aPathName)) {
@@ -3858,10 +3924,16 @@
             id = __MKSMALLINT(0);   /* could get it by opening ... */
             size = __MKLARGEINT64(1, findStruct.nFileSizeLow, findStruct.nFileSizeHigh);
 
+            if (findStruct.cFileName[0] != '\0') {
+                bcopy(findStruct.cFileName, fileNameBuffer, MAX_PATH);
+                fileNameBuffer[MAX_PATH] = '\0';
+                fileName = __MKSTRING(fileNameBuffer);             /* FULL name */
+            }
+
             if (findStruct.cAlternateFileName[0] != '\0') {
-                bcopy(findStruct.cAlternateFileName, nameBuffer, 14);
-                nameBuffer[14] = '\0';
-                name2 = __MKSTRING(nameBuffer); /* DOS name */
+                bcopy(findStruct.cAlternateFileName, alternativeFileNameBuffer, 14);
+                alternativeFileNameBuffer[14] = '\0';
+                alternativeName = __MKSTRING(alternativeFileNameBuffer); /* DOS name */
             }
 
             /*
@@ -3947,8 +4019,9 @@
                     accessed:atime 
                     modified:mtime 
                     created:ctime
-                    path:nil
-                    alternativeName:name2.
+                    path:nil            
+                    fullName:fileName    
+                    alternativeName:alternativeName.
         ^ info
    ].
    ^ nil
@@ -7327,6 +7400,15 @@
         type:t mode:m uid:u gid:g size:s 
         id:i accessed:aT modified:mT created:cT 
         path:lP alternativeName:name2
+!
+
+type:t mode:m uid:u gid:g size:s id:i accessed:aT modified:mT created:cT path:lP fullName:fullName alternativeName:name2
+    ^ self basicNew
+        type:t mode:m uid:u gid:g size:s 
+        id:i accessed:aT modified:mT created:cT 
+        path:lP 
+        fullName:fullName
+        alternativeName:name2
 ! !
 
 !Win32OperatingSystem::FileStatusInfo methodsFor:'accessing'!
@@ -7364,6 +7446,13 @@
     ^ nil
 !
 
+fullName
+    "return the files real name (non-DOS name on windows).
+     Nil if there is no other name"
+
+    ^ fullName
+!
+
 gid
     "return gid"
 
@@ -7500,6 +7589,21 @@
     created := cT.
     path := lP.
     alternativeName := name2.
+!
+
+type:t mode:m uid:u gid:g size:s id:i accessed:aT modified:mT created:cT path:lP fullName:name1 alternativeName:name2
+    type := t.
+    mode := m.
+    uid := u.
+    gid := g.
+    size := s.
+    id := i.
+    accessed := aT.
+    modified := mT.
+    created := cT.
+    path := lP.
+    fullName := name1.    
+    alternativeName := name2.
 ! !
 
 !Win32OperatingSystem::FileStatusInfo methodsFor:'queries'!
@@ -8673,7 +8777,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.117 2002-10-14 09:54:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.118 2003-02-25 18:43:44 penk Exp $'
 ! !
 
 !Win32OperatingSystem::Win32FILEHandle methodsFor:'release'!
@@ -8700,7 +8804,7 @@
 !
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.117 2002-10-14 09:54:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.118 2003-02-25 18:43:44 penk Exp $'
 ! !
 
 !Win32OperatingSystem::Win32Handle methodsFor:'io'!
@@ -9087,7 +9191,7 @@
 !Win32OperatingSystem class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.117 2002-10-14 09:54:35 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libbasic/Win32OperatingSystem.st,v 1.118 2003-02-25 18:43:44 penk Exp $'
 ! !
 
 Win32OperatingSystem initialize!