; Options parsing, similar to GNU getopt_long
; Original (c) 1996 Mark Wooding
; This module interface version (c) 1999 Darren Salt

;----- Licensing notice --------------------------------------------------*
;
; This file is part of many programs.
;
; `mdwopt' 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.
;
; `mdwopt' 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 `mdwopt'; if not, write to the Free Software Foundation,
; Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.


 [ :DEF:__mdwopt__stubs__private__
 |

; The main routine.
; This will load the module (from System:Modules) if it has to.
; Note that if it fails to load it, it *will* generate an error;
;  you may like to catch SIGOSERROR.
	IMPORT	mdwopt

; These are simple veneers. They assume that the module is loaded.
	IMPORT	mdwopt_init_args
	IMPORT	mdwopt_read_args
	IMPORT	mdwopt_parse_command_string
	IMPORT	mdwopt_add_long_option
	IMPORT	mdwopt_reconstitute_command_string

	IMPORT	xmdwopt_init_args
	IMPORT	xmdwopt_read_args
	IMPORT	xmdwopt_parse_command_string
	IMPORT	xmdwopt_add_long_option
	IMPORT	xmdwopt_reconstitute_command_string

; Just in case :-)
	IMPORT	mdwopt_global

; getopt emulation
	IMPORT	optarg
	IMPORT	optopt
	IMPORT	optind
	IMPORT	opterr
	IMPORT	optprog

 ]

; mdwopt_data
			^ 0
mdwopt_data__arg	# 4 ; char *
mdwopt_data__opt	# 4 ; int
mdwopt_data__ind	# 4 ; int
mdwopt_data__err	# 4 ; int
mdwopt_data__prog	# 4 ; char *

mdwopt_data__private	# 20

mdwopt_data__SIZE	# 0 ; size of the mdwopt_data struct


; option (long options)

			^ 0
option__name		# 4 ; const char *
option__has_arg		# 4 ; int
option__flag		# 4 ; int *
option__val		# 4 ; int

option__SIZE		# 0 ; size of the option struct


; old-style names for long opt argument flags

no_argument		* 0
required_argument	* 1
optional_argument	* 2

; new-style names

gFlag_argReq		* 1
gFlag_argOpt		* 2
gFlag_switch		* 4
gFlag_negate		* 8
gFlag__last_long_opt_flag * 0

gFlag_noLongs		* 1
gFlag_noShorts		* 2
gFlag_numbers		* 4
gFlag_negation		* 8
gFlag_envVar		* 16
gFlag_noProgName	* 32
gFlag_negNumber		* 64
gFlag__last_mdwopt_flag	* 0

gFlag_negated		* 256
gFlag__last_return_flag	* 0

	END
