#!/bin/sh
########################################################################
#             (c) Copyright 2004 Lexmark International, Inc.           #
#                        All rights reserved                           #
########################################################################
#                                                                      #
# This command shows the license agreement.                            #
#                                                                      #
########################################################################

DEBUG=0


PRODUCT_LINK="/usr/genprint"
SCRIPTS_DIR="${PRODUCT_LINK}/bin/.scripts"

#-- load the shared script
. ${SCRIPTS_DIR}/shared

#-- initialize variables:
initialize user

PRINTER_LIST1="${PRODUCT_LINK}/etc/printers/Printer.list"
PRINTER_LIST2="${ROOT_SPOOL_DIR}/.${PRODUCT_NAME}/printers/Printer.list"

if [ -f "${PRINTER_LIST2}" ]; then
	PLIST_FILES="${PRINTER_LIST1} ${PRINTER_LIST2}"
else
 	PLIST_FILES="${PRINTER_LIST1}"
fi


#-- usage text
usage()
{

help_queue_name="T420"

${CAT_CMD} << EOT

supported_printers
    Lists all supported printers types.

USAGE:
    supported_printers [-p]

OPTIONS:
    -p 
       Search for a specific printer model. 

EXAMPLES:

    To list all supported printers and supported languages:
	
      $ supported_printers

    To search for a specific printer model:
	
      $ supported_printers -p ${help_queue_name}

EOT
}

while getopts p:h? arg
do
  case "${arg}" in
  	p) ${GREP_CMD} "enable_asian=yes" ${ROOT_SPOOL_DIR}/.${PRODUCT_NAME}/props/app.properties >/dev/null 2>&1
		if [ "${?}" = "0" ];then
			${CAT_CMD} ${PLIST_FILES} | ${EGREP_CMD} -v "^ *#" | ${GREP_CMD} -i "${OPTARG}" | ${UNIQ_CMD}
		else
			${CAT_CMD} ${PLIST_FILES} | ${EGREP_CMD} -v "^ *#" | ${GREP_CMD} -v Asian | ${GREP_CMD} -i "${OPTARG}" | ${UNIQ_CMD}
		fi
		rc=$?
		if [ "${rc}" != "0" ]; then
			${PRINT_CMD} No matches found for \""${OPTARG}"\"
		fi
		exit 99
     	;;

	h) usage 
		exit
		;;
	?) usage 
		exit
		;;
  esac 
done

#-- List supported printer types. 
${GREP_CMD} "enable_asian=yes" ${ROOT_SPOOL_DIR}/.${PRODUCT_NAME}/props/app.properties >/dev/null 2>&1
if [ "${?}" = "0" ];then
	${CAT_CMD} ${PLIST_FILES} | ${EGREP_CMD} -v "^ *#" | ${UNIQ_CMD} | ${MORE_CMD}
else
	${CAT_CMD} ${PLIST_FILES} | ${EGREP_CMD} -v "^ *#" | ${GREP_CMD} -v "Asian" |  ${UNIQ_CMD} | ${MORE_CMD}
fi

