r2521 - in people: . synrg synrg/xjig

Ben Armstrong synrg at alioth.debian.org
Wed Apr 4 11:17:38 UTC 2007


Author: synrg
Date: 2007-04-04 11:17:38 +0000 (Wed, 04 Apr 2007)
New Revision: 2521

Added:
   people/synrg/
   people/synrg/xjig/
   people/synrg/xjig/xjig-menu
Log:
Front end for xjig, intended for release with xjig

Added: people/synrg/xjig/xjig-menu
===================================================================
--- people/synrg/xjig/xjig-menu	2007-03-30 11:01:16 UTC (rev 2520)
+++ people/synrg/xjig/xjig-menu	2007-04-04 11:17:38 UTC (rev 2521)
@@ -0,0 +1,282 @@
+#!/bin/bash
+
+# xjig-menu(6) - front-end to launch xjig
+# Copyright (C) 2007 Ben Armstrong <synrg at sanctuary.nslug.ns.ca> 
+
+PROGRAM="`basename ${0}`"
+DESCRIPTION="front-end to launch xjig"
+VERSION="1.1"
+COPYRIGHT="${PROGRAM}, version ${VERSION}
+
+Copyright (C) 2007 Ben Armstrong <synrg at sanctuary.nslug.ns.ca>
+
+This program is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2 of the License, or
+(at your option) any later version.
+
+This program is distributed in the hope that it will be useful,
+but WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+GNU General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with this program; if not, write to the Free Software
+Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+
+On Debian systems, the complete text of the GNU General Public License
+can be found in /usr/share/common-licenses/GPL file."
+
+USAGE="${PROGRAM} [-p|--pieces XxY] [-s|--scale XxY] [-d|--directory DIR] [FILENAME]
+  ${PROGRAM} -m|--make [-p|--pieces XxY] [-s|--scale XxY] [-d|--directory DIR] [--desktop-directory DIR] [FILENAME]"
+
+HELP="\
+--pieces XxY             number of pieces to make on the X and Y axes
+--scale XxY              scaled image X and Y axis dimensions (default: 640x480)
+--directory DIR          directory to search for image files
+--desktop-directory DIR  directory where desktop link will be made (default: $HOME/Desktop)
+--make                   make a link to the specified puzzle in the desktop directory and exit
+FILENAME                 png, jpeg or ppm image
+
+Examples:
+   To make a 5x4 (20 piece) puzzle from scene.jpg
+
+      $ $PROGRAM --pieces 5x4 scene.jpg
+
+   To make an 10x5 (50 piece) puzzle, selecting a file from
+   the ~/backgrounds directory 
+
+      $ $PROGRAM --directory ~/backgrounds --pieces 10x5
+
+   To make a desktop link for a puzzle
+
+      $ $PROGRAM --pieces 5x4 scene.jpg --make"
+
+Version ()
+{
+   echo "$COPYRIGHT"
+   exit 0
+}
+
+Do_Usage ()
+{
+   echo "${PROGRAM} - ${DESCRIPTION}"
+   echo
+   echo "Usage:"
+   echo
+
+   if [ -n "${USAGE}" ]
+   then
+      echo "  ${USAGE}"
+      echo
+   fi
+
+   echo "  ${PROGRAM} [-h|--help]"
+   echo "  ${PROGRAM} [-u|--usage]"
+   echo "  ${PROGRAM} [-v|--version]"
+   echo
+}
+
+Usage ()
+{
+   Do_Usage;
+   echo
+   echo "Try \"${PROGRAM} --help\" for more information."
+
+   exit 1
+}
+
+Help ()
+{
+   Do_Usage;
+
+   if [ -n "${HELP}" ]
+   then
+      echo "${HELP}"
+      echo
+   fi
+
+   exit 0
+}
+
+Defaults ()
+{
+   if [ -z "$pieces" ] ; then pieces="${XJIG_PIECES}"; fi
+   if [ -z "$directory" ] ; then directory="${XJIG_DIRECTORY}"; fi
+   if [ -z "$directory" ] ; then directory="${HOME}"; fi
+   if [ -z "$scale" ] ; then scale="${XJIG_SCALE}"; fi
+   if [ -z "$scale" ] ; then scale="640x480"; fi
+   if [ -z "$desktop_directory" ] ; then desktop_directory="${XJIG_DESKTOP_DIRECTORY}"; fi
+   if [ -z "$desktop_directory" ] ; then desktop_directory="${HOME}/Desktop"; fi
+}
+
+Cleanup ()
+{
+   rm -f "$tmpout"
+}
+
+Error ()
+{
+   if [ -n "${1}" ] ; then
+      if [ -x /usr/bin/zenity ]; then
+         zenity --error --text="${1}"
+      else
+         echo "${1}" >&2
+      fi
+   else
+      if [ -x /usr/bin/zenity ]; then
+         zenity --error --text="$(cat $tmperr)"
+      else
+         cat "$tmperr" >&2
+      fi
+      rm -f "$tmperr"
+   fi
+   Cleanup
+   exit 1
+}
+
+CheckError ()
+{
+   if [ ${1} -ne 0 ] ; then
+      Error "${2}"
+   else
+      rm -f "$tmperr"
+   fi
+}
+
+Arguments ()
+{
+   ARGUMENTS="`getopt --longoptions pieces:,directory:,scale:,make,desktop_directory:,help,usage,version --name=${PROGRAM} --options p:d:mhuv --shell sh -- "${@}"`"
+
+   if [ "${?}" != "0" ]
+   then
+      Error "${PROGRAM}: getopt error" >&2
+      exit 1
+   fi
+
+   eval set -- "${ARGUMENTS}"
+
+   while true
+   do
+      case "${1}" in
+         -p|--pieces)
+            pieces="${2}" ; shift 2
+            ;;
+
+         -d|--directory)
+            directory="${2}" ; shift 2
+            ;;
+
+         -m|--make)
+            make="enabled" ; shift
+            ;;
+
+         --scale)
+            scale="${2}" ; shift 2
+            ;;
+
+         --desktop_directory)
+            desktop_directory="${2}" ; shift 2
+            ;;
+
+         -h|--help)
+            Help; shift
+            ;;
+
+         -u|--usage)
+            Usage; shift
+            ;;
+
+         -v|--version)
+            Version; shift
+            ;;
+
+         --)
+            shift
+            if [ -n "${1}" ] ; then
+               filename="${1}"
+               shift
+            fi
+            break
+            ;;
+
+         *)
+            echo "Internal error."
+            exit 1
+            ;;
+      esac
+   done
+}
+
+Validate ()
+{
+   # FIXME: wrap zenity in Dialog function supporting file|text|error
+   if [ -z "$filename" ] && [ -x /usr/bin/zenity ] ; then
+      filename="$(cd "$directory" && zenity  --title='Select a file to turn into a puzzle' --file-selection)"
+   fi
+   if [ -z "$filename" ] || [ ! -f "$filename" ] ; then
+      Error "${PROGRAM}: File not found: $filename"
+   fi
+   if [ -z "$pieces" ] && [ -x /usr/bin/zenity ] ; then
+      pieces="$(zenity --entry --title='Select number of pieces of puzzle' --text='Specify height and width in pieces as XxY, e.g. 5x4 for 20 pieces')"
+   fi
+   width="$(echo $pieces | cut -dx -f1)"
+   height="$(echo $pieces | cut -dx -f2)"
+   if [ $width -lt 1 ] || [ $height -lt 1 ] ; then
+      Error "${PROGRAM}: Invalid pieces: $pieces; specify XxY, where X and Y are positive integers"
+   fi
+   # FIXME: specify scale as percentage of the most constrained display axis
+   scale_width="$(echo $scale | cut -dx -f1)"
+   scale_height="$(echo $scale | cut -dx -f2)"
+   if [ $scale_width -lt 1 ] || [ $scale_height -lt 1 ] ; then
+      Error "${PROGRAM}: Invalid scale: $scale; specify XxY, where X and Y are positive integers"
+   fi
+}
+
+Convert ()
+{
+   tmpout=`tempfile --prefix=xjig --suffix=.jpg`
+   if [ -x /usr/bin/convert ] ; then
+      tmperr=`tempfile --prefix=xjigconv --suffix=.log`
+      convert "${1}" "$tmpout" 2>"$tmperr"
+      CheckError ${?}
+      outfile="$tmpout"
+      trap "Cleanup" EXIT HUP INT QUIT BUS PIPE TERM
+   else
+      outfile="${1}"
+   fi
+}
+
+Xjig ()
+{
+   tmperr=`tempfile --prefix=xjigxjig --suffix=.log`
+	# FIXME: make everything configurable/overridable (e.g. -no_flip, -side 2)
+   xjig -no_flip -side 2 -wh $scale_height -wh $scale_width -w $width -h $height -file "${1}"  2>"$tmperr"
+   err=$?
+   if [ $err -eq 1 ] ; then
+      grep -q 'X connection to .* broken (explicit kill or server shutdown).' $tmperr
+      err=$?
+   fi
+   CheckError $err
+}
+
+Main ()
+{
+   typeset -i width=0 height=0 scale_width=0 scale_height=0
+
+   Defaults
+   Arguments "${@}"
+   Validate
+   if [ "$make" = "enabled" ] ; then
+      Error "${PROGRAM}: FIXME: make a desktop link in $desktop_directory"
+   else
+      Convert "$filename"
+      Xjig "$outfile"
+   fi
+   Cleanup
+}
+
+XJIGMENURC="$HOME/.xjigmenurc"
+if [ -f "$XJIGMENURC" ] ; then . $XJIGMENURC ; fi
+
+Main "${@}"


Property changes on: people/synrg/xjig/xjig-menu
___________________________________________________________________
Name: svn:executable
   + *




More information about the Pkg-games-commits mailing list