SNAP Library 2.4, Developer Reference  2015-05-11 19:40:56
SNAP, a general purpose, high performance system for analysis and manipulation of large networks
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
fl.cpp
Go to the documentation of this file.
1 #ifdef GLib_LINUX
2 extern "C" {
3  #include <sys/mman.h>
4 }
5 
6 #endif
7 
9 // Check-Sum
10 const int TCs::MxMask=0x0FFFFFFF;
11 
12 TCs TCs::GetCsFromBf(char* Bf, const int& BfL){
13  TCs Cs;
14  for (int BfC=0; BfC<BfL; BfC++){Cs+=Bf[BfC];}
15  return Cs;
16 }
17 
19 // Stream-Base
21  return TStr(SNm.CStr());
22 }
23 
25 // Input-Stream
26 TSIn::TSIn(const TStr& Str) : TSBase(Str.CStr()), FastMode(false){}
27 
28 void TSIn::LoadCs(){
29  TCs CurCs=Cs; TCs TestCs;
30  Cs+=GetBf(&TestCs, sizeof(TestCs));
31  EAssertR(CurCs==TestCs, "Invalid checksum reading '"+GetSNm()+"'.");
32 }
33 
34 void TSIn::Load(char*& CStr){
35  char Ch; Load(Ch);
36  int CStrLen=int(Ch);
37  EAssertR(CStrLen>=0, "Error reading stream '"+GetSNm()+"'.");
38  CStr=new char[CStrLen+1];
39  if (CStrLen>0){Cs+=GetBf(CStr, CStrLen);}
40  CStr[CStrLen]=TCh::NullCh;
41 }
42 
43 bool TSIn::GetNextLn(TStr& LnStr){
44  TChA LnChA;
45  const bool IsNext=GetNextLn(LnChA);
46  LnStr=LnChA;
47  return IsNext;
48 }
49 
50 bool TSIn::GetNextLn(TChA& LnChA){
51  LnChA.Clr();
52  while (!Eof()){
53  const char Ch=GetCh();
54  if (Ch=='\n'){return true;}
55  if (Ch=='\r' && PeekCh()=='\n'){GetCh(); return true;}
56  LnChA.AddCh(Ch);
57  }
58  return !LnChA.Empty();
59 }
60 
61 const PSIn TSIn::StdIn=PSIn(new TStdIn());
62 
63 TStdIn::TStdIn(): TSBase("Standard input"), TSIn("Standard input") {}
64 
66 // Output-Stream
67 TSOut::TSOut(const TStr& Str):
68  TSBase(Str.CStr()), MxLnLen(-1), LnLen(0){}
69 
70 int TSOut::UpdateLnLen(const int& StrLen, const bool& ForceInLn){
71  int Cs=0;
72  if (MxLnLen!=-1){
73  if ((!ForceInLn)&&(LnLen+StrLen>MxLnLen)){Cs+=PutLn();}
74  LnLen+=StrLen;
75  }
76  return Cs;
77 }
78 
79 int TSOut::PutMem(const TMem& Mem){
80  return PutBf(Mem(), Mem.Len());
81 }
82 
83 int TSOut::PutCh(const char& Ch, const int& Chs){
84  int Cs=0;
85  for (int ChN=0; ChN<Chs; ChN++){Cs+=PutCh(Ch);}
86  return Cs;
87 }
88 
89 int TSOut::PutBool(const bool& Bool){
90  return PutStr(TBool::GetStr(Bool));
91 }
92 
93 int TSOut::PutInt(const int& Int){
94  return PutStr(TInt::GetStr(Int));
95 }
96 
97 int TSOut::PutInt(const int& Int, const char* FmtStr){
98  return PutStr(TInt::GetStr(Int, FmtStr));
99 }
100 
101 int TSOut::PutUInt(const uint& UInt){
102  return PutStr(TUInt::GetStr(UInt));
103 }
104 
105 int TSOut::PutUInt(const uint& UInt, const char* FmtStr){
106  return PutStr(TUInt::GetStr(UInt, FmtStr));
107 }
108 
109 int TSOut::PutFlt(const double& Flt){
110  return PutStr(TFlt::GetStr(Flt));
111 }
112 
113 int TSOut::PutFlt(const double& Flt, const char* FmtStr){
114  return PutStr(TFlt::GetStr(Flt, FmtStr));
115 }
116 
117 int TSOut::PutStr(const char* CStr){
118  int Cs=UpdateLnLen(int(strlen(CStr)));
119  return Cs+PutBf(CStr, int(strlen(CStr)));
120 }
121 
122 int TSOut::PutStr(const TChA& ChA){
123  int Cs=UpdateLnLen(ChA.Len());
124  return Cs+PutBf(ChA.CStr(), ChA.Len());
125 }
126 
127 int TSOut::PutStr(const TStr& Str, const char* FmtStr){
128  return PutStr(TStr::GetStr(Str, FmtStr));
129 }
130 
131 int TSOut::PutStr(const TStr& Str, const bool& ForceInLn){
132  int Cs=UpdateLnLen(Str.Len(), ForceInLn);
133  return Cs+PutBf(Str.CStr(), Str.Len());
134 }
135 
136 int TSOut::PutStrFmt(const char *FmtStr, ...){
137  char Bf[10*1024];
138  va_list valist;
139  va_start(valist, FmtStr);
140  const int RetVal=vsnprintf(Bf, 10*1024-2, FmtStr, valist);
141  va_end(valist);
142  return RetVal!=-1 ? PutStr(TStr(Bf)) : 0;
143 }
144 
145 int TSOut::PutStrFmtLn(const char *FmtStr, ...){
146  char Bf[10*1024];
147  va_list valist;
148  va_start(valist, FmtStr);
149  const int RetVal=vsnprintf(Bf, 10*1024-2, FmtStr, valist);
150  va_end(valist);
151  return RetVal!=-1 ? PutStrLn(TStr(Bf)) : PutLn();
152 }
153 
154 int TSOut::PutIndent(const int& IndentLev){
155  return PutCh(' ', IndentLev*2);
156 }
157 
158 int TSOut::PutLn(const int& Lns){
159  LnLen=0; int Cs=0;
160  for (int LnN=0; LnN<Lns; LnN++){Cs+=PutCh('\n');}
161  return Cs;
162 }
163 
164 int TSOut::PutDosLn(const int& Lns){
165  LnLen=0; int Cs=0;
166  for (int LnN=0; LnN<Lns; LnN++){Cs+=PutCh(TCh::CrCh)+PutCh(TCh::LfCh);}
167  return Cs;
168 }
169 
170 int TSOut::PutSep(const int& NextStrLen){
171  int Cs=0;
172  if (MxLnLen==-1){
173  Cs+=PutCh(' ');
174  } else {
175  if (LnLen>0){
176  if (LnLen+1+NextStrLen>MxLnLen){Cs+=PutLn();} else {Cs+=PutCh(' ');}
177  }
178  }
179  return Cs;
180 }
181 
182 int TSOut::PutSepLn(const int& Lns){
183  int Cs=0;
184  if (LnLen>0){Cs+=PutLn();}
185  Cs+=PutLn(Lns);
186  return Cs;
187 }
188 
189 void TSOut::Save(const char* CStr){
190  int CStrLen=int(strlen(CStr));
191  EAssertR(CStrLen<=127, "Error writting stream '"+GetSNm()+"'.");
192  Save(char(CStrLen));
193  if (CStrLen>0){Cs+=PutBf(CStr, CStrLen);}
194 }
195 
196 void TSOut::Save(TSIn& SIn, const TSize& BfL){
197  Fail;
198  if (BfL==0){ //J: used to be ==-1
199  while (!SIn.Eof()){Save(SIn.GetCh());}
200  } else {
201  for (TSize BfC=0; BfC<BfL; BfC++){Save(SIn.GetCh());}
202  }
203 }
204 
206  while (!SIn.Eof())
207  operator<<((char)SIn.GetCh());
208  return *this;
209 }
210 
211 const PSOut TSOut::StdOut=PSOut(new TStdOut());
212 
213 TStdOut::TStdOut(): TSBase(TSStr("Standard output")), TSOut("Standard output"){}
214 
216 // Standard-Input
217 int TStdIn::GetBf(const void* LBf, const TSize& LBfL){
218  int LBfS=0;
219  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
220  LBfS+=(((char*)LBf)[LBfC]=GetCh());}
221  return LBfS;
222 }
223 
225  // not implemented
226  FailR(TStr::Fmt("TStdIn::GetNextLnBf: not implemented").CStr());
227  return false;
228 }
229 
231 // Standard-Output
232 int TStdOut::PutBf(const void* LBf, const TSize& LBfL){
233  int LBfS=0;
234  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
235  LBfS+=PutCh(((char*)LBf)[LBfC]);}
236  return LBfS;
237 }
238 
240 // Input-File
241 const int TFIn::MxBfL=16*1024;
242 
243 void TFIn::SetFPos(const int& FPos) const {
244  EAssertR(
245  fseek(FileId, FPos, SEEK_SET)==0,
246  "Error seeking into file '"+GetSNm()+"'.");
247 }
248 
249 int TFIn::GetFPos() const {
250  const int FPos=(int)ftell(FileId);
251  EAssertR(FPos!=-1, "Error seeking into file '"+GetSNm()+"'.");
252  return FPos;
253 }
254 
255 int TFIn::GetFLen() const {
256  const int FPos=GetFPos();
257  EAssertR(
258  fseek(FileId, 0, SEEK_END)==0,
259  "Error seeking into file '"+GetSNm()+"'.");
260  const int FLen=GetFPos(); SetFPos(FPos);
261  return FLen;
262 }
263 
265  EAssertR(
266  (BfC==BfL)&&((BfL==-1)||(BfL==MxBfL)),
267  "Error reading file '"+GetSNm()+"'.");
268  BfL=int(fread(Bf, 1, MxBfL, FileId));
269  EAssertR((BfC!=0)||(BfL!=0), "Error reading file '"+GetSNm()+"'.");
270  BfC=0;
271 }
272 
273 TFIn::TFIn(const TStr& FNm):
274  TSBase(FNm.CStr()), TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
275  EAssertR(!FNm.Empty(), "Empty file-name.");
276  FileId=fopen(FNm.CStr(), "rb");
277  EAssertR(FileId!=NULL, "Can not open file '"+FNm+"'.");
278  Bf=new char[MxBfL]; BfC=BfL=-1; FillBf();
279 }
280 
281 TFIn::TFIn(const TStr& FNm, bool& OpenedP):
282  TSBase(FNm.CStr()), TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
283  EAssertR(!FNm.Empty(), "Empty file-name.");
284  FileId=fopen(FNm.CStr(), "rb");
285  OpenedP=(FileId!=NULL);
286  if (OpenedP){
287  Bf=new char[MxBfL]; BfC=BfL=-1; FillBf();}
288 }
289 
290 PSIn TFIn::New(const TStr& FNm){
291  try {
292  return PSIn(new TFIn(FNm));
293  } catch (PExcept& Except) {
294  printf("*** Exception: %s\n", Except->GetMsgStr().CStr());
295  EFailR(Except->GetMsgStr());
296  }
297 
298  return PSIn(new TFIn(FNm));
299 }
300 
301 PSIn TFIn::New(const TStr& FNm, bool& OpenedP){
302  return PSIn(new TFIn(FNm, OpenedP));
303 }
304 
306  if (FileId!=NULL){
307  EAssertR(fclose(FileId)==0, "Can not close file '"+GetSNm()+"'.");}
308  if (Bf!=NULL){delete[] Bf;}
309 }
310 
311 int TFIn::GetBf(const void* LBf, const TSize& LBfL){
312  int LBfS=0;
313  if (TSize(BfC+LBfL)>TSize(BfL)){
314  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
315  if (BfC==BfL){FillBf();}
316  LBfS+=((char*)LBf)[LBfC]=Bf[BfC++];}
317  } else {
318  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
319  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
320  }
321  return LBfS;
322 }
323 
324 // Gets the next line to LnChA.
325 // Returns true, if LnChA contains a valid line.
326 // Returns false, if LnChA is empty, such as end of file was encountered.
327 
328 bool TFIn::GetNextLnBf(TChA& LnChA) {
329  int Status;
330  int BfN; // new pointer to the end of line
331  int BfP; // previous pointer to the line start
332  bool CrEnd; // last character in previous buffer was CR
333 
334  LnChA.Clr();
335 
336  CrEnd = false;
337  do {
338  if (BfC >= BfL) {
339  // reset the current pointer, FindEol() will read a new buffer
340  BfP = 0;
341  } else {
342  BfP = BfC;
343  }
344  Status = FindEol(BfN,CrEnd);
345  if (Status >= 0) {
346  if (BfN-BfP > 0) {
347  LnChA.AddBf(&Bf[BfP],BfN-BfP);
348  }
349  if (Status == 1) {
350  // got a complete line
351  return true;
352  }
353  }
354  // get more data, if the line is incomplete
355  } while (Status == 0);
356 
357  // eof or the last line has no newline
358  return !LnChA.Empty();
359 }
360 
361 // Sets BfN to the end of line or end of buffer. Reads more data, if needed.
362 // Returns 1, when an end of line was found, BfN is end of line.
363 // Returns 0, when an end of line was not found and more data is required,
364 // BfN is end of buffer.
365 // Returns -1, when an end of file was found, BfN is not defined.
366 
367 int TFIn::FindEol(int& BfN, bool& CrEnd) {
368  char Ch;
369 
370  if (BfC >= BfL) {
371  // read more data, check for eof
372  if (Eof()) {
373  return -1;
374  }
375  if (CrEnd && Bf[BfC]=='\n') {
376  BfC++;
377  BfN = BfC-1;
378  return 1;
379  }
380  }
381 
382  CrEnd = false;
383  while (BfC < BfL) {
384  Ch = Bf[BfC++];
385  if (Ch=='\n') {
386  BfN = BfC-1;
387  return 1;
388  }
389  if (Ch=='\r') {
390  if (BfC == BfL) {
391  CrEnd = true;
392  BfN = BfC-1;
393  return 0;
394  } else if (Bf[BfC]=='\n') {
395  BfC++;
396  BfN = BfC-2;
397  return 1;
398  }
399  }
400  }
401  BfN = BfC;
402 
403  return 0;
404 }
405 
407 // Output-File
408 const TSize TFOut::MxBfL=16*1024;;
409 
411  EAssertR(
412  fwrite(Bf, 1, BfL, FileId)==BfL,
413  "Error writting to the file '"+GetSNm()+"'.");
414  BfL=0;
415 }
416 
417 TFOut::TFOut(const TStr& FNm, const bool& Append):
418  TSBase(FNm.CStr()), TSOut(FNm), FileId(NULL), Bf(NULL), BfL(0){
419  if (FNm.GetUc()=="CON"){
420  FileId=stdout;
421  } else {
422  if (Append){FileId=fopen(FNm.CStr(), "a+b");}
423  else {FileId=fopen(FNm.CStr(), "w+b");}
424  EAssertR(FileId!=NULL, "Can not open file '"+FNm+"'.");
425  Bf=new char[MxBfL]; BfL=0;
426  }
427 }
428 
429 TFOut::TFOut(const TStr& FNm, const bool& Append, bool& OpenedP):
430  TSBase(FNm.CStr()), TSOut(FNm), FileId(NULL), Bf(NULL), BfL(0){
431  if (FNm.GetUc()=="CON"){
432  FileId=stdout;
433  } else {
434  if (Append){FileId=fopen(FNm.CStr(), "a+b");}
435  else {FileId=fopen(FNm.CStr(), "w+b");}
436  OpenedP=(FileId!=NULL);
437  if (OpenedP){
438  Bf=new char[MxBfL]; BfL=0;}
439  }
440 }
441 
442 PSOut TFOut::New(const TStr& FNm, const bool& Append){
443  return PSOut(new TFOut(FNm, Append));
444 }
445 
446 PSOut TFOut::New(const TStr& FNm, const bool& Append, bool& OpenedP){
447  PSOut SOut=PSOut(new TFOut(FNm, Append, OpenedP));
448  if (OpenedP){return SOut;} else {return NULL;}
449 }
450 
452  if (FileId!=NULL){FlushBf();}
453  if (Bf!=NULL){delete[] Bf;}
454  if (FileId!=NULL){
455  EAssertR(fclose(FileId)==0, "Can not close file '"+GetSNm()+"'.");}
456 }
457 
458 int TFOut::PutCh(const char& Ch){
459  if (BfL==TSize(MxBfL)){FlushBf();}
460  return Bf[BfL++]=Ch;
461 }
462 
463 int TFOut::PutBf(const void* LBf, const TSize& LBfL){
464  int LBfS=0;
465  if (BfL+LBfL>MxBfL){
466  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
467  LBfS+=PutCh(((char*)LBf)[LBfC]);}
468  } else {
469  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
470  LBfS+=(Bf[BfL++]=((char*)LBf)[LBfC]);}
471  }
472  return LBfS;
473 }
474 
476  FlushBf();
477  EAssertR(fflush(FileId)==0, "Can not flush file '"+GetSNm()+"'.");
478 }
479 
481 // Input-Output-File
482 TFInOut::TFInOut(const TStr& FNm, const TFAccess& FAccess, const bool& CreateIfNo) :
483  TSBase(TSStr(FNm.CStr())), FileId(NULL) {
484  switch (FAccess){
485  case faCreate: FileId=fopen(FNm.CStr(), "w+b"); break;
486  case faUpdate: FileId=fopen(FNm.CStr(), "r+b"); break;
487  case faAppend: FileId=fopen(FNm.CStr(), "r+b");
488  if (FileId!=NULL){fseek(FileId, SEEK_END, 0);} break;
489  case faRdOnly: FileId=fopen(FNm.CStr(), "rb"); break;
490  default: Fail;
491  }
492  if ((FileId==NULL)&&(CreateIfNo)){FileId=fopen(FNm.CStr(), "w+b");}
493  IAssert(FileId!=NULL);
494 }
495 
496 PSInOut TFInOut::New(const TStr& FNm, const TFAccess& FAccess, const bool& CreateIfNo) {
497  return PSInOut(new TFInOut(FNm, FAccess, CreateIfNo));
498 }
499 
500 int TFInOut::GetSize() const {
501  const int FPos = GetPos();
502  IAssert(fseek(FileId, 0, SEEK_END) == 0);
503  const int FLen = GetPos();
504  IAssert(fseek(FileId, FPos, SEEK_SET) == 0);
505  return FLen;
506 }
507 
508 int TFInOut::PutBf(const void* LBf, const TSize& LBfL) {
509  int LBfS = 0;
510  for (TSize i = 0; i < LBfL; i++) {
511  LBfS += ((char *)LBf)[i];
512  }
513  IAssert(fwrite(LBf, sizeof(char), LBfL, FileId) == (size_t) LBfL);
514  return LBfS;
515 }
516 
517 int TFInOut::GetBf(const void* LBf, const TSize& LBfL) {
518  IAssert(fread((void *)LBf, sizeof(char), LBfL, FileId) == (size_t) LBfL);
519  int LBfS = 0;
520  for (TSize i = 0; i < LBfL; i++) {
521  LBfS += ((char *)LBf)[i];
522  }
523  return LBfS;
524 }
525 
527  // not implemented
528  FailR(TStr::Fmt("TFInOut::GetNextLnBf: not implemented").CStr());
529  return false;
530 }
531 
533  return GetSNm();
534 }
535 
537 // Input-Memory
538 TMIn::TMIn(const void* _Bf, const int& _BfL, const bool& TakeBf):
539  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(_BfL){
540  if (TakeBf){
541  Bf=(char*)_Bf;
542  } else {
543  Bf=new char[BfL]; memmove(Bf, _Bf, BfL);
544  }
545 }
546 
548  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0){
549  BfL=SIn.Len(); Bf=new char[BfL];
550  for (int BfC=0; BfC<BfL; BfC++){Bf[BfC]=SIn.GetCh();}
551 }
552 
553 TMIn::TMIn(const char* CStr):
554  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0){
555  BfL=int(strlen(CStr)); Bf=new char[BfL+1]; strcpy(Bf, CStr);
556 }
557 
558 TMIn::TMIn(const TStr& Str):
559  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0){
560  BfL=Str.Len(); Bf=new char[BfL]; strncpy(Bf, Str.CStr(), BfL);
561 }
562 
563 TMIn::TMIn(const TChA& ChA):
564  TSBase("Input-Memory"), TSIn("Input-Memory"), Bf(NULL), BfC(0), BfL(0){
565  BfL=ChA.Len(); Bf=new char[BfL]; strncpy(Bf, ChA.CStr(), BfL);
566 }
567 
568 PSIn TMIn::New(const void* _Bf, const int& _BfL, const bool& TakeBf){
569  return PSIn(new TMIn(_Bf, _BfL, TakeBf));
570 }
571 
572 PSIn TMIn::New(const char* CStr){
573  return PSIn(new TMIn(CStr));
574 }
575 
576 PSIn TMIn::New(const TStr& Str){
577  return PSIn(new TMIn(Str));
578 }
579 
580 PSIn TMIn::New(const TChA& ChA){
581  return PSIn(new TMIn(ChA));
582 }
583 
584 char TMIn::GetCh(){
585  EAssertR(BfC<BfL, "Reading beyond the end of stream.");
586  return Bf[BfC++];
587 }
588 
590  EAssertR(BfC<BfL, "Reading beyond the end of stream.");
591  return Bf[BfC];
592 }
593 
594 int TMIn::GetBf(const void* LBf, const TSize& LBfL){
595  EAssertR(TSize(BfC+LBfL)<=TSize(BfL), "Reading beyond the end of stream.");
596  int LBfS=0;
597  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
598  LBfS+=(((char*)LBf)[LBfC]=Bf[BfC++]);}
599  return LBfS;
600 }
601 
602 bool TMIn::GetNextLnBf(TChA& LnChA){
603  // not implemented
604  FailR(TStr::Fmt("TMIn::GetNextLnBf: not implemented").CStr());
605  return false;
606 }
607 
609 // Output-Memory
610 void TMOut::Resize(const int& ReqLen){
611  IAssert(OwnBf&&(BfL==MxBfL || ReqLen >= 0));
612  if (Bf==NULL){
613  IAssert(MxBfL==0);
614  if (ReqLen < 0) Bf=new char[MxBfL=1024];
615  else Bf=new char[MxBfL=ReqLen];
616  } else {
617  if (ReqLen < 0){ MxBfL*=2; }
618  else if (ReqLen < MxBfL){ return; } // nothing to do
619  else { MxBfL=(2*MxBfL < ReqLen ? ReqLen : 2*MxBfL); }
620  char* NewBf=new char[MxBfL];
621  memmove(NewBf, Bf, BfL); delete[] Bf; Bf=NewBf;
622  }
623 }
624 
625 TMOut::TMOut(const int& _MxBfL):
626  TSBase("Output-Memory"), TSOut("Output-Memory"),
627  Bf(NULL), BfL(0), MxBfL(0), OwnBf(true){
628  MxBfL=_MxBfL>0?_MxBfL:1024;
629  Bf=new char[MxBfL];
630 }
631 
632 TMOut::TMOut(char* _Bf, const int& _MxBfL):
633  TSBase("Output-Memory"), TSOut("Output-Memory"),
634  Bf(_Bf), BfL(0), MxBfL(_MxBfL), OwnBf(false){}
635 
636 void TMOut::AppendBf(const void* LBf, const TSize& LBfL) {
637  Resize(Len() + (int)LBfL);
638  memcpy(Bf + BfL, LBf, LBfL);
639  BfL += (int)LBfL;
640 }
641 
642 int TMOut::PutBf(const void* LBf, const TSize& LBfL){
643  int LBfS=0;
644  if (TSize(BfL+LBfL)>TSize(MxBfL)){
645  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
646  LBfS+=PutCh(((char*)LBf)[LBfC]);}
647  } else {
648  for (TSize LBfC=0; LBfC<LBfL; LBfC++){
649  LBfS+=(Bf[BfL++]=((char*)LBf)[LBfC]);}
650  }
651  return LBfS;
652 }
653 
655  TChA ChA(BfL);
656  for (int BfC=0; BfC<BfL; BfC++){ChA+=Bf[BfC];}
657  return ChA;
658 }
659 
660 void TMOut::CutBf(const int& CutBfL){
661  IAssert((0<=CutBfL)&&(CutBfL<=BfL));
662  if (CutBfL==BfL){BfL=0;}
663  else {memmove(Bf, Bf+CutBfL, BfL-CutBfL); BfL=BfL-CutBfL;}
664 }
665 
666 PSIn TMOut::GetSIn(const bool& IsCut, const int& CutBfL){
667  IAssert((CutBfL==-1)||((0<=CutBfL)));
668  int SInBfL= (CutBfL==-1) ? BfL : TInt::GetMn(BfL, CutBfL);
669  PSIn SIn;
670  if (OwnBf&&IsCut&&(SInBfL==BfL)){
671  SIn=PSIn(new TMIn(Bf, SInBfL, true));
672  Bf=NULL; BfL=MxBfL=0; OwnBf=true;
673  } else {
674  SIn=PSIn(new TMIn(Bf, SInBfL, false));
675  if (IsCut){CutBf(SInBfL);}
676  }
677  return SIn;
678 }
679 
680 bool TMOut::IsCrLfLn() const {
681  for (int BfC=0; BfC<BfL; BfC++){
682  if ((Bf[BfC]==TCh::CrCh)&&((BfC+1<BfL)&&(Bf[BfC+1]==TCh::LfCh))){return true;}}
683  return false;
684 }
685 
687  IAssert(IsCrLfLn());
688  TChA Ln;
689  for (int BfC=0; BfC<BfL; BfC++){
690  char Ch=Bf[BfC];
691  if ((Ch==TCh::CrCh)&&((BfC+1<BfL)&&(Bf[BfC+1]==TCh::LfCh))){
692  Ln+=TCh::CrCh; Ln+=TCh::LfCh; CutBf(BfC+1+1); break;
693  } else {
694  Ln+=Ch;
695  }
696  }
697  return Ln;
698 }
699 
700 bool TMOut::IsEolnLn() const {
701  for (int BfC=0; BfC<BfL; BfC++){
702  if ((Bf[BfC]==TCh::CrCh)||(Bf[BfC]==TCh::LfCh)){return true;}
703  }
704  return false;
705 }
706 
707 TStr TMOut::GetEolnLn(const bool& DoAddEoln, const bool& DoCutBf){
708  IAssert(IsEolnLn());
709  int LnChs=0; TChA Ln;
710  for (int BfC=0; BfC<BfL; BfC++){
711  char Ch=Bf[BfC];
712  if ((Ch==TCh::CrCh)||(Ch==TCh::LfCh)){
713  LnChs++; if (DoAddEoln){Ln+=Ch;}
714  if (BfC+1<BfL){
715  char NextCh=Bf[BfC+1];
716  if (((Ch==TCh::CrCh)&&(NextCh==TCh::LfCh))||
717  ((Ch==TCh::LfCh)&&(NextCh==TCh::CrCh))){
718  LnChs++; if (DoAddEoln){Ln+=NextCh;}
719  }
720  }
721  break;
722  } else {
723  LnChs++; Ln+=Ch;
724  }
725  }
726  if (DoCutBf){
727  CutBf(LnChs);
728  }
729  return Ln;
730 }
731 
733  if (!IsEolnLn()){
735 }
736 
738 // Line-Returner
739 // J: after talking to BlazF -- can be removed from GLib
740 bool TLnRet::NextLn(TStr& LnStr) {
741  if (SIn->Eof()) { return false; }
742  TChA LnChA; char Ch = TCh::EofCh;
743  while (!SIn->Eof() && ((Ch=SIn->GetCh())!='\n')) {
744  if (Ch != '\r') { LnChA += Ch; }
745  }
746  LnStr = LnChA; return true;
747 }
748 
750 // fseek-Constants-Definitions
751 // because of strange Borland CBuilder behaviour in sysdefs.h
752 #ifndef SEEK_SET
753 #define SEEK_CUR 1
754 #define SEEK_END 2
755 #define SEEK_SET 0
756 #endif
757 
759 // Random-File
761  EAssertR(
762  fseek(FileId, 0, SEEK_CUR)==0,
763  "Error seeking into file '"+TStr(FNm)+"'.");
764 }
765 
766 TFRnd::TFRnd(const TStr& _FNm, const TFAccess& FAccess,
767  const bool& CreateIfNo, const int& _HdLen, const int& _RecLen):
768  FileId(NULL), FNm(_FNm.CStr()),
769  RecAct(false), HdLen(_HdLen), RecLen(_RecLen){
770  RecAct=(HdLen>=0)&&(RecLen>0);
771  switch (FAccess){
772  case faCreate: FileId=fopen(FNm.CStr(), "w+b"); break;
773  case faUpdate: FileId=fopen(FNm.CStr(), "r+b"); break;
774  case faAppend: FileId=fopen(FNm.CStr(), "r+b");
775  if (FileId!=NULL){fseek(FileId, SEEK_END, 0);} break;
776  case faRdOnly: FileId=fopen(FNm.CStr(), "rb"); break;
777  default: Fail;
778  }
779  if ((FileId==NULL)&&(CreateIfNo)){
780  FileId=fopen(FNm.CStr(), "w+b");}
781  EAssertR(FileId!=NULL, "Can not open file '"+_FNm+"'.");
782 }
783 
785  EAssertR(fclose(FileId)==0, "Can not close file '"+TStr(FNm)+"'.");
786 }
787 
789  return FNm.CStr();
790 }
791 
792 void TFRnd::SetFPos(const int& FPos){
793  EAssertR(
794  fseek(FileId, FPos, SEEK_SET)==0,
795  "Error seeking into file '"+TStr(FNm)+"'.");
796 }
797 
798 void TFRnd::MoveFPos(const int& DFPos){
799  EAssertR(
800  fseek(FileId, DFPos, SEEK_CUR)==0,
801  "Error seeking into file '"+TStr(FNm)+"'.");
802 }
803 
805  int FPos= (int) ftell(FileId);
806  EAssertR(FPos!=-1, "Error seeking into file '"+TStr(FNm)+"'.");
807  return FPos;
808 }
809 
811  int FPos=GetFPos();
812  EAssertR(
813  fseek(FileId, 0, SEEK_END)==0,
814  "Error seeking into file '"+TStr(FNm)+"'.");
815  int FLen=GetFPos(); SetFPos(FPos); return FLen;
816 }
817 
818 void TFRnd::SetRecN(const int& RecN){
819  IAssert(RecAct);
820  SetFPos(HdLen+RecN*RecLen);
821 }
822 
824  IAssert(RecAct);
825  int FPos=GetFPos()-HdLen;
826  EAssertR(FPos%RecLen==0, "Invalid position in file'"+TStr(FNm)+"'.");
827  return FPos/RecLen;
828 }
829 
831  IAssert(RecAct);
832  int FLen=GetFLen()-HdLen;
833  EAssertR(FLen%RecLen==0, "Invalid length of file'"+TStr(FNm)+"'.");
834  return FLen/RecLen;
835 }
836 
837 void TFRnd::GetBf(void* Bf, const TSize& BfL){
838  RefreshFPos();
839  EAssertR(
840  fread(Bf, 1, BfL, FileId)==BfL,
841  "Error reading file '"+TStr(FNm)+"'.");
842 }
843 
844 void TFRnd::PutBf(const void* Bf, const TSize& BfL){
845  RefreshFPos();
846  EAssertR(
847  fwrite(Bf, 1, BfL, FileId)==BfL,
848  "Error writting to the file '"+TStr(FNm)+"'.");
849 }
850 
852  EAssertR(fflush(FileId)==0, "Can not flush file '"+TStr(FNm)+"'.");
853 }
854 
855 void TFRnd::PutCh(const char& Ch, const int& Chs){
856  if (Chs>0){
857  char* CStr=new char[Chs];
858  for (int ChN=0; ChN<Chs; ChN++){CStr[ChN]=Ch;}
859  PutBf(CStr, Chs);
860  delete[] CStr;
861  }
862 }
863 
864 void TFRnd::PutStr(const TStr& Str){
865  PutBf(Str.CStr(), Str.Len()+1);
866 }
867 
868 TStr TFRnd::GetStr(const int& StrLen, bool& IsOk){
869  IsOk=false; TStr Str;
870  if (GetFPos()+StrLen+1<=GetFLen()){
871  char* CStr=new char[StrLen+1];
872  GetBf(CStr, StrLen+1);
873  if (CStr[StrLen+1-1]==TCh::NullCh){IsOk=true; Str=CStr;}
874  delete[] CStr;
875  }
876  return Str;
877 }
878 
879 TStr TFRnd::GetStr(const int& StrLen){
880  TStr Str;
881  char* CStr=new char[StrLen+1];
882  GetBf(CStr, StrLen+1);
883  EAssertR(CStr[StrLen+1-1]==TCh::NullCh, "Error reading file '"+TStr(FNm)+"'.");
884  Str=CStr;
885  delete[] CStr;
886  return Str;
887 }
888 
889 void TFRnd::PutSIn(const PSIn& SIn, TCs& Cs){
890  int BfL=SIn->Len();
891  char* Bf=new char[BfL];
892  SIn->GetBf(Bf, BfL);
893  Cs=TCs::GetCsFromBf(Bf, BfL);
894  PutBf(Bf, BfL);
895  delete[] Bf;
896 }
897 
898 PSIn TFRnd::GetSIn(const int& BfL, TCs& Cs){
899  char* Bf=new char[BfL];
900  GetBf(Bf, BfL);
901  Cs=TCs::GetCsFromBf(Bf, BfL);
902  PSIn SIn=PSIn(new TMIn(Bf, BfL, true));
903  return SIn;
904 }
905 
907  switch (FAccess){
908  case faCreate: return "Create";
909  case faUpdate: return "Update";
910  case faAppend: return "Append";
911  case faRdOnly: return "ReadOnly";
912  case faRestore: return "Restore";
913  default: Fail; return TStr();
914  }
915 }
916 
918  TStr UcStr=Str.GetUc();
919  if (UcStr=="CREATE"){return faCreate;}
920  if (UcStr=="UPDATE"){return faUpdate;}
921  if (UcStr=="APPEND"){return faAppend;}
922  if (UcStr=="READONLY"){return faRdOnly;}
923  if (UcStr=="RESTORE"){return faRestore;}
924 
925  if (UcStr=="NEW"){return faCreate;}
926  if (UcStr=="CONT"){return faUpdate;}
927  if (UcStr=="CONTINUE"){return faUpdate;}
928  if (UcStr=="REST"){return faRestore;}
929  if (UcStr=="RESTORE"){return faRestore;}
930  return faUndef;
931 }
932 
934 // Files
935 const TStr TFile::TxtFExt=".Txt";
936 const TStr TFile::HtmlFExt=".Html";
937 const TStr TFile::HtmFExt=".Htm";
938 const TStr TFile::GifFExt=".Gif";
939 const TStr TFile::JarFExt=".Jar";
940 
941 bool TFile::Exists(const TStr& FNm){
942  if (FNm.Empty()) { return false; }
943  bool DoExists;
944  TFIn FIn(FNm, DoExists);
945  return DoExists;
946 }
947 
948 #if defined(GLib_WIN32)
949 
950 void TFile::Copy(const TStr& SrcFNm, const TStr& DstFNm,
951  const bool& ThrowExceptP, const bool& FailIfExistsP){
952  if (ThrowExceptP){
953  if (CopyFile(SrcFNm.CStr(), DstFNm.CStr(), FailIfExistsP) == 0) {
954  int ErrorCode = (int)GetLastError();
956  "Error %d copying file '%s' to '%s'.",
957  ErrorCode, SrcFNm.CStr(), DstFNm.CStr()));
958  }
959  } else {
960  CopyFile(SrcFNm.CStr(), DstFNm.CStr(), FailIfExistsP);
961  }
962 }
963 
964 #elif defined(GLib_LINUX)
965 
966 void TFile::Copy(const TStr& SrcFNm, const TStr& DstFNm,
967  const bool& ThrowExceptP, const bool& FailIfExistsP){
968  int input, output;
969  size_t filesize;
970  void *source, *target;
971 
972  if( (input = open(SrcFNm.CStr(), O_RDONLY)) == -1) {
973  if (ThrowExceptP) {
975  "Error copying file '%s' to '%s': cannot open source file for reading.",
976  SrcFNm.CStr(), DstFNm.CStr()));
977  } else {
978  return;
979  }
980  }
981 
982 
983  if( (output = open(DstFNm.CStr(), O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1) {
984  close(input);
985 
986  if (ThrowExceptP) {
988  "Error copying file '%s' to '%s': cannot open destination file for writing.",
989  SrcFNm.CStr(), DstFNm.CStr()));
990  } else {
991  return;
992  }
993  }
994 
995 
996  filesize = lseek(input, 0, SEEK_END);
997  lseek(output, filesize - 1, SEEK_SET);
998  write(output, '\0', 1);
999 
1000  if((source = mmap(0, filesize, PROT_READ, MAP_SHARED, input, 0)) == (void *) -1) {
1001  close(input);
1002  close(output);
1003  if (ThrowExceptP) {
1005  "Error copying file '%s' to '%s': cannot mmap input file.",
1006  SrcFNm.CStr(), DstFNm.CStr()));
1007  } else {
1008  return;
1009  }
1010  }
1011 
1012  if((target = mmap(0, filesize, PROT_WRITE, MAP_SHARED, output, 0)) == (void *) -1) {
1013  munmap(source, filesize);
1014  close(input);
1015  close(output);
1016  if (ThrowExceptP) {
1018  "Error copying file '%s' to '%s': cannot mmap output file.",
1019  SrcFNm.CStr(), DstFNm.CStr()));
1020  } else {
1021  return;
1022  }
1023  }
1024 
1025  memcpy(target, source, filesize);
1026 
1027  munmap(source, filesize);
1028  munmap(target, filesize);
1029 
1030  close(input);
1031  close(output);
1032 
1033 }
1034 
1035 
1036 
1037 #endif
1038 
1039 void TFile::Del(const TStr& FNm, const bool& ThrowExceptP){
1040  if (ThrowExceptP){
1041  EAssertR(
1042  remove(FNm.CStr())==0,
1043  "Error removing file '"+FNm+"'.");
1044  } else {
1045  remove(FNm.CStr());
1046  }
1047 }
1048 
1049 void TFile::DelWc(const TStr& WcStr, const bool& RecurseDirP){
1050  // collect file-names
1051  TStrV FNmV;
1052  TFFile FFile(WcStr, RecurseDirP); TStr FNm;
1053  while (FFile.Next(FNm)){
1054  FNmV.Add(FNm);}
1055  // delete files
1056  for (int FNmN=0; FNmN<FNmV.Len(); FNmN++){
1057  Del(FNmV[FNmN], false);}
1058 }
1059 
1060 void TFile::Rename(const TStr& SrcFNm, const TStr& DstFNm){
1061  EAssertR(
1062  rename(SrcFNm.CStr(), DstFNm.CStr())==0,
1063  "Error renaming file '"+SrcFNm+"' to "+DstFNm+"'.");
1064 }
1065 
1067  // <name>.#.txt --> <name>.<num>.txt
1068  int Cnt=1; int ch;
1069  TStr NewFNm; TStr TmpFNm=FNm;
1070  if (FNm.SearchCh('#') == -1) {
1071  for (ch = FNm.Len()-1; ch >= 0; ch--) if (FNm[ch] == '.') break;
1072  if (ch != -1) TmpFNm.InsStr(ch, ".#");
1073  else TmpFNm += ".#";
1074  }
1075  forever{
1076  NewFNm=TmpFNm;
1077  NewFNm.ChangeStr("#", TStr::Fmt("%03d", Cnt)); Cnt++;
1078  if (!TFile::Exists(NewFNm)){break;}
1079  }
1080  return NewFNm;
1081 }
1082 
1083 #ifdef GLib_WIN
1084 
1085 uint64 TFile::GetSize(const TStr& FNm) {
1086  // open
1087  HANDLE hFile = CreateFile(
1088  FNm.CStr(), // file to open
1089  GENERIC_READ, // open for reading
1090  FILE_SHARE_READ | FILE_SHARE_WRITE, // share for reading
1091  NULL, // default security
1092  OPEN_EXISTING, // existing file only
1093  FILE_ATTRIBUTE_NORMAL, // normal file
1094  NULL); // no attr. template
1095  // check if we could open it
1096  if (hFile == INVALID_HANDLE_VALUE) {
1097  TExcept::Throw("Can not open file " + FNm + "!"); }
1098  // read file times
1099  LARGE_INTEGER lpFileSizeHigh;
1100  if (!GetFileSizeEx(hFile, &lpFileSizeHigh)) {
1101  TExcept::Throw("Can not read size of file " + FNm + "!"); }
1102  // close file
1103  CloseHandle(hFile);
1104  // convert to uint64
1105  return uint64(lpFileSizeHigh.QuadPart);
1106 }
1107 
1108 uint64 TFile::GetCreateTm(const TStr& FNm) {
1109  // open
1110  HANDLE hFile = CreateFile(
1111  FNm.CStr(), // file to open
1112  GENERIC_READ, // open for reading
1113  FILE_SHARE_READ | FILE_SHARE_WRITE, // share for reading
1114  NULL, // default security
1115  OPEN_EXISTING, // existing file only
1116  FILE_ATTRIBUTE_NORMAL, // normal file
1117  NULL); // no attr. template
1118  // check if we could open it
1119  if (hFile == INVALID_HANDLE_VALUE) {
1120  TExcept::Throw("Can not open file " + FNm + "!"); }
1121  // read file times
1122  FILETIME lpCreationTime;
1123  if (!GetFileTime(hFile, &lpCreationTime, NULL, NULL)) {
1124  TExcept::Throw("Can not read time from file " + FNm + "!"); }
1125  // close file
1126  CloseHandle(hFile);
1127  // convert to uint64
1128  TUInt64 UInt64(uint(lpCreationTime.dwHighDateTime),
1129  uint(lpCreationTime.dwLowDateTime));
1130  return UInt64.Val / uint64(10000);
1131 }
1132 
1133 uint64 TFile::GetLastAccessTm(const TStr& FNm) {
1134  // open
1135  HANDLE hFile = CreateFile(
1136  FNm.CStr(), // file to open
1137  GENERIC_READ, // open for reading
1138  FILE_SHARE_READ | FILE_SHARE_WRITE, // share for reading
1139  NULL, // default security
1140  OPEN_EXISTING, // existing file only
1141  FILE_ATTRIBUTE_NORMAL, // normal file
1142  NULL); // no attr. template
1143  // check if we could open it
1144  if (hFile == INVALID_HANDLE_VALUE) {
1145  TExcept::Throw("Can not open file " + FNm + "!"); }
1146  // read file times
1147  FILETIME lpLastAccessTime;
1148  if (!GetFileTime(hFile, NULL, &lpLastAccessTime, NULL)) {
1149  TExcept::Throw("Can not read time from file " + FNm + "!"); }
1150  // close file
1151  CloseHandle(hFile);
1152  // convert to uint64
1153  TUInt64 UInt64(uint(lpLastAccessTime.dwHighDateTime),
1154  uint(lpLastAccessTime.dwLowDateTime));
1155  return UInt64.Val / uint64(10000);
1156 }
1157 
1158 uint64 TFile::GetLastWriteTm(const TStr& FNm) {
1159  // open
1160  HANDLE hFile = CreateFile(
1161  FNm.CStr(), // file to open
1162  GENERIC_READ, // open for reading
1163  FILE_SHARE_READ | FILE_SHARE_WRITE, // share for reading
1164  NULL, // default security
1165  OPEN_EXISTING, // existing file only
1166  FILE_ATTRIBUTE_NORMAL, // normal file
1167  NULL); // no attr. template
1168  // check if we could open it
1169  if (hFile == INVALID_HANDLE_VALUE) {
1170  TExcept::Throw("Can not open file " + FNm + "!"); }
1171  // read file times
1172  FILETIME lpLastWriteTime;
1173  if (!GetFileTime(hFile, NULL, NULL, &lpLastWriteTime)) {
1174  TExcept::Throw("Can not read time from file " + FNm + "!"); }
1175  // close file
1176  CloseHandle(hFile);
1177  // convert to uint64
1178  TUInt64 UInt64(uint(lpLastWriteTime.dwHighDateTime),
1179  uint(lpLastWriteTime.dwLowDateTime));
1180  return UInt64.Val / uint64(10000);
1181 }
1182 
1183 #elif defined(GLib_LINUX)
1184 
1185 uint64 TFile::GetSize(const TStr& FNm) {
1186  Fail; return 0;
1187 }
1188 
1189 uint64 TFile::GetCreateTm(const TStr& FNm) {
1190  return GetLastWriteTm(FNm);
1191 }
1192 
1193 uint64 TFile::GetLastWriteTm(const TStr& FNm) {
1194  struct stat st;
1195  if (stat(FNm.CStr(), &st) != 0) {
1196  TExcept::Throw("Cannot read tile from file " + FNm + "!");
1197  }
1198  return uint64(st.st_mtime);
1199 }
1200 
1201 
1202 #endif
int PutMem(const TMem &Mem)
Definition: fl.cpp:79
#define IAssert(Cond)
Definition: bd.h:262
Definition: bd.h:514
~TFOut()
Definition: fl.cpp:451
int SearchCh(const char &Ch, const int &BChN=0) const
Definition: dt.cpp:1043
TStr GetStr(const int &StrLen)
Definition: fl.cpp:879
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:594
char * CStr()
Definition: bd.h:531
TStr GetStr() const
Definition: dt.h:1105
static PSOut New(const TStr &FNm, const bool &Append=false)
Definition: fl.cpp:442
Definition: xfl.h:30
int Len() const
Definition: dt.h:487
Definition: fl.h:347
TStr GetFNm() const
Definition: fl.cpp:532
int PutStrFmtLn(const char *FmtStr,...)
Definition: fl.cpp:145
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:311
int BfL
Definition: fl.h:420
virtual int PutCh(const char &Ch)=0
int BfL
Definition: fl.h:280
virtual int PutBf(const void *LBf, const TSize &LBfL)=0
static void Rename(const TStr &SrcFNm, const TStr &DstFNm)
Definition: fl.cpp:1060
static bool Exists(const TStr &FNm)
Definition: fl.cpp:941
#define SEEK_END
Definition: fl.cpp:754
TMOut(const TMOut &)
static const TStr GifFExt
Definition: fl.h:567
TStdOut()
Definition: fl.cpp:213
int PutCh(const char &Ch)
Definition: fl.cpp:458
#define forever
Definition: bd.h:6
void AppendBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:636
int Len() const
Definition: dt.h:134
unsigned int uint
Definition: bd.h:11
bool RecAct
Definition: fl.h:495
#define SEEK_CUR
Definition: fl.cpp:753
PSIn GetSIn(const bool &IsCut=true, const int &CutBfL=-1)
Definition: fl.cpp:666
void Flush()
Definition: fl.cpp:851
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:508
bool Empty() const
Definition: dt.h:260
void FillBf()
Definition: fl.cpp:264
#define Fail
Definition: bd.h:238
int FindEol(int &BfN, bool &CrEnd)
Definition: fl.cpp:367
int GetFLen()
Definition: fl.cpp:810
TStr GetUc() const
Definition: dt.h:493
static const char NullCh
Definition: dt.h:943
int PutCh(const char &Ch)
Definition: fl.h:433
bool IsEolnLn() const
Definition: fl.cpp:700
TFileId FileId
Definition: fl.h:493
void Clr()
Definition: dt.h:258
int LnLen
Definition: fl.h:130
void AddCh(const char &Ch, const int &MxLen=-1)
Definition: dt.h:271
TSizeTy Len() const
Returns the number of elements in the vector.
Definition: ds.h:535
TStdIn()
Definition: fl.cpp:63
void MkEolnLn()
Definition: fl.cpp:732
void CutBf(const int &CutBfL)
Definition: fl.cpp:660
TFileId FileId
Definition: fl.h:278
#define SEEK_SET
Definition: fl.cpp:755
void PutSIn(const PSIn &SIn, TCs &Cs)
Definition: fl.cpp:889
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:463
virtual int GetBf(const void *Bf, const TSize &BfL)=0
static const TStr HtmlFExt
Definition: fl.h:565
Definition: fl.h:347
int Len() const
Definition: dt.h:259
TStr GetCrLfLn()
Definition: fl.cpp:686
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:232
~TFIn()
Definition: fl.cpp:305
~TFRnd()
Definition: fl.cpp:784
char PeekCh()
Definition: fl.cpp:589
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:602
int PutSepLn(const int &Lns=0)
Definition: fl.cpp:182
TStr GetFNm() const
Definition: fl.cpp:788
int PutLn(const int &Lns=1)
Definition: fl.cpp:158
Definition: fl.h:275
TStr GetAsStr() const
Definition: fl.cpp:654
Definition: fl.h:40
void LoadCs()
Definition: fl.cpp:28
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:328
char * Bf
Definition: fl.h:323
int GetFPos() const
Definition: fl.cpp:249
Definition: fl.h:384
void FlushBf()
Definition: fl.cpp:410
Definition: fl.h:58
TFileId FileId
Definition: fl.h:322
int UpdateLnLen(const int &StrLen, const bool &ForceInLn=false)
Definition: fl.cpp:70
Definition: dt.h:77
static const char EofCh
Definition: dt.h:947
static uint64 GetSize(const TStr &FNm)
void Flush()
Definition: fl.cpp:475
char * Bf
Definition: fl.h:386
Definition: fl.h:240
static PSIn New(const TStr &FNm)
Definition: fl.cpp:290
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:217
static const int MxMask
Definition: fl.h:13
static const TStr TxtFExt
Definition: fl.h:564
static TCs GetCsFromBf(char *Bf, const int &BfL)
Definition: fl.cpp:12
static void DelWc(const TStr &WcStr, const bool &RecurseDirP=false)
Definition: fl.cpp:1049
static int GetMn(const int &Int1, const int &Int2)
Definition: dt.h:1088
char * CStr()
Definition: dt.h:255
static void Throw(const TStr &MsgStr)
Definition: ut.h:187
Definition: fl.h:347
static TStr GetUniqueFNm(const TStr &FNm)
Definition: fl.cpp:1066
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:224
virtual bool Eof()=0
int BfC
Definition: fl.h:387
void MoveFPos(const int &DFPos)
Definition: fl.cpp:798
static const TStr HtmFExt
Definition: fl.h:566
unsigned long long uint64
Definition: bd.h:38
void Load(bool &Bool)
Definition: fl.h:84
TFRnd(const TFRnd &)
TStr GetStr() const
Definition: dt.h:1187
size_t TSize
Definition: bd.h:58
int PutBool(const bool &Bool)
Definition: fl.cpp:89
static PSIn New(const void *_Bf, const int &_BfL, const bool &TakeBf=false)
Definition: fl.cpp:568
static void Copy(const TStr &SrcFNm, const TStr &DstFNm, const bool &ThrowExceptP=true, const bool &FailIfExistsP=false)
char * Bf
Definition: fl.h:279
static void Del(const TStr &FNm, const bool &ThrowExceptP=true)
Definition: fl.cpp:1039
Definition: fl.h:347
int PutBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:642
int PutSep(const int &NextStrLen=0)
Definition: fl.cpp:170
int PutInt(const int &Int)
Definition: fl.cpp:93
bool Eof()
Definition: fl.h:298
int MxBfL
Definition: fl.h:420
void SetFPos(const int &FPos)
Definition: fl.cpp:792
#define EFailR(Reason)
Definition: bd.h:246
TPt< TSInOut > PSInOut
Definition: fl.h:236
TFileId FileId
Definition: fl.h:351
#define FailR(Reason)
Definition: bd.h:240
void PutCh(const char &Ch)
Definition: fl.h:541
static const TPt< TSOut > StdOut
Definition: fl.h:208
Definition: fl.h:128
int GetRecs()
Definition: fl.cpp:830
bool OwnBf
Definition: fl.h:421
int PutIndent(const int &IndentLev=1)
Definition: fl.cpp:154
int PutFlt(const double &Flt)
Definition: fl.cpp:109
Definition: fl.h:260
static const char LfCh
Definition: dt.h:945
TStr GetStr() const
Definition: dt.h:679
int GetRecN()
Definition: fl.cpp:823
void Save(const bool &Bool)
Definition: fl.h:173
void PutStr(const TStr &Str)
Definition: fl.cpp:864
static PSInOut New(const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
Definition: fl.cpp:496
int BfC
Definition: fl.h:280
Definition: fl.h:347
Definition: dt.h:201
int PutDosLn(const int &Lns=1)
Definition: fl.cpp:164
static const TPt< TSIn > StdIn
Definition: fl.h:116
static const TSize MxBfL
Definition: fl.h:321
void AddBf(char *NewBf, const int &BfS)
Definition: dt.h:275
static TStr GetStrFromFAccess(const TFAccess &FAccess)
Definition: fl.cpp:906
TSIn()
Definition: fl.h:65
char GetCh()
Definition: fl.h:250
int GetBf(const void *LBf, const TSize &LBfL)
Definition: fl.cpp:517
int MxLnLen
Definition: fl.h:130
int GetPos() const
Definition: fl.h:373
Definition: dt.h:412
bool Empty() const
Definition: dt.h:488
static TFAccess GetFAccessFromStr(const TStr &Str)
Definition: fl.cpp:917
int BfL
Definition: fl.h:387
static TStr Fmt(const char *FmtStr,...)
Definition: dt.cpp:1599
int PutStr(const char *CStr)
Definition: fl.cpp:117
PSIn SIn
Definition: fl.h:481
static const char CrCh
Definition: dt.h:946
#define EAssertR(Cond, MsgStr)
Definition: bd.h:283
PSIn GetSIn(const int &SInLen, TCs &Cs)
Definition: fl.cpp:898
static TStr GetStr(const bool &Val)
Definition: dt.h:918
virtual TStr GetSNm() const
Definition: fl.cpp:20
int PutCh(const char &Ch)
Definition: fl.h:268
Definition: bd.h:196
static uint64 GetLastWriteTm(const TStr &FNm)
static uint64 GetCreateTm(const TStr &FNm)
static const int MxBfL
Definition: fl.h:277
TStr GetStr() const
Definition: dt.h:1367
TSOut()
Definition: fl.h:136
int GetSize() const
Definition: fl.cpp:500
TPt< TSIn > PSIn
Definition: fl.h:119
void Resize(const int &ReqLen=-1)
Definition: fl.cpp:610
bool IsCrLfLn() const
Definition: fl.cpp:680
bool Next(TStr &FNm)
TSize BfL
Definition: fl.h:324
char * Bf
Definition: fl.h:419
void SetRecN(const int &RecN)
Definition: fl.cpp:818
virtual char GetCh()=0
TSStr FNm
Definition: fl.h:494
int HdLen
Definition: fl.h:496
virtual char PeekCh()=0
void PutBf(const void *Bf, const TSize &BfL)
Definition: fl.cpp:844
int GetFPos()
Definition: fl.cpp:804
char * CStr()
Definition: dt.h:476
int Len() const
Definition: fl.h:439
virtual int Len() const =0
int PutStrLn(const TStr &Str, const bool &ForceInLn=false)
Definition: fl.h:161
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
Definition: ds.h:559
int GetFLen() const
Definition: fl.cpp:255
Definition: fl.h:11
int PutStrFmt(const char *FmtStr,...)
Definition: fl.cpp:136
void GetBf(void *Bf, const TSize &BfL)
Definition: fl.cpp:837
void InsStr(const int &BChN, const TStr &Str)
Definition: dt.cpp:825
TSOut & operator<<(const bool &Bool)
Definition: fl.h:191
TFAccess
Definition: fl.h:347
int PutUInt(const uint &Int)
Definition: fl.cpp:101
int RecLen
Definition: fl.h:496
bool GetNextLnBf(TChA &LnChA)
Definition: fl.cpp:526
TPt< TSOut > PSOut
Definition: fl.h:211
Definition: fl.h:347
TStr GetEolnLn(const bool &DoAddEoln, const bool &DoCutBf)
Definition: fl.cpp:707
TSStr SNm
Definition: fl.h:43
char GetCh()
Definition: fl.cpp:584
void SetFPos(const int &FPos) const
Definition: fl.cpp:243
TCs Cs
Definition: fl.h:44
Definition: dt.h:1223
static const TStr JarFExt
Definition: fl.h:568
void RefreshFPos()
Definition: fl.cpp:760
int ChangeStr(const TStr &SrcStr, const TStr &DstStr, const int &BChN=0)
Definition: dt.cpp:1130
bool NextLn(TStr &LnStr)
Definition: fl.cpp:740
bool GetNextLn(TStr &LnStr)
Definition: fl.cpp:43
static uint64 GetLastAccessTm(const TStr &FNm)