aboutsummaryrefslogtreecommitdiffstats
path: root/src/modules/file/libkvifile.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/modules/file/libkvifile.cpp')
-rw-r--r--src/modules/file/libkvifile.cpp114
1 files changed, 73 insertions, 41 deletions
diff --git a/src/modules/file/libkvifile.cpp b/src/modules/file/libkvifile.cpp
index d07ac9d15..2ff9022f1 100644
--- a/src/modules/file/libkvifile.cpp
+++ b/src/modules/file/libkvifile.cpp
@@ -86,6 +86,7 @@
@seealso:
[cmd]file.rename[/cmd], [fnc]$file.exists[/fnc]
*/
+
static bool file_kvs_cmd_copy(KviKvsModuleCommandCall * c)
{
QString szSrc,szDst;
@@ -125,6 +126,7 @@ static bool file_kvs_cmd_copy(KviKvsModuleCommandCall * c)
@seealso:
[cmd]file.delimagepath[/cmd]
*/
+
static bool file_kvs_cmd_addimagepath(KviKvsModuleCommandCall * c)
{
QString szDst;
@@ -157,6 +159,7 @@ static bool file_kvs_cmd_addimagepath(KviKvsModuleCommandCall * c)
@seealso:
[cmd]file.addimagepath[/cmd]
*/
+
static bool file_kvs_cmd_delimagepath(KviKvsModuleCommandCall * c)
{
QString szDst;
@@ -192,7 +195,7 @@ static bool file_kvs_cmd_delimagepath(KviKvsModuleCommandCall * c)
Causes the file to be written in the local 8-bit character set instead of the default UTF-8.
@description:
Writes <data> (which is a string of characters) to the file <filename>.[br]
- It does NOT append a trailing LF character: if you want it you must explicitly specify it in the <data> parameter.[br]
+ It does [b]not[/b] append a trailing LF character: if you want it you must explicitly specify it in the <data> parameter.[br]
-a causes the command to append the <data> to the file instead of overwriting the entire file.[br]
The path is adjusted according to the system that KVIrc
is running on so you don't have to bother about portability: it [i]should[/i] be automatically
@@ -204,6 +207,7 @@ static bool file_kvs_cmd_delimagepath(KviKvsModuleCommandCall * c)
@seealso:
[cmd]file.rename[/cmd], [fnc]$file.exists[/fnc]
*/
+
static bool file_kvs_cmd_write(KviKvsModuleCommandCall * c)
{
QString szFileName,szData;
@@ -257,6 +261,7 @@ static bool file_kvs_cmd_write(KviKvsModuleCommandCall * c)
@seealso:
[cmd]file.rename[/cmd], [fnc]$file.exists[/fnc], [fnc]$file.write[/fnc]
*/
+
static bool file_kvs_cmd_writeBytes(KviKvsModuleCommandCall * c)
{
QString szFileName;
@@ -325,6 +330,7 @@ static bool file_kvs_cmd_writeBytes(KviKvsModuleCommandCall * c)
@seealso:
[cmd]file.copy[/cmd], [fnc]$file.exists[/fnc]
*/
+
static bool file_kvs_cmd_rename(KviKvsModuleCommandCall * c)
{
QString szOld,szNew;
@@ -369,6 +375,7 @@ static bool file_kvs_cmd_rename(KviKvsModuleCommandCall * c)
@seealso:
[fnc]$file.exists[/fnc]
*/
+
static bool file_kvs_cmd_mkdir(KviKvsModuleCommandCall * c)
{
QString szDir;
@@ -408,6 +415,7 @@ static bool file_kvs_cmd_mkdir(KviKvsModuleCommandCall * c)
@seealso:
[fnc]$file.exists[/fnc]
*/
+
static bool file_kvs_cmd_remove(KviKvsModuleCommandCall * c)
{
QString szName;
@@ -449,6 +457,7 @@ static bool file_kvs_cmd_remove(KviKvsModuleCommandCall * c)
[fnc]$file.exists[/fnc]
[cmd]file.remove[/cmd]
*/
+
static bool file_kvs_cmd_rmdir(KviKvsModuleCommandCall * c)
{
QString szName;
@@ -485,6 +494,7 @@ static bool file_kvs_cmd_rmdir(KviKvsModuleCommandCall * c)
echo $file.exists(/etc/passwd);
[/example]
*/
+
static bool file_kvs_fnc_exists(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -508,10 +518,11 @@ static bool file_kvs_fnc_exists(KviKvsModuleFunctionCall * c)
@syntax:
<string> $file.type(<filename:string>)
@description:
- Returns "f" if the <filename> points to a real file, "d" if <filename>
- is the name of a directory or "l" if it is a symbolic link.[br]
+ Returns [b]f[/b] if the <filename> points to a real file, [b]d[/b] if <filename>
+ is the name of a directory or [b]l[/b] if it is a symbolic link.[br]
The <filename> should be an UNIX style file path and is adjusted according to the system that KVIrc is running on.[br]
*/
+
static bool file_kvs_fnc_type(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -541,9 +552,10 @@ static bool file_kvs_fnc_type(KviKvsModuleFunctionCall * c)
<integer> $file.size(<filename:string>)
@description:
Returns the size of the file pointed by <filename>.[br]
- If the file does not exist, this function returns 0.[br]
+ If the file does not exist, this function returns [b]0[/b].[br]
The <filename> should be an UNIX style file path and is adjusted according to the system that KVIrc is running on.[br]
*/
+
static bool file_kvs_fnc_size(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -565,11 +577,12 @@ static bool file_kvs_fnc_size(KviKvsModuleFunctionCall * c)
@short:
Returns the size of each file in a specified directory.
@syntax:
- <array> $file.allSize(<dirname:string>)
+ <array> $file.allSize(<dirname:string>)
@description:
- Returns the size of each file in a specified directory as an array.[br]
- This function is not recursive: it won't return the size of files in subdirectories of <dirname>.
+ Returns the size of each file in a specified directory as an array.[br]
+ This function is not recursive: it won't return the size of files in subdirectories of <dirname>.
*/
+
static bool file_kvs_fnc_allSizes(KviKvsModuleFunctionCall * c)
{
QString szDir;
@@ -618,17 +631,18 @@ static bool file_kvs_fnc_allSizes(KviKvsModuleFunctionCall * c)
<string> $file.fixpath(<filename:string>)
@description:
Returns the <filename> adjusted to match the current operating
- system file path conventions.[br] This means that on UNIX, a path like "C:\folder\file.mp3"
- will be returned as "/folder/file.mp3" and vice-versa.[br]
+ system file path conventions.[br] This means that on UNIX, a path like [i]C:\folder\file.mp3[/i]
+ will be returned as [i]/folder/file.mp3[/i] and vice-versa.[br]
There is a minor problem with UNIX paths converted to the windows system: UNIX
- has no "drive" concept thus the UNIX paths do not contain a drive. KVIrc will
- always map the paths to the "default" C: drive.[br]
+ has no [i]drive[/i] concept thus the UNIX paths do not contain a drive. KVIrc will
+ always map the paths to the [i]default[/i] C: drive.[br]
This is a good reason to avoid using absolute hard-coded paths :).[br]
Please note that you [b]don't need[/b] to call this function on paths that you
pass to the other file.* functions: they are adjusted automatically.[br]
@seealso:
[fnc]$file.ps[/fnc]
*/
+
static bool file_kvs_fnc_fixpath(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -652,10 +666,11 @@ static bool file_kvs_fnc_fixpath(KviKvsModuleFunctionCall * c)
<string> $file.ps()
@description:
Returns the file path separator for the current operating system.[br]
- On windows, '\' is returned, on UNIX, '/'.[br]
+ On windows, [b]\[/b] is returned, on UNIX, [b]/[/b].[br]
@seealso:
[fnc]$file.fixpath[/fnc]
*/
+
static bool file_kvs_fnc_ps(KviKvsModuleFunctionCall * c)
{
c->returnValue()->setString(QString(QChar(KVI_PATH_SEPARATOR_CHAR)));
@@ -676,21 +691,23 @@ static bool file_kvs_fnc_ps(KviKvsModuleFunctionCall * c)
Returns the listing of the specified directory as an array.[br]
The <directory> should be a UNIX style file path and is adjusted according to the system that KVIrc is running on.[br]
<flags> may be a combination of the following characters:[br]
- d: list directories[br]
- f: list files[br]
- l: list symbolic links[br]
- r: list readable files[br]
- w: list writable files[br]
- x: list executable files[br]
- h: list hidden files[br]
- s: list system files[br]
- n: sort files by name[br]
- t: sort files by file time[br]
- b: sort files by file size[br]
- z: put the directories first, then the files[br]
- k: invert sort order[br]
- i: case insensitive sort[br]
- If <flags> is empty then a default of 'dfrwxhs' is set.[br]
+ [pre]
+ [b]d:[/b] list directories[br]
+ [b]f:[/b] list files[br]
+ [b]l:[/b] list symbolic links[br]
+ [b]r:[/b] list readable files[br]
+ [b]w:[/b] list writable files[br]
+ [b]x:[/b] list executable files[br]
+ [b]h:[/b] list hidden files[br]
+ [b]s:[/b] list system files[br]
+ [b]n:[/b] sort files by name[br]
+ [b]t:[/b] sort files by file time[br]
+ [b]b:[/b] sort files by file size[br]
+ [b]z:[/b] put the directories first, then the files[br]
+ [b]k:[/b] invert sort order[br]
+ [b]i:[/b] case insensitive sort[br]
+ [/pre]
+ If <flags> is empty then a default of [b]dfrwxhs[/b] is set.[br]
If none of the r,w,x flags are set then KVIrc sets all of them by default.[br]
If <namefilter> is passed then it is interpreted as a wildcard string
that must match the entries to be returned.[br]
@@ -704,6 +721,7 @@ static bool file_kvs_fnc_ps(KviKvsModuleFunctionCall * c)
[cmd]foreach[/cmd](%f,%dir[])echo %f
[/example]
*/
+
static bool file_kvs_fnc_ls(KviKvsModuleFunctionCall * c)
{
QString szDir,szFlags,szFilter;
@@ -792,8 +810,8 @@ static bool file_kvs_fnc_ls(KviKvsModuleFunctionCall * c)
allocating memory, before attempting to read anything)[br]
An empty string is returned if a serious error occurs.[br]
The <filename> is adjusted according to the system that KVIrc is running on.[br]
- Flags are actually limited to the single letter 'l'. By default the file
- is decoded from the UTF-8 characters set. If 'l' is present the the file
+ Flags are actually limited to the single letter [b]l[/b]. By default the file
+ is decoded from the UTF-8 characters set. If [b]l[/b] is present the the file
is decoded by using the local 8-bit character set instead.
@examples:
[example]
@@ -802,6 +820,7 @@ static bool file_kvs_fnc_ls(KviKvsModuleFunctionCall * c)
@seealso:
[fnc]$file.readBytes[/fnc]
*/
+
static bool file_kvs_fnc_read(KviKvsModuleFunctionCall * c)
{
QString szNameZ;
@@ -884,7 +903,7 @@ static bool file_kvs_fnc_read(KviKvsModuleFunctionCall * c)
WARNING: always check the file size before attempting to read a whole file...
reading a CDROM ISO image may sit down your system :) (and will probably crash while
allocating memory, before attempting to read anything)[br]
- An empty array (or just "nothing") is returned if a serious error occurs.[br]
+ An empty array (or just [i]nothing[/i]) is returned if a serious error occurs.[br]
The <filename> is adjusted according to the system that KVIrc is running on.[br]
@examples:
[example]
@@ -893,6 +912,7 @@ static bool file_kvs_fnc_read(KviKvsModuleFunctionCall * c)
@seealso:
[fnc]$file.read[/fnc], [cmd]file.writeBytes[/cmd]
*/
+
static bool file_kvs_fnc_readBytes(KviKvsModuleFunctionCall * c)
{
QString szNameZ;
@@ -971,14 +991,14 @@ static bool file_kvs_fnc_readBytes(KviKvsModuleFunctionCall * c)
<array> $file.readLines(<filename:string>[,<startline:integer>,[<count:integer>[,<flags:string>]]])
@description:
Reads lines from the specified file and returns them as an array of strings.
- The lines are assumed to be separated by linefeed characters (which are NOT returned).
+ The lines are assumed to be separated by linefeed characters (which are [b]not[/b] returned).
Eventual terminating carriage return and line feed characters at the end of the line are stripped.
If <startline> is specified, then all the lines with indexes lower that <startline> are
discarded. If <count> is specified then at most this number of lines are returned,
otherwise the entire file is returned.
The <filename> is adjusted according to the system that KVIrc is running on.[br]
- Flags are actually limited to the single letter 'l'. By default the file
- is decoded from the UTF-8 character set, however if 'l' is present then the file
+ Flags are actually limited to the single letter [b]l[/b]. By default the file
+ is decoded from the UTF-8 character set, however if [b]l[/b] is present then the file
is decoded by the local 8-bit character set instead.
WARNING: Always check the size of the file you're going to read - it is not
a good idea attempting to read a 700 MiB binary file with this function since
@@ -990,6 +1010,7 @@ static bool file_kvs_fnc_readBytes(KviKvsModuleFunctionCall * c)
@seealso:
[fnc]$file.read[/fnc], [cmd]file.writeLines[/cmd], [fnc]$lf[/fnc]
*/
+
static bool file_kvs_fnc_readLines(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1081,7 +1102,7 @@ static bool file_kvs_fnc_readLines(KviKvsModuleFunctionCall * c)
The lines are separated by a carriage-return+line-feed character
combination, compatible with windows text mode files.
This is the only way to make the file readable in windows notepad, for example.
- Please note that this is broken design: do NOT use it :)
+ Please note that this is broken design: do [b]not[/b] use it :)
!sw: -n | --no-separator
Do not separate the lines at all (either the separators are already
inside the lines array or no line separation is desired at all).
@@ -1097,6 +1118,7 @@ static bool file_kvs_fnc_readLines(KviKvsModuleFunctionCall * c)
@seealso:
[fnc]$file.readLines[/fnc]
*/
+
static bool file_kvs_cmd_writeLines(KviKvsModuleCommandCall * c)
{
QString szFile,szFlags;
@@ -1176,6 +1198,7 @@ static bool file_kvs_cmd_writeLines(KviKvsModuleCommandCall * c)
echo panic.png would be translated to $file.localdir(pics/panic.png)
[/example]
*/
+
static bool file_kvs_fnc_localdir(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1209,6 +1232,7 @@ static bool file_kvs_fnc_localdir(KviKvsModuleFunctionCall * c)
that KVIrc is actually running on (thus you do not need to care about path
separators in the <relative_path>, KVIrc will adjust them).[br]
*/
+
static bool file_kvs_fnc_homedir(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1244,6 +1268,7 @@ static bool file_kvs_fnc_homedir(KviKvsModuleFunctionCall * c)
that KVIrc is actually running on (thus you not need to care about path
separators in the <relative_path>, KVIrc will adjust them).[br]
*/
+
static bool file_kvs_fnc_rootdir(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1278,6 +1303,7 @@ static bool file_kvs_fnc_rootdir(KviKvsModuleFunctionCall * c)
that KVIrc is actually running on (thus you do not need to care about path
separators in the <relative_path>, KVIrc will adjust them).[br]
*/
+
static bool file_kvs_fnc_cwd(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1321,6 +1347,7 @@ static bool file_kvs_fnc_cwd(KviKvsModuleFunctionCall * c)
echo panic.png would be translated to $file.globaldir(pics/panic.png)
[/example]
*/
+
static bool file_kvs_fnc_globaldir(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1349,12 +1376,13 @@ static bool file_kvs_fnc_globaldir(KviKvsModuleFunctionCall * c)
@description:
Returns the path part of the <filepath> translated to match the current
platform filesystem conventions.[br]
- The path will NOT contain a trailing path separator.[br]
+ The path will [b]not[/b] contain a trailing path separator.[br]
For example, if <filepath> is /usr/arch/mp3/Carisma_SuonoDelSilenzio.mp3 then
this function will return /usr/arch/mp3 on UNIX and C:\usr\arch\mp3 on Windows.
@seealso:
[fnc]$file.extractFileName[/fnc]
*/
+
static bool file_kvs_fnc_extractpath(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1383,6 +1411,7 @@ static bool file_kvs_fnc_extractpath(KviKvsModuleFunctionCall * c)
@seealso:
[fnc]$file.extractfilename[/fnc]
*/
+
static bool file_kvs_fnc_extractfilename(KviKvsModuleFunctionCall * c)
{
QString szName;
@@ -1406,9 +1435,10 @@ static bool file_kvs_fnc_extractfilename(KviKvsModuleFunctionCall * c)
@syntax:
<hash> $file.diskspace([dirpath:string])
@description:
- Returns as hash, with 'freespace' and 'totalspace' as key, the free diskspace in bytes.[br]
+ Returns as hash, with [b]freespace[/b] and [b]totalspace[/b] as key, the free diskspace in bytes.[br]
Without optional dirpath parameter will be returned the current device's disk space (i.e. the disk on which KVIrc has been started).[br]
*/
+
static bool file_kvs_fnc_diskSpace(KviKvsModuleFunctionCall * c)
{
QString szPath;
@@ -1457,6 +1487,7 @@ static bool file_kvs_fnc_diskSpace(KviKvsModuleFunctionCall * c)
Currently supported: md5 (default), md4, md2, sha1, mdc2, ripemd160 and dss1.
Requires OpenSSL support, but offers a minimal set of hashes in any case.
*/
+
static bool file_kvs_fnc_digest(KviKvsModuleFunctionCall * c)
{
QString szFile,szAlgo,szResult;
@@ -1553,17 +1584,18 @@ static bool file_kvs_fnc_digest(KviKvsModuleFunctionCall * c)
Returns the datetime of a file as the number of milliseconds that have passed since 1970-01-01T00:00:00.000, Coordinated Universal Time (UTC).[br]
The path should be given in UNIX-style and is adjusted according to the system that KVIrc is running on.[br]
The type have to be:[br]
- "a" to retrieve the last time the file was accessed;[br]
- "c" to retrieve the creation time of the file (on most UNIX systems, when the creation time or the last status change time - e.g. changing file permissions - are not available, it will fallback to "m";[br]
- "m" to retrieve the time of the last modification of the file. This is the default.
+ [b]a[/b] to retrieve the last time the file was accessed;[br]
+ [b]c[/b] to retrieve the creation time of the file (on most UNIX systems, when the creation time or the last status change time - e.g. changing file permissions - are not available, it will fallback to "m";[br]
+ [b]m[/b] to retrieve the time of the last modification of the file. This is the default.
@examples:
[example]
- # Windows
+ [comment]# Windows[/comment]
echo $file.time(c:/file.txt);
- # Linux, other UNIX's
+ [comment]# Linux, other UNIX's[/comment]
echo $file.time(/etc/passwd,a);
[/example]
*/
+
static bool file_kvs_fnc_time(KviKvsModuleFunctionCall * c)
{
QString szName, szType;