From ce6d73b22b8833ab3f954455e978db1750b926a3 Mon Sep 17 00:00:00 2001
From: Brad King <brad.king@kitware.com>
Date: Sun, 7 Dec 2003 14:09:58 -0500
Subject: [PATCH] ENH: Cleaned up pipe numbering.

---
 Process.h.in   | 11 +++++++----
 ProcessUNIX.c  | 14 ++++++++++----
 ProcessWin32.c | 16 +++++++++++-----
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/Process.h.in b/Process.h.in
index 11c582c..dc2bbd5 100644
--- a/Process.h.in
+++ b/Process.h.in
@@ -60,6 +60,7 @@
 #define kwsysProcess_Execute             kwsys(Process_Execute)
 #define kwsysProcess_WaitForData         kwsys(Process_WaitForData)
 #define kwsysProcess_Pipes_e             kwsys(Process_Pipes_e)
+#define kwsysProcess_Pipe_None           kwsys(Process_Pipe_None)
 #define kwsysProcess_Pipe_STDOUT         kwsys(Process_Pipe_STDOUT)
 #define kwsysProcess_Pipe_STDERR         kwsys(Process_Pipe_STDERR)
 #define kwsysProcess_Pipe_Timeout        kwsys(Process_Pipe_Timeout)
@@ -228,8 +229,8 @@ kwsysEXPORT void kwsysProcess_Execute(kwsysProcess* cp);
  *
  * Return value will be one of:
  *
- *   0            = No more data will be available from the child process,
- *                  or no process has been executed.  WaitForExit should
+ *   Pipe_None    = No more data will be available from the child process,
+ *    ( == 0)       or no process has been executed.  WaitForExit should
  *                  be called to wait for the process to terminate.
  *   Pipe_STDOUT  = Data have been read from the child's stdout pipe.
  *   Pipe_STDERR  = Data have been read from the child's stderr pipe.
@@ -241,8 +242,9 @@ kwsysEXPORT int kwsysProcess_WaitForData(kwsysProcess* cp, char** data,
                                          int* length, double* timeout);
 enum kwsysProcess_Pipes_e
 {
-  kwsysProcess_Pipe_STDOUT=1,
-  kwsysProcess_Pipe_STDERR=2,
+  kwsysProcess_Pipe_None,
+  kwsysProcess_Pipe_STDOUT,
+  kwsysProcess_Pipe_STDERR,
   kwsysProcess_Pipe_Timeout=255
 };
 
@@ -317,6 +319,7 @@ kwsysEXPORT void kwsysProcess_Kill(kwsysProcess* cp);
 # undef kwsysProcess_Execute
 # undef kwsysProcess_WaitForData
 # undef kwsysProcess_Pipes_e
+# undef kwsysProcess_Pipe_None
 # undef kwsysProcess_Pipe_STDOUT
 # undef kwsysProcess_Pipe_STDERR
 # undef kwsysProcess_Pipe_Timeout
diff --git a/ProcessUNIX.c b/ProcessUNIX.c
index f7a63c8..ff91aca 100644
--- a/ProcessUNIX.c
+++ b/ProcessUNIX.c
@@ -497,7 +497,7 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
   kwsysProcessTime userStartTime;
   int user = 0;
   int expired = 0;
-  int pipeId = 0;
+  int pipeId = kwsysProcess_Pipe_None;
   int numReady = 0;
 
   /* Record the time at which user timeout period starts.  */
@@ -542,7 +542,13 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
             /* Report this data.  */
             *data = cp->PipeBuffer;
             *length = n;
-            pipeId = (1 << i);
+            switch(i)
+              {
+              case KWSYSPE_PIPE_STDOUT:
+                pipeId = kwsysProcess_Pipe_STDOUT; break;
+              case KWSYSPE_PIPE_STDERR:
+                pipeId = kwsysProcess_Pipe_STDERR; break;
+              };
             break;
             }
           }
@@ -663,13 +669,13 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
       cp->Killed = 0;
       cp->TimeoutExpired = 1;
       cp->PipesLeft = 0;
-      return 0;
+      return kwsysProcess_Pipe_None;
       }
     }
   else
     {
     /* No pipes are left open.  */
-    return 0;
+    return kwsysProcess_Pipe_None;
     }
 }
 
diff --git a/ProcessWin32.c b/ProcessWin32.c
index 6ed98b8..add0d96 100644
--- a/ProcessWin32.c
+++ b/ProcessWin32.c
@@ -931,14 +931,14 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
   int user;
   int done = 0;
   int expired = 0;
-  int pipeId = 0;
+  int pipeId = kwsysProcess_Pipe_None;
   DWORD w;
 
   /* Make sure we are executing a process.  */
   if(cp->State != kwsysProcess_State_Executing || cp->Killed ||
      cp->TimeoutExpired)
     {
-    return 0;
+    return kwsysProcess_Pipe_None;
     }
 
   /* Record the time at which user timeout period starts.  */
@@ -1002,7 +1002,13 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
         /* Report this data.  */
         *data = cp->Pipe[cp->CurrentIndex].DataBuffer;
         *length = cp->Pipe[cp->CurrentIndex].DataLength;
-        pipeId = (1 << cp->CurrentIndex);
+        switch(cp->CurrentIndex)
+          {
+          case KWSYSPE_PIPE_STDOUT:
+            pipeId = kwsysProcess_Pipe_STDOUT; break;
+          case KWSYSPE_PIPE_STDERR:
+            pipeId = kwsysProcess_Pipe_STDERR; break;
+          }
         done = 1;
         }
       }
@@ -1047,13 +1053,13 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
       kwsysProcess_Kill(cp);
       cp->TimeoutExpired = 1;
       cp->Killed = 0;
-      return 0;
+      return kwsysProcess_Pipe_None;
       }
     }
   else
     {
     /* The children have terminated and no more data are available.  */
-    return 0;
+    return kwsysProcess_Pipe_None;
     }
 }
 
-- 
GitLab