=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/builtin/io.texi,v retrieving revision 1.4 retrieving revision 1.10 diff -u -p -r1.4 -r1.10 --- OpenXM/src/asir-doc/parts/builtin/io.texi 2000/04/28 08:12:01 1.4 +++ OpenXM/src/asir-doc/parts/builtin/io.texi 2003/04/19 15:44:58 1.10 @@ -1,4 +1,4 @@ -@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/io.texi,v 1.3 2000/03/02 07:46:14 noro Exp $ +@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/io.texi,v 1.9 2002/09/03 01:50:59 noro Exp $ \BJP @node 入出力,,, 組み込み函数 @section 入出力 @@ -16,7 +16,7 @@ * bsave bload:: * bload27:: * print:: -* open_file close_file get_line:: +* open_file close_file get_line get_byte put_byte purge_stdin:: @end menu \JP @node end quit,,, 入出力 @@ -96,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 @@ -121,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. @@ -140,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. @@ -521,7 +521,7 @@ The last 0 will not be printed. ) @item Formatted outputs are not currently supported. If one wishes to output multiple objects by a single @code{print()} command, -use list like @code{[@var{obj1,...}]}, which is not so beautiful, but +use list like @code{[@var{obj1},...]}, which is not so beautiful, but convenient to minimize programming efforts. \E @end itemize @@ -532,32 +532,48 @@ convenient to minimize programming efforts. xyz123gahaha @end example -\JP @node open_file close_file get_line,,, 入出力 -\EG @node open_file close_file get_line,,, Inputs and Outputs -@subsection @code{open_file}, @code{close_file}, @code{get_line} +\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}") -\JP :: @var{filename} を読み出し用にオープンする. +@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}) +@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()} : 文字列 -\EG @code{open_file()} : integer (fild id); @code{close_file()} : 1; @code{get_line()} : string +\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) @@ -565,27 +581,55 @@ xyz123gahaha @itemize @bullet \BJP -@item @code{open_file()} は読み出し用にファイルをオープンする. 成功した -場合, ファイル識別子として非負整数を返す. 失敗の場合エラーとなる. +@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 for reading. +@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. +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 @@ -602,6 +646,28 @@ functions such as @code{sub_str()}, @code{eval_str()}. 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