open_file, close_file, get_line, get_byte, put_byte, purge_stdinopen_file() : 整数 (識別子); close_file() : 1; get_line() : 文字列; get_byte(), put_byte() : 整数
open_file() はファイルをオープンする. mode 指定が
ない場合読み出し用, mode 指定がある場合には, C の標準入出力
関数 fopen() に対するモード指定とみなす. たとえば新規書き込み
用の場合 "w", 末尾追加の場合 "a" など.
成功した場合, ファイル識別子として非負整数を返す. 失敗の場合エラーとなる.
不要になったファイルは close_file() でクローズする.
特別なファイル名 unix://stdin, unix://stdout, unix://stderr を与えると
それぞれ標準入力, 標準出力, 標準エラー出力をオープンする.
この場合モード指定は無視される.
get_line() は現在オープンしているファイルから 1 行読み,
文字列として返す. 引数がない場合, 標準入力から 1 行読む.
get_byte() は現在オープンしているファイルから 1 バイト読み
整数として返す.
put_byte() は現在オープンしているファイルに 1 バイト書き,
そのバイトを整数として返す.
get_line() が呼ばれた場合,
整数の 0 を返す.
sub_str() などの文字列処理
関数で加工したのち eval_str() により内部形式に変換できる.
purge_stdin() は, 標準入力バッファを空にする.
関数内で get_line() により標準入力から文字列を受け取る場合,
既にバッファ内に存在する文字列による誤動作を防ぐためにあらかじめ
呼び出す.
[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]
eval_str, section str_len, str_chr, sub_str.
Go to the first, previous, next, last section, table of contents.