Rev 16209 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | #! /bin/sh |
2 | |||
16107 | bpr | 3 | #LL="env LC_COLLATE=POSIX LANG=POSIX LC_CTYPE=fr_FR.UTF-8" |
11566 | bpr | 4 | LL="env LC_ALL=C LC_CTYPE=C LANG=C" |
20 | reyssat | 5 | thisdir=`pwd` |
6 | lastdir=$thisdir |
||
16107 | bpr | 7 | |
18226 | bpr | 8 | if [ -z "$wims_home" ]; then wims_home=$1; fi; |
20 | reyssat | 9 | if [ -z "$wims_home" ]; then wims_home=$w_wims_home; fi |
10 | |||
11 | while [ -z "$wims_home" ] && [ "$lastdir" != "/" ] |
||
12 | do |
||
16107 | bpr | 13 | wims_home=`cat $lastdir/.wimshome 2>/dev/null` |
14 | lastdir=`dirname $lastdir` |
||
20 | reyssat | 15 | done |
16 | if [ -z "$wims_home" ]; then |
||
16107 | bpr | 17 | echo WIMS home directory not found. |
18 | exit; |
||
20 | reyssat | 19 | fi |
20 | proc=$wims_home/public_html/scripts/deduc |
||
18226 | bpr | 21 | test= |
22 | if [ ! -z "$w_wims_class" ]; then |
||
23 | test=`echo $thisdir | grep -a '/classes/..$'` |
||
24 | fi |
||
25 | if [ ! -z "$test" ] && [ -d $wims_home/log/classes/$w_wims_class ]; then |
||
26 | class_header=$wims_home/log/classes/$w_wims_class |
||
27 | ntest=`awk -F'=' '$1=="sharing_exo" {print $2}' $class_header/neighbors 2>/dev/null` |
||
28 | if [ ! -z "$ntest" ] && [ -d "$wims_home/log/classes/$ntest/src" ]; then |
||
29 | class_header=$wims_home/log/classes/$ntest |
||
30 | fi |
||
31 | def=$class_header/def |
||
32 | src=$class_header/src |
||
33 | exindex=$class_header/Exindex |
||
34 | extitles=$class_header/Extitles |
||
35 | dfindex=$class_header/Dataindex |
||
36 | exauth=$class_header/Exauthors |
||
37 | imindex=$class_header/Imindex |
||
38 | descindex=$class_header/Descindex |
||
39 | obsindex=$class_header/Obsindex |
||
40 | keywindex=$class_header/Exkeywords |
||
41 | dickeyword=$class_header/Dickeywords |
||
42 | tmp1=$class_header/tmp1 |
||
43 | tmp2=$class_header/tmp2 |
||
44 | imagedir=$src/images |
||
45 | mkdir -p $def |
||
46 | else |
||
47 | # not in a class ? |
||
48 | class_header= |
||
49 | def=def |
||
50 | src=src |
||
51 | exindex=Exindex |
||
52 | extitles=Extitles |
||
53 | exauth=Exauthors |
||
54 | dfindex=Dataindex |
||
55 | imindex=Imindex |
||
56 | descindex=Descindex |
||
57 | obsindex=Obsindex |
||
58 | keywindex=Exkeywords |
||
59 | dickeyword=Dickeywords |
||
60 | tmp1=tmp1 |
||
61 | tmp2=tmp2 |
||
62 | imagedir=images |
||
63 | fi |
||
20 | reyssat | 64 | |
18226 | bpr | 65 | if [ ! -d $def ]; then |
66 | echo 1>&2 "Directory $def not found." |
||
67 | exit; |
||
68 | fi |
||
69 | if [ ! -d $src ]; then |
||
70 | echo 1>&2 "Directory $src not found." |
||
71 | exit; |
||
72 | fi |
||
20 | reyssat | 73 | |
18226 | bpr | 74 | deff=`cd $def; ls *.def 2>/dev/null` |
20 | reyssat | 75 | for i in $deff |
76 | do |
||
16107 | bpr | 77 | dd=`echo $i | sed 's!\.def!.ded!g'` |
18226 | bpr | 78 | if [ ! -f $src/$dd ]; then |
79 | echo Removing $def/$i. |
||
80 | rm -f $def/$i >/dev/null; |
||
16107 | bpr | 81 | fi |
20 | reyssat | 82 | done |
83 | |||
18226 | bpr | 84 | # Processing ded src. |
20 | reyssat | 85 | sext=ded |
18226 | bpr | 86 | cd $src |
20 | reyssat | 87 | if [ -d cpp ]; then |
16107 | bpr | 88 | cd cpp |
89 | incf=`ls *.inc 2>/dev/null` |
||
90 | for i in $incf |
||
20 | reyssat | 91 | do |
16107 | bpr | 92 | list=`egrep -a -l '#[[:blank:]]*include[[:blank:]]+"'$i'"' *.inc 2>/dev/null` |
93 | for j in $list |
||
94 | do |
||
95 | if [ $i -nt $j ]; then touch $j; fi |
||
96 | done |
||
20 | reyssat | 97 | done |
16107 | bpr | 98 | for i in $incf |
20 | reyssat | 99 | do |
16107 | bpr | 100 | list=`egrep -a -l '#[[:blank:]]*include[[:blank:]]+"'$i'"' *.cpp 2>/dev/null` |
101 | for j in $list |
||
102 | do |
||
103 | if [ $i -nt $j ]; then touch $j; fi |
||
104 | done |
||
105 | done |
||
106 | pref=`ls *.cpp 2>/dev/null` |
||
107 | for i in $pref |
||
108 | do |
||
18226 | bpr | 109 | list=`$LL tr '\r' '\n' <$i | grep -a . | head -1 | grep -a target \ |
110 | | tr ',:;./?*#~$\\ ' ' ' \ |
||
111 | | awk -F'=' '{print $2}'` |
||
112 | test=`grep -a -E '^[[:blank:]]*#[[:blank:]]*include' $i \ |
||
113 | | grep -a -E -v '^[[:blank:]]*#[[:blank:]]*include[[:blank:]]*"[[:alnum:]_]+.inc"'` |
||
16107 | bpr | 114 | if [ ! -z "$test" ]; then |
115 | echo $i: include violation. $test |
||
116 | list= |
||
117 | fi |
||
18226 | bpr | 118 | test=`echo $list | grep "-"` |
119 | if [ ! -z "$test" ]; then |
||
120 | echo $i: character - not allowed in target. $test |
||
121 | list= |
||
122 | fi |
||
123 | ## perl -pi -e "s/#TARGET\s*\((\w+)\s*\)/defined TARGET_\1 /g" $i |
||
124 | $LL tr '\r' '\n' <$i | $LL sed "s/'/\'/g" | grep -a . | awk 'BEGIN {l=0}; {l++}; l>1 {print}' >cpp.tmp |
||
16107 | bpr | 125 | for j in $list |
126 | do |
||
127 | if [ ! -f ../$j.$sext ] || [ $i -nt ../$j.$sext ]; then |
||
128 | echo "Preprocessing: $i -> ../$j.$sext" |
||
129 | cat <<@ >../$j.$sext |
||
20 | reyssat | 130 | %% This file is generated by preprocessor! |
131 | %% Do not edit it by hand. |
||
132 | %% Edit the source file cpp/$i. |
||
133 | |||
134 | @ |
||
18226 | bpr | 135 | perl -pi -e "s/#TARGET\s*\((\w+)\s*\)/defined TARGET_\1 /g" cpp.tmp |
136 | cpp -P -C -nostdinc -nostdinc++ -DTARGET_$j -A"TARGET($j)" -DOEFFILE=$j cpp.tmp | \ |
||
137 | $LL sed "s/'/'/g" >>../$j.$sext |
||
16107 | bpr | 138 | fi |
139 | done |
||
140 | rm -f cpp.tmp |
||
20 | reyssat | 141 | done |
16107 | bpr | 142 | cd .. |
20 | reyssat | 143 | fi |
144 | |||
145 | srcf=`ls *.ded 2>/dev/null` |
||
18226 | bpr | 146 | cd $thisdir |
20 | reyssat | 147 | oef2wims_mdef="methods variables context environ equivalence startname goal newobject minsteps options" |
148 | export oef2wims_mdef |
||
149 | for i in $srcf |
||
150 | do |
||
18226 | bpr | 151 | dd=`echo $i | $LL sed 's!\.ded!.def!g'` |
152 | if [ ! -f $def/$dd ] || [ $src/$i -nt $def/$dd ]; then |
||
153 | rm -f $def/$dd 2>/dev/null |
||
154 | $wims_home/bin/oef2wims $src/$i $def/$dd |
||
16107 | bpr | 155 | fi |
20 | reyssat | 156 | done |
157 | |||
18226 | bpr | 158 | # Processing compiled .def files. |
159 | cd $def |
||
160 | list=`ls *.def 2>/dev/null | $LL sed 's/\.def//g'` |
||
161 | cd $thisdir |
||
162 | if [ -f "INDEX" ]; then |
||
163 | transl_lang=`grep -a translation_language INDEX | awk -F= '{print $2}'`; |
||
164 | module_lang=`grep -aw ^language INDEX | awk -F= '{print $2}'`; |
||
165 | fi |
||
166 | #if [ -z "$list" ]; then exit; fi |
||
167 | titlist= |
||
168 | titlist1= |
||
169 | list1= |
||
170 | rm -f $extitles.tmp |
||
171 | rm -f $exauth $descindex $obsindex $keywindex $dickeyword |
||
20 | reyssat | 172 | |
173 | for i in $list |
||
174 | do |
||
18226 | bpr | 175 | tit=`awk -F= 'NF>=2 {print $2; exit}' $def/$i.def | $LL tr ',\11' '; '` |
176 | echo "$i:$tit" >>$extitles.tmp |
||
177 | for lang in $transl_lang ; do |
||
178 | titl=`grep -a "title_$lang" $def/$i.def | awk -F= '{print $2}'`; |
||
179 | echo "$i:$titl" >>"${extitles}_$lang.tmp" |
||
180 | done |
||
16107 | bpr | 181 | titlist="$titlist$tit |
20 | reyssat | 182 | " |
18226 | bpr | 183 | titlist1="$titlist1$tit," |
184 | list1="$list1$i," |
||
20 | reyssat | 185 | done |
18226 | bpr | 186 | |
187 | # Processing dicsort. |
||
188 | $wims_home/bin/dicsort $extitles.tmp 1>/dev/null |
||
189 | if [ -s $extitles.tmp.sorted ]; then |
||
190 | cat $extitles.tmp.sorted >$extitles |
||
191 | rm -f $extitles.tmp* |
||
192 | else |
||
193 | rm -f $extitles.tmp.sorted |
||
194 | echo >$extitles |
||
20 | reyssat | 195 | fi |
196 | |||
18226 | bpr | 197 | # Processing trans_lang. |
198 | for lang in $transl_lang |
||
199 | do |
||
200 | $wims_home/bin/dicsort "${extitles}_$lang.tmp" |
||
201 | if [ -s "${extitles}_$lang.tmp.sorted" ]; then |
||
202 | cat "${extitles}_$lang.tmp.sorted" > "${extitles}_$lang" |
||
203 | else |
||
204 | echo >"${extitles}_$lang" |
||
205 | fi |
||
206 | done |
||
207 | rm -f *.tmp *.sorted |
||
20 | reyssat | 208 | |
18226 | bpr | 209 | echo "$titlist" >$tmp1 |
210 | echo "$list" >$tmp2 |
||
211 | llist=`$LL paste $tmp1 $tmp2 | $LL sort -t ' ' -f -k 1,1` |
||
212 | list1=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $2}' | $LL tr '\n' ' '` |
||
213 | list=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $2}' | $LL tr '\n' ','` |
||
214 | titlist=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $1}' | $LL tr '\n' ','` |
||
215 | |||
216 | rm -f $tmp1 $tmp2 |
||
217 | cat >$exindex <<@ |
||
20 | reyssat | 218 | !set exolist =!char 1 to -2 of $list |
219 | !set titlelist=!char 1 to -2 of $titlist |
||
18226 | bpr | 220 | !set titlelist_$module_lang=!char 1 to -2 of $titlist |
20 | reyssat | 221 | !set exototal =!itemcnt \$exolist |
222 | |||
223 | @ |
||
18226 | bpr | 224 | |
225 | for lang in $transl_lang ; do |
||
226 | for ex in $list1; do |
||
227 | a=`grep -a title_$lang $def/$ex.def | awk -F= '{print $2}'`; |
||
228 | if [ -z "$a" ]; then a=`grep -a "!set title" $def/$ex.def | awk -F= '{print $2}'` ; fi |
||
229 | echo "$a">>tmp1 |
||
230 | done |
||
231 | titlist2=`cat $tmp1 | $LL tr '\n' ','` ; |
||
232 | rm -f $tmp1 |
||
233 | cat >>$exindex <<@ |
||
234 | !set titlelist_$lang=!char 1 to -2 of $titlist2 |
||
235 | @ |
||
236 | done |
||
237 | |||
238 | ## keywords:exercises |
||
239 | cd $thisdir |
||
240 | export KEYWINDEX; KEYWINDEX="$keywindex"; |
||
241 | export DICKEYWORD; DICKEYWORD="$dickeyword"; |
||
242 | perl <<'EOF' |
||
243 | my %hash=();my $TEXT=''; my $hash=\%hash; |
||
244 | my ($file)=$ENV{KEYWINDEX}; open(IN, "$file"); |
||
245 | while(<IN>) { |
||
246 | my @a=split(":", $_); my @b=split(",", $a[1]); |
||
247 | for my $c (@b){ chomp $c; $c=~ s/^\s+//; $c=~ s/\s+$//; $hash->{$c} .= "$a[0],";} |
||
248 | } |
||
249 | for my $aa (keys %hash){ chop $hash->{$aa}; $TEXT .= "$aa:$hash->{$aa}\n";}; |
||
250 | if ($TEXT) { |
||
251 | open (OUT, ">$ENV{DICKEYWORD}"); print OUT $TEXT; close OUT; |
||
252 | } |
||
253 | EOF |
||
254 | |||
255 | #### index of files in images/ "name:directory" |
||
256 | cd $thisdir |
||
257 | rm -f $imindex |
||
258 | if [ -d $imagedir ]; then |
||
259 | images=`cd $imagedir ; find * -type f 2>/dev/null` |
||
260 | if [ -z "$images" ]; then |
||
261 | echo "<!-- This file is automatically generated. Do not edit! -->" >$imindex |
||
262 | for i in $images ; do d=`dirname $i` ; file=`basename $i` ; |
||
263 | echo "$file:$d" >> $imindex ; |
||
264 | done; |
||
265 | fi |
||
266 | fi |
||
267 | |||
268 | [ -n "$class_header" ] && exit |
||
269 | |||
270 | # Datafiles |
||
271 | |||
272 | if [ -d src/data ]; then |
||
273 | datafiles=`cd src/data; ls *.data | sed 's/\.data$//'` |
||
274 | rm -f $dfindex.tmp |
||
275 | for df in $datafiles; do |
||
276 | tit=`awk 'NF>0 {if($1 ~ /^[^.:]/) print; exit}' src/data/$df.data` |
||
277 | author=`awk -F.author '/^.author / {print $2}' src/data/$df.data`; |
||
278 | recordcnt=`awk '/^:/{i++}END{print i}' src/data/$df.data` |
||
279 | [ -z "$tit" ] && tit=$df |
||
280 | echo "$df,$tit,$author,$recordcnt" >>$dfindex.tmp |
||
281 | done |
||
282 | $LL sort -f -t, -k2 <$dfindex.tmp >$dfindex |
||
283 | rm -f $dfindex.tmp |
||
284 | fi |
||
285 | |||
286 | # Gather content for robots. |
||
287 | |||
288 | outputfile=content.html |
||
289 | |||
290 | tit= |
||
291 | echo "<!-- This file is automatically generated. Do not edit! -->" >$outputfile |
||
292 | for f in `ls $def/*.def 2>/dev/null`; do |
||
293 | tit=`head -1 $f | $LL cut -d= -f2` |
||
294 | [ -z "$tit" ] && continue |
||
295 | content=`awk 'BEGIN {a=0}; |
||
296 | NF == 0 {next}; |
||
297 | /!exit/ {a=0}; |
||
298 | /^!/ {next}; |
||
299 | a > 0 {print}; |
||
300 | /^:question/ {a=1}; |
||
301 | ' $f | $LL sed 's/\$()//g'` |
||
302 | echo "<hr> |
||
303 | <h3>$tit</h3> |
||
304 | $content |
||
305 | " >>$outputfile |
||
306 | tit= |
||
307 | done |