]> de.git.xonotic.org Git - xonotic/netradiant.git/blob - libs/cmdlib/cmdlib.cpp
remove RSA's md4.c, replace by DP's
[xonotic/netradiant.git] / libs / cmdlib / cmdlib.cpp
1 /*
2 Copyright (C) 1999-2006 Id Software, Inc. and contributors.
3 For a list of contributors, see the accompanying CONTRIBUTORS file.
4
5 This file is part of GtkRadiant.
6
7 GtkRadiant is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
11
12 GtkRadiant is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 GNU General Public License for more details.
16
17 You should have received a copy of the GNU General Public License
18 along with GtkRadiant; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20 */
21
22 //
23 // start of shared cmdlib stuff
24 // 
25
26 #include "cmdlib.h"
27
28 #include <string.h>
29 #include <stdio.h>
30
31 #include "string/string.h"
32 #include "os/path.h"
33 #include "container/array.h"
34
35
36 #if defined (POSIX)
37
38 #include <unistd.h>
39
40 bool Q_Exec(const char *cmd, char *cmdline, const char *, bool)
41 {
42   char fullcmd[2048];
43   char *pCmd;
44 #ifdef _DEBUG
45   printf("Q_Exec damnit\n");
46 #endif
47   switch (fork())
48   {
49   case -1:
50     return true;
51     break;
52   case 0:
53     // always concat the command on linux
54     if (cmd)
55     {
56       strcpy(fullcmd, cmd);
57     }
58     else
59       fullcmd[0] = '\0';
60     if (cmdline)
61     {
62       strcat(fullcmd, " ");
63       strcat(fullcmd, cmdline);
64     }
65     pCmd = fullcmd;
66     while (*pCmd == ' ')
67       pCmd++;
68 #ifdef _DEBUG
69     printf("Running system...\n");
70     printf("Command: %s\n", pCmd);
71 #endif
72     system( pCmd );
73 #ifdef _DEBUG
74     printf ("system() returned\n");
75 #endif
76     _exit (0);
77     break;
78   }
79   return true;
80 }
81
82 #elif defined(WIN32)
83
84 #include <windows.h>
85
86 // NOTE TTimo windows is VERY nitpicky about the syntax in CreateProcess
87 bool Q_Exec(const char *cmd, char *cmdline, const char *execdir, bool bCreateConsole)
88 {
89   PROCESS_INFORMATION ProcessInformation;
90   STARTUPINFO startupinfo = {0};
91   DWORD dwCreationFlags;
92   GetStartupInfo (&startupinfo);
93   if (bCreateConsole)
94     dwCreationFlags = CREATE_NEW_CONSOLE | NORMAL_PRIORITY_CLASS;
95   else
96     dwCreationFlags = DETACHED_PROCESS | NORMAL_PRIORITY_CLASS;
97   const char *pCmd;
98   char *pCmdline;
99   pCmd = cmd;
100   if (pCmd)
101   {
102     while (*pCmd == ' ')
103       pCmd++;
104   }
105   pCmdline = cmdline;
106   if (pCmdline)
107   {
108     while (*pCmdline == ' ')
109       pCmdline++;
110   }
111
112   if (CreateProcess(
113                     pCmd,
114                     pCmdline,
115                     NULL,
116                     NULL,
117                     FALSE,
118                     dwCreationFlags,
119                     NULL,
120                     execdir,
121                     &startupinfo,
122                     &ProcessInformation
123                     ))
124     return true;
125   return false;
126 }
127
128 #endif
129