mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 13:07:46 +00:00
test, tr, tsort: fix build
This commit is contained in:
parent
ec44be6034
commit
9b748012cd
3 changed files with 16 additions and 13 deletions
|
@ -12,6 +12,7 @@
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
use std::ffi::CString;
|
||||||
use std::os::{args_as_bytes};
|
use std::os::{args_as_bytes};
|
||||||
use std::str::{from_utf8};
|
use std::str::{from_utf8};
|
||||||
|
|
||||||
|
@ -334,7 +335,7 @@ fn path(path: &[u8], cond: PathCondition) -> bool {
|
||||||
Write = 0o2,
|
Write = 0o2,
|
||||||
Execute = 0o1,
|
Execute = 0o1,
|
||||||
}
|
}
|
||||||
let perm = |stat: stat, p: Permission| {
|
let perm = |&: stat: stat, p: Permission| {
|
||||||
use libc::{getgid, getuid};
|
use libc::{getgid, getuid};
|
||||||
let (uid, gid) = unsafe { (getuid(), getgid()) };
|
let (uid, gid) = unsafe { (getuid(), getgid()) };
|
||||||
if uid == stat.st_uid {
|
if uid == stat.st_uid {
|
||||||
|
@ -346,7 +347,7 @@ fn path(path: &[u8], cond: PathCondition) -> bool {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let path = unsafe { path.to_c_str_unchecked() };
|
let path = CString::from_slice(path);
|
||||||
let mut stat = unsafe { std::mem::zeroed() };
|
let mut stat = unsafe { std::mem::zeroed() };
|
||||||
if cond == PathCondition::SymLink {
|
if cond == PathCondition::SymLink {
|
||||||
if unsafe { lstat(path.as_ptr(), &mut stat) } == 0 {
|
if unsafe { lstat(path.as_ptr(), &mut stat) } == 0 {
|
||||||
|
|
20
src/tr/tr.rs
20
src/tr/tr.rs
|
@ -92,13 +92,15 @@ fn delete(set: Vec<char>, complement: bool) {
|
||||||
let mut out = stdout();
|
let mut out = stdout();
|
||||||
|
|
||||||
for &c in set.iter() {
|
for &c in set.iter() {
|
||||||
bset.insert(c as uint);
|
bset.insert(c as usize);
|
||||||
}
|
}
|
||||||
|
|
||||||
let is_allowed = if complement {
|
let is_allowed = |&: c : char| {
|
||||||
|c: char| bset.contains(&(c as uint))
|
if complement {
|
||||||
} else {
|
bset.contains(&(c as usize))
|
||||||
|c: char| !bset.contains(&(c as uint))
|
} else {
|
||||||
|
!bset.contains(&(c as usize))
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
for c in BufferedReader::new(stdin_raw()).chars() {
|
for c in BufferedReader::new(stdin_raw()).chars() {
|
||||||
|
@ -111,7 +113,7 @@ fn delete(set: Vec<char>, complement: bool) {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn tr(set1: &[char], set2: &[char]) {
|
fn tr(set1: &[char], set2: &[char]) {
|
||||||
const BUFFER_LEN: uint = 1024;
|
const BUFFER_LEN: usize = 1024;
|
||||||
|
|
||||||
let mut map = VecMap::new();
|
let mut map = VecMap::new();
|
||||||
let mut stdout = stdout();
|
let mut stdout = stdout();
|
||||||
|
@ -120,16 +122,16 @@ fn tr(set1: &[char], set2: &[char]) {
|
||||||
let set2_len = set2.len();
|
let set2_len = set2.len();
|
||||||
for i in range(0, set1.len()) {
|
for i in range(0, set1.len()) {
|
||||||
if i >= set2_len {
|
if i >= set2_len {
|
||||||
map.insert(set1[i] as uint, set2[set2_len - 1]);
|
map.insert(set1[i] as usize, set2[set2_len - 1]);
|
||||||
} else {
|
} else {
|
||||||
map.insert(set1[i] as uint, set2[i]);
|
map.insert(set1[i] as usize, set2[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for c in BufferedReader::new(stdin_raw()).chars() {
|
for c in BufferedReader::new(stdin_raw()).chars() {
|
||||||
match c {
|
match c {
|
||||||
Ok(inc) => {
|
Ok(inc) => {
|
||||||
let trc = match map.get(&(inc as uint)) {
|
let trc = match map.get(&(inc as usize)) {
|
||||||
Some(t) => *t,
|
Some(t) => *t,
|
||||||
None => inc,
|
None => inc,
|
||||||
};
|
};
|
||||||
|
|
|
@ -80,7 +80,7 @@ pub fn uumain(args: Vec<String>) -> isize {
|
||||||
loop {
|
loop {
|
||||||
match reader.read_line() {
|
match reader.read_line() {
|
||||||
Ok(line) => {
|
Ok(line) => {
|
||||||
let ab: Vec<&str> = line.as_slice().trim_right_chars('\n').split(' ').collect();
|
let ab: Vec<&str> = line.as_slice().trim_right_matches('\n').split(' ').collect();
|
||||||
if ab.len() > 2 {
|
if ab.len() > 2 {
|
||||||
crash!(1, "{}: input contains an odd number of tokens", input);
|
crash!(1, "{}: input contains an odd number of tokens", input);
|
||||||
}
|
}
|
||||||
|
@ -159,7 +159,7 @@ impl Graph {
|
||||||
}
|
}
|
||||||
|
|
||||||
while !start_nodes.is_empty() {
|
while !start_nodes.is_empty() {
|
||||||
let n = start_nodes.remove(0).unwrap();
|
let n = start_nodes.remove(0);
|
||||||
|
|
||||||
self.result.push(n.clone());
|
self.result.push(n.clone());
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue