[5db17077] | 1 | //
|
---|
| 2 | // Cforall Version 1.0.0 Copyright (C) 2025 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 | // eofType.cfa -- Test for end-of-file with and without a terminating newline across multiple types.
|
---|
| 8 | //
|
---|
| 9 | // Author : Peter A. Buhr
|
---|
| 10 | // Created On : Wed Jan 22 07:41:41 2025
|
---|
| 11 | // Last Modified By : Peter A. Buhr
|
---|
[a750c71b] | 12 | // Last Modified On : Thu Jan 23 14:33:08 2025
|
---|
| 13 | // Update Count : 9
|
---|
[5db17077] | 14 | //
|
---|
| 15 |
|
---|
| 16 | #include <fstream.hfa> // sin/sout
|
---|
| 17 |
|
---|
[e051c8e] | 18 | void openfile( ifstream & testfile, const char * filename ) { // helper
|
---|
[5db17077] | 19 | try {
|
---|
| 20 | open( testfile, filename );
|
---|
| 21 | } catch( open_failure * ex; ex->istream == &testfile ) { // input file errors
|
---|
| 22 | exit | "Unable to open input file \"" | filename | "\"";
|
---|
| 23 | } // try
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[a9e327a] | 26 | // test.py provides macro IN_DIR, which is the absolute path to the current .in directory
|
---|
[5db17077] | 27 | #define xstr(s) str(s)
|
---|
| 28 | #define str(s) #s
|
---|
| 29 | // Add quotes around directory name.
|
---|
| 30 | #define INDIR xstr(IN_DIR)
|
---|
| 31 |
|
---|
| 32 | int main() {
|
---|
| 33 | ifstream testfile;
|
---|
| 34 | {
|
---|
[a750c71b] | 35 | char * filenames[] = { INDIR "eofType.bool.1.txt", INDIR "eofType.bool.2.txt" };
|
---|
[5db17077] | 36 | bool value;
|
---|
| 37 |
|
---|
| 38 | for ( i; 2 ) {
|
---|
| 39 | openfile( testfile, filenames[i] );
|
---|
| 40 | try {
|
---|
| 41 | for () {
|
---|
| 42 | testfile | value;
|
---|
| 43 | sout | value;
|
---|
| 44 | } // for
|
---|
| 45 | } catch( end_of_file * ) {
|
---|
| 46 | sout | "eof";
|
---|
| 47 | } // try
|
---|
| 48 | close( testfile );
|
---|
| 49 | }
|
---|
| 50 | }
|
---|
| 51 | {
|
---|
[a750c71b] | 52 | char * filenames[] = { INDIR "eofType.char.1.txt", INDIR "eofType.char.2.txt" };
|
---|
[5db17077] | 53 | char value;
|
---|
| 54 |
|
---|
| 55 | for ( i; 2 ) {
|
---|
| 56 | openfile( testfile, filenames[i] );
|
---|
| 57 | try {
|
---|
| 58 | for () {
|
---|
| 59 | testfile | value;
|
---|
| 60 | sout | value;
|
---|
| 61 | } // for
|
---|
| 62 | } catch( end_of_file * ) {
|
---|
| 63 | sout | "eof";
|
---|
| 64 | } // try
|
---|
| 65 | close( testfile );
|
---|
| 66 | }
|
---|
| 67 | }
|
---|
| 68 | {
|
---|
[a750c71b] | 69 | char * filenames[] = { INDIR "eofType.int.1.txt", INDIR "eofType.int.2.txt" };
|
---|
[5db17077] | 70 | int value;
|
---|
| 71 |
|
---|
| 72 | for ( i; 2 ) {
|
---|
| 73 | openfile( testfile, filenames[i] );
|
---|
| 74 | try {
|
---|
| 75 | for () {
|
---|
| 76 | testfile | value;
|
---|
| 77 | sout | value;
|
---|
| 78 | } // for
|
---|
| 79 | } catch( end_of_file * ) {
|
---|
| 80 | sout | "eof";
|
---|
| 81 | } // try
|
---|
| 82 | close( testfile );
|
---|
| 83 | }
|
---|
| 84 | }
|
---|
| 85 | {
|
---|
[a750c71b] | 86 | char * filenames[] = { INDIR "eofType.double.1.txt", INDIR "eofType.double.2.txt" };
|
---|
[5db17077] | 87 | double value;
|
---|
| 88 |
|
---|
| 89 | for ( i; 2 ) {
|
---|
| 90 | openfile( testfile, filenames[i] );
|
---|
| 91 | try {
|
---|
| 92 | for () {
|
---|
| 93 | testfile | value;
|
---|
| 94 | sout | value;
|
---|
| 95 | } // for
|
---|
| 96 | } catch( end_of_file * ) {
|
---|
| 97 | sout | "eof";
|
---|
| 98 | } // try
|
---|
| 99 | close( testfile );
|
---|
| 100 | }
|
---|
| 101 | }
|
---|
| 102 | {
|
---|
[a750c71b] | 103 | char * filenames[] = { INDIR "eofType.complex.1.txt", INDIR "eofType.complex.2.txt" };
|
---|
[5db17077] | 104 | _Complex value;
|
---|
| 105 |
|
---|
| 106 | for ( i; 2 ) {
|
---|
| 107 | openfile( testfile, filenames[i] );
|
---|
| 108 | try {
|
---|
| 109 | for () {
|
---|
| 110 | testfile | value;
|
---|
| 111 | sout | value;
|
---|
| 112 | } // for
|
---|
| 113 | } catch( end_of_file * ) {
|
---|
| 114 | sout | "eof";
|
---|
| 115 | } // try
|
---|
| 116 | close( testfile );
|
---|
| 117 | }
|
---|
| 118 | }
|
---|
[a9e327a] | 119 | } // main
|
---|