SDF 2.001: SDF Reference: FindFile

Contents | Parent Topic | Previous Topic | Next Topic
Home | Catalog

# 12.3. FindFile

## Purpose

This routine is used to search for include files, imported objects, configuration modules and templates.

## Interface

      $fullname = &FindFile($filename, $image);

## Description

If filename is not found, fullname should be an empty string. If the file is found, the pathname of the file is returned, otherwise the empty string is returned. If image is true, a target-specific set of extensions is searched for, complete with implicit image format conversion.

## Examples

The default implementation is:

    sub FindFile {
        local($filename, $image) = @_;
        local($fullname);

        # Get the list of directories to search
        use Cwd;
        my @dirs = ('.');
        my $dir = $var{'DOC_DIR'};
        push(@dirs, $dir) if $dir ne cwd();
        push(@dirs, @include_path, "$'sdf_lib/stdlib", $'sdf_lib);

        # Do the search
        if ($image) {
            my $context = $var{'OPT_TARGET'};
            my @exts = @{$'SDF_IMAGE_EXTS{$context} || $'SDF_IMAGE_EXTS{'ps'}};
            return &'NameFindOrGenerate($filename, \@dirs, \@exts, $context);
        }
        else {
            return &'NameFind($filename, @dirs);
        }
    }

In order to tightly integrate SDF with certain development environments, it is occasionally necessary to override this routine in a configuration module. For example:

    !block script
    sub FindFile {
        local($filename, $image) = @_;
        local($fullname);

        # Search using our SCM
        $fullname = &'SearchSCM($filename, $image);

        # Return result
        return $fullname;
    }
    !endblock