summaryrefslogtreecommitdiff
path: root/report/prune_results/lib.sh
blob: ff951c6444007447a7a403e7166afe336a9c38f4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
echo2() {
 echo "$@" 1>&2
}

errorq() {
 echo2 ERROR: "$@"
}

error() {
 errorq "$@"
 return 2
}

showvars_required() {
 echo2 $0 RUNNING WITH REQUIRED VARIABLES:
    local k
 for k in "$@"; do
  eval local v=\$$k
  echo2 $k=$v
  if [ -z "$v" ] ; then
    errorq "required (environment or shell) variable $k not defined!"
    return 1
  fi
 done
 echo2
}

showvars_optional() {
 echo2 RUNNING WITH OPTIONAL VARIABLES:
    local k
 for k in "$@"; do
  if isset $k ; then
   eval local v=\$$k
   echo2 $k=$v
  else
   echo2 UNSET: $k
   fi
 done
 echo2
}

require_files() {
 local f
 [ "$*" ] || error "require_files called with empty args list"
 for f in "$@"; do
    if ! have_file "$f" ; then
        error "missing required file: $f"
        return 1
    fi
 done
 return 0
}

have_file() {
    [ "$1" -a -f "$1" -a \( -z "$2" -o "$1" -nt "$2" \)  -a \( -z "$require_nonempty" -o -s "$1" \) ]
}

filename_from() {
  perl -e '
sub superchomp {
    my ($ref)=@_;
    if ($$ref) {
        $$ref =~ s|^\s+||;
        $$ref =~ s|\s+$||;
        $$ref =~ s|\s+| |g;
    }
}

sub filename_from {
    my ($fname)=@_;
   &superchomp(\$fname);
   $fname =~ s|[^a-zA-Z0-9_-]+|.|g;
   $fname =~ s|^\.|_|;
    return $fname;
}

$"=" ";print filename_from("@ARGV"),"\n"
' -- "$@"
}

preview() {
 tailn=${tailn:-20}
 head -v -n $tailn "$@"
}

isset() {
  eval local v=\${$1+set}
  [ "$v" = set ]
}