1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
6 * Moonlight List (moonlight-list@lists.ximian.com)
8 * Copyright 2007-2009 Novell, Inc. (http://www.novell.com)
10 * See the LICENSE file included with the distribution for details.
17 #include "plugin-class.h"
20 MethodArgTypeNone
= (0),
21 MethodArgTypeVoid
= (1 << NPVariantType_Void
),
22 MethodArgTypeNull
= (1 << NPVariantType_Null
),
23 MethodArgTypeBool
= (1 << NPVariantType_Bool
),
24 MethodArgTypeInt32
= (1 << NPVariantType_Int32
),
25 MethodArgTypeDouble
= (1 << NPVariantType_Double
),
26 MethodArgTypeString
= (1 << NPVariantType_String
),
27 MethodArgTypeObject
= (1 << NPVariantType_Object
),
28 MethodArgTypeAny
= (0xff)
32 decode_arg_ctype (char c
)
35 case 'v': return MethodArgTypeVoid
;
36 case 'n': return MethodArgTypeNull
;
37 case 'b': return MethodArgTypeBool
;
38 case 'i': return MethodArgTypeInt32
;
39 case 'd': return MethodArgTypeDouble
;
40 case 's': return MethodArgTypeString
;
41 case 'o': return MethodArgTypeObject
;
42 case '*': return MethodArgTypeAny
;
44 return MethodArgTypeNone
;
49 decode_arg_type (const char **in
)
51 MethodArgType t
, type
= MethodArgTypeNone
;
52 register const char *inptr
= *in
;
56 while (*inptr
&& *inptr
!= ')') {
57 t
= decode_arg_ctype (*inptr
);
58 type
= (MethodArgType
) ((int) type
| (int) t
);
62 type
= decode_arg_ctype (*inptr
);
73 * @arglist: a string representing an arg-list token (see grammar below)
74 * @args: NPVariant argument count
75 * @argv: NPVariant argument vector
77 * Checks that the NPVariant arguments satisfy the argument count and
78 * types expected (provided via @typestr).
80 * The @typestr argument should follow the following syntax:
82 * simple-arg-type ::= "v" / "n" / "b" / "i" / "d" / "s" / "o" / "*"
83 * ; each char represents one of the following
84 * ; NPVariant types: Void, Null, Bool, Int32,
85 * ; Double, String, Object and wildcard
87 * arg-type ::= simple-arg-type / "(" 1*(simple-arg-type) ")"
89 * optional-args ::= "[" *(arg-type) "]"
91 * arg-list ::= *(arg-type) (optional-args)
94 * Returns: %true if @argv matches the arg-list criteria specified in
95 * @arglist or %false otherwise.
98 check_arg_list (const char *arglist
, guint32 argc
, const NPVariant
*argv
)
100 const char *inptr
= arglist
;
104 // check all of the required arguments
105 while (*inptr
&& *inptr
!= '[' && i
< argc
) {
106 mask
= decode_arg_type (&inptr
);
107 if (!(mask
& (1 << argv
[i
].type
))) {
108 // argv[i] does not match any of the expected types
115 if (*inptr
&& *inptr
!= '[' && i
< argc
) {
116 // we were not provided enough arguments
120 // now check all of the optional arguments
122 while (*inptr
&& *inptr
!= ']' && i
< argc
) {
123 mask
= decode_arg_type (&inptr
);
124 if (!(mask
& (1 << argv
[i
].type
))) {
125 // argv[i] does not match any of the expected types
133 // we were provided too many arguments