
########## END OF Device Option PROCESS #########################

	##########################
	#
	# Job seperation: before
	#
	##########################

	#printf "\033%%-12345X" > $prtout_tmp

if [ "$is_PS" -eq 1 ]
then

	##########################
	#
	# Check if the input file has %%EndSetup string in it
	#
	##########################

	#cat - > $ps_tmp

	#is_DSC=`cat $* | grep -c "%EndSetup"`
	is_DSC=` grep -c "%EndSetup" $ps_tmp `

	##########################
	#
	# Check if is_DSC variable is empty
	#
	##########################

	case $is_DSC in

	1)

		if grep '^setup' $ps_tmp > /dev/null
		then
			csplit -q -f $ps_tmp $ps_tmp "/^setup/"
		else
			csplit -q -f $ps_tmp $ps_tmp "/%%EndSetup/"
		fi
		if [ -s $device_tmp ]
		then
		cat $device_tmp >> $ps_tmp"00"
		fi
		cat $ps_tmp"00" >> $prtout_tmp
		cat $ps_tmp"01" >> $prtout_tmp

		;;
	*)
		echo "%!PS-Adobe-3.0" >> $prtout_tmp
		echo "%%BeginSetup" >> $prtout_tmp
		if [ -s $device_tmp ]
		then
		cat $device_tmp >> $prtout_tmp
		fi
		echo "%%EndSetup" >> $prtout_tmp
		cat $ps_tmp >> $prtout_tmp
		;;
	esac
elif [ "$is_TXT" -eq 1 ]
then

	##########################
	#
	# If text file, apply a filter to remove stair case effect
	#
	##########################

	#cat $* | awk '{print $0, "\r"}' > $prtout_tmp

	if [ -s "$pjl_tmp" -o -s "$pcl_tmp" ]
	then
		printf "\033%%-12345X" > $prtout_tmp
		echo "@PJL SET JOB NAME=\"$title\"" >> $prtout_tmp
		cat $pjl_tmp >> $prtout_tmp
		echo "@PJL ENTER LANGUAGE=PCL" >> $prtout_tmp
		printf "\033E" >> $prtout_tmp
		cat $pcl_tmp >> $prtout_tmp; echo >> $prtout_tmp
	fi

	cat $ps_tmp | awk '{print $0, "\r"}' >> $prtout_tmp

else
	##########################
	#
	# If PCL file, send to print directly
	#
	##########################

	cat $ps_tmp > $prtout_tmp
fi
	##########################
	#
	# Job seperation: after
	#
	##########################

	printf "\033%%-12345X" >> $prtout_tmp

	cat $prtout_tmp #| awk '{print $0, "\r"}'

##########################
#
# Remove temporary files if DEBUG=empty
#
##########################

if test -z "$DEBUG"
then
        if test -f "$device_tmp"
        then
                /bin/rm $device_tmp
        fi

        if test -f "$prtout_tmp"
        then
                /bin/rm $prtout_tmp
        fi

        if test -f $ps_tmp"00"
        then
                /bin/rm $ps_tmp"00"
        fi

        if test -f $ps_tmp"01"
        then
                /bin/rm $ps_tmp"01"
        fi

        if test -f $ps_tmp
        then
                /bin/rm $ps_tmp
        fi

	if test -f $pjl_tmp
	then
		/bin/rm $pjl_tmp
	fi

	if test -f $pcl_tmp
	then
		/bin/rm $pcl_tmp
	fi

fi

