mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 21:17:46 +00:00
int/uint -> isize/usize
This commit is contained in:
parent
cc854698d7
commit
782fad4667
42 changed files with 231 additions and 231 deletions
|
@ -32,8 +32,8 @@ fn main() {
|
||||||
crates.push_str("extern crate uutest;\n");
|
crates.push_str("extern crate uutest;\n");
|
||||||
util_map.push_str("map.insert(\"test\", uutest::uumain);\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"),
|
"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>) -> int { 1 }\nmap.insert(\"false\", uufalse);\n"),
|
"false" => util_map.push_str("fn uufalse(_: Vec<String>) -> isize { 1 }\nmap.insert(\"false\", uufalse);\n"),
|
||||||
"sync" => {
|
"sync" => {
|
||||||
crates.push_str("extern crate uusync;\n");
|
crates.push_str("extern crate uusync;\n");
|
||||||
util_map.push_str("map.insert(\"sync\", uusync::uumain);\n");
|
util_map.push_str("map.insert(\"sync\", uusync::uumain);\n");
|
||||||
|
|
|
@ -91,7 +91,7 @@ enum NumberingMode {
|
||||||
fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
||||||
show_ends: bool) {
|
show_ends: bool) {
|
||||||
|
|
||||||
let mut line_counter: uint = 1;
|
let mut line_counter: usize = 1;
|
||||||
|
|
||||||
for path in files.iter() {
|
for path in files.iter() {
|
||||||
let (mut reader, interactive) = match open(path.as_slice()) {
|
let (mut reader, interactive) = match open(path.as_slice()) {
|
||||||
|
@ -164,7 +164,7 @@ fn write_lines(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
||||||
fn write_bytes(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) {
|
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() {
|
for path in files.iter() {
|
||||||
let (mut reader, interactive) = match open(path.as_slice()) {
|
let (mut reader, interactive) = match open(path.as_slice()) {
|
||||||
|
@ -173,7 +173,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
||||||
};
|
};
|
||||||
|
|
||||||
// Flush all 1024 iterations.
|
// 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 in_buf = [0; 1024 * 32];
|
||||||
let mut out_buf = [0; 1024 * 64];
|
let mut out_buf = [0; 1024 * 64];
|
||||||
|
@ -187,7 +187,7 @@ fn write_bytes(files: Vec<String>, number: NumberingMode, squeeze_blank: bool,
|
||||||
for &byte in in_buf.slice_to(n).iter() {
|
for &byte in in_buf.slice_to(n).iter() {
|
||||||
if flush_counter.next().is_none() {
|
if flush_counter.next().is_none() {
|
||||||
writer.possibly_flush();
|
writer.possibly_flush();
|
||||||
flush_counter = range(0u, 1024);
|
flush_counter = range(0us, 1024);
|
||||||
}
|
}
|
||||||
if byte == '\n' as u8 {
|
if byte == '\n' as u8 {
|
||||||
if !at_line_start || !squeeze_blank {
|
if !at_line_start || !squeeze_blank {
|
||||||
|
@ -293,8 +293,8 @@ fn open(path: &str) -> Option<(Box<Reader>, bool)> {
|
||||||
struct UnsafeWriter<'a, W> {
|
struct UnsafeWriter<'a, W> {
|
||||||
inner: W,
|
inner: W,
|
||||||
buf: &'a mut [u8],
|
buf: &'a mut [u8],
|
||||||
pos: uint,
|
pos: usize,
|
||||||
threshold: uint,
|
threshold: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a, W: Writer> UnsafeWriter<'a, W> {
|
impl<'a, W: Writer> UnsafeWriter<'a, W> {
|
||||||
|
|
|
@ -44,7 +44,7 @@ fn crc_final(mut crc: u32, mut length: usize) -> u32 {
|
||||||
#[inline]
|
#[inline]
|
||||||
fn cksum(fname: &str) -> IoResult<(u32, usize)> {
|
fn cksum(fname: &str) -> IoResult<(u32, usize)> {
|
||||||
let mut crc = 0u32;
|
let mut crc = 0u32;
|
||||||
let mut size = 0u;
|
let mut size = 0us;
|
||||||
|
|
||||||
let mut stdin_buf;
|
let mut stdin_buf;
|
||||||
let mut file_buf;
|
let mut file_buf;
|
||||||
|
|
|
@ -1,3 +1,3 @@
|
||||||
/* auto-generated (DO NOT EDIT) */
|
/* 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];
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
use std::io;
|
use std::io;
|
||||||
|
|
||||||
static CRC_TABLE_LEN: uint = 256;
|
static CRC_TABLE_LEN: usize = 256;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let mut table = Vec::with_capacity(CRC_TABLE_LEN);
|
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 mut file = io::File::open_mode(&Path::new("crc_table.rs"), io::Truncate, io::Write).unwrap();
|
||||||
let output = format!("/* auto-generated (DO NOT EDIT) */
|
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();
|
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 {
|
fn crc_entry(input: u8) -> u32 {
|
||||||
let mut crc = (input as u32) << 24;
|
let mut crc = (input as u32) << 24;
|
||||||
|
|
||||||
for _ in range(0u, 8) {
|
for _ in range(0, 8) {
|
||||||
if crc & 0x80000000 != 0 {
|
if crc & 0x80000000 != 0 {
|
||||||
crc <<= 1;
|
crc <<= 1;
|
||||||
crc ^= 0x04c11db7;
|
crc ^= 0x04c11db7;
|
||||||
|
|
|
@ -9,10 +9,10 @@
|
||||||
|
|
||||||
#![allow(dead_code)]
|
#![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 },
|
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" {
|
if signal_name_or_value == "0" {
|
||||||
return Some(0);
|
return Some(0);
|
||||||
}
|
}
|
||||||
|
@ -153,6 +153,6 @@ pub fn signal_by_name_or_value(signal_name_or_value: &str) -> Option<uint> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
pub fn is_signal(num: uint) -> bool {
|
pub fn is_signal(num: usize) -> bool {
|
||||||
num < ALL_SIGNALS.len()
|
num < ALL_SIGNALS.len()
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,10 +14,10 @@ pub fn from_str(string: &str) -> Result<f64, String> {
|
||||||
}
|
}
|
||||||
let slice = string.slice_to(len - 1);
|
let slice = string.slice_to(len - 1);
|
||||||
let (numstr, times) = match string.char_at(len - 1) {
|
let (numstr, times) = match string.char_at(len - 1) {
|
||||||
's' | 'S' => (slice, 1u),
|
's' | 'S' => (slice, 1us),
|
||||||
'm' | 'M' => (slice, 60u),
|
'm' | 'M' => (slice, 60us),
|
||||||
'h' | 'H' => (slice, 60u * 60),
|
'h' | 'H' => (slice, 60us * 60),
|
||||||
'd' | 'D' => (slice, 60u * 60 * 24),
|
'd' | 'D' => (slice, 60us * 60 * 24),
|
||||||
val => {
|
val => {
|
||||||
if !val.is_alphabetic() {
|
if !val.is_alphabetic() {
|
||||||
(string, 1)
|
(string, 1)
|
||||||
|
|
|
@ -10,10 +10,10 @@ mod utmpx {
|
||||||
|
|
||||||
pub static DEFAULT_FILE: &'static str = "/var/run/utmp";
|
pub static DEFAULT_FILE: &'static str = "/var/run/utmp";
|
||||||
|
|
||||||
pub const UT_LINESIZE: uint = 32;
|
pub const UT_LINESIZE: usize = 32;
|
||||||
pub const UT_NAMESIZE: uint = 32;
|
pub const UT_NAMESIZE: usize = 32;
|
||||||
pub const UT_IDSIZE: uint = 4;
|
pub const UT_IDSIZE: usize = 4;
|
||||||
pub const UT_HOSTSIZE: uint = 256;
|
pub const UT_HOSTSIZE: usize = 256;
|
||||||
|
|
||||||
pub const EMPTY: libc::c_short = 0;
|
pub const EMPTY: libc::c_short = 0;
|
||||||
pub const RUN_LVL: libc::c_short = 1;
|
pub const RUN_LVL: libc::c_short = 1;
|
||||||
|
@ -56,10 +56,10 @@ mod utmpx {
|
||||||
|
|
||||||
pub static DEFAULT_FILE: &'static str = "/var/run/utmpx";
|
pub static DEFAULT_FILE: &'static str = "/var/run/utmpx";
|
||||||
|
|
||||||
pub const UT_LINESIZE: uint = 32;
|
pub const UT_LINESIZE: usize = 32;
|
||||||
pub const UT_NAMESIZE: uint = 256;
|
pub const UT_NAMESIZE: usize = 256;
|
||||||
pub const UT_IDSIZE: uint = 4;
|
pub const UT_IDSIZE: usize = 4;
|
||||||
pub const UT_HOSTSIZE: uint = 256;
|
pub const UT_HOSTSIZE: usize = 256;
|
||||||
|
|
||||||
pub const EMPTY: libc::c_short = 0;
|
pub const EMPTY: libc::c_short = 0;
|
||||||
pub const RUN_LVL: libc::c_short = 1;
|
pub const RUN_LVL: libc::c_short = 1;
|
||||||
|
@ -97,10 +97,10 @@ mod utmpx {
|
||||||
|
|
||||||
pub static DEFAULT_FILE : &'static str = "";
|
pub static DEFAULT_FILE : &'static str = "";
|
||||||
|
|
||||||
pub const UT_LINESIZE : uint = 16;
|
pub const UT_LINESIZE : usize = 16;
|
||||||
pub const UT_NAMESIZE : uint = 32;
|
pub const UT_NAMESIZE : usize = 32;
|
||||||
pub const UT_IDSIZE : uint = 8;
|
pub const UT_IDSIZE : usize = 8;
|
||||||
pub const UT_HOSTSIZE : uint = 128;
|
pub const UT_HOSTSIZE : usize = 128;
|
||||||
|
|
||||||
pub const EMPTY : libc::c_short = 0;
|
pub const EMPTY : libc::c_short = 0;
|
||||||
pub const BOOT_TIME : libc::c_short = 1;
|
pub const BOOT_TIME : libc::c_short = 1;
|
||||||
|
|
|
@ -4,14 +4,14 @@ use std::io::{IoResult, IoError};
|
||||||
pub struct BufReader<R> {
|
pub struct BufReader<R> {
|
||||||
reader: R,
|
reader: R,
|
||||||
buffer: [u8; 4096],
|
buffer: [u8; 4096],
|
||||||
start: uint,
|
start: usize,
|
||||||
end: uint, // exclusive
|
end: usize, // exclusive
|
||||||
}
|
}
|
||||||
|
|
||||||
#[allow(non_snake_case)]
|
#[allow(non_snake_case)]
|
||||||
pub mod Bytes {
|
pub mod Bytes {
|
||||||
pub trait Select {
|
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> {
|
pub enum Selected<'a> {
|
||||||
|
@ -37,7 +37,7 @@ impl<R: Reader> BufReader<R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn read(&mut self) -> IoResult<uint> {
|
fn read(&mut self) -> IoResult<usize> {
|
||||||
let buffer_fill = self.buffer.slice_from_mut(self.end);
|
let buffer_fill = self.buffer.slice_from_mut(self.end);
|
||||||
|
|
||||||
match self.reader.read(buffer_fill) {
|
match self.reader.read(buffer_fill) {
|
||||||
|
@ -50,7 +50,7 @@ impl<R: Reader> BufReader<R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn maybe_fill_buf(&mut self) -> IoResult<uint> {
|
fn maybe_fill_buf(&mut self) -> IoResult<usize> {
|
||||||
if self.end == self.start {
|
if self.end == self.start {
|
||||||
self.start = 0;
|
self.start = 0;
|
||||||
self.end = 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;
|
let mut bytes_consumed = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
|
@ -91,7 +91,7 @@ impl<R: Reader> BufReader<R> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<R: Reader> Bytes::Select for 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() {
|
match self.maybe_fill_buf() {
|
||||||
Err(IoError { kind: std::io::EndOfFile, .. }) => (),
|
Err(IoError { kind: std::io::EndOfFile, .. }) => (),
|
||||||
Err(err) => panic!("read error: {}", err.desc),
|
Err(err) => panic!("read error: {}", err.desc),
|
||||||
|
|
|
@ -53,7 +53,7 @@ fn list_to_ranges(list: &str, complement: bool) -> Result<Vec<Range>, String> {
|
||||||
|
|
||||||
fn cut_bytes<R: Reader>(reader: R,
|
fn cut_bytes<R: Reader>(reader: R,
|
||||||
ranges: &Vec<Range>,
|
ranges: &Vec<Range>,
|
||||||
opts: &Options) -> int {
|
opts: &Options) -> isize {
|
||||||
use buffer::Bytes::Select;
|
use buffer::Bytes::Select;
|
||||||
use buffer::Bytes::Selected::{NewlineFound, Complete, Partial, EndOfFile};
|
use buffer::Bytes::Selected::{NewlineFound, Complete, Partial, EndOfFile};
|
||||||
|
|
||||||
|
@ -134,7 +134,7 @@ fn cut_bytes<R: Reader>(reader: R,
|
||||||
|
|
||||||
fn cut_characters<R: Reader>(reader: R,
|
fn cut_characters<R: Reader>(reader: R,
|
||||||
ranges: &Vec<Range>,
|
ranges: &Vec<Range>,
|
||||||
opts: &Options) -> int {
|
opts: &Options) -> isize {
|
||||||
let mut buf_in = BufferedReader::new(reader);
|
let mut buf_in = BufferedReader::new(reader);
|
||||||
let mut out = BufferedWriter::new(stdio::stdout_raw());
|
let mut out = BufferedWriter::new(stdio::stdout_raw());
|
||||||
|
|
||||||
|
@ -195,7 +195,7 @@ fn cut_characters<R: Reader>(reader: R,
|
||||||
struct Searcher<'a> {
|
struct Searcher<'a> {
|
||||||
haystack: &'a [u8],
|
haystack: &'a [u8],
|
||||||
needle: &'a [u8],
|
needle: &'a [u8],
|
||||||
position: uint
|
position: usize
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Searcher<'a> {
|
impl<'a> Searcher<'a> {
|
||||||
|
@ -209,9 +209,9 @@ impl<'a> Searcher<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> Iterator for 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 {
|
if self.needle.len() == 1 {
|
||||||
for offset in range(self.position, self.haystack.len()) {
|
for offset in range(self.position, self.haystack.len()) {
|
||||||
if self.haystack[offset] == self.needle[0] {
|
if self.haystack[offset] == self.needle[0] {
|
||||||
|
@ -242,7 +242,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
|
||||||
ranges: &Vec<Range>,
|
ranges: &Vec<Range>,
|
||||||
delim: &String,
|
delim: &String,
|
||||||
only_delimited: bool,
|
only_delimited: bool,
|
||||||
out_delim: &String) -> int {
|
out_delim: &String) -> isize {
|
||||||
let mut buf_in = BufferedReader::new(reader);
|
let mut buf_in = BufferedReader::new(reader);
|
||||||
let mut out = BufferedWriter::new(stdio::stdout_raw());
|
let mut out = BufferedWriter::new(stdio::stdout_raw());
|
||||||
|
|
||||||
|
@ -316,7 +316,7 @@ fn cut_fields_delimiter<R: Reader>(reader: R,
|
||||||
|
|
||||||
fn cut_fields<R: Reader>(reader: R,
|
fn cut_fields<R: Reader>(reader: R,
|
||||||
ranges: &Vec<Range>,
|
ranges: &Vec<Range>,
|
||||||
opts: &FieldOptions) -> int {
|
opts: &FieldOptions) -> isize {
|
||||||
match opts.out_delimeter {
|
match opts.out_delimeter {
|
||||||
Some(ref delim) => {
|
Some(ref delim) => {
|
||||||
return cut_fields_delimiter(reader, ranges, &opts.delimiter,
|
return cut_fields_delimiter(reader, ranges, &opts.delimiter,
|
||||||
|
@ -395,7 +395,7 @@ fn cut_fields<R: Reader>(reader: R,
|
||||||
0
|
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 stdin_read = false;
|
||||||
let mut exit_code = 0;
|
let mut exit_code = 0;
|
||||||
|
|
||||||
|
|
|
@ -11,31 +11,31 @@ use std;
|
||||||
|
|
||||||
#[derive(PartialEq,Eq,PartialOrd,Ord,Show)]
|
#[derive(PartialEq,Eq,PartialOrd,Ord,Show)]
|
||||||
pub struct Range {
|
pub struct Range {
|
||||||
pub low: uint,
|
pub low: usize,
|
||||||
pub high: uint,
|
pub high: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::str::FromStr for Range {
|
impl std::str::FromStr for Range {
|
||||||
fn from_str(s: &str) -> Option<Range> {
|
fn from_str(s: &str) -> Option<Range> {
|
||||||
use std::uint::MAX;
|
use std::usize::MAX;
|
||||||
|
|
||||||
let mut parts = s.splitn(1, '-');
|
let mut parts = s.splitn(1, '-');
|
||||||
|
|
||||||
match (parts.next(), parts.next()) {
|
match (parts.next(), parts.next()) {
|
||||||
(Some(nm), None) => {
|
(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 })
|
.map(|nm| Range { low: nm, high: nm })
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) if m.len() == 0 => {
|
(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 })
|
.map(|low| Range { low: low, high: MAX })
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) if n.len() == 0 => {
|
(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 })
|
.map(|high| Range { low: 1, high: high })
|
||||||
}
|
}
|
||||||
(Some(n), Some(m)) => {
|
(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(low), Some(high)) if low > 0 && low <= high => {
|
||||||
Some(Range { low: low, high: high })
|
Some(Range { low: low, high: high })
|
||||||
}
|
}
|
||||||
|
@ -77,7 +77,7 @@ impl Range {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn complement(ranges: &Vec<Range>) -> Vec<Range> {
|
pub fn complement(ranges: &Vec<Range>) -> Vec<Range> {
|
||||||
use std::uint;
|
use std::usize;
|
||||||
|
|
||||||
let mut complements = Vec::with_capacity(ranges.len() + 1);
|
let mut complements = Vec::with_capacity(ranges.len() + 1);
|
||||||
|
|
||||||
|
@ -97,10 +97,10 @@ pub fn complement(ranges: &Vec<Range>) -> Vec<Range> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Some(last), None) => {
|
(Some(last), None) => {
|
||||||
if last.high < uint::MAX {
|
if last.high < usize::MAX {
|
||||||
complements.push(Range {
|
complements.push(Range {
|
||||||
low: last.high + 1,
|
low: last.high + 1,
|
||||||
high: uint::MAX
|
high: usize::MAX
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@ static VERSION: &'static str = "1.0.0";
|
||||||
struct Options {
|
struct Options {
|
||||||
all: bool,
|
all: bool,
|
||||||
program_name: String,
|
program_name: String,
|
||||||
max_depth: Option<uint>,
|
max_depth: Option<usize>,
|
||||||
total: bool,
|
total: bool,
|
||||||
separate_dirs: bool,
|
separate_dirs: bool,
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,7 @@ struct Stat {
|
||||||
}
|
}
|
||||||
// this takes `my_stat` to avoid having to stat files multiple times.
|
// this takes `my_stat` to avoid having to stat files multiple times.
|
||||||
fn du(path: &Path, mut my_stat: Stat,
|
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 stats = vec!();
|
||||||
let mut futures = vec!();
|
let mut futures = vec!();
|
||||||
|
|
||||||
|
@ -193,7 +193,7 @@ ers of 1000).",
|
||||||
let summarize = matches.opt_present("summarize");
|
let summarize = matches.opt_present("summarize");
|
||||||
|
|
||||||
let max_depth_str = matches.opt_str("max-depth");
|
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) {
|
match (max_depth_str, max_depth) {
|
||||||
(Some(ref s), _) if summarize => {
|
(Some(ref s), _) if summarize => {
|
||||||
show_error!("summarizing conflicts with --max-depth={}", *s);
|
show_error!("summarizing conflicts with --max-depth={}", *s);
|
||||||
|
@ -245,7 +245,7 @@ ers of 1000).",
|
||||||
letters.push(c);
|
letters.push(c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let number = numbers.parse::<uint>().unwrap();
|
let number = numbers.parse::<usize>().unwrap();
|
||||||
let multiple = match letters.as_slice() {
|
let multiple = match letters.as_slice() {
|
||||||
"K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024,
|
"K" => 1024, "M" => 1024 * 1024, "G" => 1024 * 1024 * 1024,
|
||||||
"T" => 1024 * 1024 * 1024 * 1024, "P" => 1024 * 1024 * 1024 * 1024 * 1024,
|
"T" => 1024 * 1024 * 1024 * 1024, "P" => 1024 * 1024 * 1024 * 1024 * 1024,
|
||||||
|
|
|
@ -30,8 +30,8 @@ struct EchoOptions {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn to_char(bytes: &Vec<u8>, base: uint) -> char {
|
fn to_char(bytes: &Vec<u8>, base: usize) -> char {
|
||||||
from_str_radix::<uint>(from_utf8(bytes.as_slice()).unwrap(), base).unwrap() as u8 as char
|
from_str_radix::<usize>(from_utf8(bytes.as_slice()).unwrap(), base).unwrap() as u8 as char
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
|
@ -51,19 +51,19 @@ fn isodigit(c: u8) -> bool {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn convert_str(string: &[u8], index: uint, base: uint) -> (char, uint) {
|
fn convert_str(string: &[u8], index: usize, base: usize) -> (char, usize) {
|
||||||
let (max_digits, is_legal_digit) : (uint, fn(u8) -> bool) = match base {
|
let (max_digits, is_legal_digit) : (usize, fn(u8) -> bool) = match base {
|
||||||
8u => (3, isodigit),
|
8us => (3, isodigit),
|
||||||
16u => (2, isxdigit),
|
16us => (2, isxdigit),
|
||||||
_ => panic!(),
|
_ => panic!(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut bytes = vec!();
|
let mut bytes = vec!();
|
||||||
for offset in range(0u, max_digits) {
|
for offset in range(0us, max_digits) {
|
||||||
if string.len() <= index + offset as uint {
|
if string.len() <= index + offset as usize {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
let c = string[index + offset as uint];
|
let c = string[index + offset as usize];
|
||||||
if is_legal_digit(c) {
|
if is_legal_digit(c) {
|
||||||
bytes.push(c as u8);
|
bytes.push(c as u8);
|
||||||
} else {
|
} else {
|
||||||
|
@ -201,7 +201,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
't' => print!("\t"),
|
't' => print!("\t"),
|
||||||
'v' => print!("\x0B"),
|
'v' => print!("\x0B"),
|
||||||
'x' => {
|
'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 {
|
if num_char_used == 0 {
|
||||||
print!("\\x");
|
print!("\\x");
|
||||||
} else {
|
} else {
|
||||||
|
@ -212,7 +212,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
'0' => {
|
'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 {
|
if num_char_used == 0 {
|
||||||
print!("\0");
|
print!("\0");
|
||||||
} else {
|
} else {
|
||||||
|
@ -223,7 +223,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 {
|
if num_char_used == 0 {
|
||||||
print!("\\{}", c);
|
print!("\\{}", c);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -22,17 +22,17 @@ mod util;
|
||||||
static NAME: &'static str = "expand";
|
static NAME: &'static str = "expand";
|
||||||
static VERSION: &'static str = "0.0.1";
|
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 words = s.as_slice().split(',').collect::<Vec<&str>>();
|
||||||
|
|
||||||
let nums = words.into_iter()
|
let nums = words.into_iter()
|
||||||
.map(|sn| sn.parse::<uint>()
|
.map(|sn| sn.parse::<usize>()
|
||||||
.unwrap_or_else(
|
.unwrap_or_else(
|
||||||
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
|| crash!(1, "{}\n", "tab size contains invalid character(s)"))
|
||||||
)
|
)
|
||||||
.collect::<Vec<uint>>();
|
.collect::<Vec<usize>>();
|
||||||
|
|
||||||
if nums.iter().any(|&n| n == 0) {
|
if nums.iter().any(|&n| n == 0) {
|
||||||
crash!(1, "{}\n", "tab size cannot be 0");
|
crash!(1, "{}\n", "tab size cannot be 0");
|
||||||
|
@ -48,7 +48,7 @@ fn tabstops_parse(s: String) -> Vec<uint> {
|
||||||
|
|
||||||
struct Options {
|
struct Options {
|
||||||
files: Vec<String>,
|
files: Vec<String>,
|
||||||
tabstops: Vec<uint>,
|
tabstops: Vec<usize>,
|
||||||
iflag: bool
|
iflag: bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -117,7 +117,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() {
|
match tabstops.as_slice() {
|
||||||
[tabstop] => tabstop - col % tabstop,
|
[tabstop] => tabstop - col % tabstop,
|
||||||
tabstops => match tabstops.iter().skip_while(|&t| *t <= col).next() {
|
tabstops => match tabstops.iter().skip_while(|&t| *t <= col).next() {
|
||||||
|
|
|
@ -49,9 +49,9 @@ struct FmtOptions {
|
||||||
xanti_prefix : bool,
|
xanti_prefix : bool,
|
||||||
uniform : bool,
|
uniform : bool,
|
||||||
quick : bool,
|
quick : bool,
|
||||||
width : uint,
|
width : usize,
|
||||||
goal : uint,
|
goal : usize,
|
||||||
tabwidth : uint,
|
tabwidth : usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> isize {
|
pub fn uumain(args: Vec<String>) -> isize {
|
||||||
|
@ -140,7 +140,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
match matches.opt_str("w") {
|
match matches.opt_str("w") {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.width =
|
fmt_opts.width =
|
||||||
match s.parse::<uint>() {
|
match s.parse::<usize>() {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
|
None => { crash!(1, "Invalid WIDTH specification: `{}'", s); }
|
||||||
};
|
};
|
||||||
|
@ -152,7 +152,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
match matches.opt_str("g") {
|
match matches.opt_str("g") {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.goal =
|
fmt_opts.goal =
|
||||||
match s.parse::<uint>() {
|
match s.parse::<usize>() {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
|
None => { crash!(1, "Invalid GOAL specification: `{}'", s); }
|
||||||
};
|
};
|
||||||
|
@ -168,7 +168,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
match matches.opt_str("T") {
|
match matches.opt_str("T") {
|
||||||
Some(s) => {
|
Some(s) => {
|
||||||
fmt_opts.tabwidth =
|
fmt_opts.tabwidth =
|
||||||
match s.parse::<uint>() {
|
match s.parse::<usize>() {
|
||||||
Some(t) => t,
|
Some(t) => t,
|
||||||
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
|
None => { crash!(1, "Invalid TABWIDTH specification: `{}'", s); }
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,16 +16,16 @@ use std::mem;
|
||||||
|
|
||||||
struct BreakArgs<'a> {
|
struct BreakArgs<'a> {
|
||||||
opts : &'a FmtOptions,
|
opts : &'a FmtOptions,
|
||||||
init_len : uint,
|
init_len : usize,
|
||||||
indent_str : &'a str,
|
indent_str : &'a str,
|
||||||
indent_len : uint,
|
indent_len : usize,
|
||||||
uniform : bool,
|
uniform : bool,
|
||||||
ostream : &'a mut Box<Writer+'static>
|
ostream : &'a mut Box<Writer+'static>
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> BreakArgs<'a> {
|
impl<'a> BreakArgs<'a> {
|
||||||
#[inline(always)]
|
#[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 {
|
if fresh {
|
||||||
0
|
0
|
||||||
} else {
|
} else {
|
||||||
|
@ -100,7 +100,7 @@ fn break_simple<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &mut BreakArgs
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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
|
// 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);
|
let wlen = winfo.word_nchars + args.compute_width(winfo, l, false);
|
||||||
|
|
||||||
|
@ -174,12 +174,12 @@ fn break_knuth_plass<'a, T: Clone + Iterator<&'a WordInfo<'a>>>(mut iter: T, arg
|
||||||
}
|
}
|
||||||
|
|
||||||
struct LineBreak<'a> {
|
struct LineBreak<'a> {
|
||||||
prev : uint,
|
prev : usize,
|
||||||
linebreak : Option<&'a WordInfo<'a>>,
|
linebreak : Option<&'a WordInfo<'a>>,
|
||||||
break_before : bool,
|
break_before : bool,
|
||||||
demerits : i64,
|
demerits : i64,
|
||||||
prev_rat : f32,
|
prev_rat : f32,
|
||||||
length : uint,
|
length : usize,
|
||||||
fresh : bool
|
fresh : bool
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
|
||||||
let next_active_breaks = &mut vec!();
|
let next_active_breaks = &mut vec!();
|
||||||
|
|
||||||
let stretch = (args.opts.width - args.opts.goal) as int;
|
let stretch = (args.opts.width - args.opts.goal) as int;
|
||||||
let minlength = args.opts.goal - stretch as uint;
|
let minlength = args.opts.goal - stretch as usize;
|
||||||
let mut new_linebreaks = vec!();
|
let mut new_linebreaks = vec!();
|
||||||
let mut is_sentence_start = false;
|
let mut is_sentence_start = false;
|
||||||
let mut least_demerits = 0;
|
let mut least_demerits = 0;
|
||||||
|
@ -311,7 +311,7 @@ fn find_kp_breakpoints<'a, T: Iterator<&'a WordInfo<'a>>>(iter: T, args: &BreakA
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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!();
|
let mut breakwords = vec!();
|
||||||
// of the active paths, we select the one with the fewest demerits
|
// 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) {
|
let mut best_idx = match active.iter().min_by(|&&a| paths[a].demerits) {
|
||||||
|
@ -378,7 +378,7 @@ fn compute_demerits(delta_len: int, stretch: int, wlen: int, prev_rat: f32) -> (
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline(always)]
|
#[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) =
|
let (break_before, line_length) =
|
||||||
if active.fresh {
|
if active.fresh {
|
||||||
// never break before a word if that word would be the first on a line
|
// never break before a word if that word would be the first on a line
|
||||||
|
@ -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.
|
// Number of spaces to add before a word, based on mode, newline, sentence start.
|
||||||
#[inline(always)]
|
#[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 uniform || newline {
|
||||||
if start || (newline && punct) {
|
if start || (newline && punct) {
|
||||||
2
|
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.
|
// If we're on a fresh line, slen=0 and we slice off leading whitespace.
|
||||||
// Otherwise, compute slen and leave whitespace alone.
|
// Otherwise, compute slen and leave whitespace alone.
|
||||||
#[inline(always)]
|
#[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 {
|
if fresh {
|
||||||
(0, word.slice_from(start))
|
(0, word.slice_from(start))
|
||||||
} else {
|
} else {
|
||||||
|
@ -442,7 +442,7 @@ fn write_newline(indent: &str, ostream: &mut Box<Writer>) {
|
||||||
|
|
||||||
// Write the word, along with slen spaces.
|
// Write the word, along with slen spaces.
|
||||||
#[inline(always)]
|
#[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 {
|
if slen == 2 {
|
||||||
silent_unwrap!(ostream.write(" ".as_bytes()));
|
silent_unwrap!(ostream.write(" ".as_bytes()));
|
||||||
} else if slen == 1 {
|
} else if slen == 1 {
|
||||||
|
|
|
@ -15,8 +15,8 @@ use FileOrStdReader;
|
||||||
use FmtOptions;
|
use FmtOptions;
|
||||||
|
|
||||||
#[inline(always)]
|
#[inline(always)]
|
||||||
fn char_width(c: char) -> uint {
|
fn char_width(c: char) -> usize {
|
||||||
if (c as uint) < 0xA0 {
|
if (c as usize) < 0xA0 {
|
||||||
// if it is ASCII, call it exactly 1 wide (including control chars)
|
// if it is ASCII, call it exactly 1 wide (including control chars)
|
||||||
// calling control chars' widths 1 is consistent with OpenBSD fmt
|
// calling control chars' widths 1 is consistent with OpenBSD fmt
|
||||||
1
|
1
|
||||||
|
@ -59,10 +59,10 @@ impl Line {
|
||||||
#[derive(Show)]
|
#[derive(Show)]
|
||||||
struct FileLine {
|
struct FileLine {
|
||||||
line : String,
|
line : String,
|
||||||
indent_end : uint, // the end of the indent, always the start of the text
|
indent_end : usize, // 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
|
pfxind_end : usize, // 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
|
indent_len : usize, // display length of indent taking into account tabs
|
||||||
prefix_len : uint, // PREFIX indent length taking into account tabs
|
prefix_len : usize, // PREFIX indent length taking into account tabs
|
||||||
}
|
}
|
||||||
|
|
||||||
// iterator that produces a stream of Lines from a file
|
// iterator that produces a stream of Lines from a file
|
||||||
|
@ -77,7 +77,7 @@ impl<'a> FileLines<'a> {
|
||||||
}
|
}
|
||||||
|
|
||||||
// returns true if this line should be formatted
|
// returns true if this line should be formatted
|
||||||
fn match_prefix(&self, line: &str) -> (bool, uint) {
|
fn match_prefix(&self, line: &str) -> (bool, usize) {
|
||||||
if !self.opts.use_prefix { return (true, 0u); }
|
if !self.opts.use_prefix { return (true, 0u); }
|
||||||
|
|
||||||
FileLines::match_prefix_generic(self.opts.prefix.as_slice(), line, self.opts.xprefix)
|
FileLines::match_prefix_generic(self.opts.prefix.as_slice(), line, self.opts.xprefix)
|
||||||
|
@ -93,7 +93,7 @@ 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) {
|
if line.starts_with(pfx) {
|
||||||
return (true, 0);
|
return (true, 0);
|
||||||
}
|
}
|
||||||
|
@ -112,7 +112,7 @@ impl<'a> FileLines<'a> {
|
||||||
(false, 0)
|
(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 prefix_len = 0;
|
||||||
let mut indent_len = 0;
|
let mut indent_len = 0;
|
||||||
let mut indent_end = 0;
|
let mut indent_end = 0;
|
||||||
|
@ -199,11 +199,11 @@ impl<'a> Iterator<Line> for FileLines<'a> {
|
||||||
pub struct Paragraph {
|
pub struct Paragraph {
|
||||||
lines : Vec<String>, // the lines of the file
|
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_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
|
pub init_len : usize, // printable length of the init string considering TABWIDTH
|
||||||
init_end : uint, // byte location of end of init in first line String
|
init_end : usize, // byte location of end of init in first line String
|
||||||
pub indent_str : String, // string representing indent
|
pub indent_str : String, // string representing indent
|
||||||
pub indent_len : uint, // length of above
|
pub indent_len : usize, // length of above
|
||||||
indent_end : uint, // byte location of end of indent (in crown and tagged mode, only applies to 2nd line and onward)
|
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
|
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 +243,7 @@ impl<'a> ParagraphStream<'a> {
|
||||||
// header field must be nonzero length
|
// header field must be nonzero length
|
||||||
if colon_posn == 0 { return false; }
|
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,
|
y if y < 33 || y > 126 => false,
|
||||||
_ => true
|
_ => true
|
||||||
});
|
});
|
||||||
|
@ -446,13 +446,13 @@ impl<'a> ParaWords<'a> {
|
||||||
struct WordSplit<'a> {
|
struct WordSplit<'a> {
|
||||||
opts : &'a FmtOptions,
|
opts : &'a FmtOptions,
|
||||||
string : &'a str,
|
string : &'a str,
|
||||||
length : uint,
|
length : usize,
|
||||||
position : uint,
|
position : usize,
|
||||||
prev_punct : bool
|
prev_punct : bool
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'a> WordSplit<'a> {
|
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)
|
// 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
|
// if there are no tabs, beforetab = -1 and aftertab is the printed length
|
||||||
let mut beforetab = None;
|
let mut beforetab = None;
|
||||||
|
@ -494,10 +494,10 @@ impl<'a> WordSplit<'a> {
|
||||||
|
|
||||||
pub struct WordInfo<'a> {
|
pub struct WordInfo<'a> {
|
||||||
pub word : &'a str,
|
pub word : &'a str,
|
||||||
pub word_start : uint,
|
pub word_start : usize,
|
||||||
pub word_nchars : uint,
|
pub word_nchars : usize,
|
||||||
pub before_tab : Option<uint>,
|
pub before_tab : Option<usize>,
|
||||||
pub after_tab : uint,
|
pub after_tab : usize,
|
||||||
pub sentence_start : bool,
|
pub sentence_start : bool,
|
||||||
pub ends_punct : bool,
|
pub ends_punct : bool,
|
||||||
pub new_line : bool
|
pub new_line : bool
|
||||||
|
|
|
@ -62,7 +62,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let width = match poss_width {
|
let width = match poss_width {
|
||||||
Some(inp_width) => match inp_width.parse::<uint>() {
|
Some(inp_width) => match inp_width.parse::<usize>() {
|
||||||
Some(width) => width,
|
Some(width) => width,
|
||||||
None => crash!(1, "illegal width value (\"{}\")", inp_width)
|
None => crash!(1, "illegal width value (\"{}\")", inp_width)
|
||||||
},
|
},
|
||||||
|
@ -91,7 +91,7 @@ fn handle_obsolete(args: &[String]) -> (Vec<String>, Option<String>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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() {
|
for filename in filenames.iter() {
|
||||||
let filename: &str = filename.as_slice();
|
let filename: &str = filename.as_slice();
|
||||||
let mut stdin_buf;
|
let mut stdin_buf;
|
||||||
|
@ -110,7 +110,7 @@ fn fold(filenames: Vec<String>, bytes: bool, spaces: bool, width: uint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[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;
|
let mut file = file;
|
||||||
for line in file.lines() {
|
for line in file.lines() {
|
||||||
let line_string = safe_unwrap!(line);
|
let line_string = safe_unwrap!(line);
|
||||||
|
@ -156,7 +156,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
|
||||||
match rfind_whitespace(slice) {
|
match rfind_whitespace(slice) {
|
||||||
Some(m) => {
|
Some(m) => {
|
||||||
let routput = slice.slice_chars(m + 1, slice.chars().count());
|
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 {
|
out + match ch {
|
||||||
'\t' => 8,
|
'\t' => 8,
|
||||||
'\x08' => if out > 0 { -1 } else { 0 },
|
'\x08' => if out > 0 { -1 } else { 0 },
|
||||||
|
@ -215,7 +215,7 @@ fn fold_file<T: io::Reader>(file: BufferedReader<T>, bytes: bool, spaces: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
fn rfind_whitespace(slice: &str) -> Option<uint> {
|
fn rfind_whitespace(slice: &str) -> Option<usize> {
|
||||||
for (i, ch) in slice.chars().rev().enumerate() {
|
for (i, ch) in slice.chars().rev().enumerate() {
|
||||||
if ch.is_whitespace() {
|
if ch.is_whitespace() {
|
||||||
return Some(slice.chars().count() - (i + 1));
|
return Some(slice.chars().count() - (i + 1));
|
||||||
|
|
|
@ -27,8 +27,8 @@ mod util;
|
||||||
static NAME: &'static str = "head";
|
static NAME: &'static str = "head";
|
||||||
|
|
||||||
pub fn uumain(args: Vec<String>) -> isize {
|
pub fn uumain(args: Vec<String>) -> isize {
|
||||||
let mut line_count = 10u;
|
let mut line_count = 10us;
|
||||||
let mut byte_count = 0u;
|
let mut byte_count = 0us;
|
||||||
|
|
||||||
// handle obsolete -number syntax
|
// handle obsolete -number syntax
|
||||||
let options = match obsolete(args.tail()) {
|
let options = match obsolete(args.tail()) {
|
||||||
|
@ -68,7 +68,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
show_error!("cannot specify both --bytes and --lines.");
|
show_error!("cannot specify both --bytes and --lines.");
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
match n.parse::<uint>() {
|
match n.parse::<usize>() {
|
||||||
Some(m) => { line_count = m }
|
Some(m) => { line_count = m }
|
||||||
None => {
|
None => {
|
||||||
show_error!("invalid line count '{}'", n);
|
show_error!("invalid line count '{}'", n);
|
||||||
|
@ -77,7 +77,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
None => match given_options.opt_str("c") {
|
None => match given_options.opt_str("c") {
|
||||||
Some(count) => match count.parse::<uint>() {
|
Some(count) => match count.parse::<usize>() {
|
||||||
Some(m) => byte_count = m,
|
Some(m) => byte_count = m,
|
||||||
None => {
|
None => {
|
||||||
show_error!("invalid byte count '{}'", count);
|
show_error!("invalid byte count '{}'", count);
|
||||||
|
@ -131,7 +131,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
//
|
//
|
||||||
// In case is found, the options vector will get rid of that object so that
|
// In case is found, the options vector will get rid of that object so that
|
||||||
// getopts works correctly.
|
// 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 options: Vec<String> = options.to_vec();
|
||||||
let mut a = 0;
|
let mut a = 0;
|
||||||
let b = options.len();
|
let b = options.len();
|
||||||
|
@ -149,7 +149,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
|
||||||
// If this is the last number
|
// If this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
options.remove(a);
|
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()));
|
return (options, Some(number.unwrap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -162,7 +162,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: handle errors on read
|
// 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 {
|
if use_bytes {
|
||||||
for byte in reader.bytes().take(count) {
|
for byte in reader.bytes().take(count) {
|
||||||
if !pipe_print!("{}", byte.unwrap() as char) {
|
if !pipe_print!("{}", byte.unwrap() as char) {
|
||||||
|
|
|
@ -33,7 +33,7 @@ mod util;
|
||||||
static NAME: &'static str = "hostid";
|
static NAME: &'static str = "hostid";
|
||||||
static VERSION: &'static str = "0.0.1";
|
static VERSION: &'static str = "0.0.1";
|
||||||
|
|
||||||
static EXIT_ERR: int = 1;
|
static EXIT_ERR: isize = 1;
|
||||||
|
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
HostId,
|
HostId,
|
||||||
|
|
|
@ -130,7 +130,7 @@ fn help_menu(program: &str, options: &[getopts::OptGroup]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn xgethostname() -> String {
|
fn xgethostname() -> String {
|
||||||
let namelen = 256u;
|
let namelen = 256us;
|
||||||
let mut name : Vec<u8> = repeat(0).take(namelen).collect();
|
let mut name : Vec<u8> = repeat(0).take(namelen).collect();
|
||||||
let err = unsafe {
|
let err = unsafe {
|
||||||
gethostname (name.as_mut_ptr() as *mut libc::c_char,
|
gethostname (name.as_mut_ptr() as *mut libc::c_char,
|
||||||
|
|
|
@ -39,8 +39,8 @@ mod signals;
|
||||||
static NAME: &'static str = "kill";
|
static NAME: &'static str = "kill";
|
||||||
static VERSION: &'static str = "0.0.1";
|
static VERSION: &'static str = "0.0.1";
|
||||||
|
|
||||||
static EXIT_OK: int = 0;
|
static EXIT_OK: isize = 0;
|
||||||
static EXIT_ERR: int = 1;
|
static EXIT_ERR: isize = 1;
|
||||||
|
|
||||||
pub enum Mode {
|
pub enum Mode {
|
||||||
Kill,
|
Kill,
|
||||||
|
@ -184,7 +184,7 @@ fn help(progname: &str, usage: &str) {
|
||||||
println!("{}", get_help_text(progname, usage));
|
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 mut status = 0;
|
||||||
let optional_signal_value = signals::signal_by_name_or_value(signalname);
|
let optional_signal_value = signals::signal_by_name_or_value(signalname);
|
||||||
let signal_value = match optional_signal_value {
|
let signal_value = match optional_signal_value {
|
||||||
|
@ -194,7 +194,7 @@ fn kill(signalname: &str, pids: std::vec::Vec<String>) -> int {
|
||||||
for pid in pids.iter() {
|
for pid in pids.iter() {
|
||||||
match pid.as_slice().parse() {
|
match pid.as_slice().parse() {
|
||||||
Some(x) => {
|
Some(x) => {
|
||||||
let result = Process::kill(x, signal_value as int);
|
let result = Process::kill(x, signal_value as isize);
|
||||||
match result {
|
match result {
|
||||||
Ok(_) => (),
|
Ok(_) => (),
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
|
|
|
@ -93,7 +93,7 @@ fn print_help(opts: &[getopts::OptGroup]) {
|
||||||
/**
|
/**
|
||||||
* Create the list of new directories
|
* 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 result = Ok(());
|
||||||
|
|
||||||
let mut parent_dirs = Vec::new();
|
let mut parent_dirs = Vec::new();
|
||||||
|
|
|
@ -186,7 +186,7 @@ fn help(progname: &str, usage: &str) {
|
||||||
println!("{}", msg);
|
println!("{}", msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
fn exec(files: &[Path], b: Behaviour) -> int {
|
fn exec(files: &[Path], b: Behaviour) -> isize {
|
||||||
match b.target_dir {
|
match b.target_dir {
|
||||||
Some(ref name) => return move_files_into_dir(files, &Path::new(name.as_slice()), &b),
|
Some(ref name) => return move_files_into_dir(files, &Path::new(name.as_slice()), &b),
|
||||||
None => {}
|
None => {}
|
||||||
|
@ -244,7 +244,7 @@ fn exec(files: &[Path], b: Behaviour) -> int {
|
||||||
0
|
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() {
|
if !target_dir.is_dir() {
|
||||||
show_error!("target ‘{}’ is not a directory", target_dir.display());
|
show_error!("target ‘{}’ is not a directory", target_dir.display());
|
||||||
return 1;
|
return 1;
|
||||||
|
|
|
@ -83,7 +83,7 @@ pub fn parse_options(settings: &mut ::Settings, opts: &getopts::Matches) -> Vec<
|
||||||
match opts.opt_str("w") {
|
match opts.opt_str("w") {
|
||||||
None => {}
|
None => {}
|
||||||
Some(val) => {
|
Some(val) => {
|
||||||
let conv: Option<uint> = val.as_slice().parse();
|
let conv: Option<usize> = val.as_slice().parse();
|
||||||
match conv {
|
match conv {
|
||||||
None => {
|
None => {
|
||||||
errs.push(String::from_str("Illegal value for -w"));
|
errs.push(String::from_str("Illegal value for -w"));
|
||||||
|
|
|
@ -42,7 +42,7 @@ struct Settings {
|
||||||
starting_line_number: u64,
|
starting_line_number: u64,
|
||||||
line_increment: u64,
|
line_increment: u64,
|
||||||
join_blank_lines: 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)
|
// The format of the number and the (default value for)
|
||||||
// renumbering each page.
|
// renumbering each page.
|
||||||
number_format: NumberFormat,
|
number_format: NumberFormat,
|
||||||
|
@ -278,7 +278,7 @@ fn nl<T: Reader> (reader: &mut BufferedReader<T>, settings: &Settings) {
|
||||||
// way, start counting empties from zero once more.
|
// way, start counting empties from zero once more.
|
||||||
empty_line_count = 0;
|
empty_line_count = 0;
|
||||||
// A line number is to be printed.
|
// A line number is to be printed.
|
||||||
let mut w: uint = 0;
|
let mut w: usize = 0;
|
||||||
if settings.number_width > line_no_width {
|
if settings.number_width > line_no_width {
|
||||||
w = settings.number_width - line_no_width;
|
w = settings.number_width - line_no_width;
|
||||||
}
|
}
|
||||||
|
|
|
@ -77,7 +77,7 @@ fn resolve_path(path: &str, strip: bool, zero: bool, quiet: bool) -> bool {
|
||||||
Some(x) => x,
|
Some(x) => x,
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut links_left = 256i;
|
let mut links_left = 256is;
|
||||||
|
|
||||||
for part in abs.components() {
|
for part in abs.components() {
|
||||||
result.push(part);
|
result.push(part);
|
||||||
|
|
|
@ -125,7 +125,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: implement one-file-system
|
// 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(());
|
let mut r = Ok(());
|
||||||
|
|
||||||
for filename in files.iter() {
|
for filename in files.iter() {
|
||||||
|
@ -167,7 +167,7 @@ fn remove(files: Vec<String>, force: bool, interactive: InteractiveMode, one_fs:
|
||||||
r
|
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 =
|
let response =
|
||||||
if interactive == InteractiveMode::InteractiveAlways {
|
if interactive == InteractiveMode::InteractiveAlways {
|
||||||
prompt_file(path, name)
|
prompt_file(path, name)
|
||||||
|
@ -187,7 +187,7 @@ fn remove_dir(path: &Path, name: &str, interactive: InteractiveMode, verbose: bo
|
||||||
Ok(())
|
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 =
|
let response =
|
||||||
if interactive == InteractiveMode::InteractiveAlways {
|
if interactive == InteractiveMode::InteractiveAlways {
|
||||||
prompt_file(path, name)
|
prompt_file(path, name)
|
||||||
|
|
|
@ -65,7 +65,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
0
|
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(());
|
let mut r = Ok(());
|
||||||
|
|
||||||
for dir in dirs.iter() {
|
for dir in dirs.iter() {
|
||||||
|
@ -86,7 +86,7 @@ fn remove(dirs: Vec<String>, ignore: bool, parents: bool, verbose: bool) -> Resu
|
||||||
r
|
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) {
|
let mut walk_dir = match fs::walk_dir(path) {
|
||||||
Ok(m) => m,
|
Ok(m) => m,
|
||||||
Err(f) => {
|
Err(f) => {
|
||||||
|
|
|
@ -36,7 +36,7 @@ fn escape_sequences(s: &str) -> String {
|
||||||
replace("\\t", "\t")
|
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 mut seq_args = vec!();
|
||||||
let program = args[0].clone();
|
let program = args[0].clone();
|
||||||
let mut iter = args.into_iter().skip(1);
|
let mut iter = args.into_iter().skip(1);
|
||||||
|
@ -215,8 +215,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) {
|
fn print_seq(first: f64, step: f64, last: f64, largest_dec: usize, separator: String, terminator: String, pad: bool, padding: usize) {
|
||||||
let mut i = 0i;
|
let mut i = 0is;
|
||||||
let mut value = first + i as f64 * step;
|
let mut value = first + i as f64 * step;
|
||||||
while !done_printing(value, step, last) {
|
while !done_printing(value, step, last) {
|
||||||
let istr = value.to_string();
|
let istr = value.to_string();
|
||||||
|
|
|
@ -17,7 +17,7 @@ use std::io;
|
||||||
use std::io::IoResult;
|
use std::io::IoResult;
|
||||||
use std::iter::{range_inclusive, RangeInclusive};
|
use std::iter::{range_inclusive, RangeInclusive};
|
||||||
use std::rand::{self, Rng};
|
use std::rand::{self, Rng};
|
||||||
use std::uint;
|
use std::usize;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -26,7 +26,7 @@ mod util;
|
||||||
enum Mode {
|
enum Mode {
|
||||||
Default,
|
Default,
|
||||||
Echo,
|
Echo,
|
||||||
InputRange(RangeInclusive<uint>)
|
InputRange(RangeInclusive<usize>)
|
||||||
}
|
}
|
||||||
|
|
||||||
static NAME: &'static str = "shuf";
|
static NAME: &'static str = "shuf";
|
||||||
|
@ -95,14 +95,14 @@ With no FILE, or when FILE is -, read standard input.",
|
||||||
let repeat = matches.opt_present("repeat");
|
let repeat = matches.opt_present("repeat");
|
||||||
let zero = matches.opt_present("zero-terminated");
|
let zero = matches.opt_present("zero-terminated");
|
||||||
let count = match matches.opt_str("head-count") {
|
let count = match matches.opt_str("head-count") {
|
||||||
Some(cnt) => match cnt.parse::<uint>() {
|
Some(cnt) => match cnt.parse::<usize>() {
|
||||||
Some(val) => val,
|
Some(val) => val,
|
||||||
None => {
|
None => {
|
||||||
show_error!("'{}' is not a valid count", cnt);
|
show_error!("'{}' is not a valid count", cnt);
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
None => uint::MAX
|
None => usize::MAX
|
||||||
};
|
};
|
||||||
let output = matches.opt_str("output");
|
let output = matches.opt_str("output");
|
||||||
let random = matches.opt_str("random-source");
|
let random = matches.opt_str("random-source");
|
||||||
|
@ -118,7 +118,7 @@ With no FILE, or when FILE is -, read standard input.",
|
||||||
0
|
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 {
|
match mode {
|
||||||
Mode::Echo => shuf_lines(input, repeat, zero, count, output, random),
|
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),
|
Mode::InputRange(range) => shuf_lines(range.map(|num| num.to_string()).collect(), repeat, zero, count, output, random),
|
||||||
|
@ -163,7 +163,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 {
|
let mut output = match outname {
|
||||||
Some(name) => Box::new(io::BufferedWriter::new(try!(io::File::create(&Path::new(name))))) as Box<Writer>,
|
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>
|
None => Box::new(io::stdout()) as Box<Writer>
|
||||||
|
@ -175,7 +175,7 @@ fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, out
|
||||||
let mut len = lines.len();
|
let mut len = lines.len();
|
||||||
let max = if repeat { count } else { cmp::min(count, len) };
|
let max = if repeat { count } else { cmp::min(count, len) };
|
||||||
for _ in range(0, max) {
|
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' }));
|
try!(write!(output, "{}{}", lines[idx], if zero { '\0' } else { '\n' }));
|
||||||
if !repeat {
|
if !repeat {
|
||||||
lines.remove(idx);
|
lines.remove(idx);
|
||||||
|
@ -185,16 +185,16 @@ fn shuf_lines(mut lines: Vec<String>, repeat: bool, zero: bool, count: uint, out
|
||||||
Ok(())
|
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();
|
let split: Vec<&str> = input_range.as_slice().split('-').collect();
|
||||||
if split.len() != 2 {
|
if split.len() != 2 {
|
||||||
Err(("invalid range format".to_string(), 1))
|
Err(("invalid range format".to_string(), 1))
|
||||||
} else {
|
} else {
|
||||||
let begin = match split[0].parse::<uint>() {
|
let begin = match split[0].parse::<usize>() {
|
||||||
Some(m) => m,
|
Some(m) => m,
|
||||||
None => return Err((format!("{} is not a valid number", split[0]), 1))
|
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,
|
Some(m) => m,
|
||||||
None => return Err((format!("{} is not a valid number", split[1]), 1))
|
None => return Err((format!("{} is not a valid number", split[1]), 1))
|
||||||
};
|
};
|
||||||
|
|
|
@ -132,7 +132,7 @@ fn frac_compare(a: &String, b: &String) -> Ordering {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if char_a.is_digit(10) && char_b.is_digit(10) {
|
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) {
|
} else if char_a.is_digit(10) {
|
||||||
skip_zeros(char_a, a_chars, Ordering::Greater)
|
skip_zeros(char_a, a_chars, Ordering::Greater)
|
||||||
} else if char_b.is_digit(10) {
|
} else if char_b.is_digit(10) {
|
||||||
|
|
|
@ -28,7 +28,7 @@ mod platform {
|
||||||
fn sync() -> libc::c_void;
|
fn sync() -> libc::c_void;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn do_sync() -> int {
|
pub unsafe fn do_sync() -> isize {
|
||||||
sync();
|
sync();
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
@ -177,7 +177,7 @@ fn help(program: &str, options: &[getopts::OptGroup]) {
|
||||||
print!("{}", usage("Force changed blocks to disk, update the super block.", options));
|
print!("{}", usage("Force changed blocks to disk, update the super block.", options));
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uusync() -> int {
|
fn uusync() -> isize {
|
||||||
unsafe {
|
unsafe {
|
||||||
platform::do_sync()
|
platform::do_sync()
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,8 +32,8 @@ static VERSION: &'static str = "0.0.1";
|
||||||
pub fn uumain(args: Vec<String>) -> isize {
|
pub fn uumain(args: Vec<String>) -> isize {
|
||||||
let mut beginning = false;
|
let mut beginning = false;
|
||||||
let mut lines = true;
|
let mut lines = true;
|
||||||
let mut byte_count = 0u;
|
let mut byte_count = 0us;
|
||||||
let mut line_count = 10u;
|
let mut line_count = 10us;
|
||||||
let mut sleep_msec = 1000u64;
|
let mut sleep_msec = 1000u64;
|
||||||
|
|
||||||
// handle obsolete -number syntax
|
// handle obsolete -number syntax
|
||||||
|
@ -147,33 +147,33 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_size(mut size_slice: &str) -> Option<uint> {
|
fn parse_size(mut size_slice: &str) -> Option<usize> {
|
||||||
let mut base =
|
let mut base =
|
||||||
if size_slice.len() > 0 && size_slice.char_at(size_slice.len() - 1) == 'B' {
|
if size_slice.len() > 0 && size_slice.char_at(size_slice.len() - 1) == 'B' {
|
||||||
size_slice = size_slice.slice_to(size_slice.len() - 1);
|
size_slice = size_slice.slice_to(size_slice.len() - 1);
|
||||||
1000u
|
1000us
|
||||||
} else {
|
} else {
|
||||||
1024u
|
1024us
|
||||||
};
|
};
|
||||||
let exponent =
|
let exponent =
|
||||||
if size_slice.len() > 0 {
|
if size_slice.len() > 0 {
|
||||||
let mut has_suffix = true;
|
let mut has_suffix = true;
|
||||||
let exp = match size_slice.char_at(size_slice.len() - 1) {
|
let exp = match size_slice.char_at(size_slice.len() - 1) {
|
||||||
'K' => 1u,
|
'K' => 1us,
|
||||||
'M' => 2u,
|
'M' => 2us,
|
||||||
'G' => 3u,
|
'G' => 3us,
|
||||||
'T' => 4u,
|
'T' => 4us,
|
||||||
'P' => 5u,
|
'P' => 5us,
|
||||||
'E' => 6u,
|
'E' => 6us,
|
||||||
'Z' => 7u,
|
'Z' => 7us,
|
||||||
'Y' => 8u,
|
'Y' => 8us,
|
||||||
'b' => {
|
'b' => {
|
||||||
base = 512u;
|
base = 512us;
|
||||||
1u
|
1us
|
||||||
}
|
}
|
||||||
_ => {
|
_ => {
|
||||||
has_suffix = false;
|
has_suffix = false;
|
||||||
0u
|
0us
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
if has_suffix {
|
if has_suffix {
|
||||||
|
@ -181,14 +181,14 @@ fn parse_size(mut size_slice: &str) -> Option<uint> {
|
||||||
}
|
}
|
||||||
exp
|
exp
|
||||||
} else {
|
} else {
|
||||||
0u
|
0us
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut multiplier = 1u;
|
let mut multiplier = 1us;
|
||||||
for _ in range(0u, exponent) {
|
for _ in range(0us, exponent) {
|
||||||
multiplier *= base;
|
multiplier *= base;
|
||||||
}
|
}
|
||||||
if base == 1000u && exponent == 0u {
|
if base == 1000us && exponent == 0us {
|
||||||
// sole B is not a valid suffix
|
// sole B is not a valid suffix
|
||||||
None
|
None
|
||||||
} else {
|
} else {
|
||||||
|
@ -204,7 +204,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
|
// In case is found, the options vector will get rid of that object so that
|
||||||
// getopts works correctly.
|
// 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 options: Vec<String> = options.to_vec();
|
||||||
let mut a = 0;
|
let mut a = 0;
|
||||||
let b = options.len();
|
let b = options.len();
|
||||||
|
@ -222,7 +222,7 @@ fn obsolete(options: &[String]) -> (Vec<String>, Option<uint>) {
|
||||||
// If this is the last number
|
// If this is the last number
|
||||||
if pos == len - 1 {
|
if pos == len - 1 {
|
||||||
options.remove(a);
|
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()));
|
return (options, Some(number.unwrap()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -243,7 +243,7 @@ macro_rules! tail_impl (
|
||||||
let mut data = $reader.$kindfn().skip(
|
let mut data = $reader.$kindfn().skip(
|
||||||
if $beginning {
|
if $beginning {
|
||||||
let temp = $count;
|
let temp = $count;
|
||||||
$count = ::std::uint::MAX;
|
$count = ::std::usize::MAX;
|
||||||
temp - 1
|
temp - 1
|
||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
|
@ -267,7 +267,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 {
|
if lines {
|
||||||
tail_impl!(String, lines, print_string, reader, line_count, beginning);
|
tail_impl!(String, lines, print_string, reader, line_count, beginning);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -39,7 +39,7 @@ pub fn uumain(_: Vec<String>) -> isize {
|
||||||
_ => args.slice(1, args.len()),
|
_ => args.slice(1, args.len()),
|
||||||
};
|
};
|
||||||
let mut error = false;
|
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 {
|
if error {
|
||||||
2
|
2
|
||||||
} else {
|
} else {
|
||||||
|
@ -160,7 +160,7 @@ fn dispatch(args: &mut &[&[u8]], error: &mut bool) -> bool {
|
||||||
val
|
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);
|
let val = two(*args, error);
|
||||||
if *error {
|
if *error {
|
||||||
*error = false;
|
*error = false;
|
||||||
|
@ -170,7 +170,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);
|
let val = three(*args, error);
|
||||||
if *error {
|
if *error {
|
||||||
*error = false;
|
*error = false;
|
||||||
|
@ -180,7 +180,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);
|
let val = four(*args, error);
|
||||||
if *error {
|
if *error {
|
||||||
*error = false;
|
*error = false;
|
||||||
|
@ -226,7 +226,7 @@ fn parse_expr_helper<'a>(hashmap: &HashMap<&'a [u8], Precedence>,
|
||||||
*error = true;
|
*error = true;
|
||||||
&min_prec
|
&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];
|
let op = args[0];
|
||||||
*args = (*args).slice_from(1);
|
*args = (*args).slice_from(1);
|
||||||
let mut rhs = dispatch(args, error);
|
let mut rhs = dispatch(args, error);
|
||||||
|
@ -235,7 +235,7 @@ fn parse_expr_helper<'a>(hashmap: &HashMap<&'a [u8], Precedence>,
|
||||||
*error = true;
|
*error = true;
|
||||||
&min_prec
|
&min_prec
|
||||||
});
|
});
|
||||||
if subprec as uint <= prec as uint || *error {
|
if subprec as usize <= prec as usize || *error {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
rhs = parse_expr_helper(hashmap, args, rhs, subprec, error);
|
rhs = parse_expr_helper(hashmap, args, rhs, subprec, error);
|
||||||
|
|
|
@ -32,7 +32,7 @@ extern {
|
||||||
static NAME: &'static str = "timeout";
|
static NAME: &'static str = "timeout";
|
||||||
static VERSION: &'static str = "1.0.0";
|
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 {
|
pub fn uumain(args: Vec<String>) -> isize {
|
||||||
let program = args[0].clone();
|
let program = args[0].clone();
|
||||||
|
@ -100,7 +100,7 @@ Usage:
|
||||||
0
|
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 {
|
if !foreground {
|
||||||
unsafe { setpgid(0, 0) };
|
unsafe { setpgid(0, 0) };
|
||||||
}
|
}
|
||||||
|
@ -128,7 +128,7 @@ fn timeout(cmdname: &str, args: &[String], duration: f64, signal: uint, kill_aft
|
||||||
ExitSignal(stat) => stat
|
ExitSignal(stat) => stat
|
||||||
},
|
},
|
||||||
Err(_) => {
|
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));
|
process.set_timeout(Some((kill_after * 1000f64) as u64));
|
||||||
match process.wait() {
|
match process.wait() {
|
||||||
Ok(status) => {
|
Ok(status) => {
|
||||||
|
@ -146,7 +146,7 @@ fn timeout(cmdname: &str, args: &[String], duration: f64, signal: uint, kill_aft
|
||||||
// XXX: this may not be right
|
// XXX: this may not be right
|
||||||
return 124;
|
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);
|
process.set_timeout(None);
|
||||||
return_if_err!(ERR_EXIT_STATUS, process.wait());
|
return_if_err!(ERR_EXIT_STATUS, process.wait());
|
||||||
137
|
137
|
||||||
|
|
|
@ -99,7 +99,7 @@ file based on its current size:
|
||||||
0
|
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 {
|
let (refsize, mode) = match reference {
|
||||||
Some(rfilename) => {
|
Some(rfilename) => {
|
||||||
let rfile = match File::open(&Path::new(rfilename.clone())) {
|
let rfile = match File::open(&Path::new(rfilename.clone())) {
|
||||||
|
|
|
@ -74,7 +74,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
exit_code as int
|
exit_code as isize
|
||||||
}
|
}
|
||||||
|
|
||||||
fn usage () {
|
fn usage () {
|
||||||
|
|
|
@ -29,8 +29,8 @@ struct Uniq {
|
||||||
all_repeated: bool,
|
all_repeated: bool,
|
||||||
delimiters: String,
|
delimiters: String,
|
||||||
show_counts: bool,
|
show_counts: bool,
|
||||||
slice_start: Option<uint>,
|
slice_start: Option<usize>,
|
||||||
slice_stop: Option<uint>,
|
slice_stop: Option<usize>,
|
||||||
ignore_case: bool,
|
ignore_case: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ impl Uniq {
|
||||||
first_line_printed
|
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 {
|
let output_line = if self.show_counts {
|
||||||
format!("{:7} {}", count, line)
|
format!("{:7} {}", count, line)
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -98,14 +98,14 @@ fn print_loadavg() {
|
||||||
else {
|
else {
|
||||||
print!("load average: ");
|
print!("load average: ");
|
||||||
for n in range(0, loads) {
|
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 { ", " } );
|
else { ", " } );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
fn process_utmpx() -> (Option<time_t>, uint) {
|
fn process_utmpx() -> (Option<time_t>, usize) {
|
||||||
unsafe {
|
unsafe {
|
||||||
utmpxname(CString::from_slice(DEFAULT_FILE.as_bytes()).as_ptr());
|
utmpxname(CString::from_slice(DEFAULT_FILE.as_bytes()).as_ptr());
|
||||||
}
|
}
|
||||||
|
@ -142,11 +142,11 @@ fn process_utmpx() -> (Option<time_t>, uint) {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(windows)]
|
#[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
|
(None, 0) // TODO: change 0 to number of users
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_nusers(nusers: uint) {
|
fn print_nusers(nusers: usize) {
|
||||||
if nusers == 1 {
|
if nusers == 1 {
|
||||||
print!("1 user, ");
|
print!("1 user, ");
|
||||||
} else if nusers > 1 {
|
} else if nusers > 1 {
|
||||||
|
|
|
@ -19,13 +19,13 @@ use std::collections::hash_map::HashMap;
|
||||||
static NAME: &'static str = "uutils";
|
static NAME: &'static str = "uutils";
|
||||||
static VERSION: &'static str = "1.0.0";
|
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();
|
let mut map = HashMap::new();
|
||||||
@UTIL_MAP@
|
@UTIL_MAP@
|
||||||
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!("{} {}", NAME, VERSION);
|
||||||
println!("");
|
println!("");
|
||||||
println!("Usage:");
|
println!("Usage:");
|
||||||
|
|
42
src/wc/wc.rs
42
src/wc/wc.rs
|
@ -26,11 +26,11 @@ mod util;
|
||||||
|
|
||||||
struct Result {
|
struct Result {
|
||||||
filename: String,
|
filename: String,
|
||||||
bytes: uint,
|
bytes: usize,
|
||||||
chars: uint,
|
chars: usize,
|
||||||
lines: uint,
|
lines: usize,
|
||||||
words: uint,
|
words: usize,
|
||||||
max_line_length: uint,
|
max_line_length: usize,
|
||||||
}
|
}
|
||||||
|
|
||||||
static NAME: &'static str = "wc";
|
static NAME: &'static str = "wc";
|
||||||
|
@ -94,25 +94,25 @@ fn is_word_seperator(byte: u8) -> bool {
|
||||||
byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF
|
byte == SPACE || byte == TAB || byte == CR || byte == SYN || byte == FF
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn wc(files: Vec<String>, matches: &Matches) -> StdResult<(), int> {
|
pub fn wc(files: Vec<String>, matches: &Matches) -> StdResult<(), isize> {
|
||||||
let mut total_line_count: uint = 0;
|
let mut total_line_count: usize = 0;
|
||||||
let mut total_word_count: uint = 0;
|
let mut total_word_count: usize = 0;
|
||||||
let mut total_char_count: uint = 0;
|
let mut total_char_count: usize = 0;
|
||||||
let mut total_byte_count: uint = 0;
|
let mut total_byte_count: usize = 0;
|
||||||
let mut total_longest_line_length: uint = 0;
|
let mut total_longest_line_length: usize = 0;
|
||||||
|
|
||||||
let mut results = vec!();
|
let mut results = vec!();
|
||||||
let mut max_str_len: uint = 0;
|
let mut max_str_len: usize = 0;
|
||||||
|
|
||||||
for path in files.iter() {
|
for path in files.iter() {
|
||||||
let mut reader = try!(open(path.as_slice()));
|
let mut reader = try!(open(path.as_slice()));
|
||||||
|
|
||||||
let mut line_count: uint = 0;
|
let mut line_count: usize = 0;
|
||||||
let mut word_count: uint = 0;
|
let mut word_count: usize = 0;
|
||||||
let mut byte_count: uint = 0;
|
let mut byte_count: usize = 0;
|
||||||
let mut char_count: uint = 0;
|
let mut char_count: usize = 0;
|
||||||
let mut current_char_count: uint = 0;
|
let mut current_char_count: usize = 0;
|
||||||
let mut longest_line_length: uint = 0;
|
let mut longest_line_length: usize = 0;
|
||||||
|
|
||||||
loop {
|
loop {
|
||||||
// reading from a TTY seems to raise a condition on, rather than return Some(0) like a file.
|
// reading from a TTY seems to raise a condition on, rather than return Some(0) like a file.
|
||||||
|
@ -191,8 +191,8 @@ pub fn wc(files: Vec<String>, matches: &Matches) -> StdResult<(), int> {
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn print_stats(filename: &str, line_count: uint, word_count: uint, char_count: uint,
|
fn print_stats(filename: &str, line_count: usize, word_count: usize, char_count: usize,
|
||||||
byte_count: uint, longest_line_length: uint, matches: &Matches, max_str_len: uint) {
|
byte_count: usize, longest_line_length: usize, matches: &Matches, max_str_len: usize) {
|
||||||
if matches.opt_present("lines") {
|
if matches.opt_present("lines") {
|
||||||
print!("{:1$}", line_count, max_str_len);
|
print!("{:1$}", line_count, max_str_len);
|
||||||
}
|
}
|
||||||
|
@ -228,7 +228,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 {
|
if "-" == path {
|
||||||
let reader = Box::new(stdin_raw()) as Box<Reader>;
|
let reader = Box::new(stdin_raw()) as Box<Reader>;
|
||||||
return Ok(BufferedReader::new(reader));
|
return Ok(BufferedReader::new(reader));
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue