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 60 61 62 63 64 65
|
// Macros to save time
#if !defined(_macro_hh_)
#define _macro_h_
#define strEQ(s1, s2) (!strcmp((s1), (s2)))
#define strNE(s1, s2) ( strcmp((s1), (s2)))
#define SMALLER_ONE(a, b) ((a) < (b) ? (a) : (b))
#define LARGER_ONE(a, b) ((a) > (b) ? (a) : (b))
#define GRI_ABS(x) ((x) < 0.0 ? (-(x)) : (x))
#define show_words() { \
for (int i = 0; i < _nword; i++) \
printf("word[%d]=`%s' ", i, _word[i]); \
printf("\n"); \
}
// If 'condition' is false, perform action (typically warning).
#define SUGGEST(condition, action_if_not) { \
if (!(condition)) { \
action_if_not; \
} \
}
// If 'condition' is untrue, perform action (typically err) and return false
#define Require(condition, action_if_not) { \
if (!(condition)) { \
action_if_not; \
return false; \
} \
}
// If 'condition' is untrue, perform action (typically error) and return void
#define Require2(condition, action_if_not) { \
if (!(condition)) { \
action_if_not; \
return; \
} \
}
#define ShowStr(x) { \
gr_textput ((x)); \
}
// Variable assignment macros, which replaces existing values.
#define PUT_VAR(name, value) { \
if (!put_var(name , double(value), true)) \
fatal_err ("Can't store value of \\", name, "\\"); \
}
// Establish return code
#define RETURN_VALUE(s) { \
if (!put_syn("\\.return_value.", (s), true)) OUT_OF_MEMORY; \
}
// Copy string 'c' into string 'n', first deleting old storage for 'n'
#define COPY_STRING(n, c) { \
if(strlen((n)) < strlen((c))) { \
delete [] (n); \
(n) = new char[1 + strlen(c)]; \
if (!(n)) OUT_OF_MEMORY; \
} \
strcpy((n), (c)); \
}
#endif
|