#!/bin/sh

# Fig2dev: Translate Fig code to various Devices
# Copyright (c) 1991 by Micah Beck
# Parts Copyright (c) 1989-2010 by Brian V. Smith
#
# Any party obtaining a copy of these files is granted, free of charge, a
# full and unrestricted irrevocable, world-wide, paid up, royalty-free,
# nonexclusive right and license to deal in this software and documentation
# files (the "Software"), including without limitation the rights to use,
# copy, modify, merge, publish, distribute, sublicense and/or sell copies
# of the Software, and to permit persons who receive copies from any such
# party to do so, with the only requirement being that the above copyright
# and this permission notice remain intact.

sed -e '
	s/\(\\f[^(]\)\(\\s[0-9]*\)/\2\1/g
	s/\(\\f(..\)\(\\s[0-9]*\)/\2\1/g
	s/"\([^"]*\)\\fP\([^"]*\)"/"\1\2"/g
	s/"\([^"]*\)\\fR\([^"]*\)"/"\1\\rm \2"/g
	s/"\([^"]*\)\\fI\([^"]*\)"/"\1\\it \2"/g
	s/"\([^"]*\)\\fB\([^"]*\)"/"\1\\bf \2"/g
	s/"\([^"]*\)\\fH\([^"]*\)"/"\1\\sf \2"/g
	s/"\([^"]*\)\\fC\([^"]*\)"/"\1\\tt \2"/g
	s/"\([^"]*\)\\f(CO\([^"]*\)"/"\1\\tt \2"/g
	s/"\([^"]*\)\\f(CW\([^"]*\)"/"\1\\tt \2"/g
	s/"\([^"]*\)\\s0\([^"]*\)"/"\1\2"/g
	s/"\([^"]*\)\\s[56]\([^0-9][^"]*\)"/"\1\\tiny \2"/g
	s/"\([^"]*\)\\s7\([^0-9][^"]*\)"/"\1\\scriptsize \2"/g
	s/"\([^"]*\)\\s8\([^0-9][^"]*\)"/"\1\\footnotesize \2"/g
	s/"\([^"]*\)\\s9\([^0-9][^"]*\)"/"\1\\small \2"/g
	s/"\([^"]*\)\\s1[01]\([^"]*\)"/"\1\\normalsize \2"/g
	s/"\([^"]*\)\\s1[23]\([^"]*\)"/"\1\\large \2"/g
	s/"\([^"]*\)\\s1[4-6]\([^"]*\)"/"\1\\Large \2"/g
	s/"\([^"]*\)\\s1[7-9]\([^"]*\)"/"\1\\LARGE \2"/g
	s/"\([^"]*\)\\s2[0-3]\([^"]*\)"/"\1\\huge \2"/g
	s/"\([^"]*\)\\s2[4-9]\([^"]*\)"/"\1\\Huge \2"/g
	s/"\([^"]*\)\\s3[0-9]\([^"]*\)"/"\1\\Huge \2"/g
	' $*
