]> git.lizzy.rs Git - rust.git/commitdiff
Test fixes and merge conflicts
authorAlex Crichton <alex@alexcrichton.com>
Fri, 18 Oct 2013 04:08:48 +0000 (21:08 -0700)
committerAlex Crichton <alex@alexcrichton.com>
Thu, 24 Oct 2013 21:21:58 +0000 (14:21 -0700)
19 files changed:
doc/tutorial-conditions.md
doc/tutorial-tasks.md
doc/tutorial.md
src/libstd/os.rs
src/libstd/rt/io/native/file.rs
src/libstd/rt/io/net/addrinfo.rs
src/libstd/rt/util.rs
src/libstd/rt/uv/addrinfo.rs
src/libstd/rt/uv/mod.rs
src/libstd/rt/uv/net.rs
src/libstd/rt/uv/uvio.rs
src/libstd/rt/uv/uvll.rs
src/libstd/run.rs
src/libsyntax/ext/source_util.rs
src/rt/rust_uv.cpp
src/rt/rustrt.def.in
src/test/bench/shootout-fasta.rs
src/test/bench/shootout-k-nucleotide-pipes.rs
src/test/bench/sudoku.rs

index 726b8bb2b8001a4ef995f057869b5dee7563145b..056d967ae6ca8ad3b9de23ca0b6ad4f6a2e1cc67 100644 (file)
@@ -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;
index 767f712a8d8c11be19bd1a3c9a7ea484fe5e3e4f..4983a5af3e5abc04d93f005f4d87436d08b9b016 100644 (file)
@@ -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
index 7451919c5becf3e37cd26aae1b72b2df0b861b41..f9f110c122b28673e207abda2199f3b0266af26b 100644 (file)
@@ -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.");
 }
 ~~~
 
index 99930b39a6533e5dcfd078f18fceeabb15f50063..1f32c6a0a35efd97c2caa117bc45dc4a2375c2d3 100644 (file)
@@ -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 @@ unsafe fn get_env_pairs() -> ~[~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
index a2b2289679afce08cd4339fa6c114eda7cf1f921..ba819df071a97d5e37862fd8b5124ad113b039ef 100644 (file)
 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,
index e0c92730cd9056cafb17a8b16de7da5416350c5d..27cf9781c9c3cda643d001843693a26488c42443 100644 (file)
@@ -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),
index e859f8e4fdb3517ea2f125dbe2c5a719ca978b6a..070985fb0a5cf79a9ac36454fdab630f74ccf67d 100644 (file)
@@ -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);
     }
 }
 
index 7556d7db665efca313d2808b77e6b18014ce6641..a1593d5c8db73efa44583ae751549bf40101f59c 100644 (file)
@@ -73,13 +73,14 @@ pub fn getaddrinfo(&mut self, loop_: &Loop, node: Option<&str>,
             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 @@ pub fn getaddrinfo(&mut self, loop_: &Loop, node: Option<&str>,
                 Some(ai::TCP) => uvll::rust_IPPROTO_TCP(),
                 _ => 0,
             };
+            */
+            let socktype = 0;
+            let protocol = 0;
 
             uvll::addrinfo {
                 ai_flags: flags,
@@ -167,7 +171,8 @@ fn delete(self) {
     }
 }
 
-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,
index 18c991577076344af929debad8f65fe67383c3e4..88bb28d3763f09c6c173e867a37971623e670655 100644 (file)
@@ -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);
index 22d7c9c61b3a9ae0f3789b2e8ffc68e4bc8f1af7..77de8348c14613a7a0aa09167a7d4adea3bb8426 100644 (file)
@@ -14,7 +14,7 @@
 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 @@ pub fn read_stop(&mut self) {
     }
 
     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);
index 0d22aa51be5be8b2635b9739e51f82295daca620..f12b1bce9e67d91e6a19442348d930540c6c4852 100644 (file)
@@ -229,7 +229,7 @@ fn callback_ms(&mut self, ms: u64, f: ~fn()) {
         }
     }
 
-    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
     }
 
index 8f8aea9d121695e6c1eadeb8500821f338fc2e66..f3e14dc314b70eaaca9634cbfb2ad8d3e0b8b2c0 100644 (file)
@@ -1146,17 +1146,18 @@ fn rust_uv_tty_get_winsize(tty: *uv_tty_t, width: *c_int,
                                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;
 }
index c4cb8be2061f904917f83f69639523e90c426039..d5f8e82b90fc5d7f91e5183d5d84c1016a6770b0 100644 (file)
@@ -19,6 +19,7 @@
 use prelude::*;
 use rt::io::native::process;
 use rt::io;
+use rt::io::extensions::ReaderUtil;
 use task;
 
 /**
@@ -189,18 +190,6 @@ pub fn finish_with_output(&mut self) -> ProcessOutput {
         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 @@ fn read_everything(r: &mut io::Reader) -> ~[u8] {
         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, ~[]))
             }
         }
index 047fc541ba8b37e3509882c72ee2c1a76649839d..119a74cccd6d505a2a965ea948571682a0fcd2e4 100644 (file)
@@ -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)))
         }
     }
index 7ab57e6909aa748cab6945c3b5aaa82d1148fa5a..55fa09c38183de1decea25c8d615e4e0889c387c 100644 (file)
@@ -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);
index 6c3988d6b01522b2188a1241a097ebb292735bd1..203f2e4d5f2b4833e7188a37ab61aa95a5e83d29 100644 (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
index 3d1362b2f2931122574334d93b7cd7acf94cb87e..52f068b8b1cdd13600440ded3f050365c4b23262 100644 (file)
@@ -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
index 83a0fbd42ced2ed404c28496fba623254a297cf0..cfc78e1615ec072da0fe76873ad3fbb2e95c66b2 100644 (file)
@@ -20,6 +20,7 @@
 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();
-
-      if line.len() == 0u { continue; }
-
-      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    => { }
-            }
-         }
-
-         // break our processing
-         ('>', true) => { break; }
-
-         // 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);
-            }
-         }
-
-         // whatever
-         _ => { }
-      }
+       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; }
+
+       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    => { }
+               }
+           }
+
+           // break our processing
+           ('>', true) => { break; }
+
+           // 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);
+               }
+           }
+
+           // 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());
    }
 }
index 21d492d85fc338c21790e019e73f7c1041391e22..d4f4a46af38b123d85118fbc7e0b58e61a7d9434 100644 (file)
@@ -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 @@ pub fn equal(&self, other: &Sudoku) -> bool {
         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 @@ pub fn read(reader: @mut io::Reader) -> 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);