diff options
author | Pedro Martelletto <pedro@cvs.openbsd.org> | 2005-03-30 01:06:50 +0000 |
---|---|---|
committer | Pedro Martelletto <pedro@cvs.openbsd.org> | 2005-03-30 01:06:50 +0000 |
commit | e66a312218b6d0be7728c42c2397bc0259a5e339 (patch) | |
tree | 2a47f678915eb8fee18beb3078add02c68646863 /sys/isofs | |
parent | 9ad16ca76bea66a3c14f2aeb246fbc0e822319e4 (diff) |
Better code in the OSTA CS0 compression/decompression routines.
Diffstat (limited to 'sys/isofs')
-rw-r--r-- | sys/isofs/udf/osta.c | 136 |
1 files changed, 65 insertions, 71 deletions
diff --git a/sys/isofs/udf/osta.c b/sys/isofs/udf/osta.c index 3fc07b6e0ba..30ff2114f42 100644 --- a/sys/isofs/udf/osta.c +++ b/sys/isofs/udf/osta.c @@ -1,4 +1,4 @@ -/* $OpenBSD: osta.c,v 1.1 2005/03/29 17:24:52 pedro Exp $ */ +/* $OpenBSD: osta.c,v 1.2 2005/03/30 01:06:49 pedro Exp $ */ /* * Various routines from the OSTA 2.01 specs. Copyrights are included with @@ -41,39 +41,36 @@ udf_UncompressUnicode( unicode_t *unicode) /* (Output) uncompressed unicode characters. */ { unsigned int compID; - int returnValue, unicodeIndex, byteIndex; + int unicodeIndex, byteIndex; /* Use UDFCompressed to store current byte being read. */ compID = UDFCompressed[0]; /* First check for valid compID. */ - if (compID != 8 && compID != 16) { - returnValue = -1; - } else { - unicodeIndex = 0; - byteIndex = 1; - - /* Loop through all the bytes. */ - while (byteIndex < numberOfBytes) { - if (compID == 16) { - /* Move the first byte to the high bits of the - * unicode char. - */ - unicode[unicodeIndex] = - UDFCompressed[byteIndex++] << 8; - } else { - unicode[unicodeIndex] = 0; - } - if (byteIndex < numberOfBytes) { - /*Then the next byte to the low bits. */ - unicode[unicodeIndex] |= - UDFCompressed[byteIndex++]; - } - unicodeIndex++; + if (compID != 8 && compID != 16) + return (-1); + + unicodeIndex = 0; + byteIndex = 1; + + /* Loop through all the bytes. */ + while (byteIndex < numberOfBytes) { + if (compID == 16) { + /* + * Move the first byte to the high + * bits of the unicode char. + */ + unicode[unicodeIndex] = UDFCompressed[byteIndex++] << 8; + } else { + unicode[unicodeIndex] = 0; + } + if (byteIndex < numberOfBytes) { + /* Then the next byte to the low bits. */ + unicode[unicodeIndex] |= UDFCompressed[byteIndex++]; } - returnValue = unicodeIndex; + unicodeIndex++; } - return(returnValue); + return (unicodeIndex); } /* @@ -87,38 +84,35 @@ udf_UncompressUnicodeByte( byte *unicode) /* (Output) uncompressed unicode characters. */ { unsigned int compID; - int returnValue, unicodeIndex, byteIndex; + int unicodeIndex, byteIndex; /* Use UDFCompressed to store current byte being read. */ compID = UDFCompressed[0]; /* First check for valid compID. */ - if (compID != 8 && compID != 16) { - returnValue = -1; - } else { - unicodeIndex = 0; - byteIndex = 1; - - /* Loop through all the bytes. */ - while (byteIndex < numberOfBytes) { - if (compID == 16) { - /* Move the first byte to the high bits of the - * unicode char. - */ - unicode[unicodeIndex++] = - UDFCompressed[byteIndex++]; - } else { - unicode[unicodeIndex++] = 0; - } - if (byteIndex < numberOfBytes) { - /*Then the next byte to the low bits. */ - unicode[unicodeIndex++] = - UDFCompressed[byteIndex++]; - } + if (compID != 8 && compID != 16) + return (-1); + + unicodeIndex = 0; + byteIndex = 1; + + /* Loop through all the bytes. */ + while (byteIndex < numberOfBytes) { + if (compID == 16) { + /* + * Move the first byte to the high + * bits of the unicode char. + */ + unicode[unicodeIndex++] = UDFCompressed[byteIndex++]; + } else { + unicode[unicodeIndex++] = 0; + } + if (byteIndex < numberOfBytes) { + /* Then the next byte to the low bits. */ + unicode[unicodeIndex++] = UDFCompressed[byteIndex++]; } - returnValue = unicodeIndex; } - return(returnValue); + return (unicodeIndex); } /*********************************************************************** @@ -148,27 +142,27 @@ udf_CompressUnicode( { int byteIndex, unicodeIndex; - if (compID != 8 && compID != 16) { - byteIndex = -1; /* Unsupported compression ID ! */ - } else { - /* Place compression code in first byte. */ - UDFCompressed[0] = compID; - - byteIndex = 1; - unicodeIndex = 0; - while (unicodeIndex < numberOfChars) { - if (compID == 16) { - /* First, place the high bits of the char - * into the byte stream. - */ - UDFCompressed[byteIndex++] = - (unicode[unicodeIndex] & 0xFF00) >> 8; - } - /*Then place the low bits into the stream. */ + if (compID != 8 && compID != 16) + return (-1); /* Unsupported compression ID ! */ + + /* Place compression code in first byte. */ + UDFCompressed[0] = compID; + + byteIndex = 1; + unicodeIndex = 0; + + while (unicodeIndex < numberOfChars) { + if (compID == 16) { + /* + * First, place the high bits of + * the char into the byte stream. + */ UDFCompressed[byteIndex++] = - unicode[unicodeIndex] & 0x00FF; - unicodeIndex++; + (unicode[unicodeIndex] & 0xFF00) >> 8; } + /* Then place the low bits into the stream. */ + UDFCompressed[byteIndex++] = unicode[unicodeIndex] & 0x00FF; + unicodeIndex++; } return(byteIndex); } |