1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-29 12:07:46 +00:00

Merge pull request #497 from ebfe/fix-build-alpha

Fix build with rust alpha
This commit is contained in:
Heather 2015-01-10 23:01:16 +03:00
commit 76bb7163d2
93 changed files with 461 additions and 352 deletions

View file

@ -222,15 +222,17 @@ $(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS
$(if $(ENABLE_STRIP),strip $@)
# Dependencies
$(BUILDDIR)/.rust-crypto: $(BUILDDIR)/.rust-time | $(BUILDDIR)
$(BUILDDIR)/.rust-crypto: | $(BUILDDIR)
cd $(BASEDIR)/deps/rust-crypto && $(CARGO) build --release
cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/librustc-serialize*.rlib $(BUILDDIR)
cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/libtime*.rlib $(BUILDDIR)/libtime.rlib
cp -r $(BASEDIR)/deps/rust-crypto/target/release/libcrypto*.rlib $(BUILDDIR)/libcrypto.rlib
@touch $@
$(BUILDDIR)/.rust-time:
cd $(BASEDIR)/deps/time && $(CARGO) build --release
cp -r $(BASEDIR)/deps/time/target/release/libtime*.rlib $(BUILDDIR)/libtime.rlib
@touch $@
#$(BUILDDIR)/.rust-time:
# cd $(BASEDIR)/deps/time && $(CARGO) build --release
# cp -r $(BASEDIR)/deps/time/target/release/libtime*.rlib $(BUILDDIR)/libtime.rlib
# @touch $@
$(BUILDDIR)/.rust-regex:
cd $(BASEDIR)/deps/regex/regex_macros && $(CARGO) build --release
@ -247,7 +249,7 @@ $(BUILDDIR)/mkuutils: mkuutils.rs | $(BUILDDIR)
$(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs
cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-time $(BUILDDIR)/.rust-regex $(SRCDIR)/cksum/crc_table.rs
deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-regex $(SRCDIR)/cksum/crc_table.rs
crates:
echo $(EXES)

View file

@ -1,8 +1,11 @@
#![allow(unstable)]
use std::io::{File, Truncate, ReadWrite};
use std::os;
use std::path::Path;
static TEMPLATE: &'static str = "\
#![allow(unstable)]
extern crate @UTIL_CRATE@;
use std::os;

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::{File, Truncate, Write};
use std::os;
use std::path::Path;
@ -32,8 +34,8 @@ fn main() {
crates.push_str("extern crate uutest;\n");
util_map.push_str("map.insert(\"test\", uutest::uumain);\n");
}
"true" => util_map.push_str("fn uutrue(_: Vec<String>) -> int { 0 }\nmap.insert(\"true\", uutrue);\n"),
"false" => util_map.push_str("fn uufalse(_: Vec<String>) -> int { 1 }\nmap.insert(\"false\", uufalse);\n"),
"true" => util_map.push_str("fn uutrue(_: Vec<String>) -> isize { 0 }\nmap.insert(\"true\", uutrue);\n"),
"false" => util_map.push_str("fn uufalse(_: Vec<String>) -> isize { 1 }\nmap.insert(\"false\", uufalse);\n"),
"sync" => {
crates.push_str("extern crate uusync;\n");
util_map.push_str("map.insert(\"sync\", uusync::uumain);\n");

View file

@ -1,4 +1,5 @@
#![crate_name = "base64"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "basename"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,6 @@
#![crate_name = "cat"]
#![allow(unstable)]
#![feature(box_syntax, unsafe_destructor)]
/*
@ -91,7 +93,7 @@ enum NumberingMode {
fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
show_ends: bool) {
let mut line_counter: uint = 1;
let mut line_counter: usize = 1;
for path in files.iter() {
let (mut reader, interactive) = match open(path.as_slice()) {
@ -164,7 +166,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
show_ends: bool, show_nonprint: bool, show_tabs: bool) {
let mut line_counter: uint = 1;
let mut line_counter: usize = 1;
for path in files.iter() {
let (mut reader, interactive) = match open(path.as_slice()) {
@ -173,7 +175,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
};
// Flush all 1024 iterations.
let mut flush_counter = range(0u, 1024);
let mut flush_counter = range(0us, 1024);
let mut in_buf = [0; 1024 * 32];
let mut out_buf = [0; 1024 * 64];
@ -187,7 +189,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
for &byte in in_buf.slice_to(n).iter() {
if flush_counter.next().is_none() {
writer.possibly_flush();
flush_counter = range(0u, 1024);
flush_counter = range(0us, 1024);
}
if byte == '\n' as u8 {
if !at_line_start || !squeeze_blank {
@ -293,8 +295,8 @@ fn open(path: &str) -> Option<(Box<Reader>, bool)> {
struct UnsafeWriter<'a, W> {
inner: W,
buf: &'a mut [u8],
pos: uint,
threshold: uint,
pos: usize,
threshold: usize,
}
impl<'a, W: Writer> UnsafeWriter<'a, W> {

View file

@ -1,4 +1,5 @@
#![crate_name = "chmod"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -15,7 +16,7 @@
extern crate getopts;
extern crate libc;
extern crate regex;
#[plugin] extern crate regex_macros;
#[plugin] #[no_link] extern crate regex_macros;
use std::ffi::CString;
use std::io::fs;

View file

@ -1,4 +1,6 @@
#![crate_name = "chroot"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*

View file

@ -1,4 +1,5 @@
#![crate_name = "cksum"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -44,7 +45,7 @@ fn crc_final(mut crc: u32, mut length: usize) -> u32 {
#[inline]
fn cksum(fname: &str) -> IoResult<(u32, usize)> {
let mut crc = 0u32;
let mut size = 0u;
let mut size = 0us;
let mut stdin_buf;
let mut file_buf;

View file

@ -1,3 +1,3 @@
/* auto-generated (DO NOT EDIT) */
pub static CRC_TABLE: [u32; 256] = [0, 79764919, 159529838, 222504665, 319059676, 398814059, 445009330, 507990021, 638119352, 583659535, 797628118, 726387553, 890018660, 835552979, 1015980042, 944750013, 1276238704, 1221641927, 1167319070, 1095957929, 1595256236, 1540665371, 1452775106, 1381403509, 1780037320, 1859660671, 1671105958, 1733955601, 2031960084, 2111593891, 1889500026, 1952343757, 2552477408, 2632100695, 2443283854, 2506133561, 2334638140, 2414271883, 2191915858, 2254759653, 3190512472, 3135915759, 3081330742, 3009969537, 2905550212, 2850959411, 2762807018, 2691435357, 3560074640, 3505614887, 3719321342, 3648080713, 3342211916, 3287746299, 3467911202, 3396681109, 4063920168, 4143685023, 4223187782, 4286162673, 3779000052, 3858754371, 3904687514, 3967668269, 881225847, 809987520, 1023691545, 969234094, 662832811, 591600412, 771767749, 717299826, 311336399, 374308984, 453813921, 533576470, 25881363, 88864420, 134795389, 214552010, 2023205639, 2086057648, 1897238633, 1976864222, 1804852699, 1867694188, 1645340341, 1724971778, 1587496639, 1516133128, 1461550545, 1406951526, 1302016099, 1230646740, 1142491917, 1087903418, 2896545431, 2825181984, 2770861561, 2716262478, 3215044683, 3143675388, 3055782693, 3001194130, 2326604591, 2389456536, 2200899649, 2280525302, 2578013683, 2640855108, 2418763421, 2498394922, 3769900519, 3832873040, 3912640137, 3992402750, 4088425275, 4151408268, 4197601365, 4277358050, 3334271071, 3263032808, 3476998961, 3422541446, 3585640067, 3514407732, 3694837229, 3640369242, 1762451694, 1842216281, 1619975040, 1682949687, 2047383090, 2127137669, 1938468188, 2001449195, 1325665622, 1271206113, 1183200824, 1111960463, 1543535498, 1489069629, 1434599652, 1363369299, 622672798, 568075817, 748617968, 677256519, 907627842, 853037301, 1067152940, 995781531, 51762726, 131386257, 177728840, 240578815, 269590778, 349224269, 429104020, 491947555, 4046411278, 4126034873, 4172115296, 4234965207, 3794477266, 3874110821, 3953728444, 4016571915, 3609705398, 3555108353, 3735388376, 3664026991, 3290680682, 3236090077, 3449943556, 3378572211, 3174993278, 3120533705, 3032266256, 2961025959, 2923101090, 2868635157, 2813903052, 2742672763, 2604032198, 2683796849, 2461293480, 2524268063, 2284983834, 2364738477, 2175806836, 2238787779, 1569362073, 1498123566, 1409854455, 1355396672, 1317987909, 1246755826, 1192025387, 1137557660, 2072149281, 2135122070, 1912620623, 1992383480, 1753615357, 1816598090, 1627664531, 1707420964, 295390185, 358241886, 404320391, 483945776, 43990325, 106832002, 186451547, 266083308, 932423249, 861060070, 1041341759, 986742920, 613929101, 542559546, 756411363, 701822548, 3316196985, 3244833742, 3425377559, 3370778784, 3601682597, 3530312978, 3744426955, 3689838204, 3819031489, 3881883254, 3928223919, 4007849240, 4037393693, 4100235434, 4180117107, 4259748804, 2310601993, 2373574846, 2151335527, 2231098320, 2596047829, 2659030626, 2470359227, 2550115596, 2947551409, 2876312838, 2788305887, 2733848168, 3165939309, 3094707162, 3040238851, 2985771188];
pub static CRC_TABLE: [u32; 256] = [0u32, 79764919u32, 159529838u32, 222504665u32, 319059676u32, 398814059u32, 445009330u32, 507990021u32, 638119352u32, 583659535u32, 797628118u32, 726387553u32, 890018660u32, 835552979u32, 1015980042u32, 944750013u32, 1276238704u32, 1221641927u32, 1167319070u32, 1095957929u32, 1595256236u32, 1540665371u32, 1452775106u32, 1381403509u32, 1780037320u32, 1859660671u32, 1671105958u32, 1733955601u32, 2031960084u32, 2111593891u32, 1889500026u32, 1952343757u32, 2552477408u32, 2632100695u32, 2443283854u32, 2506133561u32, 2334638140u32, 2414271883u32, 2191915858u32, 2254759653u32, 3190512472u32, 3135915759u32, 3081330742u32, 3009969537u32, 2905550212u32, 2850959411u32, 2762807018u32, 2691435357u32, 3560074640u32, 3505614887u32, 3719321342u32, 3648080713u32, 3342211916u32, 3287746299u32, 3467911202u32, 3396681109u32, 4063920168u32, 4143685023u32, 4223187782u32, 4286162673u32, 3779000052u32, 3858754371u32, 3904687514u32, 3967668269u32, 881225847u32, 809987520u32, 1023691545u32, 969234094u32, 662832811u32, 591600412u32, 771767749u32, 717299826u32, 311336399u32, 374308984u32, 453813921u32, 533576470u32, 25881363u32, 88864420u32, 134795389u32, 214552010u32, 2023205639u32, 2086057648u32, 1897238633u32, 1976864222u32, 1804852699u32, 1867694188u32, 1645340341u32, 1724971778u32, 1587496639u32, 1516133128u32, 1461550545u32, 1406951526u32, 1302016099u32, 1230646740u32, 1142491917u32, 1087903418u32, 2896545431u32, 2825181984u32, 2770861561u32, 2716262478u32, 3215044683u32, 3143675388u32, 3055782693u32, 3001194130u32, 2326604591u32, 2389456536u32, 2200899649u32, 2280525302u32, 2578013683u32, 2640855108u32, 2418763421u32, 2498394922u32, 3769900519u32, 3832873040u32, 3912640137u32, 3992402750u32, 4088425275u32, 4151408268u32, 4197601365u32, 4277358050u32, 3334271071u32, 3263032808u32, 3476998961u32, 3422541446u32, 3585640067u32, 3514407732u32, 3694837229u32, 3640369242u32, 1762451694u32, 1842216281u32, 1619975040u32, 1682949687u32, 2047383090u32, 2127137669u32, 1938468188u32, 2001449195u32, 1325665622u32, 1271206113u32, 1183200824u32, 1111960463u32, 1543535498u32, 1489069629u32, 1434599652u32, 1363369299u32, 622672798u32, 568075817u32, 748617968u32, 677256519u32, 907627842u32, 853037301u32, 1067152940u32, 995781531u32, 51762726u32, 131386257u32, 177728840u32, 240578815u32, 269590778u32, 349224269u32, 429104020u32, 491947555u32, 4046411278u32, 4126034873u32, 4172115296u32, 4234965207u32, 3794477266u32, 3874110821u32, 3953728444u32, 4016571915u32, 3609705398u32, 3555108353u32, 3735388376u32, 3664026991u32, 3290680682u32, 3236090077u32, 3449943556u32, 3378572211u32, 3174993278u32, 3120533705u32, 3032266256u32, 2961025959u32, 2923101090u32, 2868635157u32, 2813903052u32, 2742672763u32, 2604032198u32, 2683796849u32, 2461293480u32, 2524268063u32, 2284983834u32, 2364738477u32, 2175806836u32, 2238787779u32, 1569362073u32, 1498123566u32, 1409854455u32, 1355396672u32, 1317987909u32, 1246755826u32, 1192025387u32, 1137557660u32, 2072149281u32, 2135122070u32, 1912620623u32, 1992383480u32, 1753615357u32, 1816598090u32, 1627664531u32, 1707420964u32, 295390185u32, 358241886u32, 404320391u32, 483945776u32, 43990325u32, 106832002u32, 186451547u32, 266083308u32, 932423249u32, 861060070u32, 1041341759u32, 986742920u32, 613929101u32, 542559546u32, 756411363u32, 701822548u32, 3316196985u32, 3244833742u32, 3425377559u32, 3370778784u32, 3601682597u32, 3530312978u32, 3744426955u32, 3689838204u32, 3819031489u32, 3881883254u32, 3928223919u32, 4007849240u32, 4037393693u32, 4100235434u32, 4180117107u32, 4259748804u32, 2310601993u32, 2373574846u32, 2151335527u32, 2231098320u32, 2596047829u32, 2659030626u32, 2470359227u32, 2550115596u32, 2947551409u32, 2876312838u32, 2788305887u32, 2733848168u32, 3165939309u32, 3094707162u32, 3040238851u32, 2985771188u32];

View file

@ -10,7 +10,7 @@
use std::io;
static CRC_TABLE_LEN: uint = 256;
static CRC_TABLE_LEN: usize = 256;
fn main() {
let mut table = Vec::with_capacity(CRC_TABLE_LEN);
@ -20,7 +20,7 @@ fn main() {
let mut file = io::File::open_mode(&Path::new("crc_table.rs"), io::Truncate, io::Write).unwrap();
let output = format!("/* auto-generated (DO NOT EDIT) */
pub static CRC_TABLE: [u32; {}] = {};", CRC_TABLE_LEN, table);
pub static CRC_TABLE: [u32; {}] = {:?};", CRC_TABLE_LEN, table);
file.write_line(output.as_slice()).unwrap();
}
@ -28,7 +28,7 @@ pub static CRC_TABLE: [u32; {}] = {};", CRC_TABLE_LEN, table);
fn crc_entry(input: u8) -> u32 {
let mut crc = (input as u32) << 24;
for _ in range(0u, 8) {
for _ in range(0, 8) {
if crc & 0x80000000 != 0 {
crc <<= 1;
crc ^= 0x04c11db7;

View file

@ -1,4 +1,5 @@
#![crate_name = "comm"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -9,10 +9,10 @@
#![allow(dead_code)]
pub static DEFAULT_SIGNAL:uint = 15;
pub static DEFAULT_SIGNAL:usize= 15;
pub struct Signal<'a> { pub name:&'a str, pub value: uint}
pub struct Signal<'a> { pub name:&'a str, pub value: usize}
/*
@ -139,7 +139,7 @@ pub static ALL_SIGNALS:[Signal<'static>; 31] = [
Signal{ name: "USR2", value:31 },
];
pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<uint> {
pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<usize> {
if signal_name_or_value == "0" {
return Some(0);
}
@ -153,6 +153,6 @@ pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<uint> {
}
#[inline(always)]
pub fn is_signal(num: uint) -> bool {
pub fn is_signal(num: usize) -> bool {
num < ALL_SIGNALS.len()
}

View file

@ -14,10 +14,10 @@ pub fn from_str(string: &str) -> Result<f64, String> {
}
let slice = string.slice_to(len - 1);
let (numstr, times) = match string.char_at(len - 1) {
's' | 'S' => (slice, 1u),
'm' | 'M' => (slice, 60u),
'h' | 'H' => (slice, 60u * 60),
'd' | 'D' => (slice, 60u * 60 * 24),
's' | 'S' => (slice, 1us),
'm' | 'M' => (slice, 60us),
'h' | 'H' => (slice, 60us * 60),
'd' | 'D' => (slice, 60us * 60 * 24),
val => {
if !val.is_alphabetic() {
(string, 1)

View file

@ -10,10 +10,10 @@ mod utmpx {
pub static DEFAULT_FILE: &'static str = "/var/run/utmp";
pub const UT_LINESIZE: uint = 32;
pub const UT_NAMESIZE: uint = 32;
pub const UT_IDSIZE: uint = 4;
pub const UT_HOSTSIZE: uint = 256;
pub const UT_LINESIZE: usize = 32;
pub const UT_NAMESIZE: usize = 32;
pub const UT_IDSIZE: usize = 4;
pub const UT_HOSTSIZE: usize = 256;
pub const EMPTY: libc::c_short = 0;
pub const RUN_LVL: libc::c_short = 1;
@ -56,10 +56,10 @@ mod utmpx {
pub static DEFAULT_FILE: &'static str = "/var/run/utmpx";
pub const UT_LINESIZE: uint = 32;
pub const UT_NAMESIZE: uint = 256;
pub const UT_IDSIZE: uint = 4;
pub const UT_HOSTSIZE: uint = 256;
pub const UT_LINESIZE: usize = 32;
pub const UT_NAMESIZE: usize = 256;
pub const UT_IDSIZE: usize = 4;
pub const UT_HOSTSIZE: usize = 256;
pub const EMPTY: libc::c_short = 0;
pub const RUN_LVL: libc::c_short = 1;
@ -97,10 +97,10 @@ mod utmpx {
pub static DEFAULT_FILE : &'static str = "";
pub const UT_LINESIZE : uint = 16;
pub const UT_NAMESIZE : uint = 32;
pub const UT_IDSIZE : uint = 8;
pub const UT_HOSTSIZE : uint = 128;
pub const UT_LINESIZE : usize = 16;
pub const UT_NAMESIZE : usize = 32;
pub const UT_IDSIZE : usize = 8;
pub const UT_HOSTSIZE : usize = 128;
pub const EMPTY : libc::c_short = 0;
pub const BOOT_TIME : libc::c_short = 1;

View file

@ -1,4 +1,5 @@
#![crate_name = "cp"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -4,14 +4,14 @@ use std::io::{IoResult, IoError};
pub struct BufReader<R> {
reader: R,
buffer: [u8; 4096],
start: uint,
end: uint, // exclusive
start: usize,
end: usize, // exclusive
}
#[allow(non_snake_case)]
pub mod Bytes {
pub trait Select {
fn select<'a>(&'a mut self, bytes: uint) -> Selected<'a>;
fn select<'a>(&'a mut self, bytes: usize) -> Selected<'a>;
}
pub enum Selected<'a> {
@ -37,7 +37,7 @@ impl<R: Reader> BufReader<R> {
}
#[inline]
fn read(&mut self) -> IoResult<uint> {
fn read(&mut self) -> IoResult<usize> {
let buffer_fill = self.buffer.slice_from_mut(self.end);
match self.reader.read(buffer_fill) {
@ -50,7 +50,7 @@ impl<R: Reader> BufReader<R> {
}
#[inline]
fn maybe_fill_buf(&mut self) -> IoResult<uint> {
fn maybe_fill_buf(&mut self) -> IoResult<usize> {
if self.end == self.start {
self.start = 0;
self.end = 0;
@ -61,7 +61,7 @@ impl<R: Reader> BufReader<R> {
}
}
pub fn consume_line(&mut self) -> uint {
pub fn consume_line(&mut self) -> usize {
let mut bytes_consumed = 0;
loop {
@ -91,7 +91,7 @@ impl<R: Reader> BufReader<R> {
}
impl<R: Reader> Bytes::Select for BufReader<R> {
fn select<'a>(&'a mut self, bytes: uint) -> Bytes::Selected<'a> {
fn select<'a>(&'a mut self, bytes: usize) -> Bytes::Selected<'a> {
match self.maybe_fill_buf() {
Err(IoError { kind: std::io::EndOfFile, .. }) => (),
Err(err) => panic!("read error: {}", err.desc),

View file

@ -1,4 +1,5 @@
#![crate_name = "cut"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -53,7 +54,7 @@ fn list_to_ranges(list: &str, complement: bool) -> Result<Vec<Range>, String> {
fn cut_bytes<R: Reader>(reader: R,
ranges: &Vec<Range>,
opts: &Options) -> int {
opts: &Options) -> isize {
use buffer::Bytes::Select;
use buffer::Bytes::Selected::{NewlineFound, Complete, Partial, EndOfFile};
@ -134,7 +135,7 @@ fn cut_bytes<R: Reader>(reader: R,
fn cut_characters<R: Reader>(reader: R,
ranges: &Vec<Range>,
opts: &Options) -> int {
opts: &Options) -> isize {
let mut buf_in = BufferedReader::new(reader);
let mut out = BufferedWriter::new(stdio::stdout_raw());
@ -195,7 +196,7 @@ fn cut_characters<R: Reader>(reader: R,
struct Searcher<'a> {
haystack: &'a [u8],
needle: &'a [u8],
position: uint
position: usize
}
impl<'a> Searcher<'a> {
@ -209,9 +210,9 @@ impl<'a> Searcher<'a> {
}
impl<'a> Iterator for Searcher<'a> {
type Item = (uint, uint);
type Item = (usize, usize);
fn next(&mut self) -> Option<(uint, uint)> {
fn next(&mut self) -> Option<(usize, usize)> {
if self.needle.len() == 1 {
for offset in range(self.position, self.haystack.len()) {
if self.haystack[offset] == self.needle[0] {
@ -242,7 +243,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
ranges: &Vec<Range>,
delim: &String,
only_delimited: bool,
out_delim: &String) -> int {
out_delim: &String) -> isize {
let mut buf_in = BufferedReader::new(reader);
let mut out = BufferedWriter::new(stdio::stdout_raw());
@ -316,7 +317,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
fn cut_fields<R: Reader>(reader: R,
ranges: &Vec<Range>,
opts: &FieldOptions) -> int {
opts: &FieldOptions) -> isize {
match opts.out_delimeter {
Some(ref delim) => {
return cut_fields_delimiter(reader, ranges, &opts.delimiter,
@ -395,7 +396,7 @@ fn cut_fields<R: Reader>(reader: R,
0
}
fn cut_files(mut filenames: Vec<String>, mode: Mode) -> int {
fn cut_files(mut filenames: Vec<String>, mode: Mode) -> isize {
let mut stdin_read = false;
let mut exit_code = 0;

View file

@ -11,31 +11,31 @@ use std;
#[derive(PartialEq,Eq,PartialOrd,Ord,Show)]
pub struct Range {
pub low: uint,
pub high: uint,
pub low: usize,
pub high: usize,
}
impl std::str::FromStr for Range {
fn from_str(s: &str) -> Option<Range> {
use std::uint::MAX;
use std::usize::MAX;
let mut parts = s.splitn(1, '-');
match (parts.next(), parts.next()) {
(Some(nm), None) => {
nm.parse::<uint>().and_then(|nm| if nm > 0 { Some(nm) } else { None })
nm.parse::<usize>().and_then(|nm| if nm > 0 { Some(nm) } else { None })
.map(|nm| Range { low: nm, high: nm })
}
(Some(n), Some(m)) if m.len() == 0 => {
n.parse::<uint>().and_then(|low| if low > 0 { Some(low) } else { None })
n.parse::<usize>().and_then(|low| if low > 0 { Some(low) } else { None })
.map(|low| Range { low: low, high: MAX })
}
(Some(n), Some(m)) if n.len() == 0 => {
m.parse::<uint>().and_then(|high| if high >= 1 { Some(high) } else { None })
m.parse::<usize>().and_then(|high| if high >= 1 { Some(high) } else { None })
.map(|high| Range { low: 1, high: high })
}
(Some(n), Some(m)) => {
match (n.parse::<uint>(), m.parse::<uint>()) {
match (n.parse::<usize>(), m.parse::<usize>()) {
(Some(low), Some(high)) if low > 0 && low <= high => {
Some(Range { low: low, high: high })
}
@ -77,7 +77,7 @@ impl Range {
}
pub fn complement(ranges: &Vec<Range>) -> Vec<Range> {
use std::uint;
use std::usize;
let mut complements = Vec::with_capacity(ranges.len() + 1);
@ -97,10 +97,10 @@ pub fn complement(ranges: &Vec<Range>) -> Vec<Range> {
}
}
(Some(last), None) => {
if last.high < uint::MAX {
if last.high < usize::MAX {
complements.push(Range {
low: last.high + 1,
high: uint::MAX
high: usize::MAX
});
}
}

View file

@ -1,4 +1,5 @@
#![crate_name = "dirname"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "du"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -32,7 +33,7 @@ static VERSION: &'static str = "1.0.0";
struct Options {
all: bool,
program_name: String,
max_depth: Option<uint>,
max_depth: Option<usize>,
total: bool,
separate_dirs: bool,
}
@ -43,7 +44,7 @@ struct Stat {
}
// this takes `my_stat` to avoid having to stat files multiple times.
fn du(path: &Path, mut my_stat: Stat,
options: Arc<Options>, depth: uint) -> Vec<Arc<Stat>> {
options: Arc<Options>, depth: usize) -> Vec<Arc<Stat>> {
let mut stats = vec!();
let mut futures = vec!();
@ -193,7 +194,7 @@ ers of 1000).",
let summarize = matches.opt_present("summarize");
let max_depth_str = matches.opt_str("max-depth");
let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::<uint>());
let max_depth = max_depth_str.as_ref().and_then(|s| s.parse::<usize>());
match (max_depth_str, max_depth) {
(Some(ref s), _) if summarize => {
show_error!("summarizing conflicts with --max-depth={}", *s);
@ -245,7 +246,7 @@ ers of 1000).",
letters.push(c);
}
}
let number = numbers.parse::<uint>().unwrap();
let number = numbers.parse::<usize>().unwrap();
let multiple = match letters.as_slice() {
"K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024,
"T" => 1024 * 1024 * 1024 * 1024, "P" => 1024 * 1024 * 1024 * 1024 * 1024,

View file

@ -1,4 +1,5 @@
#![crate_name = "echo"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -30,8 +31,8 @@ struct EchoOptions {
}
#[inline(always)]
fn to_char(bytes: &Vec<u8>, base: uint) -> char {
from_str_radix::<uint>(from_utf8(bytes.as_slice()).unwrap(), base).unwrap() as u8 as char
fn to_char(bytes: &Vec<u8>, base: usize) -> char {
from_str_radix::<usize>(from_utf8(bytes.as_slice()).unwrap(), base).unwrap() as u8 as char
}
#[inline(always)]
@ -51,19 +52,19 @@ fn isodigit(c: u8) -> bool {
}
}
fn convert_str(string: &[u8], index: uint, base: uint) -> (char, uint) {
let (max_digits, is_legal_digit) : (uint, fn(u8) -> bool) = match base {
8u => (3, isodigit),
16u => (2, isxdigit),
fn convert_str(string: &[u8], index: usize, base: usize) -> (char, usize) {
let (max_digits, is_legal_digit) : (usize, fn(u8) -> bool) = match base {
8us => (3, isodigit),
16us => (2, isxdigit),
_ => panic!(),
};
let mut bytes = vec!();
for offset in range(0u, max_digits) {
if string.len() <= index + offset as uint {
for offset in range(0us, max_digits) {
if string.len() <= index + offset as usize {
break;
}
let c = string[index + offset as uint];
let c = string[index + offset as usize];
if is_legal_digit(c) {
bytes.push(c as u8);
} else {
@ -201,7 +202,7 @@ pub fn uumain(args: Vec<String>) -> isize {
't' => print!("\t"),
'v' => print!("\x0B"),
'x' => {
let (c, num_char_used) = convert_str(string.as_bytes(), index + 1, 16u);
let (c, num_char_used) = convert_str(string.as_bytes(), index + 1, 16us);
if num_char_used == 0 {
print!("\\x");
} else {
@ -212,7 +213,7 @@ pub fn uumain(args: Vec<String>) -> isize {
}
},
'0' => {
let (c, num_char_used) = convert_str(string.as_bytes(), index + 1, 8u);
let (c, num_char_used) = convert_str(string.as_bytes(), index + 1, 8us);
if num_char_used == 0 {
print!("\0");
} else {
@ -223,7 +224,7 @@ pub fn uumain(args: Vec<String>) -> isize {
}
}
_ => {
let (esc_c, num_char_used) = convert_str(string.as_bytes(), index, 8u);
let (esc_c, num_char_used) = convert_str(string.as_bytes(), index, 8us);
if num_char_used == 0 {
print!("\\{}", c);
} else {

2
src/env/env.rs vendored
View file

@ -1,4 +1,5 @@
#![crate_name = "env"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -12,6 +13,7 @@
/* last synced with: env (GNU coreutils) 8.13 */
#![allow(non_camel_case_types)]
#![feature(box_syntax)]
struct options {
ignore_env: bool,

View file

@ -1,4 +1,5 @@
#![crate_name = "expand"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -9,6 +10,8 @@
* file that was distributed with this source code.
*/
#![feature(box_syntax)]
extern crate getopts;
extern crate libc;
@ -22,17 +25,17 @@ mod util;
static NAME: &'static str = "expand";
static VERSION: &'static str = "0.0.1";
static DEFAULT_TABSTOP: uint = 8;
static DEFAULT_TABSTOP: usize = 8;
fn tabstops_parse(s: String) -> Vec<uint> {
fn tabstops_parse(s: String) -> Vec<usize> {
let words = s.as_slice().split(',').collect::<Vec<&str>>();
let nums = words.into_iter()
.map(|sn| sn.parse::<uint>()
.map(|sn| sn.parse::<usize>()
.unwrap_or_else(
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
)
.collect::<Vec<uint>>();
.collect::<Vec<usize>>();
if nums.iter().any(|&n| n == 0) {
crash!(1, "{}\n", "tab size cannot be 0");
@ -48,7 +51,7 @@ fn tabstops_parse(s: String) -> Vec<uint> {
struct Options {
files: Vec<String>,
tabstops: Vec<uint>,
tabstops: Vec<usize>,
iflag: bool
}
@ -117,7 +120,7 @@ fn open(path: String) -> io::BufferedReader<Box<Reader+'static>> {
}
}
fn to_next_stop(tabstops: &[uint], col: uint) -> uint {
fn to_next_stop(tabstops: &[usize], col: usize) -> usize {
match tabstops.as_slice() {
[tabstop] => tabstop - col % tabstop,
tabstops => match tabstops.iter().skip_while(|&t| *t <= col).next() {

View file

@ -1,4 +1,5 @@
#![crate_name = "factor"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "uufalse"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,6 @@
#![crate_name = "fmt"]
#![allow(unstable)]
/*
* This file is part of `fmt` from the uutils coreutils package.
*
@ -8,8 +10,11 @@
* file that was distributed with this source code.
*/
#![feature(box_syntax)]
extern crate core;
extern crate getopts;
extern crate unicode;
use std::cmp;
use std::io::{BufferedReader, BufferedWriter, File, IoResult};
@ -49,9 +54,9 @@ struct FmtOptions {
xanti_prefix : bool,
uniform : bool,
quick : bool,
width : uint,
goal : uint,
tabwidth : uint,
width : usize,
goal : usize,
tabwidth : usize,
}
pub fn uumain(args: Vec<String>) -> isize {
@ -140,7 +145,7 @@ pub fn uumain(args: Vec<String>) -> isize {
match matches.opt_str("w") {
Some(s) => {
fmt_opts.width =
match s.parse::<uint>() {
match s.parse::<usize>() {
Some(t) => t,
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
};
@ -152,7 +157,7 @@ pub fn uumain(args: Vec<String>) -> isize {
match matches.opt_str("g") {
Some(s) => {
fmt_opts.goal =
match s.parse::<uint>() {
match s.parse::<usize>() {
Some(t) => t,
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
};
@ -168,7 +173,7 @@ pub fn uumain(args: Vec<String>) -> isize {
match matches.opt_str("T") {
Some(s) => {
fmt_opts.tabwidth =
match s.parse::<uint>() {
match s.parse::<usize>() {
Some(t) => t,
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
};

View file

@ -16,16 +16,16 @@ use std::mem;
struct BreakArgs<'a> {
opts : &'a FmtOptions,
init_len : uint,
init_len : usize,
indent_str : &'a str,
indent_len : uint,
indent_len : usize,
uniform : bool,
ostream : &'a mut Box<Writer+'static>
}
impl<'a> BreakArgs<'a> {
#[inline(always)]
fn compute_width<'b>(&self, winfo: &WordInfo<'b>, posn: uint, fresh: bool) -> uint {
fn compute_width<'b>(&self, winfo: &WordInfo<'b>, posn: usize, fresh: bool) -> usize {
if fresh {
0
} else {
@ -94,13 +94,13 @@ pub fn break_lines(para: &Paragraph, opts: &FmtOptions, ostream: &mut Box<Writer
// break_simple implements a "greedy" breaking algorithm: print words until
// maxlength would be exceeded, then print a linebreak and indent and continue.
fn break_simple<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &mut BreakArgs<'a>) {
fn break_simple<'a, T: Iterator<Item=&'a WordInfo<'a>>>(iter: T, args: &mut BreakArgs<'a>) {
iter.fold((args.init_len, false), |l, winfo| accum_words_simple(args, l, winfo));
silent_unwrap!(args.ostream.write_char('\n'));
}
#[inline(always)]
fn accum_words_simple<'a>(args: &mut BreakArgs<'a>, (l, prev_punct): (uint, bool), winfo: &'a WordInfo<'a>) -> (uint, bool) {
fn accum_words_simple<'a>(args: &mut BreakArgs<'a>, (l, prev_punct): (usize, bool), winfo: &'a WordInfo<'a>) -> (usize, bool) {
// compute the length of this word, considering how tabs will expand at this position on the line
let wlen = winfo.word_nchars + args.compute_width(winfo, l, false);
@ -120,7 +120,7 @@ fn accum_words_simple<'a>(args: &mut BreakArgs<'a>, (l, prev_punct): (uint, bool
// Knuth, D.E., and Plass, M.F. "Breaking Paragraphs into Lines." in Software,
// Practice and Experience. Vol. 11, No. 11, November 1981.
// http://onlinelibrary.wiley.com/doi/10.1002/spe.4380111102/pdf
fn break_knuth_plass<'a, T: Clone + Iterator<&'a WordInfo<'a>>>(mut iter: T, args: &mut BreakArgs<'a>) {
fn break_knuth_plass<'a, T: Clone + Iterator<Item=&'a WordInfo<'a>>>(mut iter: T, args: &mut BreakArgs<'a>) {
// run the algorithm to get the breakpoints
let breakpoints = find_kp_breakpoints(iter.clone(), args);
@ -174,16 +174,16 @@ fn break_knuth_plass<'a, T: Clone + Iterator<&'a WordInfo<'a>>>(mut iter: T, arg
}
struct LineBreak<'a> {
prev : uint,
prev : usize,
linebreak : Option<&'a WordInfo<'a>>,
break_before : bool,
demerits : i64,
prev_rat : f32,
length : uint,
length : usize,
fresh : bool
}
fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakArgs<'a>) -> Vec<(&'a WordInfo<'a>, bool)> {
fn find_kp_breakpoints<'a, T: Iterator<Item=&'a WordInfo<'a>>>(iter: T, args: &BreakArgs<'a>) -> Vec<(&'a WordInfo<'a>, bool)> {
let mut iter = iter.peekable();
// set up the initial null linebreak
let mut linebreaks = vec!(LineBreak {
@ -199,8 +199,8 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
let active_breaks = &mut vec!(0);
let next_active_breaks = &mut vec!();
let stretch = (args.opts.width - args.opts.goal) as int;
let minlength = args.opts.goal - stretch as uint;
let stretch = (args.opts.width - args.opts.goal) as isize;
let minlength = args.opts.goal - stretch as usize;
let mut new_linebreaks = vec!();
let mut is_sentence_start = false;
let mut least_demerits = 0;
@ -256,7 +256,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
// there is no penalty for the final line's length
(0, 0.0)
} else {
compute_demerits((args.opts.goal - tlen) as int, stretch, w.word_nchars as int, active.prev_rat)
compute_demerits((args.opts.goal - tlen) as isize, stretch, w.word_nchars as isize, active.prev_rat)
};
// do not even consider adding a line that has too many demerits
@ -311,7 +311,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
}
#[inline(always)]
fn build_best_path<'a>(paths: &Vec<LineBreak<'a>>, active: &Vec<uint>) -> Vec<(&'a WordInfo<'a>, bool)> {
fn build_best_path<'a>(paths: &Vec<LineBreak<'a>>, active: &Vec<usize>) -> Vec<(&'a WordInfo<'a>, bool)> {
let mut breakwords = vec!();
// of the active paths, we select the one with the fewest demerits
let mut best_idx = match active.iter().min_by(|&&a| paths[a].demerits) {
@ -344,7 +344,7 @@ const DR_MULT: f32 = 600.0;
const DL_MULT: f32 = 300.0;
#[inline(always)]
fn compute_demerits(delta_len: int, stretch: int, wlen: int, prev_rat: f32) -> (i64, f32) {
fn compute_demerits(delta_len: isize, stretch: isize, wlen: isize, prev_rat: f32) -> (i64, f32) {
// how much stretch are we using?
let ratio =
if delta_len == 0 {
@ -378,7 +378,7 @@ fn compute_demerits(delta_len: int, stretch: int, wlen: int, prev_rat: f32) -> (
}
#[inline(always)]
fn restart_active_breaks<'a>(args: &BreakArgs<'a>, active: &LineBreak<'a>, act_idx: uint, w: &'a WordInfo<'a>, slen: uint, min: uint) -> LineBreak<'a> {
fn restart_active_breaks<'a>(args: &BreakArgs<'a>, active: &LineBreak<'a>, act_idx: usize, w: &'a WordInfo<'a>, slen: usize, min: usize) -> LineBreak<'a> {
let (break_before, line_length) =
if active.fresh {
// never break before a word if that word would be the first on a line
@ -386,8 +386,8 @@ fn restart_active_breaks<'a>(args: &BreakArgs<'a>, active: &LineBreak<'a>, act_i
} else {
// choose the lesser evil: breaking too early, or breaking too late
let wlen = w.word_nchars + args.compute_width(w, active.length, active.fresh);
let underlen: int = (min - active.length) as int;
let overlen: int = ((wlen + slen + active.length) - args.opts.width) as int;
let underlen = (min - active.length) as isize;
let overlen = ((wlen + slen + active.length) - args.opts.width) as isize;
if overlen > underlen {
// break early, put this word on the next line
(true, args.indent_len + w.word_nchars)
@ -410,7 +410,7 @@ fn restart_active_breaks<'a>(args: &BreakArgs<'a>, active: &LineBreak<'a>, act_i
// Number of spaces to add before a word, based on mode, newline, sentence start.
#[inline(always)]
fn compute_slen(uniform: bool, newline: bool, start: bool, punct: bool) -> uint {
fn compute_slen(uniform: bool, newline: bool, start: bool, punct: bool) -> usize {
if uniform || newline {
if start || (newline && punct) {
2
@ -425,7 +425,7 @@ fn compute_slen(uniform: bool, newline: bool, start: bool, punct: bool) -> uint
// If we're on a fresh line, slen=0 and we slice off leading whitespace.
// Otherwise, compute slen and leave whitespace alone.
#[inline(always)]
fn slice_if_fresh<'a>(fresh: bool, word: &'a str, start: uint, uniform: bool, newline: bool, sstart: bool, punct: bool) -> (uint, &'a str) {
fn slice_if_fresh<'a>(fresh: bool, word: &'a str, start: usize, uniform: bool, newline: bool, sstart: bool, punct: bool) -> (usize, &'a str) {
if fresh {
(0, word.slice_from(start))
} else {
@ -442,7 +442,7 @@ fn write_newline(indent: &str, ostream: &mut Box<Writer>) {
// Write the word, along with slen spaces.
#[inline(always)]
fn write_with_spaces(word: &str, slen: uint, ostream: &mut Box<Writer>) {
fn write_with_spaces(word: &str, slen: usize, ostream: &mut Box<Writer>) {
if slen == 2 {
silent_unwrap!(ostream.write(" ".as_bytes()));
} else if slen == 1 {

View file

@ -11,12 +11,13 @@ use core::iter::Peekable;
use std::io::Lines;
use std::slice::Iter;
use std::str::CharRange;
use unicode::str::UnicodeStr;
use FileOrStdReader;
use FmtOptions;
#[inline(always)]
fn char_width(c: char) -> uint {
if (c as uint) < 0xA0 {
fn char_width(c: char) -> usize {
if (c as usize) < 0xA0 {
// if it is ASCII, call it exactly 1 wide (including control chars)
// calling control chars' widths 1 is consistent with OpenBSD fmt
1
@ -59,10 +60,10 @@ impl Line {
#[derive(Show)]
struct FileLine {
line : String,
indent_end : uint, // the end of the indent, always the start of the text
pfxind_end : uint, // the end of the PREFIX's indent, that is, the spaces before the prefix
indent_len : uint, // display length of indent taking into account tabs
prefix_len : uint, // PREFIX indent length taking into account tabs
indent_end : usize, // the end of the indent, always the start of the text
pfxind_end : usize, // the end of the PREFIX's indent, that is, the spaces before the prefix
indent_len : usize, // display length of indent taking into account tabs
prefix_len : usize, // PREFIX indent length taking into account tabs
}
// iterator that produces a stream of Lines from a file
@ -77,8 +78,8 @@ impl<'a> FileLines<'a> {
}
// returns true if this line should be formatted
fn match_prefix(&self, line: &str) -> (bool, uint) {
if !self.opts.use_prefix { return (true, 0u); }
fn match_prefix(&self, line: &str) -> (bool, usize) {
if !self.opts.use_prefix { return (true, 0); }
FileLines::match_prefix_generic(self.opts.prefix.as_slice(), line, self.opts.xprefix)
}
@ -93,14 +94,14 @@ impl<'a> FileLines<'a> {
}
}
fn match_prefix_generic(pfx: &str, line: &str, exact: bool) -> (bool, uint) {
fn match_prefix_generic(pfx: &str, line: &str, exact: bool) -> (bool, usize) {
if line.starts_with(pfx) {
return (true, 0);
}
if !exact {
// we do it this way rather than byte indexing to support unicode whitespace chars
let mut i = 0u;
let mut i = 0;
while (i < line.len()) && line.char_at(i).is_whitespace() {
i = match line.char_range_at(i) { CharRange { ch: _ , next: nxi } => nxi };
if line.slice_from(i).starts_with(pfx) {
@ -112,7 +113,7 @@ impl<'a> FileLines<'a> {
(false, 0)
}
fn compute_indent(&self, string: &str, prefix_end: uint) -> (uint, uint, uint) {
fn compute_indent(&self, string: &str, prefix_end: usize) -> (usize, usize, usize) {
let mut prefix_len = 0;
let mut indent_len = 0;
let mut indent_end = 0;
@ -138,7 +139,9 @@ impl<'a> FileLines<'a> {
}
}
impl<'a> Iterator<Line> for FileLines<'a> {
impl<'a> Iterator for FileLines<'a> {
type Item = Line;
fn next(&mut self) -> Option<Line> {
let n =
match self.lines.next() {
@ -199,11 +202,11 @@ impl<'a> Iterator<Line> for FileLines<'a> {
pub struct Paragraph {
lines : Vec<String>, // the lines of the file
pub init_str : String, // string representing the init, that is, the first line's indent
pub init_len : uint, // printable length of the init string considering TABWIDTH
init_end : uint, // byte location of end of init in first line String
pub init_len : usize, // printable length of the init string considering TABWIDTH
init_end : usize, // byte location of end of init in first line String
pub indent_str : String, // string representing indent
pub indent_len : uint, // length of above
indent_end : uint, // byte location of end of indent (in crown and tagged mode, only applies to 2nd line and onward)
pub indent_len : usize, // length of above
indent_end : usize, // byte location of end of indent (in crown and tagged mode, only applies to 2nd line and onward)
pub mail_header : bool // we need to know if this is a mail header because we do word splitting differently in that case
}
@ -243,7 +246,7 @@ impl<'a> ParagraphStream<'a> {
// header field must be nonzero length
if colon_posn == 0 { return false; }
return l_slice.slice_to(colon_posn).chars().all(|x| match x as uint {
return l_slice.slice_to(colon_posn).chars().all(|x| match x as usize {
y if y < 33 || y > 126 => false,
_ => true
});
@ -252,7 +255,9 @@ impl<'a> ParagraphStream<'a> {
}
}
impl<'a> Iterator<Result<Paragraph, String>> for ParagraphStream<'a> {
impl<'a> Iterator for ParagraphStream<'a> {
type Item = Result<Paragraph, String>;
fn next(&mut self) -> Option<Result<Paragraph, String>> {
// return a NoFormatLine in an Err; it should immediately be output
let noformat =
@ -410,7 +415,7 @@ impl<'a> ParaWords<'a> {
// no extra spacing for mail headers; always exactly 1 space
// safe to trim_left on every line of a mail header, since the
// first line is guaranteed not to have any spaces
self.words.extend(self.para.lines.iter().flat_map(|x| x.as_slice().words()).map(|x| WordInfo {
self.words.extend(self.para.lines.iter().flat_map(|x| StrExt::words(x.as_slice())).map(|x| WordInfo {
word : x,
word_start : 0,
word_nchars : x.len(), // OK for mail headers; only ASCII allowed (unicode is escaped)
@ -446,13 +451,13 @@ impl<'a> ParaWords<'a> {
struct WordSplit<'a> {
opts : &'a FmtOptions,
string : &'a str,
length : uint,
position : uint,
length : usize,
position : usize,
prev_punct : bool
}
impl<'a> WordSplit<'a> {
fn analyze_tabs(&self, string: &str) -> (Option<uint>, uint, Option<uint>) {
fn analyze_tabs(&self, string: &str) -> (Option<usize>, usize, Option<usize>) {
// given a string, determine (length before tab) and (printed length after first tab)
// if there are no tabs, beforetab = -1 and aftertab is the printed length
let mut beforetab = None;
@ -480,7 +485,7 @@ impl<'a> WordSplit<'a> {
impl<'a> WordSplit<'a> {
fn new<'b>(opts: &'b FmtOptions, string: &'b str) -> WordSplit<'b> {
// wordsplits *must* start at a non-whitespace character
let trim_string = string.trim_left();
let trim_string = StrExt::trim_left(string);
WordSplit { opts: opts, string: trim_string, length: string.len(), position: 0, prev_punct: false }
}
@ -494,17 +499,19 @@ impl<'a> WordSplit<'a> {
pub struct WordInfo<'a> {
pub word : &'a str,
pub word_start : uint,
pub word_nchars : uint,
pub before_tab : Option<uint>,
pub after_tab : uint,
pub word_start : usize,
pub word_nchars : usize,
pub before_tab : Option<usize>,
pub after_tab : usize,
pub sentence_start : bool,
pub ends_punct : bool,
pub new_line : bool
}
// returns (&str, is_start_of_sentence)
impl<'a> Iterator<WordInfo<'a>> for WordSplit<'a> {
impl<'a> Iterator for WordSplit<'a> {
type Item = WordInfo<'a>;
fn next(&mut self) -> Option<WordInfo<'a>> {
if self.position >= self.length {
return None

View file

@ -1,4 +1,5 @@
#![crate_name = "fold"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -62,7 +63,7 @@ pub fn uumain(args: Vec<String>) -> isize {
}
};
let width = match poss_width {
Some(inp_width) => match inp_width.parse::<uint>() {
Some(inp_width) => match inp_width.parse::<usize>() {
Some(width) => width,
None => crash!(1, "illegal width value (\"{}\")", inp_width)
},
@ -91,7 +92,7 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
}
#[inline]
fn fold(filenames: Vec<String>, bytes: bool, spaces: bool, width: uint) {
fn fold(filenames: Vec<String>, bytes: bool, spaces: bool, width: usize) {
for filename in filenames.iter() {
let filename: &str = filename.as_slice();
let mut stdin_buf;
@ -110,7 +111,7 @@ fn fold(filenames: Vec<String>, bytes: bool, spaces: bool, width: uint) {
}
#[inline]
fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool, width: uint) {
fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool, width: usize) {
let mut file = file;
for line in file.lines() {
let line_string = safe_unwrap!(line);
@ -156,7 +157,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
match rfind_whitespace(slice) {
Some(m) => {
let routput = slice.slice_chars(m + 1, slice.chars().count());
let ncount = routput.chars().fold(0u, |out, ch: char| {
let ncount = routput.chars().fold(0us, |out, ch: char| {
out + match ch {
'\t' => 8,
'\x08' => if out > 0 { -1 } else { 0 },
@ -215,7 +216,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
}
#[inline]
fn rfind_whitespace(slice: &str) -> Option<uint> {
fn rfind_whitespace(slice: &str) -> Option<usize> {
for (i, ch) in slice.chars().rev().enumerate() {
if ch.is_whitespace() {
return Some(slice.chars().count() - (i + 1));

View file

@ -1,4 +1,6 @@
#![crate_name = "groups"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*

View file

@ -1,4 +1,5 @@
#![crate_name = "hashsum"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,6 @@
#![crate_name = "head"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*
@ -27,8 +29,8 @@ mod util;
static NAME: &'static str = "head";
pub fn uumain(args: Vec<String>) -> isize {
let mut line_count = 10u;
let mut byte_count = 0u;
let mut line_count = 10us;
let mut byte_count = 0us;
// handle obsolete -number syntax
let options = match obsolete(args.tail()) {
@ -68,7 +70,7 @@ pub fn uumain(args: Vec<String>) -> isize {
show_error!("cannot specify both --bytes and --lines.");
return 1;
}
match n.parse::<uint>() {
match n.parse::<usize>() {
Some(m) => { line_count = m }
None => {
show_error!("invalid line count '{}'", n);
@ -77,7 +79,7 @@ pub fn uumain(args: Vec<String>) -> isize {
}
}
None => match given_options.opt_str("c") {
Some(count) => match count.parse::<uint>() {
Some(count) => match count.parse::<usize>() {
Some(m) => byte_count = m,
None => {
show_error!("invalid byte count '{}'", count);
@ -131,7 +133,7 @@ pub fn uumain(args: Vec<String>) -> isize {
//
// In case is found, the options vector will get rid of that object so that
// getopts works correctly.
fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
let mut options: Vec<String> = options.to_vec();
let mut a = 0;
let b = options.len();
@ -149,7 +151,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
// If this is the last number
if pos == len - 1 {
options.remove(a);
let number: Option<uint> = from_utf8(current.slice(1,len)).unwrap().parse::<uint>();
let number: Option<usize> = from_utf8(current.slice(1,len)).unwrap().parse::<usize>();
return (options, Some(number.unwrap()));
}
}
@ -162,7 +164,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
}
// TODO: handle errors on read
fn head<T: Reader>(reader: &mut BufferedReader<T>, count: uint, use_bytes: bool) -> bool {
fn head<T: Reader>(reader: &mut BufferedReader<T>, count: usize, use_bytes: bool) -> bool {
if use_bytes {
for byte in reader.bytes().take(count) {
if !pipe_print!("{}", byte.unwrap() as char) {

View file

@ -1,4 +1,5 @@
#![crate_name = "hostid"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -33,7 +34,7 @@ mod util;
static NAME: &'static str = "hostid";
static VERSION: &'static str = "0.0.1";
static EXIT_ERR: int = 1;
static EXIT_ERR: isize = 1;
pub enum Mode {
HostId,

View file

@ -1,4 +1,6 @@
#![crate_name = "hostname"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*
@ -130,7 +132,7 @@ fn help_menu(program: &str, options: &[getopts::OptGroup]) {
}
fn xgethostname() -> String {
let namelen = 256u;
let namelen = 256us;
let mut name : Vec<u8> = repeat(0).take(namelen).collect();
let err = unsafe {
gethostname (name.as_mut_ptr() as *mut libc::c_char,

View file

@ -1,4 +1,5 @@
#![crate_name = "id"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "kill"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -39,8 +40,8 @@ mod signals;
static NAME: &'static str = "kill";
static VERSION: &'static str = "0.0.1";
static EXIT_OK: int = 0;
static EXIT_ERR: int = 1;
static EXIT_OK: isize = 0;
static EXIT_ERR: isize = 1;
pub enum Mode {
Kill,
@ -184,7 +185,7 @@ fn help(progname: &str, usage: &str) {
println!("{}", get_help_text(progname, usage));
}
fn kill(signalname: &str, pids: std::vec::Vec<String>) -> int {
fn kill(signalname: &str, pids: std::vec::Vec<String>) -> isize {
let mut status = 0;
let optional_signal_value = signals::signal_by_name_or_value(signalname);
let signal_value = match optional_signal_value {
@ -194,7 +195,7 @@ fn kill(signalname: &str, pids: std::vec::Vec<String>) -> int {
for pid in pids.iter() {
match pid.as_slice().parse() {
Some(x) => {
let result = Process::kill(x, signal_value as int);
let result = Process::kill(x, signal_value as isize);
match result {
Ok(_) => (),
Err(f) => {

View file

@ -1,4 +1,5 @@
#![crate_name = "link"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "logname"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "mkdir"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -93,7 +94,7 @@ fn print_help(opts: &[getopts::OptGroup]) {
/**
* Create the list of new directories
*/
fn exec(dirs: Vec<String>, mk_parents: bool, mode: FilePermission, verbose: bool) -> Result<(), int> {
fn exec(dirs: Vec<String>, mk_parents: bool, mode: FilePermission, verbose: bool) -> Result<(), isize> {
let mut result = Ok(());
let mut parent_dirs = Vec::new();

View file

@ -1,4 +1,5 @@
#![crate_name = "mkfifo"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "mv"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -186,7 +187,7 @@ fn help(progname: &str, usage: &str) {
println!("{}", msg);
}
fn exec(files: &[Path], b: Behaviour) -> int {
fn exec(files: &[Path], b: Behaviour) -> isize {
match b.target_dir {
Some(ref name) => return move_files_into_dir(files, &Path::new(name.as_slice()), &b),
None => {}
@ -244,7 +245,7 @@ fn exec(files: &[Path], b: Behaviour) -> int {
0
}
fn move_files_into_dir(files: &[Path], target_dir: &Path, b: &Behaviour) -> int {
fn move_files_into_dir(files: &[Path], target_dir: &Path, b: &Behaviour) -> isize {
if !target_dir.is_dir() {
show_error!("target {} is not a directory", target_dir.display());
return 1;

View file

@ -1,4 +1,5 @@
#![crate_name = "nice"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -15,7 +16,6 @@ extern crate libc;
use std::ffi::CString;
use std::io::IoError;
use std::os;
use std::ptr;
use libc::{c_char, c_int, execvp};
const NAME: &'static str = "nice";

View file

@ -8,7 +8,8 @@ fn parse_style(chars: &[char]) -> Result<::NumberingStyle, String> {
['t'] => { Ok(::NumberingStyle::NumberForNonEmpty) },
['n'] => { Ok(::NumberingStyle::NumberForNone) },
['p', rest..] => {
match regex::Regex::new(String::from_chars(rest).as_slice()) {
let s : String = rest.iter().map(|c| *c).collect();
match regex::Regex::new(s.as_slice()) {
Ok(re) => Ok(::NumberingStyle::NumberForRegularExpression(re)),
Err(_) => Err(String::from_str("Illegal regular expression")),
}
@ -83,7 +84,7 @@ pub fn parse_options(settings: &mut ::Settings, opts: &getopts::Matches) -> Vec<
match opts.opt_str("w") {
None => {}
Some(val) => {
let conv: Option<uint> = val.as_slice().parse();
let conv: Option<usize> = val.as_slice().parse();
match conv {
None => {
errs.push(String::from_str("Illegal value for -w"));

View file

@ -1,4 +1,6 @@
#![crate_name = "nl"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*
@ -8,14 +10,16 @@
* file that was distributed with this source code.
*
*/
#![feature(plugin)]
#[macro_use] extern crate regex_macros;
#[plugin] #[no_link] extern crate regex_macros;
extern crate regex;
extern crate getopts;
use std::io::{stdin};
use std::io::BufferedReader;
use std::io::fs::File;
use std::iter::repeat;
use std::num::Int;
use std::path::Path;
use getopts::{optopt, optflag, getopts, usage, OptGroup};
@ -42,7 +46,7 @@ struct Settings {
starting_line_number: u64,
line_increment: u64,
join_blank_lines: u64,
number_width: uint, // Used with String::from_char, hence uint.
number_width: usize, // Used with String::from_char, hence usize.
// The format of the number and the (default value for)
// renumbering each page.
number_format: NumberFormat,
@ -278,11 +282,11 @@ fn nl<T: Reader> (reader: &mut BufferedReader<T>, settings: &Settings) {
// way, start counting empties from zero once more.
empty_line_count = 0;
// A line number is to be printed.
let mut w: uint = 0;
let mut w: usize = 0;
if settings.number_width > line_no_width {
w = settings.number_width - line_no_width;
}
let fill = String::from_char(w, fill_char);
let fill : String = repeat(fill_char).take(w).collect();
match settings.number_format {
NumberFormat::Left => {
println!("{1}{0}{2}{3}", fill, line_no, settings.number_separator, line)

View file

@ -1,4 +1,5 @@
#![crate_name = "nohup"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "nproc"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "paste"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "printenv"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "pwd"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name= "realpath"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -77,7 +78,7 @@ fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool {
Some(x) => x,
};
let mut links_left = 256i;
let mut links_left = 256is;
for part in abs.components() {
result.push(part);

View file

@ -1,4 +1,5 @@
#![crate_name = "relpath"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -64,14 +65,13 @@ pub fn uumain(args: Vec<String>) -> isize {
}
let mut suffix_pos = 0;
absfrom.components()
.zip(absto.components())
.take_while(
|&(f, t)| if f == t {
suffix_pos += 1; true
} else {
false
}).last();
for (f, t) in absfrom.components().zip(absto.components()) {
if f == t {
suffix_pos += 1;
} else {
break;
}
}
let mut result = Path::new("");
absfrom.components().skip(suffix_pos).map(|_| result.push("..")).last();

View file

@ -1,4 +1,5 @@
#![crate_name = "rm"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -125,7 +126,7 @@ pub fn uumain(args: Vec<String>) -> isize {
}
// TODO: implement one-file-system
fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) -> Result<(), int> {
fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs: bool, preserve_root: bool, recursive: bool, dir: bool, verbose: bool) -> Result<(), isize> {
let mut r = Ok(());
for filename in files.iter() {
@ -167,7 +168,7 @@ fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs:
r
}
fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> {
fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), isize> {
let response =
if interactive == InteractiveMode::InteractiveAlways {
prompt_file(path, name)
@ -187,7 +188,7 @@ fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bo
Ok(())
}
fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), int> {
fn remove_file(path: &Path, name: &str, interactive: InteractiveMode, verbose: bool) -> Result<(), isize> {
let response =
if interactive == InteractiveMode::InteractiveAlways {
prompt_file(path, name)

View file

@ -1,4 +1,5 @@
#![crate_name = "rmdir"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -65,7 +66,7 @@ pub fn uumain(args: Vec<String>) -> isize {
0
}
fn remove(dirs: Vec<String>, ignore: bool, parents: bool, verbose: bool) -> Result<(), int>{
fn remove(dirs: Vec<String>, ignore: bool, parents: bool, verbose: bool) -> Result<(), isize>{
let mut r = Ok(());
for dir in dirs.iter() {
@ -86,7 +87,7 @@ fn remove(dirs: Vec<String>, ignore: bool, parents: bool, verbose: bool) -> Resu
r
}
fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool) -> Result<(), int> {
fn remove_dir(path: &Path, dir: &str, ignore: bool, parents: bool, verbose: bool) -> Result<(), isize> {
let mut walk_dir = match fs::walk_dir(path) {
Ok(m) => m,
Err(f) => {

View file

@ -1,4 +1,5 @@
#![crate_name = "seq"]
#![allow(unstable)]
// TODO: Make -w flag work with decimals
// TODO: Support -f flag
@ -36,7 +37,7 @@ fn escape_sequences(s: &str) -> String {
replace("\\t", "\t")
}
fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<String>, int> {
fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<String>, isize> {
let mut seq_args = vec!();
let program = args[0].clone();
let mut iter = args.into_iter().skip(1);
@ -215,8 +216,8 @@ fn done_printing(next: f64, step: f64, last: f64) -> bool {
}
}
fn print_seq(first: f64, step: f64, last: f64, largest_dec: uint, separator: String, terminator: String, pad: bool, padding: uint) {
let mut i = 0i;
fn print_seq(first: f64, step: f64, last: f64, largest_dec: usize, separator: String, terminator: String, pad: bool, padding: usize) {
let mut i = 0is;
let mut value = first + i as f64 * step;
while !done_printing(value, step, last) {
let istr = value.to_string();

View file

@ -1,4 +1,5 @@
#![crate_name = "shuf"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -17,7 +18,7 @@ use std::io;
use std::io::IoResult;
use std::iter::{range_inclusive, RangeInclusive};
use std::rand::{self, Rng};
use std::uint;
use std::usize;
#[path = "../common/util.rs"]
#[macro_use]
@ -26,7 +27,7 @@ mod util;
enum Mode {
Default,
Echo,
InputRange(RangeInclusive<uint>)
InputRange(RangeInclusive<usize>)
}
static NAME: &'static str = "shuf";
@ -95,14 +96,14 @@ With no FILE, or when FILE is -, read standard input.",
let repeat = matches.opt_present("repeat");
let zero = matches.opt_present("zero-terminated");
let count = match matches.opt_str("head-count") {
Some(cnt) => match cnt.parse::<uint>() {
Some(cnt) => match cnt.parse::<usize>() {
Some(val) => val,
None => {
show_error!("'{}' is not a valid count", cnt);
return 1;
}
},
None => uint::MAX
None => usize::MAX
};
let output = matches.opt_str("output");
let random = matches.opt_str("random-source");
@ -118,7 +119,7 @@ With no FILE, or when FILE is -, read standard input.",
0
}
fn shuf(input: Vec<String>, mode: Mode, repeat: bool, zero: bool, count: uint, output: Option<String>, random: Option<String>) -> IoResult<()> {
fn shuf(input: Vec<String>, mode: Mode, repeat: bool, zero: bool, count: usize, output: Option<String>, random: Option<String>) -> IoResult<()> {
match mode {
Mode::Echo => shuf_lines(input, repeat, zero, count, output, random),
Mode::InputRange(range) => shuf_lines(range.map(|num| num.to_string()).collect(), repeat, zero, count, output, random),
@ -163,7 +164,7 @@ impl WrappedRng {
}
}
fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, outname: Option<String>, random: Option<String>) -> IoResult<()> {
fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: usize, outname: Option<String>, random: Option<String>) -> IoResult<()> {
let mut output = match outname {
Some(name) => Box::new(io::BufferedWriter::new(try!(io::File::create(&Path::new(name))))) as Box<Writer>,
None => Box::new(io::stdout()) as Box<Writer>
@ -175,7 +176,7 @@ fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, out
let mut len = lines.len();
let max = if repeat { count } else { cmp::min(count, len) };
for _ in range(0, max) {
let idx = rng.next_u32() as uint % len;
let idx = rng.next_u32() as usize % len;
try!(write!(output, "{}{}", lines[idx], if zero { '\0' } else { '\n' }));
if !repeat {
lines.remove(idx);
@ -185,16 +186,16 @@ fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, out
Ok(())
}
fn parse_range(input_range: String) -> Result<RangeInclusive<uint>, (String, int)> {
fn parse_range(input_range: String) -> Result<RangeInclusive<usize>, (String, isize)> {
let split: Vec<&str> = input_range.as_slice().split('-').collect();
if split.len() != 2 {
Err(("invalid range format".to_string(), 1))
} else {
let begin = match split[0].parse::<uint>() {
let begin = match split[0].parse::<usize>() {
Some(m) => m,
None => return Err((format!("{} is not a valid number", split[0]), 1))
};
let end = match split[1].parse::<uint>() {
let end = match split[1].parse::<usize>() {
Some(m) => m,
None => return Err((format!("{} is not a valid number", split[1]), 1))
};

View file

@ -1,4 +1,5 @@
#![crate_name = "sleep"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "sort"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -14,7 +15,6 @@
extern crate getopts;
use std::cmp::Ordering;
use std::fmt::Show;
use std::io::{print, File, BufferedReader};
use std::io::stdio::stdin_raw;
use std::str::Chars;
@ -132,7 +132,7 @@ fn frac_compare(a: &String, b: &String) -> Ordering {
}
}
if char_a.is_digit(10) && char_b.is_digit(10) {
(char_a as int).cmp(&(char_b as int))
(char_a as isize).cmp(&(char_b as isize))
} else if char_a.is_digit(10) {
skip_zeros(char_a, a_chars, Ordering::Greater)
} else if char_b.is_digit(10) {

View file

@ -1,4 +1,5 @@
#![crate_name = "split"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -111,7 +112,7 @@ pub fn uumain(args: Vec<String>) -> isize {
struct Settings {
prefix: String,
numeric_suffix: bool,
suffix_length: uint,
suffix_length: usize,
input: String,
strategy: String,
strategy_param: String,
@ -124,30 +125,29 @@ struct SplitControl {
}
trait Splitter {
// Factory pattern
fn new(_hint: Option<Self>, &Settings) -> Box<Splitter>;
// Consume the current_line and return the consumed string
fn consume(&mut self, &mut SplitControl) -> String;
}
struct LineSplitter {
saved_lines_to_write: uint,
lines_to_write: uint,
saved_lines_to_write: usize,
lines_to_write: usize,
}
impl Splitter for LineSplitter {
fn new(_: Option<LineSplitter>, settings: &Settings) -> Box<Splitter> {
impl LineSplitter {
fn new(settings: &Settings) -> Box<Splitter> {
let n = match settings.strategy_param.as_slice().parse() {
Some(a) => a,
_ => crash!(1, "invalid number of lines")
};
box LineSplitter {
Box::new(LineSplitter {
saved_lines_to_write: n,
lines_to_write: n,
} as Box<Splitter>
}) as Box<Splitter>
}
}
impl Splitter for LineSplitter {
fn consume(&mut self, control: &mut SplitControl) -> String {
self.lines_to_write -= 1;
if self.lines_to_write == 0 {
@ -159,42 +159,44 @@ impl Splitter for LineSplitter {
}
struct ByteSplitter {
saved_bytes_to_write: uint,
bytes_to_write: uint,
saved_bytes_to_write: usize,
bytes_to_write: usize,
break_on_line_end: bool,
require_whole_line: bool,
}
impl Splitter for ByteSplitter {
fn new(_: Option<ByteSplitter>, settings: &Settings) -> Box<Splitter> {
impl ByteSplitter {
fn new(settings: &Settings) -> Box<Splitter> {
let mut strategy_param : Vec<char> = settings.strategy_param.chars().collect();
let suffix = strategy_param.pop().unwrap();
let multiplier = match suffix {
'0'...'9' => 1u,
'b' => 512u,
'k' => 1024u,
'm' => 1024u * 1024u,
'0'...'9' => 1us,
'b' => 512us,
'k' => 1024us,
'm' => 1024us * 1024us,
_ => crash!(1, "invalid number of bytes")
};
let n = if suffix.is_alphabetic() {
match strategy_param.as_slice().iter().map(|c| *c).collect::<String>().as_slice().parse::<uint>() {
match strategy_param.as_slice().iter().map(|c| *c).collect::<String>().as_slice().parse::<usize>() {
Some(a) => a,
_ => crash!(1, "invalid number of bytes")
}
} else {
match settings.strategy_param.as_slice().parse::<uint>() {
match settings.strategy_param.as_slice().parse::<usize>() {
Some(a) => a,
_ => crash!(1, "invalid number of bytes")
}
};
box ByteSplitter {
Box::new(ByteSplitter {
saved_bytes_to_write: n * multiplier,
bytes_to_write: n * multiplier,
break_on_line_end: if settings.strategy == "b" { false } else { true },
require_whole_line: false,
} as Box<Splitter>
}) as Box<Splitter>
}
}
impl Splitter for ByteSplitter {
fn consume(&mut self, control: &mut SplitControl) -> String {
let line = control.current_line.clone();
let n = std::cmp::min(line.as_slice().chars().count(), self.bytes_to_write);
@ -217,13 +219,13 @@ impl Splitter for ByteSplitter {
}
// (1, 3) -> "aab"
fn str_prefix(i: uint, width: uint) -> String {
fn str_prefix(i: usize, width: usize) -> String {
let mut c = "".to_string();
let mut n = i;
let mut w = width;
while w > 0 {
w -= 1;
let div = Int::pow(26 as uint, w);
let div = Int::pow(26 as usize, w);
let r = n / div;
n -= r * div;
c.push(char::from_u32((r as u32) + 97).unwrap());
@ -232,13 +234,13 @@ fn str_prefix(i: uint, width: uint) -> String {
}
// (1, 3) -> "001"
fn num_prefix(i: uint, width: uint) -> String {
fn num_prefix(i: usize, width: usize) -> String {
let mut c = "".to_string();
let mut n = i;
let mut w = width;
while w > 0 {
w -= 1;
let div = Int::pow(10 as uint, w);
let div = Int::pow(10 as usize, w);
let r = n / div;
n -= r * div;
c.push(char::from_digit(r, 10).unwrap());
@ -246,23 +248,23 @@ fn num_prefix(i: uint, width: uint) -> String {
c
}
fn split(settings: &Settings) -> int {
fn split(settings: &Settings) -> isize {
let mut reader = io::BufferedReader::new(
if settings.input.as_slice() == "-" {
box io::stdio::stdin_raw() as Box<Reader>
Box::new(io::stdio::stdin_raw()) as Box<Reader>
} else {
let r = match io::File::open(&Path::new(settings.input.clone())) {
Ok(a) => a,
Err(_) => crash!(1, "cannot open '{}' for reading: No such file or directory", settings.input)
};
box r as Box<Reader>
Box::new(r) as Box<Reader>
}
);
let mut splitter: Box<Splitter> =
match settings.strategy.as_slice() {
"l" => Splitter::new(None::<LineSplitter>, settings),
"b" | "C" => Splitter::new(None::<ByteSplitter>, settings),
"l" => LineSplitter::new(settings),
"b" | "C" => ByteSplitter::new(settings),
a @ _ => crash!(1, "strategy {} not supported", a)
};
@ -271,7 +273,7 @@ fn split(settings: &Settings) -> int {
request_new_file: true, // Request new file
};
let mut writer = io::BufferedWriter::new(box io::stdio::stdout_raw() as Box<Writer>);
let mut writer = io::BufferedWriter::new(Box::new(io::stdio::stdout_raw()) as Box<Writer>);
let mut fileno = 0;
loop {
if control.current_line.as_slice().chars().count() == 0 {
@ -293,7 +295,7 @@ fn split(settings: &Settings) -> int {
crash_if_err!(1, writer.flush());
}
fileno += 1;
writer = io::BufferedWriter::new(box io::File::open_mode(&Path::new(filename.as_slice()), io::Open, io::Write) as Box<Writer>);
writer = io::BufferedWriter::new(Box::new(io::File::open_mode(&Path::new(filename.as_slice()), io::Open, io::Write)) as Box<Writer>);
control.request_new_file = false;
if settings.verbose {
println!("creating file '{}'", filename);

View file

@ -1,4 +1,5 @@
#![crate_name = "sum"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,6 @@
#![crate_name = "uusync"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*
@ -28,7 +30,7 @@ mod platform {
fn sync() -> libc::c_void;
}
pub unsafe fn do_sync() -> int {
pub unsafe fn do_sync() -> isize {
sync();
0
}
@ -177,7 +179,7 @@ fn help(program: &str, options: &[getopts::OptGroup]) {
print!("{}", usage("Force changed blocks to disk, update the super block.", options));
}
fn uusync() -> int {
fn uusync() -> isize {
unsafe {
platform::do_sync()
}

View file

@ -1,4 +1,5 @@
#![crate_name = "tac"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,6 @@
#![crate_name = "tail"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*
@ -32,8 +34,8 @@ static VERSION: &'static str = "0.0.1";
pub fn uumain(args: Vec<String>) -> isize {
let mut beginning = false;
let mut lines = true;
let mut byte_count = 0u;
let mut line_count = 10u;
let mut byte_count = 0us;
let mut line_count = 10us;
let mut sleep_msec = 1000u64;
// handle obsolete -number syntax
@ -147,33 +149,33 @@ pub fn uumain(args: Vec<String>) -> isize {
0
}
fn parse_size(mut size_slice: &str) -> Option<uint> {
fn parse_size(mut size_slice: &str) -> Option<usize> {
let mut base =
if size_slice.len() > 0 && size_slice.char_at(size_slice.len() - 1) == 'B' {
size_slice = size_slice.slice_to(size_slice.len() - 1);
1000u
1000us
} else {
1024u
1024us
};
let exponent =
if size_slice.len() > 0 {
let mut has_suffix = true;
let exp = match size_slice.char_at(size_slice.len() - 1) {
'K' => 1u,
'M' => 2u,
'G' => 3u,
'T' => 4u,
'P' => 5u,
'E' => 6u,
'Z' => 7u,
'Y' => 8u,
'K' => 1us,
'M' => 2us,
'G' => 3us,
'T' => 4us,
'P' => 5us,
'E' => 6us,
'Z' => 7us,
'Y' => 8us,
'b' => {
base = 512u;
1u
base = 512us;
1us
}
_ => {
has_suffix = false;
0u
0us
}
};
if has_suffix {
@ -181,14 +183,14 @@ fn parse_size(mut size_slice: &str) -> Option<uint> {
}
exp
} else {
0u
0us
};
let mut multiplier = 1u;
for _ in range(0u, exponent) {
let mut multiplier = 1us;
for _ in range(0us, exponent) {
multiplier *= base;
}
if base == 1000u && exponent == 0u {
if base == 1000us && exponent == 0us {
// sole B is not a valid suffix
None
} else {
@ -204,7 +206,7 @@ fn parse_size(mut size_slice: &str) -> Option<uint> {
//
// In case is found, the options vector will get rid of that object so that
// getopts works correctly.
fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
fn obsolete(options: &[String]) -> (Vec<String>, Option<usize>) {
let mut options: Vec<String> = options.to_vec();
let mut a = 0;
let b = options.len();
@ -222,7 +224,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
// If this is the last number
if pos == len - 1 {
options.remove(a);
let number: Option<uint> = from_utf8(current.slice(1,len)).unwrap().parse();
let number: Option<usize> = from_utf8(current.slice(1,len)).unwrap().parse();
return (options, Some(number.unwrap()));
}
}
@ -243,7 +245,7 @@ macro_rules! tail_impl (
let mut data = $reader.$kindfn().skip(
if $beginning {
let temp = $count;
$count = ::std::uint::MAX;
$count = ::std::usize::MAX;
temp - 1
} else {
0
@ -267,7 +269,7 @@ macro_rules! tail_impl (
})
);
fn tail<T: Reader>(reader: &mut BufferedReader<T>, mut line_count: uint, mut byte_count: uint, beginning: bool, lines: bool, follow: bool, sleep_msec: u64) {
fn tail<T: Reader>(reader: &mut BufferedReader<T>, mut line_count: usize, mut byte_count: usize, beginning: bool, lines: bool, follow: bool, sleep_msec: u64) {
if lines {
tail_impl!(String, lines, print_string, reader, line_count, beginning);
} else {

View file

@ -1,5 +1,6 @@
#![crate_name = "tee"]
#![feature(phase)]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*
@ -66,7 +67,7 @@ fn options(args: &[String]) -> Result<Options, ()> {
append: m.opt_present("append"),
ignore_interrupts: m.opt_present("ignore-interrupts"),
print_and_exit: to_print,
files: box names.iter().map(|name| Path::new(name.clone())).collect()
files: Box::new(names.iter().map(|name| Path::new(name.clone())).collect())
})
}).map_err(|message| warn(message.as_slice()))
}
@ -81,7 +82,7 @@ fn exec(options: Options) -> Result<(), ()> {
fn tee(options: Options) -> Result<(), ()> {
let writers = options.files.iter().map(|path| open(path, options.append)).collect();
let output = &mut MultiWriter::new(writers);
let input = &mut NamedReader { inner: box stdin() as Box<Reader> };
let input = &mut NamedReader { inner: Box::new(stdin()) as Box<Reader> };
if copy(input, output).is_err() || output.flush().is_err() {
Err(())
} else {
@ -91,15 +92,15 @@ fn tee(options: Options) -> Result<(), ()> {
fn open(path: &Path, append: bool) -> Box<Writer+'static> {
let inner = if *path == Path::new("-") {
box stdout() as Box<Writer>
Box::new(stdout()) as Box<Writer>
} else {
let mode = if append { Append } else { Truncate };
match File::open_mode(path, mode, Write) {
Ok(file) => box file as Box<Writer>,
Err(_) => box NullWriter as Box<Writer>
Ok(file) => Box::new(file) as Box<Writer>,
Err(_) => Box::new(NullWriter) as Box<Writer>
}
};
box NamedWriter { inner: inner, path: box path.clone() } as Box<Writer>
Box::new(NamedWriter { inner: inner, path: Box::new(path.clone()) }) as Box<Writer>
}
struct NamedWriter {
@ -112,7 +113,7 @@ impl Writer for NamedWriter {
with_path(&*self.path.clone(), || {
let val = self.inner.write(buf);
if val.is_err() {
self.inner = box NullWriter as Box<Writer>;
self.inner = Box::new(NullWriter) as Box<Writer>;
}
val
})
@ -122,7 +123,7 @@ impl Writer for NamedWriter {
with_path(&*self.path.clone(), || {
let val = self.inner.flush();
if val.is_err() {
self.inner = box NullWriter as Box<Writer>;
self.inner = Box::new(NullWriter) as Box<Writer>;
}
val
})
@ -134,14 +135,14 @@ struct NamedReader {
}
impl Reader for NamedReader {
fn read(&mut self, buf: &mut [u8]) -> IoResult<uint> {
fn read(&mut self, buf: &mut [u8]) -> IoResult<usize> {
with_path(&Path::new("stdin"), || {
self.inner.read(buf)
})
}
}
fn with_path<F, T>(path: &Path, cb: F) -> IoResult<T> where F: Fn() -> IoResult<T> {
fn with_path<F, T>(path: &Path, mut cb: F) -> IoResult<T> where F: FnMut() -> IoResult<T> {
match cb() {
Err(f) => { warn(format!("{}: {}", path.display(), f.to_string()).as_slice()); Err(f) }
okay => okay

View file

@ -1,4 +1,5 @@
#![crate_name = "uutest"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -39,7 +40,7 @@ pub fn uumain(_: Vec<String>) -> isize {
_ => args.slice(1, args.len()),
};
let mut error = false;
let retval = 1 - parse_expr(args, &mut error) as int;
let retval = 1 - parse_expr(args, &mut error) as isize;
if error {
2
} else {
@ -160,7 +161,7 @@ fn dispatch(args: &mut &[&[u8]], error: &mut bool) -> bool {
val
}
fn dispatch_two(args: &mut &[&[u8]], error: &mut bool) -> (bool, uint) {
fn dispatch_two(args: &mut &[&[u8]], error: &mut bool) -> (bool, usize) {
let val = two(*args, error);
if *error {
*error = false;
@ -170,7 +171,7 @@ fn dispatch_two(args: &mut &[&[u8]], error: &mut bool) -> (bool, uint) {
}
}
fn dispatch_three(args: &mut &[&[u8]], error: &mut bool) -> (bool, uint) {
fn dispatch_three(args: &mut &[&[u8]], error: &mut bool) -> (bool, usize) {
let val = three(*args, error);
if *error {
*error = false;
@ -180,7 +181,7 @@ fn dispatch_three(args: &mut &[&[u8]], error: &mut bool) -> (bool, uint) {
}
}
fn dispatch_four(args: &mut &[&[u8]], error: &mut bool) -> (bool, uint) {
fn dispatch_four(args: &mut &[&[u8]], error: &mut bool) -> (bool, usize) {
let val = four(*args, error);
if *error {
*error = false;
@ -226,7 +227,7 @@ fn parse_expr_helper<'a>(hashmap: &HashMap<&'a [u8], Precedence>,
*error = true;
&min_prec
});
while !*error && args.len() > 0 && prec as uint >= min_prec as uint {
while !*error && args.len() > 0 && prec as usize >= min_prec as usize {
let op = args[0];
*args = (*args).slice_from(1);
let mut rhs = dispatch(args, error);
@ -235,7 +236,7 @@ fn parse_expr_helper<'a>(hashmap: &HashMap<&'a [u8], Precedence>,
*error = true;
&min_prec
});
if subprec as uint <= prec as uint || *error {
if subprec as usize <= prec as usize || *error {
break;
}
rhs = parse_expr_helper(hashmap, args, rhs, subprec, error);

View file

@ -1,4 +1,5 @@
#![crate_name = "timeout"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -32,7 +33,7 @@ extern {
static NAME: &'static str = "timeout";
static VERSION: &'static str = "1.0.0";
static ERR_EXIT_STATUS: int = 125;
static ERR_EXIT_STATUS: isize = 125;
pub fn uumain(args: Vec<String>) -> isize {
let program = args[0].clone();
@ -100,7 +101,7 @@ Usage:
0
}
fn timeout(cmdname: &str, args: &[String], duration: f64, signal: uint, kill_after: f64, foreground: bool, preserve_status: bool) -> int {
fn timeout(cmdname: &str, args: &[String], duration: f64, signal: usize, kill_after: f64, foreground: bool, preserve_status: bool) -> isize {
if !foreground {
unsafe { setpgid(0, 0) };
}
@ -128,7 +129,7 @@ fn timeout(cmdname: &str, args: &[String], duration: f64, signal: uint, kill_aft
ExitSignal(stat) => stat
},
Err(_) => {
return_if_err!(ERR_EXIT_STATUS, process.signal(signal as int));
return_if_err!(ERR_EXIT_STATUS, process.signal(signal as isize));
process.set_timeout(Some((kill_after * 1000f64) as u64));
match process.wait() {
Ok(status) => {
@ -146,7 +147,7 @@ fn timeout(cmdname: &str, args: &[String], duration: f64, signal: uint, kill_aft
// XXX: this may not be right
return 124;
}
return_if_err!(ERR_EXIT_STATUS, process.signal(signals::signal_by_name_or_value("KILL").unwrap() as int));
return_if_err!(ERR_EXIT_STATUS, process.signal(signals::signal_by_name_or_value("KILL").unwrap() as isize));
process.set_timeout(None);
return_if_err!(ERR_EXIT_STATUS, process.wait());
137

View file

@ -1,4 +1,5 @@
#![crate_name = "touch"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "tr"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name= "uutrue"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "truncate"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -99,7 +100,7 @@ file based on its current size:
0
}
fn truncate(no_create: bool, _: bool, reference: Option<String>, size: Option<String>, filenames: Vec<String>) -> Result<(), int> {
fn truncate(no_create: bool, _: bool, reference: Option<String>, size: Option<String>, filenames: Vec<String>) -> Result<(), isize> {
let (refsize, mode) = match reference {
Some(rfilename) => {
let rfile = match File::open(&Path::new(rfilename.clone())) {

View file

@ -1,4 +1,5 @@
#![crate_name = "tsort"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,5 +1,5 @@
#![crate_name = "tty"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -74,7 +74,7 @@ pub fn uumain(args: Vec<String>) -> isize {
}
};
exit_code as int
exit_code as isize
}
fn usage () {

View file

@ -1,4 +1,5 @@
#![crate_name = "uname"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "unexpand"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -21,9 +22,9 @@ mod util;
static NAME: &'static str = "unexpand";
static VERSION: &'static str = "0.0.1";
static DEFAULT_TABSTOP: uint = 8;
static DEFAULT_TABSTOP: usize = 8;
fn tabstops_parse(s: String) -> Vec<uint> {
fn tabstops_parse(s: String) -> Vec<usize> {
let words = s.as_slice().split(',').collect::<Vec<&str>>();
let nums = words.into_iter()
@ -31,7 +32,7 @@ fn tabstops_parse(s: String) -> Vec<uint> {
.unwrap_or_else(
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
)
.collect::<Vec<uint>>();
.collect::<Vec<usize>>();
if nums.iter().any(|&n| n == 0) {
crash!(1, "{}\n", "tab size cannot be 0");
@ -47,7 +48,7 @@ fn tabstops_parse(s: String) -> Vec<uint> {
struct Options {
files: Vec<String>,
tabstops: Vec<uint>,
tabstops: Vec<usize>,
aflag: bool
}
@ -108,24 +109,24 @@ pub fn uumain(args: Vec<String>) -> isize {
fn open(path: String) -> io::BufferedReader<Box<Reader+'static>> {
let mut file_buf;
if path.as_slice() == "-" {
io::BufferedReader::new(box io::stdio::stdin_raw() as Box<Reader>)
io::BufferedReader::new(Box::new(io::stdio::stdin_raw()) as Box<Reader>)
} else {
file_buf = match io::File::open(&Path::new(path.as_slice())) {
Ok(a) => a,
_ => crash!(1, "{}: {}\n", path, "No such file or directory")
};
io::BufferedReader::new(box file_buf as Box<Reader>)
io::BufferedReader::new(Box::new(file_buf) as Box<Reader>)
}
}
fn is_tabstop(tabstops: &[uint], col: uint) -> bool {
fn is_tabstop(tabstops: &[usize], col: usize) -> bool {
match tabstops {
[tabstop] => col % tabstop == 0,
tabstops => tabstops.binary_search(|&e| e.cmp(&col)).found().is_some()
tabstops => tabstops.binary_search_by(|&e| e.cmp(&col)).is_ok()
}
}
fn to_next_stop(tabstops: &[uint], col: uint) -> Option<uint> {
fn to_next_stop(tabstops: &[usize], col: usize) -> Option<usize> {
match tabstops {
[tabstop] => Some(tabstop - col % tabstop),
tabstops => tabstops.iter().skip_while(|&t| *t <= col).next()
@ -134,7 +135,7 @@ fn to_next_stop(tabstops: &[uint], col: uint) -> Option<uint> {
}
fn unexpandspan(mut output: &mut io::LineBufferedWriter<io::stdio::StdWriter>,
tabstops: &[uint], nspaces: uint, col: uint, init: bool) {
tabstops: &[usize], nspaces: usize, col: usize, init: bool) {
let mut cur = col - nspaces;
if nspaces > 1 || init {
loop {

View file

@ -1,4 +1,6 @@
#![crate_name = "uniq"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
*
@ -29,8 +31,8 @@ struct Uniq {
all_repeated: bool,
delimiters: String,
show_counts: bool,
slice_start: Option<uint>,
slice_stop: Option<uint>,
slice_start: Option<usize>,
slice_stop: Option<usize>,
ignore_case: bool,
}
@ -96,7 +98,7 @@ impl Uniq {
first_line_printed
}
fn print_line<W: Writer>(&self, writer: &mut io::BufferedWriter<W>, line: &String, count: uint, print_delimiter: bool) {
fn print_line<W: Writer>(&self, writer: &mut io::BufferedWriter<W>, line: &String, count: usize, print_delimiter: bool) {
let output_line = if self.show_counts {
format!("{:7} {}", count, line)
} else {

View file

@ -1,4 +1,5 @@
#![crate_name = "unlink"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,4 +1,5 @@
#![crate_name = "uptime"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -17,6 +18,7 @@ extern crate getopts;
extern crate libc;
extern crate "time" as rtime;
use std::ffi::CString;
use std::mem::transmute;
use std::io::{print, File};
use std::ptr::null;
@ -97,19 +99,17 @@ fn print_loadavg() {
else {
print!("load average: ");
for n in range(0, loads) {
print!("{:.2}{}", avg[n as uint], if n == loads - 1 { "\n" }
print!("{:.2}{}", avg[n as usize], if n == loads - 1 { "\n" }
else { ", " } );
}
}
}
#[cfg(unix)]
fn process_utmpx() -> (Option<time_t>, uint) {
DEFAULT_FILE.with_c_str(|filename| {
unsafe {
utmpxname(filename);
}
});
fn process_utmpx() -> (Option<time_t>, usize) {
unsafe {
utmpxname(CString::from_slice(DEFAULT_FILE.as_bytes()).as_ptr());
}
let mut nusers = 0;
let mut boot_time = None;
@ -143,11 +143,11 @@ fn process_utmpx() -> (Option<time_t>, uint) {
}
#[cfg(windows)]
fn process_utmpx() -> (Option<time_t>, uint) {
fn process_utmpx() -> (Option<time_t>, usize) {
(None, 0) // TODO: change 0 to number of users
}
fn print_nusers(nusers: uint) {
fn print_nusers(nusers: usize) {
if nusers == 1 {
print!("1 user, ");
} else if nusers > 1 {
@ -172,7 +172,7 @@ fn get_uptime(boot_time: Option<time_t>) -> i64 {
_ => return match boot_time {
Some(t) => {
let now = rtime::get_time().sec;
let time = t.to_i64().unwrap();
let time = t as i64;
((now - time) * 100) as i64 // Return in ms
},
_ => -1

View file

@ -1,4 +1,5 @@
#![crate_name = "users"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -17,7 +18,7 @@
extern crate getopts;
extern crate libc;
use std::ffi::c_str_to_bytes;
use std::ffi::{CString, c_str_to_bytes};
use std::io::print;
use std::mem;
use std::ptr;
@ -89,11 +90,9 @@ pub fn uumain(args: Vec<String>) -> isize {
}
fn exec(filename: &str) {
filename.with_c_str(|filename| {
unsafe {
utmpxname(filename);
}
});
unsafe {
utmpxname(CString::from_slice(filename.as_bytes()).as_ptr());
}
let mut users = vec!();

View file

@ -1,4 +1,5 @@
#![crate_name = "uutils"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -19,13 +20,13 @@ use std::collections::hash_map::HashMap;
static NAME: &'static str = "uutils";
static VERSION: &'static str = "1.0.0";
fn util_map() -> HashMap<&'static str, fn(Vec<String>) -> int> {
fn util_map() -> HashMap<&'static str, fn(Vec<String>) -> isize> {
let mut map = HashMap::new();
@UTIL_MAP@
map
}
fn usage(cmap: &HashMap<&'static str, fn(Vec<String>) -> int>) {
fn usage(cmap: &HashMap<&'static str, fn(Vec<String>) -> isize>) {
println!("{} {}", NAME, VERSION);
println!("");
println!("Usage:");

View file

@ -1,4 +1,5 @@
#![crate_name = "wc"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -26,11 +27,11 @@ mod util;
struct Result {
filename: String,
bytes: uint,
chars: uint,
lines: uint,
words: uint,
max_line_length: uint,
bytes: usize,
chars: usize,
lines: usize,
words: usize,
max_line_length: usize,
}
static NAME: &'static str = "wc";
@ -94,25 +95,25 @@ fn is_word_seperator(byte: u8) -> bool {
byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF
}
pub fn wc(files: Vec<String>, matches: &Matches) -> StdResult<(), int> {
let mut total_line_count: uint = 0;
let mut total_word_count: uint = 0;
let mut total_char_count: uint = 0;
let mut total_byte_count: uint = 0;
let mut total_longest_line_length: uint = 0;
pub fn wc(files: Vec<String>, matches: &Matches) -> StdResult<(), isize> {
let mut total_line_count: usize = 0;
let mut total_word_count: usize = 0;
let mut total_char_count: usize = 0;
let mut total_byte_count: usize = 0;
let mut total_longest_line_length: usize = 0;
let mut results = vec!();
let mut max_str_len: uint = 0;
let mut max_str_len: usize = 0;
for path in files.iter() {
let mut reader = try!(open(path.as_slice()));
let mut line_count: uint = 0;
let mut word_count: uint = 0;
let mut byte_count: uint = 0;
let mut char_count: uint = 0;
let mut current_char_count: uint = 0;
let mut longest_line_length: uint = 0;
let mut line_count: usize = 0;
let mut word_count: usize = 0;
let mut byte_count: usize = 0;
let mut char_count: usize = 0;
let mut current_char_count: usize = 0;
let mut longest_line_length: usize = 0;
loop {
// reading from a TTY seems to raise a condition on, rather than return Some(0) like a file.
@ -191,8 +192,8 @@ pub fn wc(files: Vec<String>, matches: &Matches) -> StdResult<(), int> {
Ok(())
}
fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: uint,
byte_count: uint, longest_line_length: uint, matches: &Matches, max_str_len: uint) {
fn print_stats(filename: &str, line_count: usize, word_count: usize, char_count: usize,
byte_count: usize, longest_line_length: usize, matches: &Matches, max_str_len: usize) {
if matches.opt_present("lines") {
print!("{:1$}", line_count, max_str_len);
}
@ -228,7 +229,7 @@ fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: u
}
}
fn open(path: &str) -> StdResult<BufferedReader<Box<Reader+'static>>, int> {
fn open(path: &str) -> StdResult<BufferedReader<Box<Reader+'static>>, isize> {
if "-" == path {
let reader = Box::new(stdin_raw()) as Box<Reader>;
return Ok(BufferedReader::new(reader));

View file

@ -1,4 +1,5 @@
#![crate_name = "whoami"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.
@ -35,9 +36,7 @@ mod platform {
let passwd: *const c_passwd = getpwuid(geteuid());
let pw_name: *const libc::c_char = (*passwd).pw_name;
let name = String::from_raw_buf(pw_name as *const u8);
name
String::from_utf8_lossy(::std::ffi::c_str_to_bytes(&pw_name)).to_string()
}
}
@ -56,7 +55,7 @@ mod platform {
if !GetUserNameA(buffer.as_mut_ptr(), &mut (buffer.len() as libc::uint32_t)) == 0 {
crash!(1, "username is too long");
}
String::from_raw_buf(buffer.as_ptr() as *const u8)
String::from_utf8_lossy(::std::ffi::c_str_to_bytes(&buffer.as_ptr())).to_string()
}
}

View file

@ -1,4 +1,5 @@
#![crate_name = "yes"]
#![allow(unstable)]
/*
* This file is part of the uutils coreutils package.

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
use std::str;

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
use std::io::File;
use std::io::fs::{unlink, PathExtensions};

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
use std::io::fs::{rmdir, PathExtensions};
use std::borrow::ToOwned;

View file

@ -1,9 +1,10 @@
#![allow(unstable)]
extern crate time;
use std::io::{process, fs, FilePermission};
use std::io::process::Command;
use std::io::fs::PathExtensions;
use std::io::pipe::PipeStream;
use std::str::from_utf8;
use std::borrow::ToOwned;
@ -30,11 +31,11 @@ fn run(cmd: &mut Command) -> CmdResult {
stdout: from_utf8(prog.output.as_slice()).unwrap().to_owned(),
}
}
fn run_interactive(cmd: &mut Command, f: |&mut PipeStream|) -> CmdResult {
fn run_interactive(cmd: &mut Command, input: &[u8])-> CmdResult {
let stdin_cfg = process::CreatePipe(true, false);
let mut command = cmd.stdin(stdin_cfg).spawn().unwrap();
f(command.stdin.as_mut().unwrap());
command.stdin.as_mut().unwrap().write(input);
let prog = command.wait_with_output().unwrap();
CmdResult {
@ -140,10 +141,7 @@ fn test_mv_interactive() {
touch(file_b);
let ia1 = |stdin: &mut PipeStream| {
stdin.write(b"n").unwrap();
};
let result1 = run_interactive(Command::new(EXE).arg("-i").arg(file_a).arg(file_b), ia1);
let result1 = run_interactive(Command::new(EXE).arg("-i").arg(file_a).arg(file_b), b"n");
assert_empty_stderr!(result1);
assert!(result1.success);
@ -152,10 +150,7 @@ fn test_mv_interactive() {
assert!(Path::new(file_b).is_file());
let ia2 = |stdin: &mut PipeStream| {
stdin.write(b"Yesh").unwrap();
};
let result2 = run_interactive(Command::new(EXE).arg("-i").arg(file_a).arg(file_b), ia2);
let result2 = run_interactive(Command::new(EXE).arg("-i").arg(file_a).arg(file_b), b"Yesh");
assert_empty_stderr!(result2);
assert!(result2.success);

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
use std::str;

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
use std::str;

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
use std::io::File;
use std::string::String;
@ -29,7 +31,7 @@ fn numeric5() {
numeric_helper(5);
}
fn numeric_helper(test_num: int) {
fn numeric_helper(test_num: isize) {
let mut cmd = Command::new(PROGNAME);
cmd.arg("-n");
let po = match cmd.clone().arg(format!("{}{}{}", "numeric", test_num, ".txt")).output() {
@ -42,5 +44,5 @@ fn numeric_helper(test_num: int) {
Ok(answer) => answer,
Err(err) => panic!("{}", err),
};
assert_eq!(String::from_utf8(po.output), String::from_utf8(answer));
assert_eq!(String::from_utf8(po.output).unwrap(), String::from_utf8(answer).unwrap());
}

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
static EXE: &'static str = "./test";

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
static PROGNAME: &'static str = "./tr";

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io;
use std::io::process::Command;
@ -34,7 +36,7 @@ fn test_decrease_file_size() {
}
file.seek(0, io::SeekEnd).unwrap();
if file.tell().unwrap() != 6 {
println!("{}", file.tell());
println!("{:?}", file.tell());
panic!();
}
io::fs::unlink(&Path::new(TFILE2)).unwrap();

View file

@ -1,3 +1,5 @@
#![allow(unstable)]
use std::io::process::Command;
static PROGNAME: &'static str = "./unexpand";