diff options
Diffstat (limited to 'gnulib-tool')
-rwxr-xr-x | gnulib-tool | 65 |
1 files changed, 56 insertions, 9 deletions
diff --git a/gnulib-tool b/gnulib-tool index 7c2efc6228..ef2bd46b71 100755 --- a/gnulib-tool +++ b/gnulib-tool @@ -117,6 +117,7 @@ func_usage () { echo "\ Usage: gnulib-tool --list + gnulib-tool --find filename gnulib-tool --import [module1 ... moduleN] gnulib-tool --update gnulib-tool --create-testdir --dir=directory [module1 ... moduleN] @@ -140,6 +141,7 @@ Usage: gnulib-tool --list Operation modes: --list print the available module names + --find find the modules which contain the specified file --import import the given modules into the current package; if no modules are specified, update the current package from the current gnulib @@ -901,6 +903,9 @@ fi --list | --lis ) mode=list shift ;; + --find | --fin | --fi | --f ) + mode=find + shift ;; --import | --impor | --impo | --imp | --im | --i ) mode=import shift ;; @@ -1291,6 +1296,23 @@ func_lookup_file () fi } +# func_sanitize_modulelist +# receives a list of possible module names on standard input, one per line. +# It removes those which are just file names unrelated to modules, and outputs +# the resulting list to standard output, one per line. +func_sanitize_modulelist () +{ + sed -e '/^CVS\//d' -e '/\/CVS\//d' \ + -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \ + -e '/^COPYING$/d' -e '/\/COPYING$/d' \ + -e '/^README$/d' -e '/\/README$/d' \ + -e '/^TEMPLATE$/d' \ + -e '/^TEMPLATE-EXTENDED$/d' \ + -e '/^TEMPLATE-TESTS$/d' \ + -e '/^\..*/d' \ + -e '/~$/d' +} + # func_all_modules # Input: # - local_gnulib_dir from --local-dir @@ -1305,15 +1327,7 @@ func_all_modules () (cd "$local_gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,' -e 's,\.diff$,,') fi } \ - | sed -e '/^CVS\//d' -e '/\/CVS\//d' \ - -e '/^ChangeLog$/d' -e '/\/ChangeLog$/d' \ - -e '/^COPYING$/d' -e '/\/COPYING$/d' \ - -e '/^README$/d' -e '/\/README$/d' \ - -e '/^TEMPLATE$/d' \ - -e '/^TEMPLATE-EXTENDED$/d' \ - -e '/^TEMPLATE-TESTS$/d' \ - -e '/^\..*/d' \ - -e '/~$/d' \ + | func_sanitize_modulelist \ | sed -e '/-tests$/d' \ | LC_ALL=C sort -u } @@ -4997,6 +5011,39 @@ case $mode in func_all_modules ;; + find ) + # sed expression that converts a literal to a basic regular expression. + # Needs to handle . [ \ * ^ $. + sed_literal_to_basic_regex='s/\\/\\\\/g +s/\[/\\[/g +s/\^/\\^/g +s/\([.*$]\)/[\1]/g' + for filename + do + if test -f "$gnulib_dir/$filename" \ + || { test -n "$local_gnulib_dir" && test -f "$local_gnulib_dir/$filename"; }; then + filenameregex='^'`echo "$filename" | sed -e "$sed_literal_to_basic_regex"`'$' + module_candidates=` + { + (cd "$gnulib_dir" && find modules -type f -print | xargs -n 100 grep -l "$filenameregex" /dev/null | sed -e 's,^modules/,,') + if test -n "$local_gnulib_dir" && test -d "$local_gnulib_dir/modules"; then + (cd "$local_gnulib_dir" && find modules -type f -print | sed -e 's,^modules/,,' -e 's,\.diff$,,') + fi + } \ + | func_sanitize_modulelist \ + | LC_ALL=C sort -u + ` + for module in $module_candidates; do + if func_get_filelist $module | grep "$filenameregex" > /dev/null; then + echo $module + fi + done + else + func_warning "file $filename does not exist" + fi + done + ;; + import | update ) # Where to import. |