14 for (
int BfC=0; BfC<BfL; BfC++){Cs+=Bf[BfC];}
30 Cs+=
GetBf(&TestCs,
sizeof(TestCs));
31 EAssertR(CurCs==TestCs,
"Invalid checksum reading '"+
GetSNm()+
"'.");
38 CStr=
new char[CStrLen+1];
39 if (CStrLen>0){
Cs+=
GetBf(CStr, CStrLen);}
53 const char Ch=
GetCh();
54 if (Ch==
'\n'){
return true;}
55 if (Ch==
'\r' &&
PeekCh()==
'\n'){
GetCh();
return true;}
58 return !LnChA.
Empty();
68 TSBase(Str.CStr()), MxLnLen(-1), LnLen(0){}
85 for (
int ChN=0; ChN<Chs; ChN++){Cs+=
PutCh(Ch);}
119 return Cs+
PutBf(CStr,
int(strlen(CStr)));
139 va_start(valist, FmtStr);
140 const int RetVal=vsnprintf(Bf, 10*1024-2, FmtStr, valist);
148 va_start(valist, FmtStr);
149 const int RetVal=vsnprintf(Bf, 10*1024-2, FmtStr, valist);
155 return PutCh(
' ', IndentLev*2);
160 for (
int LnN=0; LnN<Lns; LnN++){Cs+=
PutCh(
'\n');}
190 int CStrLen=int(strlen(CStr));
193 if (CStrLen>0){
Cs+=
PutBf(CStr, CStrLen);}
207 operator<<((
char)SIn.
GetCh());
219 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
220 LBfS+=(((
char*)LBf)[LBfC]=
GetCh());}
234 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
235 LBfS+=
PutCh(((
char*)LBf)[LBfC]);}
246 "Error seeking into file '"+
GetSNm()+
"'.");
250 const int FPos=(int)ftell(
FileId);
259 "Error seeking into file '"+
GetSNm()+
"'.");
267 "Error reading file '"+
GetSNm()+
"'.");
274 TSBase(FNm.CStr()),
TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
277 EAssertR(FileId!=NULL,
"Can not open file '"+FNm+
"'.");
282 TSBase(FNm.CStr()),
TSIn(FNm), FileId(NULL), Bf(NULL), BfC(0), BfL(0){
285 OpenedP=(FileId!=NULL);
294 printf(
"*** Exception: %s\n", Except->GetMsgStr().CStr());
295 EFailR(Except->GetMsgStr());
302 return PSIn(
new TFIn(FNm, OpenedP));
308 if (
Bf!=NULL){
delete[]
Bf;}
314 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
316 LBfS+=((
char*)LBf)[LBfC]=
Bf[
BfC++];}
318 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
319 LBfS+=(((
char*)LBf)[LBfC]=
Bf[
BfC++]);}
355 }
while (Status == 0);
358 return !LnChA.
Empty();
375 if (CrEnd &&
Bf[
BfC]==
'\n') {
394 }
else if (
Bf[
BfC]==
'\n') {
413 "Error writting to the file '"+
GetSNm()+
"'.");
418 TSBase(FNm.CStr()),
TSOut(FNm), FileId(NULL), Bf(NULL), BfL(0){
419 if (FNm.
GetUc()==
"CON"){
430 TSBase(FNm.CStr()),
TSOut(FNm), FileId(NULL), Bf(NULL), BfL(0){
431 if (FNm.
GetUc()==
"CON"){
448 if (OpenedP){
return SOut;}
else {
return NULL;}
453 if (
Bf!=NULL){
delete[]
Bf;}
466 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
467 LBfS+=
PutCh(((
char*)LBf)[LBfC]);}
469 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
470 LBfS+=(
Bf[
BfL++]=((
char*)LBf)[LBfC]);}
501 const int FPos =
GetPos();
503 const int FLen =
GetPos();
510 for (
TSize i = 0; i < LBfL; i++) {
511 LBfS += ((
char *)LBf)[i];
513 IAssert(fwrite(LBf,
sizeof(
char), LBfL,
FileId) == (
size_t) LBfL);
518 IAssert(fread((
void *)LBf,
sizeof(
char), LBfL,
FileId) == (
size_t) LBfL);
520 for (
TSize i = 0; i < LBfL; i++) {
521 LBfS += ((
char *)LBf)[i];
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){
548 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(0){
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);
559 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(0){
564 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(0){
569 return PSIn(
new TMIn(_Bf, _BfL, TakeBf));
597 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
598 LBfS+=(((
char*)LBf)[LBfC]=
Bf[
BfC++]);}
614 if (ReqLen < 0)
Bf=
new char[
MxBfL=1024];
615 else Bf=
new char[MxBfL=ReqLen];
617 if (ReqLen < 0){
MxBfL*=2; }
618 else if (ReqLen <
MxBfL){
return; }
620 char* NewBf=
new char[
MxBfL];
621 memmove(NewBf,
Bf,
BfL);
delete[]
Bf;
Bf=NewBf;
627 Bf(NULL), BfL(0), MxBfL(0), OwnBf(true){
628 MxBfL=_MxBfL>0?_MxBfL:1024;
634 Bf(_Bf), BfL(0), MxBfL(_MxBfL), OwnBf(false){}
638 memcpy(
Bf +
BfL, LBf, LBfL);
645 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
646 LBfS+=
PutCh(((
char*)LBf)[LBfC]);}
648 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
649 LBfS+=(
Bf[
BfL++]=((
char*)LBf)[LBfC]);}
656 for (
int BfC=0; BfC<
BfL; BfC++){ChA+=
Bf[BfC];}
667 IAssert((CutBfL==-1)||((0<=CutBfL)));
675 if (IsCut){
CutBf(SInBfL);}
681 for (
int BfC=0; BfC<
BfL; BfC++){
689 for (
int BfC=0; BfC<
BfL; BfC++){
701 for (
int BfC=0; BfC<
BfL; BfC++){
709 int LnChs=0;
TChA Ln;
710 for (
int BfC=0; BfC<
BfL; BfC++){
713 LnChs++;
if (DoAddEoln){Ln+=Ch;}
715 char NextCh=
Bf[BfC+1];
718 LnChs++;
if (DoAddEoln){Ln+=NextCh;}
741 if (
SIn->
Eof()) {
return false; }
744 if (Ch !=
'\r') { LnChA += Ch; }
746 LnStr = LnChA;
return true;
763 "Error seeking into file '"+
TStr(
FNm)+
"'.");
767 const bool& CreateIfNo,
const int& _HdLen,
const int& _RecLen):
768 FileId(NULL), FNm(_FNm.CStr()),
769 RecAct(false), HdLen(_HdLen), RecLen(_RecLen){
779 if ((
FileId==NULL)&&(CreateIfNo)){
795 "Error seeking into file '"+
TStr(
FNm)+
"'.");
801 "Error seeking into file '"+
TStr(
FNm)+
"'.");
805 int FPos= (int) ftell(
FileId);
814 "Error seeking into file '"+
TStr(
FNm)+
"'.");
840 fread(Bf, 1, BfL,
FileId)==BfL,
841 "Error reading file '"+
TStr(
FNm)+
"'.");
847 fwrite(Bf, 1, BfL,
FileId)==BfL,
848 "Error writting to the file '"+
TStr(
FNm)+
"'.");
857 char* CStr=
new char[Chs];
858 for (
int ChN=0; ChN<Chs; ChN++){CStr[ChN]=Ch;}
869 IsOk=
false;
TStr Str;
871 char* CStr=
new char[StrLen+1];
872 GetBf(CStr, StrLen+1);
873 if (CStr[StrLen+1-1]==
TCh::NullCh){IsOk=
true; Str=CStr;}
881 char* CStr=
new char[StrLen+1];
882 GetBf(CStr, StrLen+1);
891 char* Bf=
new char[BfL];
899 char* Bf=
new char[BfL];
919 if (UcStr==
"CREATE"){
return faCreate;}
920 if (UcStr==
"UPDATE"){
return faUpdate;}
921 if (UcStr==
"APPEND"){
return faAppend;}
922 if (UcStr==
"READONLY"){
return faRdOnly;}
926 if (UcStr==
"CONT"){
return faUpdate;}
927 if (UcStr==
"CONTINUE"){
return faUpdate;}
942 if (FNm.
Empty()) {
return false; }
944 TFIn FIn(FNm, DoExists);
948 #if defined(GLib_WIN32)
951 const bool& ThrowExceptP,
const bool& FailIfExistsP){
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()));
960 CopyFile(SrcFNm.
CStr(), DstFNm.
CStr(), FailIfExistsP);
964 #elif defined(GLib_LINUX)
967 const bool& ThrowExceptP,
const bool& FailIfExistsP){
970 void *source, *target;
972 if( (input = open(SrcFNm.
CStr(), O_RDONLY)) == -1) {
975 "Error copying file '%s' to '%s': cannot open source file for reading.",
983 if( (output = open(DstFNm.
CStr(), O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1) {
988 "Error copying file '%s' to '%s': cannot open destination file for writing.",
996 filesize = lseek(input, 0,
SEEK_END);
997 lseek(output, filesize - 1,
SEEK_SET);
998 write(output,
'\0', 1);
1000 if((source = mmap(0, filesize, PROT_READ, MAP_SHARED, input, 0)) == (
void *) -1) {
1005 "Error copying file '%s' to '%s': cannot mmap input file.",
1012 if((target = mmap(0, filesize, PROT_WRITE, MAP_SHARED, output, 0)) == (
void *) -1) {
1013 munmap(source, filesize);
1018 "Error copying file '%s' to '%s': cannot mmap output file.",
1025 memcpy(target, source, filesize);
1027 munmap(source, filesize);
1028 munmap(target, filesize);
1042 remove(FNm.
CStr())==0,
1043 "Error removing file '"+FNm+
"'.");
1053 while (FFile.
Next(FNm)){
1056 for (
int FNmN=0; FNmN<FNmV.
Len(); FNmN++){
1057 Del(FNmV[FNmN],
false);}
1062 rename(SrcFNm.
CStr(), DstFNm.
CStr())==0,
1063 "Error renaming file '"+SrcFNm+
"' to "+DstFNm+
"'.");
1071 for (ch = FNm.
Len()-1; ch >= 0; ch--)
if (FNm[ch] ==
'.')
break;
1072 if (ch != -1) TmpFNm.
InsStr(ch,
".#");
1073 else TmpFNm +=
".#";
1087 HANDLE hFile = CreateFile(
1090 FILE_SHARE_READ | FILE_SHARE_WRITE,
1093 FILE_ATTRIBUTE_NORMAL,
1096 if (hFile == INVALID_HANDLE_VALUE) {
1099 LARGE_INTEGER lpFileSizeHigh;
1100 if (!GetFileSizeEx(hFile, &lpFileSizeHigh)) {
1105 return uint64(lpFileSizeHigh.QuadPart);
1110 HANDLE hFile = CreateFile(
1113 FILE_SHARE_READ | FILE_SHARE_WRITE,
1116 FILE_ATTRIBUTE_NORMAL,
1119 if (hFile == INVALID_HANDLE_VALUE) {
1122 FILETIME lpCreationTime;
1123 if (!GetFileTime(hFile, &lpCreationTime, NULL, NULL)) {
1128 TUInt64 UInt64(
uint(lpCreationTime.dwHighDateTime),
1129 uint(lpCreationTime.dwLowDateTime));
1130 return UInt64.Val /
uint64(10000);
1135 HANDLE hFile = CreateFile(
1138 FILE_SHARE_READ | FILE_SHARE_WRITE,
1141 FILE_ATTRIBUTE_NORMAL,
1144 if (hFile == INVALID_HANDLE_VALUE) {
1147 FILETIME lpLastAccessTime;
1148 if (!GetFileTime(hFile, NULL, &lpLastAccessTime, NULL)) {
1153 TUInt64 UInt64(
uint(lpLastAccessTime.dwHighDateTime),
1154 uint(lpLastAccessTime.dwLowDateTime));
1155 return UInt64.Val /
uint64(10000);
1160 HANDLE hFile = CreateFile(
1163 FILE_SHARE_READ | FILE_SHARE_WRITE,
1166 FILE_ATTRIBUTE_NORMAL,
1169 if (hFile == INVALID_HANDLE_VALUE) {
1172 FILETIME lpLastWriteTime;
1173 if (!GetFileTime(hFile, NULL, NULL, &lpLastWriteTime)) {
1178 TUInt64 UInt64(
uint(lpLastWriteTime.dwHighDateTime),
1179 uint(lpLastWriteTime.dwLowDateTime));
1180 return UInt64.Val /
uint64(10000);
1183 #elif defined(GLib_LINUX)
1195 if (stat(FNm.
CStr(), &st) != 0) {
1198 return uint64(st.st_mtime);
int PutMem(const TMem &Mem)
int SearchCh(const char &Ch, const int &BChN=0) const
TStr GetStr(const int &StrLen)
int GetBf(const void *LBf, const TSize &LBfL)
static PSOut New(const TStr &FNm, const bool &Append=false)
int PutStrFmtLn(const char *FmtStr,...)
int GetBf(const void *LBf, const TSize &LBfL)
virtual int PutCh(const char &Ch)=0
virtual int PutBf(const void *LBf, const TSize &LBfL)=0
static void Rename(const TStr &SrcFNm, const TStr &DstFNm)
static bool Exists(const TStr &FNm)
static const TStr GifFExt
int PutCh(const char &Ch)
void AppendBf(const void *LBf, const TSize &LBfL)
PSIn GetSIn(const bool &IsCut=true, const int &CutBfL=-1)
int PutBf(const void *LBf, const TSize &LBfL)
int FindEol(int &BfN, bool &CrEnd)
int PutCh(const char &Ch)
void AddCh(const char &Ch, const int &MxLen=-1)
TSizeTy Len() const
Returns the number of elements in the vector.
void CutBf(const int &CutBfL)
void PutSIn(const PSIn &SIn, TCs &Cs)
int PutBf(const void *LBf, const TSize &LBfL)
virtual int GetBf(const void *Bf, const TSize &BfL)=0
static const TStr HtmlFExt
int PutBf(const void *LBf, const TSize &LBfL)
bool GetNextLnBf(TChA &LnChA)
int PutSepLn(const int &Lns=0)
int PutLn(const int &Lns=1)
bool GetNextLnBf(TChA &LnChA)
int UpdateLnLen(const int &StrLen, const bool &ForceInLn=false)
static uint64 GetSize(const TStr &FNm)
static PSIn New(const TStr &FNm)
int GetBf(const void *LBf, const TSize &LBfL)
static const TStr TxtFExt
static TCs GetCsFromBf(char *Bf, const int &BfL)
static void DelWc(const TStr &WcStr, const bool &RecurseDirP=false)
static int GetMn(const int &Int1, const int &Int2)
static void Throw(const TStr &MsgStr)
static TStr GetUniqueFNm(const TStr &FNm)
bool GetNextLnBf(TChA &LnChA)
void MoveFPos(const int &DFPos)
static const TStr HtmFExt
unsigned long long uint64
int PutBool(const bool &Bool)
static PSIn New(const void *_Bf, const int &_BfL, const bool &TakeBf=false)
static void Copy(const TStr &SrcFNm, const TStr &DstFNm, const bool &ThrowExceptP=true, const bool &FailIfExistsP=false)
static void Del(const TStr &FNm, const bool &ThrowExceptP=true)
int PutBf(const void *LBf, const TSize &LBfL)
int PutSep(const int &NextStrLen=0)
int PutInt(const int &Int)
void SetFPos(const int &FPos)
void PutCh(const char &Ch)
static const TPt< TSOut > StdOut
int PutIndent(const int &IndentLev=1)
int PutFlt(const double &Flt)
void Save(const bool &Bool)
void PutStr(const TStr &Str)
static PSInOut New(const TStr &FNm, const TFAccess &FAccess, const bool &CreateIfNo)
int PutDosLn(const int &Lns=1)
static const TPt< TSIn > StdIn
void AddBf(char *NewBf, const int &BfS)
static TStr GetStrFromFAccess(const TFAccess &FAccess)
int GetBf(const void *LBf, const TSize &LBfL)
static TFAccess GetFAccessFromStr(const TStr &Str)
static TStr Fmt(const char *FmtStr,...)
int PutStr(const char *CStr)
#define EAssertR(Cond, MsgStr)
PSIn GetSIn(const int &SInLen, TCs &Cs)
static TStr GetStr(const bool &Val)
virtual TStr GetSNm() const
int PutCh(const char &Ch)
static uint64 GetLastWriteTm(const TStr &FNm)
static uint64 GetCreateTm(const TStr &FNm)
void Resize(const int &ReqLen=-1)
void SetRecN(const int &RecN)
void PutBf(const void *Bf, const TSize &BfL)
virtual int Len() const =0
int PutStrLn(const TStr &Str, const bool &ForceInLn=false)
TSizeTy Add()
Adds a new element at the end of the vector, after its current last element.
int PutStrFmt(const char *FmtStr,...)
void GetBf(void *Bf, const TSize &BfL)
void InsStr(const int &BChN, const TStr &Str)
TSOut & operator<<(const bool &Bool)
int PutUInt(const uint &Int)
bool GetNextLnBf(TChA &LnChA)
TStr GetEolnLn(const bool &DoAddEoln, const bool &DoCutBf)
void SetFPos(const int &FPos) const
static const TStr JarFExt
int ChangeStr(const TStr &SrcStr, const TStr &DstStr, const int &BChN=0)
bool GetNextLn(TStr &LnStr)
static uint64 GetLastAccessTm(const TStr &FNm)