aboutsummaryrefslogtreecommitdiffstats
path: root/Game/Code/lib/JEDI-SDLv1.0/SDL/Pas/xplatformutils.pas
diff options
context:
space:
mode:
authorbrunzelchen <brunzelchen@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-02-19 17:18:42 +0000
committerbrunzelchen <brunzelchen@b956fd51-792f-4845-bead-9b4dfca2ff2c>2010-02-19 17:18:42 +0000
commit51ed8fe6f2ea9892e905e81cf5bad3960537eb40 (patch)
treea4dcb099343762dcb7bd7988f73de68c1959d3a5 /Game/Code/lib/JEDI-SDLv1.0/SDL/Pas/xplatformutils.pas
downloadusdx-51ed8fe6f2ea9892e905e81cf5bad3960537eb40.tar.gz
usdx-51ed8fe6f2ea9892e905e81cf5bad3960537eb40.tar.xz
usdx-51ed8fe6f2ea9892e905e81cf5bad3960537eb40.zip
Challenge MOD r7 alpha based on Ultrastar Deluxe v1.0.1a
for changes read Changelog.txt in folder Game git-svn-id: svn://svn.code.sf.net/p/ultrastardx/svn/branches/1.0.1 Challenge MOD@2107 b956fd51-792f-4845-bead-9b4dfca2ff2c
Diffstat (limited to 'Game/Code/lib/JEDI-SDLv1.0/SDL/Pas/xplatformutils.pas')
-rw-r--r--Game/Code/lib/JEDI-SDLv1.0/SDL/Pas/xplatformutils.pas126
1 files changed, 126 insertions, 0 deletions
diff --git a/Game/Code/lib/JEDI-SDLv1.0/SDL/Pas/xplatformutils.pas b/Game/Code/lib/JEDI-SDLv1.0/SDL/Pas/xplatformutils.pas
new file mode 100644
index 00000000..7fd3128f
--- /dev/null
+++ b/Game/Code/lib/JEDI-SDLv1.0/SDL/Pas/xplatformutils.pas
@@ -0,0 +1,126 @@
+unit xplatformutils;
+
+{$I jedi-sdl.inc}
+
+interface
+
+uses
+ {$IFDEF WIN32}
+ Windows;
+ {$ELSE}
+ {$IFDEF UNIX}
+ {$IFDEF FPC}
+ libc;
+ {$ELSE}
+ Libc,
+ Xlib;
+ {$ENDIF}
+ {$ENDIF}
+ {$ENDIF}
+
+const
+{$IFDEF MACOS}
+ DIR_SEP = ':';
+ DIR_CUR = ':';
+{$ELSE}
+{$IFDEF DARWIN}
+ DIR_SEP = ':';
+ DIR_CUR = ':';
+{$ELSE}
+{$IFDEF WIN32}
+ DIR_SEP = '\';
+ DIR_CUR = '';
+{$ELSE}
+ DIR_SEP = '/';
+ DIR_CUR = '';
+{$ENDIF}
+{$ENDIF}
+{$ENDIF}
+
+procedure ExecAndWait( aProcess : string; aArguments : array of string );
+
+
+implementation
+
+procedure ExecAndWait( aProcess : string; aArguments : array of string );
+var
+{$IFDEF WIN32}
+ CommandLine : string;
+ ProcessInfo: TProcessInformation;
+ Startupinfo: TStartupInfo;
+ ExitCode: longword;
+ x : integer;
+{$ELSE}
+{$IFDEF UNIX}
+ pid: PID_T;
+ Max: Integer;
+ i: Integer;
+ parg: PPCharArray;
+ argnum: Integer;
+ returnvalue : Integer;
+{$ENDIF}
+{$ENDIF}
+begin
+ {$IFDEF WIN32}
+ // Initialize the structures
+ FillChar(ProcessInfo, sizeof(TProcessInformation), 0);
+ FillChar(Startupinfo, sizeof(TStartupInfo), 0);
+ Startupinfo.cb := sizeof(TStartupInfo);
+
+ // Attempts to create the process
+ Startupinfo.dwFlags := STARTF_USESHOWWINDOW;
+ Startupinfo.wShowWindow := 1;
+ CommandLine := aProcess;
+ for x := Low(aArguments ) to High(aArguments ) do
+ CommandLine := CommandLine + ' ' + aArguments[ x ];
+ if CreateProcess( nil, PChar( CommandLine ), nil, nil, False, NORMAL_PRIORITY_CLASS, nil, nil, Startupinfo, ProcessInfo ) then
+ begin
+ // The process has been successfully created
+ // No let's wait till it ends...
+ WaitForSingleObject(ProcessInfo.hProcess, INFINITE);
+
+ // Process has finished. Now we should close it.
+ GetExitCodeProcess(ProcessInfo.hProcess, ExitCode); // Optional
+ CloseHandle(ProcessInfo.hThread);
+ CloseHandle(ProcessInfo.hProcess);
+ end;
+ {$ELSE}
+ {$IFDEF UNIX}
+ pid := fork;
+
+ if pid = 0 then
+ begin
+ Max := sysconf(_SC_OPEN_MAX);
+ for i := (STDERR_FILENO+1) to Max do
+ begin
+ fcntl(i, F_SETFD, FD_CLOEXEC);
+ end;
+
+ argnum := High(aArguments) + 1;
+
+ GetMem(parg,(2 + argnum) * sizeof(PChar));
+ parg[0] := PChar(aProcess);
+
+ i := 0;
+
+ while i <= high(aArguments) do
+ begin
+ inc(i);
+ parg[i] := PChar(aArguments[i-1]);
+ end;
+
+ parg[i+1] := nil;
+ execvp(PChar(aProcess),PPChar(@parg[0]));
+ halt;
+ end;
+
+ if pid > 0 then
+ begin
+ waitpid(pid,@returnvalue,0);
+ end;
+ {$ENDIF}
+ {$ENDIF}
+end;
+
+end.
+ \ No newline at end of file