"Fossies" - the Fresh Open Source Software Archive

Member "fslint-2.46/fslint/supprt/getfpf" (2 Feb 2017, 1897 Bytes) of package /linux/privat/fslint-2.46.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "getfpf": 2.44_vs_2.46.

    1 #!/bin/bash
    2 # This is not meant to be called directly!
    3 #
    4 # getfpf = get Find Path Format
    5 #
    6 # This script is used to get the correct find format for
    7 # ls etc. I.E. whether full path needs to be returned
    8 # or just the basename
    9 #
   10 # Usage: . getfpf $@
   11 # Also must do set -f before calling this
   12 # as this doesn't work correctly with filename globbing
   13 #
   14 # Returns: printf format in $FPF (Find Path format)
   15 #          find parameters in "$@"
   16 #
   17 # TODO: Have option when 1 dir specified
   18 #       which is not . or ./ or ./././. (use basename
   19 #       to reduce all these to .) then %p returned
   20 
   21 num_files=0
   22 files=
   23 switches=
   24 onfindswitches=false
   25 forcefullpath=false
   26 
   27 eval set -- "$@"
   28 for arg in "$@";
   29 do
   30    case "$arg" in
   31    -r) #turn OFF recursion
   32       switches="$switches -maxdepth 1" ;;
   33       #don't say onfindswitches=true since want to allow -r before paths
   34    -f) #force full paths even if only 1 specified
   35       forcefullpath=true ;;
   36    -*|\(|\)|!) #pass other switches onto find
   37       switches="$switches '$arg'"
   38       onfindswitches=true ;;
   39    *)
   40       if [ "$onfindswitches" = "true" ]; then
   41          switches="$switches '$arg'"
   42       else
   43          num_files=`expr $num_files + 1`
   44          if [ -z "$files" ]; then
   45             files="$(shell_quote "$arg")"
   46          else
   47             files="$files $(shell_quote "$arg")"
   48          fi
   49       fi ;;
   50    esac
   51 done
   52 
   53 if [ $num_files -gt 1 ]; then
   54    FPF="%p"
   55    findArgs="$files $switches"
   56 else
   57    if [ $forcefullpath = "true" ]; then
   58       findArgs="$files $switches"
   59       FPF="%p"
   60    else
   61       findArgs="$switches"
   62       FPF="%P"
   63 
   64       if [ $num_files -eq 1 ]; then #only cd if path specified
   65          findArgs="$files $switches"
   66          eval files=$files #remove quotes
   67          if [ -d "$files" ]; then
   68             cd "$files"
   69             findArgs="$switches"
   70          else
   71             FPF="%p"
   72          fi
   73       fi
   74    fi
   75 fi
   76 eval set -- "$findArgs"