Changeset 6c4bd02
- Timestamp:
- Jun 19, 2020, 5:49:22 PM (4 years ago)
- Branches:
- ADT, arm-eh, ast-experimental, enum, forall-pointer-decay, jacob/cs343-translation, master, new-ast, new-ast-unique-expr, pthread-emulation, qualifiedEnum
- Children:
- a8a3485
- Parents:
- 8d321f9
- Location:
- tests
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
tests/.expect/copyfile.txt
r8d321f9 r6c4bd02 8 8 // 9 9 // Author : Peter A. Buhr 10 // Created On : Tue Jul 16 16:47:22 201910 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 1 09:10:58202013 // Update Count : 2812 // Last Modified On : Fri Jun 19 14:16:44 2020 13 // Update Count : 3 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include < stdlib.hfa> // new/delete17 #include <exception.hfa> 18 18 19 19 int main( int argc, char * argv[] ) { 20 ifstream & in = stdin; // default files 21 ofstream & out = stdout; 20 ifstream in = stdin; // copy default files 21 ofstream out = stdout; 22 22 23 try { 23 24 choose ( argc ) { 25 char ch; 24 26 case 2, 3: 25 &in = new( (const char *)argv[1] );// open input file first as output creates file26 if ( argc == 3 ) &out = new( (const char *)argv[2] ); // only open output if input opens as output created if nonexistent27 case 1: ; // use default files27 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 28 30 default: 29 exit | "Usage[ input-file (default stdin) [ output-file (default stdout) ] ]";31 exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; 30 32 } // choose 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 31 39 32 char ch; 33 out | nlOff; // turn off auto newline 34 in | nlOn; // turn on reading newline 40 out | nlOff; // turn off auto newline 41 in | nlOn; // turn on reading newline 35 42 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 43 char ch; 44 for () { // read all characters 45 in | ch; 46 if ( eof( in ) ) break; // eof ? 47 out | ch; 48 } //for 45 49 } // main 46 50 -
tests/.in/copyfile.txt
r8d321f9 r6c4bd02 8 8 // 9 9 // Author : Peter A. Buhr 10 // Created On : Tue Jul 16 16:47:22 201910 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 1 09:10:58202013 // Update Count : 2812 // Last Modified On : Fri Jun 19 14:16:44 2020 13 // Update Count : 3 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include < stdlib.hfa> // new/delete17 #include <exception.hfa> 18 18 19 19 int main( int argc, char * argv[] ) { 20 ifstream & in = stdin; // default files 21 ofstream & out = stdout; 20 ifstream in = stdin; // copy default files 21 ofstream out = stdout; 22 22 23 try { 23 24 choose ( argc ) { 25 char ch; 24 26 case 2, 3: 25 &in = new( (const char *)argv[1] );// open input file first as output creates file26 if ( argc == 3 ) &out = new( (const char *)argv[2] ); // only open output if input opens as output created if nonexistent27 case 1: ; // use default files27 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 28 30 default: 29 exit | "Usage[ input-file (default stdin) [ output-file (default stdout) ] ]";31 exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; 30 32 } // choose 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 31 39 32 char ch; 33 out | nlOff; // turn off auto newline 34 in | nlOn; // turn on reading newline 40 out | nlOff; // turn off auto newline 41 in | nlOn; // turn on reading newline 35 42 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 43 char ch; 44 for () { // read all characters 45 in | ch; 46 if ( eof( in ) ) break; // eof ? 47 out | ch; 48 } //for 45 49 } // main 46 50 -
tests/copyfile.cfa
r8d321f9 r6c4bd02 8 8 // 9 9 // Author : Peter A. Buhr 10 // Created On : Tue Jul 16 16:47:22 201910 // Created On : Fri Jun 19 13:44:05 2020 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Mon Jun 1 09:10:58202013 // Update Count : 2812 // Last Modified On : Fri Jun 19 14:16:44 2020 13 // Update Count : 3 14 14 // 15 15 16 16 #include <fstream.hfa> 17 #include < stdlib.hfa> // new/delete17 #include <exception.hfa> 18 18 19 19 int main( int argc, char * argv[] ) { 20 ifstream & in = stdin; // default files 21 ofstream & out = stdout; 20 ifstream in = stdin; // copy default files 21 ofstream out = stdout; 22 22 23 try { 23 24 choose ( argc ) { 25 char ch; 24 26 case 2, 3: 25 &in = new( (const char *)argv[1] );// open input file first as output creates file26 if ( argc == 3 ) &out = new( (const char *)argv[2] ); // only open output if input opens as output created if nonexistent27 case 1: ; // use default files27 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 28 30 default: 29 exit | "Usage[ input-file (default stdin) [ output-file (default stdout) ] ]";31 exit | "Usage" | argv[0] | "[ input-file (default stdin) [ output-file (default stdout) ] ]"; 30 32 } // choose 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 31 39 32 char ch; 33 out | nlOff; // turn off auto newline 34 in | nlOn; // turn on reading newline 40 out | nlOff; // turn off auto newline 41 in | nlOn; // turn on reading newline 35 42 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 43 char ch; 44 for () { // read all characters 45 in | ch; 46 if ( eof( in ) ) break; // eof ? 47 out | ch; 48 } //for 45 49 } // main 46 50
Note: See TracChangeset
for help on using the changeset viewer.