1
|
1 // procstream.cc -*- C++ -*- |
|
2 /* |
|
3 |
1884
|
4 Copyright (C) 1996 John W. Eaton |
1
|
5 |
|
6 This file is part of Octave. |
|
7 |
|
8 Octave is free software; you can redistribute it and/or modify it |
|
9 under the terms of the GNU General Public License as published by the |
|
10 Free Software Foundation; either version 2, or (at your option) any |
|
11 later version. |
|
12 |
|
13 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
16 for more details. |
|
17 |
|
18 You should have received a copy of the GNU General Public License |
|
19 along with Octave; see the file COPYING. If not, write to the Free |
1315
|
20 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
1
|
21 |
|
22 */ |
|
23 |
1297
|
24 #if defined (__GNUG__) |
|
25 #pragma implementation |
|
26 #endif |
|
27 |
240
|
28 #ifdef HAVE_CONFIG_H |
1192
|
29 #include <config.h> |
1
|
30 #endif |
|
31 |
1380
|
32 #include <fstream.h> |
|
33 #include <procbuf.h> |
|
34 |
1
|
35 #include "procstream.h" |
|
36 |
1380
|
37 iprocstream::iprocstream (const char *command, int mode) |
1
|
38 { |
1380
|
39 pbuf = new procbuf (); |
|
40 |
|
41 init (pbuf); |
|
42 |
|
43 if (! pbuf->open (command, mode)) |
1
|
44 set (ios::badbit); |
|
45 } |
|
46 |
1380
|
47 iprocstream::~iprocstream (void) |
|
48 { |
1448
|
49 delete pbuf; |
1380
|
50 } |
|
51 |
1
|
52 void |
1380
|
53 iprocstream::open (const char *command, int mode) |
1
|
54 { |
|
55 clear (); |
1380
|
56 |
1448
|
57 if (pbuf) |
|
58 delete pbuf; |
|
59 |
|
60 pbuf = new procbuf (); |
|
61 |
|
62 init (pbuf); |
1380
|
63 |
|
64 if (! pbuf->open (command, mode)) |
1
|
65 set (ios::badbit); |
|
66 } |
|
67 |
483
|
68 int |
1380
|
69 iprocstream::is_open (void) |
|
70 { |
|
71 return pbuf && pbuf->is_open (); |
|
72 } |
|
73 |
|
74 int |
|
75 iprocstream::close (void) |
|
76 { |
|
77 int status = 0; |
|
78 |
|
79 if (is_open ()) |
|
80 { |
|
81 status = pbuf->sys_close (); |
|
82 |
|
83 if (! pbuf->close ()) |
|
84 set (ios::failbit); |
|
85 } |
|
86 |
|
87 return status; |
|
88 } |
|
89 |
1448
|
90 void |
|
91 cleanup_iprocstream (void *buf) |
1380
|
92 { |
1448
|
93 delete (iprocstream *) buf; |
1380
|
94 } |
|
95 |
|
96 oprocstream::oprocstream (const char *command, int mode) |
1
|
97 { |
1380
|
98 pbuf = new procbuf (); |
|
99 |
|
100 init (pbuf); |
|
101 |
|
102 if (! pbuf->open (command, mode)) |
|
103 set (ios::badbit); |
|
104 } |
|
105 |
|
106 oprocstream::~oprocstream (void) |
|
107 { |
1448
|
108 delete pbuf; |
1380
|
109 } |
|
110 |
|
111 void |
|
112 oprocstream::open (const char *command, int mode) |
|
113 { |
|
114 clear (); |
|
115 |
1448
|
116 if (pbuf) |
|
117 delete pbuf; |
|
118 |
|
119 pbuf = new procbuf (); |
|
120 |
|
121 init (pbuf); |
1380
|
122 |
|
123 if (! pbuf->open (command, mode)) |
|
124 set (ios::badbit); |
|
125 } |
|
126 |
|
127 int |
|
128 oprocstream::is_open (void) |
|
129 { |
|
130 return pbuf && pbuf->is_open (); |
|
131 } |
|
132 |
|
133 int |
|
134 oprocstream::close (void) |
|
135 { |
|
136 int status = 0; |
|
137 |
|
138 if (is_open ()) |
|
139 { |
|
140 if (! pbuf->close ()) |
|
141 set (ios::failbit); |
|
142 } |
|
143 |
483
|
144 return status; |
1
|
145 } |
|
146 |
1448
|
147 void |
|
148 cleanup_oprocstream (void *buf) |
|
149 { |
|
150 delete (oprocstream *) buf; |
|
151 } |
|
152 |
1
|
153 /* |
|
154 ;;; Local Variables: *** |
|
155 ;;; mode: C++ *** |
|
156 ;;; page-delimiter: "^/\\*" *** |
|
157 ;;; End: *** |
|
158 */ |