Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • tests/copyfile.cfa

    r3f654ec r8d75345a  
    1010// Created On       : Tue Jul 16 16:47:22 2019
    1111// Last Modified By : Peter A. Buhr
    12 // Last Modified On : Wed Jul 17 18:04:44 2019
    13 // Update Count     : 26
     12// Last Modified On : Tue Jul 16 16:48:16 2019
     13// Update Count     : 1
    1414//
    1515
    1616#include <fstream.hfa>
    17 #include <stdlib.hfa>                                                                   // new/delete
    1817
    1918int 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
     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
    3130
    32                 char ch;
    33                 *out | nlOff;                                                                   // turn off auto newline
    34                 *in  | nlOn;                                                                    // turn on reading newline
     31        char ch;
     32        out | nlOff;                                    // turn off auto newline
     33        in  | nlOn;                                     // turn on reading newline
    3534
    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
     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
    4544} // main
    4645
Note: See TracChangeset for help on using the changeset viewer.