chiark
/
gitweb
/
~ian
/
chiark-tcl.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
hbytes compiles
[chiark-tcl.git]
/
hbytes
/
hbytes.c
diff --git
a/hbytes/hbytes.c
b/hbytes/hbytes.c
index 5f06d7195088cdcd6464500cb169e7ed2fe83fd2..22383df0d05f889201d380e1e6c7ab79daffbc8d 100644
(file)
--- a/
hbytes/hbytes.c
+++ b/
hbytes/hbytes.c
@@
-2,57
+2,54
@@
*
*/
*
*/
-#include <string.h>
-
#include "hbytes.h"
#include "hbytes.h"
-#include "tables.h"
#define COMPLEX(hb) ((HBytes_ComplexValue*)hb->begin_complex)
#define SIMPLE_LEN(hb) ((Byte*)(hb)->end_0 - (Byte*)(hb)->begin_complex)
/* enquirers */
#define COMPLEX(hb) ((HBytes_ComplexValue*)hb->begin_complex)
#define SIMPLE_LEN(hb) ((Byte*)(hb)->end_0 - (Byte*)(hb)->begin_complex)
/* enquirers */
-int
hbytes
_len(const HBytes_Value *hb) {
+int
cht_hb
_len(const HBytes_Value *hb) {
if (HBYTES_ISEMPTY(hb)) return 0;
else if (HBYTES_ISCOMPLEX(hb)) return COMPLEX(hb)->len;
else return SIMPLE_LEN(hb);
}
if (HBYTES_ISEMPTY(hb)) return 0;
else if (HBYTES_ISCOMPLEX(hb)) return COMPLEX(hb)->len;
else return SIMPLE_LEN(hb);
}
-Byte *
hbytes
_data(const HBytes_Value *hb) {
+Byte *
cht_hb
_data(const HBytes_Value *hb) {
if (HBYTES_ISEMPTY(hb)) return 0;
else if (HBYTES_ISCOMPLEX(hb)) return COMPLEX(hb)->dstart;
else return hb->begin_complex;
}
if (HBYTES_ISEMPTY(hb)) return 0;
else if (HBYTES_ISCOMPLEX(hb)) return COMPLEX(hb)->dstart;
else return hb->begin_complex;
}
-int
hbytes
_issentinel(const HBytes_Value *hb) {
- return HBYTES_IS
COMPLEX
(hb);
+int
cht_hb
_issentinel(const HBytes_Value *hb) {
+ return HBYTES_IS
SENTINEL
(hb);
}
/* constructors */
}
/* constructors */
-void
hbytes
_empty(HBytes_Value *returns) {
+void
cht_hb
_empty(HBytes_Value *returns) {
returns->begin_complex= returns->end_0= 0;
}
returns->begin_complex= returns->end_0= 0;
}
-void
hbytes
_sentinel(HBytes_Value *returns) {
+void
cht_hb
_sentinel(HBytes_Value *returns) {
returns->begin_complex= 0;
returns->begin_complex= 0;
- returns->end_0= (void*)&hbytes_type;
+ returns->end_0= (void*)&
cht_
hbytes_type;
}
}
-Byte *
hbytes
_arrayspace(HBytes_Value *returns, int l) {
- if (!l) {
hbytes
_empty(returns); return 0; }
+Byte *
cht_hb
_arrayspace(HBytes_Value *returns, int l) {
+ if (!l) {
cht_hb
_empty(returns); return 0; }
returns->begin_complex= TALLOC(l);
returns->end_0= returns->begin_complex + l;
return returns->begin_complex;
}
returns->begin_complex= TALLOC(l);
returns->end_0= returns->begin_complex + l;
return returns->begin_complex;
}
-void
hbytes
_array(HBytes_Value *returns, const Byte *array, int l) {
- memcpy(
hbytes
_arrayspace(returns,l), array, l);
+void
cht_hb
_array(HBytes_Value *returns, const Byte *array, int l) {
+ memcpy(
cht_hb
_arrayspace(returns,l), array, l);
}
/* destructor */
}
/* destructor */
-void
hbytes_free(
HBytes_Value *frees) {
+void
cht_hb_free(const
HBytes_Value *frees) {
if (HBYTES_ISCOMPLEX(frees)) {
HBytes_ComplexValue *cx= COMPLEX(frees);
TFREE(cx->dstart - cx->prespace);
if (HBYTES_ISCOMPLEX(frees)) {
HBytes_ComplexValue *cx= COMPLEX(frees);
TFREE(cx->dstart - cx->prespace);
@@
-78,7
+75,7
@@
static HBytes_ComplexValue *complex(HBytes_Value *hb) {
return cx;
}
return cx;
}
-Byte *
hbytes
_prepend(HBytes_Value *hb, int el) {
+Byte *
cht_hb
_prepend(HBytes_Value *hb, int el) {
HBytes_ComplexValue *cx;
int new_prespace;
Byte *old_block, *new_block, *new_dstart;
HBytes_ComplexValue *cx;
int new_prespace;
Byte *old_block, *new_block, *new_dstart;
@@
-101,7
+98,7
@@
Byte *hbytes_prepend(HBytes_Value *hb, int el) {
return cx->dstart;
}
return cx->dstart;
}
-Byte *
hbytes
_append(HBytes_Value *hb, int el) {
+Byte *
cht_hb
_append(HBytes_Value *hb, int el) {
HBytes_ComplexValue *cx;
int new_len, new_avail;
Byte *newpart, *new_block, *old_block;
HBytes_ComplexValue *cx;
int new_len, new_avail;
Byte *newpart, *new_block, *old_block;
@@
-121,18
+118,19
@@
Byte *hbytes_append(HBytes_Value *hb, int el) {
return newpart;
}
return newpart;
}
-HBytes_ComplexValue *prechop(HBytes_Value *hb, int cl, const Byte **rv) {
+static HBytes_ComplexValue*
+prechop(HBytes_Value *hb, int cl, const Byte **rv) {
HBytes_ComplexValue *cx;
if (cl<0) { *rv=0; return 0; }
HBytes_ComplexValue *cx;
if (cl<0) { *rv=0; return 0; }
- if (cl==0) { *rv= (const void*)&hbytes_type; return 0; }
+ if (cl==0) { *rv= (const void*)&
cht_
hbytes_type; return 0; }
cx= complex(hb);
if (cl > cx->len) { *rv=0; return 0; }
return cx;
}
cx= complex(hb);
if (cl > cx->len) { *rv=0; return 0; }
return cx;
}
-const Byte *
hbytes
_unprepend(HBytes_Value *hb, int pl) {
+const Byte *
cht_hb
_unprepend(HBytes_Value *hb, int pl) {
const Byte *chopped;
HBytes_ComplexValue *cx= prechop(hb,pl,&chopped);
if (!cx) return chopped;
const Byte *chopped;
HBytes_ComplexValue *cx= prechop(hb,pl,&chopped);
if (!cx) return chopped;
@@
-145,7
+143,7
@@
const Byte *hbytes_unprepend(HBytes_Value *hb, int pl) {
return chopped;
}
return chopped;
}
-const Byte *
hbytes
_unappend(HBytes_Value *hb, int sl) {
+const Byte *
cht_hb
_unappend(HBytes_Value *hb, int sl) {
const Byte *chopped;
HBytes_ComplexValue *cx= prechop(hb,sl,&chopped);
if (!cx) return chopped;
const Byte *chopped;
HBytes_ComplexValue *cx= prechop(hb,sl,&chopped);
if (!cx) return chopped;
@@
-153,3
+151,7
@@
const Byte *hbytes_unappend(HBytes_Value *hb, int sl) {
cx->len -= sl;
return cx->dstart + cx->len;
}
cx->len -= sl;
return cx->dstart + cx->len;
}
+
+void memxor(Byte *dest, const Byte *src, int l) {
+ while (l--) *dest++ ^= *src++;
+}