- Timestamp:
- Oct 1, 2021, 8:22:31 AM (3 years ago)
- Branches:
- ADT, ast-experimental, enum, forall-pointer-decay, master, pthread-emulation, qualifiedEnum
- Children:
- 96f01d7f
- Parents:
- 056cbdb
- Location:
- libcfa/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r056cbdb r7ce2483 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Tue Sep 21 21:51:38202113 // Update Count : 4 6012 // Last Modified On : Fri Oct 1 08:10:21 2021 13 // Update Count : 473 14 14 // 15 15 … … 28 28 #define IO_MSG "I/O error: " 29 29 30 void ?{}( ofstream & os, void * file ) with(os) { 30 // private 31 void ?{}( ofstream & os, void * file ) with( os ) { 31 32 file$ = file; 32 33 sepDefault$ = true; … … 41 42 } // ?{} 42 43 43 // private 44 bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; } 45 void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; } 46 void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; } 47 const char * sepGetCur$( ofstream & os ) { return os.sepCur$; } 48 void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; } 49 bool getNL$( ofstream & os ) { return os.sawNL$; } 50 void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; } 51 bool getANL$( ofstream & os ) { return os.nlOnOff$; } 52 bool getPrt$( ofstream & os ) { return os.prt$; } 53 void setPrt$( ofstream & os, bool state ) { os.prt$ = state; } 44 inline bool sepPrt$( ofstream & os ) { setNL$( os, false ); return os.sepOnOff$; } 45 inline void sepReset$( ofstream & os ) { os.sepOnOff$ = os.sepDefault$; } 46 inline void sepReset$( ofstream & os, bool reset ) { os.sepDefault$ = reset; os.sepOnOff$ = os.sepDefault$; } 47 inline const char * sepGetCur$( ofstream & os ) { return os.sepCur$; } 48 inline void sepSetCur$( ofstream & os, const char sepCur[] ) { os.sepCur$ = sepCur; } 49 inline bool getNL$( ofstream & os ) { return os.sawNL$; } 50 inline void setNL$( ofstream & os, bool state ) { os.sawNL$ = state; } 51 inline bool getANL$( ofstream & os ) { return os.nlOnOff$; } 52 inline bool getPrt$( ofstream & os ) { return os.prt$; } 53 inline void setPrt$( ofstream & os, bool state ) { os.prt$ = state; } 54 55 inline void lock( ofstream & os ) with( os ) { lock( os.lock$ ); } 56 inline void unlock( ofstream & os ) { unlock( os.lock$ ); } 54 57 55 58 // public 56 59 void ?{}( ofstream & os ) { os.file$ = 0p; } 57 58 void ?{}( ofstream & os, const char name[], const char mode[] ) { 59 open( os, name, mode ); 60 } // ?{} 61 62 void ?{}( ofstream & os, const char name[] ) { 63 open( os, name, "w" ); 64 } // ?{} 65 66 void ^?{}( ofstream & os ) { 67 close( os ); 68 } // ^?{} 60 void ?{}( ofstream & os, const char name[], const char mode[] ) { open( os, name, mode ); } 61 void ?{}( ofstream & os, const char name[] ) { open( os, name, "w" ); } 62 void ^?{}( ofstream & os ) { close( os ); } 69 63 70 64 void sepOn( ofstream & os ) { os.sepOnOff$ = ! getNL$( os ); } … … 107 101 if ( &os == &exit ) exit( EXIT_FAILURE ); 108 102 if ( &os == &abort ) abort(); 109 if ( os.acquired$ ) { os.acquired$ = false; release( os ); }103 if ( os.acquired$ ) { os.acquired$ = false; unlock( os ); } 110 104 } // ends 111 105 112 bool fail( ofstream & os ) { 113 return os.file$ == 0 || ferror( (FILE *)(os.file$) ); 114 } // fail 115 116 void clear( ofstream & os ) { 117 clearerr( (FILE *)(os.file$) ); 118 } // clear 119 120 int flush( ofstream & os ) { 121 return fflush( (FILE *)(os.file$) ); 122 } // flush 106 bool fail( ofstream & os ) { return os.file$ == 0 || ferror( (FILE *)(os.file$) ); } 107 void clear( ofstream & os ) { clearerr( (FILE *)(os.file$) ); } 108 int flush( ofstream & os ) { return fflush( (FILE *)(os.file$) ); } 123 109 124 110 void open( ofstream & os, const char name[], const char mode[] ) { … … 131 117 } // open 132 118 133 void open( ofstream & os, const char name[] ) { 134 open( os, name, "w" ); 135 } // open 136 137 void close( ofstream & os ) with(os) { 119 void open( ofstream & os, const char name[] ) { open( os, name, "w" ); } 120 121 void close( ofstream & os ) with( os ) { 138 122 if ( (FILE *)(file$) == 0p ) return; 139 123 if ( (FILE *)(file$) == (FILE *)stdout || (FILE *)(file$) == (FILE *)stderr ) return; … … 143 127 // abort | IO_MSG "close output" | nl | strerror( errno ); 144 128 } // if 145 file$ = 0p; 129 file$ = 0p; // safety after close 146 130 } // close 147 131 … … 175 159 } // fmt 176 160 177 inline void acquire( ofstream & os ) with(os) {178 lock( lock$ );// may increase recursive lock161 void acquire( ofstream & os ) with( os ) { 162 lock( os ); // may increase recursive lock 179 163 if ( ! acquired$ ) acquired$ = true; // not locked ? 180 else unlock( lock$ );// unwind recursive lock at start164 else unlock( os ); // unwind recursive lock at start 181 165 } // acquire 182 166 183 inline void release( ofstream & os ) { 184 unlock( os.lock$ ); 185 } // release 186 187 void ?{}( osacquire & acq, ofstream & os ) { lock( os.lock$ ); &acq.os = &os; } 188 void ^?{}( osacquire & acq ) { release( acq.os ); } 167 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os ); } 168 void ^?{}( osacquire & acq ) { unlock( acq.os ); } 189 169 190 170 static ofstream soutFile = { (FILE *)stdout }; … … 205 185 flush( os ); 206 186 return os; 207 // (ofstream &)(os | '\n');208 // setPrt$( os, false ); // turn off209 // setNL$( os, true );210 // flush( os );211 // return sepOff( os ); // prepare for next line212 187 } // nl 213 188 … … 217 192 218 193 // private 219 void ?{}( ifstream & is, void * file ) with( is) {194 void ?{}( ifstream & is, void * file ) with( is ) { 220 195 file$ = file; 221 196 nlOnOff$ = false; … … 223 198 } // ?{} 224 199 200 inline void lock( ifstream & os ) with( os ) { lock( os.lock$ ); } 201 inline void unlock( ifstream & os ) { unlock( os.lock$ ); } 202 225 203 // public 226 204 void ?{}( ifstream & is ) { is.file$ = 0p; } 227 228 void ?{}( ifstream & is, const char name[], const char mode[] ) { 229 open( is, name, mode ); 230 } // ?{} 231 232 void ?{}( ifstream & is, const char name[] ) { 233 open( is, name, "r" ); 234 } // ?{} 235 236 void ^?{}( ifstream & is ) { 237 close( is ); 238 } // ^?{} 205 void ?{}( ifstream & is, const char name[], const char mode[] ) { open( is, name, mode ); } 206 void ?{}( ifstream & is, const char name[] ) { open( is, name, "r" ); } 207 void ^?{}( ifstream & is ) { close( is ); } 239 208 240 209 void nlOn( ifstream & os ) { os.nlOnOff$ = true; } … … 242 211 bool getANL( ifstream & os ) { return os.nlOnOff$; } 243 212 244 bool fail( ifstream & is ) { 245 return is.file$ == 0p || ferror( (FILE *)(is.file$) ); 246 } // fail 247 248 void clear( ifstream & is ) { 249 clearerr( (FILE *)(is.file$) ); 250 } // clear 213 bool fail( ifstream & is ) { return is.file$ == 0p || ferror( (FILE *)(is.file$) ); } 214 void clear( ifstream & is ) { clearerr( (FILE *)(is.file$) ); } 251 215 252 216 void ends( ifstream & is ) { 253 if ( is.acquired$ ) { is.acquired$ = false; release( is ); }217 if ( is.acquired$ ) { is.acquired$ = false; unlock( is ); } 254 218 } // ends 255 219 256 bool eof( ifstream & is ) { 257 return feof( (FILE *)(is.file$) ); 258 } // eof 220 bool eof( ifstream & is ) { return feof( (FILE *)(is.file$) ); } 259 221 260 222 void open( ifstream & is, const char name[], const char mode[] ) { … … 267 229 } // open 268 230 269 void open( ifstream & is, const char name[] ) { 270 open( is, name, "r" ); 271 } // open 272 273 void close( ifstream & is ) with(is) { 231 void open( ifstream & is, const char name[] ) { open( is, name, "r" ); } 232 233 void close( ifstream & is ) with( is ) { 274 234 if ( (FILE *)(file$) == 0p ) return; 275 235 if ( (FILE *)(file$) == (FILE *)stdin ) return; … … 320 280 } // fmt 321 281 322 inline void acquire( ifstream & is ) with(is) {323 lock( lock$ );// may increase recursive lock282 void acquire( ifstream & is ) with( is ) { 283 lock( is ); // may increase recursive lock 324 284 if ( ! acquired$ ) acquired$ = true; // not locked ? 325 else unlock( lock$ );// unwind recursive lock at start285 else unlock( is ); // unwind recursive lock at start 326 286 } // acquire 327 287 328 inline void release( ifstream & is ) { 329 unlock( is.lock$ ); 330 } // release 331 332 void ?{}( isacquire & acq, ifstream & is ) { lock( is.lock$ ); &acq.is = &is; } 333 void ^?{}( isacquire & acq ) { release( acq.is ); } 288 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is ); } 289 void ^?{}( isacquire & acq ) { unlock( acq.is ); } 334 290 335 291 static ifstream sinFile = { (FILE *)stdin }; -
libcfa/src/fstream.hfa
r056cbdb r7ce2483 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Wed Jul 28 07:35:50202113 // Update Count : 23 412 // Last Modified On : Fri Oct 1 07:40:37 2021 13 // Update Count : 238 14 14 // 15 15 … … 53 53 void setPrt$( ofstream &, bool ); 54 54 55 void lock( ofstream & ); 56 void unlock( ofstream & ); 57 55 58 // public 56 59 void sepOn( ofstream & ); … … 78 81 79 82 void acquire( ofstream & ); 80 void release( ofstream & );81 82 void lock( ofstream & );83 void unlock( ofstream & );84 83 85 84 struct osacquire { … … 114 113 115 114 // Satisfies istream 115 116 // private 117 void lock( ifstream & ); 118 void unlock( ifstream & ); 116 119 117 120 // public … … 132 135 133 136 void acquire( ifstream & is ); 134 void release( ifstream & is );135 137 136 138 struct isacquire {
Note: See TracChangeset
for help on using the changeset viewer.