.\" (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