[KLF Application][KLF Tools][KLF Backend][KLF Home]
KLatexFormula Project
Namespaces | Macros | Enumerations | Functions
klfdefs.h File Reference

Base declarations for klatexformula and some utilities. More...

#include <qobject.h>
#include <qstring.h>
#include <qvariant.h>
#include <klfdebug.h>
Include dependency graph for klfdefs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Namespaces

 KLFSysInfo
 Utilities to get system information.
 

Macros

#define klfFmtCC
 
#define KLF_FUNC_SINGLE_RUN
 Simple test for one-time-run functions. More...
 
#define KLF_PATH_SEP
 The character used in the $PATH environment variable to separate different locations. More...
 

Enumerations

enum  KLFSysInfo::Os { KLFSysInfo::Linux, KLFSysInfo::Win32, KLFSysInfo::MacOsX, KLFSysInfo::OtherOs }
 List of known operating systems. More...
 

Functions

KLF_EXPORT const char * klfVersion ()
 
KLF_EXPORT int klfVersionMaj ()
 
KLF_EXPORT int klfVersionMin ()
 
KLF_EXPORT int klfVersionRelease ()
 
KLF_EXPORT QByteArray klfFmt (const char *fmt,...)
 
KLF_EXPORT QByteArray klfFmt (const char *fmt, va_list pp)
 
int KLFSysInfo::sizeofVoidStar ()
 the processor register size. More...
 
KLF_EXPORT QString KLFSysInfo::arch ()
 The architecture of this sytem. More...
 
KLF_EXPORT KLFSysInfo::Os KLFSysInfo::os ()
 Which operating system this system is running. More...
 
KLF_EXPORT QString KLFSysInfo::osString (KLFSysInfo::Os sysos=os())
 The operating system we are running, returned as a string. More...
 
KLF_EXPORT int klfVersionCompare (const QString &v1, const QString &v2)
 Compares two version strings. More...
 
KLF_EXPORT bool klfVersionCompareLessThan (const QString &v1, const QString &v2)
 Same as klfVersionCompare(v1,v2) < 0
 
KLF_EXPORT QStringList klfSearchFind (const QString &wildcard_expression, int limit=-1)
 Find files matching a path with wildcards. More...
 
KLF_EXPORT QString klfSearchPath (const QString &prog, const QString &extra_path="")
 Smart executable searching in a given path list with wildcards. More...
 

Detailed Description

Base declarations for klatexformula and some utilities.

Definition in file klfdefs.h.

Macro Definition Documentation

#define KLF_FUNC_SINGLE_RUN

Simple test for one-time-run functions.

Usage example:

* void init_load_stuff()
* {
* // ... eg. load some initializing data in a static structure ...
* // this operation will only be performed the first time that init_load_stuff() is called.
* // ...
* }
*

Definition at line 75 of file klfdefs.h.

#define KLF_PATH_SEP

The character used in the $PATH environment variable to separate different locations.

Expands to ':' (colon) on unices/Mac and to ';' (semicolon) on Windows.

Note that the character is given as a char (observe the single-quotes), not in a string.

Definition at line 107 of file klfdefs.h.

Referenced by KLFBackend::detectSettings(), and klfSearchPath().

#define klfFmtCC

Same as klfFmt(), but returns the formatted string as a const char* C-style string.

Example:

* unsigned int flags = ... ;
* qDebug()<<"Flags are: "<<klfFmtCC("%#010x", flags) ;
*

Used in a QDebug stream, this function has the advantage (over klfFmt()) of not having its value enclosed in quotes.

Note for advanced usage
This macro, when called as klfFmtCC (format, args...) expands to

(const char*)klfFmt (format, args...)

Which means that if you are trying to do something (quite unorthodox) like:

* cout<<"3rd digit of 280 in base 8 is: "<< klfFmtCC("%o", 280)[2]; // does not compile
*

then it will fail at compile-time, since the const char* cast is evaluated after the operator[]. The working example is:

* cout<<"3rd digit of 280 in base 8 is: "<< (klfFmtCC("%o", 280))[2]; // correct
*

This macro had to be declared without any arguments, since C preprocessor macros don't support variable number of arguments (as required by printf-style formatting). This is the reason why I couldn't automatically fit in the extra required parenthesis in the macro definition.

Definition at line 70 of file klfdefs.h.

Referenced by KLFBackend::detectSettings().

Function Documentation

KLF_EXPORT QByteArray klfFmt ( const char *  fmt,
  ... 
)

Formats a printf-style string and returns the data as a QByteArray.

Warning
the final string length must not exceed 8192 bytes, the size of the internal buffer.

Definition at line 899 of file klfdefs.cpp.

KLF_EXPORT QByteArray klfFmt ( const char *  fmt,
va_list  pp 
)

Implements klfFmt(const char *, ...) functionality, but with a va_list argument pointer for use in vsprintf().

Definition at line 866 of file klfdefs.cpp.

References QByteArray::duplicate(), and KLF_FUNC_NAME.

KLF_EXPORT QStringList klfSearchFind ( const QString wildcard_expression,
int  limit 
)

Find files matching a path with wildcards.

This function returns at most limit file names that match the given wildcard_expression. The latter may be any absolute path in which (any number of) * and ? wildcards may be placed.

This function splits the wildcard_expression at '/' characters, and by starting at the root directory, recursively exploring all directories matching the given section of the pattern. (native '\' separators on windows are appropriately converted to universal '/', so you don't have to worry about passing '\'-style paths).

For example, searching for "/usr/lib*/kde4/kate*.so" will start looking in the root directory for a directory named "usr", in which a directory matching "lib*" is searched for. In each of those matches, a directory named "kde4" is searched for, in which files named "lib*.so.*" are listed. All found matches are returned (up to a given limit number of entries if limit is positive).

The drive letter in wildcard_expression on windows may not contain a wildcard.

Definition at line 1207 of file klfdefs.cpp.

References QRegExp::exactMatch(), QDir::fromNativeSeparators(), klfDbg, QString::replace(), and QDir::separator().

Referenced by klfSearchPath().

KLF_EXPORT QString klfSearchPath ( const QString programName,
const QString extra_path 
)

Smart executable searching in a given path list with wildcards.

This function looks for an executable named programName. It looks in the directories given in argument extra_path, and in the system environment variable PATH. extra_path and PATH are assumed to be a colon-separated list of directories (semicolon-separated on windows, see KLF_PATH_SEP). Each given directory may contain wildcards (in particular, wildcards in PATH are also parsed). programName itself may also contain wildcards.

This function splits extra_path and PATH into a directory list, and then, for each directory in that list, calls klfSearchFind() with as argument the string "<directory>/<programName>". This function then returns the first result that is an executable file (this check is explicitely performed).

Definition at line 1228 of file klfdefs.cpp.

References QString::isEmpty(), QFileInfo::isExecutable(), QStringList::join(), KLF_PATH_SEP, klfDbg, and klfSearchFind().

Referenced by KLFBackend::detectSettings(), and KLFBlockProcess::startProcess().

KLF_EXPORT const char* klfVersion ( )

Returns the current version of the KLatexFormula library, given as a string, eg. "3.2.1".

For non-release builds, this may have a suffix, eg. "3.2.0beta2".

Definition at line 772 of file klfdefs.cpp.

KLF_EXPORT int klfVersionCompare ( const QString v1,
const QString v2 
)

Compares two version strings.

v1 and v2 must be of the form "<MAJ>.<MIN>.<REL><suffix>" or "<MAJ>.<MIN>.<REL>" or "<MAJ>.<MIN>" or "<MAJ>" or an empty string.

Empty strings are considered less than any other version string, except to other empty strings to which they compare equal.

Returns
a negative value if v1 < v2, 0 if v1 == v2 and a positive value if v2 < v1. This function returns -200 if either of the version strings are invalid.

A less specific version number is considered as less than a more specific version number of equal common numbers, eg. "3.1" < "3.1.2".

When a suffix is appended to the version, it is attempted to be recognized:

  • "alpha" or "alphaN" is alpha version, eg. "3.1.1alpha2" < "3.1.1.alpha5" < "3.1.1"
  • "dev" is INTERNAL versioning, should not be published, it means further development after the given version number; for the next release, a higher version number has to be decided upon.
  • unrecognized suffixes are compared lexicographically, case sensitive.
  • after any non-empty suffix, you can add an optional integer number, which will be taken into account when comparing same version numbers with same suffix words, see examples below.

The full list of recognized suffixes is, in order from "least" to "most" recent version:

  • "a"
  • "alpha"
  • "b"
  • "beta"
  • "p"
  • "pre"
  • "preview"
  • "RC"
  • "rc"
  • "" ( version number specified without prefix)
  • "dev"
  • "devel"

Some examples, where "<" represents a logical "less than", characterized by this function returning a strictly negative value when called with both arguments:

   "3.1.0" < "3.1.2"
    "2" < "2.1" < "2.1.1"
    "3.0.0alpha2" < "3.0.0"
    "3.0.2" < "3.0.3alpha0"
    "3.2.0alpha" < "3.2.0beta"
    "3.2.0alpha" < "3.2.0alpha0"
    "3.2.0RC3" < "3.2.0RC4"
  

This function, when exchanging the arguments, returns a value that is of opposite sign, ie.

* klfVersionCompare(v1, v2) == - klfVersionCompare(v2, v1)
*

Mathematically such a function would be called antisymmetric or skewsymmetric.

Definition at line 1070 of file klfdefs.cpp.

References QRegExp::cap(), QRegExp::exactMatch(), QString::isEmpty(), and QString::toInt().

Referenced by klfVersionCompareLessThan().

KLF_EXPORT int klfVersionMaj ( )

Returns the current major version of the KLatexFormula library.

For example, if the version is "3.2.0", klfVersionMaj() returns 3.

Definition at line 777 of file klfdefs.cpp.

KLF_EXPORT int klfVersionMin ( )

Returns the current minor version of the KLatexFormula library.

For example, if the version is "3.2.0", klfVersionMin() returns 2.

Definition at line 781 of file klfdefs.cpp.

KLF_EXPORT int klfVersionRelease ( )

Returns the current release version of the KLatexFormula library.

For example, if the version is "3.2.0", klfVersionRelease() returns 0.

Definition at line 785 of file klfdefs.cpp.


Generated by doxygen 1.8.5