// // 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 : Tue Jul 16 16:47:22 2019 // Last Modified By : Peter A. Buhr // Last Modified On : Wed Jul 17 18:04:44 2019 // Update Count : 26 // #include #include // new/delete int main( int argc, char * argv[] ) { ifstream * in = &stdin; // default files ofstream * out = &stdout; try { choose ( argc ) { case 2, 3: in = new( (const char *)argv[1] ); // open input file first as output creates file if ( argc == 3 ) out = new( (const char *)argv[2] ); // only open output if input opens as output created if nonexistent case 1: ; // use default files default: exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]"; } // choose char ch; *out | nlOff; // turn off auto newline *in | nlOn; // turn on reading newline for () { // read all characters *in | ch; if ( eof( *in ) ) break; // eof ? *out | ch; } // for } finally { if ( in != &stdin ) delete( in ); // close file, do not delete stdin! if ( out != &stdout ) delete( out ); // close file, do not delete stdout! } // try } // main // Local Variables: // // tab-width: 4 // // compile-command: "cfa copyfile.cfa" // // End: //