blob: 6e4b813c0a715fe242d5accf1650e9849ab38a11 [file] [log] [blame]
Bram Moolenaaredf3f972016-08-29 22:49:24 +02001/* vi:set ts=8 sts=4 sw=4 noet:
Bram Moolenaar071d4272004-06-13 20:20:40 +00002 *
3 * VIM - Vi IMproved by Bram Moolenaar
4 *
5 * Do ":help uganda" in Vim to read copying and usage conditions.
6 * Do ":help credits" in Vim to see a list of people who contributed.
7 */
8
9/*
10 * macros.h: macro definitions for often used code
Bram Moolenaar91acfff2017-03-12 19:22:36 +010011 *
12 * Macros should be ALL_CAPS. An exception is for where a function is
13 * replaced and an argument is not used more than once.
Bram Moolenaar071d4272004-06-13 20:20:40 +000014 */
15
16/*
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010017 * PCHAR(lp, c) - put character 'c' at position 'lp'
Bram Moolenaar071d4272004-06-13 20:20:40 +000018 */
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010019#define PCHAR(lp, c) (*(ml_get_buf(curbuf, (lp).lnum, TRUE) + (lp).col) = (c))
Bram Moolenaar071d4272004-06-13 20:20:40 +000020
21/*
22 * Position comparisons
23 */
24#ifdef FEAT_VIRTUALEDIT
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010025# define LT_POS(a, b) (((a).lnum != (b).lnum) \
Bram Moolenaar071d4272004-06-13 20:20:40 +000026 ? (a).lnum < (b).lnum \
27 : (a).col != (b).col \
28 ? (a).col < (b).col \
29 : (a).coladd < (b).coladd)
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010030# define LT_POSP(a, b) (((a)->lnum != (b)->lnum) \
Bram Moolenaar071d4272004-06-13 20:20:40 +000031 ? (a)->lnum < (b)->lnum \
32 : (a)->col != (b)->col \
33 ? (a)->col < (b)->col \
34 : (a)->coladd < (b)->coladd)
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010035# define EQUAL_POS(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col) && ((a).coladd == (b).coladd))
36# define CLEAR_POS(a) {(a)->lnum = 0; (a)->col = 0; (a)->coladd = 0;}
Bram Moolenaar071d4272004-06-13 20:20:40 +000037#else
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010038# define LT_POS(a, b) (((a).lnum != (b).lnum) \
Bram Moolenaar071d4272004-06-13 20:20:40 +000039 ? ((a).lnum < (b).lnum) : ((a).col < (b).col))
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010040# define LT_POSP(a, b) (((a)->lnum != (b)->lnum) \
Bram Moolenaar071d4272004-06-13 20:20:40 +000041 ? ((a)->lnum < (b)->lnum) : ((a)->col < (b)->col))
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010042# define EQUAL_POS(a, b) (((a).lnum == (b).lnum) && ((a).col == (b).col))
43# define CLEAR_POS(a) {(a)->lnum = 0; (a)->col = 0;}
Bram Moolenaar071d4272004-06-13 20:20:40 +000044#endif
45
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010046#define LTOREQ_POS(a, b) (LT_POS(a, b) || EQUAL_POS(a, b))
Bram Moolenaar071d4272004-06-13 20:20:40 +000047
48/*
Bram Moolenaar1c465442017-03-12 20:10:05 +010049 * VIM_ISWHITE() is used for "^" and the like. It differs from isspace()
50 * because it doesn't include <CR> and <LF> and the like.
51 */
52#define VIM_ISWHITE(x) ((x) == ' ' || (x) == '\t')
53
54/*
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010055 * LINEEMPTY() - return TRUE if the line is empty
Bram Moolenaar071d4272004-06-13 20:20:40 +000056 */
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010057#define LINEEMPTY(p) (*ml_get(p) == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000058
59/*
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010060 * BUFEMPTY() - return TRUE if the current buffer is empty
Bram Moolenaar071d4272004-06-13 20:20:40 +000061 */
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010062#define BUFEMPTY() (curbuf->b_ml.ml_line_count == 1 && *ml_get((linenr_T)1) == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000063
64/*
65 * toupper() and tolower() that use the current locale.
Bram Moolenaardeefb632007-08-15 18:41:34 +000066 * On some systems toupper()/tolower() only work on lower/uppercase
67 * characters, first use islower() or isupper() then.
Bram Moolenaar071d4272004-06-13 20:20:40 +000068 * Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the
69 * range 0 - 255. toupper()/tolower() on some systems can't handle others.
Bram Moolenaardeefb632007-08-15 18:41:34 +000070 * Note: It is often better to use MB_TOLOWER() and MB_TOUPPER(), because many
71 * toupper() and tolower() implementations only work for ASCII.
Bram Moolenaar071d4272004-06-13 20:20:40 +000072 */
73#ifdef MSWIN
74# define TOUPPER_LOC(c) toupper_tab[(c) & 255]
75# define TOLOWER_LOC(c) tolower_tab[(c) & 255]
76#else
77# ifdef BROKEN_TOUPPER
78# define TOUPPER_LOC(c) (islower(c) ? toupper(c) : (c))
79# define TOLOWER_LOC(c) (isupper(c) ? tolower(c) : (c))
80# else
81# define TOUPPER_LOC toupper
82# define TOLOWER_LOC tolower
83# endif
84#endif
85
86/* toupper() and tolower() for ASCII only and ignore the current locale. */
87#ifdef EBCDIC
88# define TOUPPER_ASC(c) (islower(c) ? toupper(c) : (c))
89# define TOLOWER_ASC(c) (isupper(c) ? tolower(c) : (c))
90#else
91# define TOUPPER_ASC(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) - ('a' - 'A'))
92# define TOLOWER_ASC(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) + ('a' - 'A'))
93#endif
94
95/*
96 * MB_ISLOWER() and MB_ISUPPER() are to be used on multi-byte characters. But
Bram Moolenaar78622822005-08-23 21:00:13 +000097 * don't use them for negative values!
Bram Moolenaar071d4272004-06-13 20:20:40 +000098 */
99#ifdef FEAT_MBYTE
Bram Moolenaar78622822005-08-23 21:00:13 +0000100# define MB_ISLOWER(c) vim_islower(c)
101# define MB_ISUPPER(c) vim_isupper(c)
102# define MB_TOLOWER(c) vim_tolower(c)
103# define MB_TOUPPER(c) vim_toupper(c)
Bram Moolenaar071d4272004-06-13 20:20:40 +0000104#else
105# define MB_ISLOWER(c) islower(c)
106# define MB_ISUPPER(c) isupper(c)
107# define MB_TOLOWER(c) TOLOWER_LOC(c)
108# define MB_TOUPPER(c) TOUPPER_LOC(c)
109#endif
110
Bram Moolenaar2d473ab2013-06-12 17:12:24 +0200111/* Use our own isdigit() replacement, because on MS-Windows isdigit() returns
112 * non-zero for superscript 1. Also avoids that isdigit() crashes for numbers
113 * below 0 and above 255. */
114#define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10)
115
Bram Moolenaar071d4272004-06-13 20:20:40 +0000116/* Like isalpha() but reject non-ASCII characters. Can't be used with a
117 * special key (negative value). */
118#ifdef EBCDIC
119# define ASCII_ISALPHA(c) isalpha(c)
120# define ASCII_ISALNUM(c) isalnum(c)
121# define ASCII_ISLOWER(c) islower(c)
122# define ASCII_ISUPPER(c) isupper(c)
123#else
Bram Moolenaar0ea4a6b2013-06-12 14:10:26 +0200124# define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26)
125# define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26)
Bram Moolenaar2d473ab2013-06-12 17:12:24 +0200126# define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c))
127# define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000128#endif
129
Bram Moolenaar42a45122015-07-10 17:56:23 +0200130/* Returns empty string if it is NULL. */
Bram Moolenaar669cac02016-02-25 15:25:03 +0100131#define EMPTY_IF_NULL(x) ((x) ? (x) : (char_u *)"")
Bram Moolenaar42a45122015-07-10 17:56:23 +0200132
Bram Moolenaar071d4272004-06-13 20:20:40 +0000133#ifdef FEAT_LANGMAP
134/*
135 * Adjust chars in a language according to 'langmap' option.
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000136 * NOTE that there is no noticeable overhead if 'langmap' is not set.
137 * When set the overhead for characters < 256 is small.
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100138 * Don't apply 'langmap' if the character comes from the Stuff buffer or from
139 * a mapping and the langnoremap option was set.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000140 * The do-while is just to ignore a ';' after the macro.
141 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000142# ifdef FEAT_MBYTE
143# define LANGMAP_ADJUST(c, condition) \
144 do { \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100145 if (*p_langmap \
146 && (condition) \
Bram Moolenaar920694c2016-08-21 17:45:02 +0200147 && (p_lrm || (!p_lrm && KeyTyped)) \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100148 && !KeyStuffed \
149 && (c) >= 0) \
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000150 { \
151 if ((c) < 256) \
152 c = langmap_mapchar[c]; \
153 else \
154 c = langmap_adjust_mb(c); \
155 } \
Bram Moolenaar071d4272004-06-13 20:20:40 +0000156 } while (0)
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000157# else
158# define LANGMAP_ADJUST(c, condition) \
159 do { \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100160 if (*p_langmap \
161 && (condition) \
Bram Moolenaar920694c2016-08-21 17:45:02 +0200162 && (p_lrm || (!p_lrm && KeyTyped)) \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100163 && !KeyStuffed \
164 && (c) >= 0 && (c) < 256) \
Bram Moolenaar55d5c032010-07-17 23:52:29 +0200165 c = langmap_mapchar[c]; \
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000166 } while (0)
167# endif
168#else
169# define LANGMAP_ADJUST(c, condition) /* nop */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000170#endif
171
172/*
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100173 * VIM_ISBREAK() is used very often if 'linebreak' is set, use a macro to make
174 * it work fast. Only works for single byte characters!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000175 */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100176#define VIM_ISBREAK(c) ((c) < 256 && breakat_flags[(char_u)(c)])
Bram Moolenaar071d4272004-06-13 20:20:40 +0000177
178/*
179 * On VMS file names are different and require a translation.
180 * On the Mac open() has only two arguments.
181 */
182#ifdef VMS
183# define mch_access(n, p) access(vms_fixfilename(n), (p))
184 /* see mch_open() comment */
185# define mch_fopen(n, p) fopen(vms_fixfilename(n), (p))
186# define mch_fstat(n, p) fstat(vms_fixfilename(n), (p))
187 /* VMS does not have lstat() */
188# define mch_stat(n, p) stat(vms_fixfilename(n), (p))
Bram Moolenaarde5e2c22016-11-04 20:35:31 +0100189# define mch_rmdir(n) rmdir(vms_fixfilename(n))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000190#else
191# ifndef WIN32
192# define mch_access(n, p) access((n), (p))
193# endif
Bram Moolenaar071d4272004-06-13 20:20:40 +0000194# define mch_fstat(n, p) fstat((n), (p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000195# ifdef MSWIN /* has it's own mch_stat() function */
196# define mch_stat(n, p) vim_stat((n), (p))
197# else
198# ifdef STAT_IGNORES_SLASH
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100199# define mch_stat(n, p) vim_stat((n), (p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000200# else
201# define mch_stat(n, p) stat((n), (p))
202# endif
203# endif
204#endif
205
Bram Moolenaar269ec652004-07-29 08:43:53 +0000206#ifdef HAVE_LSTAT
207# define mch_lstat(n, p) lstat((n), (p))
208#else
209# define mch_lstat(n, p) mch_stat((n), (p))
210#endif
211
Bram Moolenaard0573012017-10-28 21:11:06 +0200212#ifdef VMS
Bram Moolenaar071d4272004-06-13 20:20:40 +0000213/*
214 * It is possible to force some record format with:
215 * # define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p)), "rat=cr", "rfm=stmlf", "mrs=0")
Bram Moolenaarff1d0d42007-05-10 17:24:16 +0000216 * but it is not recommended, because it can destroy indexes etc.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000217 */
Bram Moolenaard0573012017-10-28 21:11:06 +0200218# define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000219#endif
220
221/* mch_open_rw(): invoke mch_open() with third argument for user R/W. */
222#if defined(UNIX) || defined(VMS) /* open in rw------- mode */
223# define mch_open_rw(n, f) mch_open((n), (f), (mode_t)0600)
224#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100225# if defined(MSWIN) /* open read/write */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000226# define mch_open_rw(n, f) mch_open((n), (f), S_IREAD | S_IWRITE)
227# else
228# define mch_open_rw(n, f) mch_open((n), (f), 0)
229# endif
230#endif
231
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232#ifdef STARTUPTIME
Bram Moolenaar3f269672009-11-03 11:11:11 +0000233# define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000234#else
235# define TIME_MSG(s)
236#endif
237
238#ifdef FEAT_VREPLACE
239# define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))
240#else
241# define REPLACE_NORMAL(s) ((s) & REPLACE_FLAG)
242#endif
243
244#ifdef FEAT_ARABIC
245# define UTF_COMPOSINGLIKE(p1, p2) utf_composinglike((p1), (p2))
246#else
247# define UTF_COMPOSINGLIKE(p1, p2) utf_iscomposing(utf_ptr2char(p2))
248#endif
249
250#ifdef FEAT_RIGHTLEFT
251 /* Whether to draw the vertical bar on the right side of the cell. */
252# define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl))
253#endif
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000254
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000255/*
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100256 * MB_PTR_ADV(): advance a pointer to the next character, taking care of
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000257 * multi-byte characters if needed.
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100258 * MB_PTR_BACK(): backup a pointer to the previous character, taking care of
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000259 * multi-byte characters if needed.
Bram Moolenaarfd371682005-01-14 21:42:54 +0000260 * MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers.
Bram Moolenaar78984f52005-08-01 07:19:10 +0000261 * PTR2CHAR(): get character from pointer.
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000262 */
263#ifdef FEAT_MBYTE
Bram Moolenaard0573012017-10-28 21:11:06 +0200264/* Get the length of the character p points to, including composing chars */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100265# define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000266/* Advance multi-byte pointer, skip over composing chars. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100267# define MB_PTR_ADV(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000268/* Advance multi-byte pointer, do not skip over composing chars. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100269# define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1
Bram Moolenaar24dc2302014-05-13 20:19:58 +0200270/* Backup multi-byte pointer. Only use with "p" > "s" ! */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100271# define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000272/* get length of multi-byte char, not including composing chars */
Bram Moolenaard3c907b2016-08-17 21:32:09 +0200273# define MB_CPTR2LEN(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p))
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000274
Bram Moolenaarfd371682005-01-14 21:42:54 +0000275# define MB_COPY_CHAR(f, t) if (has_mbyte) mb_copy_char(&f, &t); else *t++ = *f++
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000276# define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : (int)STRLEN(p))
Bram Moolenaar473de612013-06-08 18:19:48 +0200277# define MB_CHAR2LEN(c) (has_mbyte ? mb_char2len(c) : 1)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000278# define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p))
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000279#else
Bram Moolenaar94c465c2012-07-19 17:18:26 +0200280# define MB_PTR2LEN(p) 1
Bram Moolenaard3c907b2016-08-17 21:32:09 +0200281# define MB_CPTR2LEN(p) 1
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100282# define MB_PTR_ADV(p) ++p
283# define MB_CPTR_ADV(p) ++p
284# define MB_PTR_BACK(s, p) --p
Bram Moolenaar78984f52005-08-01 07:19:10 +0000285# define MB_COPY_CHAR(f, t) *t++ = *f++
286# define MB_CHARLEN(p) STRLEN(p)
Bram Moolenaar473de612013-06-08 18:19:48 +0200287# define MB_CHAR2LEN(c) 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000288# define PTR2CHAR(p) ((int)*(p))
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000289#endif
Bram Moolenaar498efdb2006-09-05 14:31:54 +0000290
291#ifdef FEAT_AUTOCHDIR
292# define DO_AUTOCHDIR if (p_acd) do_autochdir();
293#else
294# define DO_AUTOCHDIR
295#endif
Bram Moolenaar3368ea22010-09-21 16:56:35 +0200296
297#if defined(FEAT_SCROLLBIND) && defined(FEAT_CURSORBIND)
298# define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE
299#else
300# if defined(FEAT_SCROLLBIND)
301# define RESET_BINDING(wp) (wp)->w_p_scb = FALSE
302# else
303# if defined(FEAT_CURSORBIND)
304# define RESET_BINDING(wp) (wp)->w_p_crb = FALSE
305# else
306# define RESET_BINDING(wp)
307# endif
308# endif
309#endif
Bram Moolenaar43335ea2015-09-09 20:59:37 +0200310
311#ifdef FEAT_DIFF
312# define PLINES_NOFILL(x) plines_nofill(x)
313#else
314# define PLINES_NOFILL(x) plines(x)
315#endif
Bram Moolenaar93c88e02015-09-15 14:12:05 +0200316
Bram Moolenaar509ce2a2016-03-11 22:52:15 +0100317#if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER)
Bram Moolenaar93c88e02015-09-15 14:12:05 +0200318# define MESSAGE_QUEUE
319#endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100320
321#if defined(FEAT_EVAL) && defined(FEAT_FLOAT)
322# include <float.h>
323# if defined(HAVE_MATH_H)
324 /* for isnan() and isinf() */
325# include <math.h>
326# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100327# ifdef USING_FLOAT_STUFF
328# if defined(WIN32)
329# ifndef isnan
330# define isnan(x) _isnan(x)
Bram Moolenaar0c171712016-03-04 22:57:20 +0100331 static __inline int isinf(double x) { return !_finite(x) && !_isnan(x); }
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100332# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100333# else
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100334# ifndef HAVE_ISNAN
335 static inline int isnan(double x) { return x != x; }
336# endif
337# ifndef HAVE_ISINF
338 static inline int isinf(double x) { return !isnan(x) && isnan(x - x); }
339# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100340# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100341# if !defined(INFINITY)
342# if defined(DBL_MAX)
Bram Moolenaar98500fd2016-11-06 14:17:16 +0100343# ifdef VMS
344# define INFINITY DBL_MAX
345# else
346# define INFINITY (DBL_MAX+DBL_MAX)
347# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100348# else
349# define INFINITY (1.0 / 0.0)
350# endif
351# endif
352# if !defined(NAN)
353# define NAN (INFINITY-INFINITY)
354# endif
Bram Moolenaar863e80b2017-06-04 20:30:00 +0200355# if !defined(DBL_EPSILON)
356# define DBL_EPSILON 2.2204460492503131e-16
357# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100358# endif
359#endif
Bram Moolenaar84026842016-07-17 20:37:43 +0200360
361/*
362 * In a hashtab item "hi_key" points to "di_key" in a dictitem.
363 * This avoids adding a pointer to the hashtab item.
364 * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
365 * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer.
366 * HI2DI() converts a hashitem pointer to a dictitem pointer.
367 */
Bram Moolenaara338adc2018-01-31 20:51:47 +0100368#define DI2HIKEY(di) ((di)->di_key)
369#define HIKEY2DI(p) ((dictitem_T *)(p - offsetof(dictitem_T, di_key)))
370#define HI2DI(hi) HIKEY2DI((hi)->hi_key)
371
372/*
373 * Flush control functions.
374 */
375#ifdef FEAT_GUI
376# define mch_enable_flush() gui_enable_flush()
377# define mch_disable_flush() gui_disable_flush()
378#else
379# define mch_enable_flush()
380# define mch_disable_flush()
381#endif