# the Environment API

# Typical usage

    #include"adflib.h"

    void MyVer(char *msg)
    {
        fprintf(stderr,"Verbose [%s]\n",msg);
    }

    int main()
    {
        BOOL boolPr = TRUE;

        adfEnvInitDefault();

        /* to use the dir cache blocks, default is FALSE */
        adfChgEnvProp(PR_USEDIRC, (void*)&boolPr);      // optional

        /* to override the verbose callback */
        adfChgEnvProp(PR_VFCT, MyVer);                  // optional

        adfEnvCleanUp();
    }

adfEnvInitDefault()

## Syntax

void adfEnvInitDefault()

## Description

Initialise the library data structures and default values. Must be done before any other call to the library.

There is 4 callback functions which can be (and must be) overridden, the library must not write anything to the console.

- The verbose messages redirection,
- the warning messages redirection,
- the error messages redirection (must stop the library)
- The notification callback : when the current directory has changed.
- The progress bar : this function is called with an int first set to 0. Then the value increases up to 100. It can be used to display a progress bar.

By default, those functions write a message to stderr.

Another environment property is the ability to use or not the dir cache blocks to get the content of a directory. By default, it is not used.

See adfChgEnvProp() to learn how to change those properties.

## Internals

1. Set the default values
2. Prints the library version with the verbose callback.
3. Allocate the native functions structure
4. Calls adfInitNativeFct()

adfChgEnvProp()

## Syntax

void adfChgEnvProp(int propertyName, void* new value)

## Description

Change the default or lastest value of one of the environment property. The new value has the void*, this is the only way to transmit it for several types. A cast is made depending of the property name inside adfChgEnvProp().

Here's the list of the properties, and their types :

- PR_VFCT, displays verbose messages, (void(*)(char*))
- PR_WFCT, displays warning messages, (void(*)(char*))
- PR_EFCT, displays error messages, (void(*)(char*))

- PR_NOTFCT, directory object change notification, (void(*)(SECTNUM,int))
- PR_USE_NOTFCT, toggle on/off (default=off=false), BOOL

- PR_PROGBAR, progress bar, (void(*)(int))
- PR_USE_PROGBAR, use progress bar (default=off), BOOL
  The functions that support 'progress bar' are : adfCreateFlop(), adfCreateHd(), adfCreateHdFile().

- PR_RWACCESS, read (BOOL=false) or write (BOOL=true) operation, logical block and physical sector accessed, (void(*)(SECTNUM,SECTNUM,BOOL))
- PR_USE_RWACCESS, use rwaccess (default=off), BOOL

- PR_USEDIRC, use dircache blocks, BOOL (default=off).

For the non pointer types (int with PR_USEDIRC), you have to use a temporary variable. To override successfully a function, the easiest is to reuse the default function located in adf_env.c, and to change it for your needs.

adfEnvCleanUp()

## Syntax

void adfEnvCleanUp()

## Description

Cleans up the environment.

## Internals

Frees the native functions structure.

adfEnvCleanUp() : Obsolete

## Syntax

void adfSetEnvFct( void(*eFct)(char*) error, void(*wFct)(char*) warning, void(*vFct)(char*) verbose, void(*notFct)(SECTNUM,int) notify )

Obsolete : use adfChgEnvProp() instead.

adfGetVersionNumber()

## Syntax

char* adfGetVersionNumber()

## Description

Returns the current numeric ADFlib version.

adfGetVersionDate()

## Syntax

char* adfGetVersionDate()

## Description

Returns the date of the ADFlib current version.