source: tests/.in/copyfile.txt @ 8e87f37

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

new stream test to copy input file to output file

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