osta.c (7e857dd14fe7f42f5b46af4904f84915215d8987) osta.c (51a7b740a11434580f649a98c2b44b98d60e4292)
1/*
2 * Various routines from the OSTA 2.01 specs. Copyrights are included with
3 * each code segment. Slight whitespace modifications have been made for
4 * formatting purposes. Typos/bugs have been fixed.
5 *
6 * $FreeBSD$
7 */
8
9#include <fs/udf/osta.h>
10
11/*****************************************************************************/
1/*
2 * Various routines from the OSTA 2.01 specs. Copyrights are included with
3 * each code segment. Slight whitespace modifications have been made for
4 * formatting purposes. Typos/bugs have been fixed.
5 *
6 * $FreeBSD$
7 */
8
9#include <fs/udf/osta.h>
10
11/*****************************************************************************/
12/*-
13 **********************************************************************
12/***********************************************************************
14 * OSTA compliant Unicode compression, uncompression routines.
15 * Copyright 1995 Micro Design International, Inc.
16 * Written by Jason M. Rinn.
17 * Micro Design International gives permission for the free use of the
18 * following source code.
19 */
20
13 * OSTA compliant Unicode compression, uncompression routines.
14 * Copyright 1995 Micro Design International, Inc.
15 * Written by Jason M. Rinn.
16 * Micro Design International gives permission for the free use of the
17 * following source code.
18 */
19
20#include <stddef.h>
21/***********************************************************************
22 * Takes an OSTA CS0 compressed unicode name, and converts
23 * it to Unicode.
24 * The Unicode output will be in the byte order
25 * that the local compiler uses for 16-bit values.
26 * NOTE: This routine only performs error checking on the compID.
27 * It is up to the user to ensure that the unicode buffer is large
28 * enough, and that the compressed unicode name is correct.

--- 40 unchanged lines hidden (view full) ---

69 }
70 unicodeIndex++;
71 }
72 returnValue = unicodeIndex;
73 }
74 return(returnValue);
75}
76
21/***********************************************************************
22 * Takes an OSTA CS0 compressed unicode name, and converts
23 * it to Unicode.
24 * The Unicode output will be in the byte order
25 * that the local compiler uses for 16-bit values.
26 * NOTE: This routine only performs error checking on the compID.
27 * It is up to the user to ensure that the unicode buffer is large
28 * enough, and that the compressed unicode name is correct.

--- 40 unchanged lines hidden (view full) ---

69 }
70 unicodeIndex++;
71 }
72 returnValue = unicodeIndex;
73 }
74 return(returnValue);
75}
76
77/*
78 * Almost same as udf_UncompressUnicode(). The difference is that
79 * it keeps byte order of unicode string.
80 */
81int
82udf_UncompressUnicodeByte(
83 int numberOfBytes, /* (Input) number of bytes read from media. */
84 byte *UDFCompressed, /* (Input) bytes read from media. */
85 byte *unicode) /* (Output) uncompressed unicode characters. */
86{
87 unsigned int compID;
88 int returnValue, unicodeIndex, byteIndex;
89
90 /* Use UDFCompressed to store current byte being read. */
91 compID = UDFCompressed[0];
92
93 /* First check for valid compID. */
94 if (compID != 8 && compID != 16) {
95 returnValue = -1;
96 } else {
97 unicodeIndex = 0;
98 byteIndex = 1;
99
100 /* Loop through all the bytes. */
101 while (byteIndex < numberOfBytes) {
102 if (compID == 16) {
103 /* Move the first byte to the high bits of the
104 * unicode char.
105 */
106 unicode[unicodeIndex++] =
107 UDFCompressed[byteIndex++];
108 } else {
109 unicode[unicodeIndex++] = 0;
110 }
111 if (byteIndex < numberOfBytes) {
112 /*Then the next byte to the low bits. */
113 unicode[unicodeIndex++] =
114 UDFCompressed[byteIndex++];
115 }
116 }
117 returnValue = unicodeIndex;
118 }
119 return(returnValue);
120}
121
122/***********************************************************************
123 * DESCRIPTION:
124 * Takes a string of unicode wide characters and returns an OSTA CS0
125 * compressed unicode string. The unicode MUST be in the byte order of
126 * the compiler in order to obtain correct results. Returns an error
127 * if the compression ID is invalid.
128 *
129 * NOTE: This routine assumes the implementation already knows, by

--- 119 unchanged lines hidden (view full) ---

249 x = cksum(bytes, sizeof bytes);
250 printf("checksum: calculated=%4.4x, correct=%4.4x\en", x, 0x3299);
251 exit(0);
252}
253#endif
254
255/*****************************************************************************/
256#ifdef NEEDS_ISPRINT
77/***********************************************************************
78 * DESCRIPTION:
79 * Takes a string of unicode wide characters and returns an OSTA CS0
80 * compressed unicode string. The unicode MUST be in the byte order of
81 * the compiler in order to obtain correct results. Returns an error
82 * if the compression ID is invalid.
83 *
84 * NOTE: This routine assumes the implementation already knows, by

--- 119 unchanged lines hidden (view full) ---

204 x = cksum(bytes, sizeof bytes);
205 printf("checksum: calculated=%4.4x, correct=%4.4x\en", x, 0x3299);
206 exit(0);
207}
208#endif
209
210/*****************************************************************************/
211#ifdef NEEDS_ISPRINT
257/*-
258 **********************************************************************
212/***********************************************************************
259 * OSTA UDF compliant file name translation routine for OS/2,
260 * Windows 95, Windows NT, Macintosh and UNIX.
261 * Copyright 1995 Micro Design International, Inc.
262 * Written by Jason M. Rinn.
263 * Micro Design International gives permission for the free use of the
264 * following source code.
265 */
266

--- 8 unchanged lines hidden (view full) ---

275 * Define WIN_95
276 * Define MAXLEN = 255
277 *
278 * Windows NT
279 * Define WIN_NT
280 * Define MAXLEN = 255
281 *
282 * Macintosh:
213 * OSTA UDF compliant file name translation routine for OS/2,
214 * Windows 95, Windows NT, Macintosh and UNIX.
215 * Copyright 1995 Micro Design International, Inc.
216 * Written by Jason M. Rinn.
217 * Micro Design International gives permission for the free use of the
218 * following source code.
219 */
220

--- 8 unchanged lines hidden (view full) ---

229 * Define WIN_95
230 * Define MAXLEN = 255
231 *
232 * Windows NT
233 * Define WIN_NT
234 * Define MAXLEN = 255
235 *
236 * Macintosh:
283 * Define APPLE_MAC.
237 * Define MAC.
284 * Define MAXLEN = 31.
285 *
286 * UNIX
287 * Define UNIX.
288 * Define MAXLEN as specified by unix version.
289 */
290
291#define ILLEGAL_CHAR_MARK 0x005F

--- 187 unchanged lines hidden (view full) ---

479 * Decides whether the given character is illegal for a given OS.
480 *
481 * RETURN VALUE
482 *
483 * Non-zero if char is illegal.
484 */
485int IsIllegal(unicode_t ch)
486{
238 * Define MAXLEN = 31.
239 *
240 * UNIX
241 * Define UNIX.
242 * Define MAXLEN as specified by unix version.
243 */
244
245#define ILLEGAL_CHAR_MARK 0x005F

--- 187 unchanged lines hidden (view full) ---

433 * Decides whether the given character is illegal for a given OS.
434 *
435 * RETURN VALUE
436 *
437 * Non-zero if char is illegal.
438 */
439int IsIllegal(unicode_t ch)
440{
487#ifdef APPLE_MAC
441#ifdef MAC
488 /* Only illegal character on the MAC is the colon. */
489 if (ch == 0x003A) {
490 return(1);
491 } else {
492 return(0);
493 }
494
495#elif defined UNIX

--- 17 unchanged lines hidden ---
442 /* Only illegal character on the MAC is the colon. */
443 if (ch == 0x003A) {
444 return(1);
445 } else {
446 return(0);
447 }
448
449#elif defined UNIX

--- 17 unchanged lines hidden ---