2 // Mono.Posix.Catalog.cs: Wrappers for the libintl library.
5 // Edd Dumbill (edd@usefulinc.com)
7 // (C) 2004 Edd Dumbill
9 // This file implements the low-level syscall interface to the POSIX
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
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
29 // Methods that require tuning are bound as `internal syscal_NAME' methods
30 // and then a `NAME' method is exposed.
34 using System
.Runtime
.InteropServices
;
36 namespace Mono
.Posix
{
38 [Obsolete ("Use Mono.Unix.Catalog")]
39 public class Catalog
{
41 static extern IntPtr
bindtextdomain (IntPtr domainname
, IntPtr dirname
);
43 static extern IntPtr
bind_textdomain_codeset (IntPtr domainname
,
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
);
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
);
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
);