<?xml version="1.0" encoding="utf-8"?>
<!--
 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
 * Copyright (C) 2009  - DIGITEO - Antoine ELIAS
 *
 * Copyright (C) 2012 - 2016 - Scilab Enterprises
 *
 * This file is hereby licensed under the terms of the GNU GPL v2.0,
 * pursuant to article 5.3.4 of the CeCILL v.2.1.
 * This file was originally licensed under the terms of the CeCILL v2.1,
 * and continues to be available under such terms.
 * For more information, see the COPYING file which you should have received
 * along with this program.
 *
 -->
<refentry xmlns="http://docbook.org/ns/docbook" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns:svg="http://www.w3.org/2000/svg" xmlns:ns5="http://www.w3.org/1999/xhtml" xmlns:mml="http://www.w3.org/1998/Math/MathML" xmlns:db="http://docbook.org/ns/docbook" xmlns:scilab="http://www.scilab.org" xml:id="String_management_writing_API" xml:lang="ja">
    <refnamediv>
        <refname>文字列の書き込み (Scilab ゲートウェイ)</refname>
        <refpurpose>
            ゲートウェイに文字列の行列を書き込む方法.
        </refpurpose>
    </refnamediv>
    <refsynopsisdiv>
        <title>呼び出し手順</title>
        <para>入力引数プロファイル:</para>
        <synopsis>SciErr createMatrixOfString(void* _pvCtx, int _iVar, int _iRows, int _iCols, const char* const* _pstStrings)</synopsis>
        <synopsis>SciErr createMatrixOfWideString(void* _pvCtx, int _iVar, int _iRows, int _iCols, const wchar_t* const* _pwstStrings)</synopsis>
        <para>名前指定変数プロファイル:</para>
        <synopsis>SciErr createNamedMatrixOfString(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const char* const* _pstStrings)</synopsis>
        <synopsis>SciErr createNamedMatrixOfWideString(void* _pvCtx, const char* _pstName, int _iRows, int _iCols, const wchar_t* const* _pwstStrings)</synopsis>
    </refsynopsisdiv>
    <refsection>
        <title>引数</title>
        <variablelist>
            <varlistentry>
                <term>_pvCtx</term>
                <listitem>
                    <para>
                        Scilab環境ポインタ, api_scilab.h により定義された "pvApiCtx"で指定.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>_iVar</term>
                <listitem>
                    <para>
                        変数を保存するScilabメモリの位置
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>_pstName</term>
                <listitem>
                    <para>
                        "名前指定"関数の場合の変数名.
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>_iRows</term>
                <listitem>
                    <para>
                        新規変数の行数
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>_iCols</term>
                <listitem>
                    <para>
                        新規変数の列数
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>_pstStrings</term>
                <listitem>
                    <para>
                        char*の配列のアドレス (大きさ: _iCols * _iRows)
                    </para>
                </listitem>
            </varlistentry>
            <varlistentry>
                <term>SciErr</term>
                <listitem>
                    <para>
                        エラー構造体で,エラーメッセージ履歴と最初のエラー番号を格納します.
                    </para>
                </listitem>
            </varlistentry>
        </variablelist>
    </refsection>
    <refsection>
        <title>説明</title>
        <para>このヘルプはScilab APIにより文字列の行列を処理する方法を示します.</para>
    </refsection>
    <refsection>
        <!--File_gateway: SCI/modules/api_scilab/tests/unit_tests/string_writing_api.c-->
        <!--File_scilab: SCI/modules/api_scilab/tests/unit_tests/string_writing_api.tst-->
        <!--Lib_name: string_writing-->
        <!--Func_list: write_string-->
        <title>ゲートウェイのソース</title>
        <programlisting role="code_gateway"><![CDATA[
#include "api_scilab.h"
int write_string(char *fname,void* pvApiCtx)
{
	SciErr sciErr;
	//情報変数 : 文字列の行列 2 x 3
	int iRows		= 2;
	int iCols		= 3;
	char** pstData	= NULL;
	//新規変数にデータを保存
	char string11[]	= "may";
	char string21[]	= "be";
	char string12[]	= "the";
	char string22[]	= "with";
	char string13[]	= "puffin";
	char string23[]	= "you";
	//新規配列用にメモリ確保
	pstData			= (char**)malloc(sizeof(char*) * iRows * iCols);
	//"main" 配列にデータアドレスをコピー
	pstData[0]		= string11;
	pstData[1]		= string21;
	pstData[2]		= string12;
	pstData[3]		= string22;
	pstData[4]		= string13;
	pstData[5]		= string23;
	//変数を作成
	sciErr = createMatrixOfString(pvApiCtx, nbInputArgument(pvApiCtx) + 1, iRows, iCols, pstData);
	if(sciErr.iErr)
	{
		printError(&sciErr, 0);
		return 0;
	}
	//コンテナを解放
	free(pstData);
	//確保された変数を左辺に保存
    AssignOutputVariable(pvApiCtx, 1) = nbInputArgument(pvApiCtx) + 1;
	return 0;
}
 ]]></programlisting>
    </refsection>
    <refsection>
        <title>Scilab テストスクリプト</title>
        <programlisting role="code_scilab"><![CDATA[
a_ref = "may the puffin be with you ";
b = [];
a = write_string();
for i=1:size(a,"r")
    for j=1:size(a,"c")
        b = b + a(i,j);
        b = b + " ";
    end
end
if b <> a_ref then error("failed"), end
 ]]></programlisting>
    </refsection>
</refentry>
