blob: 8ebc8ceb81d1b73375a54414d8d3b1dcc0ff69a7 [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
194# if !(defined(FEAT_MBYTE) && defined(WIN3264))
195# define mch_fopen(n, p) fopen((n), (p))
196# endif
197# define mch_fstat(n, p) fstat((n), (p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000198# ifdef MSWIN /* has it's own mch_stat() function */
199# define mch_stat(n, p) vim_stat((n), (p))
200# else
201# ifdef STAT_IGNORES_SLASH
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100202# define mch_stat(n, p) vim_stat((n), (p))
Bram Moolenaar071d4272004-06-13 20:20:40 +0000203# else
204# define mch_stat(n, p) stat((n), (p))
205# endif
206# endif
207#endif
208
Bram Moolenaar269ec652004-07-29 08:43:53 +0000209#ifdef HAVE_LSTAT
210# define mch_lstat(n, p) lstat((n), (p))
211#else
212# define mch_lstat(n, p) mch_stat((n), (p))
213#endif
214
Bram Moolenaar071d4272004-06-13 20:20:40 +0000215#ifdef MACOS_CLASSIC
216/* MacOS classic doesn't support perm but MacOS X does. */
217# define mch_open(n, m, p) open((n), (m))
218#else
219# ifdef VMS
220/*
221 * It is possible to force some record format with:
222 * # 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 +0000223 * but it is not recommended, because it can destroy indexes etc.
Bram Moolenaar071d4272004-06-13 20:20:40 +0000224 */
225# define mch_open(n, m, p) open(vms_fixfilename(n), (m), (p))
226# else
227# if !(defined(FEAT_MBYTE) && defined(WIN3264))
228# define mch_open(n, m, p) open((n), (m), (p))
229# endif
230# endif
231#endif
232
233/* mch_open_rw(): invoke mch_open() with third argument for user R/W. */
234#if defined(UNIX) || defined(VMS) /* open in rw------- mode */
235# define mch_open_rw(n, f) mch_open((n), (f), (mode_t)0600)
236#else
Bram Moolenaar48e330a2016-02-23 14:53:34 +0100237# if defined(MSWIN) /* open read/write */
Bram Moolenaar071d4272004-06-13 20:20:40 +0000238# define mch_open_rw(n, f) mch_open((n), (f), S_IREAD | S_IWRITE)
239# else
240# define mch_open_rw(n, f) mch_open((n), (f), 0)
241# endif
242#endif
243
Bram Moolenaar071d4272004-06-13 20:20:40 +0000244#ifdef STARTUPTIME
Bram Moolenaar3f269672009-11-03 11:11:11 +0000245# define TIME_MSG(s) { if (time_fd != NULL) time_msg(s, NULL); }
Bram Moolenaar071d4272004-06-13 20:20:40 +0000246#else
247# define TIME_MSG(s)
248#endif
249
250#ifdef FEAT_VREPLACE
251# define REPLACE_NORMAL(s) (((s) & REPLACE_FLAG) && !((s) & VREPLACE_FLAG))
252#else
253# define REPLACE_NORMAL(s) ((s) & REPLACE_FLAG)
254#endif
255
256#ifdef FEAT_ARABIC
257# define UTF_COMPOSINGLIKE(p1, p2) utf_composinglike((p1), (p2))
258#else
259# define UTF_COMPOSINGLIKE(p1, p2) utf_iscomposing(utf_ptr2char(p2))
260#endif
261
262#ifdef FEAT_RIGHTLEFT
263 /* Whether to draw the vertical bar on the right side of the cell. */
264# define CURSOR_BAR_RIGHT (curwin->w_p_rl && (!(State & CMDLINE) || cmdmsg_rl))
265#endif
Bram Moolenaar592e0a22004-07-03 16:05:59 +0000266
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000267/*
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100268 * MB_PTR_ADV(): advance a pointer to the next character, taking care of
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000269 * multi-byte characters if needed.
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100270 * MB_PTR_BACK(): backup a pointer to the previous character, taking care of
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000271 * multi-byte characters if needed.
Bram Moolenaarfd371682005-01-14 21:42:54 +0000272 * MB_COPY_CHAR(f, t): copy one char from "f" to "t" and advance the pointers.
Bram Moolenaar78984f52005-08-01 07:19:10 +0000273 * PTR2CHAR(): get character from pointer.
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000274 */
275#ifdef FEAT_MBYTE
Bram Moolenaar94c465c2012-07-19 17:18:26 +0200276/* Get the length of the character p points to */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100277# define MB_PTR2LEN(p) (has_mbyte ? (*mb_ptr2len)(p) : 1)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000278/* Advance multi-byte pointer, skip over composing chars. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100279# define MB_PTR_ADV(p) p += has_mbyte ? (*mb_ptr2len)(p) : 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000280/* Advance multi-byte pointer, do not skip over composing chars. */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100281# define MB_CPTR_ADV(p) p += enc_utf8 ? utf_ptr2len(p) : has_mbyte ? (*mb_ptr2len)(p) : 1
Bram Moolenaar24dc2302014-05-13 20:19:58 +0200282/* Backup multi-byte pointer. Only use with "p" > "s" ! */
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100283# define MB_PTR_BACK(s, p) p -= has_mbyte ? ((*mb_head_off)(s, p - 1) + 1) : 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000284/* get length of multi-byte char, not including composing chars */
Bram Moolenaard3c907b2016-08-17 21:32:09 +0200285# define MB_CPTR2LEN(p) (enc_utf8 ? utf_ptr2len(p) : (*mb_ptr2len)(p))
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000286
Bram Moolenaarfd371682005-01-14 21:42:54 +0000287# define MB_COPY_CHAR(f, t) if (has_mbyte) mb_copy_char(&f, &t); else *t++ = *f++
Bram Moolenaar2c4278f2009-05-17 11:33:22 +0000288# define MB_CHARLEN(p) (has_mbyte ? mb_charlen(p) : (int)STRLEN(p))
Bram Moolenaar473de612013-06-08 18:19:48 +0200289# define MB_CHAR2LEN(c) (has_mbyte ? mb_char2len(c) : 1)
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000290# define PTR2CHAR(p) (has_mbyte ? mb_ptr2char(p) : (int)*(p))
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000291#else
Bram Moolenaar94c465c2012-07-19 17:18:26 +0200292# define MB_PTR2LEN(p) 1
Bram Moolenaard3c907b2016-08-17 21:32:09 +0200293# define MB_CPTR2LEN(p) 1
Bram Moolenaar91acfff2017-03-12 19:22:36 +0100294# define MB_PTR_ADV(p) ++p
295# define MB_CPTR_ADV(p) ++p
296# define MB_PTR_BACK(s, p) --p
Bram Moolenaar78984f52005-08-01 07:19:10 +0000297# define MB_COPY_CHAR(f, t) *t++ = *f++
298# define MB_CHARLEN(p) STRLEN(p)
Bram Moolenaar473de612013-06-08 18:19:48 +0200299# define MB_CHAR2LEN(c) 1
Bram Moolenaar0fa313a2005-08-10 21:07:57 +0000300# define PTR2CHAR(p) ((int)*(p))
Bram Moolenaar1cd871b2004-12-19 22:46:22 +0000301#endif
Bram Moolenaar498efdb2006-09-05 14:31:54 +0000302
303#ifdef FEAT_AUTOCHDIR
304# define DO_AUTOCHDIR if (p_acd) do_autochdir();
305#else
306# define DO_AUTOCHDIR
307#endif
Bram Moolenaar3368ea22010-09-21 16:56:35 +0200308
309#if defined(FEAT_SCROLLBIND) && defined(FEAT_CURSORBIND)
310# define RESET_BINDING(wp) (wp)->w_p_scb = FALSE; (wp)->w_p_crb = FALSE
311#else
312# if defined(FEAT_SCROLLBIND)
313# define RESET_BINDING(wp) (wp)->w_p_scb = FALSE
314# else
315# if defined(FEAT_CURSORBIND)
316# define RESET_BINDING(wp) (wp)->w_p_crb = FALSE
317# else
318# define RESET_BINDING(wp)
319# endif
320# endif
321#endif
Bram Moolenaar43335ea2015-09-09 20:59:37 +0200322
323#ifdef FEAT_DIFF
324# define PLINES_NOFILL(x) plines_nofill(x)
325#else
326# define PLINES_NOFILL(x) plines(x)
327#endif
Bram Moolenaar93c88e02015-09-15 14:12:05 +0200328
Bram Moolenaar509ce2a2016-03-11 22:52:15 +0100329#if defined(FEAT_JOB_CHANNEL) || defined(FEAT_CLIENTSERVER)
Bram Moolenaar93c88e02015-09-15 14:12:05 +0200330# define MESSAGE_QUEUE
331#endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100332
333#if defined(FEAT_EVAL) && defined(FEAT_FLOAT)
334# include <float.h>
335# if defined(HAVE_MATH_H)
336 /* for isnan() and isinf() */
337# include <math.h>
338# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100339# ifdef USING_FLOAT_STUFF
340# if defined(WIN32)
341# ifndef isnan
342# define isnan(x) _isnan(x)
Bram Moolenaar0c171712016-03-04 22:57:20 +0100343 static __inline int isinf(double x) { return !_finite(x) && !_isnan(x); }
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100344# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100345# else
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100346# ifndef HAVE_ISNAN
347 static inline int isnan(double x) { return x != x; }
348# endif
349# ifndef HAVE_ISINF
350 static inline int isinf(double x) { return !isnan(x) && isnan(x - x); }
351# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100352# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100353# if !defined(INFINITY)
354# if defined(DBL_MAX)
Bram Moolenaar98500fd2016-11-06 14:17:16 +0100355# ifdef VMS
356# define INFINITY DBL_MAX
357# else
358# define INFINITY (DBL_MAX+DBL_MAX)
359# endif
Bram Moolenaarfefecb02016-02-27 21:27:20 +0100360# else
361# define INFINITY (1.0 / 0.0)
362# endif
363# endif
364# if !defined(NAN)
365# define NAN (INFINITY-INFINITY)
366# endif
Bram Moolenaar136f29a2016-02-27 20:14:15 +0100367# endif
368#endif
Bram Moolenaar84026842016-07-17 20:37:43 +0200369
370/*
371 * In a hashtab item "hi_key" points to "di_key" in a dictitem.
372 * This avoids adding a pointer to the hashtab item.
373 * DI2HIKEY() converts a dictitem pointer to a hashitem key pointer.
374 * HIKEY2DI() converts a hashitem key pointer to a dictitem pointer.
375 * HI2DI() converts a hashitem pointer to a dictitem pointer.
376 */
377# define DI2HIKEY(di) ((di)->di_key)
378# define HIKEY2DI(p) ((dictitem_T *)(p - offsetof(dictitem_T, di_key)))
379# define HI2DI(hi) HIKEY2DI((hi)->hi_key)