163586Sbostic.\" Copyright (c) 1993 263586Sbostic.\" The Regents of the University of California. All rights reserved. 361076Sbostic.\" 461076Sbostic.\" This code is derived from software contributed to Berkeley by 561076Sbostic.\" Paul Borman at Krystal Technologies. 661076Sbostic.\" 761076Sbostic.\" %sccs.include.redist.roff% 861076Sbostic.\" 9*65099Smckusick.\" @(#)rune.3 8.2 (Berkeley) 12/11/93 1061076Sbostic.\" 1161076Sbostic.Dd "" 1261076Sbostic.Dt RUNE 3 1361076Sbostic.Os 1461076Sbostic.Sh NAME 1561076Sbostic.Nm setrunelocale , 1661076Sbostic.Nm setinvalidrune , 1761076Sbostic.Nm sgetrune , 1861076Sbostic.Nm sputrune 1961076Sbostic.Nd rune support for C 2061076Sbostic.Sh SYNOPSIS 2161076Sbostic.Fd #include <rune.h> 2261076Sbostic.Fd #include <errno.h> 2361076Sbostic.Ft int 2461076Sbostic.Fn setrunelocale "char *locale" 2561076Sbostic.Ft void 2661076Sbostic.Fn setinvalidrune "rune_t rune" 2761076Sbostic.Ft rune_t 2861076Sbostic.Fn sgetrune "const char *string" "size_t n" "char const **result" 2961076Sbostic.Ft int 3061076Sbostic.Fn sputrune "rune_t rune" "char *string" "size_t n" "char **result" 3163585Sbostic.sp 3263585Sbostic.Fd #include <stdio.h> 3363585Sbostic.Ft long 3463585Sbostic.Fn fgetrune "FILE *stream" 3563585Sbostic.Ft int 3663585Sbostic.Fn fungetrune "rune_t rune" "FILE *stream" 3763585Sbostic.Ft int 3863585Sbostic.Fn fputrune "rune_t rune" "FILE *stream" 3961076Sbostic.Sh DESCRIPTION 4061076SbosticThe 4161076Sbostic.Fn setrunelocale 4261076Sbosticcontrols the type of encoding used to represent runes as multibyte strings 4361076Sbosticas well as the properties of the runes as defined in 4461076Sbostic\fB<ctype.h>\fP. 4561076SbosticThe 4661076Sbostic.Fa locale 47*65099Smckusickargument indicates which locale to load. 4861076SbosticIf the locale is successfully loaded, 4961076Sbostic.Dv 0 5061076Sbosticis returned, otherwise an errno value is returned to indicate the 5161076Sbostictype of error. 5261076Sbostic.Pp 5361076SbosticThe 5461076Sbostic.Fn setinvalidrune 5561076Sbosticfunction sets the value of the global value 5661076Sbostic.Ev _INVALID_RUNE 5761076Sbosticto be 5861076Sbostic.Fa rune. 5961076Sbostic.Pp 6061076SbosticThe 6161076Sbostic.Fn sgetrune 6261076Sbosticfunction tries to read a single multibyte character from 6361076Sbostic.Fa string , 6461076Sbosticwhich is at most 6561076Sbostic.Fa n 6661076Sbosticbytes long. 6761076SbosticIf 6861076Sbostic.Fn sgetrune 6961076Sbosticis successful, the rune is returned. 7061076SbosticIf 7161076Sbostic.Fa result 7261076Sbosticis not 7361076Sbostic.Dv NULL , 7461076Sbostic.Fa *result 7561076Sbosticwill point to the first byte which was not converted in 7661076Sbostic.Fa string. 7761076SbosticIf the first 7861076Sbostic.Fa n 7961076Sbosticbytes of 8061076Sbostic.Fa string 8161076Sbosticdo not describe a full multibyte character, 8261076Sbostic.Ev _INVALID_RUNE 8361076Sbosticis returned and 8461076Sbostic.Fa *result 8561076Sbosticwill point to 8661076Sbostic.Fa string. 8761076SbosticIf there is an encoding error at the start of 8861076Sbostic.Fa string , 8961076Sbostic.Ev _INVALID_RUNE 9061076Sbosticis returned and 9161076Sbostic.Fa *result 9261076Sbosticwill point to the second character of 9361076Sbostic.Fa string. 9461076Sbostic.Pp 9561076Sbosticthe 9661076Sbostic.Fn sputrune 9761076Sbosticfunction tries to encode 9861076Sbostic.Fa rune 9961076Sbosticas a multibyte string and store it at 10061076Sbostic.Fa string , 10161076Sbosticbut no more than 10261076Sbostic.Fa n 10361076Sbosticbytes will be stored. 10461076SbosticIf 10561076Sbostic.Fa result 10661076Sbosticis not 10761076Sbostic.Dv NULL , 10861076Sbostic.Fa *result 10961076Sbosticwill be set to point to the first byte in string following the new 11061076Sbosticmultibyte character. 11161076SbosticIf 11261076Sbostic.Fa string 11361076Sbosticis 11461076Sbostic.Dv NULL , 11561076Sbostic.Fa *result 11661076Sbosticwill point to 11761076Sbostic.Dv "(char *)0 +" 11861076Sbostic.Fa x , 11961076Sbosticwhere 12061076Sbostic.Fa x 12161076Sbosticis the number of bytes that would be needed to store the multibyte value. 12261076SbosticIf the multibyte character would consist of more than 12361076Sbostic.Fa n 12461076Sbosticbytes and 12561076Sbostic.Fa result 12661076Sbosticis not 12761076Sbostic.Dv NULL , 12861076Sbostic.Fa *result 12961076Sbosticwill be set to 13061076Sbostic.Dv NULL. 13161076SbosticIn all cases, 13261076Sbostic.Fn sputrune 13361076Sbosticwill return the number of bytes which would be needed to store 13461076Sbostic.Fa rune 13561076Sbosticas a multibyte character. 13663585Sbostic.Pp 13763585SbosticThe 13863585Sbostic.Fn fgetrune 13963585Sbosticfunction operates the same as 14063585Sbostic.Fn sgetrune 14163585Sbosticwith the exception that it attempts to read enough bytes from 14263585Sbostic.Fa stream 14363585Sbosticto decode a single rune. It returns either 14463585Sbostic.Ev EOF 14563585Sbosticon end of file, 14663585Sbostic.Ev _INVALID_RUNE 14763585Sbosticon an encoding error, or the rune decoded if all went well. 14863585Sbostic.Pp 14963585SbosticThe 15063585Sbostic.Fn fungetrune 151*65099Smckusickfunction pushes the multibyte encoding, as provided by 15263585Sbostic.Fn sputrune , 15363585Sbosticof 15463585Sbostic.Fa rune 15563585Sbosticonto 15663585Sbostic.Fa stream 15763585Sbosticsuch that the next 15863585Sbostic.Fn fgetrune 15963585Sbosticcall will return 16063585Sbostic.Fa rune . 16163585SbosticIt returns 16263585Sbostic.Ev EOF 16363585Sbosticif it fails and 16463585Sbostic.Dv 0 16563585Sbosticon success. 16663585Sbostic.Pp 16763585SbosticThe 16863585Sbostic.Fn fputrune 16963585Sbosticfunction writes the multibyte encoding of 17063585Sbostic.Fa rune , 17163585Sbosticas provided by 17263585Sbostic.Fn sputrune , 17363585Sbosticonto 17463585Sbostic.Fa stream . 17563585SbosticIt returns 17663585Sbostic.Ev EOF 17763585Sbosticon failure and 17863585Sbostic.Dv 0 17963585Sbosticon success. 18061076Sbostic.Sh RETURN VALUES 18161076SbosticThe 18261076Sbostic.Fn setrunelocale 18361076Sbosticfunction returns one of the following values: 18461076Sbostic.Bl -tag -width WWWWWWWW 18561076Sbostic.It Dv 0 18661076Sbostic.Fa setrunelocale was successful. 18761076Sbostic.It Ev EFAULT 18861076Sbostic.Fa locale 18961076Sbosticwas 19061076Sbostic.Dv NULL . 19161076Sbostic.It Ev ENOENT 19261076SbosticThe locale could not be found. 19361076Sbostic.It Ev EFTYPE 19461076SbosticThe file found was not a valid file. 19561076Sbostic.It Ev EINVAL 19661076SbosticThe encoding indicated by the locale was unknown. 19761076Sbostic.El 19861076Sbostic.Pp 19961076SbosticThe 20061076Sbostic.Fn sgetrune 20161076Sbosticfunction either returns the rune read or 20261076Sbostic.Ev _INVALID_RUNE . 20361076SbosticThe 20461076Sbostic.Fn sputrune 20561076Sbosticfunction returns the number of bytes needed to store 20661076Sbostic.Fa rune 20761076Sbosticas a multibyte string. 20861076Sbostic.Sh FILES 20961076Sbostic.Bl -tag -width /usr/share/locale/locale/LC_CTYPE -compact 21061076Sbostic.It Pa $PATH_LOCALE/\fIlocale\fP/LC_CTYPE 21161076Sbostic.It Pa /usr/share/locale/\fIlocale\fP/LC_CTYPE 21261076Sbosticbinary LC_CTYPE file for the locale \fIlocale\fP. 21361076Sbostic.El 21461076Sbostic.Sh "SEE ALSO 21561076Sbostic.Xr euc 4 , 21661076Sbostic.Xr mbrune 3 , 21761076Sbostic.Xr setlocale 3 , 21861076Sbostic.Xr utf2 4 21961076Sbostic.Sh NOTE 22061076SbosticThe ANSI C type 22161076Sbostic.Ev wchar_t 22261076Sbosticis the same as 22361076Sbostic.Ev rune_t . 22461076Sbostic.Ev Rune_t 22561076Sbosticwas chosen to accent the purposeful choice of not basing the 22661076Sbosticsystem with the ANSI C 22761076Sbosticprimitives, which were, shall we say, less aesthetic. 22861076Sbostic.Sh HISTORY 22961076SbosticThese functions first appeared in 23061076Sbostic.Bx 4.4 . 23161076Sbostic.Pp 23261076SbosticThe 23361076Sbostic.Fn setrunelocale 23461076Sbosticfunction and the other non-ANSI rune functions were inspired by 23561076Sbostic.Nm Plan 9 from Bell Labs 23661076Sbosticas a much more sane alternative to the ANSI multibyte and 23761076Sbosticwide character support. 23861081Sbostic.\"They were conceived at the San Diego 1993 Summer USENIX conference by 23961081Sbostic.\"Paul Borman of Krystal Technologies, Keith Bostic of CSRG and Andrew Hume 24061081Sbostic.\"of Bell Labs. 24161076Sbostic.Pp 24261076SbosticAll of the ANSI multibyte and wide character 24361076Sbosticsupport functions are built using the rune functions. 244