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];
539 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(_BfL), IsMemoryMapped(false){
543 Bf=
new char[
static_cast<size_t>(
BfL)]; memmove(
Bf, _Bf, static_cast<size_t>(
BfL));
548 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
549 BfL=SIn.
Len();
Bf=
new char[
static_cast<size_t>(
BfL)];
554 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
555 BfL=
uint64(strlen(CStr));
Bf=
new char[
static_cast<size_t>(
BfL+1)]; strcpy(
Bf, CStr);
560 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(0){
561 if (FromFile ==
false) {
562 BfL=Str.
Len();
Bf=
new char[
static_cast<size_t>(
BfL)]; strncpy(
Bf, Str.
CStr(),
static_cast<size_t>(
BfL));
572 FileId=fopen(FNm.
CStr(),
"rb");
575 EAssertR(FileId!=NULL,
"Can not open file '"+FNm+
"'.");
579 "Error seeking into file '"+
TStr(FNm)+
"'.");
580 FLen=(
uint64)ftell(FileId);
583 "Error seeking into file '"+
TStr(FNm)+
"'.");
587 mapped = (
char *) mmap (0, FLen, PROT_READ, MAP_PRIVATE, fd, 0);
590 if (mapped == MAP_FAILED) {
591 printf(
"mmap failed: %d %s\n", fd, strerror (errno));
602 TExcept::Throw(
"TMIn::TMIn(TStr, Bool): GLib_LINUX undefined.\n");
608 TSBase(
"Input-Memory"),
TSIn(
"Input-Memory"), Bf(NULL), BfC(0), BfL(0), IsMemoryMapped(false){
609 BfL=ChA.
Len();
Bf=
new char[
static_cast<size_t>(
BfL)]; strncpy(
Bf, ChA.
CStr(),
static_cast<size_t>(
BfL));
613 return PSIn(
new TMIn(_Bf, _BfL, TakeBf));
625 return new TMIn(Str, FromFile);
658 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
659 LBfS+=(((
char*)LBf)[LBfC]=
Bf[
BfC++]);}
676 if (CrEnd &&
Bf[
BfC]==
'\n') {
695 }
else if (
Bf[
BfC]==
'\n') {
731 for (
uint64 i = Lb; i < Ub; i++) {
740 while (Ind > 0 &&
Bf[Ind-1] !=
'\n') {
747 while (Ind <
BfL &&
Bf[Ind] !=
'\n') {
750 if (Ind ==
BfL) Ind--;
760 while (BfC <
BfL &&
Bf[BfC] !=
'\n') {
773 if (ReqLen < 0)
Bf=
new char[
MxBfL=1024];
774 else Bf=
new char[MxBfL=ReqLen];
776 if (ReqLen < 0){
MxBfL*=2; }
777 else if (ReqLen <
MxBfL){
return; }
779 char* NewBf=
new char[
MxBfL];
780 memmove(NewBf,
Bf,
BfL);
delete[]
Bf;
Bf=NewBf;
786 Bf(NULL), BfL(0), MxBfL(0), OwnBf(true){
787 MxBfL=_MxBfL>0?_MxBfL:1024;
793 Bf(_Bf), BfL(0), MxBfL(_MxBfL), OwnBf(false){}
797 memcpy(
Bf +
BfL, LBf, LBfL);
804 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
805 LBfS+=
PutCh(((
char*)LBf)[LBfC]);}
807 for (
TSize LBfC=0; LBfC<LBfL; LBfC++){
808 LBfS+=(
Bf[
BfL++]=((
char*)LBf)[LBfC]);}
815 for (
int BfC=0; BfC<
BfL; BfC++){ChA+=
Bf[BfC];}
826 IAssert((CutBfL==-1)||((0<=CutBfL)));
834 if (IsCut){
CutBf(SInBfL);}
840 for (
int BfC=0; BfC<
BfL; BfC++){
848 for (
int BfC=0; BfC<
BfL; BfC++){
860 for (
int BfC=0; BfC<
BfL; BfC++){
868 int LnChs=0;
TChA Ln;
869 for (
int BfC=0; BfC<
BfL; BfC++){
872 LnChs++;
if (DoAddEoln){Ln+=Ch;}
874 char NextCh=
Bf[BfC+1];
877 LnChs++;
if (DoAddEoln){Ln+=NextCh;}
900 if (
SIn->
Eof()) {
return false; }
903 if (Ch !=
'\r') { LnChA += Ch; }
905 LnStr = LnChA;
return true;
922 "Error seeking into file '"+
TStr(
FNm)+
"'.");
926 const bool& CreateIfNo,
const int& _HdLen,
const int& _RecLen):
927 FileId(NULL), FNm(_FNm.CStr()),
928 RecAct(false), HdLen(_HdLen), RecLen(_RecLen){
938 if ((
FileId==NULL)&&(CreateIfNo)){
954 "Error seeking into file '"+
TStr(
FNm)+
"'.");
960 "Error seeking into file '"+
TStr(
FNm)+
"'.");
964 int FPos= (int) ftell(
FileId);
973 "Error seeking into file '"+
TStr(
FNm)+
"'.");
999 fread(Bf, 1, BfL,
FileId)==BfL,
1000 "Error reading file '"+
TStr(
FNm)+
"'.");
1006 fwrite(Bf, 1, BfL,
FileId)==BfL,
1007 "Error writting to the file '"+
TStr(
FNm)+
"'.");
1016 char* CStr=
new char[Chs];
1017 for (
int ChN=0; ChN<Chs; ChN++){CStr[ChN]=Ch;}
1028 IsOk=
false;
TStr Str;
1030 char* CStr=
new char[StrLen+1];
1031 GetBf(CStr, StrLen+1);
1032 if (CStr[StrLen+1-1]==
TCh::NullCh){IsOk=
true; Str=CStr;}
1040 char* CStr=
new char[StrLen+1];
1041 GetBf(CStr, StrLen+1);
1050 char* Bf=
new char[BfL];
1051 SIn->
GetBf(Bf, BfL);
1058 char* Bf=
new char[BfL];
1078 if (UcStr==
"CREATE"){
return faCreate;}
1079 if (UcStr==
"UPDATE"){
return faUpdate;}
1080 if (UcStr==
"APPEND"){
return faAppend;}
1081 if (UcStr==
"READONLY"){
return faRdOnly;}
1082 if (UcStr==
"RESTORE"){
return faRestore;}
1084 if (UcStr==
"NEW"){
return faCreate;}
1085 if (UcStr==
"CONT"){
return faUpdate;}
1086 if (UcStr==
"CONTINUE"){
return faUpdate;}
1088 if (UcStr==
"RESTORE"){
return faRestore;}
1101 if (FNm.
Empty()) {
return false; }
1103 TFIn FIn(FNm, DoExists);
1107 #if defined(GLib_WIN32)
1110 const bool& ThrowExceptP,
const bool& FailIfExistsP){
1112 if (CopyFile(SrcFNm.
CStr(), DstFNm.
CStr(), FailIfExistsP) == 0) {
1113 int ErrorCode = (int)GetLastError();
1115 "Error %d copying file '%s' to '%s'.",
1116 ErrorCode, SrcFNm.
CStr(), DstFNm.
CStr()));
1119 CopyFile(SrcFNm.
CStr(), DstFNm.
CStr(), FailIfExistsP);
1123 #elif defined(GLib_LINUX)
1126 const bool& ThrowExceptP,
const bool& FailIfExistsP){
1129 void *source, *target;
1131 if( (input = open(SrcFNm.
CStr(), O_RDONLY)) == -1) {
1134 "Error copying file '%s' to '%s': cannot open source file for reading.",
1142 if( (output = open(DstFNm.
CStr(), O_RDWR | O_CREAT | O_TRUNC, 0666)) == -1) {
1147 "Error copying file '%s' to '%s': cannot open destination file for writing.",
1155 filesize = lseek(input, 0,
SEEK_END);
1156 lseek(output, filesize - 1,
SEEK_SET);
1157 write(output,
'\0', 1);
1159 if((source = mmap(0, filesize, PROT_READ, MAP_SHARED, input, 0)) == (
void *) -1) {
1164 "Error copying file '%s' to '%s': cannot mmap input file.",
1171 if((target = mmap(0, filesize, PROT_WRITE, MAP_SHARED, output, 0)) == (
void *) -1) {
1172 munmap(source, filesize);
1177 "Error copying file '%s' to '%s': cannot mmap output file.",
1184 memcpy(target, source, filesize);
1186 munmap(source, filesize);
1187 munmap(target, filesize);
1201 remove(FNm.
CStr())==0,
1202 "Error removing file '"+FNm+
"'.");
1212 while (FFile.
Next(FNm)){
1215 for (
int FNmN=0; FNmN<FNmV.
Len(); FNmN++){
1216 Del(FNmV[FNmN],
false);}
1221 rename(SrcFNm.
CStr(), DstFNm.
CStr())==0,
1222 "Error renaming file '"+SrcFNm+
"' to "+DstFNm+
"'.");
1230 for (ch = FNm.
Len()-1; ch >= 0; ch--)
if (FNm[ch] ==
'.')
break;
1231 if (ch != -1) TmpFNm.
InsStr(ch,
".#");
1232 else TmpFNm +=
".#";
1246 HANDLE hFile = CreateFile(
1249 FILE_SHARE_READ | FILE_SHARE_WRITE,
1252 FILE_ATTRIBUTE_NORMAL,
1255 if (hFile == INVALID_HANDLE_VALUE) {
1258 LARGE_INTEGER lpFileSizeHigh;
1259 if (!GetFileSizeEx(hFile, &lpFileSizeHigh)) {
1264 return uint64(lpFileSizeHigh.QuadPart);
1269 HANDLE hFile = CreateFile(
1272 FILE_SHARE_READ | FILE_SHARE_WRITE,
1275 FILE_ATTRIBUTE_NORMAL,
1278 if (hFile == INVALID_HANDLE_VALUE) {
1281 FILETIME lpCreationTime;
1282 if (!GetFileTime(hFile, &lpCreationTime, NULL, NULL)) {
1287 TUInt64 UInt64(
uint(lpCreationTime.dwHighDateTime),
1288 uint(lpCreationTime.dwLowDateTime));
1289 return UInt64.Val /
uint64(10000);
1294 HANDLE hFile = CreateFile(
1297 FILE_SHARE_READ | FILE_SHARE_WRITE,
1300 FILE_ATTRIBUTE_NORMAL,
1303 if (hFile == INVALID_HANDLE_VALUE) {
1306 FILETIME lpLastAccessTime;
1307 if (!GetFileTime(hFile, NULL, &lpLastAccessTime, NULL)) {
1312 TUInt64 UInt64(
uint(lpLastAccessTime.dwHighDateTime),
1313 uint(lpLastAccessTime.dwLowDateTime));
1314 return UInt64.Val /
uint64(10000);
1319 HANDLE hFile = CreateFile(
1322 FILE_SHARE_READ | FILE_SHARE_WRITE,
1325 FILE_ATTRIBUTE_NORMAL,
1328 if (hFile == INVALID_HANDLE_VALUE) {
1331 FILETIME lpLastWriteTime;
1332 if (!GetFileTime(hFile, NULL, NULL, &lpLastWriteTime)) {
1337 TUInt64 UInt64(
uint(lpLastWriteTime.dwHighDateTime),
1338 uint(lpLastWriteTime.dwLowDateTime));
1339 return UInt64.Val /
uint64(10000);
1342 #elif defined(GLib_LINUX)
1354 if (stat(FNm.
CStr(), &st) != 0) {
1357 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)
static bool IsHashCh(const char &Ch)
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)
void SkipCommentLines()
Move stream pointer along until a non commented line is found.
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 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)
uint64 CountNewLinesInRange(uint64 Lb, uint64 Ub)
Finds number of new line chars in interval [Lb, Ub)
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 FindEol(uint64 &BfN, bool &CrEnd)
int PutIndent(const int &IndentLev=1)
static PSIn New(const void *_Bf, const uint64 &_BfL, const bool &TakeBf=false)
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)
uint64 GetLineEndPos(uint64 Ind)
Finds end of line in which Ind is present.
uint64 GetLineStartPos(uint64 Ind)
Finds beginning of line in which Ind is present.
int PutDosLn(const int &Lns=1)
char * GetLine(uint64 Ind)
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)