예제 #1
0
        public static string GetString(string domain, string msgid, string msgidPlural, int n)
        {
            IntPtr msgid_ptr        = UnixMarshal.StringToHeap(msgid);
            IntPtr msgid_plural_ptr = UnixMarshal.StringToHeap(msgidPlural);
            IntPtr domain_ptr       = domain == null ? IntPtr.Zero : UnixMarshal.StringToHeap(domain);

            try {
                IntPtr ret_ptr = domain_ptr == IntPtr.Zero ?
                                 ngettext(msgid_ptr, msgid_plural_ptr, n) :
                                 dngettext(domain_ptr, msgid_ptr, msgid_plural_ptr, n);

                if (ret_ptr == msgid_ptr)
                {
                    return(msgid);
                }
                else if (ret_ptr == msgid_plural_ptr)
                {
                    return(msgidPlural);
                }

                return(UnixMarshal.PtrToStringUnix(ret_ptr));
            } finally {
                UnixMarshal.FreeHeap(msgid_ptr);
                UnixMarshal.FreeHeap(msgid_plural_ptr);
                if (domain_ptr != IntPtr.Zero)
                {
                    UnixMarshal.FreeHeap(domain_ptr);
                }
            }
        }
예제 #2
0
    static void DetectOS()
    {
        if (!IsUnix)
        {
            Console.WriteLine("OS is: Windows");
            style = "windows";
            return;
        }

        IntPtr buf = UnixMarshal.AllocHeap(8192);

        if (uname(buf) != 0)
        {
            Console.WriteLine("Warning: Unable to detect OS");
            UnixMarshal.FreeHeap(buf);
            return;
        }
        string os = Marshal.PtrToStringAnsi(buf);

        Console.WriteLine("OS is: " + os);
        if (os == "Darwin")
        {
            style = "osx";
        }

        UnixMarshal.FreeHeap(buf);
    }
예제 #3
0
        public static void Init(string domain, string localeDir)
        {
            if (String.IsNullOrEmpty(domain))
            {
                throw new ArgumentException("No text domain specified");
            }

            IntPtr domain_ptr    = UnixMarshal.StringToHeap(domain);
            IntPtr localedir_ptr = IntPtr.Zero;

            try {
                BindTextDomainCodeset(domain_ptr);

                if (localeDir != null && localeDir.Length > 0)
                {
                    localedir_ptr = UnixMarshal.StringToHeap(localeDir);
                    BindTextDomain(domain_ptr, localedir_ptr);
                }
            } finally {
                UnixMarshal.FreeHeap(domain_ptr);
                if (localedir_ptr != IntPtr.Zero)
                {
                    UnixMarshal.FreeHeap(localedir_ptr);
                }
            }
        }
예제 #4
0
        public static string GetString(string domain, string msgid)
        {
            IntPtr msgid_ptr  = UnixMarshal.StringToHeap(msgid);
            IntPtr domain_ptr = domain == null ? IntPtr.Zero : UnixMarshal.StringToHeap(domain);

            if (domain == null)
            {
                // FIXME banshee-1?
                IntPtr ptr = UnixMarshal.StringToHeap("banshee");
                UnixMarshal.FreeHeap(ptr);
            }

            try {
                IntPtr ret_ptr = domain_ptr == IntPtr.Zero ?
                                 gettext(msgid_ptr) :
                                 dgettext(domain_ptr, msgid_ptr);

                if (msgid_ptr != ret_ptr)
                {
                    return(UnixMarshal.PtrToStringUnix(ret_ptr));
                }

                return(msgid);
            } finally {
                UnixMarshal.FreeHeap(msgid_ptr);
                if (domain_ptr != IntPtr.Zero)
                {
                    UnixMarshal.FreeHeap(domain_ptr);
                }
            }
        }
예제 #5
0
        public void TestPtrToString()
        {
            IntPtr p = UnixMarshal.AllocHeap(1);

            Marshal.WriteByte(p, 0);
            string s = UnixMarshal.PtrToString(p);

            UnixMarshal.FreeHeap(p);
        }
예제 #6
0
 public void Dispose()
 {
     if (Pointer != IntPtr.Zero)
     {
         UnixMarshal.FreeHeap(Pointer);
         Pointer = IntPtr.Zero;
     }
     GC.SuppressFinalize(this);
 }
예제 #7
0
파일: Utils.cs 프로젝트: voed/DotMetamod
        public static void FreePluginInfo(IntPtr plInfo)
        {
            PluginInfo *pl = (PluginInfo *)plInfo.ToPointer();

            UnixMarshal.FreeHeap(new IntPtr((void *)pl->ifvers));
            UnixMarshal.FreeHeap(new IntPtr((void *)pl->name));
            UnixMarshal.FreeHeap(new IntPtr((void *)pl->version));
            UnixMarshal.FreeHeap(new IntPtr((void *)pl->date));
            UnixMarshal.FreeHeap(new IntPtr((void *)pl->author));
            UnixMarshal.FreeHeap(new IntPtr((void *)pl->url));
            UnixMarshal.FreeHeap(new IntPtr((void *)pl->logtag));
            UnixMarshal.FreeHeap(plInfo);
        }
예제 #8
0
        private static void BindTextDomainCodeset(IntPtr domain)
        {
            IntPtr codeset = UnixMarshal.StringToHeap("UTF-8");

            try {
                if (bind_textdomain_codeset(domain, codeset) == IntPtr.Zero)
                {
                    throw new UnixIOException(Mono.Unix.Native.Errno.ENOMEM);
                }
            } finally {
                UnixMarshal.FreeHeap(codeset);
            }
        }
예제 #9
0
        public static void Free(int argc, IntPtr argPtr)
        {
            if (argPtr == IntPtr.Zero)
            {
                return;
            }

            for (int i = 0; i < argc; ++i)
            {
                IntPtr p = Marshal.ReadIntPtr(argPtr, i * IntPtr.Size);
                UnixMarshal.FreeHeap(p);
            }

            UnixMarshal.FreeHeap(argPtr);
        }
예제 #10
0
        private static void StringToHeap(string s, Encoding e, bool mustBeEqual)
        {
            IntPtr p = UnixMarshal.StringToHeap(s, e);

            try {
                string _s = UnixMarshal.PtrToString(p, e);
                if (mustBeEqual)
                {
                    Assert.AreEqual(s, _s, "#TSTA (" + e.GetType() + ")");
                }
            }
            finally {
                UnixMarshal.FreeHeap(p);
            }
        }
예제 #11
0
        // Verifies if a string is present (true) in the Catalog file
        static public bool StringExists(string s)
        {
            IntPtr ints = UnixMarshal.StringToHeap(s);

            try {
                // gettext returns the input pointer if no translation is found
                IntPtr r = gettext(ints);
                return(r != ints);
            }
            catch (Exception) {
                return(true);
            }

            finally {
                UnixMarshal.FreeHeap(ints);
            }
        }
예제 #12
0
 public void CleanUpNativeData(IntPtr pNativeData)
 {
     UnixMarshal.FreeHeap(pNativeData);
 }
예제 #13
0
 public static void Free(IntPtr opPtr)
 {
     Marshal.DestroyStructure(opPtr, typeof(Operations));
     UnixMarshal.FreeHeap(opPtr);
     opPtr = IntPtr.Zero;
 }
예제 #14
0
 public void CleanUpNativeData(IntPtr pNativeData)
 {
     // Console.WriteLine ("# FileNameMarshaler.CleanUpManagedData ({0:x})", pNativeData);
     UnixMarshal.FreeHeap(pNativeData);
 }
예제 #15
0
 public void Deallocate(IntPtr ptr)
 {
     UnixMarshal.FreeHeap(ptr);
 }
예제 #16
0
 void ICustomMarshaler.CleanUpNativeData(IntPtr pNativeData)
 {
     UnixMarshal.FreeHeap(pNativeData);
 }
예제 #17
0
        public void TestUtf32PtrToString()
        {
            var utf32NativeEndianNoBom = new UTF32Encoding(
                bigEndian: !BitConverter.IsLittleEndian,
                byteOrderMark: false,
                throwOnInvalidCharacters: true
                );

            // assemble a buffer that contains:
            // 1. eight garbage bytes
            // 2. the native-endian UTF-32 string "Hello, World" without BOM
            // 3. four 0 bytes (as a C wide string terminator)
            // 4. the native-endian UTF-32 string "broken" without BOM
            // 5. eight 0 bytes
            // 6. four garbage bytes
            var buf = new List <byte>();

            for (int i = 0; i < 2; ++i)
            {
                buf.Add((byte)0x12);
                buf.Add((byte)0x34);
                buf.Add((byte)0x56);
                buf.Add((byte)0x78);
            }

            buf.AddRange(utf32NativeEndianNoBom.GetBytes("Hello, World"));

            for (int i = 0; i < 4; ++i)
            {
                buf.Add((byte)0x00);
            }

            buf.AddRange(utf32NativeEndianNoBom.GetBytes("broken"));

            for (int i = 0; i < 8; ++i)
            {
                buf.Add((byte)0x00);
            }

            buf.Add((byte)0x12);
            buf.Add((byte)0x34);
            buf.Add((byte)0x56);
            buf.Add((byte)0x78);

            // get the array version of this
            var bufArr = buf.ToArray();

            // allocate a buffer that will contain this string
            IntPtr bufPtr = UnixMarshal.AllocHeap(bufArr.Length);
            string returned;

            try
            {
                // copy it in
                Marshal.Copy(bufArr, 0, bufPtr, bufArr.Length);

                // try getting it back
                returned = UnixMarshal.PtrToString(bufPtr + 8, utf32NativeEndianNoBom);
            }
            finally
            {
                UnixMarshal.FreeHeap(bufPtr);
            }

            Assert.AreEqual("Hello, World", returned);
        }