comparison tests/encbr1test.c @ 2586:9807ae37ad69

Require stdbool.h, we require C11 now.
author Matti Hamalainen <ccr@tnsp.org>
date Thu, 08 Dec 2022 15:59:22 +0200
parents 8cd012260976
children
comparison
equal deleted inserted replaced
2585:ef6c826c5b7a 2586:9807ae37ad69
26 moffs++; 26 moffs++;
27 } 27 }
28 #endif 28 #endif
29 29
30 30
31 BOOL dmIFFEncodeByteRun1LIT(DMResource *fp, 31 bool dmIFFEncodeByteRun1LIT(DMResource *fp,
32 const Uint8 *buf, const size_t offs, 32 const Uint8 *buf, const size_t offs,
33 const size_t count) 33 const size_t count)
34 { 34 {
35 if (count <= 0) 35 if (count <= 0)
36 return TRUE; 36 return true;
37 37
38 #if BR_DEBUG != 0 || defined(BR_WRITE) 38 #if BR_DEBUG != 0 || defined(BR_WRITE)
39 Uint8 tmp = count - 1; 39 Uint8 tmp = count - 1;
40 #endif 40 #endif
41 41
51 #endif 51 #endif
52 52
53 #ifdef BR_WRITE 53 #ifdef BR_WRITE
54 if (!dmf_write_byte(fp, tmp) || 54 if (!dmf_write_byte(fp, tmp) ||
55 !dmf_write_str(fp, buf + offs, count)) 55 !dmf_write_str(fp, buf + offs, count))
56 return FALSE; 56 return false;
57 #else 57 #else
58 (void) fp; 58 (void) fp;
59 #endif 59 #endif
60 60
61 return TRUE; 61 return true;
62 } 62 }
63 63
64 64
65 BOOL dmIFFEncodeByteRun1RLE(DMResource *fp, 65 bool dmIFFEncodeByteRun1RLE(DMResource *fp,
66 const Uint8 *buf, const size_t offs, 66 const Uint8 *buf, const size_t offs,
67 const size_t count) 67 const size_t count)
68 { 68 {
69 if (count <= 0) 69 if (count <= 0)
70 return TRUE; 70 return true;
71 71
72 #if BR_DEBUG != 0 || defined(BR_WRITE) 72 #if BR_DEBUG != 0 || defined(BR_WRITE)
73 Uint8 tmp = ((Uint8) count - 2) ^ 0xff; 73 Uint8 tmp = ((Uint8) count - 2) ^ 0xff;
74 Uint8 data = buf[offs]; 74 Uint8 data = buf[offs];
75 #endif 75 #endif
82 #endif 82 #endif
83 83
84 #ifdef BR_WRITE 84 #ifdef BR_WRITE
85 if (!dmf_write_byte(fp, tmp) || 85 if (!dmf_write_byte(fp, tmp) ||
86 !dmf_write_byte(fp, data)) 86 !dmf_write_byte(fp, data))
87 return FALSE; 87 return false;
88 #else 88 #else
89 (void) fp; 89 (void) fp;
90 #endif 90 #endif
91 91
92 return TRUE; 92 return true;
93 } 93 }
94 94
95 95
96 BOOL dmIFFEncodeByteRun1Row(DMResource *fp, const Uint8 *buf, const size_t bufLen) 96 bool dmIFFEncodeByteRun1Row(DMResource *fp, const Uint8 *buf, const size_t bufLen)
97 { 97 {
98 int prev = -1, mode = DMODE_LIT; 98 int prev = -1, mode = DMODE_LIT;
99 size_t offs, l_offs, r_offs; 99 size_t offs, l_offs, r_offs;
100 BOOL ret = TRUE; 100 bool ret = true;
101 101
102 #if BR_DEBUG == 1 102 #if BR_DEBUG == 1
103 mcount = 0; 103 mcount = 0;
104 #endif 104 #endif
105 105
106 for (offs = l_offs = r_offs = 0; offs < bufLen; offs++) 106 for (offs = l_offs = r_offs = 0; offs < bufLen; offs++)
107 { 107 {
108 Uint8 data = buf[offs]; 108 Uint8 data = buf[offs];
109 BOOL flush = FALSE; 109 bool flush = false;
110 int pmode = mode; 110 int pmode = mode;
111 111
112 if (data == prev) 112 if (data == prev)
113 { 113 {
114 if (mode == DMODE_LIT && 114 if (mode == DMODE_LIT &&
142 // NOTE! RLE max is 128, checked against DP2e 142 // NOTE! RLE max is 128, checked against DP2e
143 // Not sure about LIT max yet 143 // Not sure about LIT max yet
144 if ((pmode == DMODE_RLE && offs - r_offs >= 128) || 144 if ((pmode == DMODE_RLE && offs - r_offs >= 128) ||
145 (pmode == DMODE_LIT && offs - l_offs >= 128)) 145 (pmode == DMODE_LIT && offs - l_offs >= 128))
146 { 146 {
147 flush = TRUE; 147 flush = true;
148 #if BR_DEBUG == 2 148 #if BR_DEBUG == 2
149 printf(" <LEN FLUSH>"); 149 printf(" <LEN FLUSH>");
150 #endif 150 #endif
151 } 151 }
152 152
153 // Check for last byte of input 153 // Check for last byte of input
154 if (offs == bufLen - 1) 154 if (offs == bufLen - 1)
155 { 155 {
156 offs++; 156 offs++;
157 flush = TRUE; 157 flush = true;
158 pmode = mode; 158 pmode = mode;
159 #if BR_DEBUG == 2 159 #if BR_DEBUG == 2
160 printf(" <FINAL FLUSH>"); 160 printf(" <FINAL FLUSH>");
161 #endif 161 #endif
162 } 162 }