Selaa lähdekoodia

Restore Linux functionality

Arthur Yefimov 3 vuotta sitten
vanhempi
commit
4773155873
8 muutettua tiedostoa jossa 193 lisäystä ja 293 poistoa
  1. 1 1
      data/bin/compile.sh
  2. 30 11
      data/bin/link_console.sh
  3. 5 4
      data/bin/link_graph.sh
  4. 8 5
      src/FreeOberon.Mod
  5. 4 0
      src/Term.Mod
  6. 1 0
      src/term/term.h
  7. 24 1
      src/term/term_linux.c
  8. 120 271
      src/term/term_win32.c

+ 1 - 1
data/bin/compile.sh

@@ -9,7 +9,7 @@ cd bin
 OFRDIR="../data/bin/OfrontPlus/Target/Linux_amd64"
 PATH="$OFRDIR:$PATH"
 export OBERON=".:../src:$OFRDIR/Lib/Sym"
-OFR="ofront+ -88 -7 -s"
+OFR="ofront+ -s -88 -7"
 
 
 $OFR $2 ../Programs/$1

+ 30 - 11
data/bin/link_console.sh

@@ -1,19 +1,38 @@
 #!/bin/bash
-# This script is run by Free Oberon on Linux. Current directory of the
-# script will be where FreeOberon executable is located. This
-# particular script is for console programs.
-cd bin
-VOCDIR=../data/bin/voc/install
-CC=gcc
+#   This script is run by Free Oberon on Linux. Current directory of the
+#   script will be where FreeOberon executable is located. This
+#   particular script is for console programs.
+
 THENAME="${1%.*}"
 ONAME="${THENAME##*/}"
-SDL2Opts=`sdl2-config --cflags --libs`
+OFRDIR="../data/bin/OfrontPlus/Target/Linux_amd64"
+PATH="$OFRDIR:$PATH"
+CC="gcc"
+
+cd bin
+
+
+
 shift
-$CC -fPIC -g -I $VOCDIR/C/include \
-  -o $ONAME $ONAME.o \
+
+
+
+
+
+
+
+
+
+
+
+$CC -g3 -O0 -fno-exceptions \
+  -I ../../src \
+  -I $OFRDIR/../../Mod/Lib \
+  -I $OFRDIR/Lib/Obj \
+  $ONAME.c -o $ONAME \
   $@ \
-  $VOCDIR/lib/Int.o \
-  $VOCDIR/lib/libvoc-OC.a
+  ../data/bin/libFreeOberon.a \
+  $OFRDIR/Lib/libOfront.a
 retcode=$?
 cd ..
 exit $retcode

+ 5 - 4
data/bin/link_graph.sh

@@ -1,7 +1,7 @@
 #!/bin/bash
-# This script is run by Free Oberon on Linux. Current directory of the
-# script will be where FreeOberon executable is located. This
-# particular script is for graphical programs.
+#   This script is run by Free Oberon on Linux. Current directory of the
+#   script will be where FreeOberon executable is located. This
+#   particular script is for graphical programs.
 
 cd bin
 
@@ -13,8 +13,8 @@ CC="gcc"
 
 SDL2Opts=`sdl2-config --cflags --libs`
 
-shift
 
+shift
 
 
 
@@ -27,6 +27,7 @@ shift
 
 
 $CC -g3 -O0 -fno-exceptions \
+  -I ../../src \
   -I $OFRDIR/../../Mod/Lib \
   -I $OFRDIR/Lib/Obj \
   $ONAME.c -o $ONAME \

+ 8 - 5
src/FreeOberon.Mod

@@ -590,11 +590,14 @@ BEGIN exename[0] := 0X;
   END ;
 RETURN ok END CompileAll;
 
-PROCEDURE RunProgram(prg: ARRAY OF CHAR);
-VAR cmd: ARRAY 256 OF CHAR;
-    x: INTEGER;
-BEGIN cmd := '"'; Strings.Append(prg, cmd); Strings.Append('"', cmd);
-  IF ~Term.StartProcess(cmd) THEN
+PROCEDURE RunProgram(IN prg: ARRAY OF CHAR);
+VAR dir: ARRAY 256 OF CHAR;
+  i: INTEGER;
+BEGIN dir := prg$;
+  i := 0; WHILE dir[i] # 0X DO INC(i) END;
+  WHILE (i # -1) & (dir[i] # '/') & (dir[i] # '\') DO DEC(i) END; INC(i);
+  dir[i] := 0X;
+  IF ~Term.StartProcessIn(prg, dir) THEN
     T.PutString(0, T.charsY - 1, ' Program execution failed ', 15, 4, 0);
     IF T.Draw() THEN G.Flip; G.Pause END
   ELSE

+ 4 - 0
src/Term.Mod

@@ -26,6 +26,10 @@ PROCEDURE -StartProcess*
   (cmd: ARRAY OF CHAR): BOOLEAN
   "StartProcess(cmd)";
 
+PROCEDURE -StartProcessIn*
+  (cmd, dir: ARRAY OF CHAR): BOOLEAN
+  "StartProcessIn(cmd, dir)";
+
 PROCEDURE -ProcessFinished*(VAR err: INTEGER): BOOLEAN
   "ProcessFinished(err)";
 

+ 1 - 0
src/term/term.h

@@ -2,6 +2,7 @@
 #define TERM_H
 
 int StartProcess(char *process);
+int StartProcessIn(char *process, char *dir);
 int ProcessFinished();
 int WriteToProcess(char *buf, int len);
 int ReadFromProcess(char *buf, int *len, int limit);

+ 24 - 1
src/term/term_linux.c

@@ -29,8 +29,10 @@ extern void exit(int);
 int p[2], q[2];
 pid_t pid;
 
-int StartProcess(char *process) {
+int StartProcessIn(char *process, char *dir) {
+  char cmd[600];
   int success = 0;
+  int i, j;
   if ((pipe(p) == -1) || (pipe(q) == -1)) {
     perror("StartProcess: Could not create pipes.");
   } else {
@@ -46,6 +48,23 @@ int StartProcess(char *process) {
       }
       close(q[1]);
       close(p[0]);
+      if (dir && dir[0] != '\0') {
+        getcwd(cmd, 256);
+        i = 0;
+        while (cmd[i]) i++;
+        if (i && cmd[i - 1] != '/') {
+          cmd[i] = '/';
+          i++;
+          cmd[i] = '\0';
+        }
+        j = 0;
+        while (process[j]) { cmd[i] = process[j]; i++; j++; }
+        cmd[i] = '\0';
+        if (chdir(dir) != 0) {
+          perror("StartProcess: Could not chdir() in child process.");
+        }
+        process = &cmd[0];
+      }
       if (execl(process, process, (char*)NULL)) {
         puts("Could not run program.");
         exit(0);
@@ -60,6 +79,10 @@ int StartProcess(char *process) {
   return success;
 }
 
+int StartProcess(char *process) {
+  return StartProcessIn(process, (char *)NULL);
+}
+
 int ProcessFinished(int *err) {
   int status;
   pid_t result = waitpid(pid, &status, WNOHANG|WUNTRACED);

+ 120 - 271
src/term/term_win32.c

@@ -32,7 +32,6 @@ HANDLE g_hInputFile = NULL;
 PROCESS_INFORMATION piProcInfo;
 DWORD exit_code;
 
-void CreateChildProcess(void);
 void WriteToPipe(void);
 void ReadFromPipe(void);
 void ErrorExit(PTSTR);
@@ -42,129 +41,107 @@ OVERLAPPED oOverlap;
 ULONG PipeSerialNumber;
 
 BOOL MyCreatePipeEx(
-    OUT LPHANDLE lpReadPipe,
-    OUT LPHANDLE lpWritePipe,
-    IN LPSECURITY_ATTRIBUTES lpPipeAttributes,
-    IN DWORD nSize,
-    DWORD dwReadMode,
-    DWORD dwWriteMode)
+  OUT LPHANDLE lpReadPipe,
+  OUT LPHANDLE lpWritePipe,
+  IN LPSECURITY_ATTRIBUTES lpPipeAttributes,
+  IN DWORD nSize,
+  DWORD dwReadMode,
+  DWORD dwWriteMode)
 {
-	HANDLE ReadPipeHandle, WritePipeHandle;
-	DWORD dwError;
-	UCHAR PipeNameBuffer[ MAX_PATH ];
-
-	//
-	// Only one valid OpenMode flag - FILE_FLAG_OVERLAPPED
-	//
-
-	if ((dwReadMode | dwWriteMode) & (~FILE_FLAG_OVERLAPPED)) {
-		SetLastError(ERROR_INVALID_PARAMETER);
-		return FALSE;
-	}
-
-	//
-	//  Set the default timeout to 120 seconds
-	//
+  HANDLE ReadPipeHandle, WritePipeHandle;
+  DWORD dwError;
+  UCHAR PipeNameBuffer[MAX_PATH];
+
+  // Only one valid OpenMode flag - FILE_FLAG_OVERLAPPED
+  if ((dwReadMode | dwWriteMode) & (~FILE_FLAG_OVERLAPPED)) {
+    SetLastError(ERROR_INVALID_PARAMETER);
+    return FALSE;
+  }
 
-	if (nSize == 0) {
-		nSize = 4096;
-	}
+  //  Set the default timeout to 120 seconds
+  if (nSize == 0) nSize = 4096;
 
   //PipeSerialNumber++;
   InterlockedIncrement(&PipeSerialNumber);
   
-	sprintf( PipeNameBuffer,
-					 "\\\\.\\Pipe\\RemoteExeAnon.%08x.%08x",
-					 GetCurrentProcessId(),
-					 PipeSerialNumber
-				 );
-
-	ReadPipeHandle = CreateNamedPipeA(
-											 PipeNameBuffer,
-											 PIPE_ACCESS_INBOUND | dwReadMode,
-											 PIPE_TYPE_BYTE | PIPE_WAIT,
-											 1,             // Number of pipes
-											 nSize,         // Out buffer size
-											 nSize,         // In buffer size
-											 120 * 1000,    // Timeout in ms
-											 lpPipeAttributes
-											 );
-
-	if (! ReadPipeHandle) {
-		return FALSE;
-	}
-
-	WritePipeHandle = CreateFileA(
-											PipeNameBuffer,
-											GENERIC_WRITE,
-											0,                         // No sharing
-											lpPipeAttributes,
-											OPEN_EXISTING,
-											FILE_ATTRIBUTE_NORMAL | dwWriteMode,
-											NULL                       // Template file
-										);
-
-	if (INVALID_HANDLE_VALUE == WritePipeHandle) {
-		dwError = GetLastError();
-		CloseHandle( ReadPipeHandle );
-		SetLastError(dwError);
-		return FALSE;
-	}
-
-	*lpReadPipe = ReadPipeHandle;
-	*lpWritePipe = WritePipeHandle;
-	return( TRUE );
+  sprintf(PipeNameBuffer,
+          "\\\\.\\Pipe\\RemoteExeAnon.%08x.%08x",
+          GetCurrentProcessId(),
+          PipeSerialNumber);
+
+  ReadPipeHandle = CreateNamedPipeA(
+                   PipeNameBuffer,
+                   PIPE_ACCESS_INBOUND | dwReadMode,
+                   PIPE_TYPE_BYTE | PIPE_WAIT,
+                   1,             // Number of pipes
+                   nSize,         // Out buffer size
+                   nSize,         // In buffer size
+                   120 * 1000,    // Timeout in ms
+                   lpPipeAttributes);
+
+  if (!ReadPipeHandle) return FALSE;
+
+  WritePipeHandle = CreateFileA(
+                      PipeNameBuffer,
+                      GENERIC_WRITE,
+                      0,                  // No sharing
+                      lpPipeAttributes,
+                      OPEN_EXISTING,
+                      FILE_ATTRIBUTE_NORMAL | dwWriteMode,
+                      NULL);              // Template file
+
+  if (INVALID_HANDLE_VALUE == WritePipeHandle) {
+    dwError = GetLastError();
+    CloseHandle(ReadPipeHandle);
+    SetLastError(dwError);
+    return FALSE;
+  }
+
+  *lpReadPipe = ReadPipeHandle;
+  *lpWritePipe = WritePipeHandle;
+  return TRUE;
 }
 
-int StartProcess(char *process) {
+int StartProcessIn(char *process, char *dir) {
   SECURITY_ATTRIBUTES saAttr;
 
-// Set the bInheritHandle flag so pipe handles are inherited.
+  if (dir && dir[0] == '\0') dir = NULL;
 
+  // Set the bInheritHandle flag so pipe handles are inherited.
   saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
   saAttr.bInheritHandle = TRUE;
   saAttr.lpSecurityDescriptor = NULL;
 
-// Create a pipe for the child process's STDOUT.
-
-  if ( ! MyCreatePipeEx(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0, FILE_FLAG_OVERLAPPED, 0) )
-   ErrorExit(TEXT("StdoutRd CreatePipe"));
-  //if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) )
-  // ErrorExit(TEXT("StdoutRd CreatePipe"));
-
-// Ensure the read handle to the pipe for STDOUT is not inherited.
-
-  if ( ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) )
-   ErrorExit(TEXT("Stdout SetHandleInformation"));
+  // Create a pipe for the child process's STDOUT.
+  if (!MyCreatePipeEx(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0, FILE_FLAG_OVERLAPPED, 0) )
+    ErrorExit(TEXT("StdoutRd CreatePipe"));
 
-// Create a pipe for the child process's STDIN.
+  // Ensure the read handle to the pipe for STDOUT is not inherited.
+  if (!SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) )
+    ErrorExit(TEXT("Stdout SetHandleInformation"));
 
-  if (! MyCreatePipeEx(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0, FILE_FLAG_OVERLAPPED, 0))
-   ErrorExit(TEXT("Stdin CreatePipe"));
+  // Create a pipe for the child process's STDIN.
+  if (!MyCreatePipeEx(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0, FILE_FLAG_OVERLAPPED, 0))
+    ErrorExit(TEXT("Stdin CreatePipe"));
 
-// Ensure the write handle to the pipe for STDIN is not inherited.
-
-  if ( ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) )
-   ErrorExit(TEXT("Stdin SetHandleInformation"));
+  // Ensure the write handle to the pipe for STDIN is not inherited.
+  if (!SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) )
+    ErrorExit(TEXT("Stdin SetHandleInformation"));
 
   ZeroMemory(&oOverlap, sizeof(oOverlap));
  
   // ACTUAL START PROCESS
 
-
-
   //TCHAR szCmdline[]=TEXT(process);
   STARTUPINFO siStartInfo;
   BOOL bSuccess = FALSE;
 
-// Set up members of the PROCESS_INFORMATION structure.
-
-  ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
-
-// Set up members of the STARTUPINFO structure.
-// This structure specifies the STDIN and STDOUT handles for redirection.
+  // Set up members of the PROCESS_INFORMATION structure.
+  ZeroMemory(&piProcInfo, sizeof(PROCESS_INFORMATION));
 
-  ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
+  // Set up members of the STARTUPINFO structure.
+  // This structure specifies the STDIN and STDOUT handles for redirection.
+  ZeroMemory(&siStartInfo, sizeof(STARTUPINFO));
   siStartInfo.cb = sizeof(STARTUPINFO);
   siStartInfo.hStdError = g_hChildStd_OUT_Wr;
   siStartInfo.hStdOutput = g_hChildStd_OUT_Wr;
@@ -172,34 +149,28 @@ int StartProcess(char *process) {
   siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
   siStartInfo.wShowWindow = SW_HIDE;
 
-// Create the child process.
-  
+  // Create the child process.
   bSuccess = CreateProcess(NULL,
-   process, //szCmdline,    // command line
-   NULL,      // process security attributes
-   NULL,      // primary thread security attributes
-   TRUE,      // handles are inherited
-   CREATE_NO_WINDOW,      // creation flags
-   NULL,      // use parent's environment
-   NULL,      // use parent's current directory
-   &siStartInfo,  // STARTUPINFO pointer
-   &piProcInfo);  // receives PROCESS_INFORMATION
+    process, //szCmdline,    // command line
+    NULL,    // process security attributes
+    NULL,    // primary thread security attributes
+    TRUE,    // handles are inherited
+    CREATE_NO_WINDOW, // creation flags
+    NULL,         // use parent's environment
+    dir,          // current directory of the process
+    &siStartInfo, // STARTUPINFO pointer
+    &piProcInfo); // receives PROCESS_INFORMATION
   
   // If an error occurs, exit the application.
-  if ( ! bSuccess )
-   ErrorExit(TEXT("CreateProcess"));
-  else
-  {
-   // Close handles to the child process and its primary thread.
-   // Some applications might keep these handles to monitor the status
-   // of the child process, for example.
-
-   //CloseHandle(piProcInfo.hProcess);
-   //CloseHandle(piProcInfo.hThread);
-  }
+  if (!bSuccess) ErrorExit(TEXT("CreateProcess"));
+
   return bSuccess ? 1 : 0;
 }
 
+int StartProcess(char *process) {
+  return StartProcessIn(process, (char *)NULL);
+}
+
 int ProcessFinished(int *err) {
   GetExitCodeProcess(piProcInfo.hProcess, &exit_code);
   int result = exit_code != STILL_ACTIVE;
@@ -218,17 +189,7 @@ int ProcessFinished(int *err) {
 
 void WriteToProcess(char *buf, int len) {
   DWORD dwWritten;
-//  CHAR chBuf[BUFSIZE];
-//  BOOL bSuccess = FALSE;
-
- //bSuccess = ReadFile(hParentStdIn, chBuf, BUFSIZE, &dwRead, NULL);
- //if ( ! bSuccess || dwRead == 0 ) break;
   WriteFile(g_hChildStd_IN_Wr, buf, len, &dwWritten, NULL);
-
-// Close the pipe handle so the child process stops reading.
-
-  //if ( ! CloseHandle(g_hChildStd_IN_Wr) )
-    //ErrorExit(TEXT("StdInWr CloseHandle"));
 }
 
 void ReadFromProcess(char *buf, int *len, int limit) {
@@ -269,165 +230,53 @@ void ReadFromProcess(char *buf, int *len, int limit) {
   //printf("len = %u\n===============\n", *len);
 }
 
-/*
-int _tmain(int argc, TCHAR *argv[])
-{
-  SECURITY_ATTRIBUTES saAttr;
-
-  printf("\n->Start of parent execution.\n");
-
-// Set the bInheritHandle flag so pipe handles are inherited.
-
-  saAttr.nLength = sizeof(SECURITY_ATTRIBUTES);
-  saAttr.bInheritHandle = TRUE;
-  saAttr.lpSecurityDescriptor = NULL;
-
-// Create a pipe for the child process's STDOUT.
-
-  if ( ! CreatePipe(&g_hChildStd_OUT_Rd, &g_hChildStd_OUT_Wr, &saAttr, 0) )
-   ErrorExit(TEXT("StdoutRd CreatePipe"));
-
-// Ensure the read handle to the pipe for STDOUT is not inherited.
-
-  if ( ! SetHandleInformation(g_hChildStd_OUT_Rd, HANDLE_FLAG_INHERIT, 0) )
-   ErrorExit(TEXT("Stdout SetHandleInformation"));
-
-// Create a pipe for the child process's STDIN.
-
-  if (! CreatePipe(&g_hChildStd_IN_Rd, &g_hChildStd_IN_Wr, &saAttr, 0))
-   ErrorExit(TEXT("Stdin CreatePipe"));
-
-// Ensure the write handle to the pipe for STDIN is not inherited.
-
-  if ( ! SetHandleInformation(g_hChildStd_IN_Wr, HANDLE_FLAG_INHERIT, 0) )
-   ErrorExit(TEXT("Stdin SetHandleInformation"));
-
-// Create the child process.
-  
-  CreateChildProcess();
-
-  WriteToPipe();
-  printf( "\n->Contents of %s written to child STDIN pipe.\n", argv[1]);
-
-// Read from pipe that is the standard output for child process.
-
-  printf( "\n->Contents of child process STDOUT:\n\n", argv[1]);
-  ReadFromPipe();
-
-  printf("\n->End of parent execution.\n");
-
-// The remaining open handles are cleaned up when this process terminates.
-// To avoid resource leaks in a larger application, close handles explicitly.
-
-  return 0;
-}
-*/
-
-void CreateChildProcess()
-// Create a child process that uses the previously created pipes for STDIN and STDOUT.
-{
-  TCHAR szCmdline[]=TEXT("prog.exe");
-  PROCESS_INFORMATION piProcInfo;
-  STARTUPINFO siStartInfo;
-  BOOL bSuccess = FALSE;
-
-// Set up members of the PROCESS_INFORMATION structure.
-
-  ZeroMemory( &piProcInfo, sizeof(PROCESS_INFORMATION) );
-
-// Set up members of the STARTUPINFO structure.
-// This structure specifies the STDIN and STDOUT handles for redirection.
-
-  ZeroMemory( &siStartInfo, sizeof(STARTUPINFO) );
-  siStartInfo.cb = sizeof(STARTUPINFO);
-  siStartInfo.hStdError = g_hChildStd_OUT_Wr;
-  siStartInfo.hStdOutput = g_hChildStd_OUT_Wr;
-  siStartInfo.hStdInput = g_hChildStd_IN_Rd;
-  siStartInfo.dwFlags |= STARTF_USESTDHANDLES;
-
-// Create the child process.
-  
-  bSuccess = CreateProcess(NULL,
-   szCmdline,    // command line
-   NULL,      // process security attributes
-   NULL,      // primary thread security attributes
-   TRUE,      // handles are inherited
-   0,      // creation flags
-   NULL,      // use parent's environment
-   NULL,      // use parent's current directory
-   &siStartInfo,  // STARTUPINFO pointer
-   &piProcInfo);  // receives PROCESS_INFORMATION
-  
-  // If an error occurs, exit the application.
-  if ( ! bSuccess )
-   ErrorExit(TEXT("CreateProcess"));
-  else
-  {
-   // Close handles to the child process and its primary thread.
-   // Some applications might keep these handles to monitor the status
-   // of the child process, for example.
-
-   CloseHandle(piProcInfo.hProcess);
-   CloseHandle(piProcInfo.hThread);
-  }
-}
-
-void WriteToPipe(void)
-
 // Read from a file and write its contents to the pipe for the child's STDIN.
 // Stop when there is no more data.
-{
+void WriteToPipe(void) {
   DWORD dwRead, dwWritten;
   CHAR chBuf[BUFSIZE];
   BOOL bSuccess = FALSE;
 
-   //bSuccess = ReadFile(hParentStdIn, chBuf, BUFSIZE, &dwRead, NULL);
-   //if ( ! bSuccess || dwRead == 0 ) break;
-	  chBuf[0] = '3';
-	  chBuf[1] = '5';
-	  chBuf[2] = 13;
-	  chBuf[3] = 10;
-   dwRead = 4;
-   bSuccess = WriteFile(g_hChildStd_IN_Wr, chBuf, dwRead, &dwWritten, NULL);
-
-// Close the pipe handle so the child process stops reading.
-
-  if ( ! CloseHandle(g_hChildStd_IN_Wr) )
-   ErrorExit(TEXT("StdInWr CloseHandle"));
+  //bSuccess = ReadFile(hParentStdIn, chBuf, BUFSIZE, &dwRead, NULL);
+  //if (!bSuccess || dwRead == 0) break;
+  chBuf[0] = '3';
+  chBuf[1] = '5';
+  chBuf[2] = 13;
+  chBuf[3] = 10;
+  dwRead = 4;
+  bSuccess = WriteFile(g_hChildStd_IN_Wr, chBuf, dwRead, &dwWritten, NULL);
+
+  // Close the pipe handle so the child process stops reading.
+  if (!CloseHandle(g_hChildStd_IN_Wr)) ErrorExit(TEXT("StdInWr CloseHandle"));
 }
 
-void ReadFromPipe(void)
-
 // Read output from the child process's pipe for STDOUT
 // and write to the parent process's pipe for STDOUT.
 // Stop when there is no more data.
-{
+void ReadFromPipe(void) {
   DWORD dwRead, dwWritten;
   CHAR chBuf[BUFSIZE];
   BOOL bSuccess = FALSE;
   HANDLE hParentStdOut = GetStdHandle(STD_OUTPUT_HANDLE);
 
-  for (;;)
-  {
-   bSuccess = ReadFile( g_hChildStd_OUT_Rd, chBuf, BUFSIZE, &dwRead, NULL);
-   if( ! bSuccess || dwRead == 0 ) break;
+  while (1) {
+    bSuccess = ReadFile( g_hChildStd_OUT_Rd, chBuf, BUFSIZE, &dwRead, NULL);
+    if (!bSuccess || dwRead == 0) break;
 
-   bSuccess = WriteFile(hParentStdOut, chBuf,
-             dwRead, &dwWritten, NULL);
-   if (! bSuccess ) break;
+    bSuccess = WriteFile(hParentStdOut, chBuf,
+              dwRead, &dwWritten, NULL);
+    if (!bSuccess) break;
   }
 }
 
-void ErrorExit(PTSTR lpszFunction)
-
 // Format a readable error message, display a message box,
 // and exit from the application.
-{
-   LPVOID lpMsgBuf;
-   LPVOID lpDisplayBuf;
-   DWORD dw = GetLastError();
+void ErrorExit(PTSTR lpszFunction) {
+  LPVOID lpMsgBuf;
+  LPVOID lpDisplayBuf;
+  DWORD dw = GetLastError();
 
-   FormatMessage(
+  FormatMessage(
     FORMAT_MESSAGE_ALLOCATE_BUFFER |
     FORMAT_MESSAGE_FROM_SYSTEM |
     FORMAT_MESSAGE_IGNORE_INSERTS,
@@ -435,21 +284,21 @@ void ErrorExit(PTSTR lpszFunction)
     dw,
     MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
     (LPTSTR) &lpMsgBuf,
-    0, NULL );
+    0, NULL);
 
-   lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
+  lpDisplayBuf = (LPVOID)LocalAlloc(LMEM_ZEROINIT,
     (lstrlen((LPCTSTR)lpMsgBuf)+lstrlen((LPCTSTR)lpszFunction)+40)*sizeof(TCHAR));
 
-   snprintf((LPTSTR)lpDisplayBuf,
+  snprintf((LPTSTR)lpDisplayBuf,
     LocalSize(lpDisplayBuf) / sizeof(TCHAR),
     TEXT("%s failed with error %d: %s"),
     lpszFunction, dw, lpMsgBuf);
 
-   MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
+  MessageBox(NULL, (LPCTSTR)lpDisplayBuf, TEXT("Error"), MB_OK);
 
-   LocalFree(lpMsgBuf);
-   LocalFree(lpDisplayBuf);
-   ExitProcess(1);
+  LocalFree(lpMsgBuf);
+  LocalFree(lpDisplayBuf);
+  ExitProcess(1);
 }
 
 int RunProcess(char *cmd, char *buf, int limit, int *len, int *err) {