#!/usr/bin/bash
set -o pipefail
if [ "$#" -ne 1 ] || [ ! -f "$1" ]; then
    echo "Usage: lucid source-file" >&2
    exit 1
fi
source_file=$1
# Prevent filenames beginning with a dash being parsed as options.
case $source_file in /*|./*|../*) ;; *) source_file=./$source_file ;; esac
rm -f -- "$source_file.i" || exit 1
libdir=/usr/lib64/plucid
if ! "$libdir/pass1" "$source_file" | "$libdir/pass2" | "$libdir/pass3" |
     "$libdir/pass4" | "$libdir/pass5" "$source_file"; then
    rm -f -- "$source_file.i"
    exit 1
fi
[ -f "$source_file.i" ] || exit 1
exec /usr/bin/luval "$source_file.i"
