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