31 #include <qfileinfo.h>
33 #include <qapplication.h>
34 #include <qmetaobject.h>
41 #include "klfqt34common.h"
769 static char __klf_version_string[] = KLF_VERSION_STRING;
774 return __klf_version_string;
779 return KLF_VERSION_MAJ;
783 return KLF_VERSION_MIN;
787 return KLF_VERSION_REL;
795 struct KLFDebugObjectWatcherPrivate
801 KLFDebugObjectWatcher *KLFDebugObjectWatcher::instance = NULL;
803 KLFDebugObjectWatcher *KLFDebugObjectWatcher::getWatcher()
805 if (instance == NULL)
806 instance =
new KLFDebugObjectWatcher;
810 void KLFDebugObjectWatcher::registerObjectRefInfo(
QObject *
object,
const QString& refinfo)
812 p->refInfos[(quintptr)
object] = refinfo;
815 KLFDebugObjectWatcher::KLFDebugObjectWatcher()
818 p =
new KLFDebugObjectWatcherPrivate;
820 KLFDebugObjectWatcher::~KLFDebugObjectWatcher()
824 void KLFDebugObjectWatcher::debugObjectDestroyed(
QObject *
object)
826 quintptr obji = (quintptr)
object;
827 if (p->refInfos.contains(obji)) {
828 klfDbg(
klfFmtCC(
"Object destroyed: (%s*)%p; object reference name is `%s'",
829 (
object ? object->
metaObject()->className() :
"void"),
830 object, qPrintable(p->refInfos[obji])));
833 (
object ? object->
metaObject()->className() :
"void"),
845 #ifdef KLFBACKEND_QT4
846 iParen = funcname.indexOf(
'(');
847 iSpc = funcname.lastIndexOf(
' ', iParen-2);
849 iParen = funcname.find(
'(');
850 iSpc = funcname.findRev(
' ', iParen-2);
853 if (iParen == -1 || iSpc > iParen) {
854 qWarning(
"klfShortFuncSignature('%s'): Signature parse error!", qPrintable(funcname));
858 QString f = funcname.mid(iSpc+1, iParen-(iSpc+1));
868 static const int bufferSize = 8192;
869 char buffer[bufferSize];
871 #if defined(_BSD_SOURCE) || _XOPEN_SOURCE >= 500 || defined(_ISOC99_SOURCE)
873 len = vsnprintf(buffer, bufferSize, fmt, pp);
874 if (len >= bufferSize) {
876 qWarning(
"%s(): output from format string \"%s\" was truncated from %d to %d bytes.",
881 len = vsprintf(buffer, fmt, pp);
885 qWarning(
"%s(): vs(n)printf() failed for format \"%s\"",
KLF_FUNC_NAME, fmt);
891 #ifdef KLFBACKEND_QT4
912 gettimeofday(&tv, NULL);
915 sprintf(temp,
"%03ld.%06ld", (ulong)tv.tv_sec % 1000, (ulong)tv.tv_usec);
917 sprintf(temp,
"%ld.%06ld", (ulong)tv.tv_sec, (ulong)tv.tv_usec);
923 static int __klf_dbg_block_depth_counter = 0;
926 KLFDebugBlock::KLFDebugBlock(
const QString& blockName)
927 : pBlockName(blockName), pPrintMsg(true)
930 qDebug(
"%s: [%02d]block begin", qPrintable(pBlockName), ++__klf_dbg_block_depth_counter);
933 KLFDebugBlock::KLFDebugBlock(
bool printmsg,
const QString& blockName)
934 : pBlockName(blockName), pPrintMsg(printmsg)
939 qDebug(
"%s: [%02d]block begin", qPrintable(pBlockName), ++__klf_dbg_block_depth_counter);
942 KLFDebugBlock::~KLFDebugBlock()
947 qDebug(
"%s: [%02d]block end", qPrintable(pBlockName), __klf_dbg_block_depth_counter--);
950 KLFDebugBlockTimer::KLFDebugBlockTimer(
const QString& blockName)
955 qDebug(
"+T:%s: %s: [%02d]block begin", KLF_SHORT_TIME, qPrintable(pBlockName), ++__klf_dbg_block_depth_counter);
958 KLFDebugBlockTimer::~KLFDebugBlockTimer()
962 qDebug(
"+T:%s: %s: [%02d]block end", KLF_SHORT_TIME, qPrintable(pBlockName), __klf_dbg_block_depth_counter--);
968 #ifdef KLFBACKEND_QT4
970 KLF_EXPORT QDebug __klf_dbg_hdr(QDebug dbg,
const char * funcname,
const char *refinstance,
const char * shorttime)
972 if (shorttime == NULL)
973 return dbg.nospace()<<funcname<<
"():"<<refinstance<<
"\n ";
975 return dbg.nospace()<<
"+T:"<<shorttime<<
": "<<funcname<<
"():"<<refinstance<<
"\n ";
980 int __klf_dbg_string_obj::operator=(
const QString& msg)
983 qDebug(
"%s", qPrintable(hdr + msg));
987 KLF_EXPORT __klf_dbg_string_obj
988 __klf_dbg_hdr_qt3(
const char *funcname,
const char *refinstance,
const char *shorttime)
992 if (shorttime == NULL)
996 return __klf_dbg_string_obj(s);
998 return __klf_dbg_string_obj(
QString());
1014 return KLF_CMAKE_ARCH;
1019 #if defined(Q_OS_LINUX)
1021 #elif defined(Q_OS_DARWIN)
1023 #elif defined(Q_OS_WIN32)
1039 qWarning(
"KLFSysInfo::osString: unknown OS: %d", sysos);
1045 QStringList() <<
"a" <<
"alpha" <<
"b" <<
"beta" <<
"p" <<
"pre" <<
"preview" <<
"RC" <<
"rc"
1047 <<
"post" <<
"dev" <<
"devel";
1049 static int __klf_version_compare_suffix_words(
QString w1,
QString w2)
1054 int borderBeforeAfter = words.list_indexOf(
"");
1055 if (borderBeforeAfter < 0)
1056 qWarning(
"klfVersionCompare: suffix words list doesn't contain \"\"!");
1057 int i1 = words.list_indexOf(w1);
1058 int i2 = words.list_indexOf(w2);
1059 if (i1 == -1 && i2 == -1)
1062 return i1 < borderBeforeAfter ? -1 : +1;
1064 return i2 < borderBeforeAfter ? +1 : -1;
1072 qDebug(
"klfVersionCompare(): Comparing versions %s and %s", qPrintable(v1), qPrintable(v2));
1080 QRegExp rx1(
"^(\\d+)(\\.(\\d+)(\\.(\\d+)([a-zA-Z]+\\d*)?)?)?$");
1083 qWarning(
"klfVersionLessThan: Invalid version number format: %s", qPrintable(v1));
1087 qWarning(
"klfVersionLessThan: Invalid version number format: %s", qPrintable(v2));
1090 int maj1 = rx1.
cap(1).toInt();
1091 int maj2 = rx2.
cap(1).toInt();
1094 bool hasmin1 = !rx1.
cap(2).isEmpty();
1095 bool hasmin2 = !rx2.
cap(2).isEmpty();
1096 if ( ! hasmin1 && ! hasmin2 )
1098 if ( ! hasmin1 && hasmin2 )
1100 if ( hasmin1 && ! hasmin2 )
1102 int min1 = rx1.
cap(3).toInt();
1103 int min2 = rx2.
cap(3).toInt();
1107 bool hasrel1 = !rx1.
cap(4).isEmpty();
1108 bool hasrel2 = !rx2.
cap(4).isEmpty();
1109 if ( ! hasrel1 && ! hasrel2 )
1111 if ( ! hasrel1 && hasrel2 )
1113 if ( hasrel1 && ! hasrel2 )
1115 int rel1 = rx1.
cap(5).toInt();
1116 int rel2 = rx2.
cap(5).toInt();
1125 if (suffix1 == suffix2)
1129 QRegExp rxs1(
"^([a-zA-Z]*)(\\d*)$");
1139 int cmp = __klf_version_compare_suffix_words(w1, w2);
1154 int n1 = ns1.
toInt();
1155 int n2 = ns2.
toInt();
1168 int level,
int limit)
1180 for (k = 0; k < level; ++k) { levelpathlist << newpathlist[k]; }
1184 if (flinfo.isDir()) {
1187 #ifdef KLFBACKEND_QT4
1188 entries = d.entryList(
QStringList()<<pathlist[level]);
1190 entries = d.entryList(pathlist[level]);
1193 for (k = 0; k < (int)entries.size(); ++k) {
1194 newpathlist[level] = entries[k];
1195 hitlist += __search_find_test(root, newpathlist, level+1, limit - hitlist.size());
1196 if (limit >= 0 && (
int)hitlist.size() >= limit)
1201 if (flinfo.exists()) {
1202 return QStringList() << dir_native_separators(root+pathlist.
join(
"/"));
1209 klfDbg(
"looking for "+wildcard_expression) ;
1212 #ifdef KLFBACKEND_QT4
1217 QStringList pathlist = str_split(expr,
"/",
false);
1219 static QRegExp driveregexp(
"^[A-Za-z]:$");
1222 root = pathlist[0]+
"/";
1223 pathlist.pop_front();
1225 return __search_find_test(root, pathlist, 0, limit);
1230 static const QString PATH = getenv(
"PATH");
1235 path = extra_path + pathsep + path;
1237 const QStringList paths = str_split(path, pathsep,
true);
1240 for (k = 0; k < (int)paths.size(); ++k) {
1241 klfDbg(
"searching in "+paths[k]) ;
1243 klfDbg(
"\t...resulting in hits = "+hits.
join(
" ;; ")) ;
1244 for (j = 0; j < (int)hits.size(); ++j) {
1246 klfDbg(
"\tFound definitive (executable) hit at "+hits[j]) ;
1251 return QString::null;
fromAscii(const char *str, int size=-1)
fromNativeSeparators(const QString &pathName)
KLF_EXPORT int klfVersionRelease()
Base declarations for klatexformula and some utilities.
KLF_EXPORT int klfVersionMin()
Utility to time the execution of a block.
KLF_EXPORT int klfVersionMaj()
#define klfDbg(streamableItems)
print debug stream items
join(const QString &separator)
systems on which Q_OS_LINUX is defined
KLF_EXPORT QString klfTimeOfDay(bool shortFmt=true)
replace(int position, int n, const QString &after)
KLF_EXPORT bool klfVersionCompareLessThan(const QString &v1, const QString &v2)
Same as klfVersionCompare(v1,v2) < 0
KLF_EXPORT const char * klfVersion()
fromLocal8Bit(const char *str, int size=-1)
QByteArray klfShortFuncSignature(const char *fullFuncName)
KLF_EXPORT QStringList klfSearchFind(const QString &wildcard_expression, int limit=-1)
Find files matching a path with wildcards.
KLF_EXPORT QString klfSearchPath(const QString &prog, const QString &extra_path="")
Smart executable searching in a given path list with wildcards.
toInt(bool *ok=0, int base=10)
Os
List of known operating systems.
compare(const QString &s1, const QString &s2, Qt::CaseSensitivity cs)
KLF_EXPORT QString arch()
The architecture of this sytem.
systems on which Q_OS_DARWIN is defined
KLF_EXPORT QString osString(KLFSysInfo::Os sysos=os())
The operating system we are running, returned as a string.
KLF_EXPORT int klfVersionCompare(const QString &v1, const QString &v2)
Compares two version strings.
systems on which neither Q_OS_{LINUX|WIN32|DARWIN} is defined
KLF_EXPORT KLFSysInfo::Os os()
Which operating system this system is running.
exactMatch(const QString &str)
duplicate(const QByteArray &a)
#define KLF_PATH_SEP
The character used in the $PATH environment variable to separate different locations.
KLF_EXPORT QByteArray klfFmt(const char *fmt,...)
systems on which Q_OS_WIN32 is defined