~ubuntu-branches/ubuntu/lucid/mpg123/lucid

« back to all changes in this revision

Viewing changes to src/getlopt.h

Tags: upstream-0.60
ImportĀ upstreamĀ versionĀ 0.60

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
        getlopt: command line option/parameter parsing
 
3
 
 
4
        copyright ?-2006 by the mpg123 project - free software under the terms of the LGPL 2.1
 
5
        see COPYING and AUTHORS files in distribution or http://mpg123.de
 
6
        initially written Oliver Fromme
 
7
        old timestamp: Tue Apr  8 07:13:39 MET DST 1997
 
8
*/
 
9
 
 
10
#include <stdlib.h>
 
11
#include <string.h>
 
12
 
 
13
 
 
14
#ifndef _MPG123_GETLOPT_H_
 
15
#define _MPG123_GETLOPT_H_
 
16
 
 
17
extern int loptind;     /* index in argv[] */
 
18
extern int loptchr;     /* index in argv[loptind] */
 
19
extern char *loptarg;   /* points to argument if present, else to option */
 
20
 
 
21
typedef struct {
 
22
        char sname;     /* short option name, can be 0 */
 
23
        char *lname;    /* long option name, can be 0 */
 
24
        int flags;      /* see below */
 
25
        void (*func)(char *);   /* called if != 0 (after setting of var) */
 
26
        void *var;      /* type is *long, *char or **char, see below */
 
27
        long value;
 
28
} topt;
 
29
 
 
30
/* 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 
 
31
for .... no flag) */
 
32
#define GLO_ARG  1
 
33
#define GLO_CHAR 2
 
34
#define GLO_INT  4
 
35
#define GLO_LONG 8
 
36
 
 
37
/* flags:
 
38
 *      bit 0 = 0 - no argument
 
39
 *              if var != NULL
 
40
 *                      *var := value or (char)value [see bit 1]
 
41
 *              else
 
42
 *                      loptarg = &option
 
43
 *                      return ((value != 0) ? value : sname)
 
44
 *      bit 0 = 1 - argument required
 
45
 *              if var != NULL
 
46
 *                      *var := atoi(arg) or strdup(arg) [see bit 1]
 
47
 *              else
 
48
 *                      loptarg = &arg
 
49
 *                      return ((value != 0) ? value : sname)
 
50
 *
 
51
 *      bit 1 = 1 - var is a pointer to a char (or string),
 
52
 *                      and value is interpreted as char
 
53
 *      bit 2 = 1 - var is a pointer to int
 
54
 *      bit 3 = 1 - var is a pointer to long
 
55
 *
 
56
 * Note: The options definition is terminated by a topt
 
57
 *       containing only zeroes.
 
58
 */
 
59
 
 
60
#define GLO_END         0
 
61
#define GLO_UNKNOWN     -1
 
62
#define GLO_NOARG       -2
 
63
#define GLO_CONTINUE    -3
 
64
 
 
65
int getlopt (int argc, char *argv[], topt *opts);
 
66
 
 
67
/* return values:
 
68
 *      GLO_END         (0)     end of options
 
69
 *      GLO_UNKNOWN     (-1)    unknown option *loptarg
 
70
 *      GLO_NOARG       (-2)    missing argument
 
71
 *      GLO_CONTINUE    (-3)    (reserved for internal use)
 
72
 *      else - return value according to flags (see above)
 
73
 */
 
74
 
 
75
 
 
76
#endif