Cause execution of the script expr for each file before doing anything with that file. The script is a C style statement block, terminating with a `return expression;´. The value of expression can be one of INCLUDE, EXCLUDE, UNKNOWN or IGNORE (see -i above) to explain what is to be done with that file. If expr does not contain a semi-colon (;) then it is assumed to be the name of a file - which is then loaded. In either case, the text is byte compiled into reverse-polish notation for fast execution. This option can be specified multiple times and the scripts will be executed in order until a script returns something other than UNKNOWN. A return value of UNKNOWN allows the remaining --exclude- options on the command-line to take effect.
If you find that the interpretor incorrectly reports errors or segfaults, please report the breaking script to me.
The scripting language itself is a subset of the full C programming language. For example, the following is a valid script:
/* PATH is the full name of the file including
its path, DIR is the directory, excluding
the trailing slash (/), CWD is the current
directory, and depth() returns the number
of forward slashes (/) less one. */
if (depth (DIR) - depth (CWD) > 3) {
printf ("%s: excluded\n", PATH);
return EXCLUDE;
} else
return INCLUDE;
The scripting language does not support the assignment operator, and hence does not support user defined variables.
The following predefined macros are available. Note that the expansion of the macros applies equally well to directories as to files.
- FILE
-
current file without its path
- NAME
-
file name without its path or extension or trailing dot (.)
- EXTENSION
-
file extension without its leading dot (.)
- DIR
-
directory without file-name or trailing slash (/)
- PATH
-
full file name with path
- CWD
-
current working directory
- TIME
-
current time in seconds
All of the logical, arithmetic and bitwise C operators are supported. These are ( ) >= <= > < != == && || ! - + * / % & ^ and have the same meanings and precedences as in C.
The following further predefined macros are available. Each returns an integer (type long int in C). These are based on a C lstat (or stat if --follow-symlinks is used) on the file. See stat(2) for a detailed explanation.
stat.st_dev - device
stat.st_ino - inode
stat.st_mode - permissions
stat.st_nlink - number of hard links
stat.st_uid - user id of owner
stat.st_gid - group id of owner
stat.st_rdev - device type
stat.st_size - file size in bytes
stat.st_blksize - block-size for file-system I/O
stat.st_blocks - number of blocks allocate
stat.st_atime - time of last accessed in seconds
stat.st_mtime - time of last modification in seconds
stat.st_ctime - time of creation
The following functions return boolean values:
strncmp(string1, string2, integer);
-
returns an integer less than, equal to, or greater than zero if string1 is found, respectively, to be less than, to match, or be greater than string2.
glob(glob, string);
-
returns zero if string matches glob expression glob. Try to use only one glob expression in your code for efficiency of the underlying implementation.
regexp(regexp, string);
-
returns zero if string matches regular expression regexp. Try to use only one regular expression in your code for efficiency of the underlying implementation.
strstr(string1, string2);
-
returns the first occurance of string2 in string1 up to the length of string1, or zero if it did not occur.
The following functions also return a boolean value and are analogous to the corresponding macros explained in stat(2). They return non-zero if the specified condition is true.
S_ISLNK(integer); - file is a sym-link
S_ISREG(integer); - file is a regular file
S_ISDIR(integer); - file is a directory
S_ISCHR(integer); - file is a character device
S_ISBLK(integer); - file is a block device
S_ISFIFO(integer); - file is an fifo
S_ISSOCK(integer); - file is a socket
The following functions manipulate strings:
strcat(string1, string2);
-
returns the concatenation of string1 with string2. Note that the + operator also concatenates strings.
depth(string);
-
returns one less than the number of forward slashes (/) in string.
printf(format, ...);
-
behaves like printf(3) with an important exception: only long int format specifiers should be used. The behaviour of anything that results in conversion of other than a long int is undefined. For example, use "%ld" instead of "%d". This function prints to stdout.
The following functions do system calls:
system(command);
-
executes /bin/sh -c command, but unlike the C version, it returns the exit code of the command. I.e. it executes a single line of shell script, command.
exec(argv0, argv1, ...);
-
executes process argv0 with arguments argv1.... argv0 must be a full path name. This is faster than system because it need not envoke sh.
popen([string, ] shell_command);
-
like system, but returns the output of shell_command as a string. If string is given, this writes string into the standard input of shell_command and return zero on success.
The following further integer constants are available and are analogous to the macros defined in stat.h and explained in stat(2).
S_IFMT S_IFSOCK S_IFLNK S_IFREG S_IFBLK S_IFDIR S_IFCHR S_IFIFO S_ISUID S_ISGID S_ISVTX S_IRWXU S_IRUSR S_IWUSR S_IXUSR S_IRWXG S_IRGRP S_IWGRP S_IXGRP S_IRWXO S_IROTH S_IWOTH S_IXOTH
One of the the following constants should be returned using the return keyword, and imply to the caller as follows. If nothing is returned, the return value is assumed to be UNKNOWN.
- UNKNOWN
-
didn't know what to do, continue with other --exclude- options
- IGNORE
-
do nothing with the file regardless of its existence or non-existence in the mirror directory
- EXCLUDE
-
consider the file to be non-existent in the control directory and hence must be removed from the mirror directory (this does not override the option --keep-files)
The following perform flow control analogous to C:
The if clause causes statement1, statement2, etc. to be executed if integer is true (i.e. non-zero), or otherwise causes statement1, statement2, etc. to be executed. The else {...} part is optional.
if (integer) {
statement1;
statement2;
.
.
.
} else {
statementA;
statementB;
.
.
.
}
The return clause gives a value back to mirrordir and causes the script to exit:
return expression;
The exit function cause mirrordir to exit with the specified exit code.
exit(integer);
C scripts would typically be used to exclude types of files. Note that this is an excessive implementation of a scripting language, and all the features are not meant for general use. A typical script will, for example, do nothing more than cause device files to be excluded:
if (S_ISSOCK(stat.st_mode) || S_ISFIFO(stat.st_mode)
|| S_ISBLK(stat.st_mode) || S_ISCHR(stat.st_mode)) {
return EXCLUDE;
} else
return INCLUDE;
C scripts can also be used to search for files with the --recurs-mode option (same as the recursdir command):
/* removes all core files */
/* This example has been moved to the EXAMPLES section. */