]> git.lizzy.rs Git - plan9front.git/blobdiff - sys/man/2/encode
libc: add encode(2) variants for custom alphabets
[plan9front.git] / sys / man / 2 / encode
index db79449453dc742718351abff2f1b8389259ed99..3827e7a6e979d83f781dd671024955a8c35f3748 100644 (file)
@@ -1,6 +1,7 @@
 .TH ENCODE 2
 .SH NAME
 dec64, enc64, dec32, enc32, dec16, enc16, \
+dec64x, enc64x, dec32x, enc32x, \
 dec64chr, enc64chr, dec32chr, enc32chr, dec16chr, enc16chr, \
 encodefmt \- encoding byte arrays as strings
 .SH SYNOPSIS
@@ -12,15 +13,27 @@ encodefmt \- encoding byte arrays as strings
 int    dec64(uchar *out, int lim, char *in, int n)
 .PP
 .B
+int    dec64x(uchar *out, int lim, char *in, int n, int (*map)(int))
+.PP
+.B
 int    enc64(char *out, int lim, uchar *in, int n)
 .PP
 .B
+int    enc64x(char *out, int lim, uchar *in, int n, int (*map)(int))
+.PP
+.B
 int    dec32(uchar *out, int lim, char *in, int n)
 .PP
 .B
+int    dec32x(uchar *out, int lim, char *in, int n, int (*map)(int))
+.PP
+.B
 int    enc32(char *out, int lim, uchar *in, int n)
 .PP
 .B
+int    enc32x(char *out, int lim, uchar *in, int n, int (*map)(int))
+.PP
+.B
 int    dec16(uchar *out, int lim, char *in, int n)
 .PP
 .B
@@ -82,6 +95,31 @@ and
 .I enc64chr
 encode a symbol of the alphabet given a value.
 if the value is out of range then zero is returned.
+.PP
+The
+.I enc64x
+and
+.I enc32x
+variants are identical to the above, except that they take a
+function mapping from an arbitrary index in the alphabet to
+the encoded character.
+For example, in the following 32-character alphabet,
+.EX
+.I ABCDEFGHIJKLMNOPQRSTUVWXYZ234567
+.EE
+the chr function would map the value
+.I 3
+to the character
+.IR D .
+
+The
+.I dec64x
+and
+.I dec32x
+variants are similar to the above, however the function passed
+maps from a character within the alphabet to the index within
+the alphabet.
+
 .PP
 .I Encodefmt
 can be used with