Exemplo n.º 1
0
 private void DoNegAOORTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
 {
     Assert.Throws <ArgumentOutOfRangeException>(() =>
     {
         ascii.GetCharCount(bytes, index, count);
     });
 }
Exemplo n.º 2
0
    public static void Main()
    {
        Char[] chars;
        Byte[] bytes = new Byte[] {
            65, 83, 67, 73, 73, 32, 69,
            110, 99, 111, 100, 105, 110, 103,
            32, 69, 120, 97, 109, 112, 108, 101
        };

        ASCIIEncoding ascii = new ASCIIEncoding();

        int charCount = ascii.GetCharCount(bytes, 6, 8);

        chars = new Char[charCount];
        int charsDecodedCount = ascii.GetChars(bytes, 6, 8, chars, 0);

        Console.WriteLine(
            "{0} characters used to decode bytes.", charsDecodedCount
            );

        Console.Write("Decoded chars: ");
        foreach (Char c in chars)
        {
            Console.Write("[{0}]", c);
        }
        Console.WriteLine();
    }
 private void DoPosTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
 {
     int actualValue;
     ascii = new ASCIIEncoding();
     actualValue = ascii.GetCharCount(bytes, index, count);
     Assert.Equal(count, actualValue);
 }
Exemplo n.º 4
0
        private void DoPosTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
        {
            int actualValue;

            ascii       = new ASCIIEncoding();
            actualValue = ascii.GetCharCount(bytes, index, count);
            Assert.Equal(count, actualValue);
        }
Exemplo n.º 5
0
        public void NegTest5()
        {
            ASCIIEncoding ascii = new ASCIIEncoding();

            byte[] bytes = null;
            Assert.Throws <ArgumentNullException>(() =>
            {
                ascii.GetCharCount(bytes, 0, 0);
            });
        }
        public int GetCharCount()
        {
            int retVal = 0;

            foreach (byte[] bytes in _bytesOfBytesAllAscii)
            {
                retVal += _asciiEncodingErrorFallback.GetCharCount(bytes);
            }

            return(retVal);
        }
Exemplo n.º 7
0
        public void GetCharCountTest()
        {
            ASCIIEncoding target = new ASCIIEncoding(); // TODO: Initialize to an appropriate value

            byte[] bytes    = null;                     // TODO: Initialize to an appropriate value
            int    index    = 0;                        // TODO: Initialize to an appropriate value
            int    count    = 0;                        // TODO: Initialize to an appropriate value
            int    expected = 0;                        // TODO: Initialize to an appropriate value
            int    actual;

            actual = target.GetCharCount(bytes, index, count);
            Assert.AreEqual(expected, actual);
            Assert.Inconclusive("Verify the correctness of this test method.");
        }
Exemplo n.º 8
0
        public static string FromBase64String(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return(string.Empty);
            }
            //System.Diagnostics.Contracts.Contract.Assert(str != String.Empty, "str cannot be empty");
            ////str = (isUrlSafe) ? FromBase64UrlSafeString(str) : str;
            ASCIIEncoding AE = new ASCIIEncoding();

            char[] carr = new char[AE.GetCharCount(Convert.FromBase64String(str))];
            AE.GetChars(Convert.FromBase64String(str), 0, Convert.FromBase64String(str).Length, carr, 0);
            return(new string(carr));
        }
Exemplo n.º 9
0
    public static void Main()
    {
        Byte[] bytes = new Byte[] {
            65, 83, 67, 73, 73, 32, 69,
            110, 99, 111, 100, 105, 110, 103,
            32, 69, 120, 97, 109, 112, 108, 101
        };

        ASCIIEncoding ascii     = new ASCIIEncoding();
        int           charCount = ascii.GetCharCount(bytes, 6, 8);

        Console.WriteLine(
            "{0} characters needed to decode bytes.", charCount
            );
    }
Exemplo n.º 10
0
        // Read the table of contents of the ARC file
        private void ReadARCToC()
        {
            // Format of an ARC file
            // 0x08 - 4 bytes = # of files
            // 0x0C - 4 bytes = # of parts
            // 0x18 - 4 bytes = offset to directory structure
            //
            // Format of directory structure
            // 4-byte int = offset in file where this part begins
            // 4-byte int = size of compressed part
            // 4-byte int = size of uncompressed part
            // these triplets repeat for each part in the arc file
            // After these triplets are a bunch of null-terminated strings
            // which are the sub filenames.
            // After the subfilenames comes the subfile data:
            // 4-byte int = 3 == indicates start of subfile item  (maybe compressed flag??)
            //				1 == maybe uncompressed flag??
            // 4-byte int = offset in file where first part of this subfile begins
            // 4-byte int = compressed size of this file
            // 4-byte int = uncompressed size of this file
            // 4-byte crap
            // 4-byte crap
            // 4-byte crap
            // 4-byte int = numParts this file uses
            // 4-byte int = part# of first part for this file (starting at 0).
            // 4-byte int = length of filename string
            // 4-byte int = offset in directory structure for filename

            m_fileHasBeenRead = true;

            try {
                FileStream   arcFile = new FileStream(m_filename, FileMode.Open, FileAccess.Read);
                BinaryReader reader  = new BinaryReader(arcFile);
                try
                {
                    // check the file header
                    if (reader.ReadByte() != 0x41)
                    {
                        return;                                         // A
                    }
                    if (reader.ReadByte() != 0x52)
                    {
                        return;                                         // R
                    }
                    if (reader.ReadByte() != 0x43)
                    {
                        return;                                         // C
                    }
                    if (arcFile.Length < 0x21)
                    {
                        return;
                    }

                    reader.BaseStream.Seek(0x08, SeekOrigin.Begin);
                    int numEntries = reader.ReadInt32();
                    int numParts   = reader.ReadInt32();

                    ARCPartEntry[] parts   = new ARCPartEntry[numParts];
                    ARCDirEntry[]  records = new ARCDirEntry[numEntries];

                    reader.BaseStream.Seek(0x18, SeekOrigin.Begin);
                    int tocOffset = reader.ReadInt32();

                    if (arcFile.Length < (tocOffset + 4 * 3))
                    {
                        return;
                    }

                    // Read in all of the part data
                    reader.BaseStream.Seek(tocOffset, SeekOrigin.Begin);
                    int i;
                    for (i = 0; i < numParts; ++i)
                    {
                        parts[i]                = new ARCPartEntry();
                        parts[i].fileOffset     = reader.ReadInt32();
                        parts[i].compressedSize = reader.ReadInt32();
                        parts[i].realSize       = reader.ReadInt32();
                    }

                    // Now record this offset so we can come back and read in the filenames after we have
                    // read in the file records
                    int fileNamesOffset = (int)arcFile.Position;
                    // Now seek to the location where the file record data is
                    // This offset is from the end of the file.
                    int fileRecordOffset = 44 * numEntries;

                    arcFile.Seek(-1 * fileRecordOffset, SeekOrigin.End);
                    for (i = 0; i < numEntries; ++i)
                    {
                        records[i] = new ARCDirEntry();
                        int storageType = reader.ReadInt32();                     // storageType = 3 - compressed / 1- non compressed

                        // Added by VillageIdiot to support stored types
                        records[i].storageType    = storageType;
                        records[i].fileOffset     = reader.ReadInt32();
                        records[i].compressedSize = reader.ReadInt32();
                        records[i].realSize       = reader.ReadInt32();
                        int crap = reader.ReadInt32();             // crap

                        crap = reader.ReadInt32();                 // crap
                        crap = reader.ReadInt32();                 // crap

                        int np = reader.ReadInt32();
                        if (np < 1)
                        {
                            records[i].parts = null;
                        }
                        else
                        {
                            records[i].parts = new ARCPartEntry[np];
                        }

                        int firstPart = reader.ReadInt32();
                        crap = reader.ReadInt32();                 // filename length

                        crap = reader.ReadInt32();                 // filename offset

                        if (storageType != 1 && records[i].IsActive)
                        {
                            for (int ip = 0; ip < records[i].parts.Length; ++ip)
                            {
                                records[i].parts[ip] = parts[ip + firstPart];
                            }
                        }
                    }

                    // Now read in the record names
                    arcFile.Seek(fileNamesOffset, SeekOrigin.Begin);
                    byte[]        buffer = new byte[2048];
                    ASCIIEncoding ascii  = new ASCIIEncoding();
                    for (i = 0; i < numEntries; ++i)
                    {
                        // only Active files have a filename entry
                        if (records[i].IsActive)
                        {
                            // For each string, read bytes until I hit a 0x00 byte.
                            int bufSize = 0;

                            while ((buffer[bufSize++] = reader.ReadByte()) != 0x00)
                            {
                                if (buffer[bufSize - 1] == 0x03)
                                {                                         // god damn it
                                    arcFile.Seek(-1, SeekOrigin.Current); // backup
                                    bufSize--;
                                    buffer[bufSize] = 0x00;
                                    break;
                                }
                            }

                            string newfile;
                            if (bufSize >= 1)
                            {
                                // Now convert the buffer to a String
                                char[] chars = new char[ascii.GetCharCount(buffer, 0, bufSize - 1)];
                                ascii.GetChars(buffer, 0, bufSize - 1, chars, 0);
                                newfile = new string(chars);
                            }
                            else
                            {
                                newfile = string.Format("Null File {0}", i);
                            }

                            records[i].filename = NormalizeRecordPath(newfile);
                        }
                    }

                    // Now convert the array of records into a hash table.
                    Hashtable hash = new Hashtable(numEntries);

                    for (i = 0; i < numEntries; ++i)
                    {
                        if (records[i].IsActive)
                        {
                            hash.Add(records[i].filename, records[i]);
                        }
                    }
                    m_dir = hash;

                    BuildKeyTable();
                }
                finally
                {
                    reader.Close();
                }
            }
            catch (IOException)
            {
                // silently eat these errors
            }
        }
Exemplo n.º 11
0
        /// <summary>
        /// Read the table of contents of the ARC file
        /// </summary>
        public void ReadARCToC(ArcFile file)
        {
            // Format of an ARC file
            // 0x08 - 4 bytes = # of files
            // 0x0C - 4 bytes = # of parts
            // 0x18 - 4 bytes = offset to directory structure
            //
            // Format of directory structure
            // 4-byte int = offset in file where this part begins
            // 4-byte int = size of compressed part
            // 4-byte int = size of uncompressed part
            // these triplets repeat for each part in the arc file
            // After these triplets are a bunch of null-terminated strings
            // which are the sub filenames.
            // After the subfilenames comes the subfile data:
            // 4-byte int = 3 == indicates start of subfile item  (maybe compressed flag??)
            //          1 == maybe uncompressed flag??
            // 4-byte int = offset in file where first part of this subfile begins
            // 4-byte int = compressed size of this file
            // 4-byte int = uncompressed size of this file
            // 4-byte crap
            // 4-byte crap
            // 4-byte crap
            // 4-byte int = numParts this file uses
            // 4-byte int = part# of first part for this file (starting at 0).
            // 4-byte int = length of filename string
            // 4-byte int = offset in directory structure for filename
            file.FileHasBeenRead = true;

            if (TQDebug.ArcFileDebugLevel > 0)
            {
                Log.DebugFormat(CultureInfo.InvariantCulture, "ARCFile.ReadARCToC({0})", file.FileName);
            }

            try
            {
                using (FileStream arcFile = new FileStream(file.FileName, FileMode.Open, FileAccess.Read))
                {
                    using (BinaryReader reader = new BinaryReader(arcFile))
                    {
                        if (TQDebug.ArcFileDebugLevel > 1)
                        {
                            Log.DebugFormat(CultureInfo.InvariantCulture, "File Length={0}", arcFile.Length);
                        }

                        // check the file header
                        if (reader.ReadByte() != 0x41)
                        {
                            return;
                        }

                        if (reader.ReadByte() != 0x52)
                        {
                            return;
                        }

                        if (reader.ReadByte() != 0x43)
                        {
                            return;
                        }

                        if (arcFile.Length < 0x21)
                        {
                            return;
                        }

                        reader.BaseStream.Seek(0x08, SeekOrigin.Begin);
                        int numEntries = reader.ReadInt32();
                        int numParts   = reader.ReadInt32();

                        if (TQDebug.ArcFileDebugLevel > 1)
                        {
                            Log.DebugFormat(CultureInfo.InvariantCulture, "numEntries={0}, numParts={1}", numEntries, numParts);
                        }

                        ArcPartEntry[] parts   = new ArcPartEntry[numParts];
                        ArcDirEntry[]  records = new ArcDirEntry[numEntries];

                        if (TQDebug.ArcFileDebugLevel > 2)
                        {
                            Log.Debug("Seeking to tocOffset location");
                        }

                        reader.BaseStream.Seek(0x18, SeekOrigin.Begin);
                        int tocOffset = reader.ReadInt32();

                        if (TQDebug.ArcFileDebugLevel > 1)
                        {
                            Log.DebugFormat(CultureInfo.InvariantCulture, "tocOffset = {0}", tocOffset);
                        }

                        // Make sure all 3 entries exist for the toc entry.
                        if (arcFile.Length < (tocOffset + 12))
                        {
                            return;
                        }

                        // Read in all of the part data
                        reader.BaseStream.Seek(tocOffset, SeekOrigin.Begin);
                        int i;
                        for (i = 0; i < numParts; ++i)
                        {
                            parts[i]                = new ArcPartEntry();
                            parts[i].FileOffset     = reader.ReadInt32();
                            parts[i].CompressedSize = reader.ReadInt32();
                            parts[i].RealSize       = reader.ReadInt32();

                            if (TQDebug.ArcFileDebugLevel > 2)
                            {
                                Log.DebugFormat(CultureInfo.InvariantCulture, "parts[{0}]", i);
                                Log.DebugFormat(CultureInfo.InvariantCulture
                                                , "  fileOffset={0}, compressedSize={1}, realSize={2}"
                                                , parts[i].FileOffset
                                                , parts[i].CompressedSize
                                                , parts[i].RealSize
                                                );
                            }
                        }

                        // Now record this offset so we can come back and read in the filenames
                        // after we have read in the file records
                        int fileNamesOffset = (int)arcFile.Position;

                        // Now seek to the location where the file record data is
                        // This offset is from the end of the file.
                        int fileRecordOffset = 44 * numEntries;

                        if (TQDebug.ArcFileDebugLevel > 1)
                        {
                            Log.DebugFormat(CultureInfo.InvariantCulture
                                            , "fileNamesOffset = {0}.  Seeking to {1} to read file record data."
                                            , fileNamesOffset
                                            , fileRecordOffset
                                            );
                        }

                        arcFile.Seek(-1 * fileRecordOffset, SeekOrigin.End);
                        for (i = 0; i < numEntries; ++i)
                        {
                            records[i] = new ArcDirEntry();

                            // storageType = 3 - compressed / 1- non compressed
                            int storageType = reader.ReadInt32();

                            if (TQDebug.ArcFileDebugLevel > 2)
                            {
                                Log.DebugFormat(CultureInfo.InvariantCulture, "StorageType={0}", storageType);
                            }

                            // Added by VillageIdiot to support stored types
                            records[i].StorageType    = storageType;
                            records[i].FileOffset     = reader.ReadInt32();
                            records[i].CompressedSize = reader.ReadInt32();
                            records[i].RealSize       = reader.ReadInt32();
                            int crap = reader.ReadInt32();                             // crap
                            if (TQDebug.ArcFileDebugLevel > 2)
                            {
                                Log.DebugFormat(CultureInfo.InvariantCulture, "Crap2={0}", crap);
                            }

                            crap = reader.ReadInt32();                             // crap
                            if (TQDebug.ArcFileDebugLevel > 2)
                            {
                                Log.DebugFormat(CultureInfo.InvariantCulture, "Crap3={0}", crap);
                            }

                            crap = reader.ReadInt32();                             // crap
                            if (TQDebug.ArcFileDebugLevel > 2)
                            {
                                Log.DebugFormat(CultureInfo.InvariantCulture, "Crap4={0}", crap);
                            }

                            int numberOfParts = reader.ReadInt32();
                            if (numberOfParts < 1)
                            {
                                records[i].Parts = null;
                                if (TQDebug.ArcFileDebugLevel > 2)
                                {
                                    Log.DebugFormat(CultureInfo.InvariantCulture, "File {0} is not compressed.", i);
                                }
                            }
                            else
                            {
                                records[i].Parts = new ArcPartEntry[numberOfParts];
                            }

                            int firstPart = reader.ReadInt32();
                            crap = reader.ReadInt32();                             // filename length
                            if (TQDebug.ArcFileDebugLevel > 2)
                            {
                                Log.DebugFormat(CultureInfo.InvariantCulture, "Filename Length={0}", crap);
                            }

                            crap = reader.ReadInt32();                             // filename offset
                            if (TQDebug.ArcFileDebugLevel > 2)
                            {
                                Log.DebugFormat(CultureInfo.InvariantCulture, "Filename Offset={0}", crap);

                                Log.DebugFormat(CultureInfo.InvariantCulture, "record[{0}]", i);
                                Log.DebugFormat(
                                    CultureInfo.InvariantCulture,
                                    "  offset={0} compressedSize={1} realSize={2}",
                                    records[i].FileOffset,
                                    records[i].CompressedSize,
                                    records[i].RealSize);

                                if (storageType != 1 && records[i].IsActive)
                                {
                                    Log.DebugFormat(
                                        CultureInfo.InvariantCulture,
                                        "  numParts={0} firstPart={1} lastPart={2}",
                                        records[i].Parts.Length,
                                        firstPart,
                                        firstPart + records[i].Parts.Length - 1);
                                }
                                else
                                {
                                    Log.DebugFormat(CultureInfo.InvariantCulture, "  INACTIVE firstPart={0}", firstPart);
                                }
                            }

                            if (storageType != 1 && records[i].IsActive)
                            {
                                for (int ip = 0; ip < records[i].Parts.Length; ++ip)
                                {
                                    records[i].Parts[ip] = parts[ip + firstPart];
                                }
                            }
                        }

                        // Now read in the record names
                        arcFile.Seek(fileNamesOffset, SeekOrigin.Begin);
                        byte[]        buffer = new byte[2048];
                        ASCIIEncoding ascii  = new ASCIIEncoding();
                        for (i = 0; i < numEntries; ++i)
                        {
                            // only Active files have a filename entry
                            if (records[i].IsActive)
                            {
                                // For each string, read bytes until I hit a 0x00 byte.
                                if (TQDebug.ArcFileDebugLevel > 2)
                                {
                                    Log.DebugFormat(CultureInfo.InvariantCulture, "Reading entry name {0:n0}", i);
                                }

                                int bufferSize = 0;

                                while ((buffer[bufferSize++] = reader.ReadByte()) != 0x00)
                                {
                                    if (buffer[bufferSize - 1] == 0x03)
                                    {
                                        // File is null?
                                        arcFile.Seek(-1, SeekOrigin.Current);                                         // backup
                                        bufferSize--;
                                        buffer[bufferSize] = 0x00;
                                        if (TQDebug.ArcFileDebugLevel > 2)
                                        {
                                            Log.Debug("Null file - inactive?");
                                        }

                                        break;
                                    }

                                    if (bufferSize >= buffer.Length)
                                    {
                                        Log.Debug("ARCFile.ReadARCToC() Error - Buffer size of 2048 has been exceeded.");
                                        if (TQDebug.ArcFileDebugLevel > 2)
                                        {
                                            var content = buffer.Select(b => string.Format(CultureInfo.InvariantCulture, "0x{0:X}", b)).ToArray();
                                            Log.Debug($"Buffer contents:{Environment.NewLine}{string.Join(string.Empty, content)}{Environment.NewLine}{string.Empty}");
                                        }
                                    }
                                }

                                if (TQDebug.ArcFileDebugLevel > 2)
                                {
                                    Log.DebugFormat(
                                        CultureInfo.InvariantCulture,
                                        "Read {0:n0} bytes for name.  Converting to string.",
                                        bufferSize);
                                }

                                string newfile;
                                if (bufferSize >= 1)
                                {
                                    // Now convert the buffer to a string
                                    char[] chars = new char[ascii.GetCharCount(buffer, 0, bufferSize - 1)];
                                    ascii.GetChars(buffer, 0, bufferSize - 1, chars, 0);
                                    newfile = new string(chars);
                                }
                                else
                                {
                                    newfile = string.Format(CultureInfo.InvariantCulture, "Null File {0}", i);
                                }

                                records[i].FileName = TQData.NormalizeRecordPath(newfile);

                                if (TQDebug.ArcFileDebugLevel > 2)
                                {
                                    Log.DebugFormat(CultureInfo.InvariantCulture, "Name {0:n0} = '{1}'", i, records[i].FileName);
                                }
                            }
                        }

                        // Now convert the array of records into a Dictionary.
                        Dictionary <string, ArcDirEntry> dictionary = new Dictionary <string, ArcDirEntry>(numEntries);

                        if (TQDebug.ArcFileDebugLevel > 1)
                        {
                            Log.Debug("Creating Dictionary");
                        }

                        for (i = 0; i < numEntries; ++i)
                        {
                            if (records[i].IsActive)
                            {
                                dictionary.Add(records[i].FileName, records[i]);
                            }
                        }

                        file.DirectoryEntries = dictionary;

                        if (TQDebug.ArcFileDebugLevel > 0)
                        {
                            Log.Debug("Exiting ARCFile.ReadARCToC()");
                        }
                    }
                }
            }
            catch (IOException exception)
            {
                Log.Error("ARCFile.ReadARCToC() - Error reading arcfile", exception);
            }
        }
Exemplo n.º 12
0
 private void DoNegAOORTest(ASCIIEncoding ascii, byte[] bytes, int index, int count)
 {
     Assert.Throws<ArgumentOutOfRangeException>(() =>
     {
         ascii.GetCharCount(bytes, index, count);
     });
 }
Exemplo n.º 13
0
 public void NegTest5()
 {
     ASCIIEncoding ascii = new ASCIIEncoding();
     byte[] bytes = null;
     Assert.Throws<ArgumentNullException>(() =>
    {
        ascii.GetCharCount(bytes, 0, 0);
    });
 }
Exemplo n.º 14
0
        /// <summary>Initializes the MPI environment.</summary>
        /// <param name="args">
        ///   Arguments passed to the <c>Main</c> function in your program. MPI
        ///   may use some of these arguments for its initialization, and will remove
        ///   them from this argument before returning.
        /// </param>
        /// <param name="threading">
        ///   The level of threading support requested of the MPI implementation. The
        ///   implementation will attempt to provide this level of threading support.
        ///   However, the actual level of threading support provided will be published
        ///   via the <see cref="MPI.Environment.Threading"/> property.
        /// </param>
        /// <remarks>
        ///   This routine must be invoked before using any other MPI facilities.
        ///   Be sure to call <c>Dispose()</c> to finalize the MPI environment before exiting!
        /// </remarks>
        /// <example>This simple program initializes MPI and writes out the rank of each processor:
        /// <code>
        /// using MPI;
        ///
        /// public class Hello
        /// {
        ///     static int Main(string[] args)
        ///     {
        ///         using (MPI.Environment env = new MPI.Environment(ref args))
        ///         {
        ///             System.Console.WriteLine("Hello, from process number "
        ///                 + MPI.Communicator.world.Rank.ToString() + " of "
        ///                 + MPI.Communicator.world.Size.ToString());
        ///         }
        ///     }
        /// }
        /// </code>
        /// </example>
        public Environment(ref string[] args, Threading threading)
        {
            if (Finalized)
            {
                throw new ObjectDisposedException("Constructor called when object already finalized.");
            }

            if (!Initialized)
            {
                int requiredThreadLevel = 0;
                int providedThreadLevel;

                switch (threading)
                {
                case Threading.Single:
                    requiredThreadLevel = Unsafe.MPI_THREAD_SINGLE;
                    break;

                case Threading.Funneled:
                    requiredThreadLevel = Unsafe.MPI_THREAD_FUNNELED;
                    break;

                case Threading.Serialized:
                    requiredThreadLevel = Unsafe.MPI_THREAD_SERIALIZED;
                    break;

                case Threading.Multiple:
                    requiredThreadLevel = Unsafe.MPI_THREAD_MULTIPLE;
                    break;
                }

                if (args == null)
                {
                    unsafe
                    {
                        int    argc = 0;
                        byte **argv = null;
                        Unsafe.MPI_Init_thread(ref argc, ref argv, requiredThreadLevel, out providedThreadLevel);
                    }
                }
                else
                {
                    ASCIIEncoding ascii = new ASCIIEncoding();
                    unsafe
                    {
                        // Copy args into C-style argc/argv
                        int    my_argc = args.Length;
                        byte **my_argv = stackalloc byte *[my_argc];
                        for (int argidx = 0; argidx < my_argc; ++argidx)
                        {
                            // Copy argument into a byte array (C-style characters)
                            char[] arg = args[argidx].ToCharArray();
                            fixed(char *argp = arg)
                            {
                                int   length = ascii.GetByteCount(arg);
                                byte *c_arg  = stackalloc byte[length];

                                if (length > 0)
                                {
                                    ascii.GetBytes(argp, arg.Length, c_arg, length);
                                }
                                my_argv[argidx] = c_arg;
                            }
                        }

                        // Initialize MPI
                        int    mpi_argc = my_argc;
                        byte **mpi_argv = my_argv;
                        Unsafe.MPI_Init_thread(ref mpi_argc, ref mpi_argv, requiredThreadLevel, out providedThreadLevel);

                        // \todo Copy c-style argc/argv back into args
                        if (mpi_argc != my_argc || mpi_argv != my_argv)
                        {
                            args = new string[mpi_argc];
                            for (int argidx = 0; argidx < args.Length; ++argidx)
                            {
                                // Find the end of the string
                                int byteCount = 0;
                                while (mpi_argv[argidx][byteCount] != 0)
                                {
                                    ++byteCount;
                                }

                                // Determine how many Unicode characters we need
                                int charCount = ascii.GetCharCount(mpi_argv[argidx], byteCount);

                                // Convert ASCII characters into unicode characters
                                char[] chars = new char[charCount];
                                fixed(char *argp = chars)
                                {
                                    ascii.GetChars(mpi_argv[argidx], byteCount, argp, charCount);
                                }

                                // Create the resulting string
                                args[argidx] = new string(chars);
                            }
                        }
                    }
                }

                switch (providedThreadLevel)
                {
                case Unsafe.MPI_THREAD_SINGLE:
                    Environment.providedThreadLevel = Threading.Single;
                    break;

                case Unsafe.MPI_THREAD_FUNNELED:
                    Environment.providedThreadLevel = Threading.Funneled;
                    break;

                case Unsafe.MPI_THREAD_SERIALIZED:
                    Environment.providedThreadLevel = Threading.Serialized;
                    break;

                case Unsafe.MPI_THREAD_MULTIPLE:
                    Environment.providedThreadLevel = Threading.Multiple;
                    break;

                default:
                    throw new ApplicationException("MPI.NET: Underlying MPI library returned incorrect value for thread level");
                }

                // Setup communicators
                Communicator.world = Intracommunicator.Adopt(Unsafe.MPI_COMM_WORLD);
                Communicator.self  = Intracommunicator.Adopt(Unsafe.MPI_COMM_SELF);
            }
        }
Exemplo n.º 15
0
        /** HEXDUMPº¯Êý */

        /*
         * hex_view = 4096 bytes
         * offset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F
         * 0000 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? | ................
         * 0001 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? | ................
         * 0002 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? | ................
         * 0003 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? | ................
         * 0004 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? | ................
         * 0005 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? | ................
         * 0006 | ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? ?? | ................
         */
        public static void hexall(byte[] buff)
        {
            int     i = 0, j = 0;
            int     cur      = 0;
            int     linemax  = 0;
            int     nprinted = 0;
            Boolean flag     = false;
            int     len      = buff.Length;

            Char[] chars;
            if (0 == len)
            {
                return;
            }
            //UTF8Encoding utf8 = new UTF8Encoding();
            ASCIIEncoding asiic     = new ASCIIEncoding();
            int           charCount = asiic.GetCharCount(buff);

            chars = new Char[charCount];
            int charsDecodedCount = asiic.GetChars(buff, 0, len, chars, 0);

            Console.Write("hex_view = {0:d} bytes\r\noffset 00 01 02 03 04 05 06 07 08 09 0A 0B 0C 0D 0E 0F", len); Console.WriteLine();
            i = 0; j = 0; flag = true;
            do
            {
                Console.Write("{0:X4} | ", (nprinted / 16));
                if (nprinted >= len)
                {
                    flag = false;
                    break;
                }
                linemax = 16;
                for (j = 0; j < linemax; j++)
                {
                    cur = i + j;
                    if (cur >= len)
                    {
                        flag = false;
                        Console.Write("   ");
                    }
                    else
                    {
                        Console.Write("{0:X2} ", buff[cur]);
                        nprinted++;
                    }
                }
                Console.Write("| ");
                for (j = 0; j < linemax; j++)
                {
                    cur = i + j;
                    if (cur >= len)
                    {
                        flag = false;
                        break;
                    }
                    if (buff[cur] > 30 && buff[cur] < 127)
                    { //Console.Write("{0:c}", buff[cur]);
                        Console.Write("{0}", chars[cur]);
                        //Console.Write(buff[cur].ToString);
                    }
                    else
                    {
                        Console.Write(".");
                    }
                }
                i += 16;
                Console.WriteLine();
            } while (flag);
            Console.WriteLine();
            return;
        }