~ubuntu-branches/debian/experimental/lftp/experimental

« back to all changes in this revision

Viewing changes to lib/argmatch.h

  • Committer: Package Import Robot
  • Author(s): Noël Köthe
  • Date: 2015-08-21 16:06:22 UTC
  • mfrom: (1.1.20) (24.1.38 sid)
  • Revision ID: package-import@ubuntu.com-20150821160622-lckdmbiqx16wefgy
Tags: 4.6.4-1
new upstream release 2015-08-21

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* argmatch.h -- definitions and prototypes for argmatch.c
2
2
 
3
 
   Copyright (C) 1990, 1998, 1999, 2001, 2002, 2004, 2005 Free Software
 
3
   Copyright (C) 1990, 1998-1999, 2001-2002, 2004-2005, 2009-2015 Free Software
4
4
   Foundation, Inc.
5
5
 
6
6
   This program is free software: you can redistribute it and/or modify
26
26
 
27
27
# include "verify.h"
28
28
 
 
29
#ifdef  __cplusplus
 
30
extern "C" {
 
31
#endif
 
32
 
29
33
# define ARRAY_CARDINALITY(Array) (sizeof (Array) / sizeof *(Array))
30
34
 
31
35
/* Assert there are as many real arguments as there are values
40
44
   to the same values in VALLIST).  */
41
45
 
42
46
ptrdiff_t argmatch (char const *arg, char const *const *arglist,
43
 
                    char const *vallist, size_t valsize);
 
47
                    char const *vallist, size_t valsize) _GL_ATTRIBUTE_PURE;
44
48
 
45
49
# define ARGMATCH(Arg, Arglist, Vallist) \
46
50
  argmatch (Arg, Arglist, (char const *) (Vallist), sizeof *(Vallist))
47
51
 
48
52
/* xargmatch calls this function when it fails.  This function should not
49
53
   return.  By default, this is a function that calls ARGMATCH_DIE which
50
 
   in turn defaults to `exit (exit_failure)'.  */
 
54
   in turn defaults to 'exit (exit_failure)'.  */
51
55
typedef void (*argmatch_exit_fn) (void);
52
56
extern argmatch_exit_fn argmatch_die;
53
57
 
54
58
/* Report on stderr why argmatch failed.  Report correct values. */
55
59
 
56
60
void argmatch_invalid (char const *context, char const *value,
57
 
                       ptrdiff_t problem);
 
61
                       ptrdiff_t problem);
58
62
 
59
63
/* Left for compatibility with the old name invalid_arg */
60
64
 
66
70
/* Report on stderr the list of possible arguments.  */
67
71
 
68
72
void argmatch_valid (char const *const *arglist,
69
 
                     char const *vallist, size_t valsize);
 
73
                     char const *vallist, size_t valsize);
70
74
 
71
75
# define ARGMATCH_VALID(Arglist, Vallist) \
72
76
  argmatch_valid (Arglist, (char const *) (Vallist), sizeof *(Vallist))
73
77
 
74
78
 
75
79
 
76
 
/* Same as argmatch, but upon failure, reports a explanation on the
77
 
   failure, and exits using the function EXIT_FN. */
 
80
/* Same as argmatch, but upon failure, report an explanation of the
 
81
   failure, and exit using the function EXIT_FN. */
78
82
 
79
83
ptrdiff_t __xargmatch_internal (char const *context,
80
 
                                char const *arg, char const *const *arglist,
81
 
                                char const *vallist, size_t valsize,
82
 
                                argmatch_exit_fn exit_fn);
 
84
                                char const *arg, char const *const *arglist,
 
85
                                char const *vallist, size_t valsize,
 
86
                                argmatch_exit_fn exit_fn);
83
87
 
84
88
/* Programmer friendly interface to __xargmatch_internal. */
85
89
 
86
 
# define XARGMATCH(Context, Arg, Arglist, Vallist)              \
87
 
  ((Vallist) [__xargmatch_internal (Context, Arg, Arglist,      \
88
 
                                    (char const *) (Vallist),   \
89
 
                                    sizeof *(Vallist),          \
90
 
                                    argmatch_die)])
 
90
# define XARGMATCH(Context, Arg, Arglist, Vallist)              \
 
91
  ((Vallist) [__xargmatch_internal (Context, Arg, Arglist,      \
 
92
                                    (char const *) (Vallist),   \
 
93
                                    sizeof *(Vallist),          \
 
94
                                    argmatch_die)])
91
95
 
92
96
/* Convert a value into a corresponding argument. */
93
97
 
94
98
char const *argmatch_to_argument (char const *value,
95
 
                                  char const *const *arglist,
96
 
                                  char const *vallist, size_t valsize);
97
 
 
98
 
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist)                  \
99
 
  argmatch_to_argument (Value, Arglist,                                 \
100
 
                        (char const *) (Vallist), sizeof *(Vallist))
 
99
                                  char const *const *arglist,
 
100
                                  char const *vallist, size_t valsize)
 
101
  _GL_ATTRIBUTE_PURE;
 
102
 
 
103
# define ARGMATCH_TO_ARGUMENT(Value, Arglist, Vallist)                  \
 
104
  argmatch_to_argument (Value, Arglist,                                 \
 
105
                        (char const *) (Vallist), sizeof *(Vallist))
 
106
 
 
107
#ifdef  __cplusplus
 
108
}
 
109
#endif
101
110
 
102
111
#endif /* ARGMATCH_H_ */