ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

infhostrtl.c
Go to the documentation of this file.
00001 /*
00002  * PROJECT:    .inf file parser
00003  * LICENSE:    GPL - See COPYING in the top level directory
00004  * PROGRAMMER: Royce Mitchell III
00005  *             Eric Kohl
00006  *             Ge van Geldorp <gvg@reactos.org>
00007  */
00008 
00009 /* INCLUDES *****************************************************************/
00010 
00011 #include "inflib.h"
00012 #include "infhost.h"
00013 
00014 #define NDEBUG
00015 #include <debug.h>
00016 
00017 NTSTATUS NTAPI
00018 RtlMultiByteToUnicodeN(
00019    IN PWCHAR UnicodeString,
00020    IN ULONG UnicodeSize,
00021    IN PULONG ResultSize,
00022    IN PCSTR MbString,
00023    IN ULONG MbSize)
00024 {
00025     ULONG Size = 0;
00026     ULONG i;
00027     PUCHAR WideString;
00028 
00029     /* single-byte code page */
00030     if (MbSize > (UnicodeSize / sizeof(WCHAR)))
00031         Size = UnicodeSize / sizeof(WCHAR);
00032     else
00033         Size = MbSize;
00034 
00035     if (ResultSize != NULL)
00036         *ResultSize = Size * sizeof(WCHAR);
00037 
00038     WideString = (PUCHAR)UnicodeString;
00039     for (i = 0; i < Size; i++)
00040     {
00041         WideString[2 * i + 0] = (UCHAR)MbString[i];
00042         WideString[2 * i + 1] = 0;
00043     }
00044 
00045     return STATUS_SUCCESS;
00046 }
00047 
00048 
00049 BOOLEAN
00050 NTAPI
00051 RtlIsTextUnicode( PVOID buf, INT len, INT *pf )
00052 {
00053     static const WCHAR std_control_chars[] = {'\r','\n','\t',' ',0x3000,0};
00054     static const WCHAR byterev_control_chars[] = {0x0d00,0x0a00,0x0900,0x2000,0};
00055     const WCHAR *s = buf;
00056     int i;
00057     unsigned int flags = MAXULONG, out_flags = 0;
00058 
00059     if (len < sizeof(WCHAR))
00060     {
00061         /* FIXME: MSDN documents IS_TEXT_UNICODE_BUFFER_TOO_SMALL but there is no such thing... */
00062         if (pf) *pf = 0;
00063         return FALSE;
00064     }
00065     if (pf)
00066         flags = (unsigned int)*pf;
00067     /*
00068      * Apply various tests to the text string. According to the
00069      * docs, each test "passed" sets the corresponding flag in
00070      * the output flags. But some of the tests are mutually
00071      * exclusive, so I don't see how you could pass all tests ...
00072      */
00073 
00074     /* Check for an odd length ... pass if even. */
00075     if (len & 1) out_flags |= IS_TEXT_UNICODE_ODD_LENGTH;
00076 
00077     if (((char *)buf)[len - 1] == 0)
00078         len--;  /* Windows seems to do something like that to avoid e.g. false IS_TEXT_UNICODE_NULL_BYTES  */
00079 
00080     len /= (INT)sizeof(WCHAR);
00081     /* Windows only checks the first 256 characters */
00082     if (len > 256) len = 256;
00083 
00084     /* Check for the special byte order unicode marks. */
00085     if (*s == 0xFEFF) out_flags |= IS_TEXT_UNICODE_SIGNATURE;
00086     if (*s == 0xFFFE) out_flags |= IS_TEXT_UNICODE_REVERSE_SIGNATURE;
00087 
00088     /* apply some statistical analysis */
00089     if (flags & IS_TEXT_UNICODE_STATISTICS)
00090     {
00091         int stats = 0;
00092         /* FIXME: checks only for ASCII characters in the unicode stream */
00093         for (i = 0; i < len; i++)
00094         {
00095             if (s[i] <= 255) stats++;
00096         }
00097         if (stats > len / 2)
00098             out_flags |= IS_TEXT_UNICODE_STATISTICS;
00099     }
00100 
00101     /* Check for unicode NULL chars */
00102     if (flags & IS_TEXT_UNICODE_NULL_BYTES)
00103     {
00104         for (i = 0; i < len; i++)
00105         {
00106             if (!(s[i] & 0xff) || !(s[i] >> 8))
00107             {
00108                 out_flags |= IS_TEXT_UNICODE_NULL_BYTES;
00109                 break;
00110             }
00111         }
00112     }
00113 
00114     if (flags & IS_TEXT_UNICODE_CONTROLS)
00115     {
00116         for (i = 0; i < len; i++)
00117         {
00118             if (strchrW(std_control_chars, s[i]))
00119             {
00120                 out_flags |= IS_TEXT_UNICODE_CONTROLS;
00121                 break;
00122             }
00123         }
00124     }
00125 
00126     if (flags & IS_TEXT_UNICODE_REVERSE_CONTROLS)
00127     {
00128         for (i = 0; i < len; i++)
00129         {
00130             if (strchrW(byterev_control_chars, s[i]))
00131             {
00132                 out_flags |= IS_TEXT_UNICODE_REVERSE_CONTROLS;
00133                 break;
00134             }
00135         }
00136     }
00137 
00138     if (pf)
00139     {
00140         out_flags &= (unsigned int)*pf;
00141         *pf = (INT)out_flags;
00142     }
00143     /* check for flags that indicate it's definitely not valid Unicode */
00144     if (out_flags & (IS_TEXT_UNICODE_REVERSE_MASK | IS_TEXT_UNICODE_NOT_UNICODE_MASK)) return FALSE;
00145     /* now check for invalid ASCII, and assume Unicode if so */
00146     if (out_flags & IS_TEXT_UNICODE_NOT_ASCII_MASK) return TRUE;
00147     /* now check for Unicode flags */
00148     if (out_flags & IS_TEXT_UNICODE_UNICODE_MASK) return TRUE;
00149     /* no flags set */
00150     return FALSE;
00151 }

Generated on Sun May 27 2012 04:36:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.