#!/bin/sh
# vim: ft=sh ts=4 sw=4 et
# Assemble a C source file from its component parts.
# The parts are stage2.{$base,$trial}/$testeddir/$module.c.part.{1,2,...$count}.
# Assemble uses the parts from stage2.$trial for the parts whose numbers are
# listed in $tested, and the parts from stage2.$base for the other parts.
# The patchwork file will be put in stage2/$testeddir/$module.c.

if test $# -le 5
then
    echo "Usage: assemble base trial testeddir module count testedparts ..."
    exit 1
fi

base="$1"
trial="$2"
testeddir="$3"
module="$4"
cnt="$5"
shift; shift; shift; shift; shift
tested="$@"

cat /dev/null > stage2/$testeddir/$module.c
i=0
while test $i -le $cnt
do
    if appears $i $tested
    then
        which="$trial"
    else
        which="$base"
    fi
    cat stage2.$which/$testeddir/$module.c.part.$i \
        >> stage2/$testeddir/$module.c
    i=`expr $i + 1`
done
