Mercurial > hg > dmlib
annotate src/dmgrowbuf.c @ 2298:b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
dmGrowBufConstCopyOffsSize().
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 04 Jul 2019 10:54:16 +0300 |
parents | 39b4e06785f5 |
children | c801995cbb13 |
rev | line source |
---|---|
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
1 /* |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
2 * DMLib |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
3 * -- Growable buffer implementation |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
4 * Programmed and designed by Matti 'ccr' Hamalainen |
2297 | 5 * (C) Copyright 2018-2019 Tecnic Software productions (TNSP) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
6 */ |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
7 #include "dmgrowbuf.h" |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
8 |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
9 //#define DM_GROWBUF_DEBUG 1 |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
10 |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
11 #ifdef DM_GROWBUF_DEBUG |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
12 # define DM_DBG(...) do { fprintf(stderr, __VA_ARGS__); } while (0) |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
13 #else |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
14 # define DM_DBG(...) do { } while (0) |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
15 #endif |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
16 |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
17 |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
18 int dmGrowBufInit(DMGrowBuf *buf) |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
19 { |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
20 DM_DBG("dmGrowBufInit(%p)\n", buf); |
1687 | 21 |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
22 if (buf == NULL) |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
23 return DMERR_NULLPTR; |
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
24 |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1796
diff
changeset
|
25 dmMemset(buf, 0, sizeof(DMGrowBuf)); |
1458
b2dd6a72d162
Adjust semantics of growbuf and add new function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1455
diff
changeset
|
26 |
1694
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
27 return DMERR_OK; |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
28 } |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
29 |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
30 |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
31 int dmGrowBufAlloc(DMGrowBuf *buf, const size_t initial, const size_t mingrow) |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
32 { |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
33 int res; |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
34 |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
35 DM_DBG("dmGrowBufAlloc(%p, %" DM_PRIu_SIZE_T ", %" DM_PRIu_SIZE_T ")\n", |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
36 buf, initial, mingrow); |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
37 |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
38 if ((res = dmGrowBufInit(buf)) != DMERR_OK) |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
39 return res; |
e568535e1a96
Backed out changeset 9611ecd2c4fb
Matti Hamalainen <ccr@tnsp.org>
parents:
1693
diff
changeset
|
40 |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
41 buf->len = 0; |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
42 buf->offs = 0; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
43 buf->size = initial; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
44 buf->mingrow = mingrow; |
1702
94329f678841
Explicitly initialize some DMGrowBuf fields for clarity, though they are already cleared previously by memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1701
diff
changeset
|
45 buf->backwards = FALSE; |
94329f678841
Explicitly initialize some DMGrowBuf fields for clarity, though they are already cleared previously by memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1701
diff
changeset
|
46 buf->is_const = FALSE; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
47 |
1509
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
48 // Allocate the data |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
49 if ((buf->data = dmMalloc0(initial)) == NULL) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
50 return DMERR_MALLOC; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
51 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
52 return DMERR_OK; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
53 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
54 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
55 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
56 void dmGrowBufFree(DMGrowBuf *buf) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
57 { |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
58 DM_DBG("dmGrowBufFree(%p)\n", buf); |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
59 if (buf != NULL) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
60 { |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
61 DM_DBG( |
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
62 " buf->data = %p\n" |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
63 " buf->is_const = %s\n", |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
64 buf->data, |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
65 buf->is_const ? "YES" : "NO"); |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
66 |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
67 if (buf->is_const) |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
68 return; |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
69 |
1796
0801fd0e26cb
Zero out the struct data in dmGrowBufFree().
Matti Hamalainen <ccr@tnsp.org>
parents:
1785
diff
changeset
|
70 dmFree(buf->data); |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1796
diff
changeset
|
71 dmMemset(buf, 0, sizeof(DMGrowBuf)); |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
72 } |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
73 } |
1531
260bf529a8f2
Implement current len/offs push/pop for growbuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1530
diff
changeset
|
74 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
75 |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
76 DMGrowBuf * dmGrowBufCopy(DMGrowBuf *dst, const DMGrowBuf *src, const size_t enlarge) |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
77 { |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
78 if (dst == NULL) |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
79 return NULL; |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
80 |
1782
22b6fa1a2ee4
Fix one DMGrowBuf debug print.
Matti Hamalainen <ccr@tnsp.org>
parents:
1747
diff
changeset
|
81 DM_DBG("dmGrowBufCopy(dst=%p, src=%p, enlarge=%" DM_PRIu_SIZE_T "):\n" |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
82 " data=%p, size=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T ", offs=%" DM_PRIu_SIZE_T "\n", |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
83 dst, src, enlarge, src->data, src->size, src->len, src->offs); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
84 |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
85 // Copy the struct here |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
86 memcpy(dst, src, sizeof(DMGrowBuf)); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
87 dst->size += enlarge; |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
88 |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
89 // Allocate new memory for the data |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
90 if ((dst->data = dmMalloc(dst->size)) == NULL) |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
91 { |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
92 // If that fails, clear the struct |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1796
diff
changeset
|
93 dmMemset(dst, 0, sizeof(DMGrowBuf)); |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
94 return NULL; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
95 } |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
96 |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
97 // Copy data |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
98 memcpy(dst->data, src->data, src->size); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
99 if (enlarge > 0) |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1796
diff
changeset
|
100 dmMemset(dst->data + src->size, 0, enlarge); |
1817 | 101 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
102 // And reset some struct information |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
103 dst->is_const = FALSE; |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
104 |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
105 return dst; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
106 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
107 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
108 |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
109 DMGrowBuf * dmGrowBufConstCopy(DMGrowBuf *dst, const DMGrowBuf *src) |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
110 { |
1701 | 111 if (dst == NULL) |
112 return NULL; | |
113 | |
114 DM_DBG("dmGrowBufConstCopy(dst=%p, src=%p):\n" | |
115 " data=%p, size=%" DM_PRIu_SIZE_T ", len=%" DM_PRIu_SIZE_T ", offs=%" DM_PRIu_SIZE_T "\n", | |
116 dst, src, src->data, src->size, src->len, src->offs); | |
117 | |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
118 memcpy(dst, src, sizeof(DMGrowBuf)); |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
119 dst->is_const = TRUE; |
1701 | 120 |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
121 return dst; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
122 } |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
123 |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
124 |
2296 | 125 DMGrowBuf * dmGrowBufConstCreateFrom(DMGrowBuf *dst, Uint8 *data, const size_t len) |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
126 { |
1701 | 127 if (dmGrowBufInit(dst) != DMERR_OK) |
128 return NULL; | |
129 | |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
130 DM_DBG("dmGrowBufConstCreateFrom(dst=%p, data=%p, len=%" DM_PRIu_SIZE_T ")\n", |
1701 | 131 dst, data, len); |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
132 |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
133 dst->data = data; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
134 dst->len = dst->size = len; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
135 dst->is_const = TRUE; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
136 |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
137 return dst; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
138 } |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
139 |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
140 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
141 DMGrowBuf * dmGrowBufConstCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs) |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
142 { |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
143 return dmGrowBufConstCreateFrom(dst, src->data + offs, src->len - offs); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
144 } |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
145 |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
146 |
2298
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
147 DMGrowBuf * dmGrowBufConstCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len) |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
148 { |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
149 if (src->len < offs + len) |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
150 return NULL; |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
151 |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
152 return dmGrowBufConstCreateFrom(dst, src->data + offs, len); |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
153 } |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
154 |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
155 |
1747
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
156 DMGrowBuf * dmGrowBufCopyOffs(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t enlarge) |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
157 { |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
158 DMGrowBuf tmp; |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
159 return dmGrowBufCopy(dst, |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
160 dmGrowBufConstCreateFrom(&tmp, src->data + offs, src->len - offs), enlarge); |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
161 } |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
162 |
5e928618fdc8
Change DMGrowBuf API somewhat and implement more copy operations.
Matti Hamalainen <ccr@tnsp.org>
parents:
1744
diff
changeset
|
163 |
2298
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
164 DMGrowBuf * dmGrowBufCopyOffsSize(DMGrowBuf *dst, const DMGrowBuf *src, const size_t offs, const size_t len, const size_t enlarge) |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
165 { |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
166 DMGrowBuf tmp; |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
167 |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
168 if (src->len < offs + len) |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
169 return NULL; |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
170 |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
171 return dmGrowBufCopy(dst, |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
172 dmGrowBufConstCreateFrom(&tmp, src->data + offs, len), enlarge); |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
173 } |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
174 |
b5abfff07ca9
Add new DMGrowBuf helper functions dmGrowBufCopyOffsSize() and
Matti Hamalainen <ccr@tnsp.org>
parents:
2297
diff
changeset
|
175 |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
176 static BOOL dmGrowBufRealloc(DMGrowBuf *buf, const size_t nsize, const BOOL clear) |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
177 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
178 DM_DBG("dmGrowBufRealloc(%p):\n" |
1701 | 179 " size=%" DM_PRIu_SIZE_T ", nsize=%" DM_PRIu_SIZE_T |
180 ", offs=%" DM_PRIu_SIZE_T "\n", | |
181 buf, buf->size, nsize, buf->offs); | |
1536
064fc2e3ee64
Add compile-time debugging information to DMGrowBuf.
Matti Hamalainen <ccr@tnsp.org>
parents:
1531
diff
changeset
|
182 |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
183 if (buf->is_const) |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
184 return FALSE; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
185 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
186 // Can't be smaller than current size! |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
187 if (nsize < buf->size) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
188 return FALSE; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
189 |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
190 if ((buf->data = dmRealloc(buf->data, nsize)) == NULL) |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
191 return FALSE; |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
192 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
193 // For buffers growing backwards, we must move the |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
194 // current data to the end of the buffer .. |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
195 size_t clrsize = nsize - buf->size; |
1784
a29d38862037
Improve DMGrowBuf debugging slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
1782
diff
changeset
|
196 DM_DBG(" clrsize=%" DM_PRIu_SIZE_T "\n", clrsize); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
197 if (buf->backwards) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
198 { |
1785
86d10d5d4915
Fix case where DMGrowBuf is growing backwards and needs to be reallocated in
Matti Hamalainen <ccr@tnsp.org>
parents:
1784
diff
changeset
|
199 memmove(buf->data + clrsize, buf->data, buf->size); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
200 buf->offs += clrsize; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
201 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
202 |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
203 // Check if we need to clear the newly allocated area? |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
204 if (clear) |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
205 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
206 if (buf->backwards) |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1796
diff
changeset
|
207 dmMemset(buf->data, 0, clrsize); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
208 else |
1814
0b7062d874ef
Use dmMemset() instead of memset().
Matti Hamalainen <ccr@tnsp.org>
parents:
1796
diff
changeset
|
209 dmMemset(buf->data + buf->size, 0, clrsize); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
210 } |
1530
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
211 |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
212 buf->size = nsize; |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
213 |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
214 return TRUE; |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
215 } |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
216 |
94eb6a8a7d56
Add helper function dmGrowBufRealloc() to handle the common case of
Matti Hamalainen <ccr@tnsp.org>
parents:
1509
diff
changeset
|
217 |
1509
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
218 // |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
219 // Grow the buffer by "amount" bytes, but at least by buf->mingrow, |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
220 // if there is not enough space for at least that amount compared to |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
221 // current buffer "len". |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
222 // |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
223 BOOL dmGrowBufGrow(DMGrowBuf *buf, const size_t amount) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
224 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
225 size_t grow = (amount > buf->mingrow) ? amount : buf->mingrow; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
226 |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
227 if (buf->is_const) |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
228 return FALSE; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
229 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
230 if (buf->data == NULL || |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
231 (buf->backwards && amount >= buf->offs) || |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
232 (!buf->backwards && buf->offs + amount >= buf->size)) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
233 { |
1784
a29d38862037
Improve DMGrowBuf debugging slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
1782
diff
changeset
|
234 DM_DBG("dmGrowBufGrow(%p, amount=%" DM_PRIu_SIZE_T "): grow=%" DM_PRIu_SIZE_T "\n", |
a29d38862037
Improve DMGrowBuf debugging slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
1782
diff
changeset
|
235 buf, amount, grow); |
a29d38862037
Improve DMGrowBuf debugging slightly.
Matti Hamalainen <ccr@tnsp.org>
parents:
1782
diff
changeset
|
236 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
237 if (!dmGrowBufRealloc(buf, buf->size + grow, TRUE)) |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
238 return FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
239 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
240 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
241 buf->len += amount; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
242 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
243 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
244 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
245 |
1509
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
246 // |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
247 // Grow the buffer if "nsize" is larger than the current buffer size. |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
248 // Buffer is enlarged to nsize + mingrow. |
15afe578f0ae
Add few comments to clarify things.
Matti Hamalainen <ccr@tnsp.org>
parents:
1508
diff
changeset
|
249 // |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
250 BOOL dmGrowBufCheckGrow(DMGrowBuf *buf, const size_t nsize) |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
251 { |
1700
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
252 if (buf->is_const) |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
253 return FALSE; |
a2e65aa47554
Implement dmGrowBufConstCopy() and dmGrowBufCreateFrom(), and also
Matti Hamalainen <ccr@tnsp.org>
parents:
1699
diff
changeset
|
254 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
255 if (buf->data == NULL || nsize > buf->size) |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
256 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
257 if (!dmGrowBufRealloc(buf, nsize + buf->mingrow, TRUE)) |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
258 return FALSE; |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
259 } |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
260 |
1707
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1706
diff
changeset
|
261 if (nsize > buf->len) |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1706
diff
changeset
|
262 buf->len = nsize; |
a0986cfd6f9d
More consistently use DMGrowBuf in the lib64gfx APIs, and implement
Matti Hamalainen <ccr@tnsp.org>
parents:
1706
diff
changeset
|
263 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
264 return TRUE; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
265 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
266 |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
267 |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
268 BOOL dmGrowBufPut(DMGrowBuf *buf, const Uint8 *data, const size_t len) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
269 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
270 if (data == NULL) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
271 return FALSE; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
272 |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
273 if (!dmGrowBufGrow(buf, len)) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
274 return FALSE; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
275 |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
276 if (buf->backwards) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
277 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
278 if (buf->literal) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
279 { |
1831
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1830
diff
changeset
|
280 for (size_t n = 0; n < len; n++) |
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1830
diff
changeset
|
281 buf->data[--buf->offs] = data[len - n]; |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
282 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
283 else |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
284 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
285 for (size_t n = 0; n < len; n++) |
1831
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1830
diff
changeset
|
286 buf->data[--buf->offs] = data[n]; |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
287 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
288 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
289 else |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
290 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
291 memcpy(buf->data + buf->offs, data, len); |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
292 buf->offs += len; |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
293 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
294 |
1455
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
295 return TRUE; |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
296 } |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
297 |
a957b318fbe2
Add dmGrowBufCheckGrow() function.
Matti Hamalainen <ccr@tnsp.org>
parents:
1454
diff
changeset
|
298 |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
299 BOOL dmGrowBufPutU8(DMGrowBuf *buf, const Uint8 value) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
300 { |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
301 if (!dmGrowBufGrow(buf, sizeof(Uint8))) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
302 return FALSE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
303 |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
304 if (buf->backwards) |
1831
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1830
diff
changeset
|
305 buf->data[--buf->offs] = value; |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
306 else |
1831
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1830
diff
changeset
|
307 buf->data[buf->offs++] = value; |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
308 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
309 return TRUE; |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
310 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
311 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
312 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
313 BOOL dmGrowBufPutU16BE(DMGrowBuf *buf, const Uint16 val) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
314 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
315 if (buf->literal && buf->backwards) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
316 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
317 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
318 dmGrowBufPutU8(buf, val & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
319 dmGrowBufPutU8(buf, (val >> 8) & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
320 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
321 else |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
322 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
323 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
324 dmGrowBufPutU8(buf, (val >> 8) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
325 dmGrowBufPutU8(buf, val & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
326 } |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
327 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
328 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
329 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
330 BOOL dmGrowBufPutU16LE(DMGrowBuf *buf, const Uint16 val) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
331 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
332 if (buf->literal && buf->backwards) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
333 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
334 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
335 dmGrowBufPutU8(buf, (val >> 8) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
336 dmGrowBufPutU8(buf, val & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
337 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
338 else |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
339 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
340 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
341 dmGrowBufPutU8(buf, val & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
342 dmGrowBufPutU8(buf, (val >> 8) & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
343 } |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
344 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
345 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
346 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
347 BOOL dmGrowBufPutU32BE(DMGrowBuf *buf, const Uint32 val) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
348 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
349 if (buf->literal && buf->backwards) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
350 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
351 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
352 dmGrowBufPutU8(buf, (val >> 24) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
353 dmGrowBufPutU8(buf, (val >> 16) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
354 dmGrowBufPutU8(buf, (val >> 8) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
355 dmGrowBufPutU8(buf, val & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
356 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
357 else |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
358 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
359 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
360 dmGrowBufPutU8(buf, val & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
361 dmGrowBufPutU8(buf, (val >> 8) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
362 dmGrowBufPutU8(buf, (val >> 16) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
363 dmGrowBufPutU8(buf, (val >> 24) & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
364 } |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
365 } |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
366 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
367 |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
368 BOOL dmGrowBufPutU32LE(DMGrowBuf *buf, const Uint32 val) |
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
369 { |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
370 if (buf->literal && buf->backwards) |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
371 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
372 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
373 dmGrowBufPutU8(buf, val & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
374 dmGrowBufPutU8(buf, (val >> 8) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
375 dmGrowBufPutU8(buf, (val >> 16) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
376 dmGrowBufPutU8(buf, (val >> 24) & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
377 } |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
378 else |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
379 { |
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
380 return |
1706
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
381 dmGrowBufPutU8(buf, (val >> 24) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
382 dmGrowBufPutU8(buf, (val >> 16) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
383 dmGrowBufPutU8(buf, (val >> 8) & 0xff) && |
311b14855a1e
Ehm .. the boolean logic conditions used in dmGrowBufPutU{16,32}{LE,BE}()
Matti Hamalainen <ccr@tnsp.org>
parents:
1705
diff
changeset
|
384 dmGrowBufPutU8(buf, val & 0xff); |
1697
1036b0dcccb5
Refactor DMGrowBuf so that there can be buffers that grow "backwards".
Matti Hamalainen <ccr@tnsp.org>
parents:
1694
diff
changeset
|
385 } |
1454
fff3b58d031c
Add a growable buffer implementation.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff
changeset
|
386 } |
1699
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
387 |
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
388 |
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
389 BOOL dmGrowBufGetU8(DMGrowBuf *buf, Uint8 *value) |
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
390 { |
1703
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
391 if (buf->backwards) |
1699
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
392 { |
1703
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
393 if (buf->offs > 0) |
1831
ce1a734b016f
Change the logic of how DMGrowBuf works in "backwards" growing mode. Adjust
Matti Hamalainen <ccr@tnsp.org>
parents:
1830
diff
changeset
|
394 *value = buf->data[--buf->offs]; |
1703
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
395 else |
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
396 return FALSE; |
1699
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
397 } |
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
398 else |
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
399 { |
1744
e40227e994e2
Fix unitialized data accesses.
Matti Hamalainen <ccr@tnsp.org>
parents:
1707
diff
changeset
|
400 if (buf->offs < buf->len) |
1703
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
401 *value = buf->data[buf->offs++]; |
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
402 else |
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
403 return FALSE; |
1699
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
404 } |
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
405 |
1703
fcc568e03bed
Clarify dmGrowBufGetU8() a bit.
Matti Hamalainen <ccr@tnsp.org>
parents:
1702
diff
changeset
|
406 return TRUE; |
1699
f71cd6691e05
Implement dmGrowBufGetU8().
Matti Hamalainen <ccr@tnsp.org>
parents:
1697
diff
changeset
|
407 } |