Rev 17176 | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
20 | reyssat | 1 | #! /bin/sh |
2 | |||
13636 | bpr | 3 | #LL="env LC_COLLATE=POSIX LANG=POSIX LC_CTYPE=fr_FR.UTF-8" |
8769 | bpr | 4 | LL="env LC_ALL=C LC_CTYPE=C LANG=C" |
20 | reyssat | 5 | thisdir=`pwd` |
6 | lastdir=$thisdir |
||
6072 | bpr | 7 | |
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 |
||
13639 | obado | 13 | wims_home=`cat $lastdir/.wimshome 2>/dev/null` |
14 | lastdir=`dirname $lastdir` |
||
20 | reyssat | 15 | done |
16 | if [ -z "$wims_home" ]; then |
||
13639 | obado | 17 | echo WIMS home directory not found. |
18 | exit; |
||
20 | reyssat | 19 | fi |
20 | |||
21 | test= |
||
22 | if [ ! -z "$w_wims_class" ]; then |
||
14652 | bpr | 23 | test=`echo $thisdir | grep -a '/classes/..$'` |
20 | reyssat | 24 | fi |
25 | if [ ! -z "$test" ] && [ -d $wims_home/log/classes/$w_wims_class ]; then |
||
16346 | obado | 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 |
||
20 | reyssat | 46 | else |
16346 | obado | 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 |
||
20 | reyssat | 63 | fi |
64 | |||
7434 | bpr | 65 | if [ ! -d $def ]; then |
13639 | obado | 66 | echo 1>&2 "Directory $def not found." |
67 | exit; |
||
20 | reyssat | 68 | fi |
69 | if [ ! -d $src ]; then |
||
13639 | obado | 70 | echo 1>&2 "Directory $src not found." |
71 | exit; |
||
20 | reyssat | 72 | fi |
73 | |||
74 | deff=`cd $def; ls *.def 2>/dev/null` |
||
75 | for i in $deff |
||
76 | do |
||
13639 | obado | 77 | dd=`echo $i | sed 's!\.def!.oef!g'` |
78 | if [ ! -f $src/$dd ]; then |
||
79 | echo Removing $def/$i. |
||
80 | rm -f $def/$i >/dev/null; |
||
81 | fi |
||
20 | reyssat | 82 | done |
83 | |||
16346 | obado | 84 | # Processing OEF src. |
20 | reyssat | 85 | sext=oef |
86 | cd $src |
||
87 | if [ -d cpp ]; then |
||
13639 | obado | 88 | cd cpp |
89 | incf=`ls *.inc 2>/dev/null` |
||
90 | for i in $incf |
||
20 | reyssat | 91 | do |
14652 | bpr | 92 | list=`egrep -a -l '#[[:blank:]]*include[[:blank:]]+"'$i'"' *.inc 2>/dev/null` |
14176 | bpr | 93 | for j in $list |
94 | do |
||
95 | if [ $i -nt $j ]; then touch $j; fi |
||
96 | done |
||
97 | done |
||
98 | for i in $incf |
||
99 | do |
||
14652 | bpr | 100 | list=`egrep -a -l '#[[:blank:]]*include[[:blank:]]+"'$i'"' *.cpp 2>/dev/null` |
13639 | obado | 101 | for j in $list |
102 | do |
||
103 | if [ $i -nt $j ]; then touch $j; fi |
||
104 | done |
||
20 | reyssat | 105 | done |
13639 | obado | 106 | pref=`ls *.cpp 2>/dev/null` |
107 | for i in $pref |
||
108 | do |
||
14652 | bpr | 109 | list=`$LL tr '\r' '\n' <$i | grep -a . | head -1 | grep -a target \ |
13639 | obado | 110 | | tr ',:;./?*#~$\\ ' ' ' \ |
111 | | awk -F'=' '{print $2}'` |
||
14652 | bpr | 112 | test=`grep -a -E '^[[:blank:]]*#[[:blank:]]*include' $i \ |
113 | | grep -a -E -v '^[[:blank:]]*#[[:blank:]]*include[[:blank:]]*"[[:alnum:]_]+.inc"'` |
||
13639 | obado | 114 | if [ ! -z "$test" ]; then |
115 | echo $i: include violation. $test |
||
116 | list= |
||
117 | fi |
||
16248 | bpr | 118 | test=`echo $list | grep "-"` |
119 | if [ ! -z "$test" ]; then |
||
16269 | bpr | 120 | echo $i: character - not allowed in target. $test |
16248 | bpr | 121 | list= |
122 | fi |
||
8461 | bpr | 123 | ## perl -pi -e "s/#TARGET\s*\((\w+)\s*\)/defined TARGET_\1 /g" $i |
17100 | bpr | 124 | $LL tr '\r' '\n' <$i | $LL sed "s/'/\'/g" | grep -a . | awk 'BEGIN {l=0}; {l++}; l>1 {print}' >cpp.tmp |
13639 | obado | 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 | @ |
||
13639 | obado | 135 | perl -pi -e "s/#TARGET\s*\((\w+)\s*\)/defined TARGET_\1 /g" cpp.tmp |
17210 | czzmrn | 136 | cpp -P -C -nostdinc -nostdinc++ -DTARGET_$j -A"TARGET($j)" -DOEFFILE=$j cpp.tmp | \ |
13639 | obado | 137 | $LL sed "s/'/'/g" >>../$j.$sext |
138 | fi |
||
139 | done |
||
140 | rm -f cpp.tmp |
||
20 | reyssat | 141 | done |
13639 | obado | 142 | cd .. |
20 | reyssat | 143 | fi |
144 | |||
145 | srcf=`ls *.oef 2>/dev/null` |
||
146 | cd $thisdir |
||
147 | oef2wims_mdef="oefenv" |
||
148 | export oef2wims_mdef |
||
149 | for i in $srcf |
||
150 | do |
||
13639 | obado | 151 | dd=`echo $i | $LL sed 's!\.oef!.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 |
||
155 | fi |
||
20 | reyssat | 156 | done |
157 | |||
16346 | obado | 158 | # Processing compiled .def files. |
20 | reyssat | 159 | cd $def |
8769 | bpr | 160 | list=`ls *.def 2>/dev/null | $LL sed 's/\.def//g'` |
20 | reyssat | 161 | cd $thisdir |
7434 | bpr | 162 | if [ -f "INDEX" ]; then |
14652 | bpr | 163 | transl_lang=`grep -a translation_language INDEX | awk -F= '{print $2}'`; |
15438 | bpr | 164 | module_lang=`grep -aw ^language INDEX | awk -F= '{print $2}'`; |
7234 | bpr | 165 | fi |
20 | reyssat | 166 | #if [ -z "$list" ]; then exit; fi |
167 | titlist= |
||
983 | bpr | 168 | titlist1= |
169 | list1= |
||
20 | reyssat | 170 | rm -f $extitles.tmp |
13636 | bpr | 171 | rm -f $exauth $descindex $obsindex $keywindex $dickeyword |
16346 | obado | 172 | |
20 | reyssat | 173 | for i in $list |
174 | do |
||
16346 | obado | 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 |
||
181 | titlist="$titlist$tit |
||
20 | reyssat | 182 | " |
16346 | obado | 183 | titlist1="$titlist1$tit," |
184 | list1="$list1$i," |
||
17087 | guerimand | 185 | auth=`grep -a -m1 ^author $def/$i.def | awk -F= '{print $2}'`; |
16346 | obado | 186 | echo "$i:$auth" >> $exauth |
17087 | guerimand | 187 | desc=`grep -a -m1 ^oefdescription $def/$i.def | awk -F= '{print $2}'`; |
16346 | obado | 188 | if [ ! -z "$desc" ] ; then echo "$i:$desc" >> $descindex ; fi |
17087 | guerimand | 189 | obs=`grep -a -m1 ^oefobservation $def/$i.def | awk -F= '{print $2}'`; |
16346 | obado | 190 | if [ ! -z "$obs" ] ; then echo "$i:$obs" >> $obsindex ; fi; |
191 | obs="" |
||
17087 | guerimand | 192 | keyw=`grep -a -m1 ^keywords $def/$i.def | awk -F= '{print $2}'`; |
16346 | obado | 193 | if [ ! -z "$keyw" ] ; then echo "$i:$keyw" >> $keywindex ; fi |
20 | reyssat | 194 | done |
16346 | obado | 195 | |
196 | # Processing dicsort. |
||
9658 | bpr | 197 | $wims_home/bin/dicsort $extitles.tmp 1>/dev/null |
20 | reyssat | 198 | if [ -s $extitles.tmp.sorted ]; then |
13639 | obado | 199 | cat $extitles.tmp.sorted >$extitles |
200 | rm -f $extitles.tmp* |
||
20 | reyssat | 201 | else |
13639 | obado | 202 | rm -f $extitles.tmp.sorted |
203 | echo >$extitles |
||
20 | reyssat | 204 | fi |
16346 | obado | 205 | |
206 | # Processing trans_lang. |
||
6431 | bpr | 207 | for lang in $transl_lang |
208 | do |
||
209 | $wims_home/bin/dicsort "${extitles}_$lang.tmp" |
||
210 | if [ -s "${extitles}_$lang.tmp.sorted" ]; then |
||
13639 | obado | 211 | cat "${extitles}_$lang.tmp.sorted" > "${extitles}_$lang" |
6431 | bpr | 212 | else |
13639 | obado | 213 | echo >"${extitles}_$lang" |
6431 | bpr | 214 | fi |
215 | done |
||
216 | rm -f *.tmp *.sorted |
||
20 | reyssat | 217 | |
218 | echo "$titlist" >$tmp1 |
||
219 | echo "$list" >$tmp2 |
||
983 | bpr | 220 | llist=`$LL paste $tmp1 $tmp2 | $LL sort -t ' ' -f -k 1,1` |
3574 | bpr | 221 | list1=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $2}' | $LL tr '\n' ' '` |
222 | list=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $2}' | $LL tr '\n' ','` |
||
223 | titlist=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $1}' | $LL tr '\n' ','` |
||
20 | reyssat | 224 | |
3288 | bpr | 225 | rm -f $tmp1 $tmp2 |
20 | reyssat | 226 | cat >$exindex <<@ |
227 | !set exolist =!char 1 to -2 of $list |
||
228 | !set titlelist=!char 1 to -2 of $titlist |
||
15430 | bpr | 229 | !set titlelist_$module_lang=!char 1 to -2 of $titlist |
20 | reyssat | 230 | !set exototal =!itemcnt \$exolist |
231 | |||
232 | @ |
||
233 | |||
3288 | bpr | 234 | for lang in $transl_lang ; do |
7434 | bpr | 235 | for ex in $list1; do |
14652 | bpr | 236 | a=`grep -a title_$lang $def/$ex.def | awk -F= '{print $2}'`; |
237 | if [ -z "$a" ]; then a=`grep -a "!set title" $def/$ex.def | awk -F= '{print $2}'` ; fi |
||
17053 | bpr | 238 | echo "$a">>tmp1 |
3288 | bpr | 239 | done |
240 | titlist2=`cat $tmp1 | $LL tr '\n' ','` ; |
||
241 | rm -f $tmp1 |
||
242 | cat >>$exindex <<@ |
||
243 | !set titlelist_$lang=!char 1 to -2 of $titlist2 |
||
244 | @ |
||
245 | done |
||
7324 | bpr | 246 | |
13636 | bpr | 247 | ## keywords:exercises |
248 | cd $thisdir |
||
249 | export KEYWINDEX; KEYWINDEX="$keywindex"; |
||
250 | export DICKEYWORD; DICKEYWORD="$dickeyword"; |
||
251 | perl <<'EOF' |
||
252 | my %hash=();my $TEXT=''; my $hash=\%hash; |
||
253 | my ($file)=$ENV{KEYWINDEX}; open(IN, "$file"); |
||
254 | while(<IN>) { |
||
255 | my @a=split(":", $_); my @b=split(",", $a[1]); |
||
256 | for my $c (@b){ chomp $c; $c=~ s/^\s+//; $c=~ s/\s+$//; $hash->{$c} .= "$a[0],";} |
||
257 | } |
||
258 | for my $aa (keys %hash){ chop $hash->{$aa}; $TEXT .= "$aa:$hash->{$aa}\n";}; |
||
259 | if ($TEXT) { |
||
260 | open (OUT, ">$ENV{DICKEYWORD}"); print OUT $TEXT; close OUT; |
||
261 | } |
||
262 | EOF |
||
263 | |||
7324 | bpr | 264 | #### index of files in images/ "name:directory" |
265 | cd $thisdir |
||
266 | rm -f $imindex |
||
267 | if [ -d $imagedir ]; then |
||
268 | images=`cd $imagedir ; find * -type f 2>/dev/null` |
||
16346 | obado | 269 | if [ -z "$images" ]; then |
270 | echo "<!-- This file is automatically generated. Do not edit! -->" >$imindex |
||
13636 | bpr | 271 | for i in $images ; do d=`dirname $i` ; file=`basename $i` ; |
272 | echo "$file:$d" >> $imindex ; |
||
273 | done; |
||
16346 | obado | 274 | fi |
7324 | bpr | 275 | fi |
276 | |||
20 | reyssat | 277 | [ -n "$class_header" ] && exit |
278 | |||
279 | # Datafiles |
||
280 | |||
281 | if [ -d src/data ]; then |
||
13639 | obado | 282 | datafiles=`cd src/data; ls *.data | sed 's/\.data$//'` |
283 | rm -f $dfindex.tmp |
||
284 | for df in $datafiles; do |
||
285 | tit=`awk 'NF>0 {if($1 ~ /^[^.:]/) print; exit}' src/data/$df.data` |
||
16346 | obado | 286 | author=`awk -F.author '/^.author / {print $2}' src/data/$df.data`; |
13639 | obado | 287 | recordcnt=`awk '/^:/{i++}END{print i}' src/data/$df.data` |
288 | [ -z "$tit" ] && tit=$df |
||
16346 | obado | 289 | echo "$df,$tit,$author,$recordcnt" >>$dfindex.tmp |
13639 | obado | 290 | done |
291 | $LL sort -f -t, -k2 <$dfindex.tmp >$dfindex |
||
292 | rm -f $dfindex.tmp |
||
20 | reyssat | 293 | fi |
294 | |||
295 | # Gather content for robots. |
||
296 | |||
297 | outputfile=content.html |
||
298 | |||
299 | tit= |
||
300 | echo "<!-- This file is automatically generated. Do not edit! -->" >$outputfile |
||
9658 | bpr | 301 | for f in `ls $def/*.def 2>/dev/null`; do |
13639 | obado | 302 | tit=`head -1 $f | $LL cut -d= -f2` |
303 | [ -z "$tit" ] && continue |
||
304 | content=`awk 'BEGIN {a=0}; |
||
305 | NF == 0 {next}; |
||
306 | /!exit/ {a=0}; |
||
307 | /^!/ {next}; |
||
308 | a > 0 {print}; |
||
309 | /^:question/ {a=1}; |
||
310 | ' $f | $LL sed 's/\$()//g'` |
||
17176 | bpr | 311 | echo "<hr> |
20 | reyssat | 312 | <h3>$tit</h3> |
313 | $content |
||
314 | " >>$outputfile |
||
315 | tit= |
||
316 | done |