source: tests/copyfile.cfa @ 6c4bd02

ADTarm-ehast-experimentalenumforall-pointer-decayjacob/cs343-translationnew-astnew-ast-unique-exprpthread-emulationqualifiedEnum
Last change on this file since 6c4bd02 was 6c4bd02, checked in by Peter A. Buhr <pabuhr@…>, 4 years ago

update idiomic Cforall command-line processing and coping input file to output file

  • Property mode set to 100644
File size: 1.5 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
[6c4bd02]10// Created On       : Fri Jun 19 13:44:05 2020
[8d75345a]11// Last Modified By : Peter A. Buhr
[6c4bd02]12// Last Modified On : Fri Jun 19 14:16:44 2020
13// Update Count     : 3
[8d75345a]14//
15
16#include <fstream.hfa>
[6c4bd02]17#include <exception.hfa>
[8d75345a]18
19int main( int argc, char * argv[] ) {
[6c4bd02]20        ifstream in  = stdin;                                                           // copy default files
21        ofstream out = stdout;
22
[3f654ec]23        try {
24                choose ( argc ) {
[6c4bd02]25                        char ch;
[3f654ec]26                  case 2, 3:
[6c4bd02]27                        open( in, argv[1] );                                            // open input file first as output creates file
28                        if ( argc == 3 ) open( out, argv[2] );          // do not create output unless input opens
29                  case 1: ;                                                                             // use default files
[3f654ec]30                  default:
[6c4bd02]31                        exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]";
[3f654ec]32                } // choose
[6c4bd02]33        } catch( Open_Failure * ex ; ex->istream == &in ) {
34                exit | "Unable to open input file" | argv[1];
35        } catch( Open_Failure * ex ; ex->ostream == &out ) {
36                close( in );                                                                    // optional
37                exit | "Unable to open output file" | argv[2];
38        } // try
[8d75345a]39
[6c4bd02]40        out | nlOff;                                                                            // turn off auto newline
41        in  | nlOn;                                                                                     // turn on reading newline
[8d75345a]42
[6c4bd02]43        char ch;
44        for () {                                                                                        // read all characters
45                in | ch;
46          if ( eof( in ) ) break;                                                       // eof ?
47                out | ch;
48        } //for
[8d75345a]49} // main
50
51// Local Variables: //
52// tab-width: 4 //
53// compile-command: "cfa copyfile.cfa" //
54// End: //
Note: See TracBrowser for help on using the repository browser.