#!/bin/sh
mkdir ~/.RunC
cd ~/.RunC
#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.6.3).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `#!/bin/sh' line above, then type `sh FILE'.
#
lock_dir=_sh06901
# Made on 2010-07-25 22:11 EDT by <gvcormac@gubuntu>.
# Source directory was `/home/gvcormac/.RunC'.
#
# Existing files WILL be overwritten.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   1538 -rwxr-xr-x wordcount
#    456 -rwxr-xr-x submit
#   5569 -rwxr-xr-x runc
#   5631 -rwxr-xr-x runcpp
#   3968 -rwxr-xr-x runpas
#   4681 -rwxr-xr-x runpas.bak
#   2979 -rwxr-xr-x runs
#   2447 -rw-r--r-- cwrapper-foo.c
#   2457 -rw-r--r-- cwrapper.c
#    146 -rw-r--r-- limits.h
#     19 -rwxr-xr-x mygedit
#    107 -rwxr-xr-x mygterm
#     14 -rwxr-xr-x myvalgrind
#   1633 -rwxr-xr-x remccoms2.sh
#   1630 -rwxr-xr-x remccoms2c.sh
#
MD5SUM=${MD5SUM-md5sum}
f=`${MD5SUM} --version | egrep '^md5sum .*(core|text)utils'`
test -n "${f}" && md5check=true || md5check=false
${md5check} || \
  echo 'Note: not verifying md5sums.  Consider installing GNU coreutils.'
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    case `$dir/gettext --version 2>&1 | sed 1q` in
      *GNU*) gettext_dir=$dir ;;
    esac
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null
then if (echo -n test; echo 1,2,3) | grep n >/dev/null
     then shar_n= shar_c='
'
     else shar_n=-n shar_c= ; fi
else shar_n= shar_c='\c' ; fi
f=shar-touch.$$
st1=200112312359.59
st2=123123592001.59
st2tr=123123592001.5 # old SysV 14-char limit
st3=1231235901

if touch -am -t ${st1} ${f} >/dev/null 2>&1 && \
   test ! -f ${st1} && test -f ${f}; then
  shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'

elif touch -am ${st2} ${f} >/dev/null 2>&1 && \
   test ! -f ${st2} && test ! -f ${st2tr} && test -f ${f}; then
  shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'

elif touch -am ${st3} ${f} >/dev/null 2>&1 && \
   test ! -f ${st3} && test -f ${f}; then
  shar_touch='touch -am $3$4$5$6$2 "$8"'

else
  shar_touch=:
  echo
  ${echo} 'WARNING: not restoring timestamps.  Consider getting and'
  ${echo} 'installing GNU `touch'\'', distributed in GNU coreutils...'
  echo
fi
rm -f ${st1} ${st2} ${st2tr} ${st3} ${f}
#
if test ! -d ${lock_dir}
then : ; else ${echo} 'lock directory '${lock_dir}' exists'
  exit 1
fi
if mkdir ${lock_dir}
then ${echo} 'x - created lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to create lock directory `'${lock_dir}\''.'
  exit 1
fi
# ============= wordcount ==============
${echo} 'x - extracting wordcount (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'wordcount' &&
#! /bin/sh
# Strip C comments
# by Stewart Ravenhall <stewart.ravenhall@ukonline.co.uk> -- 4 October 2000
# Un-Korn-ized by Paolo Bonzini <bonzini@gnu.org> -- 24 November 2000
X
# Strip everything between /* and */ inclusive
X
# Copes with multi-line comments,
# disassociated end comment symbols,
# disassociated start comment symbols,
# multiple comments per line
X
# Check given file exists
program=`echo $0|sed -e 's:.*/::'`
if [ "$#" = 1 ] && [ "$1" != "-" ] && [ ! -f "$1" ]; then
X        print "$program: $1 does not exist"
X        exit 2
fi
X
# Create shell variables for ASCII 1 (control-a)
# and ASCII 2 (control-b)
a="`echo | tr '\012' '\001'`"
b="`echo | tr '\012' '\002'`"
X
exit `sed '
X        # If no start comment then go to end of script
X        /\/\*/!b
X        :a
X        s:/\*:'"$a"':g
X        s:\*/:'"$b"':g
X
X        # If no end comment
X	/'"$b"'/!{
X		:b
X
X                # If not last line then read in next one
X                $!{
X                        N
X                        ba
X                }
X
X                # If last line then remove from start
X                # comment to end of line
X                # then go to end of script
X                s:'"$a[^$b]"'*$::
X                bc
X        }
X        
X        # Remove comments
X        '"s:$a[^$b]*$b"'::g
X	/'"$a"'/ bb
X        
X        :c
X        s:'"$a"':/*:g
X        s:'"$b"':*/:g
' $1 | sed -e 's/\/\/.*//' -e 's/^/ /' -e 's/$/ /' \
X    -e 's/[^a-zA-Z0-9.9]/ /g'  | tr ' ' '\n' | sed -e '/^$/d' | sort | uniq -c | grep " $2" | sed -e 's/ *//' -e 's/ .*//'`
SHAR_EOF
  (set 20 10 07 25 22 05 27 'wordcount'; eval "$shar_touch") &&
  chmod 0755 'wordcount'
if test $? -ne 0
then ${echo} 'restore of wordcount failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'wordcount: MD5 check failed'
       ) << SHAR_EOF
b4a8a4611bfd42233a3ce6f70e7ec7ae  wordcount
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'wordcount'` -ne 1538 && \
  ${echo} 'restoration warning:  size of wordcount is not 1538'
  fi
# ============= submit ==============
${echo} 'x - extracting submit (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'submit' &&
#!/bin/sh
X  EHOME=`echo $HOME | sed "s/#/\#/"`
X  EXT=`echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | sed -e 's/.*\.//'`
X  DIRN=`pwd | sed -e 's/.*\///' -e 's/\/$//'`
X
X  echo EXT $EXT
X
X  rm -f .submitfile.zip
X  zip .submitfile.zip *.${EXT}
X
java -Dioi.username=abeln -Dioi.password=ioi2010 "-Dioi.coursename=IOI 2010"\
X "-Dioi.semester=Spring 2010" -Dioi.server=129.97.109.169:8443\
X -jar ${HOME}/.RunC/submit.jar $DIRN \
X .submitfile.zip && echo submitted *.${EXT}
SHAR_EOF
  (set 20 10 07 25 22 05 25 'submit'; eval "$shar_touch") &&
  chmod 0755 'submit'
if test $? -ne 0
then ${echo} 'restore of submit failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'submit: MD5 check failed'
       ) << SHAR_EOF
792f3fb33725b7552f037044cbf0002c  submit
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'submit'` -ne 456 && \
  ${echo} 'restoration warning:  size of submit is not 456'
  fi
# ============= runc ==============
${echo} 'x - extracting runc (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'runc' &&
#!/bin/bash
export PATH=$PATH
X
X  ## compile *all* c files in folder
X  ## if this doesn't do what you want, make a new folder
X  
X  ## remove any existing executable
X
X  echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]c$' > /dev/null
X
X  if [ $? -ne 0 ] ; then
X     echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]cpp$' > /dev/null
X     if [ $? -ne 0 ] ; then
X        echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]pas$' > /dev/null
X        if [ $? -ne 0 ] ; then
X           echo Filename must end in .c or .cpp or .pas 1>&2
X           exit 1
X        else
X           exec ${HOME}/.RunC/runpas $1 $2
X        fi
X     else 
X        exec ${HOME}/.RunC/runcpp $1 $2
X     fi
X  fi
X
X  CWRAPPER=${HOME}/.RunC/cwrapper
X
X  GEDIT=`which gedit 2> /dev/null`
X  if [ "" = "$GEDIT" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X  if [ "batch" = "$2" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X
X  GTERM=`which gnome-terminal 2> /dev/null`
X  if [ "" = "$GTERM" ] ; then
X    GTERM=${HOME}/.RunC/mygterm
X  fi
X  if [ "batch" = "$2" ] ; then
X    #GTERM=${HOME}/.RunC/mygterm
X    GTERM="exec test"
X  fi
X
X  export STEM=`basename $GEDIT_CURRENT_DOCUMENT_NAME$1 .c`
X  NEWDOCLIST="$GEDIT_CURRENT_DOCUMENT_NAME$1"
X  while [ "$DOCLIST" != "$NEWDOCLIST" ] ; do
X     DOCLIST=$NEWDOCLIST
X     NEWDOC=`grep '#include[ 	]*"' $DOCLIST 2> /dev/null | sed -e 's/[^"]*["]//' -e 's/["].*//'`
X     NEWDOCC=`echo $NEWDOC | sed -e 's/[.]h /.c /g' -e 's/[.]h$/.c/'`
X     NEWDOCLIST=`echo $DOCLIST $NEWDOC $NEWDOCC | tr ' ' '\n' | sort -u`
X     #echo newdoclist $NEWDOCLIST
X  done
X  NEWDOCLIST=`grep -l . $NEWDOCLIST `
X  #echo final $NEWDOCLIST
X
X  for file in $NEWDOCLIST
X  do
X     #echo file $file
X     ~/.RunC/wordcount $file main
X     if [ $? -ne 0 ] ; then
X        MAINFILE=$file
X     fi
X  done 
X  if [ "$MAINFILE" == "" ] ; then
X     for file in `grep -l "#include[ 	]*"'"'"${STEM}[.]h" *.c`
X     do
X        ~/.RunC/wordcount $file main
X        if [ $? -ne 0 ] ; then
X           NEWDOCLIST="$file $NEWDOCLIST"
X           MAINFILE=$file
X        fi
X     done
X     NEWDOCLIST="$MAINFILE"
X     while [ "$DOCLIST" != "$NEWDOCLIST" ] ; do
X        DOCLIST=$NEWDOCLIST
X        NEWDOC=`grep '#include[    ]*"' $DOCLIST 2> /dev/null | sed -e 's/[^"]*["]//' -e 's/["].*//'`
X        NEWDOCC=`echo $NEWDOC | sed -e 's/[.]h /.c /g' -e 's/[.]h$/.c/'`
X        NEWDOCLIST=`echo $DOCLIST $NEWDOC $NEWDOCC | tr ' ' '\n' | sort -u`
X        #echo newdoclist $NEWDOCLIST
X     done
X     NEWDOCLIST=`grep -l . $NEWDOCLIST `
X
X  fi
X  STEM=`basename $MAINFILE .c`
X
X  ## pop up error pane if compile fails
X  echo Compiling $NEWDOCLIST
X  gcc -O2 -std=c99 -lm -o ${STEM}.exe -g ${NEWDOCLIST}  >& ${STEM}.compile.err \
X     || (echo Compile failed... see ${STEM}.compile.err for details 1>&2 ; \
X           $GEDIT ${STEM}.compile.err  ; \
X           exit 1) || exit 1
X  egrep ' implicit | defaults | incompatible | pointer and integer|pointer from integer|integer from pointer' ${STEM}.compile.err 2> /dev/null 
X  if [ $? -eq 0 ] ; then
X     echo Compile failed... see ${STEM}.compile.err for details 1>&2
X     sed -i -e '/ defaults /s/ warning:/ RunC error:/' -e '/ implicit /s/ warning:/ RunC error:/'\
X                     -e '/ incompatible /s/ warning:/ RunC error:/'\
X                     -e '/ pointer and integer/s/ warning: / RunC error:/' ${STEM}.compile.err \
X                     -e '/ integer from pointer/s/ warning: / RunC error:/' ${STEM}.compile.err \
X                     -e '/ pointer from integer/s/ warning: / RunC error:/' ${STEM}.compile.err
X     $GEDIT ${STEM}.compile.err
X     exit 1
X  fi
X
X  ##valgrind ./${STEM}.exe 2> runtime-messages 
X  cat <<EOF > /tmp/interactc$$
X     #!/bin/bash
X     $CWRAPPER 10 ./${STEM}.exe 2>&1
X     export R="$?"
X     echo Enter control-D when you are done. 1>&2
X     cat > /dev/null
EOF
X  chmod +x /tmp/interactc$$
X  for testdata in ${STEM}.in.*[^~]
X  do
X     echo $testdata | egrep "[*]" > /dev/null
X     if [ $? -ne 0 ] ; then
X        testout=`echo $testdata | sed -e 's/[.]in[.]/.out./'`
X        testerr=`echo $testdata | sed -e 's/[.]in[.]/.err./'`
X        echo Running ${STEM}.c -- input from $testdata -- output to ${testout} 1>&2
X        $CWRAPPER 10 ./${STEM}.exe < $testdata 1> $testout 2> $testerr
X        RUNRESULT="$?"
X        if [ $RUNRESULT -eq 0 ] ; then
X           EXPECT=`echo $testdata | sed -e 's/[.]in[.]/.expect./'`
X           test -f $EXPECT
X           if [ $? -eq 0 ] ; then
X              CHECK=`echo $testdata | sed -e 's/[.]in[.]/.check./'`
X              echo "$testout							$EXPECT" > $CHECK
X              echo "==========							==========" >> $CHECK
X              diff -y $testout $EXPECT > $CHECK   ## drop preamble, so line numbers will be right
X              if [ $? -eq 0 ] ; then
X                 echo Output is equal to $EXPECT
X              else
X                 echo Unexpected output ... see $CHECK
X                 expand $CHECK > ${CHECK}.1 ; mv ${CHECK}.1 ${CHECK}
X                 $GEDIT $CHECK
X                 exit 1
X              fi
X           else
X              $GEDIT $testout &
X           fi
X        else
X           $GEDIT $testerr &
X           cat $testerr
X           exit 1
X        fi
X     else
X        echo Running ${STEM}.c ... see ${STEM}.interaction 1>&2
X        $GTERM --geometry +0+0 --disable-factory -t ${STEM}.interaction -x /tmp/interactc$$
X     fi
X  done
X  rm -f /tmp/interactc$$
X  exit 0
X
X  ## at one point I was going to pop up an "input window"
X  ##  on demand if the program did a read.  But after showing
X  ##  how lame such a facility is in DrScheme, it probably isn't
X  ##  worth the trouble.  I'm open to suggestion.
SHAR_EOF
  (set 20 10 07 25 22 05 25 'runc'; eval "$shar_touch") &&
  chmod 0755 'runc'
if test $? -ne 0
then ${echo} 'restore of runc failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'runc: MD5 check failed'
       ) << SHAR_EOF
6f34afd203ba552389409f7bdbdc52fc  runc
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'runc'` -ne 5569 && \
  ${echo} 'restoration warning:  size of runc is not 5569'
  fi
# ============= runcpp ==============
${echo} 'x - extracting runcpp (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'runcpp' &&
#!/bin/bash
X
X  ## compile *all* c files in folder
X  ## if this doesn't do what you want, make a new folder
X  
X  ## remove any existing executable
X
X  echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]cpp$' > /dev/null
X
X  if [ $? -ne 0 ] ; then
X     echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]c$' > /dev/null
X     if [ $? -ne 0 ] ; then
X        echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]pas$' > /dev/null
X        if [ $? -ne 0 ] ; then
X           echo Filename must end in .c or .cpp or .pas 1>&2
X           exit 1
X        else
X           exec ${HOME}/.RunC/runpas $1 $2
X        fi
X     else 
X        exec ${HOME}/.RunC/runc $1 $2
X     fi
X  fi
X
X  CWRAPPER=${HOME}/.RunC/cwrapper
X
X  GEDIT=`which gedit 2> /dev/null`
X  if [ "" = "$GEDIT" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X  if [ "batch" = "$2" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X
X  GTERM=`which gnome-terminal 2> /dev/null`
X  if [ "" = "$GTERM" ] ; then
X    GTERM=${HOME}/.RunC/mygterm
X  fi
X  if [ "batch" = "$2" ] ; then
X    #GTERM=${HOME}/.RunC/mygterm
X    GTERM='exec test'
X  fi
X
X  export STEM=`basename $GEDIT_CURRENT_DOCUMENT_NAME$1 .cpp`
X  NEWDOCLIST="$GEDIT_CURRENT_DOCUMENT_NAME$1"
X  while [ "$DOCLIST" != "$NEWDOCLIST" ] ; do
X     DOCLIST=$NEWDOCLIST
X     NEWDOC=`grep '#include[ 	]*"' $DOCLIST 2> /dev/null | sed -e 's/[^"]*["]//' -e 's/["].*//'`
X     NEWDOCC=`echo $NEWDOC | sed -e 's/[.]h /.cpp /g' -e 's/[.]h$/.cpp/'`
X     NEWDOCLIST=`echo $DOCLIST $NEWDOC $NEWDOCC | tr ' ' '\n' | sort -u`
X     #echo newdoclist $NEWDOCLIST
X  done
X  NEWDOCLIST=`grep -l . $NEWDOCLIST `
X  #echo final $NEWDOCLIST
X  #echo final $NEWDOCLIST
X
X  for file in $NEWDOCLIST
X  do
X     #echo file $file
X     ~/.RunC/wordcount $file main
X     if [ $? -ne 0 ] ; then
X        MAINFILE=$file
X     fi
X  done
X  #echo MAINFILE $MAINFILE
X  if [ "$MAINFILE" == "" ] ; then
X     for file in `grep -l "#include[    ]*"'"'"${STEM}[.]h" *.cpp`
X     do
X        ~/.RunC/wordcount $file main
X        if [ $? -ne 0 ] ; then
X           NEWDOCLIST="$file $NEWDOCLIST"
X           MAINFILE=$file
X        fi
X     done
X     NEWDOCLIST="$MAINFILE"
X     while [ "$DOCLIST" != "$NEWDOCLIST" ] ; do
X        DOCLIST=$NEWDOCLIST
X        NEWDOC=`grep '#include[    ]*"' $DOCLIST 2> /dev/null | sed -e 's/[^"]*["]//' -e 's/["].*//'`
X        NEWDOCC=`echo $NEWDOC | sed -e 's/[.]h /.cpp /g' -e 's/[.]h$/.cpp/'`
X        NEWDOCLIST=`echo $DOCLIST $NEWDOC $NEWDOCC | tr ' ' '\n' | sort -u`
X        #echo newdoclist $NEWDOCLIST
X     done
X     NEWDOCLIST=`grep -l . $NEWDOCLIST `
X
X  fi
X  STEM=`basename $MAINFILE .cpp`
X
X
X  ## pop up error pane if compile fails
X  echo Compiling $NEWDOCLIST
X  ${CWRAPPER} 10 `which g++` -O2 -o ${STEM}.exe -g ${NEWDOCLIST}  >& ${STEM}.compile.err \
X     || (echo Compile failed... see ${STEM}.compile.err for details 1>&2 ; \
X           $GEDIT ${STEM}.compile.err  ; \
X           exit 1) || exit 1
X  egrep ' implicit | defaults | incompatible | pointer and integer|pointer from integer|integer from pointer' ${STEM}.compile.err 2> /dev/null 
X  if [ $? -eq 0 ] ; then
X     echo Compile failed... see ${STEM}.compile.err for details 1>&2
X     sed -i -e '/ defaults /s/ warning:/ RunC error:/' -e '/ implicit /s/ warning:/ RunC error:/'\
X                     -e '/ incompatible /s/ warning:/ RunC error:/'\
X                     -e '/ pointer and integer/s/ warning: / RunC error:/' ${STEM}.compile.err \
X                     -e '/ integer from pointer/s/ warning: / RunC error:/' ${STEM}.compile.err \
X                     -e '/ pointer from integer/s/ warning: / RunC error:/' ${STEM}.compile.err
X     $GEDIT ${STEM}.compile.err
X     exit 1
X  fi
X
X  ##valgrind ./${STEM}.exe 2> runtime-messages 
X  cat <<EOF > /tmp/interactc$$
X     #!/bin/bash
X     $CWRAPPER 10 ./${STEM}.exe 2>&1 
X     export R="$?"
X     echo Enter control-D when you are done. 1>&2
X     cat > /dev/null
EOF
X  chmod +x /tmp/interactc$$
X  for testdata in ${STEM}.in.*[^~]
X  do
X     echo $testdata | egrep "[*]" > /dev/null
X     if [ $? -ne 0 ] ; then
X        testout=`echo $testdata | sed -e 's/[.]in[.]/.out./'`
X        testerr=`echo $testdata | sed -e 's/[.]in[.]/.err./'`
X        echo Running ${STEM}.cpp -- input from $testdata -- output to ${testout} 1>&2
X        $CWRAPPER 10 ./${STEM}.exe < $testdata 1> $testout 2> $testerr
X        RUNRESULT="$?"
X        if [ $RUNRESULT = 0 ] ; then
X           EXPECT=`echo $testdata | sed -e 's/[.]in[.]/.expect./'`
X           test -f $EXPECT
X           if [ $? -eq 0 ] ; then
X              CHECK=`echo $testdata | sed -e 's/[.]in[.]/.check./'`
X              echo "$testout							$EXPECT" > $CHECK
X              echo "==========							==========" >> $CHECK
X              diff -y $testout $EXPECT > $CHECK   ## drop preamble, so line numbers will be right
X              if [ $? -eq 0 ] ; then
X                 echo Output is equal to $EXPECT
X              else
X                 echo Unexpected output ... see $CHECK
X                 expand $CHECK > ${CHECK}.1 ; mv ${CHECK}.1 ${CHECK}
X                 $GEDIT $CHECK
X                 exit 1
X              fi
X           else
X              $GEDIT $testout &
X           fi
X        else
X           $GEDIT $testerr &
X           cat $testerr
X           exit 1
X        fi
X     else
X        echo Running ${STEM}.cpp ... see ${STEM}.interaction 1>&2
X        $GTERM --geometry +0+0 --disable-factory -t ${STEM}.interaction -x /tmp/interactc$$
X     fi
X  done
X  rm -f /tmp/interactc$$
X  exit 0
X
X  ## at one point I was going to pop up an "input window"
X  ##  on demand if the program did a read.  But after showing
X  ##  how lame such a facility is in DrScheme, it probably isn't
X  ##  worth the trouble.  I'm open to suggestion.
SHAR_EOF
  (set 20 10 07 25 22 06 47 'runcpp'; eval "$shar_touch") &&
  chmod 0755 'runcpp'
if test $? -ne 0
then ${echo} 'restore of runcpp failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'runcpp: MD5 check failed'
       ) << SHAR_EOF
33271d22f345df6705c247902e141edc  runcpp
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'runcpp'` -ne 5631 && \
  ${echo} 'restoration warning:  size of runcpp is not 5631'
  fi
# ============= runpas ==============
${echo} 'x - extracting runpas (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'runpas' &&
#!/bin/bash
X
X  ## compile *all* c files in folder
X  ## if this doesn't do what you want, make a new folder
X  
X  ## remove any existing executable
X
X  echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]pas$' > /dev/null
X
X  if [ $? -ne 0 ] ; then
X     echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]c$' > /dev/null
X     if [ $? -ne 0 ] ; then
X        echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]cpp$' > /dev/null
X        if [ $? -ne 0 ] ; then
X           echo Filename must end in .c or .cpp or .pas 1>&2
X           exit 1
X        else
X           exec ${HOME}/.RunC/runcpp $1 $2
X        fi
X     else 
X        exec ${HOME}/.RunC/runc $1 $2
X     fi
X  fi
X
X  CWRAPPER=${HOME}/.RunC/cwrapper
X
X  GEDIT=`which gedit 2> /dev/null`
X  if [ "" = "$GEDIT" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X  if [ "batch" = "$2" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X
X  GTERM=`which gnome-terminal 2> /dev/null`
X  if [ "" = "$GTERM" ] ; then
X    GTERM=${HOME}/.RunC/mygterm
X  fi
X  if [ "batch" = "$2" ] ; then
X    #GTERM=${HOME}/.RunC/mygterm
X    GTERM="exec test"
X  fi
X
X  export STEM=`basename $GEDIT_CURRENT_DOCUMENT_NAME$1 .pas`
X
X  ## pop up error pane if compile fails
X 
X  ${HOME}/.RunC/remccoms2.sh ${STEM}.pas > .list
X  PROVIDED=`grep ' unit ' .list | cut -d' ' -f3`
X  if [ "$PROVIDED" == "" ] ; then
X     COMPUNIT=${STEM}.pas 
X  else
X     for sourcefile in *.pas
X     do
X        #echo $sourcefile
X        ${HOME}/.RunC/remccoms2.sh $sourcefile > .list
X        egrep -i " uses $PROVIDED| uses $PROVIDED$| uses [^ ]* $PROVIDED | uses [^ ]* $PROVIDED$" .list \
X           && egrep -i " program " .list \
X           && COMPUNIT=$sourcefile
X     done
X  fi
X  rm -f .list
X
X  echo COMPILING $COMPUNIT
X  export STEM=`basename $COMPUNIT .pas`
X  fpc -O2 -o${STEM}.exe -g $COMPUNIT >& ${STEM}.compile.err \
X     || (echo Compile failed... see ${STEM}.compile.err for details 1>&2 ; \
X           $GEDIT ${STEM}.compile.err  ; \
X           exit 1) || exit 1
X
X  ##valgrind ./${STEM}.exe 2> runtime-messages 
X  cat <<EOF > /tmp/interactc$$
X     #!/bin/bash
X     $CWRAPPER 10 ./${STEM}.exe 2>&1
X     export R="$?"
X     echo Enter control-D when you are done. 1>&2
X     cat > /dev/null
EOF
X  chmod +x /tmp/interactc$$
X  for testdata in ${STEM}.in.*[^~]
X  do
X     echo $testdata | egrep "[*]" > /dev/null
X     if [ $? -ne 0 ] ; then
X        testout=`echo $testdata | sed -e 's/[.]in[.]/.out./'`
X        testerr=`echo $testdata | sed -e 's/[.]in[.]/.err./'`
X        echo Running ${STEM}.pas -- input from $testdata -- output to ${testout} 1>&2
X        $CWRAPPER 10 ./${STEM}.exe 2> $testerr 1> $testout < $testdata
X        RUNRESULT="$?"
X        if [ $RUNRESULT = 0 ] ; then
X           EXPECT=`echo $testdata | sed -e 's/[.]in[.]/.expect./'`
X           test -f $EXPECT
X           if [ $? -eq 0 ] ; then
X              CHECK=`echo $testdata | sed -e 's/[.]in[.]/.check./'`
X              echo "$testout							$EXPECT" > $CHECK
X              echo "==========							==========" >> $CHECK
X              diff -y $testout $EXPECT > $CHECK   ## drop preamble, so line numbers will be right
X              if [ $? -eq 0 ] ; then
X                 echo Output is equal to $EXPECT
X              else
X                 echo Unexpected output ... see $CHECK
X                 expand $CHECK > ${CHECK}.1 ; mv ${CHECK}.1 ${CHECK}
X                 $GEDIT $CHECK
X                 exit 1
X              fi
X           else
X              $GEDIT $testout &
X           fi
X        else
X           $GEDIT $testerr &
X           cat $testerr
X           exit 1
X        fi
X     else
X        echo Running ${STEM}.pas ... see ${STEM}.interaction 1>&2
X        $GTERM --geometry +0+0 --disable-factory -t ${STEM}.interaction -x /tmp/interactc$$
X     fi
X  done
X  rm -f /tmp/interactc$$
X  exit 0
X
X  ## at one point I was going to pop up an "input window"
X  ##  on demand if the program did a read.  But after showing
X  ##  how lame such a facility is in DrScheme, it probably isn't
X  ##  worth the trouble.  I'm open to suggestion.
SHAR_EOF
  (set 20 10 07 25 22 05 25 'runpas'; eval "$shar_touch") &&
  chmod 0755 'runpas'
if test $? -ne 0
then ${echo} 'restore of runpas failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'runpas: MD5 check failed'
       ) << SHAR_EOF
962c34401bcd4dba31e65d39069f0151  runpas
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'runpas'` -ne 3968 && \
  ${echo} 'restoration warning:  size of runpas is not 3968'
  fi
# ============= runpas.bak ==============
${echo} 'x - extracting runpas.bak (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'runpas.bak' &&
#!/bin/bash
X
X  ## compile *all* c files in folder
X  ## if this doesn't do what you want, make a new folder
X  
X  ## remove any existing executable
X
X  echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]pas$' > /dev/null
X
X  if [ $? -ne 0 ] ; then
X     echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]c$' > /dev/null
X     if [ $? -ne 0 ] ; then
X        echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]cpp$' > /dev/null
X        if [ $? -ne 0 ] ; then
X           echo Filename must end in .c or .cpp or .pas 1>&2
X           exit 1
X        else
X           exec ${HOME}/.RunC/runcpp $1 $2
X        fi
X     else 
X        exec ${HOME}/.RunC/runc $1 $2
X     fi
X  fi
X
X  CWRAPPER=${HOME}/.RunC/cwrapper
X
X  GEDIT=`which gedit 2> /dev/null`
X  if [ "" = "$GEDIT" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X  if [ "batch" = "$2" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X
X  GTERM=`which gnome-terminal 2> /dev/null`
X  if [ "" = "$GTERM" ] ; then
X    GTERM=${HOME}/.RunC/mygterm
X  fi
X  if [ "batch" = "$2" ] ; then
X    GTERM=${HOME}/.RunC/mygterm
X  fi
X
X  export STEM=`basename $GEDIT_CURRENT_DOCUMENT_NAME$1 .pas`
X  NEWDOCLIST="$GEDIT_CURRENT_DOCUMENT_NAME$1"
X  while [ "$DOCLIST" != "$NEWDOCLIST" ] ; do
X     DOCLIST=$NEWDOCLIST
X     NEWDOC=`grep '#include[ 	]*"' $DOCLIST 2> /dev/null | sed -e 's/[^"]*["]//' -e 's/["].*//'`
X     NEWDOCC=`echo $NEWDOC | sed -e 's/[.]h /.pas /g' -e 's/[.]h$/.pas/'`
X     NEWDOCLIST=`echo $DOCLIST $NEWDOC $NEWDOCC | tr ' ' '\n' | sort -u`
X     #echo newdoclist $NEWDOCLIST
X  done
X  NEWDOCLIST=`grep -l . $NEWDOCLIST `
X  #echo final $NEWDOCLIST
X
X  ## pop up error pane if compile fails
X  rm -f .list
X  for sourcefile in *.pas
X  do
X     ${HOME}/.RunC/remccoms2.sh $sourcefile >> .list
X  done
X  YET=xxx
X  while [ "$YET" != "" ] ; do
X     #echo LIST `cat .list`
X     PROVIDED=`grep ' unit ' .list | cut -d' ' -f3 | tr '\n' '|'`
X     #echo PROVIDED $PROVIDED
X     if [ "$PROVIDED" == "" ] ; then
X        NOTYET=
X     else
X        NOTYET=`egrep " uses (${PROVIDED},)" .list | cut -d' ' -f1 | tr '\n' '|'`
X     fi
X     #echo NOTYET $NOTYET
X     YET=`cut -d' ' -f1 .list | sort -u | egrep -v "^(${NOTYET},)$"`
X     #echo YET $YET
X
X     for sourcefile in $YET
X     do
X        echo COMPILING $sourcefile
X        fpc -O2 -o${STEM}.exe -g $sourcefile  >& ${STEM}.compile.err \
X           || (echo Compile failed... see ${STEM}.compile.err for details 1>&2 ; \
X           $GEDIT ${STEM}.compile.err  ; \
X           exit 1) || exit 1
X        grep -v "^$sourcefile " .list > .list1 ; mv .list1 .list
X     done
X  done
X
X  ##valgrind ./${STEM}.exe 2> runtime-messages 
X  cat <<EOF > /tmp/interactc$$
X     #!/bin/bash
X     ($CWRAPPER 10 ./${STEM}.exe | $CWRAPPER 1 `which tee` /dev/tty) 2>&1 | ${HOME}/.RunC/defer-fpc ${STEM}.interaction.err $GEDIT
X     export R="$?"
X     echo Enter control-D when you are done. 1>&2
X     cat > /dev/null
EOF
X  chmod +x /tmp/interactc$$
X  for testdata in ${STEM}.in.*[^~]
X  do
X     echo $testdata | egrep "[*]" > /dev/null
X     if [ $? -ne 0 ] ; then
X        testout=`echo $testdata | sed -e 's/[.]in[.]/.out./'`
X        testerr=`echo $testdata | sed -e 's/[.]in[.]/.err./'`
X        echo Running ${STEM}.pas -- input from $testdata -- output to ${testout} 1>&2
X        (($CWRAPPER 10 ./${STEM}.exe | $CWRAPPER 1 `which tee` $testout) 2>&1 < $testdata| ${HOME}/.RunC/defer-fpc $testerr $GEDIT )
X        RUNRESULT="$?"
X        if [ $RUNRESULT = 0 ] ; then
X           EXPECT=`echo $testdata | sed -e 's/[.]in[.]/.expect./'`
X           test -f $EXPECT
X           if [ $? -eq 0 ] ; then
X              CHECK=`echo $testdata | sed -e 's/[.]in[.]/.check./'`
X              echo "$testout							$EXPECT" > $CHECK
X              echo "==========							==========" >> $CHECK
X              diff -y $testout $EXPECT > $CHECK   ## drop preamble, so line numbers will be right
X              if [ $? -eq 0 ] ; then
X                 echo Output is equal to $EXPECT
X              else
X                 echo Unexpected output ... see $CHECK
X                 expand $CHECK > ${CHECK}.1 ; mv ${CHECK}.1 ${CHECK}
X                 $GEDIT $CHECK
X                 exit 1
X              fi
X           else
X              $GEDIT $testout &
X           fi
X        else
X           $GEDIT $testerr &
X           exit 1
X        fi
X     else
X        echo Running ${STEM}.pas ... see ${STEM}.interaction 1>&2
X        $GTERM --geometry +0+0 --disable-factory -t ${STEM}.interaction -x /tmp/interactc$$
X     fi
X  done
X  rm -f /tmp/interactc$$
X  exit 0
X
X  ## at one point I was going to pop up an "input window"
X  ##  on demand if the program did a read.  But after showing
X  ##  how lame such a facility is in DrScheme, it probably isn't
X  ##  worth the trouble.  I'm open to suggestion.
SHAR_EOF
  (set 20 10 07 25 22 05 25 'runpas.bak'; eval "$shar_touch") &&
  chmod 0755 'runpas.bak'
if test $? -ne 0
then ${echo} 'restore of runpas.bak failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'runpas.bak: MD5 check failed'
       ) << SHAR_EOF
45694adca349100c8beada48d9f624a8  runpas.bak
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'runpas.bak'` -ne 4681 && \
  ${echo} 'restoration warning:  size of runpas.bak is not 4681'
  fi
# ============= runs ==============
${echo} 'x - extracting runs (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'runs' &&
#!/bin/bash
X
X  ## compile *all* c files in folder
X  ## if this doesn't do what you want, make a new folder
X  
X  ## remove any existing executable
X
X  rm -f ${STEM}.exe
X  echo $GEDIT_CURRENT_DOCUMENT_NAME$1 | grep '[.]ss$' > /dev/null
X
X  if [ $? -ne 0 ] ; then
X     echo Filename must end in .c or .ss 1>&2
X     exit 1
X  fi
X
X  MZSCHEME=`which mzscheme 2> /dev/null`
X  if [ "" = "$MZSCHEME" ] ; then
X     echo You need mzcheme to run this program 1>&2
X     exit 1
X  fi
X
X  CWRAPPER=${HOME}/.RunC/cwrapper
X  test -f $CWRAPPER
X  if [ $? = 0 ] ; then
X     MZSCHEME="$CWRAPPER 10 $MZSCHEME"
X  fi
X
X  GEDIT=`which gedit 2> /dev/null`
X  if [ "" = "$GEDIT" ] ; then
X     GEDIT=${HOME}/.RunC/mygedit
X  fi
X
X  GTERM=`which gnome-terminal 2> /dev/null`
X  if [ "" = "$GTERM" ] ; then
X    GTERM=${HOME}/.RunC/mygterm
X  fi
X
X  STEM=`basename $GEDIT_CURRENT_DOCUMENT_NAME$1 .ss`
X  cat <<EOF > /tmp/interactc$$
X     #!/bin/bash
X     ($MZSCHEME ${STEM}.ss 1>/dev/tty) 2>&1 | ${HOME}/.RunC/defer ${STEM}.interaction.err $GEDIT
X     export R="$?"
X     echo Enter control-D when you are done. 1>&2
X     cat > /dev/null
EOF
X  chmod +x /tmp/interactc$$
X
X  for testdata in ${STEM}.in.*[^~]
X  do
X     echo $testdata | egrep "[*]" > /dev/null
X     if [ $? -ne 0 ] ; then
X        testout=`echo $testdata | sed -e 's/[.]in[.]/.out./'`
X        testerr=`echo $testdata | sed -e 's/[.]in[.]/.err./'`
X        echo Running ${STEM}.ss -- input from $testdata -- output to ${testout} 1>&2
X        (($MZSCHEME ./${STEM}.ss 1>&3) 2>&1 < $testdata| ${HOME}/.RunC/defer $testerr $GEDIT ) \
X             3> $testout
X        RUNRESULT="$?"
X        if [ $RUNRESULT = 0 ] ; then
X           EXPECT=`echo $testdata | sed -e 's/[.]in[.]/.expect./'`
X           test -f $EXPECT
X           if [ $? -eq 0 ] ; then
X              CHECK=`echo $testdata | sed -e 's/[.]in[.]/.check./'`
X              echo "$testout                                                    $EXPECT" > $CHECK
X              echo "==========                                                  ==========" >> $CHECK
X              diff -y $testout $EXPECT > $CHECK   ## drop preamble, so line numbers will be right
X              if [ $? -eq 0 ] ; then
X                 echo Output is equal to $EXPECT
X              else
X                 echo Unexpected output ... see $CHECK
X                 expand $CHECK > ${CHECK}.1 ; mv ${CHECK}.1 ${CHECK}
X                 $GEDIT $CHECK
X                 exit 1
X              fi
X           else
X              $GEDIT $testout
X           fi
X        else
X           exit 1
X        fi
X     else
X        echo Running ${STEM}.c ... see ${STEM}.interaction 1>&2
X        $GTERM --geometry +0+0 --disable-factory -t ${STEM}.interaction -x /tmp/interactc$$
X     fi
X  done
X  rm -f /tmp/interactc$$
X  exit 0
X
X  ## at one point I was going to pop up an "input window"
X  ##  on demand if the program did a read.  But after showing
X  ##  how lame such a facility is in DrScheme, it probably isn't
X  ##  worth the trouble.  I'm open to suggestion.
SHAR_EOF
  (set 20 10 07 25 22 05 25 'runs'; eval "$shar_touch") &&
  chmod 0755 'runs'
if test $? -ne 0
then ${echo} 'restore of runs failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'runs: MD5 check failed'
       ) << SHAR_EOF
b71b0afe0a942ea4233c8f26ff33c2b5  runs
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'runs'` -ne 2979 && \
  ${echo} 'restoration warning:  size of runs is not 2979'
  fi
# ============= cwrapper-foo.c ==============
${echo} 'x - extracting cwrapper-foo.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'cwrapper-foo.c' &&
/* This program ensures that SIGXCPU is set to SIG_DFL.
X
X   If there are future problems with limits, the debugging stuff will
X   be useful.
*/
X
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "limits.h"
X
char *message[] =
{
X  "",
X  "Hangup",
X  "Interrupt",
X  "Quit",
X  "Illegal instruction",
X  "Trace trap",
X  "Abort",
X  "Bus error",
X  "Floating-point exception",
X  "Kill",
X  "USR1",
X  "Segmentation fault",
X  "USR2",
X  "Broken pipe",
X  "Alarm",
X  "Terminate",
X  "Stack fault",
X  "Child status has changed",
X  "Continue",
X  "Stop",
X  "Keyboard stop",
X  "Background read from tty",
X  "Background write to tty",
X  "Urgent condition on socket",
X  "CPU limit exceeded",
X  "File size limit exceeded",
X  "Virtual alarm clock",
X  "Profiling alarm clock",
X  "Window size change",
X  "I/O now possible",
X  "Power failure restart",
X  "Bad system call"
};
int counter;
int main(int argc, char *argv[])
{
X  struct rlimit r;
X  pid_t pid;
X  const int runtime_ret = 1;
X  const int timelimit_ret = 2;
X  int num_signals = sizeof(message)/sizeof(char *);
X
for (counter=0;counter < 10;counter++) {
X
X  if ((pid = fork())) {
X    int status, retval, sig;
X    waitpid(pid, &status, 0);
X    if (WIFEXITED(status)) {
X      return 0;
X    } else if (WIFSIGNALED(status)) {
X      sig = WTERMSIG(status);
X      if (sig == SIGKILL) {
X	retval = timelimit_ret;
X	sig = SIGXCPU;
X      } else {
X	retval = runtime_ret;
X	fprintf(stderr,"\nRun-time error: ");
X      }
X      if (sig < num_signals) {
X        fprintf(stderr,"%s\n", message[sig]);
X      } else {
X        fprintf(stderr,"Signal %d\n", sig);
X      }
X      //return retval;
X      printf("retvaql %d\n",retval);
X    }
X  } else if (!pid) {
X    /* child */
X    signal(SIGXCPU, SIG_DFL);
X    r.rlim_cur = r.rlim_max = atoi(argv[1]);
X    setrlimit(RLIMIT_CPU, &r);
X    r.rlim_cur = r.rlim_max = 0;
X    setrlimit(RLIMIT_CORE, &r);
X    r.rlim_cur = r.rlim_max = FILE_SIZE_LIMIT*1024*1024*0;
X    setrlimit(RLIMIT_FSIZE, &r);
X    r.rlim_cur = r.rlim_max = DATA_STACK_LIMIT*1024*1024;
X    setrlimit(RLIMIT_DATA, &r);
X    setrlimit(RLIMIT_STACK, &r);
X
X    //execv(argv[2], argv+2);
X    if (counter % 3 == 0)
X       printf("hello\n"); fflush(stdout);
X    if (counter % 3) == 1) while(1);
X    if (counter %3 ==2) { while (1) malloc(10000);
X  } else {
X    fprintf(stderr,"cwrapper error: Cannot fork!\n");
X  }
}
X  return -1;
}
SHAR_EOF
  (set 20 10 07 25 22 05 24 'cwrapper-foo.c'; eval "$shar_touch") &&
  chmod 0644 'cwrapper-foo.c'
if test $? -ne 0
then ${echo} 'restore of cwrapper-foo.c failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'cwrapper-foo.c: MD5 check failed'
       ) << SHAR_EOF
d750a2c7dad0d2f441b56d3ec2363d1a  cwrapper-foo.c
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'cwrapper-foo.c'` -ne 2447 && \
  ${echo} 'restoration warning:  size of cwrapper-foo.c is not 2447'
  fi
# ============= cwrapper.c ==============
${echo} 'x - extracting cwrapper.c (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'cwrapper.c' &&
/* This program ensures that SIGXCPU is set to SIG_DFL.
X
X   If there are future problems with limits, the debugging stuff will
X   be useful.
*/
X
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/resource.h>
#include <sys/types.h>
#include <sys/wait.h>
#include "limits.h"
X
char *message[] =
{
X  "",
X  "Hangup",
X  "Interrupt",
X  "Quit",
X  "Illegal instruction",
X  "Trace trap",
X  "Abort",
X  "Bus error",
X  "Floating-point exception",
X  "Kill",
X  "USR1",
X  "Segmentation fault",
X  "USR2",
X  "Broken pipe",
X  "Alarm",
X  "Terminate",
X  "Stack fault",
X  "Child status has changed",
X  "Continue",
X  "Stop",
X  "Keyboard stop",
X  "Background read from tty",
X  "Background write to tty",
X  "Urgent condition on socket",
X  "CPU limit exceeded",
X  "File size limit exceeded",
X  "Virtual alarm clock",
X  "Profiling alarm clock",
X  "Window size change",
X  "I/O now possible",
X  "Power failure restart",
X  "Bad system call"
};
X
int main(int argc, char *argv[])
{
X  struct rlimit r;
X  pid_t pid;
X  const int runtime_ret = 1;
X  const int timelimit_ret = 2;
X  int num_signals = sizeof(message)/sizeof(char *);
X
X  if ((pid = fork())) {
X    int status, retval=0, sig;
X    waitpid(pid, &status, 0);
X    if (WIFEXITED(status)) {
X      if (WEXITSTATUS(status) != 0) {
X         fprintf(stderr,"%s\n",WEXITSTATUS(status)==91?"Wrong answer":WEXITSTATUS(status)==92?"Bad library call":WEXITSTATUS(status)==93?"Too many library calls":"Run-time error");
X         retval = runtime_ret;
X      }
X      return retval;
X    } else if (WIFSIGNALED(status)) {
X      sig = WTERMSIG(status);
X      if (sig == SIGKILL) {
X	retval = timelimit_ret;
X	sig = SIGXCPU;
X      } else {
X	retval = runtime_ret;
X	fprintf(stderr,"\nRun-time error: ");
X      }
X      if (sig < num_signals) {
X        fprintf(stderr,"%s\n", message[sig]);
X      } else {
X        fprintf(stderr,"Signal %d\n", sig);
X      }
X      return retval;
X    }
X  } else if (!pid) {
X    /* child */
X    signal(SIGXCPU, SIG_DFL);
X    r.rlim_cur = r.rlim_max = atoi(argv[1]);
X    setrlimit(RLIMIT_CPU, &r);
X    r.rlim_cur = r.rlim_max = 0;
X    setrlimit(RLIMIT_CORE, &r);
X    r.rlim_cur = r.rlim_max = FILE_SIZE_LIMIT*1024*1024;
X    setrlimit(RLIMIT_FSIZE, &r);
X    r.rlim_cur = r.rlim_max = DATA_STACK_LIMIT*1024*1024;
X    setrlimit(RLIMIT_DATA, &r);
X    setrlimit(RLIMIT_STACK, &r);
X
X    execv(argv[2], argv+2);
X  } else {
X    fprintf(stderr,"cwrapper error: Cannot fork!\n");
X  }
X  return -1;
}
SHAR_EOF
  (set 20 10 07 25 22 05 24 'cwrapper.c'; eval "$shar_touch") &&
  chmod 0644 'cwrapper.c'
if test $? -ne 0
then ${echo} 'restore of cwrapper.c failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'cwrapper.c: MD5 check failed'
       ) << SHAR_EOF
5c50d1ba2e2960277e2f0f7885778226  cwrapper.c
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'cwrapper.c'` -ne 2457 && \
  ${echo} 'restoration warning:  size of cwrapper.c is not 2457'
  fi
# ============= limits.h ==============
${echo} 'x - extracting limits.h (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'limits.h' &&
/* max size of output file in MB */
#define FILE_SIZE_LIMIT 100
X
/* max size of data and stack (separately) in MB */
#define DATA_STACK_LIMIT 256
SHAR_EOF
  (set 20 10 07 25 22 05 24 'limits.h'; eval "$shar_touch") &&
  chmod 0644 'limits.h'
if test $? -ne 0
then ${echo} 'restore of limits.h failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'limits.h: MD5 check failed'
       ) << SHAR_EOF
35223c092279d8fde0ea2ca8a9131851  limits.h
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'limits.h'` -ne 146 && \
  ${echo} 'restoration warning:  size of limits.h is not 146'
  fi
# ============= mygedit ==============
${echo} 'x - extracting mygedit (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'mygedit' &&
#!/bin/sh
X
#cat $1
SHAR_EOF
  (set 20 10 07 25 22 05 25 'mygedit'; eval "$shar_touch") &&
  chmod 0755 'mygedit'
if test $? -ne 0
then ${echo} 'restore of mygedit failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'mygedit: MD5 check failed'
       ) << SHAR_EOF
8df89b71f41f8baa68778ab07cc8bbff  mygedit
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'mygedit'` -ne 19 && \
  ${echo} 'restoration warning:  size of mygedit is not 19'
  fi
# ============= mygterm ==============
${echo} 'x - extracting mygterm (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'mygterm' &&
#!/bin/sh
X
echo "Error: batch execution requires input file(s) named ${STEM}.in.1 ${STEM}.in.2 ..."
exit 1
SHAR_EOF
  (set 20 10 07 25 22 05 25 'mygterm'; eval "$shar_touch") &&
  chmod 0755 'mygterm'
if test $? -ne 0
then ${echo} 'restore of mygterm failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'mygterm: MD5 check failed'
       ) << SHAR_EOF
2ee113a5761b0004a4a7a70ada0c6ca6  mygterm
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'mygterm'` -ne 107 && \
  ${echo} 'restoration warning:  size of mygterm is not 107'
  fi
# ============= myvalgrind ==============
${echo} 'x - extracting myvalgrind (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'myvalgrind' &&
#!/bin/sh
X
$3
SHAR_EOF
  (set 20 10 07 25 22 05 25 'myvalgrind'; eval "$shar_touch") &&
  chmod 0755 'myvalgrind'
if test $? -ne 0
then ${echo} 'restore of myvalgrind failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'myvalgrind: MD5 check failed'
       ) << SHAR_EOF
e3a004139d16ba76340475aa4a782814  myvalgrind
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'myvalgrind'` -ne 14 && \
  ${echo} 'restoration warning:  size of myvalgrind is not 14'
  fi
# ============= remccoms2.sh ==============
${echo} 'x - extracting remccoms2.sh (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'remccoms2.sh' &&
#! /bin/sh
# Strip C comments
# by Stewart Ravenhall <stewart.ravenhall@ukonline.co.uk> -- 4 October 2000
# Un-Korn-ized by Paolo Bonzini <bonzini@gnu.org> -- 24 November 2000
X
# Strip everything between /* and */ inclusive
X
# Copes with multi-line comments,
# disassociated end comment symbols,
# disassociated start comment symbols,
# multiple comments per line
X
# Check given file exists
program=`echo $0|sed -e 's:.*/::'`
if [ "$#" = 1 ] && [ "$1" != "-" ] && [ ! -f "$1" ]; then
X        print "$program: $1 does not exist"
X        exit 2
fi
X
# Create shell variables for ASCII 1 (control-a)
# and ASCII 2 (control-b)
a="`echo | tr '\012' '\001'`"
b="`echo | tr '\012' '\002'`"
X
cat $1 |
tr '\n\t\r' '   ' |
sed -e 's/^/ /' -e 's/(\*/\/*/g' -e 's/\*)/*\//g' -e 's/{/\/*/g' -e 's/}/*\//g'  |
sed '
X        # If no start comment then go to end of script
X        /\/\*/!b
X        :a
X        s:/\*:'"$a"':g
X        s:\*/:'"$b"':g
X
X        # If no end comment
X	/'"$b"'/!{
X		:b
X
X                # If not last line then read in next one
X                $!{
X                        N
X                        ba
X                }
X
X                # If last line then remove from start
X                # comment to end of line
X                # then go to end of script
X                s:'"$a[^$b]"'*$::
X                bc
X        }
X        
X        # Remove comments
X        '"s:$a[^$b]*$b"'::g
X	/'"$a"'/ bb
X        
X        :c
X        s:'"$a"':/*:g
X        s:'"$b"':*/:g
' | sed -e 's/ uses [^;]*/@&#/' -e 's/ program [^;]*/@&#/'  -e 's/ unit [^;]*/@&#/'  \
X    -e 's/^[^@]*@//' -e 's/#[^@]*@/\n/g' -e 's/#[^@]*$/\n/' | sed -e "s/^/$1/"
SHAR_EOF
  (set 20 10 07 25 22 05 25 'remccoms2.sh'; eval "$shar_touch") &&
  chmod 0755 'remccoms2.sh'
if test $? -ne 0
then ${echo} 'restore of remccoms2.sh failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'remccoms2.sh: MD5 check failed'
       ) << SHAR_EOF
4c7bd456899c42d920ae5bc9122803e9  remccoms2.sh
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'remccoms2.sh'` -ne 1633 && \
  ${echo} 'restoration warning:  size of remccoms2.sh is not 1633'
  fi
# ============= remccoms2c.sh ==============
${echo} 'x - extracting remccoms2c.sh (text)'
  sed 's/^X//' << 'SHAR_EOF' > 'remccoms2c.sh' &&
#! /bin/sh
# Strip C comments
# by Stewart Ravenhall <stewart.ravenhall@ukonline.co.uk> -- 4 October 2000
# Un-Korn-ized by Paolo Bonzini <bonzini@gnu.org> -- 24 November 2000
X
# Strip everything between /* and */ inclusive
X
# Copes with multi-line comments,
# disassociated end comment symbols,
# disassociated start comment symbols,
# multiple comments per line
X
# Check given file exists
program=`echo $0|sed -e 's:.*/::'`
if [ "$#" = 1 ] && [ "$1" != "-" ] && [ ! -f "$1" ]; then
X        print "$program: $1 does not exist"
X        exit 2
fi
X
# Create shell variables for ASCII 1 (control-a)
# and ASCII 2 (control-b)
a="`echo | tr '\012' '\001'`"
b="`echo | tr '\012' '\002'`"
X
cat $1 |
tr '\n\t\r' '   ' |
sed -e 's/^/ /' -e 's/(\*/\/*/g' -e 's/\*)/*\//g' -e 's/{/\/*/g' -e 's/}/*\//g'  |
sed '
X        # If no start comment then go to end of script
X        /\/\*/!b
X        :a
X        s:/\*:'"$a"':g
X        s:\*/:'"$b"':g
X
X        # If no end comment
X	/'"$b"'/!{
X		:b
X
X                # If not last line then read in next one
X                $!{
X                        N
X                        ba
X                }
X
X                # If last line then remove from start
X                # comment to end of line
X                # then go to end of script
X                s:'"$a[^$b]"'*$::
X                bc
X        }
X        
X        # Remove comments
X        '"s:$a[^$b]*$b"'::g
X	/'"$a"'/ bb
X        
X        :c
X        s:'"$a"':/*:g
X        s:'"$b"':*/:g
' | sed -e 's/ main [^;]*/@&#/' -e 's/ main [^;]*/@&#/'  -e 's/ main [^;]*/@&#/'  \
X    -e 's/^[^@]*@//' -e 's/#[^@]*@/\n/g' -e 's/#[^@]*$/\n/' | sed -e "s/^/$1/"
SHAR_EOF
  (set 20 10 07 25 22 05 25 'remccoms2c.sh'; eval "$shar_touch") &&
  chmod 0755 'remccoms2c.sh'
if test $? -ne 0
then ${echo} 'restore of remccoms2c.sh failed'
fi
  if ${md5check}
  then (
       ${MD5SUM} -c >/dev/null 2>&1 || ${echo} 'remccoms2c.sh: MD5 check failed'
       ) << SHAR_EOF
d16299cbb137aa094d6459d2743d7472  remccoms2c.sh
SHAR_EOF
  else
test `LC_ALL=C wc -c < 'remccoms2c.sh'` -ne 1630 && \
  ${echo} 'restoration warning:  size of remccoms2c.sh is not 1630'
  fi
if rm -fr ${lock_dir}
then ${echo} 'x - removed lock directory `'${lock_dir}\''.'
else ${echo} 'x - failed to remove lock directory `'${lock_dir}\''.'
  exit 1
fi
gcc -o cwrapper cwrapper.c

