]>
Commit | Line | Data |
---|---|---|
1 | /////////////////////////////////////////////////////////////////////////////// | |
2 | // Name: unix/baseunix.cpp | |
3 | // Purpose: misc stuff only used in console applications under Unix | |
4 | // Author: Vadim Zeitlin | |
5 | // Modified by: | |
6 | // Created: 23.06.2003 | |
7 | // RCS-ID: $Id$ | |
8 | // Copyright: (c) 2003 Vadim Zeitlin <vadim@wxwindows.org> | |
9 | // License: wxWindows licence | |
10 | /////////////////////////////////////////////////////////////////////////////// | |
11 | ||
12 | // ============================================================================ | |
13 | // declarations | |
14 | // ============================================================================ | |
15 | ||
16 | // ---------------------------------------------------------------------------- | |
17 | // headers | |
18 | // ---------------------------------------------------------------------------- | |
19 | ||
20 | // for compilers that support precompilation, includes "wx.h". | |
21 | #include "wx/wxprec.h" | |
22 | ||
23 | #ifdef __BORLANDC__ | |
24 | #pragma hdrstop | |
25 | #endif | |
26 | ||
27 | #ifndef WX_PRECOMP | |
28 | #include "wx/log.h" | |
29 | #include "wx/intl.h" | |
30 | #endif //WX_PRECOMP | |
31 | ||
32 | #include "wx/apptrait.h" | |
33 | #include "wx/utils.h" | |
34 | #include "wx/unix/execute.h" | |
35 | ||
36 | // for waitpid() | |
37 | #include <sys/types.h> | |
38 | #include <sys/wait.h> | |
39 | ||
40 | // ============================================================================ | |
41 | // wxConsoleAppTraits implementation | |
42 | // ============================================================================ | |
43 | ||
44 | // ---------------------------------------------------------------------------- | |
45 | // wxExecute support | |
46 | // ---------------------------------------------------------------------------- | |
47 | ||
48 | bool wxConsoleAppTraits::CreateEndProcessPipe(wxExecuteData& WXUNUSED(data)) | |
49 | { | |
50 | // nothing to do, so always ok | |
51 | return true; | |
52 | } | |
53 | ||
54 | bool | |
55 | wxConsoleAppTraits::IsWriteFDOfEndProcessPipe(wxExecuteData& WXUNUSED(data), | |
56 | int WXUNUSED(fd)) | |
57 | { | |
58 | // we don't have any pipe | |
59 | return false; | |
60 | } | |
61 | ||
62 | void | |
63 | wxConsoleAppTraits::DetachWriteFDOfEndProcessPipe(wxExecuteData& WXUNUSED(data)) | |
64 | { | |
65 | // nothing to do | |
66 | } | |
67 | ||
68 | ||
69 | int | |
70 | wxConsoleAppTraits::WaitForChild(wxExecuteData& execData) | |
71 | { | |
72 | wxASSERT_MSG( execData.flags & wxEXEC_SYNC, | |
73 | wxT("async execution not supported yet") ); | |
74 | ||
75 | int exitcode = 0; | |
76 | if ( waitpid(execData.pid, &exitcode, 0) == -1 || !WIFEXITED(exitcode) ) | |
77 | { | |
78 | wxLogSysError(_("Waiting for subprocess termination failed")); | |
79 | } | |
80 | ||
81 | return exitcode; | |
82 | } | |
83 | ||
84 | // ---------------------------------------------------------------------------- | |
85 | // misc other stuff | |
86 | // ---------------------------------------------------------------------------- | |
87 | ||
88 | // this is in mac/utils.cpp under Mac | |
89 | #if !defined(__WXMAC__) | |
90 | ||
91 | wxToolkitInfo& wxConsoleAppTraits::GetToolkitInfo() | |
92 | { | |
93 | static wxToolkitInfo info; | |
94 | int major, minor; | |
95 | ||
96 | FILE *f = popen("uname -r", "r"); | |
97 | if (f) | |
98 | { | |
99 | char buf[32]; | |
100 | size_t c = fread(buf, 1, sizeof(buf) - 1, f); | |
101 | pclose(f); | |
102 | buf[c] = '\0'; | |
103 | if ( sscanf(buf, "%d.%d", &major, &minor) != 2 ) | |
104 | { | |
105 | // unrecognized uname string format | |
106 | major = | |
107 | minor = -1; | |
108 | } | |
109 | } | |
110 | else | |
111 | { | |
112 | // failed to run uname | |
113 | major = | |
114 | minor = -1; | |
115 | } | |
116 | ||
117 | info.versionMajor = major; | |
118 | info.versionMinor = minor; | |
119 | info.name = _T("wxBase"); | |
120 | info.os = wxUNIX; | |
121 | ||
122 | return info; | |
123 | } | |
124 | ||
125 | #endif // __WXMAC__ | |
126 |