Convert all uses of std::io to std::ioivec
This commit is contained in:
parent
c0846525e8
commit
82b1e3f5cc
src
lib
test
bench
compiletest
run-pass
stdtest
@ -36,9 +36,9 @@ fn run_program(prog: str, args: vec[str]) -> int {
|
||||
type program =
|
||||
obj {
|
||||
fn get_id() -> int;
|
||||
fn input() -> io::writer;
|
||||
fn output() -> io::reader;
|
||||
fn err() -> io::reader;
|
||||
fn input() -> ioivec::writer;
|
||||
fn output() -> ioivec::reader;
|
||||
fn err() -> ioivec::reader;
|
||||
fn close_input();
|
||||
fn finish() -> int;
|
||||
fn destroy();
|
||||
@ -65,14 +65,17 @@ fn start_program(prog: str, args: vec[str]) -> @program_res {
|
||||
err_file: os::libc::FILE,
|
||||
mutable finished: bool) {
|
||||
fn get_id() -> int { ret pid; }
|
||||
fn input() -> io::writer {
|
||||
ret io::new_writer(io::fd_buf_writer(in_fd, option::none));
|
||||
fn input() -> ioivec::writer {
|
||||
ret ioivec::new_writer(
|
||||
ioivec::fd_buf_writer(in_fd, option::none));
|
||||
}
|
||||
fn output() -> io::reader {
|
||||
ret io::new_reader(io::FILE_buf_reader(out_file, option::none));
|
||||
fn output() -> ioivec::reader {
|
||||
ret ioivec::new_reader(
|
||||
ioivec::FILE_buf_reader(out_file, option::none));
|
||||
}
|
||||
fn err() -> io::reader {
|
||||
ret io::new_reader(io::FILE_buf_reader(err_file, option::none));
|
||||
fn err() -> ioivec::reader {
|
||||
ret ioivec::new_reader(
|
||||
ioivec::FILE_buf_reader(err_file, option::none));
|
||||
}
|
||||
fn close_input() {
|
||||
let invalid_fd = -1;
|
||||
@ -100,10 +103,10 @@ fn start_program(prog: str, args: vec[str]) -> @program_res {
|
||||
false));
|
||||
}
|
||||
|
||||
fn read_all(rd: &io::reader) -> str {
|
||||
fn read_all(rd: &ioivec::reader) -> str {
|
||||
let buf = "";
|
||||
while !rd.eof() {
|
||||
let bytes = ivec::from_vec(rd.read_bytes(4096u));
|
||||
let bytes = rd.read_bytes(4096u);
|
||||
buf += str::unsafe_from_bytes(bytes);
|
||||
}
|
||||
ret buf;
|
||||
|
@ -40,11 +40,11 @@ const color_bright_cyan: u8 = 14u8;
|
||||
|
||||
const color_bright_white: u8 = 15u8;
|
||||
|
||||
fn esc(writer: io::buf_writer) { writer.write([0x1bu8, '[' as u8]); }
|
||||
fn esc(writer: ioivec::buf_writer) { writer.write(~[0x1bu8, '[' as u8]); }
|
||||
|
||||
fn reset(writer: io::buf_writer) {
|
||||
fn reset(writer: ioivec::buf_writer) {
|
||||
esc(writer);
|
||||
writer.write(['0' as u8, 'm' as u8]);
|
||||
writer.write(~['0' as u8, 'm' as u8]);
|
||||
}
|
||||
|
||||
fn color_supported() -> bool {
|
||||
@ -55,18 +55,18 @@ fn color_supported() -> bool {
|
||||
};
|
||||
}
|
||||
|
||||
fn set_color(writer: io::buf_writer, first_char: u8, color: u8) {
|
||||
fn set_color(writer: ioivec::buf_writer, first_char: u8, color: u8) {
|
||||
assert (color < 16u8);
|
||||
esc(writer);
|
||||
if color >= 8u8 { writer.write(['1' as u8, ';' as u8]); color -= 8u8; }
|
||||
writer.write([first_char, ('0' as u8) + color, 'm' as u8]);
|
||||
if color >= 8u8 { writer.write(~['1' as u8, ';' as u8]); color -= 8u8; }
|
||||
writer.write(~[first_char, ('0' as u8) + color, 'm' as u8]);
|
||||
}
|
||||
|
||||
fn fg(writer: io::buf_writer, color: u8) {
|
||||
fn fg(writer: ioivec::buf_writer, color: u8) {
|
||||
ret set_color(writer, '3' as u8, color);
|
||||
}
|
||||
|
||||
fn bg(writer: io::buf_writer, color: u8) {
|
||||
fn bg(writer: ioivec::buf_writer, color: u8) {
|
||||
ret set_color(writer, '4' as u8, color);
|
||||
}
|
||||
// export fg;
|
||||
|
@ -106,7 +106,7 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
|
||||
to_task: &test_to_task) -> bool {
|
||||
|
||||
type test_state = @{
|
||||
out: io::writer,
|
||||
out: ioivec::writer,
|
||||
use_color: bool,
|
||||
mutable total: uint,
|
||||
mutable passed: uint,
|
||||
@ -148,7 +148,7 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
|
||||
}
|
||||
|
||||
let st = @{
|
||||
out: io::stdout(),
|
||||
out: ioivec::stdout(),
|
||||
use_color: use_color(),
|
||||
mutable total: 0u,
|
||||
mutable passed: 0u,
|
||||
@ -181,19 +181,19 @@ fn run_tests_console_(opts: &test_opts, tests: &[test_desc],
|
||||
|
||||
ret success;
|
||||
|
||||
fn write_ok(out: &io::writer, use_color: bool) {
|
||||
fn write_ok(out: &ioivec::writer, use_color: bool) {
|
||||
write_pretty(out, "ok", term::color_green, use_color);
|
||||
}
|
||||
|
||||
fn write_failed(out: &io::writer, use_color: bool) {
|
||||
fn write_failed(out: &ioivec::writer, use_color: bool) {
|
||||
write_pretty(out, "FAILED", term::color_red, use_color);
|
||||
}
|
||||
|
||||
fn write_ignored(out: &io::writer, use_color: bool) {
|
||||
fn write_ignored(out: &ioivec::writer, use_color: bool) {
|
||||
write_pretty(out, "ignored", term::color_yellow, use_color);
|
||||
}
|
||||
|
||||
fn write_pretty(out: &io::writer, word: &str, color: u8,
|
||||
fn write_pretty(out: &ioivec::writer, word: &str, color: u8,
|
||||
use_color: bool) {
|
||||
if use_color && term::color_supported() {
|
||||
term::fg(out.get_buf_writer(), color);
|
||||
|
@ -17,7 +17,7 @@ import std::uint;
|
||||
import std::time;
|
||||
import std::str;
|
||||
import std::int::range;
|
||||
import std::io;
|
||||
import std::ioivec;
|
||||
import std::getopts;
|
||||
import std::task;
|
||||
import std::u64;
|
||||
@ -94,7 +94,7 @@ fn main(argv: vec[str]) {
|
||||
|
||||
let num_trials = 10;
|
||||
|
||||
let out = io::stdout();
|
||||
let out = ioivec::stdout();
|
||||
|
||||
|
||||
for each n: int in range(1, max + 1) {
|
||||
|
@ -10,7 +10,6 @@
|
||||
|
||||
use std;
|
||||
|
||||
import std::io;
|
||||
import option = std::option::t;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
@ -18,6 +17,7 @@ import std::str;
|
||||
import std::vec;
|
||||
import std::map;
|
||||
import std::ivec;
|
||||
import std::ioivec;
|
||||
|
||||
import std::time;
|
||||
import std::u64;
|
||||
@ -27,7 +27,7 @@ import clone = std::task::clone_chan;
|
||||
|
||||
fn map(filename: str, emit: map_reduce::putter) {
|
||||
// log_err "mapping " + filename;
|
||||
let f = io::file_reader(filename);
|
||||
let f = ioivec::file_reader(filename);
|
||||
|
||||
|
||||
while true {
|
||||
@ -51,7 +51,7 @@ fn reduce(word: str, get: map_reduce::getter) {
|
||||
}
|
||||
}
|
||||
|
||||
// auto out = io::stdout();
|
||||
// auto out = ioivec::stdout();
|
||||
// out.write_line(#fmt("%s: %d", word, count));
|
||||
|
||||
// log_err "reduce " + word + " done.";
|
||||
@ -226,7 +226,7 @@ mod map_reduce {
|
||||
|
||||
fn main(argv: vec[str]) {
|
||||
if vec::len(argv) < 2u {
|
||||
let out = io::stdout();
|
||||
let out = ioivec::stdout();
|
||||
|
||||
out.write_line(#fmt("Usage: %s <filename> ...", argv.(0)));
|
||||
|
||||
@ -251,7 +251,7 @@ fn main(argv: vec[str]) {
|
||||
log_err "MapReduce completed in " + u64::str(elapsed) + "ms";
|
||||
}
|
||||
|
||||
fn read_word(r: io::reader) -> option[str] {
|
||||
fn read_word(r: ioivec::reader) -> option[str] {
|
||||
let w = "";
|
||||
|
||||
while !r.eof() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
import std::option;
|
||||
import std::str;
|
||||
import std::io;
|
||||
import std::ioivec;
|
||||
import std::fs;
|
||||
|
||||
import common::config;
|
||||
@ -69,7 +69,7 @@ fn is_test_ignored(config: &config, testfile: &str) -> bool {
|
||||
}
|
||||
|
||||
iter iter_header(testfile: &str) -> str {
|
||||
let rdr = io::file_reader(testfile);
|
||||
let rdr = ioivec::file_reader(testfile);
|
||||
while !rdr.eof() {
|
||||
let ln = rdr.read_line();
|
||||
|
||||
|
@ -12,7 +12,7 @@ import std::ivec;
|
||||
import std::os;
|
||||
import std::run;
|
||||
import std::unsafe;
|
||||
import std::io;
|
||||
import std::ioivec;
|
||||
import std::str;
|
||||
|
||||
export handle;
|
||||
@ -73,8 +73,8 @@ fn run(handle: &handle, lib_path: &str,
|
||||
|
||||
fn writeclose(fd: int, s: &option::t[str]) {
|
||||
if option::is_some(s) {
|
||||
let writer = io::new_writer(
|
||||
io::fd_buf_writer(fd, option::none));
|
||||
let writer = ioivec::new_writer(
|
||||
ioivec::fd_buf_writer(fd, option::none));
|
||||
writer.write_str(option::get(s));
|
||||
}
|
||||
|
||||
@ -84,10 +84,11 @@ fn writeclose(fd: int, s: &option::t[str]) {
|
||||
fn readclose(fd: int) -> str {
|
||||
// Copied from run::program_output
|
||||
let file = os::fd_FILE(fd);
|
||||
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
|
||||
let reader = ioivec::new_reader(
|
||||
ioivec::FILE_buf_reader(file, option::none));
|
||||
let buf = "";
|
||||
while !reader.eof() {
|
||||
let bytes = ivec::from_vec(reader.read_bytes(4096u));
|
||||
let bytes = reader.read_bytes(4096u);
|
||||
buf += str::unsafe_from_bytes(bytes);
|
||||
}
|
||||
os::libc::fclose(file);
|
||||
|
@ -1,4 +1,3 @@
|
||||
import std::io;
|
||||
import std::ioivec;
|
||||
import std::str;
|
||||
import std::option;
|
||||
@ -24,7 +23,7 @@ fn run(cx: &cx, testfile: &str) {
|
||||
test::configure_test_task();
|
||||
if (cx.config.verbose) {
|
||||
// We're going to be dumping a lot of info. Start on a new line.
|
||||
io::stdout().write_str("\n\n");
|
||||
ioivec::stdout().write_str("\n\n");
|
||||
}
|
||||
log #fmt("running %s", testfile);
|
||||
let props = load_props(testfile);
|
||||
@ -168,7 +167,7 @@ actual:\n\
|
||||
------------------------------------------\n\
|
||||
\n",
|
||||
expected, actual);
|
||||
io::stdout().write_str(msg);
|
||||
ioivec::stdout().write_str(msg);
|
||||
fail;
|
||||
}
|
||||
}
|
||||
@ -336,7 +335,8 @@ fn dump_output(config: &config, testfile: &str,
|
||||
fn dump_output_file(config: &config, testfile: &str,
|
||||
out: &str, extension: &str) {
|
||||
let outfile = make_out_name(config, testfile, extension);
|
||||
let writer = io::file_writer(outfile, [io::create, io::truncate]);
|
||||
let writer = ioivec::file_writer(outfile,
|
||||
~[ioivec::create, ioivec::truncate]);
|
||||
writer.write_str(out);
|
||||
}
|
||||
|
||||
@ -370,15 +370,15 @@ fn maybe_dump_to_stdout(config: &config,
|
||||
let sep2 = #fmt("------%s------------------------------",
|
||||
"stderr");
|
||||
let sep3 = "------------------------------------------";
|
||||
io::stdout().write_line(sep1);
|
||||
io::stdout().write_line(out);
|
||||
io::stdout().write_line(sep2);
|
||||
io::stdout().write_line(err);
|
||||
io::stdout().write_line(sep3);
|
||||
ioivec::stdout().write_line(sep1);
|
||||
ioivec::stdout().write_line(out);
|
||||
ioivec::stdout().write_line(sep2);
|
||||
ioivec::stdout().write_line(err);
|
||||
ioivec::stdout().write_line(sep3);
|
||||
}
|
||||
}
|
||||
|
||||
fn error(err: &str) { io::stdout().write_line(#fmt("\nerror: %s", err)); }
|
||||
fn error(err: &str) { ioivec::stdout().write_line(#fmt("\nerror: %s", err)); }
|
||||
|
||||
fn fatal(err: &str) -> ! { error(err); fail; }
|
||||
|
||||
@ -397,6 +397,6 @@ stderr:\n\
|
||||
------------------------------------------\n\
|
||||
\n",
|
||||
err, procres.cmdline, procres.stdout, procres.stderr);
|
||||
io::stdout().write_str(msg);
|
||||
ioivec::stdout().write_str(msg);
|
||||
fail;
|
||||
}
|
||||
|
@ -1,6 +1,6 @@
|
||||
import std::option;
|
||||
import std::generic_os::getenv;
|
||||
import std::io;
|
||||
import std::ioivec;
|
||||
|
||||
import common::config;
|
||||
|
||||
@ -25,5 +25,5 @@ fn lib_path_env_var() -> str { "PATH" }
|
||||
|
||||
fn logv(config: &config, s: &str) {
|
||||
log s;
|
||||
if config.verbose { io::stdout().write_line(s); }
|
||||
if config.verbose { ioivec::stdout().write_line(s); }
|
||||
}
|
||||
|
@ -6,7 +6,6 @@
|
||||
|
||||
use std;
|
||||
|
||||
import std::io;
|
||||
import option = std::option::t;
|
||||
import std::option::some;
|
||||
import std::option::none;
|
||||
|
@ -1,6 +1,5 @@
|
||||
use std;
|
||||
import std::str;
|
||||
import std::io;
|
||||
import std::ivec;
|
||||
|
||||
fn main() {
|
||||
|
@ -1,6 +1,6 @@
|
||||
// -*- rust -*-
|
||||
use std;
|
||||
import std::io;
|
||||
import std::ioivec;
|
||||
import std::str;
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
@ -12,11 +12,11 @@ fn test_simple() {
|
||||
let frood: str = "A hoopy frood who really knows where his towel is.";
|
||||
log frood;
|
||||
{
|
||||
let out: io::writer =
|
||||
io::file_writer(tmpfile, [io::create, io::truncate]);
|
||||
let out: ioivec::writer =
|
||||
ioivec::file_writer(tmpfile, ~[ioivec::create, ioivec::truncate]);
|
||||
out.write_str(frood);
|
||||
}
|
||||
let inp: io::reader = io::file_reader(tmpfile);
|
||||
let inp: ioivec::reader = ioivec::file_reader(tmpfile);
|
||||
let frood2: str = inp.read_c_str();
|
||||
log frood2;
|
||||
assert (str::eq(frood, frood2));
|
||||
|
@ -1,7 +1,7 @@
|
||||
use std;
|
||||
import std::run;
|
||||
import std::os;
|
||||
import std::io;
|
||||
import std::ioivec;
|
||||
import std::option;
|
||||
import std::str;
|
||||
import std::ivec;
|
||||
@ -46,8 +46,8 @@ fn test_pipes() {
|
||||
assert expected == actual;
|
||||
|
||||
fn writeclose(fd: int, s: &str) {
|
||||
let writer = io::new_writer(
|
||||
io::fd_buf_writer(fd, option::none));
|
||||
let writer = ioivec::new_writer(
|
||||
ioivec::fd_buf_writer(fd, option::none));
|
||||
writer.write_str(s);
|
||||
|
||||
os::libc::close(fd);
|
||||
@ -56,10 +56,11 @@ fn test_pipes() {
|
||||
fn readclose(fd: int) -> str {
|
||||
// Copied from run::program_output
|
||||
let file = os::fd_FILE(fd);
|
||||
let reader = io::new_reader(io::FILE_buf_reader(file, option::none));
|
||||
let reader = ioivec::new_reader(
|
||||
ioivec::FILE_buf_reader(file, option::none));
|
||||
let buf = "";
|
||||
while !reader.eof() {
|
||||
let bytes = ivec::from_vec(reader.read_bytes(4096u));
|
||||
let bytes = reader.read_bytes(4096u);
|
||||
buf += str::unsafe_from_bytes(bytes);
|
||||
}
|
||||
os::libc::fclose(file);
|
||||
|
Loading…
x
Reference in New Issue
Block a user