* hbytes raw2h BINARY => hex
* hbytes h2raw HEX => binary
*
- * hbytes prefix VAR [VALUE ...] = set VAR [concat VALUE ... $VAR]
- * hbytes append VAR [VALUE ...] = set VAR [concat $VAR VALUE ...]
- * hbytes concat VAR [VALUE ...] = set VAR [concat VALUE ...]
+ * hbytes prepend VAR [VALUE ...] = set VAR [concat VALUE ... $VAR]
+ * hbytes append VAR [VALUE ...] = set VAR [concat $VAR VALUE ...]
+ * hbytes concat VAR [VALUE ...] = set VAR [concat VALUE ...]
* hbytes unprepend VAR PREFIXLENGTH => prefix (removed from VAR)
* hbytes unappend VAR SUFFIXLENGTH => suffix (removed from VAR)
* hbytes chopto VAR NEWVARLENGTH => suffix (removed from VAR)
return TCL_OK;
}
+int pat_int(Tcl_Interp *ip, Tcl_Obj *obj, int *val) {
+ return Tcl_GetIntFromObj(ip, obj, val);
+}
+
int pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) {
int rc;
Tcl_Obj *val;
Tcl_Obj *ret_hb(Tcl_Interp *ip, HBytes_Value val) {
return hbytes_set_obj(0, val.start, HBYTES_LEN(val));
}
+
+Tcl_Obj *ret_obj(Tcl_Interp *ip, Tcl_Obj *val) {
+ return val;
+}
+
+void setstringresult(Tcl_Interp *ip, const char *m) {
+ Tcl_ResetResult(ip);
+ Tcl_AppendResult(ip, m, (char*)0);
+}
h2raw
hex hb
=> obj
- prefix
- v hbv
- str ...
- append
- v hbv
- str ...
- concat
- v hbv
- str ...
- unprepend
- v hbv
- length int
- => hb
- unappend
- v hbv
- length int
- => hb
- chopto
- v hbv
- length int
- => hb
- pkcs5
- meth enum(PadMethod, "hbytes pad subcommand")
- obj ...
- blockcipher
- encrypt charfrom("de","encrypt/decrypt")
- v hbv
- alg enum(BlockCipherAlgInfo, "alg")
- mode enum(BlockCipherModeInfo, "mode")
- ?iv hb
- => hb
- hash
- alg enum(HashAlgInfo, "hash alg")
- message hb
- => hb
- hmac
- alg enum(HashAlgInfo, "hash alg for hmac")
- message hb
- key hb
- maclen int
+ prepend
+ v hbv
+ str ...
+ append
+ v hbv
+ str ...
+ concat
+ str ...
=> hb
+# unprepend
+# v hbv
+# length int
+# => hb
+# unappend
+# v hbv
+# length int
+# => hb
+# chopto
+# v hbv
+# length int
+# => hb
+# pkcs5
+# meth enum(PadMethod, "hbytes pad subcommand")
+# obj ...
+# blockcipher
+# encrypt charfrom("de","encrypt/decrypt")
+# v hbv
+# alg enum(BlockCipherAlgInfo, "alg")
+# mode enum(BlockCipherModeInfo, "mode")
+# ?iv hb
+# => hb
+# hash
+# alg enum(HashAlgInfo, "hash alg")
+# message hb
+# => hb
+# hmac
+# alg enum(HashAlgInfo, "hash alg for hmac")
+# message hb
+# key hb
+# maclen int
+# => hb
-Table padmethod PadMethod
- pa 1, 0
+#Table padmethod PadMethod
+# pa 1, 0
-EntryExtra PadMethod
- int pad, algname;
+#EntryExtra PadMethod
+# int pad, algname;
chomp; s/\s+$//;
next if m/^\s*\#/;
next if !m/\S/;
- s/\t/ ' 'x(8-(length $`) % 8) /eg;
+ while (s/\t/ ' 'x(8 - (length $`) % 8) /e) { }
s/^\s*//;
$this_indent= length $&;
$pa_body .= " if (!objc--) goto end_optional;\n";
$any_optl= 1;
} else {
+ die if $any_optl;
$any_mand++;
}
$paarg= "&a_$n";
push @do_aa, "a_$n";
}
if (exists $r_entry->{V}) {
+ if ($any_mand) {
+ $pa_body .= " objc -= $any_mand;\n";
+ }
$va= $r_entry->{V};
push @do_al, subst_in_decl("${va}c", 'int @');
push @do_al, subst_in_decl("${va}v", 'Tcl_Obj *const *@');
- push @do_aa, "objc-1", "objv+1";
+ push @do_aa, "objc+1", "objv-1";
} else {
- $pa_body .= " if (--objc) { e=\"too many args\"; goto e_err; }\n";
- $any_eerr= 1;
+ if (!$any_optl) {
+ $pa_argc .= " if (objc != $any_mand) {".
+ " e=\"wrong number of args\"; goto e_err; }\n";
+ $any_eerr= 1;
+ }
}
if ($any_optl) {
$pa_body .= "end_optional:\n";
OBJS= tables.o \
hbytes.o \
enum.o \
+ chop.o \
parse.o
HDRS= hbytes.h \
--- /dev/null
+/*
+ */
+
+#include <string.h>
+
+#include "hbytes.h"
+
+static int strs(Tcl_Interp *ip, int strc, Tcl_Obj *const *strv, int *l_r) {
+ int rc, l, i;
+
+ l= 0;
+ for (i=1; i<strc; i++) {
+ rc= Tcl_ConvertToType(ip,strv[i],&hbytes_type);
+ if (rc) return rc;
+ l += HBYTES_LEN(HBYTES(strv[i]));
+ }
+ *l_r= l;
+ return TCL_OK;
+}
+
+int app_pre(ClientData cd, Tcl_Interp *ip, int begin,
+ HBytes_Var v, int strc, Tcl_Obj *const *strv) {
+ int ol, rc, al, i, tl;
+
+ rc= strs(ip,strc,strv,&al); if (rc) return rc;
+
+ ol= HBYTES_LEN(*v.hb);
+ v.hb->start= v.hb->end= Tcl_Realloc(v.hb->start, ol + al);
+
+ if (begin) v.hb->end += ol;
+ else memmove(v.hb->start + al, v.hb->start, ol);
+
+ for (i=1; i<strc; i++) {
+ tl= HBYTES_LEN(HBYTES(strv[i]));
+ memcpy(v.hb->end, HBYTES(strv[i]).start, tl);
+ v.hb->end += tl;
+ }
+ return TCL_OK;
+}
+
+int do_hbytes_append(ClientData cd, Tcl_Interp *ip,
+ HBytes_Var v, int strc, Tcl_Obj *const *strv) {
+ return app_pre(cd,ip,1,v,strc,strv);
+}
+
+int do_hbytes_prepend(ClientData cd, Tcl_Interp *ip,
+ HBytes_Var v, int strc, Tcl_Obj *const *strv) {
+ return app_pre(cd,ip,0,v,strc,strv);
+}
+
+int do_hbytes_concat(ClientData cd, Tcl_Interp *ip,
+ int strc, Tcl_Obj *const *strv, HBytes_Value *result) {
+ HBytes_Var fake;
+
+ result->start= result->end= 0;
+ fake.hb= result;
+ return app_pre(cd,ip,1,fake,strc,strv);
+}
+
* hbytes raw2h BINARY => hex
* hbytes h2raw HEX => binary
*
- * hbytes prefix VAR [VALUE ...] = set VAR [concat VALUE ... $VAR]
- * hbytes append VAR [VALUE ...] = set VAR [concat $VAR VALUE ...]
- * hbytes concat VAR [VALUE ...] = set VAR [concat VALUE ...]
+ * hbytes prepend VAR [VALUE ...] = set VAR [concat VALUE ... $VAR]
+ * hbytes append VAR [VALUE ...] = set VAR [concat $VAR VALUE ...]
+ * hbytes concat VAR [VALUE ...] = set VAR [concat VALUE ...]
* hbytes unprepend VAR PREFIXLENGTH => prefix (removed from VAR)
* hbytes unappend VAR SUFFIXLENGTH => suffix (removed from VAR)
* hbytes chopto VAR NEWVARLENGTH => suffix (removed from VAR)
return TCL_OK;
}
+int pat_int(Tcl_Interp *ip, Tcl_Obj *obj, int *val) {
+ return Tcl_GetIntFromObj(ip, obj, val);
+}
+
int pat_hbv(Tcl_Interp *ip, Tcl_Obj *var, HBytes_Var *agg) {
int rc;
Tcl_Obj *val;
Tcl_Obj *ret_hb(Tcl_Interp *ip, HBytes_Value val) {
return hbytes_set_obj(0, val.start, HBYTES_LEN(val));
}
+
+Tcl_Obj *ret_obj(Tcl_Interp *ip, Tcl_Obj *val) {
+ return val;
+}
+
+void setstringresult(Tcl_Interp *ip, const char *m) {
+ Tcl_ResetResult(ip);
+ Tcl_AppendResult(ip, m, (char*)0);
+}