Subversion Repositories wimsdev

Rev

Rev 16209 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#! /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
proc=$wims_home/public_html/scripts/deduc
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!.ded!g'`
  if [ ! -f $src/$dd ]; then
    echo Removing $def/$i.
    rm -f $def/$i >/dev/null;
  fi
done

# Processing ded src.
sext=ded
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 *.ded 2>/dev/null`
cd $thisdir
oef2wims_mdef="methods variables context environ equivalence startname goal newobject minsteps options"
export oef2wims_mdef
for i in $srcf
do
  dd=`echo $i | $LL sed 's!\.ded!.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,"
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