grrr...fix reverse chronological order
[dragonfly.git] / lib / libcr / locale / rune.3
1 .\" Copyright (c) 1993
2 .\"     The Regents of the University of California.  All rights reserved.
3 .\"
4 .\" This code is derived from software contributed to Berkeley by
5 .\" Paul Borman at Krystal Technologies.
6 .\"
7 .\" Redistribution and use in source and binary forms, with or without
8 .\" modification, are permitted provided that the following conditions
9 .\" are met:
10 .\" 1. Redistributions of source code must retain the above copyright
11 .\"    notice, this list of conditions and the following disclaimer.
12 .\" 2. Redistributions in binary form must reproduce the above copyright
13 .\"    notice, this list of conditions and the following disclaimer in the
14 .\"    documentation and/or other materials provided with the distribution.
15 .\" 3. All advertising materials mentioning features or use of this software
16 .\"    must display the following acknowledgement:
17 .\"     This product includes software developed by the University of
18 .\"     California, Berkeley and its contributors.
19 .\" 4. Neither the name of the University nor the names of its contributors
20 .\"    may be used to endorse or promote products derived from this software
21 .\"    without specific prior written permission.
22 .\"
23 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 .\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 .\" SUCH DAMAGE.
34 .\"
35 .\"     @(#)rune.3      8.2 (Berkeley) 12/11/93
36 .\" $FreeBSD: src/lib/libc/locale/rune.3,v 1.10.2.7 2002/08/07 06:24:14 ache Exp $
37 .\" $DragonFly: src/lib/libcr/locale/Attic/rune.3,v 1.2 2003/06/17 04:26:44 dillon Exp $
38 .\"
39 .Dd December 11, 1993
40 .Dt RUNE 3
41 .Os
42 .Sh NAME
43 .Nm setrunelocale ,
44 .Nm setinvalidrune ,
45 .Nm sgetrune ,
46 .Nm sputrune ,
47 .Nm fgetrune ,
48 .Nm fungetrune ,
49 .Nm fputrune
50 .Nd rune support for C
51 .Sh LIBRARY
52 .Lb libc
53 .Sh SYNOPSIS
54 .In rune.h
55 .In errno.h
56 .Ft int
57 .Fn setrunelocale "char *locale"
58 .Ft void
59 .Fn setinvalidrune "rune_t rune"
60 .Ft rune_t
61 .Fn sgetrune "const char *string" "size_t n" "char const **result"
62 .Ft int
63 .Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result"
64 .Pp
65 .In stdio.h
66 .Ft long
67 .Fn fgetrune "FILE *stream"
68 .Ft int
69 .Fn fungetrune "rune_t rune" "FILE *stream"
70 .Ft int
71 .Fn fputrune "rune_t rune" "FILE *stream"
72 .Sh DESCRIPTION
73 The
74 .Fn setrunelocale
75 controls the type of encoding used to represent runes as multibyte strings
76 as well as the properties of the runes as defined in
77 .Aq Pa ctype.h .
78 The
79 .Fa locale
80 argument indicates which locale to load.
81 If the locale is successfully loaded,
82 .Dv 0
83 is returned, otherwise an errno value is returned to indicate the
84 type of error.
85 .Pp
86 The
87 .Fn setinvalidrune
88 function sets the value of the global value
89 .Dv _INVALID_RUNE
90 to be
91 .Fa rune .
92 .Pp
93 The
94 .Fn sgetrune
95 function tries to read a single multibyte character from
96 .Fa string ,
97 which is at most
98 .Fa n
99 bytes long.
100 If
101 .Fn sgetrune
102 is successful, the rune is returned.
103 If
104 .Fa result
105 is not
106 .Dv NULL ,
107 .Fa *result
108 will point to the first byte which was not converted in
109 .Fa string .
110 If the first
111 .Fa n
112 bytes of
113 .Fa string
114 do not describe a full multibyte character,
115 .Dv _INVALID_RUNE
116 is returned and
117 .Fa *result
118 will point to
119 .Fa string .
120 If there is an encoding error at the start of
121 .Fa string ,
122 .Dv _INVALID_RUNE
123 is returned and
124 .Fa *result
125 will point to the second character of
126 .Fa string .
127 .Pp
128 the
129 .Fn sputrune
130 function tries to encode
131 .Fa rune
132 as a multibyte string and store it at
133 .Fa string ,
134 but no more than
135 .Fa n
136 bytes will be stored.
137 If
138 .Fa result
139 is not
140 .Dv NULL ,
141 .Fa *result
142 will be set to point to the first byte in string following the new
143 multibyte character.
144 If
145 .Fa string
146 is
147 .Dv NULL ,
148 .Fa *result
149 will point to
150 .Dv "(char *)0 +"
151 .Fa x ,
152 where
153 .Fa x
154 is the number of bytes that would be needed to store the multibyte value.
155 If the multibyte character would consist of more than
156 .Fa n
157 bytes and
158 .Fa result
159 is not
160 .Dv NULL ,
161 .Fa *result
162 will be set to
163 .Dv NULL .
164 In all cases,
165 .Fn sputrune
166 will return the number of bytes which would be needed to store
167 .Fa rune
168 as a multibyte character.
169 .Pp
170 The
171 .Fn fgetrune
172 function operates the same as
173 .Fn sgetrune
174 with the exception that it attempts to read enough bytes from
175 .Fa stream
176 to decode a single rune.  It returns either
177 .Dv EOF
178 on end of file,
179 .Dv _INVALID_RUNE
180 on an encoding error, or the rune decoded if all went well.
181 .Pp
182 The
183 .Fn fungetrune
184 function pushes the multibyte encoding, as provided by
185 .Fn sputrune ,
186 of
187 .Fa rune
188 onto
189 .Fa stream
190 such that the next
191 .Fn fgetrune
192 call will return
193 .Fa rune .
194 It returns
195 .Dv EOF
196 if it fails and
197 .Dv 0
198 on success.
199 .Pp
200 The
201 .Fn fputrune
202 function writes the multibyte encoding of
203 .Fa rune ,
204 as provided by
205 .Fn sputrune ,
206 onto
207 .Fa stream .
208 It returns
209 .Dv EOF
210 on failure and
211 .Dv 0
212 on success.
213 .Sh RETURN VALUES
214 The
215 .Fn setrunelocale
216 function returns one of the following values:
217 .Bl -tag -width Er
218 .It Er 0
219 .Fn setrunelocale
220 was successful.
221 .It Bq Er EINVAL
222 .Fa locale
223 name was incorrect.
224 .It Bq Er ENOENT
225 The locale could not be found.
226 .It Bq Er EFTYPE
227 The file found was not a valid file.
228 .El
229 .Pp
230 The
231 .Fn sgetrune
232 function either returns the rune read or
233 .Dv _INVALID_RUNE .
234 The
235 .Fn sputrune
236 function returns the number of bytes needed to store
237 .Fa rune
238 as a multibyte string.
239 .Sh FILES
240 .Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact
241 .It Pa $PATH_LOCALE/ Ns Em locale Ns /LC_CTYPE
242 .It Pa /usr/share/locale/ Ns Em locale Ns /LC_CTYPE
243 binary LC_CTYPE file for the locale
244 .Em locale .
245 .El
246 .Sh SEE ALSO
247 .Xr mbrune 3 ,
248 .Xr setlocale 3 ,
249 .Xr euc 4 ,
250 .Xr utf2 4
251 .Sh NOTES
252 The ANSI C type
253 .Em wchar_t
254 is the same as
255 .Em rune_t .
256 .Em Rune_t
257 was chosen to accent the purposeful choice of not basing the
258 system with the ANSI C
259 primitives, which were, shall we say, less aesthetic.
260 .Sh HISTORY
261 These functions first appeared in
262 .Bx 4.4 .
263 .Pp
264 The
265 .Fn setrunelocale
266 function and the other non-ANSI rune functions were inspired by
267 .Sy "Plan 9 from Bell Labs"
268 as a much more sane alternative to the ANSI multibyte and
269 wide character support.
270 .\"They were conceived at the San Diego 1993 Summer USENIX conference by
271 .\"Paul Borman of Krystal Technologies, Keith Bostic of CSRG and Andrew Hume
272 .\"of Bell Labs.
273 .Pp
274 All of the ANSI multibyte and wide character
275 support functions are built using the rune functions.