1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943
|
.TH io 3 "stdlib 1.15.3" "Ericsson AB" "ERLANG MODULE DEFINITION"
.SH MODULE
io \- Standard IO Server Interface Functions
.SH DESCRIPTION
.LP
This module provides an interface to standard Erlang IO servers\&. The output functions all return \fIok\fR if they are successful, or exit if they are not\&.
.LP
In the following description, all functions have an optional parameter \fIIoDevice\fR\&. If included, it must be the pid of a process which handles the IO protocols\&. Normally, it is the \fIIoDevice\fR returned by file:open/2\&.
.LP
For a description of the IO protocols refer to Armstrong, Virding and Williams, \&'Concurrent Programming in Erlang\&', Chapter 13, unfortunately now very outdated, but the general principles still apply\&.
.SH DATA TYPES
.nf
io_device()
as returned by file:open/2, a process handling IO protocols
.fi
.SH EXPORTS
.LP
.B
columns([IoDevice]) -> {ok,int()} | {error, enotsup}
.br
.RS
.TP
Types
IoDevice = io_device()
.br
.RE
.RS
.LP
Retrieves the number of columns of the \fIIoDevice\fR (i\&.e\&. the width of a terminal)\&. The function only succeeds for terminal devices, for all other devices the function returns \fI{error, enotsup}\fR
.RE
.LP
.B
put_chars([IoDevice,] IoData) -> ok
.br
.RS
.TP
Types
IoDevice = io_device()
.br
IoData = iodata() -- see erlang(3)
.br
.RE
.RS
.LP
Writes the characters of \fIIoData\fR to the standard output (\fIIoDevice\fR)\&.
.RE
.LP
.B
nl([IoDevice]) -> ok
.br
.RS
.TP
Types
IoDevice = io_device()
.br
.RE
.RS
.LP
Writes new line to the standard output (\fIIoDevice\fR)\&.
.RE
.LP
.B
get_chars([IoDevice,] Prompt, Count) -> string() | eof
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
Count = int()
.br
.RE
.RS
.LP
Reads \fICount\fR characters from standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. It returns:
.RS 2
.TP 4
.B
\fIString\fR:
The input characters\&.
.TP 4
.B
\fIeof\fR:
End of file was encountered\&.
.RE
.RE
.LP
.B
get_line([IoDevice,] Prompt) -> string() | eof
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
.RE
.RS
.LP
Reads a line from the standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. It returns:
.RS 2
.TP 4
.B
\fIString\fR:
The characters in the line terminated by a LF (or end of file)\&.
.TP 4
.B
\fIeof\fR:
End of file was encountered\&.
.RE
.RE
.LP
.B
setopts([IoDevice,] Opts) -> ok | {error, Reason}
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Opts = [Opt]
.br
Opt = binary | list
.br
Reason = term()
.br
.RE
.RS
.LP
Set options for standard input/output (\fIIoDevice\fR)\&. Possible options are:
.RS 2
.TP 4
.B
\fIbinary\fR:
Makes \fIget_chars/2, 3\fR and \fIget_line/1, 2\fR return binaries instead of lists of chars\&.
.TP 4
.B
\fIlist\fR:
Makes \fIget_chars/2, 3\fR and \fIget_line/1, 2\fR return lists of chars, which is the default\&.
.TP 4
.B
\fIexpand_fun\fR:
Provide a function for tab-completion (expansion) like the erlang shell\&. This function is called when the user presses the Tab key\&. The expansion is active when calling line-reading functions such as \fIget_line/1, 2\fR\&.
.RS 4
.LP
.LP
The function is called with the current line, upto the cursor, as a reversed string\&. It should return a three-tuple: \fI{yes|no, string(), [string(), \&.\&.\&.]}\fR\&. The first element gives a beep if \fIno\fR, otherwise the expansion is silent, the second is a string that will be entered at the cursor position, and the third is a list of possible expansions\&. If this list is non-empty, the list will be printed and the current input line will be written once again\&.
.LP
.LP
Trivial example (beep on anything except empty line, which is expanded to "quit"):
.LP
.nf
fun("") -> {yes, "quit", []};
(_) -> {no, "", ["quit"]} end
.fi
.RE
.RE
.SS Note:
.LP
The \fIbinary\fR option does not work against IO servers on remote nodes running an older version of Erlang/OTP than R9C\&.
.RE
.LP
.B
write([IoDevice,] Term) -> ok
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Term = term()
.br
.RE
.RS
.LP
Writes the term \fITerm\fR to the standard output (\fIIoDevice\fR)\&.
.RE
.LP
.B
read([IoDevice,] Prompt) -> Result
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
Result = {ok, Term} | eof | {error, ErrorInfo}
.br
Term = term()
.br
ErrorInfo -- see section Error Information below
.br
.RE
.RS
.LP
Reads a term \fITerm\fR from the standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. It returns:
.RS 2
.TP 4
.B
\fI{ok, Term}\fR:
The parsing was successful\&.
.TP 4
.B
\fIeof\fR:
End of file was encountered\&.
.TP 4
.B
\fI{error, ErrorInfo}\fR:
The parsing failed\&.
.RE
.RE
.LP
.B
read(IoDevice, Prompt, StartLine) -> Result
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
StartLine = int()
.br
Result = {ok, Term, EndLine} | {eof, EndLine} | {error, ErrorInfo, EndLine}
.br
Term = term()
.br
EndLine = int()
.br
ErrorInfo -- see section Error Information below
.br
.RE
.RS
.LP
Reads a term \fITerm\fR from \fIIoDevice\fR, prompting it with \fIPrompt\fR\&. Reading starts at line number \fIStartLine\fR\&. It returns:
.RS 2
.TP 4
.B
\fI{ok, Term, EndLine}\fR:
The parsing was successful\&.
.TP 4
.B
\fI{eof, EndLine}\fR:
End of file was encountered\&.
.TP 4
.B
\fI{error, ErrorInfo, EndLine}\fR:
The parsing failed\&.
.RE
.RE
.LP
.B
fwrite(Format) ->
.br
.B
fwrite([IoDevice,] Format, Data) -> ok
.br
.B
format(Format) ->
.br
.B
format([IoDevice,] Format, Data) -> ok
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Format = atom() | string() | binary()
.br
Data = [term()]
.br
.RE
.RS
.LP
Writes the items in \fIData\fR (\fI[]\fR) on the standard output (\fIIoDevice\fR) in accordance with \fIFormat\fR\&. \fIFormat\fR contains plain characters which are copied to the output device, and control sequences for formatting, see below\&. If \fIFormat\fR is an atom or a binary, it is first converted to a list with the aid of \fIatom_to_list/1\fR or \fIbinary_to_list/1\fR\&.
.nf
1> io:fwrite("Hello world!~n", [])\&.
Hello world!
ok
.fi
.LP
The general format of a control sequence is \fI~F\&.P\&.PadC\fR\&. The character \fIC\fR determines the type of control sequence to be used, \fIF\fR and \fIP\fR are optional numeric arguments\&. If \fIF\fR, \fIP\fR, or \fIPad\fR is \fI*\fR, the next argument in \fIData\fR is used as the numeric value of \fIF\fR or \fIP\fR\&.
.LP
\fIF\fR is the \fIfield width\fR of the printed argument\&. A negative value means that the argument will be left justified within the field, otherwise it will be right justified\&. If no field width is specified, the required print width will be used\&. If the field width specified is too small, then the whole field will be filled with \fI*\fR characters\&.
.LP
\fIP\fR is the \fIprecision\fR of the printed argument\&. A default value is used if no precision is specified\&. The interpretation of precision depends on the control sequences\&. Unless otherwise specified, the argument \fIwithin\fR is used to determine print width\&.
.LP
\fIPad\fR is the padding character\&. This is the character used to pad the printed representation of the argument so that it conforms to the specified field width and precision\&. Only one padding character can be specified and, whenever applicable, it is used for both the field width and precision\&. The default padding character is \fI\&' \&'\fR (space)\&.
.LP
The following control sequences are available:
.RS 2
.TP 4
.B
\fI~\fR:
The character \fI~\fR is written\&.
.TP 4
.B
\fIc\fR:
The argument is a number that will be interpreted as an ASCII code\&. The precision is the number of times the character is printed and it defaults to the field width, which in turn defaults to 1\&. The following example illustrates:
.RS 4
.LP
.nf
2> io:fwrite("|~10\&.5c|~-10\&.5c|~5c|~n", [$a, $b, $c])\&.
| aaaaa|bbbbb |ccccc|
ok
.fi
.RE
.TP 4
.B
\fIf\fR:
The argument is a float which is written as \fI[-]ddd\&.ddd\fR, where the precision is the number of digits after the decimal point\&. The default precision is 6 and it cannot be less than 1\&.
.TP 4
.B
\fIe\fR:
The argument is a float which is written as \fI[-]d\&.ddde+-ddd\fR, where the precision is the number of digits written\&. The default precision is 6 and it cannot be less than 2\&.
.TP 4
.B
\fIg\fR:
The argument is a float which is written as \fIf\fR, if it is >= 0\&.1 and < 10000\&.0\&. Otherwise, it is written in the \fIe\fR format\&. The precision is the number of significant digits\&. It defaults to 6 and should not be less than 2\&. If the absolute value of the float does not allow it to be written in the \fIf\fR format with the desired number of significant digits, it is also written in the \fIe\fR format\&.
.TP 4
.B
\fIs\fR:
Prints the argument with the \fIstring\fR syntax\&. The argument is an I/O list, a binary, or an atom\&. The characters are printed without quotes\&. In this format, the printed argument is truncated to the given precision and field width\&.
.RS 4
.LP
.LP
This format can be used for printing any object and truncating the output so it fits a specified field:
.LP
.nf
3> io:fwrite("|~10w|~n", [{hey, hey, hey}])\&.
|**********|
ok
4> io:fwrite("|~10s|~n", [io_lib:write({hey, hey, hey})])\&.
|{hey,hey,h|
ok
.fi
.RE
.TP 4
.B
\fIw\fR:
Writes data with the standard syntax\&. This is used to output Erlang terms\&. Atoms are printed within quotes if they contain embedded non-printable characters, and floats are printed accurately as the shortest, correctly rounded string\&.
.TP 4
.B
\fIp\fR:
Writes the data with standard syntax in the same way as \fI~w\fR, but breaks terms whose printed representation is longer than one line into many lines and indents each line sensibly\&. It also tries to detect lists of printable characters and to output these as strings\&. For example:
.RS 4
.LP
.nf
5> T = [{attributes,[[{id,age,1\&.50000},{mode,explicit},
{typename,"INTEGER"}], [{id,cho},{mode,explicit},{typename,\&'Cho\&'}]]},
{typename,\&'Person\&'},{tag,{\&'PRIVATE\&',3}},{mode,implicit}]\&.
\&.\&.\&.
6> io:fwrite("~w~n", [T])\&.
[{attributes,[[{id,age,1\&.5},{mode,explicit},{typename,
[73,78,84,69,71,69,82]}],[{id,cho},{mode,explicit},{typena
me,\&'Cho\&'}]]},{typename,\&'Person\&'},{tag,{\&'PRIVATE\&',3}},{mode
,implicit}]
ok
7> io:fwrite("~62p~n", [T])\&.
[{attributes,[[{id,age,1\&.5},
{mode,explicit},
{typename,"INTEGER"}],
[{id,cho},{mode,explicit},{typename,\&'Cho\&'}]]},
{typename,\&'Person\&'},
{tag,{\&'PRIVATE\&',3}},
{mode,implicit}]
ok
.fi
.LP
.LP
The field width specifies the maximum line length\&. It defaults to 80\&. The precision specifies the initial indentation of the term\&. It defaults to the number of characters printed on this line in the \fIsame\fR call to \fIio:fwrite\fR or \fIio:format\fR\&. For example, using \fIT\fR above:
.LP
.nf
8> io:fwrite("Here T = ~62p~n", [T])\&.
Here T = [{attributes,[[{id,age,1\&.5},
{mode,explicit},
{typename,"INTEGER"}],
[{id,cho},
{mode,explicit},
{typename,\&'Cho\&'}]]},
{typename,\&'Person\&'},
{tag,{\&'PRIVATE\&',3}},
{mode,implicit}]
ok
.fi
.RE
.TP 4
.B
\fIW\fR:
Writes data in the same way as \fI~w\fR, but takes an extra argument which is the maximum depth to which terms are printed\&. Anything below this depth is replaced with \fI\&.\&.\&.\fR\&. For example, using \fIT\fR above:
.RS 4
.LP
.nf
9> io:fwrite("~W~n", [T,9])\&.
[{attributes,[[{id,age,1\&.5},{mode,explicit},{typename,\&.\&.\&.}],
[{id,cho},{mode,\&.\&.\&.},{\&.\&.\&.}]]},{typename,\&'Person\&'},
{tag,{\&'PRIVATE\&',3}},{mode,implicit}]
ok
.fi
.LP
.LP
If the maximum depth has been reached, then it is impossible to read in the resultant output\&. Also, the \fI, \&.\&.\&.\fR form in a tuple denotes that there are more elements in the tuple but these are below the print depth\&.
.RE
.TP 4
.B
\fIP\fR:
Writes data in the same way as \fI~p\fR, but takes an extra argument which is the maximum depth to which terms are printed\&. Anything below this depth is replaced with \fI\&.\&.\&.\fR\&. For example:
.RS 4
.LP
.nf
10> io:fwrite("~62P~n", [T,9])\&.
[{attributes,[[{id,age,1\&.5},{mode,explicit},{typename,\&.\&.\&.}],
[{id,cho},{mode,\&.\&.\&.},{\&.\&.\&.}]]},
{typename,\&'Person\&'},
{tag,{\&'PRIVATE\&',3}},
{mode,implicit}]
ok
.fi
.RE
.TP 4
.B
\fIB\fR:
Writes an integer in base 2\&.\&.36, the default base is 10\&. A leading dash is printed for negative integers\&.
.RS 4
.LP
.LP
The precision field selects base\&. For example:
.LP
.nf
11> io:fwrite("~\&.16B~n", [31])\&.
1F
ok
12> io:fwrite("~\&.2B~n", [-19])\&.
-10011
ok
13> io:fwrite("~\&.36B~n", [5*36+35])\&.
5Z
ok
.fi
.RE
.TP 4
.B
\fIX\fR:
Like \fIB\fR, but takes an extra argument that is a prefix to insert before the number, but after the leading dash, if any\&.
.RS 4
.LP
.LP
The prefix can be a possibly deep list of characters or an atom\&.
.LP
.nf
14> io:fwrite("~X~n", [31,"10#"])\&.
10#31
ok
15> io:fwrite("~\&.16X~n", [-31,"0x"])\&.
-0x1F
ok
.fi
.RE
.TP 4
.B
\fI#\fR:
Like \fIB\fR, but prints the number with an Erlang style \&'#\&'-separated base prefix\&.
.RS 4
.LP
.nf
16> io:fwrite("~\&.10#~n", [31])\&.
10#31
ok
17> io:fwrite("~\&.16#~n", [-31])\&.
-16#1F
ok
.fi
.RE
.TP 4
.B
\fIb\fR:
Like \fIB\fR, but prints lowercase letters\&.
.TP 4
.B
\fIx\fR:
Like \fIX\fR, but prints lowercase letters\&.
.TP 4
.B
\fI+\fR:
Like \fI#\fR, but prints lowercase letters\&.
.TP 4
.B
\fIn\fR:
Writes a new line\&.
.TP 4
.B
\fIi\fR:
Ignores the next term\&.
.RE
.LP
Returns:
.RS 2
.TP 4
.B
\fIok\fR:
The formatting succeeded\&.
.RE
.LP
If an error occurs, there is no output\&. For example:
.nf
18> io:fwrite("~s ~w ~i ~w ~c ~n",[\&'abc def\&', \&'abc def\&', {foo, 1},{foo, 1}, 65])\&.
abc def \&'abc def\&' {foo,1} A
ok
19> io:fwrite("~s", [65])\&.
** exception exit: {badarg,[{io,format,[<0\&.22\&.0>,"~s","A"]},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_exprs,6},
{shell,eval_loop,3}]}
in function io:o_request/2
.fi
.LP
In this example, an attempt was made to output the single character \&'65\&' with the aid of the string formatting directive "~s"\&.
.RE
.LP
.B
fread([IoDevice,] Prompt, Format) -> Result
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
Format = string()
.br
Result = {ok, Terms} | eof | {error, What}
.br
Terms = [term()]
.br
What = term()
.br
.RE
.RS
.LP
Reads characters from the standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. Interprets the characters in accordance with \fIFormat\fR\&. \fIFormat\fR contains control sequences which directs the interpretation of the input\&.
.LP
\fIFormat\fR may contain:
.RS 2
.TP 2
*
White space characters (SPACE, TAB and NEWLINE) which cause input to be read to the next non-white space character\&.
.TP 2
*
Ordinary characters which must match the next input character\&.
.TP 2
*
Control sequences, which have the general format \fI~*FC\fR\&. The character \fI*\fR is an optional return suppression character\&. It provides a method to specify a field which is to be omitted\&. \fIF\fR is the \fIfield width\fR of the input field and \fIC\fR determines the type of control sequence\&.
.RS 2
.LP
.LP
Unless otherwise specified, leading white-space is ignored for all control sequences\&. An input field cannot be more than one line wide\&. The following control sequences are available:
.LP
.RS 2
.TP 4
.B
\fI~\fR:
A single \fI~\fR is expected in the input\&.
.TP 4
.B
\fId\fR:
A decimal integer is expected\&.
.TP 4
.B
\fIu\fR:
An unsigned integer in base 2\&.\&.36 is expected\&. The field width parameter is used to specify base\&. Leading white-space characters are not skipped\&.
.TP 4
.B
\fI-\fR:
An optional sign character is expected\&. A sign character \&'-\&' gives the return value \fI-1\fR\&. Sign character \&'+\&' or none gives \fI1\fR\&. The field width parameter is ignored\&. Leading white-space characters are not skipped\&.
.TP 4
.B
\fI#\fR:
An integer in base 2\&.\&.36 with Erlang-style base prefix (for example \fI"16#ffff"\fR) is expected\&.
.TP 4
.B
\fIf\fR:
A floating point number is expected\&. It must follow the Erlang floating point number syntax\&.
.TP 4
.B
\fIs\fR:
A string of non-white-space characters is read\&. If a field width has been specified, this number of characters are read and all trailing white-space characters are stripped\&. An Erlang string (list of characters) is returned\&.
.TP 4
.B
\fIa\fR:
Similar to \fIs\fR, but the resulting string is converted into an atom\&.
.TP 4
.B
\fIc\fR:
The number of characters equal to the field width are read (default is 1) and returned as an Erlang string\&. However, leading and trailing white-space characters are not omitted as they are with \fIs\fR\&. All characters are returned\&.
.TP 4
.B
\fIl\fR:
Returns the number of characters which have been scanned up to that point, including white-space characters\&.
.RE
.LP
.LP
It returns:
.LP
.RS 2
.TP 4
.B
\fI{ok, Terms}\fR:
The read was successful and \fITerms\fR is the list of successfully matched and read items\&.
.TP 4
.B
\fIeof\fR:
End of file was encountered\&.
.TP 4
.B
\fI{error, What}\fR:
The read operation failed and the parameter \fIWhat\fR gives a hint about the error\&.
.RE
.RE
.RE
.LP
Examples:
.nf
20> io:fread(\&'enter>\&', "~f~f~f")\&.
enter>1\&.9 35\&.5e3 15\&.0
{ok,[1\&.9,3\&.55e4,15\&.0]}
21> io:fread(\&'enter>\&', "~10f~d")\&.
enter> 5\&.67899
{ok,[5\&.678,99]}
22> io:fread(\&'enter>\&', ":~10s:~10c:")\&.
enter>:
alan
:
joe
:
{ok, ["alan", " joe "]}
.fi
.RE
.LP
.B
rows([IoDevice]) -> {ok,int()} | {error, enotsup}
.br
.RS
.TP
Types
IoDevice = io_device()
.br
.RE
.RS
.LP
Retrieves the number of rows of the \fIIoDevice\fR (i\&.e\&. the height of a terminal)\&. The function only succeeds for terminal devices, for all other devices the function returns \fI{error, enotsup}\fR
.RE
.LP
.B
scan_erl_exprs(Prompt) ->
.br
.B
scan_erl_exprs([IoDevice,] Prompt, StartLine) -> Result
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
StartLine = int()
.br
Result = {ok, Tokens, EndLine} | {eof, EndLine} | {error, ErrorInfo, EndLine}
.br
Tokens -- see erl_scan(3)
.br
EndLine = int()
.br
ErrorInfo -- see section Error Information below
.br
.RE
.RS
.LP
Reads data from the standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. Reading starts at line number \fIStartLine\fR (1)\&. The data is tokenized as if it were a sequence of Erlang expressions until a final \fI\&'\&.\&'\fR is reached\&. This token is also returned\&. It returns:
.RS 2
.TP 4
.B
\fI{ok, Tokens, EndLine}\fR:
The tokenization succeeded\&.
.TP 4
.B
\fI{eof, EndLine}\fR:
End of file was encountered\&.
.TP 4
.B
\fI{error, ErrorInfo, EndLine}\fR:
An error occurred\&.
.RE
.LP
Example:
.nf
23> io:scan_erl_exprs(\&'enter>\&')\&.
enter>abc(), "hey"\&.
{ok,[{atom,1,abc},{\&'(\&',1},{\&')\&',1},{\&',\&',1},{string,1,"hey"},{dot,1}],2}
24> io:scan_erl_exprs(\&'enter>\&')\&.
enter>1\&.0er\&.
{error,{1,erl_scan,{illegal,float}},2}
.fi
.RE
.LP
.B
scan_erl_form(Prompt) ->
.br
.B
scan_erl_form([IoDevice,] Prompt, StartLine) -> Result
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
StartLine = int()
.br
Result = {ok, Tokens, EndLine} | {eof, EndLine} | {error, ErrorInfo, EndLine}
.br
Tokens -- see erl_scan(3)
.br
EndLine = int()
.br
ErrorInfo -- see section Error Information below
.br
.RE
.RS
.LP
Reads data from the standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. Starts reading at line number \fIStartLine\fR (1)\&. The data is tokenized as if it were an Erlang form - one of the valid Erlang expressions in an Erlang source file - until a final \fI\&'\&.\&'\fR is reached\&. This last token is also returned\&. The return values are the same as for \fIscan_erl_exprs/1, 2, 3\fR above\&.
.RE
.LP
.B
parse_erl_exprs(Prompt) ->
.br
.B
parse_erl_exprs([IoDevice,] Prompt, StartLine) -> Result
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
StartLine = int()
.br
Result = {ok, Expr_list, EndLine} | {eof, EndLine} | {error, ErrorInfo, EndLine}
.br
Expr_list -- see erl_parse(3)
.br
EndLine = int()
.br
ErrorInfo -- see section Error Information below
.br
.RE
.RS
.LP
Reads data from the standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. Starts reading at line number \fIStartLine\fR (1)\&. The data is tokenized and parsed as if it were a sequence of Erlang expressions until a final \&'\&.\&' is reached\&. It returns:
.RS 2
.TP 4
.B
\fI{ok, Expr_list, EndLine}\fR:
The parsing was successful\&.
.TP 4
.B
\fI{eof, EndLine}\fR:
End of file was encountered\&.
.TP 4
.B
\fI{error, ErrorInfo, EndLine}\fR:
An error occurred\&.
.RE
.LP
Example:
.nf
25> io:parse_erl_exprs(\&'enter>\&')\&.
enter>abc(), "hey"\&.
{ok, [{call,1,{atom,1,abc},[]},{string,1,"hey"}],2}
26> io:parse_erl_exprs (\&'enter>\&')\&.
enter>abc("hey"\&.
{error,{1,erl_parse,["syntax error before: ",["\&'\&.\&'"]]},2}
.fi
.RE
.LP
.B
parse_erl_form(Prompt) ->
.br
.B
parse_erl_form([IoDevice,] Prompt, StartLine) -> Result
.br
.RS
.TP
Types
IoDevice = io_device()
.br
Prompt = atom() | string()
.br
StartLine = int()
.br
Result = {ok, AbsForm, EndLine} | {eof, EndLine} | {error, ErrorInfo, EndLine}
.br
AbsForm -- see erl_parse(3)
.br
EndLine = int()
.br
ErrorInfo -- see section Error Information below
.br
.RE
.RS
.LP
Reads data from the standard input (\fIIoDevice\fR), prompting it with \fIPrompt\fR\&. Starts reading at line number \fIStartLine\fR (1)\&. The data is tokenized and parsed as if it were an Erlang form - one of the valid Erlang expressions in an Erlang source file - until a final \&'\&.\&' is reached\&. It returns:
.RS 2
.TP 4
.B
\fI{ok, AbsForm, EndLine}\fR:
The parsing was successful\&.
.TP 4
.B
\fI{eof, EndLine}\fR:
End of file was encountered\&.
.TP 4
.B
\fI{error, ErrorInfo, EndLine}\fR:
An error occurred\&.
.RE
.RE
.SH STANDARD INPUT/OUTPUT
.LP
All Erlang processes have a default standard IO device\&. This device is used when no \fIIoDevice\fR argument is specified in the above function calls\&. However, it is sometimes desirable to use an explicit \fIIoDevice\fR argument which refers to the default IO device\&. This is the case with functions that can access either a file or the default IO device\&. The atom \fIstandard_io\fR has this special meaning\&. The following example illustrates this:
.nf
27> io:read(\&'enter>\&')\&.
enter>foo\&.
{ok,foo}
28> io:read(standard_io, \&'enter>\&')\&.
enter>bar\&.
{ok,bar}
.fi
.LP
There is always a process registered under the name of \fIuser\fR\&. This can be used for sending output to the user\&.
.SH ERROR INFORMATION
.LP
The \fIErrorInfo\fR mentioned above is the standard \fIErrorInfo\fR structure which is returned from all IO modules\&. It has the format:
.nf
{ErrorLine, Module, ErrorDescriptor}
.fi
.LP
A string which describes the error is obtained with the following call:
.nf
apply(Module, format_error, ErrorDescriptor)
.fi
|