2010-05-27 Jb Evain <jbevain@novell.com>
[mcs.git] / class / Mono.Posix / Mono.Posix / Catalog.cs
blobea3c1046972cb490e8c40fa1e5631a4f1dc11533
1 //
2 // Mono.Posix.Catalog.cs: Wrappers for the libintl library.
3 //
4 // Author:
5 // Edd Dumbill (edd@usefulinc.com)
6 //
7 // (C) 2004 Edd Dumbill
8 //
9 // This file implements the low-level syscall interface to the POSIX
10 // subsystem.
12 // This file tries to stay close to the low-level API as much as possible
13 // using enumerations, structures and in a few cases, using existing .NET
14 // data types.
16 // Implementation notes:
18 // Since the values for the various constants on the API changes
19 // from system to system (even Linux on different architectures will
20 // have different values), we define our own set of values, and we
21 // use a set of C helper routines to map from the constants we define
22 // to the values of the native OS.
24 // Bitfields are flagged with the [Map] attribute, and a helper program
25 // generates a set of map_XXXX routines that we can call to convert
26 // from our value definitions to the value definitions expected by the
27 // OS.
29 // Methods that require tuning are bound as `internal syscal_NAME' methods
30 // and then a `NAME' method is exposed.
33 using System;
34 using System.Runtime.InteropServices;
36 namespace Mono.Posix {
38 [Obsolete ("Use Mono.Unix.Catalog")]
39 public class Catalog {
40 [DllImport("intl")]
41 static extern IntPtr bindtextdomain (IntPtr domainname, IntPtr dirname);
42 [DllImport("intl")]
43 static extern IntPtr bind_textdomain_codeset (IntPtr domainname,
44 IntPtr codeset);
45 [DllImport("intl")]
46 static extern IntPtr textdomain (IntPtr domainname);
48 public static void Init (String package, String localedir)
50 IntPtr ipackage = Marshal.StringToHGlobalAuto (package);
51 IntPtr ilocaledir = Marshal.StringToHGlobalAuto (localedir);
52 IntPtr iutf8 = Marshal.StringToHGlobalAuto ("UTF-8");
53 bindtextdomain (ipackage, ilocaledir);
54 bind_textdomain_codeset (ipackage, iutf8);
55 textdomain (ipackage);
56 Marshal.FreeHGlobal (ipackage);
57 Marshal.FreeHGlobal (ilocaledir);
58 Marshal.FreeHGlobal (iutf8);
61 [DllImport("intl")]
62 static extern IntPtr gettext (IntPtr instring);
64 public static String GetString (String s)
66 IntPtr ints = Marshal.StringToHGlobalAuto (s);
67 String t = Marshal.PtrToStringAuto (gettext (ints));
68 Marshal.FreeHGlobal (ints);
69 return t;
72 [DllImport("intl")]
73 static extern IntPtr ngettext (IntPtr singular, IntPtr plural, Int32 n);
75 public static String GetPluralString (String s, String p, Int32 n)
77 IntPtr ints = Marshal.StringToHGlobalAuto (s);
78 IntPtr intp = Marshal.StringToHGlobalAuto (p);
79 String t = Marshal.PtrToStringAnsi (ngettext (ints, intp, n));
80 Marshal.FreeHGlobal (ints);
81 Marshal.FreeHGlobal (intp);
82 return t;