File: mkindex

package info (click to toggle)
wims 2%3A4.29a%2Bdfsg1-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 185,704 kB
  • sloc: xml: 366,687; javascript: 120,570; ansic: 62,341; java: 62,170; sh: 7,744; perl: 3,937; yacc: 3,217; cpp: 1,915; lex: 1,805; makefile: 1,084; lisp: 914; pascal: 601; python: 520; php: 318; asm: 7
file content (316 lines) | stat: -rwxr-xr-x 8,677 bytes parent folder | download | duplicates (3)
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
#! /bin/sh

#LL="env LC_COLLATE=POSIX LANG=POSIX LC_CTYPE=fr_FR.UTF-8"
LL="env LC_ALL=C LC_CTYPE=C LANG=C"
thisdir=`pwd`
lastdir=$thisdir

if [ -z "$wims_home" ]; then wims_home=$1; fi;
if [ -z "$wims_home" ]; then wims_home=$w_wims_home; fi

while [ -z "$wims_home" ] && [ "$lastdir" != "/" ]
do
  wims_home=`cat $lastdir/.wimshome 2>/dev/null`
  lastdir=`dirname $lastdir`
done
if [ -z "$wims_home" ]; then
  echo WIMS home directory not found.
  exit;
fi

test=
if [ ! -z "$w_wims_class" ]; then
  test=`echo $thisdir | grep -a '/classes/..$'`
fi
if [ ! -z "$test" ] && [ -d $wims_home/log/classes/$w_wims_class ]; then
  class_header=$wims_home/log/classes/$w_wims_class
  ntest=`awk -F'=' '$1=="sharing_exo" {print $2}' $class_header/neighbors 2>/dev/null`
  if [ ! -z "$ntest" ] && [ -d "$wims_home/log/classes/$ntest/src" ]; then
    class_header=$wims_home/log/classes/$ntest
  fi
  def=$class_header/def
  src=$class_header/src
  exindex=$class_header/Exindex
  extitles=$class_header/Extitles
  dfindex=$class_header/Dataindex
  exauth=$class_header/Exauthors
  imindex=$class_header/Imindex
  descindex=$class_header/Descindex
  obsindex=$class_header/Obsindex
  keywindex=$class_header/Exkeywords
  dickeyword=$class_header/Dickeywords
  tmp1=$class_header/tmp1
  tmp2=$class_header/tmp2
  imagedir=$src/images
  mkdir -p $def
else
  # not in a class ?
  class_header=
  def=def
  src=src
  exindex=Exindex
  extitles=Extitles
  exauth=Exauthors
  dfindex=Dataindex
  imindex=Imindex
  descindex=Descindex
  obsindex=Obsindex
  keywindex=Exkeywords
  dickeyword=Dickeywords
  tmp1=tmp1
  tmp2=tmp2
  imagedir=images
fi

if [ ! -d $def ]; then
  echo 1>&2 "Directory $def not found."
  exit;
fi
if [ ! -d $src ]; then
  echo 1>&2 "Directory $src not found."
  exit;
fi

deff=`cd $def; ls *.def 2>/dev/null`
for i in $deff
do
  dd=`echo $i | sed 's!\.def!.oef!g'`
  if [ ! -f $src/$dd ]; then
    echo Removing $def/$i.
    rm -f $def/$i >/dev/null;
  fi
done

# Processing OEF src.
sext=oef
cd $src
if [ -d cpp ]; then
  cd cpp
  incf=`ls *.inc 2>/dev/null`
  for i in $incf
  do
    list=`egrep -a -l '#[[:blank:]]*include[[:blank:]]+"'$i'"' *.inc 2>/dev/null`
    for j in $list
    do
      if [ $i -nt $j ]; then touch $j; fi
    done
  done
  for i in $incf
  do
    list=`egrep -a -l '#[[:blank:]]*include[[:blank:]]+"'$i'"' *.cpp 2>/dev/null`
    for j in $list
    do
      if [ $i -nt $j ]; then touch $j; fi
    done
  done
  pref=`ls *.cpp 2>/dev/null`
  for i in $pref
  do
    list=`$LL tr '\r' '\n' <$i | grep -a . | head -1 | grep -a target \
    | tr ',:;./?*#~$\\ ' '                  ' \
    | awk -F'=' '{print $2}'`
    test=`grep -a -E '^[[:blank:]]*#[[:blank:]]*include' $i \
    | grep -a -E -v '^[[:blank:]]*#[[:blank:]]*include[[:blank:]]*"[[:alnum:]_]+.inc"'`
    if [ ! -z "$test" ]; then
      echo $i: include violation. $test
      list=
    fi
    test=`echo $list | grep "-"`
    if [ ! -z "$test" ]; then
      echo $i: character - not allowed in target. $test
      list=
    fi
## perl -pi -e "s/#TARGET\s*\((\w+)\s*\)/defined TARGET_\1 /g" $i
    $LL tr '\r' '\n' <$i | $LL sed "s/'/\&#39;/g" | grep -a . | awk 'BEGIN {l=0}; {l++}; l>1 {print}' >cpp.tmp
    for j in $list
    do
      if [ ! -f ../$j.$sext ] || [ $i -nt ../$j.$sext ]; then
        echo "Preprocessing: $i -> ../$j.$sext"
        cat <<@ >../$j.$sext
%% This file is generated by preprocessor!
%% Do not edit it by hand.
%% Edit the source file cpp/$i.

@
        perl -pi -e "s/#TARGET\s*\((\w+)\s*\)/defined TARGET_\1 /g" cpp.tmp
        cpp -P -C -nostdinc -nostdinc++ -DTARGET_$j -A"TARGET($j)" -DOEFFILE=$j cpp.tmp | \
        $LL sed "s/&#39;/'/g" >>../$j.$sext
      fi
    done
    rm -f cpp.tmp
  done
  cd ..
fi

srcf=`ls *.oef 2>/dev/null`
cd $thisdir
oef2wims_mdef="oefenv"
export oef2wims_mdef
for i in $srcf
do
  dd=`echo $i | $LL sed 's!\.oef!.def!g'`
  if [ ! -f $def/$dd ] || [ $src/$i -nt $def/$dd ]; then
    rm -f $def/$dd 2>/dev/null
    $wims_home/bin/oef2wims $src/$i $def/$dd
  fi
done

# Processing compiled .def files.
cd $def
list=`ls *.def 2>/dev/null | $LL sed 's/\.def//g'`
cd $thisdir
if [ -f "INDEX" ]; then
  transl_lang=`grep -a translation_language INDEX | awk -F= '{print $2}'`;
  module_lang=`grep -aw ^language INDEX | awk -F= '{print $2}'`;
fi
#if [ -z "$list" ]; then exit; fi
titlist=
titlist1=
list1=
rm -f $extitles.tmp
rm -f $exauth $descindex $obsindex $keywindex $dickeyword

for i in $list
do
  tit=`awk -F= 'NF>=2 {print $2; exit}' $def/$i.def | $LL tr ',\11' '; '`
  echo "$i:$tit" >>$extitles.tmp
  for lang in $transl_lang ; do
    titl=`grep -a "title_$lang" $def/$i.def | awk -F= '{print $2}'`;
    echo "$i:$titl" >>"${extitles}_$lang.tmp"
  done
  titlist="$titlist$tit
"
  titlist1="$titlist1$tit,"
  list1="$list1$i,"
  auth=`grep -a -m1 ^author $def/$i.def | awk -F= '{print $2}'`;
  echo "$i:$auth" >> $exauth
  desc=`grep -a -m1 ^oefdescription $def/$i.def | awk -F= '{print $2}'`;
  if [ ! -z "$desc" ] ; then echo "$i:$desc" >> $descindex ; fi
  obs=`grep -a -m1 ^oefobservation $def/$i.def | awk -F= '{print $2}'`;
  if [ ! -z "$obs" ] ; then echo "$i:$obs" >> $obsindex ; fi;
  obs=""
  keyw=`grep -a -m1 ^keywords $def/$i.def | awk -F= '{print $2}'`;
  if [ ! -z "$keyw" ] ; then echo "$i:$keyw" >> $keywindex ; fi
done

# Processing dicsort.
$wims_home/bin/dicsort $extitles.tmp 1>/dev/null
if [ -s $extitles.tmp.sorted ]; then
  cat $extitles.tmp.sorted >$extitles
  rm -f $extitles.tmp*
else
  rm -f $extitles.tmp.sorted
  echo >$extitles
fi

# Processing trans_lang.
for lang in $transl_lang
do
  $wims_home/bin/dicsort "${extitles}_$lang.tmp"
  if [ -s "${extitles}_$lang.tmp.sorted" ]; then
    cat "${extitles}_$lang.tmp.sorted" > "${extitles}_$lang"
  else
    echo >"${extitles}_$lang"
  fi
done
rm -f *.tmp *.sorted

echo "$titlist" >$tmp1
echo "$list" >$tmp2
llist=`$LL paste $tmp1 $tmp2 | $LL sort -t '	' -f -k 1,1`
list1=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $2}' | $LL tr '\n' ' '`
list=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $2}' | $LL tr '\n' ','`
titlist=`echo "$llist" | $LL awk -F'\11' 'length()>2 {print $1}' | $LL tr '\n' ','`

rm -f $tmp1 $tmp2
cat >$exindex <<@
!set exolist  =!char 1 to -2 of $list
!set titlelist=!char 1 to -2 of $titlist
!set titlelist_$module_lang=!char 1 to -2 of $titlist
!set exototal =!itemcnt \$exolist

@

for lang in $transl_lang ; do
  for ex in $list1; do
    a=`grep -a title_$lang $def/$ex.def | awk -F= '{print $2}'`;
    if [ -z "$a" ]; then a=`grep -a "!set title" $def/$ex.def | awk -F= '{print $2}'` ; fi
    echo "$a">>tmp1
  done
  titlist2=`cat $tmp1 | $LL tr '\n' ','` ;
  rm -f $tmp1
  cat >>$exindex <<@
!set titlelist_$lang=!char 1 to -2 of $titlist2
@
done

## keywords:exercises
cd $thisdir
export KEYWINDEX; KEYWINDEX="$keywindex";
export DICKEYWORD; DICKEYWORD="$dickeyword";
perl <<'EOF'
  my %hash=();my $TEXT=''; my $hash=\%hash;
  my ($file)=$ENV{KEYWINDEX}; open(IN, "$file");
  while(<IN>) {
    my @a=split(":", $_); my @b=split(",", $a[1]);
    for my $c (@b){ chomp $c; $c=~ s/^\s+//; $c=~ s/\s+$//; $hash->{$c} .= "$a[0],";}
  }
  for my $aa (keys %hash){ chop $hash->{$aa}; $TEXT .= "$aa:$hash->{$aa}\n";};
  if ($TEXT) {
    open (OUT, ">$ENV{DICKEYWORD}"); print OUT $TEXT; close OUT;
  }
EOF

#### index of files in images/ "name:directory"
cd $thisdir
rm -f $imindex
if [ -d $imagedir ]; then
  images=`cd $imagedir ; find * -type f 2>/dev/null`
  if [ -z "$images" ]; then
    echo "<!-- This file is automatically generated. Do not edit! -->" >$imindex
    for i in $images ; do d=`dirname $i` ; file=`basename $i` ;
      echo "$file:$d" >> $imindex ;
    done;
  fi
fi

[ -n "$class_header" ] && exit

# Datafiles

if [ -d src/data ]; then
  datafiles=`cd src/data; ls *.data | sed 's/\.data$//'`
  rm -f $dfindex.tmp
  for df in $datafiles; do
    tit=`awk 'NF>0 {if($1 ~ /^[^.:]/) print; exit}' src/data/$df.data`
    author=`awk -F.author '/^.author / {print $2}' src/data/$df.data`;
    recordcnt=`awk '/^:/{i++}END{print i}' src/data/$df.data`
    [ -z "$tit" ] && tit=$df
      echo "$df,$tit,$author,$recordcnt" >>$dfindex.tmp
  done
  $LL sort -f -t, -k2 <$dfindex.tmp >$dfindex
  rm -f $dfindex.tmp
fi

# Gather content for robots.

outputfile=content.html

tit=
echo "<!-- This file is automatically generated. Do not edit! -->" >$outputfile
for f in `ls $def/*.def 2>/dev/null`; do
  tit=`head -1 $f | $LL cut -d= -f2`
  [ -z "$tit" ] && continue
  content=`awk 'BEGIN {a=0};
    NF == 0 {next};
    /!exit/ {a=0};
    /^!/ {next};
    a > 0 {print};
    /^:question/ {a=1};
    ' $f | $LL sed 's/\$()//g'`
  echo "<hr>
<h3>$tit</h3>
$content
" >>$outputfile
tit=
done