// // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo // // The contents of this file are covered under the licence agreement in the // file "LICENCE" distributed with Cforall. // // copyfile.cfa -- // // Author : Peter A. Buhr // Created On : Fri Jun 19 13:44:05 2020 // Last Modified By : Peter A. Buhr // Last Modified On : Sat Aug 17 14:18:47 2024 // Update Count : 11 // #include #include int main( int argc, char * argv[] ) { ifstream in = stdin; // copy default files ofstream out = stdout; try { choose ( argc ) { // terminate if command-line errors case 3, 2: open( in, argv[1] ); // open input file first as output creates file if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens case 1: ; // use default files default: // wrong number of options exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; } // choose } catch( open_failure * ex ; ex->istream == &in ) { exit | "Unable to open input file" | argv[1]; } catch( open_failure * ex ; ex->ostream == &out ) { close( in ); // optional exit | "Unable to open output file" | argv[2]; } // try out | nlOff; // turn off auto newline in | nlOn; // turn on reading newline char ch; try { for () { // read all characters in | ch; out | ch; } // for } catch( end_of_file * ) { } // try } // main