annotate src/xdiff/xmacros.h @ 32174:f84e5db372ea v9.0.1418

patch 9.0.1418: the included xdiff code is a bit outdated Commit: https://github.com/vim/vim/commit/5fedb8a5ab7addb584728c89e809be190de992bf Author: Yee Cheng Chin <ychin.git@gmail.com> Date: Mon Mar 20 17:30:52 2023 +0000 patch 9.0.1418: the included xdiff code is a bit outdated Problem: The included xdiff code is a bit outdated. Solution: Sync with the latest git xdiff code. (Yee Cheng Chin, closes #12181)
author Bram Moolenaar <Bram@vim.org>
date Mon, 20 Mar 2023 18:45:04 +0100
parents d5142d87f898
children 9493de63a3f6
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
14696
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
1 /*
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
2 * LibXDiff by Davide Libenzi ( File Differential Library )
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
3 * Copyright (C) 2003 Davide Libenzi
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
4 *
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
5 * This library is free software; you can redistribute it and/or
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
6 * modify it under the terms of the GNU Lesser General Public
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
7 * License as published by the Free Software Foundation; either
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
8 * version 2.1 of the License, or (at your option) any later version.
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
9 *
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
10 * This library is distributed in the hope that it will be useful,
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
13 * Lesser General Public License for more details.
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
14 *
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
15 * You should have received a copy of the GNU Lesser General Public
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
16 * License along with this library; if not, see
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
17 * <http://www.gnu.org/licenses/>.
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
18 *
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
19 * Davide Libenzi <davidel@xmailserver.org>
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
20 *
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
21 */
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
22
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
23 #if !defined(XMACROS_H)
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
24 #define XMACROS_H
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
25
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
26
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
27
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
28
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
29 #define XDL_MIN(a, b) ((a) < (b) ? (a): (b))
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
30 #define XDL_MAX(a, b) ((a) > (b) ? (a): (b))
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
31 #define XDL_ABS(v) ((v) >= 0 ? (v): -(v))
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
32 #define XDL_ISDIGIT(c) ((c) >= '0' && (c) <= '9')
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
33 #define XDL_ISSPACE(c) (isspace((unsigned char)(c)))
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
34 #define XDL_ADDBITS(v,b) ((v) + ((v) >> (b)))
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
35 #define XDL_MASKBITS(b) ((1UL << (b)) - 1)
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
36 #define XDL_HASHLONG(v,b) (XDL_ADDBITS((unsigned long)(v), b) & XDL_MASKBITS(b))
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
37 #define XDL_LE32_PUT(p, v) \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
38 do { \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
39 unsigned char *__p = (unsigned char *) (p); \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
40 *__p++ = (unsigned char) (v); \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
41 *__p++ = (unsigned char) ((v) >> 8); \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
42 *__p++ = (unsigned char) ((v) >> 16); \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
43 *__p = (unsigned char) ((v) >> 24); \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
44 } while (0)
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
45 #define XDL_LE32_GET(p, v) \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
46 do { \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
47 unsigned char const *__p = (unsigned char const *) (p); \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
48 (v) = (unsigned long) __p[0] | ((unsigned long) __p[1]) << 8 | \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
49 ((unsigned long) __p[2]) << 16 | ((unsigned long) __p[3]) << 24; \
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
50 } while (0)
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
51
32174
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
52 /* Allocate an array of nr elements, returns NULL on failure */
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
53 #define XDL_ALLOC_ARRAY(p, nr) \
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
54 ((p) = SIZE_MAX / sizeof(*(p)) >= (size_t)(nr) \
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
55 ? xdl_malloc((nr) * sizeof(*(p))) \
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
56 : NULL)
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
57
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
58 /* Allocate an array of nr zeroed out elements, returns NULL on failure */
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
59 #define XDL_CALLOC_ARRAY(p, nr) ((p) = xdl_calloc(nr, sizeof(*(p))))
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
60
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
61 /*
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
62 * Ensure array p can accommodate at least nr elements, growing the
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
63 * array and updating alloc (which is the number of allocated
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
64 * elements) as necessary. Frees p and returns -1 on failure, returns
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
65 * 0 on success
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
66 */
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
67 #define XDL_ALLOC_GROW(p, nr, alloc) \
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
68 (-!((nr) <= (alloc) || \
f84e5db372ea patch 9.0.1418: the included xdiff code is a bit outdated
Bram Moolenaar <Bram@vim.org>
parents: 25709
diff changeset
69 ((p) = xdl_alloc_grow_helper((p), (nr), &(alloc), sizeof(*(p))))))
14696
195e8b1fcbbf patch 8.1.0360: using an external diff program is slow and inflexible
Christian Brabandt <cb@256bit.org>
parents:
diff changeset
70
25709
d5142d87f898 patch 8.2.3390: included xdiff code is outdated
Bram Moolenaar <Bram@vim.org>
parents: 18802
diff changeset
71 #endif /* #if !defined(XMACROS_H) */