OSDN Git Service

(split) LDP: Update draft
[linuxjm/LDP_man-pages.git] / draft / man3 / mbstowcs.3
index 08d3ad6..e05d213 100644 (file)
@@ -1,9 +1,13 @@
+.\" t -*- coding: UTF-8 -*-
 .\" Copyright (c) Bruno Haible <haible@clisp.cons.org>
+.\" and Copyright 2014 Michael Kerrisk <mtk.manpages@gmail.com>
 .\"
+.\" %%%LICENSE_START(GPLv2+_DOC_ONEPARA)
 .\" This is free documentation; you can redistribute it and/or
 .\" modify it under the terms of the GNU General Public License as
 .\" published by the Free Software Foundation; either version 2 of
 .\" the License, or (at your option) any later version.
+.\" %%%LICENSE_END
 .\"
 .\" References consulted:
 .\"   GNU glibc-2 source code and manual
 .\"   OpenGroup's Single UNIX specification http://www.UNIX-systems.org/online.html
 .\"   ISO/IEC 9899:1999
 .\"
+.\"*******************************************************************
+.\"
+.\" This file was generated with po4a. Translate the source file.
+.\"
+.\"*******************************************************************
+.\"
 .\" Japanese Version Copyright (c) 1999 HANATAKA Shinya
 .\"         all rights reserved.
 .\" Translated Tue Jan 11 00:56:04 JST 2000
 .\"         by HANATAKA Shinya <hanataka@abyss.rim.or.jp>
 .\"
-.TH MBSTOWCS 3  2011-09-28 "GNU" "Linux Programmer's Manual"
-.\"O .SH NAME
+.TH MBSTOWCS 3 2014\-03\-18 GNU "Linux Programmer's Manual"
 .SH 名前
-.\"O mbstowcs \- convert a multibyte string to a wide-character string
 mbstowcs \- マルチバイト文字列をワイド文字列に変換する
-.\"O .SH SYNOPSIS
 .SH 書式
 .nf
-.B #include <stdlib.h>
+\fB#include <stdlib.h>\fP
 .sp
-.BI "size_t mbstowcs(wchar_t *" dest ", const char *" src ", size_t " n );
+\fBsize_t mbstowcs(wchar_t *\fP\fIdest\fP\fB, const char *\fP\fIsrc\fP\fB, size_t \fP\fIn\fP\fB);\fP
 .fi
-.\"O .SH DESCRIPTION
 .SH 説明
-.\"O If \fIdest\fP is not a NULL pointer, the
-.\"O .BR mbstowcs ()
-.\"O function converts the
-.\"O multibyte string \fIsrc\fP to a wide-character string starting at \fIdest\fP.
-.\"O At most \fIn\fP wide characters are written to \fIdest\fP.
-.\"O The conversion starts
-.\"O in the initial state.
-.\"O The conversion can stop for three reasons:
-\fIdest\fP が NULL ポインターでなければ
-.BR mbstowcs ()
-関数は
-マルチバイト文字列 \fI*src\fP を \fIdest\fP から始まるワイド文字列に
-変換する。\fIdest\fP には最大で \fIn\fP 文字のワイド文字が
-書き込まれる。変換は初期状態で開始され、
+\fIdest\fP が NULL でなければ \fBmbstowcs\fP()  関数は マルチバイト文字列 \fI*src\fP を \fIdest\fP
+から始まるワイド文字列に 変換する。\fIdest\fP には最大で \fIn\fP 文字のワイド文字が 書き込まれる。変換は初期状態で開始され、
 以下の三つのいずれかの条件で停止する:
 .IP 1. 3
-.\"O An invalid multibyte sequence has been encountered.
-.\"O In this case
-.\"O .I (size_t)\ \-1
-.\"O is returned.
-不正なマルチバイト列に遭遇した。この場合には
-.I (size_t)\ \-1
-を返す。
+不正なマルチバイト列に遭遇した。この場合には \fI(size_t)\ \-1\fP を返す。
 .IP 2.
-.\"O \fIn\fP non-L\(aq\\0\(aq wide characters have been stored at \fIdest\fP.
-.\"O In this
-.\"O case the number of wide characters written to \fIdest\fP is returned, but the
-.\"O shift state at this point is lost.
-\fIn\fP 文字の L\(aq\\0\(aq 以外のワイド文字を \fIdest\fP に格納した場合。
-この場合は \fI*src\fP が次に変換されるマルチバイト列を指すようにして、
-\fIdest\fP に書き込まれたワイド文字の数を返す。しかしこの指している
-場所のシフト状態は失われる。
+\fIn\fP 文字の L\(aq\e0\(aq 以外のワイド文字を \fIdest\fP に格納した場合。 この場合は \fI*src\fP
+が次に変換されるマルチバイト列を指すようにして、 \fIdest\fP に書き込まれたワイド文字の数を返す。しかしこの指している 場所のシフト状態は失われる。
 .IP 3.
-.\"O The multibyte string has been completely converted, including the
-.\"O terminating null wide character (\(aq\\0\(aq).
-.\"O In this case the number of wide characters written to
-.\"O \fIdest\fP, excluding the terminating null wide character, is returned.
-マルチバイト文字列が終端の NULL ワイド文字 (\(aq\\0\(aq) まで含めて完全に
-変換された場合。この場合は終端の NULL ワイド文字を除いて
-\fIdest\fP に書き込まれた文字数を返す。
+マルチバイト文字列が終端の NULL ワイド文字 (\(aq\e0\(aq) まで含めて完全に 変換された場合。この場合は終端の NULL
+ワイド文字を除いて \fIdest\fP に書き込まれた文字数を返す。
 .PP
-.\"O The programmer must ensure that there is room for at least \fIn\fP wide
-.\"O characters at \fIdest\fP.
-プログラマーは \fIdest\fP に最低でも \fIn\fP ワイド文字を書き込むこ
-とができる空間があることを保証しなければならない。
+プログラマーは \fIdest\fP に最低でも \fIn\fP ワイド文字を書き込むこ とができる空間があることを保証しなければならない。
 .PP
-.\"O If \fIdest\fP is NULL, \fIn\fP is ignored, and the conversion proceeds as
-.\"O above, except that the converted wide characters are not written out to memory,
-.\"O and that no length limit exists.
-\fIdest\fP が NULL の場合、\fIn\fP は無視され、上記と同様の変換が
-行われるが、変換されたワイド文字はメモリに書き込まれず、変換先の上限
+\fIdest\fP が NULL の場合、\fIn\fP は無視され、上記と同様の変換が 行われるが、変換されたワイド文字はメモリに書き込まれず、変換先の上限
 が存在しない。
 .PP
-.\"O In order to avoid the case 2 above, the programmer should make sure \fIn\fP is
-.\"O greater or equal to \fImbstowcs(NULL,src,0)+1\fP.
-上記の 2. の場合を避けるためにプログラマーは \fIn\fP が
-\fImbstowcs(NULL,src,0)+1\fP 以上であることを保証すべきである。
-.\"O .SH "RETURN VALUE"
+上記の 2. の場合を避けるためにプログラマーは \fIn\fP が \fImbstowcs(NULL,src,0)+1\fP 以上であることを保証すべきである。
 .SH 返り値
-.\"O The
-.\"O .BR mbstowcs ()
-.\"O function returns the number of wide characters that make
-.\"O up the converted part of the wide-character string, not including the
-.\"O terminating null wide character.
-.\"O If an invalid multibyte sequence was
-.\"O encountered,
-.\"O .I (size_t)\ \-1
-.\"O is returned.
-.BR mbstowcs ()
-関数はワイド文字列に変換完了したワイド文字の数を返す。
-終端のナルワイド文字は含まない。不正なマルチバイト列に遭遇した場合には
-.I (size_t)\ \-1
-を返す。
-.\"O .SH "CONFORMING TO"
+\fBmbstowcs\fP()  関数はワイド文字列に変換完了したワイド文字の数を返す。
+終端のナルワイド文字は含まない。不正なマルチバイト列に遭遇した場合には \fI(size_t)\ \-1\fP を返す。
 .SH 準拠
 C99.
-.\"O .SH NOTES
 .SH 注意
-.\"O The behavior of
-.\"O .BR mbstowcs ()
-.\"O depends on the
-.\"O .B LC_CTYPE
-.\"O category of the
-.\"O current locale.
-.BR mbstowcs ()
-の動作は現在のロケールの
-.B LC_CTYPE
-カテゴリに依存している。
+\fBmbstowcs\fP()  の動作は現在のロケールの \fBLC_CTYPE\fP カテゴリに依存している。
 .PP
-.\"O The function
-.\"O .BR mbsrtowcs (3)
-.\"O provides a better interface to the same
-.\"O functionality.
-.BR mbsrtowcs (3)
-関数は同じ機能のより良いインターフェースを提供する。
-.\"O .SH "SEE ALSO"
+\fBmbsrtowcs\fP(3)  関数は同じ機能のより良いインターフェースを提供する。
+.SH 例
+下記のプログラムは \fBmbstowcs\fP() といくつかのワイド文字分類関数の使用方法を示したものである。実行例は以下のようになる。
+.in +4n
+.nf
+
+$ ./t_mbstowcs de_DE.UTF\-8 Grüße!
+Length of source string (excluding terminator):
+    8 bytes
+    6 multibyte characters
+
+Wide character string is: Grüße! (6 characters)
+    G alpha upper
+    r alpha lower
+    ü alpha lower
+    ß alpha lower
+    e alpha lower
+    ! !alpha
+.fi
+.in
+.SS プログラムのソース
+.nf
+#include <locale.h>
+#include <wchar.h>
+#include <stdio.h>
+#include <string.h>
+#include <stdlib.h>
+
+int
+main(int argc, char *argv[])
+{
+    size_t mbslen;      /* Number of multibyte characters in source */
+    wchar_t *wcs;       /* Pointer to converted wide character string */
+    wchar_t *wp;
+
+    if (argc < 3) {
+        fprintf(stderr, "Usage: %s <locale> <string>\en", argv[0]);
+        exit(EXIT_FAILURE);
+    }
+
+    /* Apply the specified locale */
+
+    if (setlocale(LC_ALL, argv[1]) == NULL) {
+        perror("setlocale");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Calculate the length required to hold argv[2] converted to
+       a wide character string */
+
+    mbslen = mbstowcs(NULL, argv[2], 0);
+    if (mbslen == (size_t) \-1) {
+        perror("mbstowcs");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Describe the source string to the user */
+
+    printf("Length of source string (excluding terminator):\en");
+    printf("    %zu bytes\en", strlen(argv[2]));
+    printf("    %zu multibyte characters\en\en", mbslen);
+
+    /* Allocate wide character string of the desired size.  Add 1
+       to allow for terminating null wide character (L\(aq\e0\(aq). */
+
+    wcs = calloc(mbslen + 1, sizeof(wchar_t));
+    if (wcs == NULL) {
+        perror("calloc");
+        exit(EXIT_FAILURE);
+    }
+
+    /* Convert the multibyte character string in argv[2] to a
+       wide character string */
+
+    if (mbstowcs(wcs, argv[2], mbslen + 1) == (size_t) \-1) {
+        perror("mbstowcs");
+        exit(EXIT_FAILURE);
+    }
+
+    printf("Wide character string is: %ls (%zu characters)\en",
+            wcs, mbslen);
+
+    /* Now do some inspection of the classes of the characters in
+       the wide character string */
+
+    for (wp = wcs; *wp != 0; wp++) {
+        printf("    %lc ", (wint_t) *wp);
+
+        if (!iswalpha(*wp))
+            printf("!");
+        printf("alpha ");
+
+        if (iswalpha(*wp)) {
+            if (iswupper(*wp))
+                printf("upper ");
+
+            if (iswlower(*wp))
+                printf("lower ");
+        }
+
+        putchar(\(aq\en\(aq);
+    }
+
+    exit(EXIT_SUCCESS);
+}
+.fi
 .SH 関連項目
-.BR mbsrtowcs (3),
-.BR wcstombs(3)
+\fBmblen\fP(3), \fBmbsrtowcs\fP(3), \fBmbtowc\fP(3), \fBwctomb\fP(3), \fBwcstombs\fP(3)
+.SH この文書について
+この man ページは Linux \fIman\-pages\fP プロジェクトのリリース 3.64 の一部
+である。プロジェクトの説明とバグ報告に関する情報は
+http://www.kernel.org/doc/man\-pages/ に書かれている。