Mercurial > hg > octave-lyh
annotate src/oct-procbuf.cc @ 14553:aacb604ca2b6
Clean generated fortran files.
* libcruft/Makefile.am (nodist_libcruft_la_SOURCES): New variable.
(DISTCLEANFILES): Include $(nodist_libcruft_la_SOURCES) in the list.
* libcruft/slatec-fn/module.mk (nodist_libcruft_la_SOURCES):
Append derfc.f and erfc.f here.
(libcruft_la_SOURCES): Not here.
author | Mike Miller <mtmiller@ieee.org> |
---|---|
date | Wed, 11 Apr 2012 23:12:43 -0400 |
parents | 72c96de7a403 |
children |
rev | line source |
---|---|
2094 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2094 | 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. | |
2094 | 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/>. | |
2094 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
27 #include <cerrno> | |
28 | |
3503 | 29 #include <iostream> |
2094 | 30 |
31 #include <sys/types.h> | |
32 #include <unistd.h> | |
33 | |
3174 | 34 #include "lo-mappers.h" |
35 #include "lo-utils.h" | |
2094 | 36 #include "oct-procbuf.h" |
5453 | 37 #include "oct-syscalls.h" |
6726 | 38 #include "sysdep.h" |
3176 | 39 #include "variables.h" |
2094 | 40 |
3174 | 41 #include "defun.h" |
42 #include "gripes.h" | |
3308 | 43 #include "utils.h" |
3174 | 44 |
2094 | 45 // This class is based on the procbuf class from libg++, written by |
46 // Per Bothner, Copyright (C) 1993 Free Software Foundation. | |
47 | |
48 static octave_procbuf *octave_procbuf_list = 0; | |
49 | |
6094 | 50 #ifndef BUFSIZ |
51 #define BUFSIZ 1024 | |
52 #endif | |
53 | |
2094 | 54 octave_procbuf * |
55 octave_procbuf::open (const char *command, int mode) | |
56 { | |
6096 | 57 #if defined (__CYGWIN__) || defined (__MINGW32__) || defined (_MSC_VER) |
4472 | 58 |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
59 if (is_open ()) |
4472 | 60 return 0; |
61 | |
6726 | 62 f = octave_popen (command, (mode & std::ios::in) ? "r" : "w"); |
4472 | 63 |
64 if (! f) | |
65 return 0; | |
66 | |
67 // Oops... popen doesn't return the associated pid, so fake it for now | |
68 | |
69 proc_pid = 1; | |
70 | |
71 open_p = true; | |
72 | |
73 if (mode & std::ios::out) | |
6094 | 74 ::setvbuf (f, 0, _IOLBF, BUFSIZ); |
4472 | 75 |
76 return this; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
77 |
4472 | 78 #elif defined (HAVE_SYS_WAIT_H) |
2094 | 79 |
80 int pipe_fds[2]; | |
81 | |
3544 | 82 volatile int child_std_end = (mode & std::ios::in) ? 1 : 0; |
3156 | 83 |
3147 | 84 volatile int parent_end, child_end; |
2094 | 85 |
86 if (is_open ()) | |
87 return 0; | |
88 | |
89 if (pipe (pipe_fds) < 0) | |
90 return 0; | |
91 | |
3544 | 92 if (mode & std::ios::in) |
2094 | 93 { |
94 parent_end = pipe_fds[0]; | |
95 child_end = pipe_fds[1]; | |
96 } | |
97 else | |
98 { | |
99 parent_end = pipe_fds[1]; | |
100 child_end = pipe_fds[0]; | |
101 } | |
102 | |
3156 | 103 proc_pid = ::fork (); |
2094 | 104 |
105 if (proc_pid == 0) | |
106 { | |
10411 | 107 gnulib::close (parent_end); |
2094 | 108 |
109 if (child_end != child_std_end) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
110 { |
10411 | 111 gnulib::dup2 (child_end, child_std_end); |
112 gnulib::close (child_end); | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
113 } |
2094 | 114 |
115 while (octave_procbuf_list) | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
116 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
117 FILE *fp = octave_procbuf_list->f; |
3644 | 118 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
119 if (fp) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
120 { |
10411 | 121 gnulib::fclose (fp); |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
122 fp = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
123 } |
3644 | 124 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
125 octave_procbuf_list = octave_procbuf_list->next; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
126 } |
2094 | 127 |
5510 | 128 execl ("/bin/sh", "sh", "-c", command, static_cast<void *> (0)); |
2094 | 129 |
130 exit (127); | |
131 } | |
132 | |
10411 | 133 gnulib::close (child_end); |
2094 | 134 |
135 if (proc_pid < 0) | |
136 { | |
10411 | 137 gnulib::close (parent_end); |
2094 | 138 return 0; |
139 } | |
140 | |
3632 | 141 f = ::fdopen (parent_end, (mode & std::ios::in) ? "r" : "w"); |
3631 | 142 |
3649 | 143 if (mode & std::ios::out) |
6094 | 144 ::setvbuf (f, 0, _IOLBF, BUFSIZ); |
3649 | 145 |
3631 | 146 open_p = true; |
2094 | 147 |
148 next = octave_procbuf_list; | |
149 octave_procbuf_list = this; | |
150 | |
151 return this; | |
152 | |
153 #else | |
154 | |
155 return 0; | |
156 | |
157 #endif | |
158 } | |
159 | |
3631 | 160 octave_procbuf * |
161 octave_procbuf::close (void) | |
2094 | 162 { |
6096 | 163 #if defined (__CYGWIN__) || defined (__MINGW32__) || defined (_MSC_VER) |
4472 | 164 |
165 if (f) | |
166 { | |
6726 | 167 wstatus = octave_pclose (f); |
4472 | 168 f = 0; |
169 } | |
170 | |
171 open_p = false; | |
172 | |
173 return this; | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
174 |
4472 | 175 #elif defined (HAVE_SYS_WAIT_H) |
2094 | 176 |
3644 | 177 if (f) |
178 { | |
179 pid_t wait_pid; | |
2094 | 180 |
3644 | 181 int status = -1; |
182 | |
183 for (octave_procbuf **ptr = &octave_procbuf_list; | |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
184 *ptr != 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
185 ptr = &(*ptr)->next) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
186 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
187 if (*ptr == this) |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
188 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
189 *ptr = (*ptr)->next; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
190 status = 0; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
191 break; |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
192 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
193 } |
2094 | 194 |
10411 | 195 if (status == 0 && gnulib::fclose (f) == 0) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
196 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
197 using namespace std; |
3531 | 198 |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
199 do |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
200 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
201 wait_pid = octave_syscalls::waitpid (proc_pid, &wstatus, 0); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
202 } |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
203 while (wait_pid == -1 && errno == EINTR); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10182
diff
changeset
|
204 } |
3644 | 205 |
206 f = 0; | |
3631 | 207 } |
2094 | 208 |
3631 | 209 open_p = false; |
2094 | 210 |
3631 | 211 return this; |
2094 | 212 |
213 #else | |
214 | |
3631 | 215 return 0; |
2094 | 216 |
217 #endif | |
218 } |