#!/bin/ksh -p
#
# ident "@(#)utxrot.ksh	1.1	08/11/20 SMI"
#
# Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
# Use is subject to license terms.
#

PATH=/usr/bin:/bin:/usr/sbin:/sbin:/usr/X11/bin:/usr/X11R6/bin:/usr/openwin/bin
export PATH

Progname="$0"

# Write a usage synopsis to stderr.  (The caller may redirect stderr
# to cause the output to go someplace else.)
#
function usage {
	print -u2 -- "$Progname: $@"
	print -u2 -- "  use: $Progname  # takes no options or arguments"
}


# Write the program name and the given message to stderr.
#
function errmsg {
	print -u2 -- "$Progname: Error; $@"
}


########################################################################
# Main program.  Everything before here was function definitions or
# static initialisation.

# This script expects to be invoked through one of a small number of
# names, each of which will result in the execution of 'xrandr' with
# different arguments.  Validate the invocation name before examining
# the rest of the command line so that we can establish an appropriate
# usage message.
#
invocation_name=$( basename $Progname )
case "$invocation_name" in

	utxrot0)
		xrandr_args="-o normal"
		usage_msg="set normal X screen orientation"
		;;

	utxrot180)
		xrandr_args="-o inverted"
		usage_msg="set inverted X screen orientation"
		;;

	*)	errmsg "unrecognised invocation name \"$invocation_name\""
		exit 1
		;;
esac

# If we were going to process options that would happen here

if [[ 0 -ne $# ]] ; then
	errmsg "illegal argument \"$1\""
	usage "$usage_msg"
	exit 1
fi

exec xrandr $xrandr_args

errmsg "failed to execute xrandr"
exit 2

