=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/builtin/io.texi,v retrieving revision 1.2 retrieving revision 1.9 diff -u -p -r1.2 -r1.9 --- OpenXM/src/asir-doc/parts/builtin/io.texi 1999/12/21 02:47:33 1.2 +++ OpenXM/src/asir-doc/parts/builtin/io.texi 2002/09/03 01:50:59 1.9 @@ -1,4 +1,4 @@ -@comment $OpenXM$ +@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/io.texi,v 1.8 2002/07/15 01:58:24 takayama Exp $ \BJP @node 入出力,,, 組み込み函数 @section 入出力 @@ -16,6 +16,7 @@ * bsave bload:: * bload27:: * print:: +* open_file close_file get_line get_byte put_byte purge_stdin:: @end menu \JP @node end quit,,, 入出力 @@ -81,7 +82,7 @@ line of the input file is strongly recommended. @table @t @item load("@var{filename}") \JP :: @var{filename} を読み込む. -\EG :: Read a program file @var{filename}. +\EG :: Reads a program file @var{filename}. @end table @table @var @@ -95,7 +96,7 @@ line of the input file is strongly recommended. @itemize @bullet \BJP @item -実際のプログラムの書き方は, @xref{ユーザ言語 Asir}. +実際のプログラムの書き方は, @pxref{ユーザ言語 Asir}. テキストファイルを読み込む場合, @code{cpp} を通すので, C のプログラム同様 @code{#include}, @code{#define} を使うことができる. @item @@ -120,7 +121,7 @@ Windows 版もディレクトリのセパレータとして @samp \E \BEG @item -@xref{User language Asir} for practical programming. +See @ref{User language Asir} for practical programming. Since text files are read through @code{cpp}, the user can use, as in C programs, @code{#include} and @code{#define} in @b{Asir} program source codes. @@ -139,7 +140,7 @@ On Windows, @code{get_rootdir()/lib} is searched if We recommend to write an @code{end} command at the last line of your program. If not, @b{Asir} will not give you a prompt after it will have executed @code{load} command. -(Escape with an interrupt character (@pxref{Interruption}), +(Escape with an interrupt character (@ref{Interruption}), if you have lost yourself.) Even in such a situation, @b{Asir} itself is still ready to read keyboard inputs as usual. @@ -330,7 +331,7 @@ output(); @item bsave(@var{obj},"@var{filename}") \JP :: @var{filename} に @var{obj} をバイナリ形式で書き込む. \EG :: This function writes @var{obj} onto @var{filename} in binary form. -@item bsave("@var{filename}") +@item bload("@var{filename}") \JP :: @var{filename} から数式をバイナリ形式で読み込む. \EG :: This function reads an expression from @var{filename} in binary form. @end table @@ -421,7 +422,7 @@ y^2+2*x*y+x^2 @findex bload27 @table @t -@item xxx(@var{filename}) +@item bload27("@var{filename}") \JP :: 旧版で作られた bsave file の読み込み \EG :: Reads bsaved file created by older version of @b{Asir}. @end table @@ -531,3 +532,146 @@ convenient to minimize programming efforts. xyz123gahaha @end example +\JP @node open_file close_file get_line get_byte put_byte purge_stdin,,, 入出力 +\EG @node open_file close_file get_line get_byte put_byte purge_stdin,,, Inputs and Outputs +@subsection @code{open_file}, @code{close_file}, @code{get_line}, @code{get_byte}, @code{put_byte}, @code{purge_stdin} +@findex open_file +@findex close_file +@findex get_line +@findex get_byte +@findex put_byte +@findex purge_stdin + +@table @t +@item open_file("@var{filename}"[,"@var{mode}"]) +\JP :: @var{filename} をオープンする. +\EG :: Opens @var{filename} for reading. +@item close_file(@var{num}) +\JP :: 識別子 @var{num} のファイルをクローズする. +\EG :: Closes the file indicated by a descriptor @var{num}. +@item get_line([@var{num}]) +\JP :: 識別子 @var{num} のファイルから 1 行読む. +\EG :: Reads a line from the file indicated by a descriptor @var{num}. +@item get_byte(@var{num}) +\JP :: 識別子 @var{num} のファイルから 1 バイト読む. +\EG :: Reads a byte from the file indicated by a descriptor @var{num}. +@item put_byte(@var{num},@var{c}) +\JP :: 識別子 @var{num} のファイルに 1 バイト @var{c} を書く. +\EG :: Writes a byte @var{c} to the file indicated by a descriptor @var{num}. +@item purge_stdin() +@item purge_stdin() +\JP :: 標準入力のバッファをクリアする. +\EG :: Clears the buffer for the standard input. +@end table + +@table @var +@item return +\JP @code{open_file()} : 整数 (識別子); @code{close_file()} : 1; @code{get_line()} : 文字列; @code{get_byte()}, @code{put_byte()} : 整数 +\EG @code{open_file()} : integer (fild id); @code{close_file()} : 1; @code{get_line()} : string; @code{get_byte()}, @code{put_byte()} : integer +@item filename +\JP ファイル名 (パス名) +\EG file (path) name +@item mode +\JP 文字列 +\EG string +@item num +\JP 非負整数 (ファイル識別子) +\EG non-negative integer (file descriptor) +@end table + +@itemize @bullet +\BJP +@item @code{open_file()} はファイルをオープンする. @var{mode} 指定が +ない場合読み出し用, @var{mode} 指定がある場合には, C の標準入出力 +関数 @code{fopen()} に対するモード指定とみなす. たとえば新規書き込み +用の場合 @code{"w"}, 末尾追加の場合 @code{"a"} など. +成功した場合, ファイル識別子として非負整数を返す. 失敗の場合エラーとなる. +不要になったファイルは @code{close_file()} でクローズする. +@item @code{get_line()} は現在オープンしているファイルから 1 行読み, +文字列として返す. 引数がない場合, 標準入力から 1 行読む. +@item @code{get_byte()} は現在オープンしているファイルから 1 バイト読み +整数として返す. +@item @code{put_byte()} は現在オープンしているファイルに 1 バイト書き, +そのバイトを整数として返す. +@item ファイルの終りまで読んだ後に @code{get_line()} が呼ばれた場合, +整数の 0 を返す. +@item 読み出した文字列は, 必要があれば @code{sub_str()} などの文字列処理 +関数で加工したのち @code{eval_str()} により内部形式に変換できる. +@item @code{purge_stdin()} は, 標準入力バッファを空にする. +関数内で @code{get_line()} により標準入力から文字列を受け取る場合, +既にバッファ内に存在する文字列による誤動作を防ぐためにあらかじめ +呼び出す. +\E +\BEG +@item @code{open_file()} opens a file. +If @var{mode} is not specified, a file is opened for reading. +If @var{mode} is specified, it is used as the mode specification for +C standard I/O function @code{fopen()}. For example @code{"w"} requests +that the file is truncated to zero length or created for writing. +@code{"a"} requests that the file is opened for writing or created +if it does not exist. +The stream pointer is set at the end of the file. +If successful, it returns a non-negative integer as the file descriptor. +Otherwise the system error function is called. +Unnecessary files should be closed by @code{close_file()}. +@item @code{get_line()} reads a line from an opened file and returns the +line as a string. If no argument is supplied, it reads a line from the +standard input. +@item @code{get_byte()} reads a byte from an opened file and returns the +it as an integer. +@item @code{put_byte()} writes a byte from an opened file and returns the +the byte as an integer. +@item A @code{get_line()} call after reading the end of file returns +an integer 0. +@item Strings can be converted into internal forms with string manipulation +functions such as @code{sub_str()}, @code{eval_str()}. +@item @code{purge_stdin()} clears the buffer for the standard input. +When a function receives a character string from @code{get_line()}, +this functions should be called in advance in order to avoid +an incorrect behavior which is caused by the characters already +exists in the buffer. +\E +@end itemize + +@example +[185] Id = open_file("test"); +0 +[186] get_line(Id); +12345 + +[187] get_line(Id); +67890 + +[188] get_line(Id); +0 +[189] type(@@@@); +0 +[190] close_file(Id); +1 +[191] open_file("test"); +1 +[192] get_line(1); +12345 + +[193] get_byte(1); +54 /* the ASCII code of '6' */ +[194] get_line(1); +7890 /* the rest of the last line */ +[195] def test() @{ return get_line(); @} +[196] def test1() @{ purge_stdin(); return get_line(); @} +[197] test(); + /* a remaining newline character has been read */ + /* returns immediately */ +[198] test1(); +123; /* input from a keyboard */ +123; /* returned value */ + +[199] + +@end example + +@table @t +\JP @item 参照 +\EG @item References +@fref{eval_str}, @fref{str_len str_chr sub_str}. +@end table