Last change
on this file since 50e04cc was
3ac5fd8,
checked in by Peter A. Buhr <pabuhr@…>, 4 months ago
|
first attempt changing end-of-file to an exception
|
-
Property mode set to
100644
|
File size:
1.5 KB
|
Rev | Line | |
---|
[8d75345a] | 1 | // |
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2015 University of Waterloo |
---|
| 3 | // |
---|
| 4 | // The contents of this file are covered under the licence agreement in the |
---|
| 5 | // file "LICENCE" distributed with Cforall. |
---|
| 6 | // |
---|
| 7 | // copyfile.cfa -- |
---|
| 8 | // |
---|
| 9 | // Author : Peter A. Buhr |
---|
[6c4bd02] | 10 | // Created On : Fri Jun 19 13:44:05 2020 |
---|
[8d75345a] | 11 | // Last Modified By : Peter A. Buhr |
---|
[3ac5fd8] | 12 | // Last Modified On : Sat Aug 17 14:18:47 2024 |
---|
| 13 | // Update Count : 11 |
---|
[8d75345a] | 14 | // |
---|
| 15 | |
---|
| 16 | #include <fstream.hfa> |
---|
[6c4bd02] | 17 | #include <exception.hfa> |
---|
[8d75345a] | 18 | |
---|
| 19 | int main( int argc, char * argv[] ) { |
---|
[6c4bd02] | 20 | ifstream in = stdin; // copy default files |
---|
| 21 | ofstream out = stdout; |
---|
| 22 | |
---|
[3f654ec] | 23 | try { |
---|
[d9326ad] | 24 | choose ( argc ) { // terminate if command-line errors |
---|
[3ac5fd8] | 25 | case 3, 2: |
---|
[6c4bd02] | 26 | open( in, argv[1] ); // open input file first as output creates file |
---|
| 27 | if ( argc == 3 ) open( out, argv[2] ); // do not create output unless input opens |
---|
| 28 | case 1: ; // use default files |
---|
[d9326ad] | 29 | default: // wrong number of options |
---|
[6c4bd02] | 30 | exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; |
---|
[3f654ec] | 31 | } // choose |
---|
[874b16e] | 32 | } catch( open_failure * ex ; ex->istream == &in ) { |
---|
[6c4bd02] | 33 | exit | "Unable to open input file" | argv[1]; |
---|
[874b16e] | 34 | } catch( open_failure * ex ; ex->ostream == &out ) { |
---|
[6c4bd02] | 35 | close( in ); // optional |
---|
| 36 | exit | "Unable to open output file" | argv[2]; |
---|
| 37 | } // try |
---|
[8d75345a] | 38 | |
---|
[6c4bd02] | 39 | out | nlOff; // turn off auto newline |
---|
| 40 | in | nlOn; // turn on reading newline |
---|
[8d75345a] | 41 | |
---|
[6c4bd02] | 42 | char ch; |
---|
[3ac5fd8] | 43 | try { |
---|
| 44 | for () { // read all characters |
---|
| 45 | in | ch; |
---|
| 46 | out | ch; |
---|
| 47 | } // for |
---|
| 48 | } catch( end_of_file * ) { |
---|
| 49 | } // try |
---|
[8d75345a] | 50 | } // main |
---|
Note: See
TracBrowser
for help on using the repository browser.