#!/usr/bin/env python
# encoding: utf-8
"""
Created by Brendan Erwin on 2008-05-21.
Copyright (c) 2008 Brendan Erwin. All rights reserved.

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 Street, Fifth Floor, Boston, MA  02110-1301, USA.

"""

import sys
import getopt
import MAppCommon

help_message = '''
M-App for EMC RepStrap.

M110 - NoOp.
	Does nothing. This command exists to provide some backward
	compatability with G-Code produced by SkeinForge.

Usage: M110

------------------------------------------------------------------

Copyright (C) 2008 Brendan Erwin

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 Street, Fifth Floor, Boston, MA  
02110-1301, USA.
'''


class Usage(Exception):
	def __init__(self, msg):
		self.msg = msg


def main(argv=None):

	if argv is None:
		argv = sys.argv
		
	try:		
		#Remove default "null" values
		argv = filter(MAppCommon.filterDefault, argv)
		
		try:
			opts, args = getopt.getopt(argv[1:], "h:", ["help"])
		except getopt.error, msg:
			raise Usage(msg)
	
		# option processing
		for option, value in opts:
			if option in ("-h", "--help"):
				raise Usage(help_message)
	
	except Usage, err:
		#print >> sys.stderr, sys.argv[0].split("/")[-1] + ": " + str(err.msg)
		print >> sys.stderr, str(err.msg)
		print >> sys.stderr, "For help use --help"
		return 2
	
	return 0

if __name__ == "__main__":
	sys.exit(main())
