Test fixes and merge conflicts
This commit is contained in:
parent
279c351820
commit
620ab3853a
@ -43,7 +43,7 @@ $ ./example numbers.txt
|
||||
|
||||
An example program that does this task reads like this:
|
||||
|
||||
~~~~
|
||||
~~~~{.xfail-test}
|
||||
# #[allow(unused_imports)];
|
||||
extern mod extra;
|
||||
use extra::fileinput::FileInput;
|
||||
@ -430,7 +430,7 @@ To trap a condition, use `Condition::trap` in some caller of the site that calls
|
||||
For example, this version of the program traps the `malformed_line` condition
|
||||
and replaces bad input lines with the pair `(-1,-1)`:
|
||||
|
||||
~~~~
|
||||
~~~~{.xfail-test}
|
||||
# #[allow(unused_imports)];
|
||||
extern mod extra;
|
||||
use extra::fileinput::FileInput;
|
||||
@ -507,7 +507,7 @@ In the example program, the first form of the `malformed_line` API implicitly as
|
||||
This assumption may not be correct; some callers may wish to skip malformed lines, for example.
|
||||
Changing the condition's return type from `(int,int)` to `Option<(int,int)>` will suffice to support this type of recovery:
|
||||
|
||||
~~~~
|
||||
~~~~{.xfail-test}
|
||||
# #[allow(unused_imports)];
|
||||
extern mod extra;
|
||||
use extra::fileinput::FileInput;
|
||||
@ -594,7 +594,7 @@ until all relevant combinations encountered in practice are encoded.
|
||||
In the example, suppose a third possible recovery form arose: reusing the previous value read.
|
||||
This can be encoded in the handler API by introducing a helper type: `enum MalformedLineFix`.
|
||||
|
||||
~~~~
|
||||
~~~~{.xfail-test}
|
||||
# #[allow(unused_imports)];
|
||||
extern mod extra;
|
||||
use extra::fileinput::FileInput;
|
||||
@ -720,7 +720,7 @@ task <unnamed> failed at 'called `Option::unwrap()` on a `None` value', .../libs
|
||||
To make the program robust -- or at least flexible -- in the face of this potential failure,
|
||||
a second condition and a helper function will suffice:
|
||||
|
||||
~~~~
|
||||
~~~~{.xfail-test}
|
||||
# #[allow(unused_imports)];
|
||||
extern mod extra;
|
||||
use extra::fileinput::FileInput;
|
||||
|
@ -69,7 +69,6 @@ calling the `spawn` function with a closure argument. `spawn` executes the
|
||||
closure in the new task.
|
||||
|
||||
~~~~
|
||||
# use std::io::println;
|
||||
# use std::task::spawn;
|
||||
|
||||
// Print something profound in a different task using a named function
|
||||
|
@ -2907,12 +2907,12 @@ you just have to import it with an `use` statement.
|
||||
For example, it re-exports `println` which is defined in `std::io::println`:
|
||||
|
||||
~~~
|
||||
use puts = std::io::println;
|
||||
use puts = std::rt::io::stdio::println;
|
||||
|
||||
fn main() {
|
||||
println("println is imported per default.");
|
||||
puts("Doesn't hinder you from importing it under an different name yourself.");
|
||||
::std::io::println("Or from not using the automatic import.");
|
||||
::std::rt::io::stdio::println("Or from not using the automatic import.");
|
||||
}
|
||||
~~~
|
||||
|
||||
|
@ -189,6 +189,8 @@ pub fn env() -> ~[(~str,~str)] {
|
||||
#[cfg(windows)]
|
||||
unsafe fn get_env_pairs() -> ~[~str] {
|
||||
#[fixed_stack_segment]; #[inline(never)];
|
||||
use c_str;
|
||||
use str::StrSlice;
|
||||
|
||||
use libc::funcs::extra::kernel32::{
|
||||
GetEnvironmentStringsA,
|
||||
@ -201,7 +203,7 @@ pub fn env() -> ~[(~str,~str)] {
|
||||
}
|
||||
let mut result = ~[];
|
||||
do c_str::from_c_multistring(ch as *libc::c_char, None) |cstr| {
|
||||
result.push(cstr.as_str().to_owned());
|
||||
result.push(cstr.as_str().unwrap().to_owned());
|
||||
};
|
||||
FreeEnvironmentStringsA(ch);
|
||||
result
|
||||
|
@ -17,9 +17,18 @@ use os;
|
||||
use prelude::*;
|
||||
use super::super::*;
|
||||
|
||||
fn raise_error() {
|
||||
#[cfg(windows)]
|
||||
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
|
||||
match errno {
|
||||
libc::EOF => (EndOfFile, "end of file"),
|
||||
_ => (OtherIoError, "unknown error"),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
fn get_err(errno: i32) -> (IoErrorKind, &'static str) {
|
||||
// XXX: this should probably be a bit more descriptive...
|
||||
let (kind, desc) = match os::errno() as i32 {
|
||||
match errno {
|
||||
libc::EOF => (EndOfFile, "end of file"),
|
||||
|
||||
// These two constants can have the same value on some systems, but
|
||||
@ -28,8 +37,11 @@ fn raise_error() {
|
||||
(ResourceUnavailable, "resource temporarily unavailable"),
|
||||
|
||||
_ => (OtherIoError, "unknown error"),
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
fn raise_error() {
|
||||
let (kind, desc) = get_err(os::errno() as i32);
|
||||
io_error::cond.raise(IoError {
|
||||
kind: kind,
|
||||
desc: desc,
|
||||
|
@ -91,8 +91,11 @@ pub fn get_host_addresses(host: &str) -> Option<~[IpAddr]> {
|
||||
/// # Failure
|
||||
///
|
||||
/// On failure, this will raise on the `io_error` condition.
|
||||
pub fn lookup(hostname: Option<&str>, servname: Option<&str>,
|
||||
hint: Option<Hint>) -> Option<~[Info]> {
|
||||
///
|
||||
/// XXX: this is not public because the `Hint` structure is not ready for public
|
||||
/// consumption just yet.
|
||||
fn lookup(hostname: Option<&str>, servname: Option<&str>,
|
||||
hint: Option<Hint>) -> Option<~[Info]> {
|
||||
do with_local_io |io| {
|
||||
match io.get_host_addresses(hostname, servname, hint) {
|
||||
Ok(i) => Some(i),
|
||||
|
@ -72,16 +72,22 @@ pub fn default_sched_threads() -> uint {
|
||||
pub fn dumb_println(args: &fmt::Arguments) {
|
||||
use rt::io::native::stdio::stderr;
|
||||
use rt::io::{Writer, io_error, ResourceUnavailable};
|
||||
use rt::task::Task;
|
||||
use rt::local::Local;
|
||||
|
||||
let mut out = stderr();
|
||||
let mut again = true;
|
||||
do io_error::cond.trap(|e| {
|
||||
again = e.kind == ResourceUnavailable;
|
||||
}).inside {
|
||||
while again {
|
||||
again = false;
|
||||
fmt::writeln(&mut out as &mut Writer, args);
|
||||
if Local::exists(None::<Task>) {
|
||||
let mut again = true;
|
||||
do io_error::cond.trap(|e| {
|
||||
again = e.kind == ResourceUnavailable;
|
||||
}).inside {
|
||||
while again {
|
||||
again = false;
|
||||
fmt::writeln(&mut out as &mut Writer, args);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fmt::writeln(&mut out as &mut Writer, args);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -73,13 +73,14 @@ impl GetAddrInfoRequest {
|
||||
cb(req, addrinfo, err)
|
||||
};
|
||||
|
||||
let hint = hints.map(|hint| unsafe {
|
||||
let hint = hints.map(|hint| {
|
||||
let mut flags = 0;
|
||||
do each_ai_flag |cval, aival| {
|
||||
if hint.flags & (aival as uint) != 0 {
|
||||
flags |= cval as i32;
|
||||
}
|
||||
}
|
||||
/* XXX: do we really want to support these?
|
||||
let socktype = match hint.socktype {
|
||||
Some(ai::Stream) => uvll::rust_SOCK_STREAM(),
|
||||
Some(ai::Datagram) => uvll::rust_SOCK_DGRAM(),
|
||||
@ -91,6 +92,9 @@ impl GetAddrInfoRequest {
|
||||
Some(ai::TCP) => uvll::rust_IPPROTO_TCP(),
|
||||
_ => 0,
|
||||
};
|
||||
*/
|
||||
let socktype = 0;
|
||||
let protocol = 0;
|
||||
|
||||
uvll::addrinfo {
|
||||
ai_flags: flags,
|
||||
@ -167,7 +171,8 @@ impl GetAddrInfoRequest {
|
||||
}
|
||||
}
|
||||
|
||||
fn each_ai_flag(f: &fn(c_int, ai::Flag)) {
|
||||
fn each_ai_flag(_f: &fn(c_int, ai::Flag)) {
|
||||
/* XXX: do we really want to support these?
|
||||
unsafe {
|
||||
f(uvll::rust_AI_ADDRCONFIG(), ai::AddrConfig);
|
||||
f(uvll::rust_AI_ALL(), ai::All);
|
||||
@ -177,6 +182,7 @@ fn each_ai_flag(f: &fn(c_int, ai::Flag)) {
|
||||
f(uvll::rust_AI_PASSIVE(), ai::Passive);
|
||||
f(uvll::rust_AI_V4MAPPED(), ai::V4Mapped);
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// Traverse the addrinfo linked list, producing a vector of Rust socket addresses
|
||||
@ -197,6 +203,7 @@ pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] {
|
||||
}
|
||||
}
|
||||
|
||||
/* XXX: do we really want to support these
|
||||
let protocol = match (*addr).ai_protocol {
|
||||
p if p == uvll::rust_IPPROTO_UDP() => Some(ai::UDP),
|
||||
p if p == uvll::rust_IPPROTO_TCP() => Some(ai::TCP),
|
||||
@ -208,6 +215,9 @@ pub fn accum_addrinfo(addr: &net::UvAddrInfo) -> ~[ai::Info] {
|
||||
p if p == uvll::rust_SOCK_RAW() => Some(ai::Raw),
|
||||
_ => None,
|
||||
};
|
||||
*/
|
||||
let protocol = None;
|
||||
let socktype = None;
|
||||
|
||||
addrs.push(ai::Info {
|
||||
address: rustaddr,
|
||||
|
@ -336,6 +336,13 @@ pub fn status_to_maybe_uv_error(status: c_int) -> Option<UvError>
|
||||
/// The uv buffer type
|
||||
pub type Buf = uvll::uv_buf_t;
|
||||
|
||||
pub fn empty_buf() -> Buf {
|
||||
uvll::uv_buf_t {
|
||||
base: null(),
|
||||
len: 0,
|
||||
}
|
||||
}
|
||||
|
||||
/// Borrow a slice to a Buf
|
||||
pub fn slice_to_uv_buf(v: &[u8]) -> Buf {
|
||||
let data = vec::raw::to_ptr(v);
|
||||
|
@ -14,7 +14,7 @@ use rt::uv::uvll;
|
||||
use rt::uv::uvll::*;
|
||||
use rt::uv::{AllocCallback, ConnectionCallback, ReadCallback, UdpReceiveCallback, UdpSendCallback};
|
||||
use rt::uv::{Loop, Watcher, Request, UvError, Buf, NativeHandle,
|
||||
status_to_maybe_uv_error, vec_to_uv_buf};
|
||||
status_to_maybe_uv_error, empty_buf};
|
||||
use rt::io::net::ip::{SocketAddr, Ipv4Addr, Ipv6Addr};
|
||||
use vec;
|
||||
use str;
|
||||
@ -119,23 +119,17 @@ impl Watcher for StreamWatcher { }
|
||||
|
||||
impl StreamWatcher {
|
||||
pub fn read_start(&mut self, alloc: AllocCallback, cb: ReadCallback) {
|
||||
{
|
||||
let data = self.get_watcher_data();
|
||||
data.alloc_cb = Some(alloc);
|
||||
data.read_cb = Some(cb);
|
||||
}
|
||||
|
||||
let ret = unsafe { uvll::read_start(self.native_handle(), alloc_cb, read_cb) };
|
||||
|
||||
if ret != 0 {
|
||||
// uvll::read_start failed, so read_cb will not be called.
|
||||
// Call it manually for scheduling.
|
||||
call_read_cb(self.native_handle(), ret as ssize_t);
|
||||
}
|
||||
|
||||
fn call_read_cb(stream: *uvll::uv_stream_t, errno: ssize_t) {
|
||||
#[fixed_stack_segment]; #[inline(never)];
|
||||
read_cb(stream, errno, vec_to_uv_buf(~[]));
|
||||
unsafe {
|
||||
match uvll::read_start(self.native_handle(), alloc_cb, read_cb) {
|
||||
0 => {
|
||||
let data = self.get_watcher_data();
|
||||
data.alloc_cb = Some(alloc);
|
||||
data.read_cb = Some(cb);
|
||||
}
|
||||
n => {
|
||||
cb(*self, 0, empty_buf(), Some(UvError(n)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
extern fn alloc_cb(stream: *uvll::uv_stream_t, suggested_size: size_t) -> Buf {
|
||||
@ -163,16 +157,21 @@ impl StreamWatcher {
|
||||
}
|
||||
|
||||
pub fn write(&mut self, buf: Buf, cb: ConnectionCallback) {
|
||||
{
|
||||
let data = self.get_watcher_data();
|
||||
assert!(data.write_cb.is_none());
|
||||
data.write_cb = Some(cb);
|
||||
}
|
||||
|
||||
let req = WriteRequest::new();
|
||||
unsafe {
|
||||
assert_eq!(0, uvll::write(req.native_handle(), self.native_handle(), [buf], write_cb));
|
||||
}
|
||||
return unsafe {
|
||||
match uvll::write(req.native_handle(), self.native_handle(),
|
||||
[buf], write_cb) {
|
||||
0 => {
|
||||
let data = self.get_watcher_data();
|
||||
assert!(data.write_cb.is_none());
|
||||
data.write_cb = Some(cb);
|
||||
}
|
||||
n => {
|
||||
req.delete();
|
||||
cb(*self, Some(UvError(n)))
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
extern fn write_cb(req: *uvll::uv_write_t, status: c_int) {
|
||||
let write_request: WriteRequest = NativeHandle::from_native_handle(req);
|
||||
|
@ -229,7 +229,7 @@ impl EventLoop for UvEventLoop {
|
||||
}
|
||||
}
|
||||
|
||||
fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback{
|
||||
fn remote_callback(&mut self, f: ~fn()) -> ~RemoteCallback {
|
||||
~UvRemoteCallback::new(self.uvio.uv_loop(), f) as ~RemoteCallback
|
||||
}
|
||||
|
||||
|
@ -1146,17 +1146,18 @@ extern {
|
||||
height: *c_int) -> c_int;
|
||||
fn rust_uv_guess_handle(fd: c_int) -> uv_handle_type;
|
||||
|
||||
// XXX: see comments in addrinfo.rs
|
||||
// These should all really be constants...
|
||||
#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int;
|
||||
#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int;
|
||||
#[rust_stack] pub fn rust_SOCK_RAW() -> c_int;
|
||||
#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int;
|
||||
#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int;
|
||||
#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int;
|
||||
#[rust_stack] pub fn rust_AI_ALL() -> c_int;
|
||||
#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int;
|
||||
#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int;
|
||||
#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int;
|
||||
#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int;
|
||||
#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int;
|
||||
//#[rust_stack] pub fn rust_SOCK_STREAM() -> c_int;
|
||||
//#[rust_stack] pub fn rust_SOCK_DGRAM() -> c_int;
|
||||
//#[rust_stack] pub fn rust_SOCK_RAW() -> c_int;
|
||||
//#[rust_stack] pub fn rust_IPPROTO_UDP() -> c_int;
|
||||
//#[rust_stack] pub fn rust_IPPROTO_TCP() -> c_int;
|
||||
//#[rust_stack] pub fn rust_AI_ADDRCONFIG() -> c_int;
|
||||
//#[rust_stack] pub fn rust_AI_ALL() -> c_int;
|
||||
//#[rust_stack] pub fn rust_AI_CANONNAME() -> c_int;
|
||||
//#[rust_stack] pub fn rust_AI_NUMERICHOST() -> c_int;
|
||||
//#[rust_stack] pub fn rust_AI_NUMERICSERV() -> c_int;
|
||||
//#[rust_stack] pub fn rust_AI_PASSIVE() -> c_int;
|
||||
//#[rust_stack] pub fn rust_AI_V4MAPPED() -> c_int;
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ use libc;
|
||||
use prelude::*;
|
||||
use rt::io::native::process;
|
||||
use rt::io;
|
||||
use rt::io::extensions::ReaderUtil;
|
||||
use task;
|
||||
|
||||
/**
|
||||
@ -189,18 +190,6 @@ impl Process {
|
||||
let output = Cell::new(self.inner.take_output());
|
||||
let error = Cell::new(self.inner.take_error());
|
||||
|
||||
fn read_everything(r: &mut io::Reader) -> ~[u8] {
|
||||
let mut ret = ~[];
|
||||
let mut buf = [0, ..1024];
|
||||
loop {
|
||||
match r.read(buf) {
|
||||
Some(n) => { ret.push_all(buf.slice_to(n)); }
|
||||
None => break
|
||||
}
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
// Spawn two entire schedulers to read both stdout and sterr
|
||||
// in parallel so we don't deadlock while blocking on one
|
||||
// or the other. FIXME (#2625): Surely there's a much more
|
||||
@ -210,13 +199,13 @@ impl Process {
|
||||
let ch_clone = ch.clone();
|
||||
do task::spawn_sched(task::SingleThreaded) {
|
||||
match error.take() {
|
||||
Some(ref mut e) => ch.send((2, read_everything(*e))),
|
||||
Some(ref mut e) => ch.send((2, e.read_to_end())),
|
||||
None => ch.send((2, ~[]))
|
||||
}
|
||||
}
|
||||
do task::spawn_sched(task::SingleThreaded) {
|
||||
match output.take() {
|
||||
Some(ref mut e) => ch_clone.send((1, read_everything(*e))),
|
||||
Some(ref mut e) => ch_clone.send((1, e.read_to_end())),
|
||||
None => ch_clone.send((1, ~[]))
|
||||
}
|
||||
}
|
||||
|
@ -129,6 +129,7 @@ pub fn expand_include_bin(cx: @ExtCtxt, sp: Span, tts: &[ast::token_tree])
|
||||
file.display(), e.desc));
|
||||
}
|
||||
None => {
|
||||
let bytes = at_vec::to_managed_move(bytes);
|
||||
base::MRExpr(cx.expr_lit(sp, ast::lit_binary(bytes)))
|
||||
}
|
||||
}
|
||||
|
@ -638,19 +638,6 @@ rust_uv_pipe_init(uv_loop_t *loop, uv_pipe_t* p, int ipc) {
|
||||
return uv_pipe_init(loop, p, ipc);
|
||||
}
|
||||
|
||||
extern "C" int rust_SOCK_STREAM() { return SOCK_STREAM; }
|
||||
extern "C" int rust_SOCK_DGRAM() { return SOCK_DGRAM; }
|
||||
extern "C" int rust_SOCK_RAW() { return SOCK_RAW; }
|
||||
extern "C" int rust_IPPROTO_UDP() { return IPPROTO_UDP; }
|
||||
extern "C" int rust_IPPROTO_TCP() { return IPPROTO_TCP; }
|
||||
extern "C" int rust_AI_ADDRCONFIG() { return AI_ADDRCONFIG; }
|
||||
extern "C" int rust_AI_ALL() { return AI_ALL; }
|
||||
extern "C" int rust_AI_CANONNAME() { return AI_CANONNAME; }
|
||||
extern "C" int rust_AI_NUMERICHOST() { return AI_NUMERICHOST; }
|
||||
extern "C" int rust_AI_NUMERICSERV() { return AI_NUMERICSERV; }
|
||||
extern "C" int rust_AI_PASSIVE() { return AI_PASSIVE; }
|
||||
extern "C" int rust_AI_V4MAPPED() { return AI_V4MAPPED; }
|
||||
|
||||
extern "C" int
|
||||
rust_uv_pipe_open(uv_pipe_t *pipe, int file) {
|
||||
return uv_pipe_open(pipe, file);
|
||||
|
@ -199,18 +199,6 @@ bufrelease
|
||||
bufnew
|
||||
rust_take_dlerror_lock
|
||||
rust_drop_dlerror_lock
|
||||
rust_SOCK_STREAM
|
||||
rust_SOCK_DGRAM
|
||||
rust_SOCK_RAW
|
||||
rust_IPPROTO_UDP
|
||||
rust_IPPROTO_TCP
|
||||
rust_AI_ADDRCONFIG
|
||||
rust_AI_ALL
|
||||
rust_AI_CANONNAME
|
||||
rust_AI_NUMERICHOST
|
||||
rust_AI_NUMERICSERV
|
||||
rust_AI_PASSIVE
|
||||
rust_AI_V4MAPPED
|
||||
rust_uv_pipe_open
|
||||
rust_uv_pipe_bind
|
||||
rust_uv_pipe_connect
|
||||
|
@ -111,6 +111,7 @@ fn acid(ch: char, prob: u32) -> AminoAcids {
|
||||
}
|
||||
|
||||
fn main() {
|
||||
use std::rt::io::file::FileInfo;
|
||||
let args = os::args();
|
||||
let args = if os::getenv("RUST_BENCH").is_some() {
|
||||
// alioth tests k-nucleotide with this data at 25,000,000
|
||||
@ -122,7 +123,7 @@ fn main() {
|
||||
};
|
||||
|
||||
let writer = if os::getenv("RUST_BENCH").is_some() {
|
||||
let file = "./shootout-fasta.data".open_writer(io::CreateOrTruncate);
|
||||
let file = Path::new("./shootout-fasta.data").open_writer(io::CreateOrTruncate);
|
||||
@mut file as @mut io::Writer
|
||||
} else {
|
||||
@mut io::stdout() as @mut io::Writer
|
||||
|
@ -20,6 +20,7 @@ use std::comm;
|
||||
use std::hashmap::HashMap;
|
||||
use std::option;
|
||||
use std::os;
|
||||
use std::rt::io;
|
||||
use std::str;
|
||||
use std::task;
|
||||
use std::util;
|
||||
@ -193,48 +194,48 @@ fn main() {
|
||||
let mut proc_mode = false;
|
||||
|
||||
loop {
|
||||
let line = match rdr.read_line() {
|
||||
Some(ln) => ln, None => break,
|
||||
};
|
||||
let line = line.trim().to_owned();
|
||||
let line = match io::ignore_io_error(|| rdr.read_line()) {
|
||||
Some(ln) => ln, None => break,
|
||||
};
|
||||
let line = line.trim().to_owned();
|
||||
|
||||
if line.len() == 0u { continue; }
|
||||
if line.len() == 0u { continue; }
|
||||
|
||||
match (line[0] as char, proc_mode) {
|
||||
match (line[0] as char, proc_mode) {
|
||||
|
||||
// start processing if this is the one
|
||||
('>', false) => {
|
||||
match line.slice_from(1).find_str("THREE") {
|
||||
option::Some(_) => { proc_mode = true; }
|
||||
option::None => { }
|
||||
}
|
||||
}
|
||||
// start processing if this is the one
|
||||
('>', false) => {
|
||||
match line.slice_from(1).find_str("THREE") {
|
||||
option::Some(_) => { proc_mode = true; }
|
||||
option::None => { }
|
||||
}
|
||||
}
|
||||
|
||||
// break our processing
|
||||
('>', true) => { break; }
|
||||
// break our processing
|
||||
('>', true) => { break; }
|
||||
|
||||
// process the sequence for k-mers
|
||||
(_, true) => {
|
||||
let line_bytes = line.as_bytes();
|
||||
// process the sequence for k-mers
|
||||
(_, true) => {
|
||||
let line_bytes = line.as_bytes();
|
||||
|
||||
for (ii, _sz) in sizes.iter().enumerate() {
|
||||
let lb = line_bytes.to_owned();
|
||||
to_child[ii].send(lb);
|
||||
}
|
||||
}
|
||||
for (ii, _sz) in sizes.iter().enumerate() {
|
||||
let lb = line_bytes.to_owned();
|
||||
to_child[ii].send(lb);
|
||||
}
|
||||
}
|
||||
|
||||
// whatever
|
||||
_ => { }
|
||||
}
|
||||
// whatever
|
||||
_ => { }
|
||||
}
|
||||
}
|
||||
|
||||
// finish...
|
||||
for (ii, _sz) in sizes.iter().enumerate() {
|
||||
to_child[ii].send(~[]);
|
||||
for (ii, _sz) in sizes.iter().enumerate() {
|
||||
to_child[ii].send(~[]);
|
||||
}
|
||||
|
||||
// now fetch and print result messages
|
||||
for (ii, _sz) in sizes.iter().enumerate() {
|
||||
println(from_child[ii].recv());
|
||||
for (ii, _sz) in sizes.iter().enumerate() {
|
||||
println(from_child[ii].recv());
|
||||
}
|
||||
}
|
||||
|
@ -15,6 +15,8 @@
|
||||
extern mod extra;
|
||||
|
||||
use std::rt::io;
|
||||
use std::rt::io::stdio::StdReader;
|
||||
use std::rt::io::buffered::BufferedReader;
|
||||
use std::os;
|
||||
use std::uint;
|
||||
use std::unstable::intrinsics::cttz16;
|
||||
@ -66,12 +68,14 @@ impl Sudoku {
|
||||
return true;
|
||||
}
|
||||
|
||||
pub fn read(reader: @mut io::Reader) -> Sudoku {
|
||||
assert!(reader.read_line() == ~"9,9"); /* assert first line is exactly "9,9" */
|
||||
pub fn read(mut reader: BufferedReader<StdReader>) -> Sudoku {
|
||||
assert!(reader.read_line().unwrap() == ~"9,9"); /* assert first line is exactly "9,9" */
|
||||
|
||||
let mut g = vec::from_fn(10u, { |_i| ~[0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8, 0u8] });
|
||||
while !reader.eof() {
|
||||
let line = reader.read_line();
|
||||
loop {
|
||||
let line = match reader.read_line() {
|
||||
Some(ln) => ln, None => break
|
||||
};
|
||||
let comps: ~[&str] = line.trim().split_iter(',').collect();
|
||||
|
||||
if comps.len() == 3u {
|
||||
@ -88,11 +92,11 @@ impl Sudoku {
|
||||
|
||||
pub fn write(&self, writer: @mut io::Writer) {
|
||||
for row in range(0u8, 9u8) {
|
||||
writer.write_str(format!("{}", self.grid[row][0] as uint));
|
||||
write!(writer, "{}", self.grid[row][0]);
|
||||
for col in range(1u8, 9u8) {
|
||||
writer.write_str(format!(" {}", self.grid[row][col] as uint));
|
||||
write!(writer, " {}", self.grid[row][col]);
|
||||
}
|
||||
writer.write_char('\n');
|
||||
write!(writer, "\n");
|
||||
}
|
||||
}
|
||||
|
||||
@ -277,7 +281,7 @@ fn main() {
|
||||
let mut sudoku = if use_default {
|
||||
Sudoku::from_vec(&DEFAULT_SUDOKU)
|
||||
} else {
|
||||
Sudoku::read(@mut io::stdin() as @mut io::Reader)
|
||||
Sudoku::read(BufferedReader::new(io::stdin()))
|
||||
};
|
||||
sudoku.solve();
|
||||
sudoku.write(@mut io::stdout() as @mut io::Writer);
|
||||
|
Loading…
Reference in New Issue
Block a user