mnemonicode-0.73/mnemonic.h
author Jens Alfke <jens@mooseyard.com>
Wed Sep 02 08:41:25 2009 -0700 (2009-09-02)
changeset 35 5cab3034d3a1
permissions -rw-r--r--
10.6 compatibility: Fix some new compiler warnings, and work around apparent regressions in NSTask and -stringByStandardizingPath.
jens@0
     1
/* mnemonic.h 
jens@0
     2
jens@0
     3
 Copyright (c) 2000  Oren Tirosh <oren@hishome.net>
jens@0
     4
jens@0
     5
 Permission is hereby granted, free of charge, to any person obtaining a copy
jens@0
     6
 of this software and associated documentation files (the "Software"), to deal
jens@0
     7
 in the Software without restriction, including without limitation the rights
jens@0
     8
 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
jens@0
     9
 copies of the Software, and to permit persons to whom the Software is
jens@0
    10
 furnished to do so, subject to the following conditions:
jens@0
    11
jens@0
    12
 The above copyright notice and this permission notice shall be included in
jens@0
    13
 all copies or substantial portions of the Software.
jens@0
    14
jens@0
    15
 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
jens@0
    16
 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
jens@0
    17
 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
jens@0
    18
 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
jens@0
    19
 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
jens@0
    20
 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
jens@0
    21
 THE SOFTWARE.
jens@0
    22
jens@0
    23
*/
jens@0
    24
jens@0
    25
#define MN_BASE		1626		/* cubic root of 2^32, rounded up */
jens@0
    26
#define MN_REMAINDER	7		/* extra words for 24 bit remainders */
jens@0
    27
#define MN_WORDS (MN_BASE+MN_REMAINDER)	/* total number of words */
jens@0
    28
#define MN_WORD_BUFLEN	25		/* size for a word buffer+headroom */
jens@0
    29
jens@0
    30
#define MN_EOF		0		/* signal end to mn_decode_word_index */
jens@0
    31
jens@0
    32
/* result codes */
jens@0
    33
#define MN_OK		0		/* decoding ok */
jens@0
    34
#define MN_EREM		-1		/* unexpected arithmetic remainder */
jens@0
    35
#define MN_EOVERRUN	-2		/* output buffer overrun */
jens@0
    36
#define MN_EOVERRUN24	-3		/* data after 24 bit remainder */
jens@0
    37
#define MN_EINDEX	-4		/* bad word index */
jens@0
    38
#define MN_EINDEX24	-5		/* unexpected 24 bit remainder word */
jens@0
    39
#define MN_EENCODING	-6		/* invalid arithmetic encoding */
jens@0
    40
#define MN_EWORD	-7		/* unrecognized word */
jens@0
    41
#define MN_EFORMAT	-8		/* bad format string */
jens@0
    42
jens@0
    43
/* Sample formats for mn_encode */
jens@0
    44
#define MN_FDEFAULT 		"x-x-x--"
jens@0
    45
#define MN_F64BITSPERLINE	" x-x-x--x-x-x\n"
jens@0
    46
#define MN_F96BITSPERLINE	" x-x-x--x-x-x--x-x-x\n"
jens@0
    47
#define MN_F128BITSPERLINE	" x-x-x--x-x-x--x-x-x--x-x-x\n"
jens@0
    48
/* Note that the last format does not fit in a standard 80 character line */
jens@0
    49
jens@0
    50
typedef unsigned char mn_byte;		/* 8 bit quantity */
jens@0
    51
typedef unsigned long mn_word32;	/* temporary value, at least 32 bits */
jens@0
    52
typedef unsigned int mn_index;		/* index into wordlist */
jens@0
    53
jens@0
    54
extern const char *mn_words[];		/* the word list itself */
jens@0
    55
extern const char *mn_wordlist_version;	/* version notice string */
jens@0
    56
jens@0
    57
int 		mn_decode (char *src, void *dest, int destsize);
jens@0
    58
int 		mn_encode (void *src , int srcsize, 
jens@0
    59
			   char *dest, int destsize, char *format);
jens@0
    60
jens@0
    61
int 		mn_words_required (int size);
jens@0
    62
mn_index 	mn_encode_word_index (void *src, int srcsize, int n);
jens@0
    63
const char*	mn_encode_word (void *src, int srcsize, int n);
jens@0
    64
mn_index 	mn_next_word_index (char **ptr);
jens@0
    65
int 		mn_decode_word_index (mn_index index, void *dest, 
jens@0
    66
				     int destsize, int *offset);
jens@0
    67
jens@0
    68