=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/appendix.texi,v retrieving revision 1.5 retrieving revision 1.6 diff -u -p -r1.5 -r1.6 --- OpenXM/src/asir-doc/parts/appendix.texi 2000/03/17 02:17:03 1.5 +++ OpenXM/src/asir-doc/parts/appendix.texi 2000/03/17 08:27:28 1.6 @@ -1,4 +1,4 @@ -@comment $OpenXM: OpenXM/src/asir-doc/parts/appendix.texi,v 1.4 1999/12/24 04:38:04 noro Exp $ +@comment $OpenXM: OpenXM/src/asir-doc/parts/appendix.texi,v 1.5 2000/03/17 02:17:03 noro Exp $ \BJP @node 付録,,, Top @appendix 付録 @@ -13,6 +13,7 @@ * 文法の詳細:: * 添付のユーザ定義函数ファイル:: * 入力インタフェース:: +* ライブラリインタフェース:: * 変更点:: * 文献:: \E @@ -20,6 +21,7 @@ * Details of syntax:: * Files of user defined functions:: * Input interfaces:: +* Library interfaces:: * Changes:: * References:: \E @@ -636,6 +638,304 @@ is available via ftp. The way of setting up and the usage can be found at the top of @samp{asir.el}. \E + +\BJP +@node ライブラリインタフェース,,, 付録 +@section ライブラリインタフェース +\E +\BEG +@node Library interfaces,,, Appendix +@section Library interfaces +\E + +\BJP +@b{Asir} の提供する機能を他のプログラムから使用する方法として, @b{OpenXM} による +他に, ライブラリの直接リンクによる方法が可能である. ライブラリは, +GC ライブラリである @samp{libasir-gc.a} とともに @b{OpenXM} +distribution (@code{http://www.math.kobe-u.ac.jp/OpenXM}) に含まれる. +現状では@b{OpenXM} インタフェースのみが公開されているため, 以下では +@b{OpenXM} がインストールされていると仮定する. @b{OpenXM} root ディレクトリを +@code{$OpenXM_HOME}と書く. ライブラリファイルは全て @samp{$OpenXM_HOME/lib} +におかれている. ライブラリには以下の 3 種類がある. +\E +\BEG +It is possible to link an @b{Asir} library to use the functionalities of +@b{Asir} from other programs. +The necessary libraries are included in the @b{OpenXM} distribution +(@code{http://www.math.kobe-u.ac.jp/OpenXM}). +At present only the @b{OpenXM} interfaces are available. Here we assume +that @b{OpenXM} is already installed. In the following +@code{$OpenXM_HOME} denotes the @b{OpenXM} root directory. +All the library files are placed in @samp{$OpenXM_HOME/lib}. +There are three kinds of libraries as follows. +\E +@itemize @bullet +@item @samp{libasir.a} +@* +\BJP +@b{PARI}, @b{X11} 関連の機能を含まない. +リンクには @samp{libasir-gc.a} のみが必要. +\E +\BEG +It does not contain the functionalities related to @b{PARI} and @b{X11}. +Only @samp{libasir-gc.a} is necessary for linking. +\E + +@item @samp{libasir_pari.a} +@* +\BJP +@b{X11} 関連の機能を含まない. リンクには @samp{libasir-gc.a}, +@samp{libpari.a} が必要. +\E +\BEG +It does not contain the functionalities related to @b{X11}. +@samp{libasir-gc.a}, @samp{libpari.a} are necessary for linking. +\E + +@item @samp{libasir_pari_X.a} +@* +\BJP +全ての機能を含む. リンクには @samp{libasir-gc.a}, @samp{libpari.a} +および @b{X11} 関連のライブラリ指定が必要. +\E +\BEG +All the functionalities are included. @samp{libasir-gc.a}, @samp{libpari.a} +and libraries related to @b{X11} are necessary for linking. +\E +@end itemize +\BJP +提供されている関数は以下の通りである. +\E +@itemize @bullet +@item @code{int asir_ox_init(int @var{byteorder})} +@* +\BJP +ライブラリの初期化. @var{byteorder} はメモリ上へのバイナリ CMO データ +への展開方法を指定する. @var{byteorder} が 0 のときマシン固有の byteorder +を用いる. 1 のとき network byteorder を用いる. 初期化に成功した場合 0, +失敗の時 -1 を返す. +\E +\BEG +It initializes the library. +@var{byteorder} specifies the format of binary CMO data on the memory. +If @var{byteorder} is 0, the byteorder native to the machine is used. +If @var{byteorder} is 1, the network byteorder is used. It returns +0 if the initialization is successful, -1 otherwise. +\E + +@item @code{void asir_ox_push_cmo(void *@var{cmo})} +@* +\BJP +メモリ上に置かれた CMO データを @b{Asir} の内部形式に変換してスタックに +push する. +\E +\BJP +It converts CMO data pointed by @var{cmo} into an @b{Asir} object and +it pushes the object onto the stack. +\E + +@item @code{int asir_ox_peek_cmo_size()} +@* +\BJP +スタックの最上位にある @b{Asir} データを CMO に変換したときのサイズを返す. +変換不能な場合には -1 を返す. +\E +\BEG +It returns the size of the object at the top of the stack as CMO object. +It returns -1 if the object cannot be converted into CMO object. +\E + +@item @code{int asir_ox_pop_cmo(void *@var{cmo}, int @var{limit})} +@* +\BJP +スタックの最上位にある @b{Asir} データを pop し, CMO に変換して @var{cmo}で +指される配列に書き, CMO のサイズを返す. このとき, CMO のサイズが +@var{limit} より大きい場合には -1 を返す. @var{cmo} は長さが少なくとも +@var{limit}バイトの配列を指す必要がある. 変換された CMO を収容できる +配列の長さを知るために, @code{asir_ox_peek_cmo_size} を用いる. +\E +\BEG +It pops an @b{Asir} object at the top of the stack and it converts +the object into CMO data. If the size of the CMO data is not greater +than @var{limit}, then the data is written in @var{cmo} and the size +is returned. Otherwise -1 is returned. The size of the array pointed +by @var{cmo} must be at least @var{limit}. In order to know the size +of converted CMO data in advance @code{asir_ox_peek_cmo_size} is called. +\E + +@item @code{void asir_ox_push_cmd(int @var{cmd})} +@* +\BJP +スタックマシンコマンド @var{cmd} を実行する. +\E +\BEG +It executes a stack machine command @var{cmd}. +\E + +@item @code{void asir_ox_execute_string(char *@var{str})} +@* +\BJP +@b{Asir} が実行可能な文字列 @var{str} を実行し, その結果をスタックに push する. +\E +\BEG +It evaluates @var{str} as a string written in the @b{Asir} user language. +The result is pushed onto the stack. +\E +@end itemize + +\BJP +include すべき header file は @samp{$OpenXM_HOME/include/asir/ox.h} である. +この header file には, @b{OpenXM} に関する全ての tag, command の定義が含まれて +いる. +次の例 (@samp{$OpenXM_HOME/doc/oxlib/test3.c}) は上記関数の使用 +法を示す. +\E +\BEG +A program calling the above functions should include +@samp{$OpenXM_HOME/include/asir/ox.h}. +In this file all the definitions of @b{OpenXM} tags and commands. +The following example +(@samp{$OpenXM_HOME/doc/oxlib/test3.c}) illustrates the usage of +the above functions. +\E + +@example +#include +#include + +main(int argc, char **argv) +@{ + char buf[BUFSIZ+1]; + int c; + unsigned char sendbuf[BUFSIZ+10]; + unsigned char *result; + unsigned char h[3]; + int len,i,j; + static int result_len = 0; + char *kwd,*bdy; + unsigned int cmd; + + signal(SIGINT,SIG_IGN); + asir_ox_init(1); /* 1: network byte order; 0: native byte order */ + result_len = BUFSIZ; + result = (void *)malloc(BUFSIZ); + while ( 1 ) @{ + printf("Input>"); fflush(stdout); + fgets(buf,BUFSIZ,stdin); + for ( i = 0; buf[i] && isspace(buf[i]); i++ ); + if ( !buf[i] ) + continue; + kwd = buf+i; + for ( ; buf[i] && !isspace(buf[i]); i++ ); + buf[i] = 0; + bdy = buf+i+1; + if ( !strcmp(kwd,"asir") ) @{ + sprintf(sendbuf,"%s;",bdy); + asir_ox_execute_string(sendbuf); + @} else if ( !strcmp(kwd,"push") ) @{ + h[0] = 0; + h[2] = 0; + j = 0; + while ( 1 ) @{ + for ( ; (c= *bdy) && isspace(c); bdy++ ); + if ( !c ) + break; + else if ( h[0] ) @{ + h[1] = c; + sendbuf[j++] = strtoul(h,0,16); + h[0] = 0; + @} else + h[0] = c; + bdy++; + @} + if ( h[0] ) + fprintf(stderr,"Number of characters is odd.\n"); + else @{ + sendbuf[j] = 0; + asir_ox_push_cmo(sendbuf); + @} + @} else if ( !strcmp(kwd,"cmd") ) @{ + cmd = atoi(bdy); + asir_ox_push_cmd(cmd); + @} else if ( !strcmp(kwd,"pop") ) @{ + len = asir_ox_peek_cmo_size(); + if ( !len ) + continue; + if ( len > result_len ) @{ + result = (char *)realloc(result,len); + result_len = len; + @} + asir_ox_pop_cmo(result,len); + printf("Output>"); fflush(stdout); + printf("\n"); + for ( i = 0; i < len; ) @{ + printf("%02x ",result[i]); + i++; + if ( !(i%16) ) + printf("\n"); + @} + printf("\n"); + @} + @} +@} +@end example +\BJP +このプログラムは, @var{keyword} @var{body} なる 1 行を入力として受け取り +@var{keyword} に応じて次のような動作を行う. +\E +\BEG +This program receives a line in the form of @var{keyword} @var{body} +as an input and it executes the following operations according to +@var{keyword}. +\E +@itemize @bullet +@item @code{asir} @var{body} +@* +\BJP +@var{body} を @b{Asir} 言語で書かれた式とみなし, 実行結果をスタックに push する. +@code{asir_ox_execute_string()} が用いられる. +\E +\BEG +@var{body} is regarded as an expression written in the @b{Asir} user language. +The expression is evaluated and the result is pushed onto the stack. +@code{asir_ox_execute_string()} is called. +\E + +@item @code{push} @var{body} +@* +\BJP +@var{body} を 16 進数で表示された CMO データとみなし, @b{Asir} オブジェクトに変換 +してスタックに push する. @code{asir_ox_push_cmo()} が用いられる. +\E +\BEG +@var{body} is regarded as a CMO object in the hexadecimal form. +The CMO object is converted into an @b{Asir} object and is pushed onto the stack. +@code{asir_ox_push_cmo()} is called. +\E + +@item @code{pop} +@* +\BJP +スタック最上位のオブジェクトを CMO に変換し, 16 進数で表示する. +@code{asir_ox_peek_cmo_size()} および @code{asir_ox_pop_cmo()} が用いられる. +\E +\BEG +The object at the top of the stack is converted into a CMO object +and it is displayed in the hexadecimal form. +@code{asir_ox_peek_cmo_size()} and @code{asir_ox_pop_cmo()} are called. +\E + +@item @code{cmd} @var{body} +@* +\BJP +@var{body} を SM コマンドとみなし, 実行する. +@code{asir_ox_push_cmd()} が用いられる. +\E +\BEG +@var{body} is regarded as an SM command and the command is executed. +@code{asir_ox_push_cmd()} is called. +\E +@end itemize \BJP @node 変更点,,, 付録