From 63dedc7de4877eb4d7fba2716a2eeedb31efa794 Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 29 Jun 2004 01:17:39 +0000 Subject: * io.c (rb_io_popen): update the document for the first argument and exceptions. * process.c (rb_f_exec, rb_f_system): update the document for exceptions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6540 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 426 ++++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 217 insertions(+), 209 deletions(-) (limited to 'io.c') diff --git a/io.c b/io.c index f71ef8f0b6..14443da712 100644 --- a/io.c +++ b/io.c @@ -431,17 +431,17 @@ rb_io_fwrite(ptr, len, f) /* * call-seq: * ios.write(string) => integer - * + * * Writes the given string to ios. The stream must be opened * for writing. If the argument is not a string, it will be converted * to a string using to_s. Returns the number of bytes * written. - * + * * count = $stdout.write( "This is a test\n" ) * puts "That was #{count} bytes of data" - * + * * produces: - * + * * This is a test * That was 15 bytes of data */ @@ -491,15 +491,15 @@ rb_io_write(io, str) /* * call-seq: * ios << obj => ios - * + * * String Output---Writes obj to ios. * obj will be converted to a string using * to_s. - * + * * $stdout << "Hello " << "world!\n" - * + * * produces: - * + * * Hello world! */ @@ -515,16 +515,16 @@ rb_io_addstr(io, str) /* * call-seq: * ios.flush => ios - * + * * Flushes any buffered data within ios to the underlying * operating system (note that this is Ruby internal buffering only; * the OS may buffer the data as well). - * + * * $stdout.print "no newline" * $stdout.flush - * + * * produces: - * + * * no newline */ @@ -549,9 +549,9 @@ rb_io_flush(io) * call-seq: * ios.pos => integer * ios.tell => integer - * + * * Returns the current offset (in bytes) of ios. - * + * * f = File.new("testfile") * f.pos #=> 0 * f.gets #=> "This is line one\n" @@ -590,19 +590,19 @@ rb_io_seek(io, offset, whence) /* * call-seq: * ios.seek(amount, whence=SEEK_SET) -> 0 - * + * * Seeks to a given offset anInteger in the stream according to * the value of whence: * * IO::SEEK_CUR | Seeks to _amount_ plus current position * --------------+---------------------------------------------------- - * IO::SEEK_END | Seeks to _amount_ plus end of stream (you probably + * IO::SEEK_END | Seeks to _amount_ plus end of stream (you probably * | want a negative value for _amount_) * --------------+---------------------------------------------------- * IO::SEEK_SET | Seeks to the absolute location given by _amount_ * * Example: - * + * * f = File.new("testfile") * f.seek(-13, IO::SEEK_END) #=> 0 * f.readline #=> "And so on...\n" @@ -627,9 +627,9 @@ rb_io_seek_m(argc, argv, io) /* * call-seq: * ios.pos = integer => 0 - * + * * Seeks to the given position (in bytes) in ios. - * + * * f = File.new("testfile") * f.pos = 17 * f.gets #=> "This is line two\n" @@ -653,10 +653,10 @@ rb_io_set_pos(io, offset) /* * call-seq: * ios.rewind => 0 - * + * * Positions ios to the beginning of input, resetting * lineno to zero. - * + * * f = File.new("testfile") * f.readline #=> "This is line one\n" * f.rewind #=> 0 @@ -685,10 +685,10 @@ rb_io_rewind(io) * call-seq: * ios.eof => true or false * ios.eof? => true or false - * + * * Returns true if ios is at end of file. The stream must be * opened for reading or an IOError will be raised. - * + * * f = File.new("testfile") * dummy = f.readlines * f.eof #=> true @@ -722,12 +722,12 @@ rb_io_eof(io) /* * call-seq: * ios.sync => true or false - * + * * Returns the current ``sync mode'' of ios. When sync mode is * true, all output is immediately flushed to the underlying operating * system and is not buffered by Ruby internally. See also * IO#fsync. - * + * * f = File.new("testfile") * f.sync #=> false */ @@ -745,15 +745,15 @@ rb_io_sync(io) /* * call-seq: * ios.sync = boolean => boolean - * + * * Sets the ``sync mode'' to true or false. * When sync mode is true, all output is immediately flushed to the * underlying operating system and is not buffered internally. Returns * the new state. See also IO#fsync. - * + * * f = File.new("testfile") * f.sync = true - * + * * (produces no output) */ @@ -776,7 +776,7 @@ rb_io_set_sync(io, mode) /* * call-seq: * ios.fsync => 0 or nil - * + * * Immediately writes all buffered data in ios to disk. * Returns nil if the underlying operating system does not * support fsync(2). Note that fsync differs from @@ -810,10 +810,10 @@ rb_io_fsync(io) * call-seq: * ios.fileno => fixnum * ios.to_i => fixnum - * + * * Returns an integer representing the numeric file descriptor for * ios. - * + * * $stdin.fileno #=> 0 * $stdout.fileno #=> 1 */ @@ -834,19 +834,19 @@ rb_io_fileno(io) /* * call-seq: * ios.pid => fixnum - * + * * Returns the process ID of a child process associated with * ios. This will be set by IO::popen. - * + * * pipe = IO.popen("-") * if pipe * $stderr.puts "In parent, child pid is #{pipe.pid}" * else * $stderr.puts "In child, pid is #{$$}" * end - * + * * produces: - * + * * In child, pid is 26209 * In parent, child pid is 26209 */ @@ -895,7 +895,7 @@ rb_io_inspect(obj) /* * call-seq: * ios.to_io -> ios - * + * * Returns ios. */ @@ -1043,13 +1043,13 @@ read_all(fptr, siz, str) /* * call-seq: * ios.read([integer [, buffer]]) => string, buffer, or nil - * + * * Reads at most integer bytes from the I/O stream, or to the * end of file if integer is omitted or is nil. * If the optional buffer argument is present, it must reference * a String, which will receive the data. Returns nil * if called at end of file. - * + * * f = File.new("testfile") * f.read(16) #=> "This is line one" */ @@ -1335,7 +1335,7 @@ rb_io_gets(io) /* * call-seq: * ios.gets(sep_string=$/) => string or nil - * + * * Reads the next ``line'' from the I/O stream; lines are separated by * sep_string. A separator of nil reads the entire * contents, and a zero-length separator reads the input a paragraph at @@ -1344,7 +1344,7 @@ rb_io_gets(io) * will be raised. The line read in will be returned and also assigned * to $_. Returns nil if called at end of * file. - * + * * File.new("testfile").gets #=> "This is line one\n" * $_ #=> "This is line one\n" */ @@ -1374,14 +1374,14 @@ rb_io_gets_m(argc, argv, io) /* * call-seq: * ios.lineno => integer - * + * * Returns the current line number in ios. The stream must be * opened for reading. lineno counts the number of times * gets is called, rather than the number of newlines * encountered. The two values will differ if gets is * called with a separator other than newline. See also the * $. variable. - * + * * f = File.new("testfile") * f.lineno #=> 0 * f.gets #=> "This is line one\n" @@ -1404,10 +1404,10 @@ rb_io_lineno(io) /* * call-seq: * ios.lineno = integer => integer - * + * * Manually sets the current line number to the given value. * $. is updated only on the next read. - * + * * f = File.new("testfile") * f.gets #=> "This is line one\n" * $. #=> 1 @@ -1458,7 +1458,7 @@ argf_lineno() /* * call-seq: * ios.readline(sep_string=$/) => string - * + * * Reads a line as with IO#gets, but raises an * EOFError on end of file. */ @@ -1480,14 +1480,14 @@ rb_io_readline(argc, argv, io) /* * call-seq: * ios.readlines(sep_string=$/) => array - * + * * Reads all of the lines in ios, and returns them in * anArray. Lines are separated by the optional * sep_string. If set_string is nil, the * rest of the stream is returned as a single record. * The stream must be opened for reading or an * IOError will be raised. - * + * * f = File.new("testfile") * f.readlines[0] #=> "This is line one\n" */ @@ -1520,16 +1520,16 @@ rb_io_readlines(argc, argv, io) * call-seq: * ios.each(sep_string=$/) {|line| block } => ios * ios.each_line(sep_string=$/) {|line| block } => ios - * + * * Executes the block for every line in ios, where lines are * separated by sep_string. ios must be opened for * reading or an IOError will be raised. - * + * * f = File.new("testfile") * f.each {|line| puts "#{f.lineno}: #{line}" } - * + * * produces: - * + * * 1: This is line one * 2: This is line two * 3: This is line three @@ -1562,11 +1562,11 @@ rb_io_each_line(argc, argv, io) /* * call-seq: * ios.each_byte {|byte| block } => ios - * + * * Calls the given block once for each byte (0..255) in ios, * passing the byte as an argument. The stream must be opened for * reading or an IOError will be raised. - * + * * f = File.new("testfile") * checksum = 0 * f.each_byte {|x| checksum ^= x } #=> # @@ -1608,10 +1608,10 @@ rb_io_each_byte(io) /* * call-seq: * ios.getc => fixnum or nil - * + * * Gets the next 8-bit byte (0..255) from ios. Returns * nil if called at end of file. - * + * * f = File.new("testfile") * f.getc #=> 84 * f.getc #=> 104 @@ -1666,7 +1666,7 @@ rb_getc(f) /* * call-seq: * ios.readchar => fixnum - * + * * Reads a character as with IO#getc, but raises an * EOFError on end of file. */ @@ -1686,13 +1686,13 @@ rb_io_readchar(io) /* * call-seq: * ios.ungetc(integer) => nil - * + * * Pushes back one character (passed as a parameter) onto ios, * such that a subsequent buffered read will return it. Only one character * may be pushed back before a subsequent read operation (that is, * you will be able to read only the last of several characters that have been pushed * back). Has no effect with unbuffered reads (such as IO#sysread). - * + * * f = File.new("testfile") #=> # * c = f.getc #=> 84 * f.ungetc(c) #=> nil @@ -1721,10 +1721,10 @@ rb_io_ungetc(io, c) * call-seq: * ios.isatty => true or false * ios.tty? => true or false - * + * * Returns true if ios is associated with a * terminal device (tty), false otherwise. - * + * * File.new("testfile").isatty #=> false * File.new("/dev/tty").isatty #=> true */ @@ -1842,7 +1842,7 @@ rb_io_close(io) /* * call-seq: * ios.close => nil - * + * * Closes ios and flushes any pending writes to the operating * system. The stream is unavailable for any further data operations; * an IOError is raised if such an attempt is made. I/O @@ -1872,11 +1872,11 @@ io_close(io) /* * call-seq: * ios.closed? => true or false - * + * * Returns true if ios is completely closed (for * duplex streams, both reader and writer), false * otherwise. - * + * * f = File.new("testfile") * f.close #=> nil * f.closed? #=> true @@ -1901,17 +1901,17 @@ rb_io_closed(io) /* * call-seq: * ios.close_read => nil - * + * * Closes the read end of a duplex I/O stream (i.e., one that contains * both a read and a write stream, such as a pipe). Will raise an * IOError if the stream is not duplexed. - * + * * f = IO.popen("/bin/sh","r+") * f.close_read * f.readlines - * + * * produces: - * + * * prog.rb:3:in `readlines': not opened for reading (IOError) * from prog.rb:3 */ @@ -1945,17 +1945,17 @@ rb_io_close_read(io) /* * call-seq: * ios.close_write => nil - * + * * Closes the write end of a duplex I/O stream (i.e., one that contains * both a read and a write stream, such as a pipe). Will raise an * IOError if the stream is not duplexed. - * + * * f = IO.popen("/bin/sh","r+") * f.close_write * f.print "nowhere" - * + * * produces: - * + * * prog.rb:3:in `write': not opened for writing (IOError) * from prog.rb:3:in `print' * from prog.rb:3 @@ -1989,11 +1989,11 @@ rb_io_close_write(io) /* * call-seq: * ios.sysseek(offset, whence=SEEK_SET) => integer - * + * * Seeks to a given offset in the stream according to the value * of whence (see IO#seek for values of * whence). Returns the new offset into the file. - * + * * f = File.new("testfile") * f.sysseek(-13, IO::SEEK_END) #=> 53 * f.sysread(10) #=> "And so on." @@ -2031,12 +2031,12 @@ rb_io_sysseek(argc, argv, io) /* * call-seq: * ios.syswrite(string ) => integer - * + * * Writes the given string to ios using a low-level write. * Returns the number of bytes written. Do not mix with other methods * that write to ios or you may get unpredictable results. * Raises SystemCallError on error. - * + * * f = File.new("out", "w") * f.syswrite("ABCDEF") #=> 6 */ @@ -2073,13 +2073,13 @@ rb_io_syswrite(io, str) /* * call-seq: * ios.sysread(integer ) => string - * + * * Reads integer bytes from ios using a low-level * read and returns them as a string. Do not mix with other methods * that read from ios or you may get unpredictable results. * Raises SystemCallError on error and * EOFError at end of file. - * + * * f = File.new("testfile") * f.sysread(16) #=> "This is line one" */ @@ -2137,7 +2137,7 @@ rb_io_sysread(argc, argv, io) /* * call-seq: * ios.binmode => ios - * + * * Puts ios into binary mode. This is useful only in * MS-DOS/Windows environments. Once a stream is in binary mode, it * cannot be reset to nonbinary mode. @@ -2798,43 +2798,51 @@ rb_io_popen(str, argc, argv, klass) /* * call-seq: - * IO.popen(cmd_string, mode="r" ) => io - * IO.popen(cmd_string, mode="r" ) {|io| block } => obj - * - * Runs the specified command string as a subprocess; the subprocess's + * IO.popen(cmd, mode="r") => io + * IO.popen(cmd, mode="r") {|io| block } => obj + * + * Runs the specified command as a subprocess; the subprocess's * standard input and output will be connected to the returned - * IO object. If cmd_string starts with a + * IO object. If _cmd_ is a +String+ * ``-'', then a new instance of Ruby is started as the - * subprocess. The default mode for the new file object is ``r'', but - * mode may be set to any of the modes listed in the description - * for class IO. - * + * subprocess. If cmd is an +Array+ of +String+, then it will + * be used as the subprocess's +argv+ bypassing a shell. The default + * mode for the new file object is ``r'', but mode may be set + * to any of the modes listed in the description for class IO. + * + * Raises exceptions which IO::pipe and + * Kernel::system raise. + * * If a block is given, Ruby will run the command as a child connected * to Ruby with a pipe. Ruby's end of the pipe will be passed as a * parameter to the block. In this case IO::popen returns * the value of the block. - * - * If a block is given with a cmd_string of ``-'', + * + * If a block is given with a _cmd_ of ``-'', * the block will be run in two separate processes: once in the parent, * and once in a child. The parent process will be passed the pipe * object as a parameter to the block, the child version of the block * will be passed nil, and the child's standard in and * standard out will be connected to the parent through the pipe. Not * available on all platforms. - * + * * f = IO.popen("uname") * p f.readlines * puts "Parent is #{Process.pid}" - * IO.popen ("date") { |f| puts f.gets } + * IO.popen("date") { |f| puts f.gets } * IO.popen("-") {|f| $stderr.puts "#{Process.pid} is here, f is #{f}"} - * + * IO.popen(%w"sed -e s|^|| -e s&$&;zot;&", "r+") {|f| + * f.puts "bar"; f.close_write; puts f.gets + * } + * * produces: - * + * * ["Linux\n"] * Parent is 26166 * Wed Apr 9 08:53:52 CDT 2003 * 26169 is here, f is * 26166 is here, f is # + * bar;zot; */ static VALUE @@ -2922,13 +2930,13 @@ rb_open_file(argc, argv, io) * call-seq: * IO.open(fd, mode_string="r" ) => io * IO.open(fd, mode_string="r" ) {|io| block } => obj - * + * * With no associated block, open is a synonym for * IO::new. If the optional code block is given, it will * be passed io as an argument, and the IO object will * automatically be closed when the block terminates. In this instance, * IO::open returns the value of the block. - * + * */ static VALUE @@ -2949,12 +2957,12 @@ rb_io_s_open(argc, argv, klass) /* * call-seq: * IO.sysopen(path, [mode, [perm]]) => fixnum - * + * * Opens the given path, returning the underlying file descriptor as a * Fixnum. - * + * * IO.sysopen("testfile") #=> 3 - * + * */ static VALUE @@ -2985,21 +2993,21 @@ rb_io_s_sysopen(argc, argv) * call-seq: * open(path [, mode [, perm]] ) => io or nil * open(path [, mode [. perm]] ) {|io| block } => nil - * + * * Creates an IO object connected to the given stream, * file, or subprocess. - * + * * If path does not start with a pipe character * (``|''), treat it as the name of a file to open using * the specified mode (defaulting to ``r''). (See the table * of valid modes on page 331.) If a file is being created, its initial * permissions may be set using the integer third parameter. - * + * * If a block is specified, it will be invoked with the * File object as a parameter, and the file will be * automatically closed when the block terminates. The call always * returns nil in this case. - * + * * If path starts with a pipe character, a subprocess is * created, connected to the caller by a pair of pipes. The returned * IO object may be used to write to the standard input @@ -3015,27 +3023,27 @@ rb_io_s_sysopen(argc, argv) * will be connected to the child's $stdin and * $stdout. The subprocess will be terminated at the end * of the block. - * + * * open("testfile") do |f| * print f.gets * end - * + * * produces: - * + * * This is line one - * + * * Open a subprocess and read its output: - * + * * cmd = open("|date") * print cmd.gets * cmd.close - * + * * produces: - * + * * Wed Apr 9 08:56:31 CDT 2003 - * + * * Open a subprocess running the same Ruby program: - * + * * f = open("|-", "w+") * if f == nil * puts "in Child" @@ -3043,13 +3051,13 @@ rb_io_s_sysopen(argc, argv) * else * puts "Got: #{f.gets}" * end - * + * * produces: - * + * * Got: in Child - * + * * Open a subprocess using a block to receive the I/O object: - * + * * open("|-") do |f| * if f == nil * puts "in Child" @@ -3057,9 +3065,9 @@ rb_io_s_sysopen(argc, argv) * puts "Got: #{f.gets}" * end * end - * + * * produces: - * + * * Got: in Child */ @@ -3210,13 +3218,13 @@ io_reopen(io, nfile) /* * call-seq: - * ios.reopen(other_IO) => ios + * ios.reopen(other_IO) => ios * ios.reopen(path, mode_str) => ios - * + * * Reassociates ios with the I/O stream given in * other_IO or to a new stream opened on path. This may * dynamically change the actual class of this stream. - * + * * f1 = File.new("testfile") * f2 = File.new("testfile") * f2.readlines[0] #=> "This is line one\n" @@ -3354,7 +3362,7 @@ rb_io_init_copy(dest, io) /* * call-seq: * ios.printf(format_string [, obj, ...] ) => nil - * + * * Formats and writes to ios, converting parameters under * control of the format string. See Kernel#sprintf * for details. @@ -3374,7 +3382,7 @@ rb_io_printf(argc, argv, out) * call-seq: * printf(io, string [, obj ... ] ) => nil * printf(string [, obj ... ] ) => nil - * + * * Equivalent to: * io.write(sprintf(string, obj, ...) * or @@ -3406,7 +3414,7 @@ rb_f_printf(argc, argv) * call-seq: * ios.print() => nil * ios.print(obj, ...) => nil - * + * * Writes the given object(s) to ios. The stream must be * opened for writing. If the output record separator ($\) * is not nil, it will be appended to the output. If no @@ -3414,11 +3422,11 @@ rb_f_printf(argc, argv) * strings will be converted by calling their to_s method. * With no argument, prints the contents of the variable $_. * Returns nil. - * + * * $stdout.print("This is ", 100, " percent.\n") - * + * * produces: - * + * * This is 100 percent. */ @@ -3460,7 +3468,7 @@ rb_io_print(argc, argv, out) /* * call-seq: * print(obj, ...) => nil - * + * * Prints each object in turn to $stdout. If the output * field separator ($,) is not +nil+, its * contents will appear between each field. If the output record @@ -3468,14 +3476,14 @@ rb_io_print(argc, argv, out) * appended to the output. If no arguments are given, prints * $_. Objects that aren't strings will be converted by * calling their to_s method. - * + * * print "cat", [1,2,3], 99, "\n" * $, = ", " * $\ = "\n" * print "cat", [1,2,3], 99 - * + * * produces: - * + * * cat12399 * cat, 1, 2, 3, 99 */ @@ -3492,16 +3500,16 @@ rb_f_print(argc, argv) /* * call-seq: * ios.putc(obj) => obj - * + * * If obj is Numeric, write the character whose * code is obj, otherwise write the first character of the * string representation of obj to ios. - * + * * $stdout.putc "A" * $stdout.putc 65 - * + * * produces: - * + * * AA */ @@ -3518,7 +3526,7 @@ rb_io_putc(io, ch) /* * call-seq: * putc(int) => int - * + * * Equivalent to: * * $stdout.putc(int) @@ -3551,17 +3559,17 @@ io_puts_ary(ary, out) /* * call-seq: * ios.puts(obj, ...) => nil - * + * * Writes the given objects to ios as with * IO#print. Writes a record separator (typically a * newline) after any that do not already end with a newline sequence. * If called with an array argument, writes each element on a new line. * If called without arguments, outputs a single record separator. - * + * * $stdout.puts("this", "is", "a", "test") - * + * * produces: - * + * * this * is * a @@ -3607,8 +3615,8 @@ rb_io_puts(argc, argv, out) /* * call-seq: * puts(obj, ...) => nil - * - * Equivalent to + * + * Equivalent to * * $stdout.puts(obj, ...) */ @@ -3633,18 +3641,18 @@ rb_p(obj) /* for debug print within C code */ /* * call-seq: * p(obj, ...) => nil - * + * * For each object, directly writes * _obj_.+inspect+ followed by the current output * record separator to the program's standard output. +p+ * bypasses the Ruby I/O libraries. - * + * * S = Struct.new(:name, :state) * s = S['dave', 'TX'] * p s - * + * * produces: - * + * * # */ @@ -3667,23 +3675,23 @@ rb_f_p(argc, argv) /* * call-seq: * obj.display(port=$>) => nil - * + * * Prints obj on the given port (default $>). * Equivalent to: - * + * * def display(port=$>) * port.write self * end - * + * * For example: - * + * * 1.display * "cat".display * [ 4, 5, 6 ].display * puts - * + * * produces: - * + * * 1cat456 */ @@ -3799,7 +3807,7 @@ prep_path(io, path) /* * call-seq: * IO.new(fd, mode) => io - * + * * Returns a new IO object (a stream) for the given * IO object or integer file descriptor and mode * string. See also IO#fileno and @@ -3810,9 +3818,9 @@ prep_path(io, path) * a = IO.new(2,"w") # '2' is standard error * $stderr.puts "Hello" * a.puts "World" - * + * * produces: - * + * * Hello * World */ @@ -3893,7 +3901,7 @@ rb_io_initialize(argc, argv, io) * call-seq: * File.new(filename, mode="r") => file * File.new(filename [, mode [, perm]]) => file - * + * * Opens the file named by _filename_ according to * _mode_ (default is ``r'') and returns a new @@ -3937,17 +3945,17 @@ rb_file_initialize(argc, argv, io) /* * call-seq: * IO.new(fd, mode_string) => io - * + * * Returns a new IO object (a stream) for the given * integer file descriptor and mode string. See also * IO#fileno and IO::for_fd. - * + * * a = IO.new(2,"w") # '2' is standard error * $stderr.puts "Hello" * a.puts "World" - * + * * produces: - * + * * Hello * World */ @@ -3971,9 +3979,9 @@ rb_io_s_new(argc, argv, klass) /* * call-seq: * IO.for_fd(fd, mode) => io - * + * * Synonym for IO::new. - * + * */ static VALUE @@ -4172,7 +4180,7 @@ argf_getline(argc, argv) /* * call-seq: * gets(separator=$/) => string or nil - * + * * Returns (and assigns to $_) the next line from the list * of files in +ARGV+ (or $*), or from standard * input if no files are present on the command line. Returns @@ -4183,17 +4191,17 @@ argf_getline(argc, argv) * at a time, where paragraphs are divided by two consecutive newlines. * If multiple filenames are present in +ARGV+, * +gets(nil)+ will read the contents one file at a time. - * + * * ARGV << "testfile" * print while gets - * + * * produces: - * + * * This is line one * This is line two * This is line three * And so on... - * + * * The style of programming using $_ as an implicit * parameter is gradually losing favor in the Ruby community. */ @@ -4245,7 +4253,7 @@ rb_gets() /* * call-seq: * readline(separator=$/ => string - * + * * Equivalent to Kernel::gets, except * +readline+ raises +EOFError+ at end of file. */ @@ -4283,7 +4291,7 @@ rb_f_getc() /* * call-seq: * readlines(separator=$/) => array - * + * * Returns an array containing the lines returned by calling * Kernel.gets(aString) until the end of file. */ @@ -4307,11 +4315,11 @@ rb_f_readlines(argc, argv) /* * call-seq: * `cmd` => string - * + * * Returns the standard output of running _cmd_ in a subshell. * The built-in syntax %x{...} uses * this method. Sets $? to the process status. - * + * * `date` #=> "Wed Apr 9 08:56:30 CDT 2003\n" * `ls testdir`.split[1] #=> "main.rb" * `echo oops && exit 99` #=> "oops\n" @@ -4342,11 +4350,11 @@ rb_f_backquote(obj, str) /* * call-seq: - * IO.select(read_array - * [, write_array - * [, error_array + * IO.select(read_array + * [, write_array + * [, error_array * [, timeout]]] ) => array or nil - * + * * See Kernel#select. */ @@ -4591,7 +4599,7 @@ rb_io_ctl(io, req, arg, io_p) /* * call-seq: * ios.ioctl(integer_cmd, arg) => integer - * + * * Provides a mechanism for issuing low-level commands to control or * query I/O devices. Arguments and results are platform dependent. If * arg is a number, its value is passed directly. If it is a @@ -4615,7 +4623,7 @@ rb_io_ioctl(argc, argv, io) /* * call-seq: * ios.fcntl(integer_cmd, arg) => integer - * + * * Provides a mechanism for issuing low-level commands to control or * query file-oriented I/O streams. Arguments and results are platform * dependent. If arg is a number, its value is passed @@ -4645,7 +4653,7 @@ rb_io_fcntl(argc, argv, io) /* * call-seq: * syscall(fixnum [, args...]) => integer - * + * * Calls the operating system function identified by _fixnum_, * passing in the arguments, which must be either +String+ * objects, or +Integer+ objects that ultimately fit within @@ -4653,11 +4661,11 @@ rb_io_fcntl(argc, argv, io) * on the Atari-ST). The function identified by _fixnum_ is system * dependent. On some Unix systems, the numbers may be obtained from a * header file called syscall.h. - * + * * syscall 4, 1, "hello\n", 6 # '4' is write(2) on our box - * + * * produces: - * + * * hello */ @@ -4773,21 +4781,21 @@ io_new_instance(args) /* * call-seq: * IO.pipe -> array - * + * * Creates a pair of pipe endpoints (connected to each other) and * returns them as a two-element array of IO objects: * [ read_file, write_file ]. Not * available on all platforms. - * + * * In the example below, the two processes close the ends of the pipe * that they are not using. This is not just a cosmetic nicety. The * read end of a pipe will not generate an end of file condition if * there are any writers with the pipe still open. In the case of the * parent process, the rd.read will never return if it * does not first issue a wr.close. - * + * * rd, wr = IO.pipe - * + * * if fork * wr.close * puts "Parent got: <#{rd.read}>" @@ -4799,9 +4807,9 @@ io_new_instance(args) * wr.write "Hi Dad" * wr.close * end - * + * * produces: - * + * * Sending message to parent * Parent got: */ @@ -4869,19 +4877,19 @@ io_s_foreach(arg) /* * call-seq: * IO.foreach(name, sep_string=$/) {|line| block } => nil - * + * * Executes the block for every line in the named I/O port, where lines * are separated by sep_string. - * + * * IO.foreach("testfile") {|x| print "GOT ", x } - * + * * produces: - * + * * GOT This is line one * GOT This is line two * GOT This is line three * GOT And so on... - */ + */ static VALUE rb_io_s_foreach(argc, argv) @@ -4915,14 +4923,14 @@ io_s_readlines(arg) /* * call-seq: * IO.readlines(name, sep_string=$/) => array - * + * * Reads the entire file specified by name as individual * lines, and returns those lines in an array. Lines are separated by * sep_string. - * + * * a = IO.readlines("testfile") * a[0] #=> "This is line one\n" - * + * */ static VALUE @@ -4952,11 +4960,11 @@ io_s_read(arg) /* * call-seq: * IO.read(rane, [length [, offset]] ) => string - * + * * Opens the file, optionally seeks to the given offset, then returns * length bytes (defaulting to the rest of the file). * read ensures the file is closed before returning. - * + * * IO.read("testfile") #=> "This is line one\nThis is line two\nThis is line three\nAnd so on...\n" * IO.read("testfile", 20) #=> "This is line one\nThi" * IO.read("testfile", 20, 10) #=> "ne one\nThis is line " @@ -5258,38 +5266,38 @@ opt_i_set(val) * Class IO is the basis for all input and output in Ruby. * An I/O stream may be duplexed (that is, bidirectional), and * so may use more than one native operating system stream. - * + * * Many of the examples in this section use class File, * the only standard subclass of IO. The two classes are * closely associated. - * + * * As used in this section, portname may take any of the * following forms. - * + * * * A plain string represents a filename suitable for the underlying * operating system. - * + * * * A string starting with ``|'' indicates a subprocess. * The remainder of the string following the ``|'' is * invoked as a process with appropriate input/output channels * connected to it. - * + * * * A string equal to ``|-'' will create another Ruby * instance as a subprocess. - * + * * Ruby will convert pathnames between different operating system * conventions if possible. For instance, on a Windows system the * filename ``/gumby/ruby/test.rb'' will be opened as * ``\gumby\ruby\test.rb''. When specifying a * Windows-style filename in a Ruby string, remember to escape the * backslashes: - * + * * "c:\\gumby\\ruby\\test.rb" - * + * * Our examples here will use the Unix-style forward slashes; * File::SEPARATOR can be used to get the * platform-specific separator character. - * + * * I/O ports may be opened in any one of several different modes, which * are shown in this section as mode. The mode may * either be a Fixnum or a String. If numeric, it should be @@ -5306,7 +5314,7 @@ opt_i_set(val) * -----+-------------------------------------------------------- * "r+" | Read-write, starts at beginning of file. * -----+-------------------------------------------------------- - * "w" | Write-only, truncates existing file + * "w" | Write-only, truncates existing file * | to zero length or creates a new file for writing. * -----+-------------------------------------------------------- * "w+" | Read-write, truncates existing file to zero length @@ -5316,10 +5324,10 @@ opt_i_set(val) * | otherwise creates a new file for writing. * -----+-------------------------------------------------------- * "a+" | Read-write, starts at end of file if file exists, - * | otherwise creates a new file for reading and + * | otherwise creates a new file for reading and * | writing. * -----+-------------------------------------------------------- - * "b" | (DOS/Windows only) Binary file mode (may appear with + * "b" | (DOS/Windows only) Binary file mode (may appear with * | any of the key letters listed above). * * @@ -5333,7 +5341,7 @@ opt_i_set(val) void Init_IO() { -#ifdef __CYGWIN__ +#ifdef __CYGWIN__ #include static struct __cygwin_perfile pf[] = { -- cgit v1.2.3