// Copyright (c) 2005-2007 Andre Merzky (andre@merzky.net) // // Distributed under the Boost Software License, Version 1.0. (See accompanying // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) #include "shell.hpp" // open a file, and read chunks of data until we reach EOF, // printing the data found to stdout void shell::c_cat (std::string args) { // sanity checks if ( ! cwd_.exists (args) ) { carp ("No such file: " + args); return; } if ( cwd_.is_dir (args) ) { carp ("Cannot cat directory: " + args); return; } // open the file saga::file file = cwd_.open (args, saga::file::Read); while ( true ) { int const n = 10; char data[n]; for ( int i = 0; i <= n; ++i ) { data[i] = '\0'; } // read a chunk into the buffer if ( file.read (saga::buffer (data)) ) { // show what we found std::cout << data; } else { break; } } // file closes when going out of scope return; }