Changes in / [96f01d7f:172a88d]
- Location:
- libcfa/src
- Files:
-
- 2 edited
-
fstream.cfa (modified) (13 diffs)
-
fstream.hfa (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
libcfa/src/fstream.cfa
r96f01d7f r172a88d 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Oct 1 08:10:21202113 // Update Count : 4 7312 // Last Modified On : Tue Sep 21 21:51:38 2021 13 // Update Count : 460 14 14 // 15 15 … … 28 28 #define IO_MSG "I/O error: " 29 29 30 // private 31 void ?{}( ofstream & os, void * file ) with( os ) { 30 void ?{}( ofstream & os, void * file ) with(os) { 32 31 file$ = file; 33 32 sepDefault$ = true; … … 42 41 } // ?{} 43 42 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$ ); } 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; } 57 54 58 55 // public 59 56 void ?{}( ofstream & os ) { os.file$ = 0p; } 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 ); } 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 } // ^?{} 63 69 64 70 void sepOn( ofstream & os ) { os.sepOnOff$ = ! getNL$( os ); } … … 101 107 if ( &os == &exit ) exit( EXIT_FAILURE ); 102 108 if ( &os == &abort ) abort(); 103 if ( os.acquired$ ) { os.acquired$ = false; unlock( os ); }109 if ( os.acquired$ ) { os.acquired$ = false; release( os ); } 104 110 } // ends 105 111 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$) ); } 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 109 123 110 124 void open( ofstream & os, const char name[], const char mode[] ) { … … 117 131 } // open 118 132 119 void open( ofstream & os, const char name[] ) { open( os, name, "w" ); } 120 121 void close( ofstream & os ) with( os ) { 133 void open( ofstream & os, const char name[] ) { 134 open( os, name, "w" ); 135 } // open 136 137 void close( ofstream & os ) with(os) { 122 138 if ( (FILE *)(file$) == 0p ) return; 123 139 if ( (FILE *)(file$) == (FILE *)stdout || (FILE *)(file$) == (FILE *)stderr ) return; … … 127 143 // abort | IO_MSG "close output" | nl | strerror( errno ); 128 144 } // if 129 file$ = 0p; // safety after close145 file$ = 0p; 130 146 } // close 131 147 … … 159 175 } // fmt 160 176 161 void acquire( ofstream & os ) with( os) {162 lock( os );// may increase recursive lock177 inline void acquire( ofstream & os ) with(os) { 178 lock( lock$ ); // may increase recursive lock 163 179 if ( ! acquired$ ) acquired$ = true; // not locked ? 164 else unlock( os );// unwind recursive lock at start180 else unlock( lock$ ); // unwind recursive lock at start 165 181 } // acquire 166 182 167 void ?{}( osacquire & acq, ofstream & os ) { &acq.os = &os; lock( os ); } 168 void ^?{}( osacquire & acq ) { unlock( acq.os ); } 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 ); } 169 189 170 190 static ofstream soutFile = { (FILE *)stdout }; … … 185 205 flush( os ); 186 206 return os; 207 // (ofstream &)(os | '\n'); 208 // setPrt$( os, false ); // turn off 209 // setNL$( os, true ); 210 // flush( os ); 211 // return sepOff( os ); // prepare for next line 187 212 } // nl 188 213 … … 192 217 193 218 // private 194 void ?{}( ifstream & is, void * file ) with( is) {219 void ?{}( ifstream & is, void * file ) with(is) { 195 220 file$ = file; 196 221 nlOnOff$ = false; … … 198 223 } // ?{} 199 224 200 inline void lock( ifstream & os ) with( os ) { lock( os.lock$ ); }201 inline void unlock( ifstream & os ) { unlock( os.lock$ ); }202 203 225 // public 204 226 void ?{}( ifstream & is ) { is.file$ = 0p; } 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 ); } 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 } // ^?{} 208 239 209 240 void nlOn( ifstream & os ) { os.nlOnOff$ = true; } … … 211 242 bool getANL( ifstream & os ) { return os.nlOnOff$; } 212 243 213 bool fail( ifstream & is ) { return is.file$ == 0p || ferror( (FILE *)(is.file$) ); } 214 void clear( ifstream & is ) { clearerr( (FILE *)(is.file$) ); } 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 215 251 216 252 void ends( ifstream & is ) { 217 if ( is.acquired$ ) { is.acquired$ = false; unlock( is ); }253 if ( is.acquired$ ) { is.acquired$ = false; release( is ); } 218 254 } // ends 219 255 220 bool eof( ifstream & is ) { return feof( (FILE *)(is.file$) ); } 256 bool eof( ifstream & is ) { 257 return feof( (FILE *)(is.file$) ); 258 } // eof 221 259 222 260 void open( ifstream & is, const char name[], const char mode[] ) { … … 229 267 } // open 230 268 231 void open( ifstream & is, const char name[] ) { open( is, name, "r" ); } 232 233 void close( ifstream & is ) with( is ) { 269 void open( ifstream & is, const char name[] ) { 270 open( is, name, "r" ); 271 } // open 272 273 void close( ifstream & is ) with(is) { 234 274 if ( (FILE *)(file$) == 0p ) return; 235 275 if ( (FILE *)(file$) == (FILE *)stdin ) return; … … 280 320 } // fmt 281 321 282 void acquire( ifstream & is ) with( is) {283 lock( is );// may increase recursive lock322 inline void acquire( ifstream & is ) with(is) { 323 lock( lock$ ); // may increase recursive lock 284 324 if ( ! acquired$ ) acquired$ = true; // not locked ? 285 else unlock( is );// unwind recursive lock at start325 else unlock( lock$ ); // unwind recursive lock at start 286 326 } // acquire 287 327 288 void ?{}( isacquire & acq, ifstream & is ) { &acq.is = &is; lock( is ); } 289 void ^?{}( isacquire & acq ) { unlock( acq.is ); } 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 ); } 290 334 291 335 static ifstream sinFile = { (FILE *)stdin }; -
libcfa/src/fstream.hfa
r96f01d7f r172a88d 10 10 // Created On : Wed May 27 17:56:53 2015 11 11 // Last Modified By : Peter A. Buhr 12 // Last Modified On : Fri Oct 1 07:40:37202113 // Update Count : 23 812 // Last Modified On : Wed Jul 28 07:35:50 2021 13 // Update Count : 234 14 14 // 15 15 … … 53 53 void setPrt$( ofstream &, bool ); 54 54 55 void lock( ofstream & );56 void unlock( ofstream & );57 58 55 // public 59 56 void sepOn( ofstream & ); … … 81 78 82 79 void acquire( ofstream & ); 80 void release( ofstream & ); 81 82 void lock( ofstream & ); 83 void unlock( ofstream & ); 83 84 84 85 struct osacquire { … … 113 114 114 115 // Satisfies istream 115 116 // private117 void lock( ifstream & );118 void unlock( ifstream & );119 116 120 117 // public … … 135 132 136 133 void acquire( ifstream & is ); 134 void release( ifstream & is ); 137 135 138 136 struct isacquire {
Note:
See TracChangeset
for help on using the changeset viewer.