mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-30 04:27:45 +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 = "*"
|
||||
rand = "0.3.8"
|
||||
regex = "0.1.30"
|
||||
regex_macros = "0.1.17"
|
||||
rust-crypto = "0.2.31"
|
||||
rustc-serialize = "0.3.13"
|
||||
time = "0.1.25"
|
||||
|
|
|
@ -11,8 +11,6 @@
|
|||
*/
|
||||
|
||||
#![allow(unused_variables)] // only necessary while the TODOs still exist
|
||||
#![feature(plugin)]
|
||||
#![plugin(regex_macros)]
|
||||
|
||||
extern crate getopts;
|
||||
extern crate libc;
|
||||
|
@ -114,9 +112,9 @@ Each MODE is of the form '[ugoa]*([-+=]([rwxXst]*|[ugo]))+|[-+=]?[0-7]+'.",
|
|||
#[cfg(unix)]
|
||||
#[inline]
|
||||
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(',') {
|
||||
if !REGEXP.is_match(mode) {
|
||||
if !re.is_match(mode) {
|
||||
return Err(format!("invalid mode '{}'", mode));
|
||||
}
|
||||
}
|
||||
|
@ -127,9 +125,9 @@ fn verify_mode(modes: &str) -> Result<(), String> {
|
|||
#[inline]
|
||||
// XXX: THIS IS NOT TESTED!!!
|
||||
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(',') {
|
||||
match REGEXP.captures(mode) {
|
||||
match re.captures(mode) {
|
||||
Some(cap) => {
|
||||
let symbols = cap.at(1);
|
||||
let numbers = cap.at(2);
|
||||
|
@ -206,8 +204,8 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
|
|||
}
|
||||
None => {
|
||||
// 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 mut stat : libc::stat = unsafe { mem::uninitialized() };
|
||||
let re: regex::Regex = Regex::new(r"^(([ugoa]*)((?:[-+=](?:[rwxXst]*|[ugo]))+))|([-+=]?[0-7]+)$").unwrap();
|
||||
let mut stat: libc::stat = unsafe { mem::uninitialized() };
|
||||
let statres = unsafe { libc::stat(path.as_ptr(), &mut stat as *mut libc::stat) };
|
||||
let mut fperm =
|
||||
if statres == 0 {
|
||||
|
@ -217,7 +215,7 @@ fn chmod_file(file: &Path, name: &str, changes: bool, quiet: bool, verbose: bool
|
|||
return Err(1);
|
||||
};
|
||||
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) {
|
||||
Some("") | None => false,
|
||||
_ => true,
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
DEPLIBS += regex
|
||||
DEPPLUGS += regex_macros
|
||||
|
|
|
@ -1,2 +1 @@
|
|||
DEPLIBS += regex
|
||||
DEPPLUGS += regex_macros
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
#![crate_name = "nl"]
|
||||
#![feature(collections, rustc_private, slice_patterns)]
|
||||
#![plugin(regex_macros)]
|
||||
|
||||
/*
|
||||
* This file is part of the uutils coreutils package.
|
||||
|
@ -11,10 +10,9 @@
|
|||
* file that was distributed with this source code.
|
||||
*
|
||||
*/
|
||||
#![feature(plugin)]
|
||||
|
||||
extern crate regex;
|
||||
extern crate getopts;
|
||||
extern crate regex;
|
||||
|
||||
use std::fs::File;
|
||||
use std::io::{BufRead, BufReader, Read, stdin, Write};
|
||||
|
@ -30,7 +28,6 @@ mod helper;
|
|||
static NAME: &'static str = "nl";
|
||||
static USAGE: &'static str = "nl [OPTION]... [FILE]...";
|
||||
// A regular expression matching everything.
|
||||
static REGEX_DUMMY: &'static regex::Regex = ®ex!(r".?");
|
||||
|
||||
// Settings store options used by nl to produce its output.
|
||||
pub struct Settings {
|
||||
|
@ -158,6 +155,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
|||
|
||||
// nl implements the main functionality for an individual buffer.
|
||||
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;
|
||||
// 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.
|
||||
|
@ -174,7 +172,7 @@ fn nl<T: Read> (reader: &mut BufReader<T>, settings: &Settings) {
|
|||
// Initially, we use the body's line counting settings
|
||||
let mut regex_filter = match settings.body_numbering {
|
||||
NumberingStyle::NumberForRegularExpression(ref re) => re,
|
||||
_ => REGEX_DUMMY,
|
||||
_ => ®exp,
|
||||
};
|
||||
let mut line_filter : fn(&str, ®ex::Regex) -> bool = pass_regex;
|
||||
for mut l in reader.lines().map(|r| r.unwrap()) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue