Show More
@@ -1,23 +1,23 b'' | |||||
1 |
#ifndef |
|
1 | #ifndef HG_BDIFF_H | |
2 |
#define |
|
2 | #define HG_BDIFF_H | |
3 |
|
3 | |||
4 | #include "compat.h" |
|
4 | #include "compat.h" | |
5 |
|
5 | |||
6 | struct bdiff_line { |
|
6 | struct bdiff_line { | |
7 | int hash, n, e; |
|
7 | int hash, n, e; | |
8 | ssize_t len; |
|
8 | ssize_t len; | |
9 | const char *l; |
|
9 | const char *l; | |
10 | }; |
|
10 | }; | |
11 |
|
11 | |||
12 | struct bdiff_hunk; |
|
12 | struct bdiff_hunk; | |
13 | struct bdiff_hunk { |
|
13 | struct bdiff_hunk { | |
14 | int a1, a2, b1, b2; |
|
14 | int a1, a2, b1, b2; | |
15 | struct bdiff_hunk *next; |
|
15 | struct bdiff_hunk *next; | |
16 | }; |
|
16 | }; | |
17 |
|
17 | |||
18 | int bdiff_splitlines(const char *a, ssize_t len, struct bdiff_line **lr); |
|
18 | int bdiff_splitlines(const char *a, ssize_t len, struct bdiff_line **lr); | |
19 | int bdiff_diff(struct bdiff_line *a, int an, struct bdiff_line *b, int bn, |
|
19 | int bdiff_diff(struct bdiff_line *a, int an, struct bdiff_line *b, int bn, | |
20 | struct bdiff_hunk *base); |
|
20 | struct bdiff_hunk *base); | |
21 | void bdiff_freehunks(struct bdiff_hunk *l); |
|
21 | void bdiff_freehunks(struct bdiff_hunk *l); | |
22 |
|
22 | |||
23 | #endif |
|
23 | #endif |
@@ -1,77 +1,77 b'' | |||||
1 |
#ifndef |
|
1 | #ifndef HG_BITMANIPULATION_H | |
2 |
#define |
|
2 | #define HG_BITMANIPULATION_H | |
3 |
|
3 | |||
4 | #include <string.h> |
|
4 | #include <string.h> | |
5 |
|
5 | |||
6 | #include "compat.h" |
|
6 | #include "compat.h" | |
7 |
|
7 | |||
8 | /* Reads a 64 bit integer from big-endian bytes. Assumes that the data is long |
|
8 | /* Reads a 64 bit integer from big-endian bytes. Assumes that the data is long | |
9 | enough */ |
|
9 | enough */ | |
10 | static inline uint64_t getbe64(const char *c) |
|
10 | static inline uint64_t getbe64(const char *c) | |
11 | { |
|
11 | { | |
12 | const unsigned char *d = (const unsigned char *)c; |
|
12 | const unsigned char *d = (const unsigned char *)c; | |
13 |
|
13 | |||
14 | return ((((uint64_t)d[0]) << 56) | (((uint64_t)d[1]) << 48) | |
|
14 | return ((((uint64_t)d[0]) << 56) | (((uint64_t)d[1]) << 48) | | |
15 | (((uint64_t)d[2]) << 40) | (((uint64_t)d[3]) << 32) | |
|
15 | (((uint64_t)d[2]) << 40) | (((uint64_t)d[3]) << 32) | | |
16 | (((uint64_t)d[4]) << 24) | (((uint64_t)d[5]) << 16) | |
|
16 | (((uint64_t)d[4]) << 24) | (((uint64_t)d[5]) << 16) | | |
17 | (((uint64_t)d[6]) << 8) | (d[7])); |
|
17 | (((uint64_t)d[6]) << 8) | (d[7])); | |
18 | } |
|
18 | } | |
19 |
|
19 | |||
20 | static inline uint32_t getbe32(const char *c) |
|
20 | static inline uint32_t getbe32(const char *c) | |
21 | { |
|
21 | { | |
22 | const unsigned char *d = (const unsigned char *)c; |
|
22 | const unsigned char *d = (const unsigned char *)c; | |
23 |
|
23 | |||
24 | return ((((uint32_t)d[0]) << 24) | (((uint32_t)d[1]) << 16) | |
|
24 | return ((((uint32_t)d[0]) << 24) | (((uint32_t)d[1]) << 16) | | |
25 | (((uint32_t)d[2]) << 8) | (d[3])); |
|
25 | (((uint32_t)d[2]) << 8) | (d[3])); | |
26 | } |
|
26 | } | |
27 |
|
27 | |||
28 | static inline int16_t getbeint16(const char *c) |
|
28 | static inline int16_t getbeint16(const char *c) | |
29 | { |
|
29 | { | |
30 | const unsigned char *d = (const unsigned char *)c; |
|
30 | const unsigned char *d = (const unsigned char *)c; | |
31 |
|
31 | |||
32 | return ((d[0] << 8) | (d[1])); |
|
32 | return ((d[0] << 8) | (d[1])); | |
33 | } |
|
33 | } | |
34 |
|
34 | |||
35 | static inline uint16_t getbeuint16(const char *c) |
|
35 | static inline uint16_t getbeuint16(const char *c) | |
36 | { |
|
36 | { | |
37 | const unsigned char *d = (const unsigned char *)c; |
|
37 | const unsigned char *d = (const unsigned char *)c; | |
38 |
|
38 | |||
39 | return ((d[0] << 8) | (d[1])); |
|
39 | return ((d[0] << 8) | (d[1])); | |
40 | } |
|
40 | } | |
41 |
|
41 | |||
42 | /* Writes a 64 bit integer to bytes in a big-endian format. |
|
42 | /* Writes a 64 bit integer to bytes in a big-endian format. | |
43 | Assumes that the buffer is long enough */ |
|
43 | Assumes that the buffer is long enough */ | |
44 | static inline void putbe64(uint64_t x, char *c) |
|
44 | static inline void putbe64(uint64_t x, char *c) | |
45 | { |
|
45 | { | |
46 | c[0] = (x >> 56) & 0xff; |
|
46 | c[0] = (x >> 56) & 0xff; | |
47 | c[1] = (x >> 48) & 0xff; |
|
47 | c[1] = (x >> 48) & 0xff; | |
48 | c[2] = (x >> 40) & 0xff; |
|
48 | c[2] = (x >> 40) & 0xff; | |
49 | c[3] = (x >> 32) & 0xff; |
|
49 | c[3] = (x >> 32) & 0xff; | |
50 | c[4] = (x >> 24) & 0xff; |
|
50 | c[4] = (x >> 24) & 0xff; | |
51 | c[5] = (x >> 16) & 0xff; |
|
51 | c[5] = (x >> 16) & 0xff; | |
52 | c[6] = (x >> 8) & 0xff; |
|
52 | c[6] = (x >> 8) & 0xff; | |
53 | c[7] = (x)&0xff; |
|
53 | c[7] = (x)&0xff; | |
54 | } |
|
54 | } | |
55 |
|
55 | |||
56 | static inline void putbe32(uint32_t x, char *c) |
|
56 | static inline void putbe32(uint32_t x, char *c) | |
57 | { |
|
57 | { | |
58 | c[0] = (x >> 24) & 0xff; |
|
58 | c[0] = (x >> 24) & 0xff; | |
59 | c[1] = (x >> 16) & 0xff; |
|
59 | c[1] = (x >> 16) & 0xff; | |
60 | c[2] = (x >> 8) & 0xff; |
|
60 | c[2] = (x >> 8) & 0xff; | |
61 | c[3] = (x)&0xff; |
|
61 | c[3] = (x)&0xff; | |
62 | } |
|
62 | } | |
63 |
|
63 | |||
64 | static inline double getbefloat64(const char *c) |
|
64 | static inline double getbefloat64(const char *c) | |
65 | { |
|
65 | { | |
66 | const unsigned char *d = (const unsigned char *)c; |
|
66 | const unsigned char *d = (const unsigned char *)c; | |
67 | double ret; |
|
67 | double ret; | |
68 | int i; |
|
68 | int i; | |
69 | uint64_t t = 0; |
|
69 | uint64_t t = 0; | |
70 | for (i = 0; i < 8; i++) { |
|
70 | for (i = 0; i < 8; i++) { | |
71 | t = (t << 8) + d[i]; |
|
71 | t = (t << 8) + d[i]; | |
72 | } |
|
72 | } | |
73 | memcpy(&ret, &t, sizeof(t)); |
|
73 | memcpy(&ret, &t, sizeof(t)); | |
74 | return ret; |
|
74 | return ret; | |
75 | } |
|
75 | } | |
76 |
|
76 | |||
77 | #endif |
|
77 | #endif |
@@ -1,58 +1,58 b'' | |||||
1 |
#ifndef |
|
1 | #ifndef HG_COMPAT_H | |
2 |
#define |
|
2 | #define HG_COMPAT_H | |
3 |
|
3 | |||
4 | #ifdef _WIN32 |
|
4 | #ifdef _WIN32 | |
5 | #ifdef _MSC_VER |
|
5 | #ifdef _MSC_VER | |
6 | #if _MSC_VER < 1900 |
|
6 | #if _MSC_VER < 1900 | |
7 | /* msvc 6.0 has problems */ |
|
7 | /* msvc 6.0 has problems */ | |
8 | #define inline __inline |
|
8 | #define inline __inline | |
9 | #if defined(_WIN64) |
|
9 | #if defined(_WIN64) | |
10 | typedef __int64 ssize_t; |
|
10 | typedef __int64 ssize_t; | |
11 | typedef unsigned __int64 uintptr_t; |
|
11 | typedef unsigned __int64 uintptr_t; | |
12 | #else |
|
12 | #else | |
13 | typedef int ssize_t; |
|
13 | typedef int ssize_t; | |
14 | typedef unsigned int uintptr_t; |
|
14 | typedef unsigned int uintptr_t; | |
15 | #endif |
|
15 | #endif | |
16 | typedef signed char int8_t; |
|
16 | typedef signed char int8_t; | |
17 | typedef short int16_t; |
|
17 | typedef short int16_t; | |
18 | typedef long int32_t; |
|
18 | typedef long int32_t; | |
19 | typedef __int64 int64_t; |
|
19 | typedef __int64 int64_t; | |
20 | typedef unsigned char uint8_t; |
|
20 | typedef unsigned char uint8_t; | |
21 | typedef unsigned short uint16_t; |
|
21 | typedef unsigned short uint16_t; | |
22 | typedef unsigned long uint32_t; |
|
22 | typedef unsigned long uint32_t; | |
23 | typedef unsigned __int64 uint64_t; |
|
23 | typedef unsigned __int64 uint64_t; | |
24 | #else |
|
24 | #else | |
25 | /* VC++ 14 */ |
|
25 | /* VC++ 14 */ | |
26 | #include <stdint.h> |
|
26 | #include <stdint.h> | |
27 |
|
27 | |||
28 | #if defined(_WIN64) |
|
28 | #if defined(_WIN64) | |
29 | typedef __int64 ssize_t; |
|
29 | typedef __int64 ssize_t; | |
30 | #else |
|
30 | #else | |
31 | typedef int ssize_t; |
|
31 | typedef int ssize_t; | |
32 | #endif |
|
32 | #endif | |
33 | #endif /* _MSC_VER < 1900 */ |
|
33 | #endif /* _MSC_VER < 1900 */ | |
34 |
|
34 | |||
35 | #else |
|
35 | #else | |
36 | /* not msvc */ |
|
36 | /* not msvc */ | |
37 | #include <stdint.h> |
|
37 | #include <stdint.h> | |
38 | #endif |
|
38 | #endif | |
39 | #else |
|
39 | #else | |
40 | /* not windows */ |
|
40 | /* not windows */ | |
41 | #include <sys/types.h> |
|
41 | #include <sys/types.h> | |
42 | #if defined __BEOS__ && !defined __HAIKU__ |
|
42 | #if defined __BEOS__ && !defined __HAIKU__ | |
43 | #include <ByteOrder.h> |
|
43 | #include <ByteOrder.h> | |
44 | #else |
|
44 | #else | |
45 | #include <arpa/inet.h> |
|
45 | #include <arpa/inet.h> | |
46 | #endif |
|
46 | #endif | |
47 | #include <inttypes.h> |
|
47 | #include <inttypes.h> | |
48 | #endif |
|
48 | #endif | |
49 |
|
49 | |||
50 | #if defined __hpux || defined __SUNPRO_C || defined _AIX |
|
50 | #if defined __hpux || defined __SUNPRO_C || defined _AIX | |
51 | #define inline |
|
51 | #define inline | |
52 | #endif |
|
52 | #endif | |
53 |
|
53 | |||
54 | #ifdef __linux |
|
54 | #ifdef __linux | |
55 | #define inline __inline |
|
55 | #define inline __inline | |
56 | #endif |
|
56 | #endif | |
57 |
|
57 | |||
58 | #endif |
|
58 | #endif |
@@ -1,26 +1,26 b'' | |||||
1 |
#ifndef |
|
1 | #ifndef HG_MPATCH_H | |
2 |
#define |
|
2 | #define HG_MPATCH_H | |
3 |
|
3 | |||
4 | #define MPATCH_ERR_NO_MEM -3 |
|
4 | #define MPATCH_ERR_NO_MEM -3 | |
5 | #define MPATCH_ERR_CANNOT_BE_DECODED -2 |
|
5 | #define MPATCH_ERR_CANNOT_BE_DECODED -2 | |
6 | #define MPATCH_ERR_INVALID_PATCH -1 |
|
6 | #define MPATCH_ERR_INVALID_PATCH -1 | |
7 |
|
7 | |||
8 | struct mpatch_frag { |
|
8 | struct mpatch_frag { | |
9 | int start, end, len; |
|
9 | int start, end, len; | |
10 | const char *data; |
|
10 | const char *data; | |
11 | }; |
|
11 | }; | |
12 |
|
12 | |||
13 | struct mpatch_flist { |
|
13 | struct mpatch_flist { | |
14 | struct mpatch_frag *base, *head, *tail; |
|
14 | struct mpatch_frag *base, *head, *tail; | |
15 | }; |
|
15 | }; | |
16 |
|
16 | |||
17 | int mpatch_decode(const char *bin, ssize_t len, struct mpatch_flist **res); |
|
17 | int mpatch_decode(const char *bin, ssize_t len, struct mpatch_flist **res); | |
18 | ssize_t mpatch_calcsize(ssize_t len, struct mpatch_flist *l); |
|
18 | ssize_t mpatch_calcsize(ssize_t len, struct mpatch_flist *l); | |
19 | void mpatch_lfree(struct mpatch_flist *a); |
|
19 | void mpatch_lfree(struct mpatch_flist *a); | |
20 | int mpatch_apply(char *buf, const char *orig, ssize_t len, |
|
20 | int mpatch_apply(char *buf, const char *orig, ssize_t len, | |
21 | struct mpatch_flist *l); |
|
21 | struct mpatch_flist *l); | |
22 | struct mpatch_flist * |
|
22 | struct mpatch_flist * | |
23 | mpatch_fold(void *bins, struct mpatch_flist *(*get_next_item)(void *, ssize_t), |
|
23 | mpatch_fold(void *bins, struct mpatch_flist *(*get_next_item)(void *, ssize_t), | |
24 | ssize_t start, ssize_t end); |
|
24 | ssize_t start, ssize_t end); | |
25 |
|
25 | |||
26 | #endif |
|
26 | #endif |
General Comments 0
You need to be logged in to leave comments.
Login now