#!/bin/bash # # Syntax: fig2ps [-h] [-c] [-d ps_dir] [-v] filename [...] # # Purpose: Transforms .fig files into .ps files using fig2dev. # The resulting .ps files are placed in ~/fig/ps except # when the -d or the -c flag is specified. # If the -d flag is specified, then the .ps files are placed # in ps_dir. # By default the fig files are taken from ~/fig/xfig. # However, if the -c flag is given, then the fig files are taken # from the current directory and the output is placed into the # current directory. # If the -v flag is specified, extra information about succesful # transformations is displayed. # The -h flag shows the help info for this command. # Created: May 19, 1995 by Bart De Schutter # Last revised: Jan 2, 2011 by Bart De Schutter # # See http://www.deschutter.info/util/scripts.html for the latest version of # this script. # Status: public # Category: xfig # # Process options. # long_ps_dir=~/fig/ps short_ps_dir=$long_ps_dir fig_dir=~/fig/xfig verbatim=0 while getopts :hvcd: option do case "$option" in h) sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 ;; c) fig_dir=$(pwd) long_ps_dir=$(pwd) short_ps_dir="." ;; d) short_ps_dir=${OPTARG} # Create absolute path name. long_ps_dir=$(cd "$short_ps_dir" >/dev/null 2>&1 && pwd) ;; v) verbatim=1 ;; :) echo >&2 echo >&2 "Option -$OPTARG requires an argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 echo >&2 exit 1 ;; \?) echo >&2 echo >&2 "Unknown option: $OPTARG" echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 ;; esac done shift $(($OPTIND-1)) if [ ! -d "$short_ps_dir" ]; then echo >&2 echo >&2 "ERROR: The destination directory $short_ps_dir does not exist." echo >&2 exit 1 fi if [ $# -eq 0 ]; then echo >&2 echo >&2 "ERROR: ${0##*/} requires at least 1 input argument." echo >&2 sed '/^$/q;/^#!/d;s/^# //;s/^#//' $0 >&2 exit 1 fi # # Process fig files. # cd "$fig_dir" for fname in "$@" do filename=${fname%.fig} basename=${filename##*/} if [ -f "${filename}.fig" ]; then fig2dev -L ps -c "${filename}.fig" > "${long_ps_dir}/${basename}.ps" if [[ ( $verbatim -eq 1 ) && ( $? -eq 0 ) ]]; then echo "${filename}.fig exported to ${short_ps_dir}/${filename}.ps" fi else echo >&2 echo >&2 "ERROR: file ${filename}.fig not found." echo >&2 fi done