.\" (c) 1993 by Thomas Koenig (ig25@rz.uni-karlsruhe.de) .\" and 1999 by Bruno Haible (haible@clisp.cons.org) .\" .\" Permission is granted to make and distribute verbatim copies of this .\" manual provided the copyright notice and this permission notice are .\" preserved on all copies. .\" .\" Permission is granted to copy and distribute modified versions of this .\" manual under the conditions for verbatim copying, provided that the .\" entire resulting derived work is distributed under the terms of a .\" permission notice identical to this one .\" .\" Since the Linux kernel and libraries are constantly changing, this .\" manual page may be incorrect or out-of-date. The author(s) assume no .\" responsibility for errors or omissions, or for damages resulting from .\" the use of the information contained herein. The author(s) may not .\" have taken the same level of care in the production of this manual, .\" which is licensed free of charge, as they might when working .\" professionally. .\" .\" Formatted or processed versions of this manual, if unaccompanied by .\" the source, must acknowledge the copyright and authors of this work. .\" License. .\" Modified Sat Jul 24 18:20:12 1993 by Rik Faith (faith@cs.unc.edu) .\" Modified Tue Jul 15 16:49:10 1997 by Andries Brouwer (aeb@cwi.nl) .\" Modified Sun Jul 4 14:52:16 1999 by Bruno Haible (haible@clisp.cons.org) .\" Modified Tue Aug 24 17:11:01 1999 by Andries Brouwer (aeb@cwi.nl) .\" Modified Tue Feb 6 03:31:55 2001 by Andries Brouwer (aeb@cwi.nl) .TH SETLOCALE 3 1999-07-04 "GNU" "Linux Programmer's Manual" .SH NAME setlocale \- 設置當前的區域選項 .SH "總覽 (SYNOPSIS)" .nf .B #include .sp .BI "char *setlocale(int " category ", const char * " locale ");" .fi .SH "描述 (DESCRIPTION)" .B setlocale() 函數 用來 設置 或者 查詢 程序 當前 的 區域選項. .PP 如果 .I locale 不是 .BR NULL , 程序 就會 根據 參數 更改 相應的 區域選項. .I category 參數 指定 區域選項 的 哪一部分 需要 更改. .TP .B LC_ALL 代表 所有 部分. .TP .B LC_COLLATE 代表 正則 表達式 匹配 (和 範圍 表達式[range expressions] 以及 字符類[classes] 有關係) 和 字符串 排序. .TP .B LC_CTYPE 代表 正則 表達式 匹配, 字符類(character classification), 轉換, 區分大小寫 的 比較, 以及 寬字符 函數. .TP .B LC_MESSAGES 代表 可以 本地化的 消息 (自然語言). .TP .B LC_MONETARY 代表 貨幣 格式. .TP .B LC_NUMERIC 代表 數字 格式 (比如 小數點 和 千位分組符). .TP .B LC_TIME 代表 時間 和 日期 格式. .PP .I locale 參數 是 一個 指向 字符串的 指針. 此 字符串 爲 .IR category 需要的 設置. 此 字符串 可以是 一個 衆所周知 的 區域選項 常量, 如 "C" 或 "da_DK" (見下), 也可以是 另外 一個 .BR setlocale 調用 返回 的 字符串. .PP 如果 .I locale 是 .BR """""" , 需要 更改 的 部分 會根據 環境變量 做 相應的 設置. 具體的 和 實現 有關. 對於 glibc 來說, 首先 查看 .\" [This is false on my system - must check which library versions do this] .\" if .\" .I category .\" is LC_MESSAGES, the environment variable LANGUAGE is inspected, .\" then 環境變量 LC_ALL (不管 .IR category ), 然後 查看 和 category (LC_COLLATE, LC_CTYPE, LC_MESSAGES, LC_MONETARY, LC_NUMERIC, LC_TIME) 同名的 環境變量, 最後 查看 環境變量 LANG. 以 先查到 的 環境變量 爲準. 如果 其值 不是 一個 有效 的 區域選項, 區域選項 將 不會改變, .B setlocale 會 返回 NULL. .\" The environment variable LANGUAGE may contain several, colon-separated, .\" locale names. .PP 標準 區域選項 .B """C""" 和 .B """POSIX""" 是 可移植的; 它的 LC_CTYPE 部分 對應的 是 7 位的 ASCII 字符集. .PP 一個 典型的 區域選項 有 如下的 格式: .IR language "[_" territory "][." codeset "][@" modifier "]," 其中 .I language 是 一個 ISO 639 語言 代碼, .I territory 是 一個 ISO 3166 國家 代碼, .I codeset 是 一個 象 .B "ISO-8859-1" 或者 .BR "UTF-8" 的 字符集 或者 編碼 標識符. 用 "locale -a", cf.\& .BR locale (1) 可以 獲得 一個 系統 支持的 區域選項 的 列表. .PP 如果 .I locale 是 .BR NULL , 意味着 只是 查詢 當前 的 區域選項 而不 更改它. .PP 當 main 程序 開始的 時候 可移植的 .B """C""" 區域選項 作爲 默認值 被設置. 一個 程序 可以 在 初始化 之後 調用 .B setlocale(LC_ALL, """""") 函數, 並且 從 .B localeconv() 調用 的 返回 中 獲得 和 區域選項 相關的 信息, 如果 .BR "MB_CUR_MAX > 1" 就用 多字節 和 寬字節 函數 來 處理 文本, 用 .BR strcoll() ", " wcscoll() 或者 .BR strxfrm() ", " wcsxfrm() 來 比較 字符串, 這樣 就可以 使 程序 有 較好的 移植性. .SH "返回值 (RETURN VALUE)" 一個 成功的 .B setlocale() 調用 會 返回 一個 表示 當前 區域選項 的 字符串 (指針). 這個 字符串 可能 是在 靜態 存儲區 中 分配 的. 之後 用 相應的 category 和 這個 字符串 作爲 參數 再去 調用 這個 函數 會 重新 把 程序 區域選項 的 相應 部分 恢復. 如果 請求 不能 完成 將會 返回 .B NULL . .SH "遵循 (CONFORMING TO)" ANSI C, POSIX.1 .SH "注意 (NOTES)" Linux (也就是, GNU libc) 支持 可移植的 .BR """C""" " 和 " """POSIX""" 區域選項. 在 以前 它 曾經 支持 歐洲 Latin-1 區域選項 .B """ISO-8859-1""" (比如說 在 libc-4.5.21 和 libc-4.6.27 中), 和 俄羅斯的 .B """KOI-8""" (更 準確點 是, "koi-8r") 區域選項 (比如 在 libc-4.6.27 中), 所以 設置 一個 環境變量 LC_CTYPE=ISO-8859-1 就 能夠 讓 isprint() 返回 正確的 結果. 現在 不講 英語 的 歐洲人 會 比以前 更麻煩 一些, 他們 需要 安裝 相應 的 區域選項 文件. .SH "參見 (SEE ALSO)" .BR locale (1), .BR localedef (1), .BR strcoll (3), .BR isalpha (3), .BR localeconv (3), .BR strftime (3), .BR charsets (4), .BR locale (7) .SH "[中文版維護人]" .B 唐友 \ .SH "[中文版最新更新]" .BR 2001/12/2 .SH "[中國Linux論壇man手冊頁翻譯計劃]" .BI http://cmpp.linuxforum.net .SH "跋" .br 本頁面中文版由中文 man 手冊頁計劃提供。 .br 中文 man 手冊頁計劃:\fBhttps://github.com/man-pages-zh/manpages-zh\fR