#!/bin/sh
# Didier Spaier didieratslintdotfr 2019-2022
# I wrote this script from scratch and put it in the public domain.
export TEXTDOMAIN=slint-scripts
if [ "$(id -u)" -eq 0 ]; then
	gettext "Please run this script as regular user."; echo
	exit
fi
program_name=$0
features='emacspeak
speechd-el'
desc_emacsspeak=$(gettext "emacspeak (The Complete Audio Desktop, based on emacs)")
desc_speechdel=$(gettext "speechd-el (Emacs client to speech synthesizers and Braille displays)")
descriptions="$desc_emacsspeak
$desc_speechdel"

#emacspeak_cmd='(load-file "/usr/share/emacs/site-lisp/emacspeak/lisp/emacspeak-setup.el")'
#speechd_el_cmd="(autoload 'speechd-speak \"speechd-speak\" nil t)"
usage() {
  gettext "Usage: "
  printf '%s' "$program_name <emacspeak> "
  gettext "or"
  echo  " <speechd-el>"
  gettext "This script allows to disable:"; echo
  echo "$descriptions"
  exit
}
if [ $# -ne 1 ]; then usage; fi
if  ! echo "$features"|grep -qw "$1"; then
	printf '%s' "$1 "
	gettext "is an unknown feature."; echo
	gettext "Available features:"; echo
	echo "$descriptions"
	exit
fi
case $1 in
	emacspeak)
		if [ "$(find /var/lib/pkgtools/packages/ -name "${1}*")" = "" ]; then
			printf '%s' "$1 "
			gettext "is not installed."; echo
			exit
		fi
		if grep -q emacspeak-setup.el ~/.emacs 2>/dev/null; then
			bof=$(mktemp)
			sed	'/emacspeak-setup.el/d
			/"DTK_PROGRAM" "outloud"/d' ~/.emacs > "$bof"
			mv "$bof" ~/.emacs
		fi
		gettext "emacspeak is disabled."; echo
	;;
	speechd-el)
		if [ "$(find /var/lib/pkgtools/packages/ -name "${1}*")" = "" ]; then
			printf '%s' "$1 "
			gettext "is not installed."
			exit
		fi
		if grep -q speechd-speak ~/.emacs 2>/dev/null; then
			bof=$(mktemp)
			sed "/speechd-speak/d
			/speechd-out-active-drivers/d" ~/.emacs > "$bof"
			mv "$bof" ~/.emacs
		fi
		gettext "speechd-el is disabled."; echo
	;;
esac

