cutil/debug.h

Go to the documentation of this file.
00001 
00026 /* #define SECURE_NAMES done in secnames.h when necessary */
00027 
00028 #ifndef DEBUG_H
00029 #define DEBUG_H
00030 
00031 #include "variables.h"
00032 #include "callcpp.h"
00033 #include <stdio.h>
00034 
00035 /*----------------------------------------------------------------------
00036               T y p e s
00037 ----------------------------------------------------------------------*/
00042 typedef struct
00043 {
00044   const char *menu_string;
00045   void_proc menu_function;
00046 } MENU_ITEM;
00047 
00048 /*----------------------------------------------------------------------
00049               V a r i a b l e s
00050 ----------------------------------------------------------------------*/
00051 #define NUM_MENUS       30
00052 #define NUM_MENU_ITEMS  30
00053 
00054 extern MENU_ITEM menu_table[NUM_MENUS][NUM_MENU_ITEMS];
00055 
00056 /*----------------------------------------------------------------------
00057               M a c r o s
00058 ----------------------------------------------------------------------*/
00060 #define float_value(proc,string,variable,default)  \
00061                                        \
00062 float variable = default;                          \
00063                                        \
00064 int proc ()                                        \
00065 {                                                  \
00066    return (set_float_value (string, &variable));   \
00067 }                                                  \
00068 
00069 
00071 #define handle_menu(menu,handle_menu_x)           \
00072                                     \
00073 int handle_menu_x ()                            \
00074 {                                               \
00075    int x;                                      \
00076    cprintf ("\t 0. Continue\n");               \
00077    for (x = 0; x < NUM_MENU_ITEMS; x++) {      \
00078       if (menu_table[menu][x].menu_string)                           \
00079       cprintf ("\t%2d. %s\n", x, menu_table[menu][x].menu_string);  \
00080    }                                                                 \
00081                                     \
00082    scanf ("%d", &x);                           \
00083                                     \
00084    if (x == 0) return (0);                     \
00085    if ((0 < x && x < NUM_MENU_ITEMS) &&        \
00086       (menu_table[menu][x].menu_function)) {  \
00087       (*menu_table[menu][x].menu_function) ();\
00088       return (1);                             \
00089    }                                           \
00090    else {                                      \
00091       cprintf ("Bad menu selection");         \
00092       return (0);                             \
00093    }                                           \
00094 }                                               \
00095 
00096 
00098 #define int_value(proc,string,variable,default)    \
00099                                     \
00100 int variable = default;                         \
00101                                     \
00102 int proc ()                                     \
00103 {                                               \
00104    return (set_int_value (string, &variable)); \
00105 }                                               \
00106 
00107 
00108 #ifdef SECURE_NAMES
00109 
00110 #define toggle_value(proc,string,variable,default) \
00111                                     \
00112 int variable = default;                          \
00113                                     \
00114 int proc ()                                        \
00115 {                                                  \
00116    if (variable) {                                \
00117       variable = 0;                              \
00118    }                                              \
00119    else {                                         \
00120       variable = 1;                              \
00121    }                                              \
00122    return (1);                                    \
00123 }                                                  \
00124 
00125 #else
00126 
00127 #define toggle_value(proc,string,variable,default) \
00128                                     \
00129 int variable = default;                            \
00130                                     \
00131 int proc ()                                        \
00132 {                                                  \
00133    if (variable) {                                \
00134       cprintf( "%s is OFF\n", string);   \
00135       variable = 0;                              \
00136    }                                              \
00137    else {                                         \
00138       cprintf( "%s is ON\n", string);    \
00139       variable = 1;                              \
00140    }                                              \
00141    return (1);                                    \
00142 }                                                  \
00143 
00144 #endif
00145 
00147 #define make_float_const(name,default,installer)   \
00148                                        \
00149 float name = default;                        \
00150                                        \
00151 void installer ()                                   \
00152 {                                                   \
00153 float_variable (name, #name, default);              \
00154 }                                                   \
00155 
00156 
00158 #define make_int_const(name,default,installer)     \
00159                                        \
00160 int name = default;                          \
00161                                        \
00162 void installer ()                                   \
00163 {                                                   \
00164 int_variable (name, #name, default);                \
00165 }                                                   \
00166 
00167 
00169 #define make_toggle_const(name,default,installer)  \
00170                                        \
00171 int name = default;                          \
00172                                        \
00173 void installer ()                                   \
00174 {                                                   \
00175 int_variable (name, #name, default);                \
00176 }                                                   \
00177 
00178 
00179 #ifdef SECURE_NAMES
00180 
00181 #define make_float_var(name,default,installer,menu,menuitem,menufunct,menustring) \
00182                                        \
00183 float_value (menufunct, "", name, default);         \
00184                                        \
00185 void installer ()                                   \
00186 {                                                   \
00187 float_variable (name, #name, default);              \
00188 }                                                   \
00189 
00190 
00192 #define make_int_var(name,default,installer,menu,menuitem,menufunct,menustring)   \
00193                                        \
00194 int_value (menufunct, "", name, default);           \
00195                                        \
00196 void installer ()                                   \
00197 {                                                   \
00198 int_variable (name, #name, default);                \
00199 }                                                   \
00200 
00201 
00202 #define make_toggle_var(name,default,installer,menu,menuitem,menufunct,menustring)   \
00203                                        \
00204 toggle_value (menufunct, "", name, default);        \
00205                                        \
00206 void installer ()                                   \
00207 {                                                   \
00208 int_variable (name, #name, default);                \
00209 }                                                   \
00210 
00211 #else
00212 
00214 #define make_float_var(name,default,installer,menu,menuitem,menufunct,menustring) \
00215                                        \
00216 float_value (menufunct, menustring, name, default); \
00217                                        \
00218 void installer ()                                   \
00219 {                                                   \
00220 float_variable (name, #name, default);              \
00221 make_menu_item (menu, menuitem, menustring, menufunct); \
00222 }                                                   \
00223 
00224 
00228 #define make_int_var(name,default,installer,menu,menuitem,menufunct,menustring)   \
00229                                        \
00230 int_value (menufunct, menustring, name, default);   \
00231                                        \
00232 void installer ()                                   \
00233 {                                                   \
00234 int_variable (name, #name, default);                \
00235 make_menu_item (menu, menuitem, menustring, menufunct); \
00236 }                                                   \
00237 
00238 
00242 #define make_toggle_var(name,default,installer,menu,menuitem,menufunct,menustring)   \
00243                                        \
00244 toggle_value (menufunct, menustring, name, default);\
00245                                        \
00246 void installer ()                                   \
00247 {                                                   \
00248 int_variable (name, #name, default);                \
00249 make_menu_item (menu, menuitem, menustring, menufunct); \
00250 }                                                   \
00251 
00252 #endif
00253 
00254 /*----------------------------------------------------------------------
00255               F u n c t i o n s
00256 ----------------------------------------------------------------------*/
00257 int set_float_value(const char *message, float *variable); 
00258 
00259 int set_int_value(const char *message, int *variable); 
00260 
00261 void make_menu_item(int menu,
00262                     int menu_item,
00263                     const char *menu_string,
00264                     int_void menu_funct);
00265 
00266 /*
00267 #if defined(__STDC__) || defined(__cplusplus)
00268 # define _ARGS(s) s
00269 #else
00270 # define _ARGS(s) ()
00271 #endif
00272 
00273 int set_float_value
00274 _ARGS((char *message,
00275     float *variable));
00276 
00277 int set_int_value
00278 _ARGS((char *message,
00279     int *variable));
00280 
00281 void make_menu_item
00282 _ARGS((int menu,
00283     int menu_item,
00284     char *menu_string,
00285     int_proc menu_funct));
00286 
00287 #undef _ARGS
00288 */
00289 #endif

Generated on Wed Feb 28 19:49:10 2007 for Tesseract by  doxygen 1.5.1