Shared libraries

We already described that the commandos exclude and excludedir in the Directories file may be used to specify functions in an external shared library, used to decide whether a given file or directory should be excluded or not. Usually, the shared library is expected to be in the directory /usr/local/lib/rab/lib. Additional directories may be specified in the /etc/rab.conf file.

Each of the functions used with the exclude command, shall use the following prototype.

int fct(char *dir, char *file, char *arg);

The meaning of the three arguments is as follows

dir

The absolute path of the directory currently processed.

file

The name of the file or directory in dir to be examined by fct.

arg

The argument given either on the exclude or on the excludedir command line.

All these three arguments are read only values, fct shall not modify them in any way. Finally, if the returned integer value is different from zero, the file or directory in question will be excluded.

In order to allow for extensions of this simple interface, a shared library used by RAB contains an internal interface version number. The interface described above has version number 1. This number is the value of an integer variable rab_version. This is not the version number of the RAB package, but only the version number of our interface. In fact, I don't think there will ever be a version number 2. RAB programs should read the variable rab_version, and use the library as indicated by this number.

To support this trivial protocol, RAB contains a simple C header file /usr/local/include/rabversion.h. This header contains only two things. First, a macro definition RAB_INTERFACE_VERSION expanding to the current interface version, as described in this document. The second entry in rabversion.h is an external definition of the integer variable rab_version. Ok, this isn't really usefull, and you are not required to use this header.

Finally, we will give a simple example function which excludes all dot files.

Example 1. An exclude function

#include <rabversion.h>

int rab_version = RAB_INTERFACE_VERSION;

int
exclude_dot(char *dir, char *file, char *arg)
{
	return *file == '.';
}

RAB comes with a small example library installed in /usr/local/lib/rab/lib, called rabstd.so. Sourcecode is installed in /usr/local/lib/rab/doc/rab/src. This library contains just three simple, and possibly not really usefull, functions.

hidden(dir, file, arg)

The file will be excluded if the first character of it's name equals the first character in arg.

binprog(dir, file, arg)

If the specified file is an executable not beginning with arg, it will be excluded.

generated(dir, file, arg)

The file will be excluded if there exists a source version of file using the extension arg.