Put io_data_t detail printing in virtual io_data_t::print

This commit is contained in:
Cheer Xiao 2013-01-09 15:49:12 +08:00
parent 89993e9cbf
commit 165068c81d
2 changed files with 25 additions and 18 deletions

41
io.cpp
View file

@ -51,6 +51,28 @@ Utilities for io redirection.
#include "io.h"
void io_data_t::print() const
{
switch (io_mode)
{
case IO_FILE:
fprintf(stderr, "file (%s)\n", filename_cstr);
break;
case IO_PIPE:
fprintf(stderr, "pipe {%d, %d}\n", param1.pipe_fd[0], param1.pipe_fd[1]);
break;
case IO_FD:
fprintf(stderr, "FD map %d -> %d\n", param1.old_fd, fd);
break;
case IO_BUFFER:
fprintf(stderr, "buffer %p (size %lu)\n", out_buffer_ptr(), out_buffer_size());
break;
case IO_CLOSE:
fprintf(stderr, "close %d\n", fd);
break;
}
}
void io_buffer_read(io_data_t *d)
{
exec_close(d->param1.pipe_fd[1]);
@ -195,24 +217,7 @@ void io_print(const io_chain_t &chain)
{
const shared_ptr<const io_data_t> &io = chain.at(i);
fprintf(stderr, "\t%lu: fd:%d, input:%s, ", (unsigned long)i, io->fd, io->is_input ? "yes" : "no");
switch (io->io_mode)
{
case IO_FILE:
fprintf(stderr, "file (%s)\n", io->filename_cstr);
break;
case IO_PIPE:
fprintf(stderr, "pipe {%d, %d}\n", io->param1.pipe_fd[0], io->param1.pipe_fd[1]);
break;
case IO_FD:
fprintf(stderr, "FD map %d -> %d\n", io->param1.old_fd, io->fd);
break;
case IO_BUFFER:
fprintf(stderr, "buffer %p (size %lu)\n", io->out_buffer_ptr(), io->out_buffer_size());
break;
case IO_CLOSE:
fprintf(stderr, "close %d\n", io->fd);
break;
}
io->print();
}
}

2
io.h
View file

@ -94,6 +94,8 @@ public:
return out_buffer->size();
}
virtual void print() const;
/** Set to true if this is an input io redirection */
bool is_input;