sphinx: don't try to dereference NULL input_buf_t.
[profile/ivi/speech-recognition.git] / build-aux / enlicense
1 #!/bin/bash
2
3 TOP="${0%/*}/.."
4 LICENSE="$TOP/LICENSE-BSD"
5 EXCLUDE=""
6
7 show_usage () {
8     echo "usage: $0 [options]"
9     echo "The possible options are:"
10     echo "  --dry-run|-n         Just find files lacking license info."
11     echo "  --license|-L <file>  Use file to obtain license text."
12     echo "  --git|-g             Add license only to files in the repository."
13     echo "  --exclude|-e <pat>   Exclude files matching egrep pattern <pat>."
14     echo "  --help|-h            Show this help and exit."
15 }
16
17 fatal () {
18     local _err _msg
19
20     _err="$1"
21     shift
22     _msg="$*"
23
24     echo "fatal error: $_msg"
25     exit $_err
26 }
27
28 enlicense () {
29     local _file _in _out
30
31     case $1 in
32         *-func-info.c)
33             return 0
34             ;;
35     esac
36
37     _file="$1"
38     _in="$1.no-license"
39     _out="$1.license"
40
41     cp $_file $_in
42     echo "Inserting licensing information to $_file..."
43     echo "/*"                                    > $_out
44     cat $LICENSE | sed 's/^    /  /g;s/^/ * /g' \
45                  | sed 's/ *$//g'               >> $_out
46     echo " */"                                  >> $_out
47     echo ""                                     >> $_out
48     cat $_in                                    >> $_out
49     cp $_out $_file
50 }
51
52 find_missing_licenses () {
53     local _lacking _files _f
54
55     _lacking=""
56     if [ -z "$EXCLUDE" ]; then
57         _files="`find . -name '*.[hc]'`"
58     else
59         _files="`find . -name '*.[hc]' | egrep -v -e $EXCLUDE`"
60     fi
61
62     for _f in $_files; do
63         _f="${_f#./}"
64         grep -ql 'Copyright .*Intel .*' $_f
65         if [ $? != 0 ]; then
66             if [ "$GIT" = "y" ]; then
67                 git ls-files | grep -q "$_f\$" && _lacking="$_lacking $_f" || :
68             else
69                 _lacking="$_lacking $_f"
70             fi
71         fi
72     done
73
74     echo "$_lacking"
75 }
76
77
78 DRY_RUN=""
79 GIT=""
80
81 while [ "${1#-}" != "$1" -a -n "$1" ]; do
82     case $1 in
83         --dry-run|-n)
84             DRY_RUN="y"
85             ;;
86         --license|-L)
87             if [ -n "$2" ]; then
88                 shift
89                 LICENSE="$1"
90             else
91                 fatal 1 "missing license argument"
92             fi
93             ;;
94         --git|-g)
95             GIT="y"
96             ;;
97         --exclude|-e)
98             if [ -n "$2" ]; then
99                 shift
100                 EXCLUDE="$1"
101             else
102                 fatal 1 "missing exclusion pattern"
103             fi
104             ;;
105         --help|-h)
106             show_usage
107             exit 0
108             ;;
109          *)
110             echo "Unknown command line option \'$1\'."
111             show_usage
112             exit 1
113             ;;
114     esac
115     shift
116 done
117
118 if [ ! -f "$LICENSE" ]; then
119     fatal 1 "license file \'$LICENSE\' missing"
120 fi
121
122 pushd $TOP >& /dev/null
123
124 lacking="`find_missing_licenses`"
125
126 for f in $lacking; do
127     if [ "$DRY_RUN" != "y" ]; then
128         enlicense $f
129     else
130         echo "$f is lacking licensing information."
131     fi
132 done