source: tests/copyfile.cfa @ 3f654ec

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationjenkins-sandboxnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 3f654ec was 3f654ec, checked in by Peter A. Buhr <pabuhr@…>, 5 years ago

update copyfile idiom

  • Property mode set to 100644
File size: 1.5 KB
Line 
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
10// Created On       : Tue Jul 16 16:47:22 2019
11// Last Modified By : Peter A. Buhr
12// Last Modified On : Wed Jul 17 18:04:44 2019
13// Update Count     : 26
14//
15
16#include <fstream.hfa>
17#include <stdlib.hfa>                                                                   // new/delete
18
19int main( int argc, char * argv[] ) {
20        ifstream * in  = &stdin;                                                        // default files
21        ofstream * out = &stdout;
22        try {
23                choose ( argc ) {
24                  case 2, 3:
25                          in = new( (const char *)argv[1] );            // open input file first as output creates file
26                          if ( argc == 3 ) out = new( (const char *)argv[2] ); // only open output if input opens as output created if nonexistent
27                  case 1: ;                                     // use default files
28                  default:
29                          exit | "Usage [ input-file (default stdin) [ output-file (default stdout) ] ]";
30                } // choose
31
32                char ch;
33                *out | nlOff;                                                                   // turn off auto newline
34                *in  | nlOn;                                                                    // turn on reading newline
35
36                for () {                                                                                // read all characters
37                        *in | ch;
38                  if ( eof( *in ) ) break;                                              // eof ?
39                        *out | ch;
40                } // for
41        } finally {
42                if ( in  != &stdin  ) delete( in );                             // close file, do not delete stdin!
43                if ( out != &stdout ) delete( out );                    // close file, do not delete stdout!
44        } // try
45} // main
46
47// Local Variables: //
48// tab-width: 4 //
49// compile-command: "cfa copyfile.cfa" //
50// End: //
Note: See TracBrowser for help on using the repository browser.