ruby-changes:7265
From: akr <ko1@a...>
Date: Sat, 23 Aug 2008 10:46:06 +0900 (JST)
Subject: [ruby-changes:7265] Ruby:r18784 (trunk): * io.c (check_pipe_command): extracted from rb_f_open and rb_io_open.
akr 2008-08-23 10:45:49 +0900 (Sat, 23 Aug 2008) New Revision: 18784 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=18784 Log: * io.c (check_pipe_command): extracted from rb_f_open and rb_io_open. (rb_f_open): use check_pipe_command. (rb_io_open): ditto. Modified files: trunk/ChangeLog trunk/io.c Index: ChangeLog =================================================================== --- ChangeLog (revision 18783) +++ ChangeLog (revision 18784) @@ -1,3 +1,9 @@ +Sat Aug 23 10:42:52 2008 Tanaka Akira <akr@f...> + + * io.c (check_pipe_command): extracted from rb_f_open and rb_io_open. + (rb_f_open): use check_pipe_command. + (rb_io_open): ditto. + Sat Aug 23 10:13:00 2008 Tanaka Akira <akr@f...> * io.c (read_all): fptr->enc2 is 0 if no conversion. Index: io.c =================================================================== --- io.c (revision 18783) +++ io.c (revision 18784) @@ -4673,6 +4673,22 @@ return INT2NUM(fd); } +static VALUE +check_pipe_command(VALUE filename_or_command) +{ + char *s = RSTRING_PTR(filename_or_command); + long l = RSTRING_LEN(filename_or_command); + char *e = s + l; + int chlen; + + if (rb_enc_ascget(s, e, &chlen, rb_enc_get(filename_or_command)) == '|') { + VALUE cmd = rb_str_new(s+chlen, l-chlen); + OBJ_INFECT(cmd, filename_or_command); + return cmd; + } + return Qnil; +} + /* * call-seq: * open(path [, mode_enc [, perm]] ) => io or nil @@ -4798,10 +4814,9 @@ redirect = Qtrue; } else { - char *str = StringValuePtr(tmp); - if (str && str[0] == '|') { - argv[0] = rb_str_new(str+1, RSTRING_LEN(tmp)-1); - OBJ_INFECT(argv[0], tmp); + VALUE cmd = check_pipe_command(tmp); + if (!NIL_P(cmd)) { + argv[0] = cmd; return rb_io_s_popen(argc, argv, rb_cIO); } } @@ -4821,13 +4836,12 @@ static VALUE rb_io_open(VALUE filename, VALUE mode, VALUE opt) { - char *fname = RSTRING_PTR(filename); + VALUE cmd; int modenum, flags; convconfig_t convconfig; rb_io_extract_modeenc(&mode, opt, &modenum, &flags, &convconfig); - if (fname[0] == '|') { - VALUE cmd = rb_str_new2(fname+1); + if (!NIL_P(cmd = check_pipe_command(filename))) { return pipe_open_s(cmd, rb_io_modenum_mode(modenum), flags, &convconfig); } else { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/