Blame src/getlopt.h

Packit c32a2d
/*
Packit c32a2d
	getlopt: command line option/parameter parsing
Packit c32a2d
Packit c32a2d
	copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
Packit c32a2d
	see COPYING and AUTHORS files in distribution or http://mpg123.org
Packit c32a2d
	initially written Oliver Fromme
Packit c32a2d
	old timestamp: Tue Apr  8 07:13:39 MET DST 1997
Packit c32a2d
*/
Packit c32a2d
Packit c32a2d
#include <stdlib.h>
Packit c32a2d
#include <string.h>
Packit c32a2d
Packit c32a2d
Packit c32a2d
#ifndef _MPG123_GETLOPT_H_
Packit c32a2d
#define _MPG123_GETLOPT_H_
Packit c32a2d
Packit c32a2d
extern int loptind;	/* index in argv[] */
Packit c32a2d
extern int loptchr;	/* index in argv[loptind] */
Packit c32a2d
extern char *loptarg;	/* points to argument if present, else to option */
Packit c32a2d
Packit c32a2d
typedef struct {
Packit c32a2d
	char sname;	/* short option name, can be 0 */
Packit c32a2d
	char *lname;	/* long option name, can be 0 */
Packit c32a2d
	int flags;	/* see below */
Packit c32a2d
	void (*func)(char *);	/* called if != 0 (after setting of var) */
Packit c32a2d
	void *var;	/* type is *long, *char or **char, see below */
Packit c32a2d
	long value;
Packit c32a2d
} topt;
Packit c32a2d
Packit c32a2d
/* ThOr: make this clear; distict long from int (since this is != on my Alpha) and really use a flag for every case (spare the 0 case 
Packit c32a2d
for .... no flag) */
Packit c32a2d
#define GLO_ARG  1
Packit c32a2d
#define GLO_CHAR 2
Packit c32a2d
#define GLO_INT  4
Packit c32a2d
#define GLO_LONG 8
Packit c32a2d
#define GLO_DOUBLE 16
Packit c32a2d
Packit c32a2d
/* flags:
Packit c32a2d
 *	bit 0 = 0 - no argument
Packit c32a2d
 *		if var != NULL
Packit c32a2d
 *			*var := value or (char)value [see bit 1]
Packit c32a2d
 *		else
Packit c32a2d
 *			loptarg = &option
Packit c32a2d
 *			return ((value != 0) ? value : sname)
Packit c32a2d
 *	bit 0 = 1 - argument required
Packit c32a2d
 *		if var != NULL
Packit c32a2d
 *			*var := atoi(arg) or strdup(arg) [see bit 1]
Packit c32a2d
 *		else
Packit c32a2d
 *			loptarg = &arg
Packit c32a2d
 *			return ((value != 0) ? value : sname)
Packit c32a2d
 *
Packit c32a2d
 *	bit 1 = 1 - var is a pointer to a char (or string),
Packit c32a2d
 *			and value is interpreted as char
Packit c32a2d
 *	bit 2 = 1 - var is a pointer to int
Packit c32a2d
 *	bit 3 = 1 - var is a pointer to long
Packit c32a2d
 *
Packit c32a2d
 * Note: The options definition is terminated by a topt
Packit c32a2d
 *	 containing only zeroes.
Packit c32a2d
 */
Packit c32a2d
Packit c32a2d
#define GLO_END		0
Packit c32a2d
#define GLO_UNKNOWN	-1
Packit c32a2d
#define GLO_NOARG	-2
Packit c32a2d
#define GLO_CONTINUE	-3
Packit c32a2d
Packit c32a2d
int getlopt (int argc, char *argv[], topt *opts);
Packit c32a2d
Packit c32a2d
/* return values:
Packit c32a2d
 *	GLO_END		(0)	end of options
Packit c32a2d
 *	GLO_UNKNOWN	(-1)	unknown option *loptarg
Packit c32a2d
 *	GLO_NOARG	(-2)	missing argument
Packit c32a2d
 *	GLO_CONTINUE	(-3)	(reserved for internal use)
Packit c32a2d
 *	else - return value according to flags (see above)
Packit c32a2d
 */
Packit c32a2d
Packit c32a2d
Packit c32a2d
#endif