2009-06-20 Zoltan Varga <vargaz@gmail.com>
[mcs.git] / tools / gensources.sh
blob7e71029d8bc8b374d441c9c1a58eed0affcaf8ea
1 #!/usr/bin/env bash
3 includefile=$1
4 excludefile=$2
6 ## input variables:
7 ## $filelist:
8 ## A colon (':') separated list of files already read.
9 ## Must be initialized to ":".
10 ## $excludelist:
11 ## A newline separated of element (support Shell Patterns) to exclude.
12 ## $separator:
13 ## The separator used in list for the output
14 ##
15 ## output variables:
16 ## $list:
17 ## A list of elements separated by the separator given in $separator.
18 ## The new elements will be appended to the list.
19 readlist () {
20 local onelist
21 local onelistcontent
22 onelist=$1
24 if [ ":$onelist:" = "::" ] ; then return ; fi
25 if [ ! -f $onelist ] ; then return ; fi
26 if [ ":${filelist##*:$onelist:*}:" = "::" ] ; then return ; fi
27 filelist=":$onelist$filelist"
29 onelistcontent=`cat $onelist | sed "s=[ \t]*$==g" | while read line ; do echo -n $line ; echo -n ":" ; done`
31 OFS="$IFS"
32 IFS=":"
33 for line in $onelistcontent ; do
34 line2=${line##\#}
35 if [ ":$line:" = ":$line2:" ] ; then
36 for linex in $excludelist ; do
37 if [ ":${line##$linex}:" = "::" ] ; then line="" ; fi
38 done
39 if [ ":$line:" != "::" ] ; then
40 if [ ":$list:" = "::" ] ; then
41 list="$line"
42 else
43 list="$list$separator$line"
46 else
47 line3=${line2##include }
48 if [ ":$line3:" != ":$line2:" -a ":$line3:" != "::" ] ; then
49 readlist "$line3"
52 done
53 IFS="$OFS"
56 list=""
57 filelist=":"
58 excludelist=""
59 separator=":"
60 readlist "$excludefile"
62 excludelist="$list"
63 list=""
64 filelist=":"
65 separator="
67 readlist "$includefile"
68 echo "$list" | sort | uniq