]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - lib/libc/locale/rune.3
This commit was generated by cvs2svn to compensate for changes in r48907,
[FreeBSD/FreeBSD.git] / lib / libc / 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 .\"     $Id$
37 .\"
38 .Dd December 11, 1993
39 .Dt RUNE 3
40 .Os
41 .Sh NAME
42 .Nm setrunelocale ,
43 .Nm setinvalidrune ,
44 .Nm sgetrune ,
45 .Nm sputrune
46 .Nd rune support for C
47 .Sh SYNOPSIS
48 .Fd #include <rune.h>
49 .Fd #include <errno.h>
50 .Ft int
51 .Fn setrunelocale "char *locale"
52 .Ft void
53 .Fn setinvalidrune "rune_t rune"
54 .Ft rune_t
55 .Fn sgetrune "const char *string" "size_t n" "char const **result"
56 .Ft int
57 .Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result"
58 .Pp
59 .Fd #include <stdio.h>
60 .Ft long
61 .Fn fgetrune "FILE *stream"
62 .Ft int
63 .Fn fungetrune "rune_t rune" "FILE *stream"
64 .Ft int
65 .Fn fputrune "rune_t rune" "FILE *stream"
66 .Sh DESCRIPTION
67 The
68 .Fn setrunelocale
69 controls the type of encoding used to represent runes as multibyte strings
70 as well as the properties of the runes as defined in
71 .Aq Pa ctype.h .
72 The
73 .Fa locale
74 argument indicates which locale to load.
75 If the locale is successfully loaded,
76 .Dv 0
77 is returned, otherwise an errno value is returned to indicate the
78 type of error.
79 .Pp
80 The
81 .Fn setinvalidrune
82 function sets the value of the global value
83 .Ev _INVALID_RUNE
84 to be
85 .Fa rune.
86 .Pp
87 The
88 .Fn sgetrune
89 function tries to read a single multibyte character from
90 .Fa string ,
91 which is at most
92 .Fa n
93 bytes long.
94 If
95 .Fn sgetrune
96 is successful, the rune is returned.
97 If
98 .Fa result
99 is not
100 .Dv NULL ,
101 .Fa *result
102 will point to the first byte which was not converted in
103 .Fa string.
104 If the first
105 .Fa n
106 bytes of
107 .Fa string
108 do not describe a full multibyte character,
109 .Ev _INVALID_RUNE
110 is returned and
111 .Fa *result
112 will point to
113 .Fa string.
114 If there is an encoding error at the start of
115 .Fa string ,
116 .Ev _INVALID_RUNE
117 is returned and 
118 .Fa *result
119 will point to the second character of
120 .Fa string.
121 .Pp
122 the
123 .Fn sputrune
124 function tries to encode
125 .Fa rune
126 as a multibyte string and store it at
127 .Fa string ,
128 but no more than
129 .Fa n
130 bytes will be stored.
131 If
132 .Fa result
133 is not
134 .Dv NULL ,
135 .Fa *result
136 will be set to point to the first byte in string following the new
137 multibyte character.
138 If
139 .Fa string
140 is
141 .Dv NULL ,
142 .Fa *result
143 will point to
144 .Dv "(char *)0 +"
145 .Fa x ,
146 where
147 .Fa x
148 is the number of bytes that would be needed to store the multibyte value.
149 If the multibyte character would consist of more than
150 .Fa n
151 bytes and
152 .Fa result
153 is not
154 .Dv NULL ,
155 .Fa *result
156 will be set to
157 .Dv NULL.
158 In all cases, 
159 .Fn sputrune
160 will return the number of bytes which would be needed to store
161 .Fa rune
162 as a multibyte character.
163 .Pp
164 The
165 .Fn fgetrune
166 function operates the same as
167 .Fn sgetrune
168 with the exception that it attempts to read enough bytes from 
169 .Fa stream
170 to decode a single rune.  It returns either
171 .Ev EOF
172 on end of file,
173 .Ev _INVALID_RUNE
174 on an encoding error, or the rune decoded if all went well.
175 .Pp
176 The
177 .Fn fungetrune
178 function pushes the multibyte encoding, as provided by
179 .Fn sputrune ,
180 of
181 .Fa rune
182 onto
183 .Fa stream 
184 such that the next
185 .Fn fgetrune
186 call will return
187 .Fa rune .
188 It returns
189 .Ev EOF
190 if it fails and
191 .Dv 0
192 on success.
193 .Pp
194 The
195 .Fn fputrune
196 function writes the multibyte encoding of
197 .Fa rune ,
198 as provided by
199 .Fn sputrune ,
200 onto
201 .Fa stream .
202 It returns
203 .Ev EOF
204 on failure and
205 .Dv 0
206 on success.
207 .Sh RETURN VALUES
208 The
209 .Fn setrunelocale
210 function returns one of the following values:
211 .Bl -tag -width WWWWWWWW
212 .It Dv 0
213 .Fa setrunelocale was successful.
214 .It Ev EFAULT
215 .Fa locale
216 was
217 .Dv NULL .
218 .It Ev ENOENT
219 The locale could not be found.
220 .It Ev EFTYPE
221 The file found was not a valid file.
222 .It Ev EINVAL
223 The encoding indicated by the locale was unknown.
224 .El
225 .Pp
226 The
227 .Fn sgetrune
228 function either returns the rune read or
229 .Ev _INVALID_RUNE .
230 The
231 .Fn sputrune
232 function returns the number of bytes needed to store
233 .Fa rune
234 as a multibyte string.
235 .Sh FILES
236 .Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact
237 .It Pa $PATH_LOCALE/ Ns Em locale Ns /LC_CTYPE
238 .It Pa /usr/share/locale/ Ns Em locale Ns /LC_CTYPE
239 binary LC_CTYPE file for the locale 
240 .Em locale .
241 .El
242 .Sh "SEE ALSO
243 .Xr mbrune 3 ,
244 .Xr setlocale 3 ,
245 .Xr euc 4 ,
246 .Xr utf2 4
247 .Sh NOTE
248 The ANSI C type
249 .Ev wchar_t
250 is the same as
251 .Ev rune_t .
252 .Ev Rune_t
253 was chosen to accent the purposeful choice of not basing the
254 system with the ANSI C
255 primitives, which were, shall we say, less aesthetic.
256 .Sh HISTORY
257 These functions first appeared in
258 .Bx 4.4 .
259 .Pp
260 The
261 .Fn setrunelocale
262 function and the other non-ANSI rune functions were inspired by
263 .Nm Plan 9 from Bell Labs
264 as a much more sane alternative to the ANSI multibyte and
265 wide character support.
266 .\"They were conceived at the San Diego 1993 Summer USENIX conference by
267 .\"Paul Borman of Krystal Technologies, Keith Bostic of CSRG and Andrew Hume
268 .\"of Bell Labs.
269 .Pp
270 All of the ANSI multibyte and wide character
271 support functions are built using the rune functions.