Mercurial > hg > octave-lyh
annotate liboctave/lo-sysdep.cc @ 14294:9e3983c8963c
deprecate the static keyword
* octave.gperf: Use PERSISTENT as the token for "static" and
"persistent" but use separate static_kw and persistent_kw values so we
can distinguish them.
* lex.ll (is_keyword_token): Handle static_kw and persistent_kw
separately. Generate deprecated keyword warning for static_kw.
* oct-parse.cc: Use PERSISTENT token instead of STATIC.
* pt-decl.h, pt-decl.cc (tree_persistent_command): Rename from
tree_static_command. Change all uses.
* pt-walk.h (tree_walker::visit_persistent_command):
Rename from visit_static_command. Change all derived classes.
* NEWS: note that static has been deprecated.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 30 Jan 2012 23:42:41 -0500 |
parents | 583d3d6f6fde |
children | 460a3c6d8bf1 |
rev | line source |
---|---|
2926 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
12223
diff
changeset
|
3 Copyright (C) 1996-2012 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__) |
76 if (path.length() == 2 && path[1] == ':') | |
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 | |
86 octave_popen2 (const std::string& cmd, const string_vector& args, bool sync_mode, | |
87 int *fildes, std::string& msg) | |
88 { | |
89 pid_t pid; | |
90 PROCESS_INFORMATION pi; | |
91 STARTUPINFO si; | |
92 std::string command = "\"" + cmd + "\""; | |
93 HANDLE hProcess = GetCurrentProcess(), childRead, childWrite, parentRead, parentWrite; | |
94 DWORD pipeMode; | |
95 | |
96 ZeroMemory (&pi, sizeof (pi)); | |
97 ZeroMemory (&si, sizeof (si)); | |
98 si.cb = sizeof (si); | |
99 | |
100 if (! CreatePipe (&childRead, &parentWrite, 0, 0) || | |
101 ! DuplicateHandle (hProcess, childRead, hProcess, &childRead, 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) | |
102 { | |
103 msg = "popen2: pipe creation failed"; | |
104 return -1; | |
105 } | |
106 if (! CreatePipe (&parentRead, &childWrite, 0, 0) || | |
107 ! DuplicateHandle (hProcess, childWrite, hProcess, &childWrite, 0, TRUE, DUPLICATE_SAME_ACCESS | DUPLICATE_CLOSE_SOURCE)) | |
108 { | |
109 msg = "popen2: pipe creation failed"; | |
110 return -1; | |
111 } | |
112 if (! sync_mode) | |
113 { | |
114 pipeMode = PIPE_NOWAIT; | |
115 SetNamedPipeHandleState (parentRead, &pipeMode, 0, 0); | |
116 } | |
117 fildes[1] = _open_osfhandle (reinterpret_cast<long> (parentRead), _O_RDONLY | _O_BINARY); | |
118 fildes[0] = _open_osfhandle (reinterpret_cast<long> (parentWrite), _O_WRONLY | _O_BINARY); | |
119 si.dwFlags |= STARTF_USESTDHANDLES; | |
120 si.hStdInput = childRead; | |
121 si.hStdOutput = childWrite; | |
122 | |
123 // Ignore first arg as it is the command | |
124 for (int k=1; k<args.length(); k++) | |
125 command += " \"" + args[k] + "\""; | |
126 OCTAVE_LOCAL_BUFFER (char, c_command, command.length () + 1); | |
127 strcpy (c_command, command.c_str ()); | |
128 if (! CreateProcess (0, c_command, 0, 0, TRUE, 0, 0, 0, &si, &pi)) | |
129 { | |
130 msg = "popen2: process creation failed"; | |
131 return -1; | |
132 } | |
133 pid = pi.dwProcessId; | |
134 | |
135 CloseHandle (childRead); | |
136 CloseHandle (childWrite); | |
137 CloseHandle (pi.hProcess); | |
138 CloseHandle (pi.hThread); | |
139 | |
140 return pid; | |
141 } | |
142 | |
143 #endif |