diff options
Diffstat (limited to 'src/kvilib/file/kvi_fileutils.cpp')
-rw-r--r-- | src/kvilib/file/kvi_fileutils.cpp | 204 |
1 files changed, 102 insertions, 102 deletions
diff --git a/src/kvilib/file/kvi_fileutils.cpp b/src/kvilib/file/kvi_fileutils.cpp index 648d9125..1ad09d60 100644 --- a/src/kvilib/file/kvi_fileutils.cpp +++ b/src/kvilib/file/kvi_fileutils.cpp @@ -31,18 +31,18 @@ #include "kvi_file.h" #include "kvi_malloc.h" -#include <qdir.h> -#include <qfileinfo.h> -#include <qglobal.h> -#include <qtextcodec.h> -#include <qtextstream.h> +#include <tqdir.h> +#include <tqfileinfo.h> +#include <tqglobal.h> +#include <tqtextcodec.h> +#include <tqtextstream.h> namespace KviFileUtils { /* WORKING CODE BUT UNUSED FOR NOW - bool readLine(QFile * f,QString &szBuffer,bool bClearBuffer) + bool readLine(TQFile * f,TQString &szBuffer,bool bClearBuffer) { // FIXME: Should this assume UTF8 encoding ? char tmp_buf[256]; @@ -60,7 +60,7 @@ namespace KviFileUtils if(tmp_buf[255] == '\r')cur_len--; //Ignore CR... int lastlen = szBuffer.length(); szBuffer.setLength(lastlen + cur_len); - QChar *p1 = szBuffer.unicode() + lastlen; + TQChar *p1 = szBuffer.tqunicode() + lastlen; char * p2 = tmp_buf; for(int i=0;i<cur_len;i++)*p1++ = *p2++; cur_len = 0; @@ -76,16 +76,16 @@ namespace KviFileUtils if(tmp_buf[cur_len - 1] == '\r')cur_len--; //Ignore CR... int lastlen = szBuffer.length(); szBuffer.setLength(lastlen + cur_len); - QChar *p1 = szBuffer.unicode() + lastlen; + TQChar *p1 = szBuffer.tqunicode() + lastlen; char * p2 = tmp_buf; for(int i=0;i<cur_len;i++)*p1++ = *p2++; } return (ch == '\n'); //more data to read else a broken file or EOF } - bool loadFileStripCR(const QString &szPath,QString &szBuffer) + bool loadFileStripCR(const TQString &szPath,TQString &szBuffer) { - QFile f(szPath); + TQFile f(szPath); if(!f.open(IO_ReadOnly))return false; szBuffer = ""; while(readLine(&f,szBuffer,false)) @@ -97,18 +97,18 @@ namespace KviFileUtils } */ - bool makeDir(const QString &szPath) + bool makeDir(const TQString &szPath) { - QDir d; - QString dir = KviQString::trimmed(szPath); + TQDir d; + TQString dir = KviTQString::trimmed(szPath); adjustFilePath(dir); - QString createdDir; + TQString createdDir; #ifdef COMPILE_ON_WINDOWS #ifdef COMPILE_USE_QT4 int idx = dir.indexOf(':'); #else - int idx = dir.find(':'); + int idx = dir.tqfind(':'); #endif if(idx == 1) { @@ -117,44 +117,44 @@ namespace KviFileUtils } #endif - KviQString::stripLeft(dir,KVI_PATH_SEPARATOR_CHAR); + KviTQString::stripLeft(dir,KVI_PATH_SEPARATOR_CHAR); while(!dir.isEmpty()) { createdDir += KVI_PATH_SEPARATOR; - createdDir += KviQString::getToken(dir,KVI_PATH_SEPARATOR_CHAR); + createdDir += KviTQString::getToken(dir,KVI_PATH_SEPARATOR_CHAR); if(!directoryExists(createdDir)) { if(!d.mkdir(createdDir)) { - debug("Can't create directory %s",KviQString::toUtf8(createdDir).data()); + debug("Can't create directory %s",KviTQString::toUtf8(createdDir).data()); return false; } } - KviQString::stripLeft(dir,KVI_PATH_SEPARATOR_CHAR); + KviTQString::stripLeft(dir,KVI_PATH_SEPARATOR_CHAR); } return true; } bool makeDir(const char* path) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return makeDir(szPath); } - bool renameFile(const QString &szSrc,const QString &szDst) + bool renameFile(const TQString &szSrc,const TQString &szDst) { - QDir d; + TQDir d; return d.rename(szSrc,szDst); } bool renameFile(const char* path,const char* path2) { - QString szPath=QString::fromUtf8(path); - QString szPath2=QString::fromUtf8(path2); + TQString szPath=TQString::fromUtf8(path); + TQString szPath2=TQString::fromUtf8(path2); return renameFile(szPath,szPath2); } - bool copyFile(const QString &szSrc,const QString &szDst) + bool copyFile(const TQString &szSrc,const TQString &szDst) { KviFile f1(szSrc); if(!f1.openForReading())return false; @@ -183,139 +183,139 @@ namespace KviFileUtils bool copyFile(const char* path,const char* path2) { - QString szPath=QString::fromUtf8(path); - QString szPath2=QString::fromUtf8(path2); + TQString szPath=TQString::fromUtf8(path); + TQString szPath2=TQString::fromUtf8(path2); return copyFile(szPath,szPath2); } - bool loadFile(const QString &szPath,QString &szBuffer,bool bUtf8) + bool loadFile(const TQString &szPath,TQString &szBuffer,bool bUtf8) { KviFile f(szPath); if(!f.openForReading())return false; if(bUtf8) { - QByteArray ba = f.readAll(); - szBuffer = QString::fromUtf8(ba.data(),ba.size()); + TQByteArray ba = f.readAll(); + szBuffer = TQString::fromUtf8(ba.data(),ba.size()); //debug("BUFFERLEN: %d",szBuffer.length()); } else { - szBuffer = QString(f.readAll()); + szBuffer = TQString(f.readAll()); } return true; } - bool loadFile(const char* path,QString &szBuffer,bool bUtf8) + bool loadFile(const char* path,TQString &szBuffer,bool bUtf8) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return loadFile(szPath,szBuffer,bUtf8); } - void adjustFilePath(QString &szPath) + void adjustFilePath(TQString &szPath) { #ifdef COMPILE_ON_WINDOWS - szPath.replace('/',"\\"); + szPath.tqreplace('/',"\\"); #ifdef COMPILE_USE_QT4 - szPath.replace("\\\\","\\"); + szPath.tqreplace("\\\\","\\"); #else - while(szPath.find("\\\\") != -1)szPath.replace("\\\\","\\"); + while(szPath.tqfind("\\\\") != -1)szPath.tqreplace("\\\\","\\"); #endif // FIXME: Use the default drive here ? if(szPath.startsWith("\\"))szPath.prepend("C:"); #else - szPath.replace('\\',"/"); + szPath.tqreplace('\\',"/"); #ifdef COMPILE_USE_QT4 - szPath.replace("//","/"); + szPath.tqreplace("//","/"); #else - while(KviQString::find(szPath,"//") != -1)szPath.replace("//","/"); + while(KviTQString::tqfind(szPath,"//") != -1)szPath.tqreplace("//","/"); #endif // deal with windows paths - if((szPath.length() > 2) && (szPath.at(0) != QChar('/'))) + if((szPath.length() > 2) && (szPath.at(0) != TQChar('/'))) { - if((szPath.at(1) == QChar(':')) && (szPath.at(2) == QChar('/'))) + if((szPath.at(1) == TQChar(':')) && (szPath.at(2) == TQChar('/'))) { szPath.remove(0,2); } } #ifdef COMPILE_USE_QT4 - szPath=QDir::cleanPath(szPath); + szPath=TQDir::cleanPath(szPath); #else - szPath=QDir::cleanDirPath(szPath); + szPath=TQDir::cleanDirPath(szPath); #endif #endif } - bool directoryExists(const QString &szPath) + bool directoryExists(const TQString &szPath) { - QFileInfo f(szPath); + TQFileInfo f(szPath); return (f.exists() && f.isDir()); } bool directoryExists(const char* path) { - QString szPath=QString::fromUtf8(path); - QFileInfo f(szPath); + TQString szPath=TQString::fromUtf8(path); + TQFileInfo f(szPath); return (f.exists() && f.isDir()); } - bool fileExists(const QString &szPath) + bool fileExists(const TQString &szPath) { - QFileInfo f(szPath); + TQFileInfo f(szPath); return (f.exists() && f.isFile()); } bool fileExists(const char* path) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return fileExists(szPath); } - bool removeFile(const QString &szPath) + bool removeFile(const TQString &szPath) { - QDir d; + TQDir d; return d.remove(szPath); } bool removeFile(const char* path) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return removeFile(szPath); } - bool removeDir(const QString &szPath) + bool removeDir(const TQString &szPath) { - QDir d; + TQDir d; return d.rmdir(szPath); } bool removeDir(const char* path) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return removeDir(szPath); } - bool deleteDir(const QString &szPath) + bool deleteDir(const TQString &szPath) { - QDir d(szPath); - QStringList sl = d.entryList(QDir::Dirs); - QStringList::Iterator it; + TQDir d(szPath); + TQStringList sl = d.entryList(TQDir::Dirs); + TQStringList::Iterator it; for(it=sl.begin();it != sl.end();it++) { - QString szSubdir = *it; - if(!(KviQString::equalCS(szSubdir,"..") || KviQString::equalCS(szSubdir,"."))) + TQString szSubdir = *it; + if(!(KviTQString::equalCS(szSubdir,"..") || KviTQString::equalCS(szSubdir,"."))) { - QString szSubPath = szPath; - KviQString::ensureLastCharIs(szSubPath,QChar(KVI_PATH_SEPARATOR_CHAR)); + TQString szSubPath = szPath; + KviTQString::ensureLastCharIs(szSubPath,TQChar(KVI_PATH_SEPARATOR_CHAR)); szSubPath += szSubdir; if(!KviFileUtils::deleteDir(szSubPath)) return false; } } - sl = d.entryList(QDir::Files); + sl = d.entryList(TQDir::Files); for(it=sl.begin();it != sl.end();it++) { - QString szFilePath = szPath; - KviQString::ensureLastCharIs(szFilePath,QChar(KVI_PATH_SEPARATOR_CHAR)); + TQString szFilePath = szPath; + KviTQString::ensureLastCharIs(szFilePath,TQChar(KVI_PATH_SEPARATOR_CHAR)); szFilePath += *it; if(!KviFileUtils::removeFile(szFilePath)) return false; @@ -324,39 +324,39 @@ namespace KviFileUtils return KviFileUtils::removeDir(szPath); } - bool writeFile(const QString &szPath,const QString &szData,bool bAppend) + bool writeFile(const TQString &szPath,const TQString &szData,bool bAppend) { KviFile f(szPath); if(!f.openForWriting(bAppend))return false; - KviQCString szTmp = KviQString::toUtf8(szData); + KviTQCString szTmp = KviTQString::toUtf8(szData); if(!szTmp.data())return true; if(f.writeBlock(szTmp.data(),szTmp.length()) != ((int)(szTmp.length())))return false; return true; } - bool writeFile(const char* path,const QString &szData,bool bAppend) + bool writeFile(const char* path,const TQString &szData,bool bAppend) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return writeFile(szPath,szData,bAppend); } - bool writeFileLocal8Bit(const QString &szPath,const QString &szData,bool bAppend) + bool writeFileLocal8Bit(const TQString &szPath,const TQString &szData,bool bAppend) { KviFile f(szPath); if(!f.openForWriting(bAppend))return false; - KviQCString szTmp = QTextCodec::codecForLocale()->fromUnicode(szData); + KviTQCString szTmp = TQTextCodec::codecForLocale()->fromUnicode(szData); if(!szTmp.data())return true; if(f.writeBlock(szTmp.data(),szTmp.length()) != ((int)(szTmp.length())))return false; return true; } - bool writeFileLocal8Bit(const char* path,const QString &szData,bool bAppend) + bool writeFileLocal8Bit(const char* path,const TQString &szData,bool bAppend) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return writeFileLocal8Bit(szPath,szData,bAppend); } - bool readFile(const QString &szPath,QString &szBuffer,unsigned int uMaxSize) + bool readFile(const TQString &szPath,TQString &szBuffer,unsigned int uMaxSize) { KviFile f(szPath); if(!f.openForReading())return false; @@ -375,40 +375,40 @@ namespace KviFileUtils return false; } buf[f.size()] = '\0'; - szBuffer = QString::fromUtf8(buf); + szBuffer = TQString::fromUtf8(buf); delete[] buf; return true; } - bool readFile(const char* path,QString &szBuffer,unsigned int uMaxSize) + bool readFile(const char* path,TQString &szBuffer,unsigned int uMaxSize) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return readFile(szPath,szBuffer,uMaxSize); } - QString extractFileName(const QString &szFileNameWithPath) + TQString extractFileName(const TQString &szFileNameWithPath) { - return QFileInfo(szFileNameWithPath).fileName(); + return TQFileInfo(szFileNameWithPath).fileName(); } - QString extractFilePath(const QString &szFileNameWithPath) + TQString extractFilePath(const TQString &szFileNameWithPath) { - return QFileInfo(szFileNameWithPath).dirPath(true); + return TQFileInfo(szFileNameWithPath).dirPath(true); } - bool readLine(QFile * f,QString &szBuffer,bool bUtf8) + bool readLine(TQFile * f,TQString &szBuffer,bool bUtf8) { - QTextStream stream(f); - stream.setEncoding(bUtf8 ? QTextStream::UnicodeUTF8 : QTextStream::Locale); + TQTextStream stream(f); + stream.setEncoding(bUtf8 ? TQTextStream::UnicodeUTF8 : TQTextStream::Locale); szBuffer=stream.readLine(); return !szBuffer.isNull(); } - bool readLines(QFile * f,QStringList &buffer,int iStartLine, int iCount, bool bUtf8) + bool readLines(TQFile * f,TQStringList &buffer,int iStartLine, int iCount, bool bUtf8) { - QTextStream stream( f ); - stream.setEncoding(bUtf8 ? QTextStream::UnicodeUTF8 : QTextStream::Locale); + TQTextStream stream( f ); + stream.setEncoding(bUtf8 ? TQTextStream::UnicodeUTF8 : TQTextStream::Locale); for(int i=0;i<iStartLine;i++) stream.readLine(); @@ -424,21 +424,21 @@ namespace KviFileUtils return buffer.count()!= 0; } - bool isReadable(const QString &szFname) + bool isReadable(const TQString &szFname) { - QFileInfo f(szFname); + TQFileInfo f(szFname); return (f.exists() && f.isFile() && f.isReadable()); } bool isReadable(const char* path) { - QString szPath=QString::fromUtf8(path); + TQString szPath=TQString::fromUtf8(path); return isReadable(szPath); } - bool isAbsolutePath(const QString &szPath) + bool isAbsolutePath(const TQString &szPath) { - QFileInfo f(szPath); + TQFileInfo f(szPath); return !f.isRelative(); } }; @@ -448,18 +448,18 @@ static char hexchars[16] = { '0' , '1' , '2' , '3' , '4' , '5' , '6' , '7' , '8' void kvi_encodeFileName(KviStr & path) { - QString szPath(path.ptr()); + TQString szPath(path.ptr()); kvi_encodeFileName(szPath); path=szPath; } -void kvi_encodeFileName(QString & path) +void kvi_encodeFileName(TQString & path) { - QString src(path); + TQString src(path); path=""; for(int i=0;i<src.length();i++) { - QChar cur=src[i]; + TQChar cur=src[i]; if( ! (cur.isLetter() || cur.isDigit() || cur==' ' || cur=='_' || cur=='.' || cur=='#' || cur=='%') ) { if(cur.row()!=0) @@ -494,10 +494,10 @@ bool kvi_isAbsolutePath(const char *path) //=================== kvi_readLine =====================// -bool kvi_readLine(QFile *f,KviStr &str) +bool kvi_readLine(TQFile *f,KviStr &str) { - QTextStream stream(f); - QString szBuff=stream.readLine(); + TQTextStream stream(f); + TQString szBuff=stream.readLine(); str=szBuff; return szBuff.isNull() ? 1 : 0; } |