mnemonicode-0.73/mnemonic.h
changeset 35 5cab3034d3a1
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/mnemonicode-0.73/mnemonic.h	Wed Sep 02 08:41:25 2009 -0700
     1.3 @@ -0,0 +1,68 @@
     1.4 +/* mnemonic.h 
     1.5 +
     1.6 + Copyright (c) 2000  Oren Tirosh <oren@hishome.net>
     1.7 +
     1.8 + Permission is hereby granted, free of charge, to any person obtaining a copy
     1.9 + of this software and associated documentation files (the "Software"), to deal
    1.10 + in the Software without restriction, including without limitation the rights
    1.11 + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
    1.12 + copies of the Software, and to permit persons to whom the Software is
    1.13 + furnished to do so, subject to the following conditions:
    1.14 +
    1.15 + The above copyright notice and this permission notice shall be included in
    1.16 + all copies or substantial portions of the Software.
    1.17 +
    1.18 + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
    1.19 + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
    1.20 + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
    1.21 + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
    1.22 + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
    1.23 + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
    1.24 + THE SOFTWARE.
    1.25 +
    1.26 +*/
    1.27 +
    1.28 +#define MN_BASE		1626		/* cubic root of 2^32, rounded up */
    1.29 +#define MN_REMAINDER	7		/* extra words for 24 bit remainders */
    1.30 +#define MN_WORDS (MN_BASE+MN_REMAINDER)	/* total number of words */
    1.31 +#define MN_WORD_BUFLEN	25		/* size for a word buffer+headroom */
    1.32 +
    1.33 +#define MN_EOF		0		/* signal end to mn_decode_word_index */
    1.34 +
    1.35 +/* result codes */
    1.36 +#define MN_OK		0		/* decoding ok */
    1.37 +#define MN_EREM		-1		/* unexpected arithmetic remainder */
    1.38 +#define MN_EOVERRUN	-2		/* output buffer overrun */
    1.39 +#define MN_EOVERRUN24	-3		/* data after 24 bit remainder */
    1.40 +#define MN_EINDEX	-4		/* bad word index */
    1.41 +#define MN_EINDEX24	-5		/* unexpected 24 bit remainder word */
    1.42 +#define MN_EENCODING	-6		/* invalid arithmetic encoding */
    1.43 +#define MN_EWORD	-7		/* unrecognized word */
    1.44 +#define MN_EFORMAT	-8		/* bad format string */
    1.45 +
    1.46 +/* Sample formats for mn_encode */
    1.47 +#define MN_FDEFAULT 		"x-x-x--"
    1.48 +#define MN_F64BITSPERLINE	" x-x-x--x-x-x\n"
    1.49 +#define MN_F96BITSPERLINE	" x-x-x--x-x-x--x-x-x\n"
    1.50 +#define MN_F128BITSPERLINE	" x-x-x--x-x-x--x-x-x--x-x-x\n"
    1.51 +/* Note that the last format does not fit in a standard 80 character line */
    1.52 +
    1.53 +typedef unsigned char mn_byte;		/* 8 bit quantity */
    1.54 +typedef unsigned long mn_word32;	/* temporary value, at least 32 bits */
    1.55 +typedef unsigned int mn_index;		/* index into wordlist */
    1.56 +
    1.57 +extern const char *mn_words[];		/* the word list itself */
    1.58 +extern const char *mn_wordlist_version;	/* version notice string */
    1.59 +
    1.60 +int 		mn_decode (char *src, void *dest, int destsize);
    1.61 +int 		mn_encode (void *src , int srcsize, 
    1.62 +			   char *dest, int destsize, char *format);
    1.63 +
    1.64 +int 		mn_words_required (int size);
    1.65 +mn_index 	mn_encode_word_index (void *src, int srcsize, int n);
    1.66 +const char*	mn_encode_word (void *src, int srcsize, int n);
    1.67 +mn_index 	mn_next_word_index (char **ptr);
    1.68 +int 		mn_decode_word_index (mn_index index, void *dest, 
    1.69 +				     int destsize, int *offset);
    1.70 +
    1.71 +