1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
-
-
-
+
-
-
-
+
+
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
-
-
-
+
+
+
+
-
-
-
-
-
+
+
+
+
-
-
+
+
-
-
-
-
-
+
+
+
+
-
-
-
-
-
-
+
+
+
+
-
-
-
+
+
-
-
+
-
-
+
-
-
-
+
+
-
-
-
|
/*
* Copyright (C) 1997-2000 Matt Newman <[email protected]>
*
* Stylized option processing - requires consistent
* Convenient option processing
* external vars: opt, idx, objc, objv
*/
#ifndef _TCL_OPTS_H
#define _TCL_OPTS_H
#define OPT_PROLOG(option) \
if (strcmp(opt, (option)) == 0) { \
#define GET_OPT_BOOL(objPtr, varPtr) \
if (Tcl_GetBooleanFromObj(interp, objPtr, varPtr) != TCL_OK) { \
if (++idx >= objc) { \
Tcl_AppendResult(interp, \
"no argument given for ", \
(option), " option", \
(char *) NULL); \
return TCL_ERROR; \
}
#define OPT_POSTLOG() \
continue; \
return TCL_ERROR; \
}
#define GET_OPT_INT(objPtr, varPtr) \
if (Tcl_GetIntFromObj(interp, objPtr, varPtr) != TCL_OK) { \
return TCL_ERROR; \
}
#define OPTOBJ(option, var) \
OPT_PROLOG(option) \
var = objv[idx]; \
#define GET_OPT_LONG(objPtr, varPtr) \
if (Tcl_GetLongFromObj(interp, objPtr, varPtr) != TCL_OK) { \
return TCL_ERROR; \
OPT_POSTLOG()
#define OPTSTR(option, var) \
OPT_PROLOG(option) \
var = Tcl_GetString(objv[idx]);\
}
#define GET_OPT_WIDE(objPtr, varPtr) \
if (Tcl_GetWideIntFromObj(interp, objPtr, varPtr) != TCL_OK) { \
OPT_POSTLOG()
return TCL_ERROR; \
}
#define OPTINT(option, var) \
OPT_PROLOG(option) \
if (Tcl_GetIntFromObj(interp, objv[idx], \
&(var)) != TCL_OK) { \
return TCL_ERROR; \
#define GET_OPT_BIGNUM(objPtr, varPtr) \
if (Tcl_GetBignumFromObj(interp, objPtr, varPtr) != TCL_OK) { \
return TCL_ERROR; \
} \
OPT_POSTLOG()
#define OPTBOOL(option, var) \
OPT_PROLOG(option) \
if (Tcl_GetBooleanFromObj(interp, objv[idx],\
}
#define GET_OPT_STRING(objPtr, var, lenPtr) \
if ((var = Tcl_GetStringFromObj(objPtr, lenPtr)) == NULL) { \
&(var)) != TCL_OK) { \
return TCL_ERROR; \
} \
return TCL_ERROR; \
} \
OPT_POSTLOG()
#define OPTBYTE(option, var, lvar) \
#define GET_OPT_BYTE_ARRAY(objPtr, var, lenPtr) \
OPT_PROLOG(option) \
var = Tcl_GetByteArrayFromObj(objv[idx], &(lvar));\
if ((var = Tcl_GetByteArrayFromObj(objPtr, lenPtr)) == NULL) { \
OPT_POSTLOG()
#define OPTBAD(type, list) \
return TCL_ERROR; \
} \
Tcl_AppendResult(interp, "bad ", (type), \
" \"", opt, "\": must be ", \
(list), (char *) NULL)
#endif /* _TCL_OPTS_H */
|