From a94bd0bd35775d018037e4a300f9d036c378d2d0 Mon Sep 17 00:00:00 2001 From: Joseph Crail Date: Tue, 19 May 2015 21:35:17 -0400 Subject: [PATCH] Remove unstable regex macros. This will allow coreutils to get further along when building against Rust 1.0. --- deps/Cargo.toml | 1 - src/chmod/chmod.rs | 16 +++++++--------- src/chmod/deps.mk | 1 - src/nl/deps.mk | 1 - src/nl/nl.rs | 8 +++----- 5 files changed, 10 insertions(+), 17 deletions(-) diff --git a/deps/Cargo.toml b/deps/Cargo.toml index 7c6086937..8b217d015 100644 --- a/deps/Cargo.toml +++ b/deps/Cargo.toml @@ -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" diff --git a/src/chmod/chmod.rs b/src/chmod/chmod.rs index 64015cf13..4d68c1f35 100644 --- a/src/chmod/chmod.rs +++ b/src/chmod/chmod.rs @@ -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, diff --git a/src/chmod/deps.mk b/src/chmod/deps.mk index fbf77a3ce..8ee594ed9 100644 --- a/src/chmod/deps.mk +++ b/src/chmod/deps.mk @@ -1,2 +1 @@ DEPLIBS += regex -DEPPLUGS += regex_macros diff --git a/src/nl/deps.mk b/src/nl/deps.mk index fbf77a3ce..8ee594ed9 100644 --- a/src/nl/deps.mk +++ b/src/nl/deps.mk @@ -1,2 +1 @@ DEPLIBS += regex -DEPPLUGS += regex_macros diff --git a/src/nl/nl.rs b/src/nl/nl.rs index d80a048d9..25678d9d3 100644 --- a/src/nl/nl.rs +++ b/src/nl/nl.rs @@ -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) -> i32 { // nl implements the main functionality for an individual buffer. fn nl (reader: &mut BufReader, 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 (reader: &mut BufReader, 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()) {