mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 20:47:46 +00:00
Merge pull request #611 from jbcrail/rm-unstable-regex-macros
Remove unstable regex macros.
This commit is contained in:
commit
90af62721e
5 changed files with 10 additions and 17 deletions
1
deps/Cargo.toml
vendored
1
deps/Cargo.toml
vendored
|
@ -10,7 +10,6 @@ libc = "0.1.7"
|
||||||
num_cpus = "*"
|
num_cpus = "*"
|
||||||
rand = "0.3.8"
|
rand = "0.3.8"
|
||||||
regex = "0.1.30"
|
regex = "0.1.30"
|
||||||
regex_macros = "0.1.17"
|
|
||||||
rust-crypto = "0.2.31"
|
rust-crypto = "0.2.31"
|
||||||
rustc-serialize = "0.3.13"
|
rustc-serialize = "0.3.13"
|
||||||
time = "0.1.25"
|
time = "0.1.25"
|
||||||
|
|
|
@ -11,8 +11,6 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#![allow(unused_variables)] // only necessary while the TODOs still exist
|
#![allow(unused_variables)] // only necessary while the TODOs still exist
|
||||||
#![feature(plugin)]
|
|
||||||
#![plugin(regex_macros)]
|
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
@ -114,9 +112,9 @@ Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
#[inline]
|
#[inline]
|
||||||
fn verify_mode(modes: &str) -> Result<(), String> {
|
fn verify_mode(modes: &str) -> Result<(), String> {
|
||||||
static REGEXP: regex::Regex = regex!(r"^[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+$");
|
let re: regex::Regex = Regex::new(r"^[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+$").unwrap();
|
||||||
for mode in modes.split(',') {
|
for mode in modes.split(',') {
|
||||||
if !REGEXP.is_match(mode) {
|
if !re.is_match(mode) {
|
||||||
return Err(format!("invalid mode '{}'", mode));
|
return Err(format!("invalid mode '{}'", mode));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -127,9 +125,9 @@ fn verify_mode(modes: &str) -> Result<(), String> {
|
||||||
#[inline]
|
#[inline]
|
||||||
// XXX: THIS IS NOT TESTED!!!
|
// XXX: THIS IS NOT TESTED!!!
|
||||||
fn verify_mode(mode: &str) -> Result<(), String> {
|
fn verify_mode(mode: &str) -> Result<(), String> {
|
||||||
static REGEXP: regex::Regex = regex!(r"^[ugoa]*(?:[-+=](?:([rwxXst]*)|[ugo]))+|[-+=]?([0-7]+)$");
|
let re: regex::Regex = Regex::new(r"^[ugoa]*(?:[-+=](?:([rwxXst]*)|[ugo]))+|[-+=]?([0-7]+)$").unwrap();
|
||||||
for mode in modes.split(',') {
|
for mode in modes.split(',') {
|
||||||
match REGEXP.captures(mode) {
|
match re.captures(mode) {
|
||||||
Some(cap) => {
|
Some(cap) => {
|
||||||
let symbols = cap.at(1);
|
let symbols = cap.at(1);
|
||||||
let numbers = cap.at(2);
|
let numbers = cap.at(2);
|
||||||
|
@ -206,8 +204,8 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
|
||||||
}
|
}
|
||||||
None => {
|
None => {
|
||||||
// TODO: make the regex processing occur earlier (i.e. once in the main function)
|
// TODO: make the regex processing occur earlier (i.e. once in the main function)
|
||||||
static REGEXP: regex::Regex = regex!(r"^(([ugoa]*)((?:[-+=](?:[rwxXst]*|[ugo]))+))|([-+=]?[0-7]+)$");
|
let re: regex::Regex = Regex::new(r"^(([ugoa]*)((?:[-+=](?:[rwxXst]*|[ugo]))+))|([-+=]?[0-7]+)$").unwrap();
|
||||||
let mut stat : libc::stat = unsafe { mem::uninitialized() };
|
let mut stat: libc::stat = unsafe { mem::uninitialized() };
|
||||||
let statres = unsafe { libc::stat(path.as_ptr(), &mut stat as *mut libc::stat) };
|
let statres = unsafe { libc::stat(path.as_ptr(), &mut stat as *mut libc::stat) };
|
||||||
let mut fperm =
|
let mut fperm =
|
||||||
if statres == 0 {
|
if statres == 0 {
|
||||||
|
@ -217,7 +215,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
|
||||||
return Err(1);
|
return Err(1);
|
||||||
};
|
};
|
||||||
for mode in cmode.unwrap().split(',') { // cmode is guaranteed to be Some in this case
|
for mode in cmode.unwrap().split(',') { // cmode is guaranteed to be Some in this case
|
||||||
let cap = REGEXP.captures(mode).unwrap(); // mode was verified earlier, so this is safe
|
let cap = re.captures(mode).unwrap(); // mode was verified earlier, so this is safe
|
||||||
if match cap.at(1) {
|
if match cap.at(1) {
|
||||||
Some("") | None => false,
|
Some("") | None => false,
|
||||||
_ => true,
|
_ => true,
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
DEPLIBS += regex
|
DEPLIBS += regex
|
||||||
DEPPLUGS += regex_macros
|
|
||||||
|
|
|
@ -1,2 +1 @@
|
||||||
DEPLIBS += regex
|
DEPLIBS += regex
|
||||||
DEPPLUGS += regex_macros
|
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
#![crate_name = "nl"]
|
#![crate_name = "nl"]
|
||||||
#![feature(collections, rustc_private, slice_patterns)]
|
#![feature(collections, rustc_private, slice_patterns)]
|
||||||
#![plugin(regex_macros)]
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This file is part of the uutils coreutils package.
|
* This file is part of the uutils coreutils package.
|
||||||
|
@ -11,10 +10,9 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
#![feature(plugin)]
|
|
||||||
|
|
||||||
extern crate regex;
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
|
extern crate regex;
|
||||||
|
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
||||||
|
@ -30,7 +28,6 @@ mod helper;
|
||||||
static NAME: &'static str = "nl";
|
static NAME: &'static str = "nl";
|
||||||
static USAGE: &'static str = "nl [OPTION]... [FILE]...";
|
static USAGE: &'static str = "nl [OPTION]... [FILE]...";
|
||||||
// A regular expression matching everything.
|
// A regular expression matching everything.
|
||||||
static REGEX_DUMMY: &'static regex::Regex = ®ex!(r".?");
|
|
||||||
|
|
||||||
// Settings store options used by nl to produce its output.
|
// Settings store options used by nl to produce its output.
|
||||||
pub struct Settings {
|
pub struct Settings {
|
||||||
|
@ -158,6 +155,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
|
|
||||||
// nl implements the main functionality for an individual buffer.
|
// nl implements the main functionality for an individual buffer.
|
||||||
fn nl<T: Read> (reader: &mut BufReader<T>, settings: &Settings) {
|
fn nl<T: Read> (reader: &mut BufReader<T>, settings: &Settings) {
|
||||||
|
let regexp: regex::Regex = regex::Regex::new(r".?").unwrap();
|
||||||
let mut line_no = settings.starting_line_number;
|
let mut line_no = settings.starting_line_number;
|
||||||
// The current line number's width as a string. Using to_string is inefficient
|
// The current line number's width as a string. Using to_string is inefficient
|
||||||
// but since we only do it once, it should not hurt.
|
// but since we only do it once, it should not hurt.
|
||||||
|
@ -174,7 +172,7 @@ fn nl<T: Read> (reader: &mut BufReader<T>, settings: &Settings) {
|
||||||
// Initially, we use the body's line counting settings
|
// Initially, we use the body's line counting settings
|
||||||
let mut regex_filter = match settings.body_numbering {
|
let mut regex_filter = match settings.body_numbering {
|
||||||
NumberingStyle::NumberForRegularExpression(ref re) => re,
|
NumberingStyle::NumberForRegularExpression(ref re) => re,
|
||||||
_ => REGEX_DUMMY,
|
_ => ®exp,
|
||||||
};
|
};
|
||||||
let mut line_filter : fn(&str, ®ex::Regex) -> bool = pass_regex;
|
let mut line_filter : fn(&str, ®ex::Regex) -> bool = pass_regex;
|
||||||
for mut l in reader.lines().map(|r| r.unwrap()) {
|
for mut l in reader.lines().map(|r| r.unwrap()) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue