=================================================================== RCS file: /home/cvs/OpenXM/src/asir-doc/parts/builtin/io.texi,v retrieving revision 1.5 retrieving revision 1.17 diff -u -p -r1.5 -r1.17 --- OpenXM/src/asir-doc/parts/builtin/io.texi 2000/11/13 00:16:36 1.5 +++ OpenXM/src/asir-doc/parts/builtin/io.texi 2014/04/09 05:34:30 1.17 @@ -1,4 +1,4 @@ -@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/io.texi,v 1.4 2000/04/28 08:12:01 noro Exp $ +@comment $OpenXM: OpenXM/src/asir-doc/parts/builtin/io.texi,v 1.16 2008/07/17 15:01:10 iwane Exp $ \BJP @node 入出力,,, 組み込み函数 @section 入出力 @@ -16,7 +16,9 @@ * bsave bload:: * bload27:: * print:: -* open_file close_file get_line get_byte purge_stdin:: +* access:: +* remove_file:: +* open_file close_file get_line get_byte put_byte purge_stdin:: @end menu \JP @node end quit,,, 入出力 @@ -96,9 +98,14 @@ line of the input file is strongly recommended. @itemize @bullet \BJP @item -実際のプログラムの書き方は, @xref{ユーザ言語 Asir}. +実際のプログラムの書き方は, @pxref{ユーザ言語 Asir}. テキストファイルを読み込む場合, @code{cpp} を通すので, C のプログラム同様 @code{#include}, @code{#define} を使うことができる. +unix 版では, システムにインストールされている @code{cpp} を利用している. +Windows 版では @code{mcpp} @url{http://mcpp.sourceforge.net} を用いている. +これには行の長さに制限があるので注意. +unix/OpenXM 版(Mac 用 cfep/asir を含む)では @code{OpenXM/bin/ox_cpp} を用いている. +これは Portable C compiler @url{http://pcc.ludd.ltu.se} に附属する @code{cpp} である. @item 指定したファイルが存在した時には 1 を返し, 存在しなかった時は 0 を返す. @item @@ -121,10 +128,16 @@ 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. +The @code{cpp} which is installed to the system with a C compler is used in the unix version. +The @code{mcpp} @url{http://mcpp.sourceforge.net} is used in the Windows version. +Note that the length of a line has a limit for an input @code{mcpp}. +The @code{OpenXM/bin/ox_cpp} is used in the unix/OpenXM version +(including cfep/asir for MacOS X). +This is the @code{cpp} distributed with the Portable C compiler @url{http://pcc.ludd.ltu.se}. @item It returns 1 if the designated file exists, 0 otherwise. @item @@ -140,7 +153,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. @@ -492,7 +505,7 @@ On Windows one has to use @samp{/} as the separator of @var{obj} を評価して表示する. @item 第 2 引数がないか, または 0, 2 以外の場合, 改行する. -第 2 引数が 1 の場合, 改行せず, 出力はバッファに書き込まれ, +第 2 引数が 0 の場合, 改行せず, 出力はバッファに書き込まれ, バッファはフラッシュされない. 第 2 引数が 2 の場合, 改行しないがバッファはフラッシュされる. @item @@ -521,29 +534,76 @@ 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 @example -[8] def cat(L) @{ while ( L != [] ) @{ print(car(L),0); L = cdr(L);@} print(""); @} +[8] def cat(L) @{ while ( L != [] ) @{ print(car(L),0); L = cdr(L);@} +print(""); @} [9] cat([xyz,123,"gahaha"])$ xyz123gahaha @end example -\JP @node open_file close_file get_line get_byte purge_stdin,,, 入出力 -\EG @node open_file close_file get_line get_byte purge_stdin,,, Inputs and Outputs -@subsection @code{open_file}, @code{close_file}, @code{get_line}, @code{get_byte}, @code{purge_stdin} +\JP @node access,,, 入出力 +\EG @node access,,, Inputs and Outputs +@subsection @code{access} +@findex access + +@table @t +@item access(@var{file}) +\JP :: @var{file} の存在をテストする. +\EG :: testing an existence of @var{file}. +@end table + +@table @var +@item return +(1|0) +@item file +\JP ファイル名 +\EG filename +@end table + +@itemize @bullet +\BJP +@item +@var{file} が存在すれば 1, 存在しなければ 0 を返す. +\E +@end itemize + +\JP @node remove_file,,, 入出力 +\EG @node remove_file,,, Inputs and Outputs +@subsection @code{remove_file} +@findex remove_file + +@table @t +@item remove_file(@var{file}) +\JP :: @var{file} を消去する. +\EG :: Delete an file @var{file}. +@end table + +@table @var +@item return +1 +@item file +\JP ファイル名 +\EG filename +@end table + +\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} のファイルをクローズする. @@ -554,6 +614,9 @@ xyz123gahaha @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() \JP :: 標準入力のバッファをクリアする. \EG :: Clears the buffer for the standard input. @@ -561,11 +624,14 @@ xyz123gahaha @table @var @item return -\JP @code{open_file()} : 整数 (識別子); @code{close_file()} : 1; @code{get_line()} : 文字列, @code{get_byte()} : 整数 -\EG @code{open_file()} : integer (fild id); @code{close_file()} : 1; @code{get_line()} : string, @code{get_byte()} : integer +\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) @@ -573,13 +639,21 @@ 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()} でクローズする. +特別なファイル名 unix://stdin, unix://stdout, unix://stderr を与えると +それぞれ標準入力, 標準出力, 標準エラー出力をオープンする. +この場合モード指定は無視される. @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()} などの文字列処理 @@ -590,15 +664,28 @@ xyz123gahaha 呼び出す. \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()}. +If the special file name unix://stdin or unix://stdout or unix://stderr +is given, it returns the file descriptor for the standard input or +the standard output or the standard error stream respectively. +The mode argument is ignored in this case. @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