Mercurial > octave-nkf
annotate liboctave/system/lo-sysdep.cc @ 19898:17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
* gl-select.cc, betainc.cc, bitfcns.cc, bsxfun.cc, gl-render.cc,
graphics.cc, load-save.cc, ls-mat-ascii.cc, ls-mat5.cc, lu.cc,
oct-stream.cc, symtab.cc, variables.cc, __eigs__.cc,
__magick_read__.cc, chol.cc, ov-base-sparse.cc, ov-class.cc,
ov-classdef.cc, ov-fcn-inline.cc, ov-perm.cc, ov.cc, CMatrix.cc,
CSparse.cc, MSparse.cc, MatrixType.cc, MatrixType.h, dMatrix.cc,
dSparse.cc, fCMatrix.cc, fMatrix.cc, eigs-base.cc, lo-sysdep.cc,
kpse.cc: Break long lines before && and ||.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 26 Feb 2015 13:07:04 -0500 |
parents | 4197fc428c7d |
children |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
19731
4197fc428c7d
maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents:
17769
diff
changeset
|
3 Copyright (C) 1996-2015 John W. Eaton |
2926 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2926 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2926 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
3503 | 27 #include <iostream> |
2926 | 28 #include <string> |
6321 | 29 #include <vector> |
2926 | 30 |
31 #include <sys/types.h> | |
32 #include <unistd.h> | |
33 | |
6321 | 34 #include <fcntl.h> |
35 | |
7695
eacf87a24f55
lo-sysdep.cc: include windows.h if windows and not cygwin
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
36 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
10346
65d5776379c3
Reduce the amount of stuff included by windows.h and avoid min/max being #define-d
Michael Goffioul <michael.goffioul@gmail.com>
parents:
10314
diff
changeset
|
37 #define WIN32_LEAN_AND_MEAN |
7695
eacf87a24f55
lo-sysdep.cc: include windows.h if windows and not cygwin
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
38 #include <windows.h> |
eacf87a24f55
lo-sysdep.cc: include windows.h if windows and not cygwin
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
39 #endif |
eacf87a24f55
lo-sysdep.cc: include windows.h if windows and not cygwin
John W. Eaton <jwe@octave.org>
parents:
7017
diff
changeset
|
40 |
5872 | 41 #include "file-ops.h" |
3069 | 42 #include "lo-error.h" |
2926 | 43 #include "pathlen.h" |
6123 | 44 #include "lo-sysdep.h" |
6321 | 45 #include "str-vec.h" |
8377
25bc2d31e1bf
improve OCTAVE_LOCAL_BUFFER
Jaroslav Hajek <highegg@gmail.com>
parents:
7732
diff
changeset
|
46 #include "oct-locbuf.h" |
2926 | 47 |
3504 | 48 std::string |
2926 | 49 octave_getcwd (void) |
50 { | |
3504 | 51 std::string retval; |
3069 | 52 |
10250 | 53 // Using the gnulib getcwd module ensures that we have a getcwd that |
54 // will allocate a buffer as large as necessary if buf and size are | |
55 // both 0. | |
3069 | 56 |
10411 | 57 char *tmp = gnulib::getcwd (0, 0); |
2926 | 58 |
59 if (tmp) | |
10250 | 60 { |
61 retval = tmp; | |
62 free (tmp); | |
63 } | |
3069 | 64 else |
65 (*current_liboctave_error_handler) ("unable to find current directory"); | |
2926 | 66 |
67 return retval; | |
68 } | |
69 | |
70 int | |
5872 | 71 octave_chdir (const std::string& path_arg) |
2926 | 72 { |
5872 | 73 std::string path = file_ops::tilde_expand (path_arg); |
74 | |
6244 | 75 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14155
diff
changeset
|
76 if (path.length () == 2 && path[1] == ':') |
6244 | 77 path += "\\"; |
78 #endif | |
79 | |
14152
933bf1b4ab29
* lo-sysdep.cc (octave_chdir): Use gnulib::chdir.
John W. Eaton <jwe@octave.org>
parents:
14138
diff
changeset
|
80 return gnulib::chdir (path.c_str ()); |
2926 | 81 } |
82 | |
6321 | 83 #if defined (__WIN32__) && ! defined (__CYGWIN__) |
84 | |
85 pid_t | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
86 octave_popen2 (const std::string& cmd, const string_vector& args, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
87 bool sync_mode, |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
88 int *fildes, std::string& msg) |
6321 | 89 { |
90 pid_t pid; | |
91 PROCESS_INFORMATION pi; | |
92 STARTUPINFO si; | |
93 std::string command = "\"" + cmd + "\""; | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
94 HANDLE hProcess = GetCurrentProcess (); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
95 HANDLE childRead, childWrite, parentRead, parentWrite; |
6321 | 96 DWORD pipeMode; |
97 | |
98 ZeroMemory (&pi, sizeof (pi)); | |
99 ZeroMemory (&si, sizeof (si)); | |
100 si.cb = sizeof (si); | |
101 | |
19898
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
102 if (! CreatePipe (&childRead, &parentWrite, 0, 0) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
103 || ! DuplicateHandle (hProcess, childRead, hProcess, &childRead, |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
104 0, TRUE, |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
105 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) |
6321 | 106 { |
107 msg = "popen2: pipe creation failed"; | |
108 return -1; | |
109 } | |
19898
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
110 if (! CreatePipe (&parentRead, &childWrite, 0, 0) |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
111 || ! DuplicateHandle (hProcess, childWrite, hProcess, &childWrite, |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
112 0, TRUE, |
17d647821d61
maint: More cleanup of C++ code to follow Octave coding conventions.
John W. Eaton <jwe@octave.org>
parents:
19731
diff
changeset
|
113 DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) |
6321 | 114 { |
115 msg = "popen2: pipe creation failed"; | |
116 return -1; | |
117 } | |
118 if (! sync_mode) | |
119 { | |
120 pipeMode = PIPE_NOWAIT; | |
121 SetNamedPipeHandleState (parentRead, &pipeMode, 0, 0); | |
122 } | |
17769
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
123 fildes[1] = _open_osfhandle (reinterpret_cast<intptr_t> (parentRead), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
124 _O_RDONLY | _O_BINARY); |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
125 fildes[0] = _open_osfhandle (reinterpret_cast<intptr_t> (parentWrite), |
49a5a4be04a1
maint: Use GNU style coding conventions for code in liboctave/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
126 _O_WRONLY | _O_BINARY); |
6321 | 127 si.dwFlags |= STARTF_USESTDHANDLES; |
128 si.hStdInput = childRead; | |
129 si.hStdOutput = childWrite; | |
130 | |
131 // Ignore first arg as it is the command | |
14846
460a3c6d8bf1
maint: Use Octave coding convention for cuddled parenthis in function calls with empty argument lists.
Rik <octave@nomad.inbox5.com>
parents:
14155
diff
changeset
|
132 for (int k=1; k<args.length (); k++) |
6321 | 133 command += " \"" + args[k] + "\""; |
134 OCTAVE_LOCAL_BUFFER (char, c_command, command.length () + 1); | |
135 strcpy (c_command, command.c_str ()); | |
136 if (! CreateProcess (0, c_command, 0, 0, TRUE, 0, 0, 0, &si, &pi)) | |
137 { | |
138 msg = "popen2: process creation failed"; | |
139 return -1; | |
140 } | |
141 pid = pi.dwProcessId; | |
142 | |
143 CloseHandle (childRead); | |
144 CloseHandle (childWrite); | |
145 CloseHandle (pi.hProcess); | |
146 CloseHandle (pi.hThread); | |
147 | |
148 return pid; | |
149 } | |
150 | |
151 #endif |