#!/bin/bash # # Syntax: fig2pdf [-h] [-c] [-d pdf_dir] [-v] filename [...] # # Purpose: Transforms .fig files into .pdf files using fig2dev. # The resulting .pdf files are placed in ~/fig/pdf except # when the -d or the -c flag is specified. # If the -d flag is specified, then the .pdf files are placed in # pdf_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: Jun 20, 2009 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_pdf_dir=~/fig/pdf short_pdf_dir=$long_pdf_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_pdf_dir=$(pwd) short_pdf_dir="." ;; d) short_pdf_dir=${OPTARG} # Create absolute path name. long_pdf_dir=$(cd "$short_pdf_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_pdf_dir" ]; then echo >&2 echo >&2 "ERROR: The destination directory $short_pdf_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 pdf -c "${filename}.fig" > "${long_pdf_dir}/${basename}.pdf" if [[ ( $verbatim -eq 1 ) && ( $? -eq 0 ) ]] then echo "${filename}.fig exported to ${short_pdf_dir}/${filename}.pdf" fi else echo >&2 echo >&2 "ERROR: file ${filename}.fig not found." echo >&2 fi done