@@ -204,88 +204,86 @@ pub fn run_program(prog: &str, args: &[~str]) -> int {
204
204
* A class with a <program> field
205
205
*/
206
206
pub fn start_program ( prog : & str , args : & [ ~str ] ) -> Program {
207
- unsafe {
208
- let pipe_input = os:: pipe ( ) ;
209
- let pipe_output = os:: pipe ( ) ;
210
- let pipe_err = os:: pipe ( ) ;
211
- let pid =
212
- spawn_process ( prog, args, & None , & None ,
213
- pipe_input. in , pipe_output. out ,
214
- pipe_err. out ) ;
207
+ let pipe_input = os:: pipe ( ) ;
208
+ let pipe_output = os:: pipe ( ) ;
209
+ let pipe_err = os:: pipe ( ) ;
210
+ let pid =
211
+ spawn_process ( prog, args, & None , & None ,
212
+ pipe_input. in , pipe_output. out ,
213
+ pipe_err. out ) ;
215
214
216
- unsafe {
217
- if pid == -1 as pid_t { fail; }
218
- libc:: close ( pipe_input. in ) ;
219
- libc:: close ( pipe_output. out ) ;
220
- libc:: close ( pipe_err. out ) ;
221
- }
215
+ unsafe {
216
+ if pid == -1 as pid_t { fail; }
217
+ libc:: close ( pipe_input. in ) ;
218
+ libc:: close ( pipe_output. out ) ;
219
+ libc:: close ( pipe_err. out ) ;
220
+ }
222
221
223
- struct ProgRepr {
224
- pid : pid_t ,
225
- mut in_fd : c_int ,
226
- out_file : * libc:: FILE ,
227
- err_file : * libc:: FILE ,
228
- mut finished : bool ,
229
- }
222
+ struct ProgRepr {
223
+ pid : pid_t ,
224
+ mut in_fd : c_int ,
225
+ out_file : * libc:: FILE ,
226
+ err_file : * libc:: FILE ,
227
+ mut finished : bool ,
228
+ }
230
229
231
- fn close_repr_input ( r : & ProgRepr ) {
232
- let invalid_fd = -1i32 ;
233
- if r. in_fd != invalid_fd {
234
- unsafe {
235
- libc:: close ( r. in_fd ) ;
236
- }
237
- r. in_fd = invalid_fd;
238
- }
239
- }
240
- fn finish_repr ( r : & ProgRepr ) -> int {
241
- if r. finished { return 0 ; }
242
- r. finished = true ;
243
- close_repr_input ( r) ;
244
- return waitpid ( r. pid ) ;
245
- }
246
- fn destroy_repr ( r : & ProgRepr ) {
230
+ fn close_repr_input ( r : & ProgRepr ) {
231
+ let invalid_fd = -1i32 ;
232
+ if r. in_fd != invalid_fd {
247
233
unsafe {
248
- finish_repr ( r) ;
249
- libc:: fclose ( r. out_file ) ;
250
- libc:: fclose ( r. err_file ) ;
234
+ libc:: close ( r. in_fd ) ;
251
235
}
236
+ r. in_fd = invalid_fd;
252
237
}
253
- struct ProgRes {
254
- r : ProgRepr ,
255
- drop { destroy_repr( & self . r) ; }
238
+ }
239
+ fn finish_repr ( r : & ProgRepr ) -> int {
240
+ if r. finished { return 0 ; }
241
+ r. finished = true ;
242
+ close_repr_input ( r) ;
243
+ return waitpid ( r. pid ) ;
244
+ }
245
+ fn destroy_repr ( r : & ProgRepr ) {
246
+ unsafe {
247
+ finish_repr ( r) ;
248
+ libc:: fclose ( r. out_file ) ;
249
+ libc:: fclose ( r. err_file ) ;
256
250
}
251
+ }
252
+ struct ProgRes {
253
+ r : ProgRepr ,
254
+ drop { destroy_repr( & self . r) ; }
255
+ }
257
256
258
- fn ProgRes ( r : ProgRepr ) -> ProgRes {
259
- ProgRes {
260
- r : move r
261
- }
257
+ fn ProgRes ( r : ProgRepr ) -> ProgRes {
258
+ ProgRes {
259
+ r : move r
262
260
}
261
+ }
263
262
264
- impl ProgRes : Program {
265
- fn get_id ( ) -> pid_t { return self . r . pid ; }
266
- fn input ( ) -> io:: Writer {
267
- io:: fd_writer ( self . r . in_fd , false )
268
- }
269
- fn output ( ) -> io:: Reader {
270
- io:: FILE_reader ( self . r . out_file , false )
271
- }
272
- fn err ( ) -> io:: Reader {
273
- io:: FILE_reader ( self . r . err_file , false )
274
- }
275
- fn close_input ( ) { close_repr_input ( & self . r ) ; }
276
- fn finish ( ) -> int { finish_repr ( & self . r ) }
277
- fn destroy ( ) { destroy_repr ( & self . r ) ; }
263
+ impl ProgRes : Program {
264
+ fn get_id ( ) -> pid_t { return self . r . pid ; }
265
+ fn input ( ) -> io:: Writer {
266
+ io:: fd_writer ( self . r . in_fd , false )
278
267
}
279
- let repr = ProgRepr {
280
- pid : pid ,
281
- in_fd : pipe_input . out ,
282
- out_file : os :: fdopen ( pipe_output . in ) ,
283
- err_file : os :: fdopen ( pipe_err . in ) ,
284
- finished : false ,
285
- } ;
286
-
287
- ProgRes ( repr ) as Program
268
+ fn output ( ) -> io :: Reader {
269
+ io :: FILE_reader ( self . r . out_file , false )
270
+ }
271
+ fn err ( ) -> io :: Reader {
272
+ io :: FILE_reader ( self . r . err_file , false )
273
+ }
274
+ fn close_input ( ) { close_repr_input ( & self . r ) ; }
275
+ fn finish ( ) -> int { finish_repr ( & self . r ) }
276
+ fn destroy ( ) { destroy_repr ( & self . r ) ; }
288
277
}
278
+ let repr = ProgRepr {
279
+ pid : pid,
280
+ in_fd : pipe_input. out ,
281
+ out_file : os:: fdopen ( pipe_output. in ) ,
282
+ err_file : os:: fdopen ( pipe_err. in ) ,
283
+ finished : false ,
284
+ } ;
285
+
286
+ ProgRes ( repr) as Program
289
287
}
290
288
291
289
fn read_all ( rd : io:: Reader ) -> ~str {
0 commit comments