blob: 97e7e832239e198b427292b6cd5a1e629071d466 [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 Moolenaarb5aedf32017-03-12 18:23:53 +010049 * LINEEMPTY() - return TRUE if the line is empty
Bram Moolenaar071d4272004-06-13 20:20:40 +000050 */
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010051#define LINEEMPTY(p) (*ml_get(p) == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000052
53/*
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010054 * BUFEMPTY() - return TRUE if the current buffer is empty
Bram Moolenaar071d4272004-06-13 20:20:40 +000055 */
Bram Moolenaarb5aedf32017-03-12 18:23:53 +010056#define BUFEMPTY() (curbuf->b_ml.ml_line_count == 1 && *ml_get((linenr_T)1) == NUL)
Bram Moolenaar071d4272004-06-13 20:20:40 +000057
58/*
59 * toupper() and tolower() that use the current locale.
Bram Moolenaardeefb632007-08-15 18:41:34 +000060 * On some systems toupper()/tolower() only work on lower/uppercase
61 * characters, first use islower() or isupper() then.
Bram Moolenaar071d4272004-06-13 20:20:40 +000062 * Careful: Only call TOUPPER_LOC() and TOLOWER_LOC() with a character in the
63 * range 0 - 255. toupper()/tolower() on some systems can't handle others.
Bram Moolenaardeefb632007-08-15 18:41:34 +000064 * Note: It is often better to use MB_TOLOWER() and MB_TOUPPER(), because many
65 * toupper() and tolower() implementations only work for ASCII.
Bram Moolenaar071d4272004-06-13 20:20:40 +000066 */
67#ifdef MSWIN
68# define TOUPPER_LOC(c) toupper_tab[(c) & 255]
69# define TOLOWER_LOC(c) tolower_tab[(c) & 255]
70#else
71# ifdef BROKEN_TOUPPER
72# define TOUPPER_LOC(c) (islower(c) ? toupper(c) : (c))
73# define TOLOWER_LOC(c) (isupper(c) ? tolower(c) : (c))
74# else
75# define TOUPPER_LOC toupper
76# define TOLOWER_LOC tolower
77# endif
78#endif
79
80/* toupper() and tolower() for ASCII only and ignore the current locale. */
81#ifdef EBCDIC
82# define TOUPPER_ASC(c) (islower(c) ? toupper(c) : (c))
83# define TOLOWER_ASC(c) (isupper(c) ? tolower(c) : (c))
84#else
85# define TOUPPER_ASC(c) (((c) < 'a' || (c) > 'z') ? (c) : (c) - ('a' - 'A'))
86# define TOLOWER_ASC(c) (((c) < 'A' || (c) > 'Z') ? (c) : (c) + ('a' - 'A'))
87#endif
88
89/*
90 * MB_ISLOWER() and MB_ISUPPER() are to be used on multi-byte characters. But
Bram Moolenaar78622822005-08-23 21:00:13 +000091 * don't use them for negative values!
Bram Moolenaar071d4272004-06-13 20:20:40 +000092 */
93#ifdef FEAT_MBYTE
Bram Moolenaar78622822005-08-23 21:00:13 +000094# define MB_ISLOWER(c) vim_islower(c)
95# define MB_ISUPPER(c) vim_isupper(c)
96# define MB_TOLOWER(c) vim_tolower(c)
97# define MB_TOUPPER(c) vim_toupper(c)
Bram Moolenaar071d4272004-06-13 20:20:40 +000098#else
99# define MB_ISLOWER(c) islower(c)
100# define MB_ISUPPER(c) isupper(c)
101# define MB_TOLOWER(c) TOLOWER_LOC(c)
102# define MB_TOUPPER(c) TOUPPER_LOC(c)
103#endif
104
Bram Moolenaar2d473ab2013-06-12 17:12:24 +0200105/* Use our own isdigit() replacement, because on MS-Windows isdigit() returns
106 * non-zero for superscript 1. Also avoids that isdigit() crashes for numbers
107 * below 0 and above 255. */
108#define VIM_ISDIGIT(c) ((unsigned)(c) - '0' < 10)
109
Bram Moolenaar071d4272004-06-13 20:20:40 +0000110/* Like isalpha() but reject non-ASCII characters. Can't be used with a
111 * special key (negative value). */
112#ifdef EBCDIC
113# define ASCII_ISALPHA(c) isalpha(c)
114# define ASCII_ISALNUM(c) isalnum(c)
115# define ASCII_ISLOWER(c) islower(c)
116# define ASCII_ISUPPER(c) isupper(c)
117#else
Bram Moolenaar0ea4a6b2013-06-12 14:10:26 +0200118# define ASCII_ISLOWER(c) ((unsigned)(c) - 'a' < 26)
119# define ASCII_ISUPPER(c) ((unsigned)(c) - 'A' < 26)
Bram Moolenaar2d473ab2013-06-12 17:12:24 +0200120# define ASCII_ISALPHA(c) (ASCII_ISUPPER(c) || ASCII_ISLOWER(c))
121# define ASCII_ISALNUM(c) (ASCII_ISALPHA(c) || VIM_ISDIGIT(c))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000122#endif
123
Bram Moolenaar42a45122015-07-10 17:56:23 +0200124/* Returns empty string if it is NULL. */
Bram Moolenaar669cac02016-02-25 15:25:03 +0100125#define EMPTY_IF_NULL(x) ((x) ? (x) : (char_u *)"")
Bram Moolenaar42a45122015-07-10 17:56:23 +0200126
Bram Moolenaar071d4272004-06-13 20:20:40 +0000127#ifdef FEAT_LANGMAP
128/*
129 * Adjust chars in a language according to 'langmap' option.
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000130 * NOTE that there is no noticeable overhead if 'langmap' is not set.
131 * When set the overhead for characters < 256 is small.
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100132 * Don't apply 'langmap' if the character comes from the Stuff buffer or from
133 * a mapping and the langnoremap option was set.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000134 * The do-while is just to ignore a ';' after the macro.
135 */
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000136# ifdef FEAT_MBYTE
137# define LANGMAP_ADJUST(c, condition) \
138 do { \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100139 if (*p_langmap \
140 && (condition) \
Bram Moolenaar920694c2016-08-21 17:45:02 +0200141 && (p_lrm || (!p_lrm && KeyTyped)) \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100142 && !KeyStuffed \
143 && (c) >= 0) \
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000144 { \
145 if ((c) < 256) \
146 c = langmap_mapchar[c]; \
147 else \
148 c = langmap_adjust_mb(c); \
149 } \
Bram Moolenaar071d4272004-06-13 20:20:40 +0000150 } while (0)
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000151# else
152# define LANGMAP_ADJUST(c, condition) \
153 do { \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100154 if (*p_langmap \
155 && (condition) \
Bram Moolenaar920694c2016-08-21 17:45:02 +0200156 && (p_lrm || (!p_lrm && KeyTyped)) \
Bram Moolenaar4391cf92014-11-05 17:44:52 +0100157 && !KeyStuffed \
158 && (c) >= 0 && (c) < 256) \
Bram Moolenaar55d5c032010-07-17 23:52:29 +0200159 c = langmap_mapchar[c]; \
Bram Moolenaar28e8d272009-02-21 19:28:48 +0000160 } while (0)
161# endif
162#else
163# define LANGMAP_ADJUST(c, condition) /* nop */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000164#endif
165
166/*
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100167 * VIM_ISBREAK() is used very often if 'linebreak' is set, use a macro to make
168 * it work fast. Only works for single byte characters!
Bram Moolenaar071d4272004-06-13 20:20:40 +0000169 */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100170#define VIM_ISBREAK(c) ((c) < 256 && breakat_flags[(char_u)(c)])
Bram Moolenaar071d4272004-06-13 20:20:40 +0000171
172/*
173 * On VMS file names are different and require a translation.
174 * On the Mac open() has only two arguments.
175 */
176#ifdef VMS
177# define mch_access(n, p) access(vms_fixfilename(n), (p))
178 /* see mch_open() comment */
179# define mch_fopen(n, p) fopen(vms_fixfilename(n), (p))
180# define mch_fstat(n, p) fstat(vms_fixfilename(n), (p))
181 /* VMS does not have lstat() */
182# define mch_stat(n, p) stat(vms_fixfilename(n), (p))
Bram Moolenaarde5e2c22016-11-04 20:35:31 +0100183# define mch_rmdir(n) rmdir(vms_fixfilename(n))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000184#else
185# ifndef WIN32
186# define mch_access(n, p) access((n), (p))
187# endif
188# if !(defined(FEAT_MBYTE) && defined(WIN3264))
189# define mch_fopen(n, p) fopen((n), (p))
190# endif
191# define mch_fstat(n, p) fstat((n), (p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000192# ifdef MSWIN /* has it's own mch_stat() function */
193# define mch_stat(n, p) vim_stat((n), (p))
194# else
195# ifdef STAT_IGNORES_SLASH
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100196# define mch_stat(n, p) vim_stat((n), (p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000197# else
198# define mch_stat(n, p) stat((n), (p))
199# endif
200# endif
201#endif
202
Bram Moolenaar269ec652004-07-29 08:43:53 +0000203#ifdef HAVE_LSTAT
204# define mch_lstat(n, p) lstat((n), (p))
205#else
206# define mch_lstat(n, p) mch_stat((n), (p))
207#endif
208
Bram Moolenaar071d4272004-06-13 20:20:40 +0000209#ifdef MACOS_CLASSIC
210/* MacOS classic doesn't support perm but MacOS X does. */
211# define mch_open(n, m, p) open((n), (m))
212#else
213# ifdef VMS
214/*
215 * It is possible to force some record format with:
216 * # 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 +0000217 * but it is not recommended, because it can destroy indexes etc.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000218 */
219# define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p))
220# else
221# if !(defined(FEAT_MBYTE) && defined(WIN3264))
222# define mch_open(n, m, p) open((n), (m), (p))
223# endif
224# endif
225#endif
226
227/* mch_open_rw(): invoke mch_open() with third argument for user R/W. */
228#if defined(UNIX) || defined(VMS) /* open in rw------- mode */
229# define mch_open_rw(n, f) mch_open((n), (f), (mode_t)0600)
230#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100231# if defined(MSWIN) /* open read/write */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000232# define mch_open_rw(n, f) mch_open((n), (f), S_IREAD | S_IWRITE)
233# else
234# define mch_open_rw(n, f) mch_open((n), (f), 0)
235# endif
236#endif
237
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238#ifdef STARTUPTIME
Bram Moolenaar3f269672009-11-03 11:11:11 +0000239# define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000240#else
241# define TIME_MSG(s)
242#endif
243
244#ifdef FEAT_VREPLACE
245# define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))
246#else
247# define REPLACE_NORMAL(s) ((s) & REPLACE_FLAG)
248#endif
249
250#ifdef FEAT_ARABIC
251# define UTF_COMPOSINGLIKE(p1, p2) utf_composinglike((p1), (p2))
252#else
253# define UTF_COMPOSINGLIKE(p1, p2) utf_iscomposing(utf_ptr2char(p2))
254#endif
255
256#ifdef FEAT_RIGHTLEFT
257 /* Whether to draw the vertical bar on the right side of the cell. */
258# define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl))
259#endif
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000260
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000261/*
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100262 * MB_PTR_ADV(): advance a pointer to the next character, taking care of
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000263 * multi-byte characters if needed.
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100264 * MB_PTR_BACK(): backup a pointer to the previous character, taking care of
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000265 * multi-byte characters if needed.
Bram Moolenaarfd371682005-01-14 21:42:54 +0000266 * MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers.
Bram Moolenaar78984f52005-08-01 07:19:10 +0000267 * PTR2CHAR(): get character from pointer.
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000268 */
269#ifdef FEAT_MBYTE
Bram Moolenaar94c465c2012-07-19 17:18:26 +0200270/* Get the length of the character p points to */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100271# define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000272/* Advance multi-byte pointer, skip over composing chars. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100273# define MB_PTR_ADV(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000274/* Advance multi-byte pointer, do not skip over composing chars. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100275# define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1
Bram Moolenaar24dc2302014-05-13 20:19:58 +0200276/* Backup multi-byte pointer. Only use with "p" > "s" ! */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100277# define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000278/* get length of multi-byte char, not including composing chars */
Bram Moolenaard3c907b2016-08-17 21:32:09 +0200279# define MB_CPTR2LEN(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p))
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000280
Bram Moolenaarfd371682005-01-14 21:42:54 +0000281# define MB_COPY_CHAR(f, t) if (has_mbyte) mb_copy_char(&f, &t); else *t++ = *f++
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000282# define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : (int)STRLEN(p))
Bram Moolenaar473de612013-06-08 18:19:48 +0200283# define MB_CHAR2LEN(c) (has_mbyte ? mb_char2len(c) : 1)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000284# define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p))
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000285#else
Bram Moolenaar94c465c2012-07-19 17:18:26 +0200286# define MB_PTR2LEN(p) 1
Bram Moolenaard3c907b2016-08-17 21:32:09 +0200287# define MB_CPTR2LEN(p) 1
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100288# define MB_PTR_ADV(p) ++p
289# define MB_CPTR_ADV(p) ++p
290# define MB_PTR_BACK(s, p) --p
Bram Moolenaar78984f52005-08-01 07:19:10 +0000291# define MB_COPY_CHAR(f, t) *t++ = *f++
292# define MB_CHARLEN(p) STRLEN(p)
Bram Moolenaar473de612013-06-08 18:19:48 +0200293# define MB_CHAR2LEN(c) 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000294# define PTR2CHAR(p) ((int)*(p))
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000295#endif
Bram Moolenaar498efdb2006-09-05 14:31:54 +0000296
297#ifdef FEAT_AUTOCHDIR
298# define DO_AUTOCHDIR if (p_acd) do_autochdir();
299#else
300# define DO_AUTOCHDIR
301#endif
Bram Moolenaar3368ea22010-09-21 16:56:35 +0200302
303#if defined(FEAT_SCROLLBIND) && defined(FEAT_CURSORBIND)
304# define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE
305#else
306# if defined(FEAT_SCROLLBIND)
307# define RESET_BINDING(wp) (wp)->w_p_scb = FALSE
308# else
309# if defined(FEAT_CURSORBIND)
310# define RESET_BINDING(wp) (wp)->w_p_crb = FALSE
311# else
312# define RESET_BINDING(wp)
313# endif
314# endif
315#endif
Bram Moolenaar43335ea2015-09-09 20:59:37 +0200316
317#ifdef FEAT_DIFF
318# define PLINES_NOFILL(x) plines_nofill(x)
319#else
320# define PLINES_NOFILL(x) plines(x)
321#endif
Bram Moolenaar93c88e02015-09-15 14:12:05 +0200322
Bram Moolenaar509ce2a2016-03-11 22:52:15 +0100323#if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER)
Bram Moolenaar93c88e02015-09-15 14:12:05 +0200324# define MESSAGE_QUEUE
325#endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100326
327#if defined(FEAT_EVAL) && defined(FEAT_FLOAT)
328# include <float.h>
329# if defined(HAVE_MATH_H)
330 /* for isnan() and isinf() */
331# include <math.h>
332# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100333# ifdef USING_FLOAT_STUFF
334# if defined(WIN32)
335# ifndef isnan
336# define isnan(x) _isnan(x)
Bram Moolenaar0c171712016-03-04 22:57:20 +0100337 static __inline int isinf(double x) { return !_finite(x) && !_isnan(x); }
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100338# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100339# else
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100340# ifndef HAVE_ISNAN
341 static inline int isnan(double x) { return x != x; }
342# endif
343# ifndef HAVE_ISINF
344 static inline int isinf(double x) { return !isnan(x) && isnan(x - x); }
345# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100346# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100347# if !defined(INFINITY)
348# if defined(DBL_MAX)
Bram Moolenaar98500fd2016-11-06 14:17:16 +0100349# ifdef VMS
350# define INFINITY DBL_MAX
351# else
352# define INFINITY (DBL_MAX+DBL_MAX)
353# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100354# else
355# define INFINITY (1.0 / 0.0)
356# endif
357# endif
358# if !defined(NAN)
359# define NAN (INFINITY-INFINITY)
360# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100361# endif
362#endif
Bram Moolenaar84026842016-07-17 20:37:43 +0200363
364/*
365 * In a hashtab item "hi_key" points to "di_key" in a dictitem.
366 * This avoids adding a pointer to the hashtab item.
367 * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
368 * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer.
369 * HI2DI() converts a hashitem pointer to a dictitem pointer.
370 */
371# define DI2HIKEY(di) ((di)->di_key)
372# define HIKEY2DI(p) ((dictitem_T *)(p - offsetof(dictitem_T, di_key)))
373# define HI2DI(hi) HIKEY2DI((hi)->hi_key)