Module filelist_simplify: file list simplification

This module simplifies the file list of package. It makes it better human readable.

Module requires for init: filelist

Module requires for running: package

Module defines phase: filelist_simplify before filelist_finish

Module uses phase: filelist_simplify before filelist_finish

filelist_simplify

Filelist inspector, which simplifies file lists by globbing.

filelist_simplify_add_callback function ...

function: callback function

Add Callback for pre-creating pattern guesses.

Callback argument is file name to be simplified. You can define variables, which can be later used for creating patterns.

See filelist_simplify_dotsep_callback for example.

filelist_simplify_add_pattern pattern ...

pattern: pattern to be checked

Add a preferred pattern to list of pattern guesses in simplification process. Shell variables used in those patterns are expanded each time they are used (it allows co-ordination with filelist_simplify_add_callback).

Preferred patterns: Patterns are used, even if * is valid.

NOTE: Empty patterns are allowed and ignored.

filelist_simplify_add_fallback_pattern pattern ...

pattern: pattern to be checked

Add an unpreferred pattern to list of pattern guesses in simplification process. Shell variables used in those patterns are expanded each time they are used (it allows co-ordination with filelist_simplify_add_callback).

Unpreferred patterns: Those are used, only if * is not valid.

Preferred patterns: Patterns are used, even if * is valid.

NOTE: Empty patterns are allowed and ignored.

filelist_simplify_compare_filename_pattern filename pattern

filename: file name

pattern: pattern to be checked

returns: 0: matches, 1: does not match

Checks, whether filename matches filename pattern.

NOTE: "case" and string replacement in Bash uses different pattern matching (it's only filename-like expansion, because it does not take '/' as special character).

filelist_simplify_compare_filename_pattern_gen pattern

pattern: pattern to be checked

returns $filelist_simplify_compare_file_pattern_pregen: pregenerated pattern

Generate extglob pattern for file checking. Re-implemetation of filelist_simplify_compare_file_pattern in two parts increases efficiency of comparing many files with the same pattern.

filelist_simplify_compare_filename_pattern_gen filename

filename: file name

uses $filelist_simplify_compare_file_pattern_pregen: pregenerated pattern

Checks, whether filename matches filename pattern. Re-implemetation of filelist_simplify_compare_file_pattern in two parts increases efficiency of comparing many files with the same pattern.

WARNING: This function must be run in extglob mode!

filelist_simplify_dotsep_callback filename

filename: file name to be simplified

Using standard filelist_simplify functions, define on-fly simplification guess for file.ext: *.ext. Active by default.

Code example (simplified):

shopt -s extglob
function filelist_simplify_dotsep_callback {
    local basename="${1##*/}"
    local ext="${basename##*.}"
    if ! test "$ext" = "$basename" ; then
	filelist_simplify_dotsep_pattern="*.$ext"
    else
	filelist_simplify_dotsep_pattern=
    fi
}
shopt -u extglob
filelist_simplify_add_callback filelist_simplify_dotsep_callback
filelist_simplify_add_fallback_pattern '$filelist_simplify_dotsep_pattern'