cctw  0.2.1
cctwtclutils.h
Go to the documentation of this file.
1 /*
2  * cctwtclutils.h
3  *
4  * Created on: Nov 18, 2013
5  * Author: wozniak
6  */
7 
8 #ifndef CCTWTCLUTILS_H
9 #define CCTWTCLUTILS_H
10 
11 #include <tcl.h>
12 
18 #define TCL_ARGS(count_expr, help) { \
19  int count = count_expr; \
20  if (objc != count) { \
21  char* tmp = Tcl_GetStringFromObj(objv[0], NULL); \
22  printf("command %s requires %i arguments, received %i\n", \
23  tmp, count, objc); \
24  printf(help "\n"); \
25  return TCL_ERROR; \
26  } \
27  }
28 
32 void tcl_condition_failed(Tcl_Interp* interp, Tcl_Obj* command,
33  const char* format, ...)
34  __attribute__ ((format (printf, 3, 4)));
35 
40 #define TCL_RETURN_ERROR(format, args...) \
41  { \
42  tcl_condition_failed(interp, objv[0], format, ## args); \
43  return TCL_ERROR; \
44  }
45 
49 #define TCL_CHECK_MSG(rc, format, args...) \
50  if (rc != TCL_OK) { \
51  TCL_RETURN_ERROR(format, ## args); \
52  }
53 
57 #define TCL_CHECK(rc) { if (rc != TCL_OK) { return TCL_ERROR; }}
58 
59 #define TCL_CONDITION(condition, format, args...) \
60  if (!(condition)) { \
61  TCL_RETURN_ERROR(format, ## args); \
62  }
63 
64 #endif
void tcl_condition_failed(Tcl_Interp *interp, Tcl_Obj *command, const char *format,...) __attribute__((format(printf