#!/bin/bash

#This script opens a telnet connection in the default X11 terminal emulator. The
#URL is in the usual telnet://<host>[:<port>] format.

if [ ! "$1" ]
then
	echo "no URL provided" >&2
	exit 1
fi

if ! echo "$1" | egrep -q '^telnet_mame_[0-9a-z]+://'
then
	echo "URL does not start with telnet_mame_<type>://" >&2
	exit 1
fi

terminal_type="`echo $1 | sed -E 's,telnet_mame_([0-9a-z_]*)://.*,\1,'`"
telnet_args="`echo $1 | sed 's_telnet[0-9a-z_]*://__' | tr ':' ' '`"

exec mame_terminal $terminal_type $telnet_args
