mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-31 21:17:46 +00:00
Merge pull request #543 from kwantam/master
refactor Makefile to use Cargo to build all dependencies; make seq build
This commit is contained in:
commit
c24b14e0a0
24 changed files with 110 additions and 69 deletions
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -2,6 +2,8 @@
|
||||||
/target/
|
/target/
|
||||||
/tmp/
|
/tmp/
|
||||||
/busybox/
|
/busybox/
|
||||||
|
/deps/target/
|
||||||
*~
|
*~
|
||||||
.*.swp
|
.*.swp
|
||||||
.*.swo
|
.*.swo
|
||||||
|
Cargo.lock
|
||||||
|
|
9
.gitmodules
vendored
9
.gitmodules
vendored
|
@ -1,9 +0,0 @@
|
||||||
[submodule "deps/rust-crypto"]
|
|
||||||
path = deps/rust-crypto
|
|
||||||
url = https://github.com/DaGenix/rust-crypto
|
|
||||||
[submodule "deps/time"]
|
|
||||||
path = deps/time
|
|
||||||
url = https://github.com/rust-lang/time
|
|
||||||
[submodule "deps/regex"]
|
|
||||||
path = deps/regex
|
|
||||||
url = https://github.com/rust-lang/regex
|
|
70
Makefile
70
Makefile
|
@ -175,6 +175,22 @@ TEST ?= $(TEST_PROGS)
|
||||||
TESTS := \
|
TESTS := \
|
||||||
$(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
|
$(filter $(TEST),$(filter-out $(DONT_TEST),$(filter $(BUILD),$(filter-out $(DONT_BUILD),$(TEST_PROGS)))))
|
||||||
|
|
||||||
|
# figure out what dependencies we need based on which programs we're building
|
||||||
|
define DEP_INCLUDE
|
||||||
|
-include $(SRCDIR)/$(1)/deps.mk
|
||||||
|
endef
|
||||||
|
# we always depend on libc because common/util does
|
||||||
|
DEPLIBS := libc
|
||||||
|
DEPPLUGS :=
|
||||||
|
# now, add in deps in src/utilname/deps.mk
|
||||||
|
$(foreach build,$(sort $(EXES) $(TESTS)),$(eval $(call DEP_INCLUDE,$(build))))
|
||||||
|
# uniqify deps
|
||||||
|
DEPLIBS := $(sort $(DEPLIBS))
|
||||||
|
DEPPLUGS := $(sort $(DEPPLUGS))
|
||||||
|
# build --extern commandline for rustc
|
||||||
|
DEP_EXTERN := $(foreach lib,$(subst -,_,$(DEPLIBS)),--extern $(lib)=$(BUILDDIR)/lib$(lib).rlib)
|
||||||
|
DEP_EXTERN += $(foreach plug,$(subst -,_,$(DEPPLUGS)),--extern $(plug)=$(BUILDDIR)/lib$(plug).$(DYLIB_EXT))
|
||||||
|
|
||||||
# Setup for building crates
|
# Setup for building crates
|
||||||
define BUILD_SETUP
|
define BUILD_SETUP
|
||||||
X := $(shell $(RUSTC) --print file-names --crate-type rlib $(SRCDIR)/$(1)/$(1).rs)
|
X := $(shell $(RUSTC) --print file-names --crate-type rlib $(SRCDIR)/$(1)/$(1).rs)
|
||||||
|
@ -187,6 +203,7 @@ $(foreach crate,$(EXES),$(eval $(call BUILD_SETUP,$(crate))))
|
||||||
EXES_PATHS := $(addprefix $(BUILDDIR)/,$(EXES))
|
EXES_PATHS := $(addprefix $(BUILDDIR)/,$(EXES))
|
||||||
RLIB_PATHS := $(addprefix $(BUILDDIR)/,$(CRATE_RLIBS))
|
RLIB_PATHS := $(addprefix $(BUILDDIR)/,$(CRATE_RLIBS))
|
||||||
command = sh -c '$(1)'
|
command = sh -c '$(1)'
|
||||||
|
RESERVED_EXTERNS := --extern uufalse=$(BUILDDIR)/libfalse.rlib --extern uutrue=$(BUILDDIR)/libtrue.rlib --extern uutest=$(BUILDDIR)/libtest.rlib
|
||||||
|
|
||||||
# Main exe build rule
|
# Main exe build rule
|
||||||
define EXE_BUILD
|
define EXE_BUILD
|
||||||
|
@ -194,15 +211,26 @@ $(BUILDDIR)/gen/$(1).rs: $(BUILDDIR)/mkmain
|
||||||
$(BUILDDIR)/mkmain $(1) $$@
|
$(BUILDDIR)/mkmain $(1) $$@
|
||||||
|
|
||||||
$(BUILDDIR)/$(1): $(BUILDDIR)/gen/$(1).rs $(BUILDDIR)/$($(1)_RLIB) | $(BUILDDIR) deps
|
$(BUILDDIR)/$(1): $(BUILDDIR)/gen/$(1).rs $(BUILDDIR)/$($(1)_RLIB) | $(BUILDDIR) deps
|
||||||
$(RUSTC) $(RUSTCBINFLAGS) --extern test=$(BUILDDIR)/libtest.rlib -o $$@ $$<
|
$(RUSTC) $(RUSTCBINFLAGS) $(RESERVED_EXTERNS) -o $$@ $$<
|
||||||
$(if $(ENABLE_STRIP),strip $$@,)
|
$(if $(ENABLE_STRIP),strip $$@,)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
|
# GRRR rust-crypto makes a crate called "crypto".
|
||||||
|
# This should NOT be allowed by crates.io. GRRRR.
|
||||||
|
define DEP_BUILD
|
||||||
|
DEP_$(1):
|
||||||
|
ifeq ($(1),crypto)
|
||||||
|
cd $(BASEDIR)/deps && $(CARGO) build --package rust-crypto --release
|
||||||
|
else
|
||||||
|
cd $(BASEDIR)/deps && $(CARGO) build --package $(1) --release
|
||||||
|
endif
|
||||||
|
endef
|
||||||
|
|
||||||
define CRATE_BUILD
|
define CRATE_BUILD
|
||||||
-include $(BUILDDIR)/$(1).d
|
-include $(BUILDDIR)/$(1).d
|
||||||
|
|
||||||
$(BUILDDIR)/$($(1)_RLIB): $(SRCDIR)/$(1)/$(1).rs | $(BUILDDIR) deps
|
$(BUILDDIR)/$($(1)_RLIB): $(SRCDIR)/$(1)/$(1).rs | $(BUILDDIR) deps
|
||||||
$(RUSTC) $(RUSTCLIBFLAGS) --extern libc=$(BUILDDIR)/liblibc.rlib --extern time=$(BUILDDIR)/libtime.rlib --extern rand=$(BUILDDIR)/librand.rlib --extern regex=$(BUILDDIR)/libregex.rlib --extern serialize=$(BUILDDIR)/librustc_serialize.rlib --crate-type rlib --emit link,dep-info $$< --out-dir $(BUILDDIR)
|
$(RUSTC) $(RUSTCLIBFLAGS) $(DEP_EXTERN) --crate-type rlib --emit link,dep-info $$< --out-dir $(BUILDDIR)
|
||||||
endef
|
endef
|
||||||
|
|
||||||
# Aliases build rule
|
# Aliases build rule
|
||||||
|
@ -224,7 +252,7 @@ test_$(1): $(TEMPDIR)/$(1)/$(1)_test $(BUILDDIR)/$(1)
|
||||||
$(call command,cp $(BUILDDIR)/$(1) $(TEMPDIR)/$(1) && cd $(TEMPDIR)/$(1) && $$<)
|
$(call command,cp $(BUILDDIR)/$(1) $(TEMPDIR)/$(1) && cd $(TEMPDIR)/$(1) && $$<)
|
||||||
|
|
||||||
$(TEMPDIR)/$(1)/$(1)_test: $(TESTDIR)/$(1).rs | $(TEMPDIR)/$(1)
|
$(TEMPDIR)/$(1)/$(1)_test: $(TESTDIR)/$(1).rs | $(TEMPDIR)/$(1)
|
||||||
$(call command,$(RUSTC) $(RUSTCTESTFLAGS) --extern time=$(BUILDDIR)/libtime.rlib --extern regex=$(BUILDDIR)/libregex.rlib --test -o $$@ $$<)
|
$(call command,$(RUSTC) $(RUSTCTESTFLAGS) $(DEP_EXTERN) --test -o $$@ $$<)
|
||||||
|
|
||||||
$(TEMPDIR)/$(1): | $(TEMPDIR)
|
$(TEMPDIR)/$(1): | $(TEMPDIR)
|
||||||
$(call command,cp -r $(TESTDIR)/fixtures/$(1) $$@ || mkdir $$@)
|
$(call command,cp -r $(TESTDIR)/fixtures/$(1) $$@ || mkdir $$@)
|
||||||
|
@ -238,11 +266,12 @@ $(foreach crate,$(EXES),$(eval $(call CRATE_BUILD,$(crate))))
|
||||||
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
|
$(foreach exe,$(EXES),$(eval $(call EXE_BUILD,$(exe))))
|
||||||
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
|
$(foreach alias,$(ALIASES),$(eval $(call MAKE_ALIAS,$(alias))))
|
||||||
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
|
$(foreach test,$(TESTS),$(eval $(call TEST_BUILD,$(test))))
|
||||||
|
$(foreach dep,$(sort $(DEPLIBS) $(DEPPLUGS)),$(eval $(call DEP_BUILD,$(dep))))
|
||||||
|
|
||||||
-include $(BUILDDIR)/uutils.d
|
-include $(BUILDDIR)/uutils.d
|
||||||
$(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS)
|
$(BUILDDIR)/uutils: $(SRCDIR)/uutils/uutils.rs $(BUILDDIR)/mkuutils $(RLIB_PATHS)
|
||||||
$(BUILDDIR)/mkuutils $(BUILDDIR)/gen/uutils.rs $(EXES)
|
$(BUILDDIR)/mkuutils $(BUILDDIR)/gen/uutils.rs $(EXES)
|
||||||
$(RUSTC) $(RUSTCBINFLAGS) --extern test=$(BUILDDIR)/libtest.rlib --emit link,dep-info $(BUILDDIR)/gen/uutils.rs --out-dir $(BUILDDIR)
|
$(RUSTC) $(RUSTCBINFLAGS) $(RESERVED_EXTERNS) --emit link,dep-info $(BUILDDIR)/gen/uutils.rs --out-dir $(BUILDDIR)
|
||||||
$(if $(ENABLE_STRIP),strip $@)
|
$(if $(ENABLE_STRIP),strip $@)
|
||||||
|
|
||||||
# Library for stdbuf
|
# Library for stdbuf
|
||||||
|
@ -255,26 +284,9 @@ $(BUILDDIR)/libstdbuf.$(DYLIB_EXT): $(SRCDIR)/stdbuf/libstdbuf.rs $(SRCDIR)/stdb
|
||||||
|
|
||||||
$(BUILDDIR)/stdbuf: $(BUILDDIR)/libstdbuf.$(DYLIB_EXT)
|
$(BUILDDIR)/stdbuf: $(BUILDDIR)/libstdbuf.$(DYLIB_EXT)
|
||||||
|
|
||||||
# Dependencies
|
deps: $(BUILDDIR) $(SRCDIR)/cksum/crc_table.rs $(addprefix DEP_,$(DEPLIBS) $(DEPPLUGS))
|
||||||
$(BUILDDIR)/.rust-crypto: | $(BUILDDIR)
|
$(foreach lib,$(subst -,_,$(DEPLIBS)),$(shell cp $(BASEDIR)/deps/target/release/deps/lib$(lib)-*.rlib $(BUILDDIR)/lib$(lib).rlib))
|
||||||
cd $(BASEDIR)/deps/rust-crypto && $(CARGO) build --release
|
$(foreach plug,$(subst -,_,$(DEPPLUGS)),$(shell cp $(BASEDIR)/deps/target/release/deps/lib$(plug)-*.$(DYLIB_EXT) $(BUILDDIR)/lib$(plug).$(DYLIB_EXT)))
|
||||||
cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/librand*.rlib $(BUILDDIR)/librand.rlib
|
|
||||||
cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/librustc_serialize*.rlib $(BUILDDIR)/librustc_serialize.rlib
|
|
||||||
cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/libtime*.rlib $(BUILDDIR)/libtime.rlib
|
|
||||||
cp -r $(BASEDIR)/deps/rust-crypto/target/release/deps/liblibc*.rlib $(BUILDDIR)/liblibc.rlib
|
|
||||||
cp -r $(BASEDIR)/deps/rust-crypto/target/release/libcrypto*.rlib $(BUILDDIR)/libcrypto.rlib
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
#$(BUILDDIR)/.rust-time: | $(BUILDDIR)
|
|
||||||
# cd $(BASEDIR)/deps/time && $(CARGO) build --release
|
|
||||||
# cp -r $(BASEDIR)/deps/time/target/release/libtime*.rlib $(BUILDDIR)/libtime.rlib
|
|
||||||
# @touch $@
|
|
||||||
|
|
||||||
$(BUILDDIR)/.rust-regex: | $(BUILDDIR)
|
|
||||||
cd $(BASEDIR)/deps/regex/regex_macros && $(CARGO) build --release
|
|
||||||
cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/libregex_macros* $(BUILDDIR)
|
|
||||||
cp -r $(BASEDIR)/deps/regex/regex_macros/target/release/deps/libregex*.rlib $(BUILDDIR)/libregex.rlib
|
|
||||||
@touch $@
|
|
||||||
|
|
||||||
$(BUILDDIR)/mkmain: mkmain.rs | $(BUILDDIR)
|
$(BUILDDIR)/mkmain: mkmain.rs | $(BUILDDIR)
|
||||||
$(RUSTC) $(RUSTCFLAGS) $< -o $@
|
$(RUSTC) $(RUSTCFLAGS) $< -o $@
|
||||||
|
@ -285,8 +297,6 @@ $(BUILDDIR)/mkuutils: mkuutils.rs | $(BUILDDIR)
|
||||||
$(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs
|
$(SRCDIR)/cksum/crc_table.rs: $(SRCDIR)/cksum/gen_table.rs
|
||||||
cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCBINFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
|
cd $(SRCDIR)/cksum && $(RUSTC) $(RUSTCBINFLAGS) gen_table.rs && ./gen_table && $(RM) gen_table
|
||||||
|
|
||||||
deps: $(BUILDDIR)/.rust-crypto $(BUILDDIR)/.rust-regex $(SRCDIR)/cksum/crc_table.rs
|
|
||||||
|
|
||||||
crates:
|
crates:
|
||||||
echo $(EXES)
|
echo $(EXES)
|
||||||
|
|
||||||
|
@ -294,10 +304,12 @@ test: $(TEMPDIR) $(addprefix test_,$(TESTS))
|
||||||
$(RM) -rf $(TEMPDIR)
|
$(RM) -rf $(TEMPDIR)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
$(RM) -rf $(BUILDDIR) $(TEMPDIR) $(BASEDIR)/deps/time/target
|
$(RM) -rf $(BUILDDIR) $(TEMPDIR)
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
cd $(BASEDIR)/deps && $(CARGO) clean
|
||||||
|
|
||||||
$(BUILDDIR):
|
$(BUILDDIR):
|
||||||
git submodule update --init
|
|
||||||
mkdir -p $(BUILDDIR)/gen
|
mkdir -p $(BUILDDIR)/gen
|
||||||
|
|
||||||
$(TEMPDIR):
|
$(TEMPDIR):
|
||||||
|
@ -356,4 +368,4 @@ busytest: $(BUILDDIR)/busybox $(BUILDDIR)/.config
|
||||||
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(BUILDDIR) ./runtest $(RUNTEST_ARGS))
|
(cd $(BUSYBOX_SRC)/testsuite && bindir=$(BUILDDIR) ./runtest $(RUNTEST_ARGS))
|
||||||
endif
|
endif
|
||||||
|
|
||||||
.PHONY: $(TEMPDIR) all deps test clean busytest install uninstall
|
.PHONY: $(TEMPDIR) all deps test distclean clean busytest install uninstall
|
||||||
|
|
16
deps/Cargo.toml
vendored
Normal file
16
deps/Cargo.toml
vendored
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
[project]
|
||||||
|
name = "deps"
|
||||||
|
version = "0.0.0"
|
||||||
|
|
||||||
|
[lib]
|
||||||
|
name = "null"
|
||||||
|
|
||||||
|
[dependencies]
|
||||||
|
libc = "0.1.6"
|
||||||
|
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"
|
||||||
|
unicode-width = "0.1.1"
|
1
deps/regex
vendored
1
deps/regex
vendored
|
@ -1 +0,0 @@
|
||||||
Subproject commit 399758aeae3dcab382b0af5fa9964c1e32066dda
|
|
1
deps/rust-crypto
vendored
1
deps/rust-crypto
vendored
|
@ -1 +0,0 @@
|
||||||
Subproject commit 5571cb41690b9cee12025192393ea7df0eddc21b
|
|
1
deps/time
vendored
1
deps/time
vendored
|
@ -1 +0,0 @@
|
||||||
Subproject commit a7869dcee07de6df4e81b48bdfe137c70c153643
|
|
|
@ -23,7 +23,12 @@ fn main() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
let crat = &args[1][..];
|
let crat = match &args[1][..] {
|
||||||
|
"false" => "uufalse",
|
||||||
|
"test" => "uutest",
|
||||||
|
"true" => "uutrue",
|
||||||
|
_ => &args[1][..],
|
||||||
|
};
|
||||||
let outfile = &args[2][..];
|
let outfile = &args[2][..];
|
||||||
|
|
||||||
let main = TEMPLATE.replace("@UTIL_CRATE@", crat);
|
let main = TEMPLATE.replace("@UTIL_CRATE@", crat);
|
||||||
|
|
12
mkuutils.rs
12
mkuutils.rs
|
@ -29,9 +29,15 @@ fn main() {
|
||||||
util_map.push_str("map.insert(\"sha512sum\", hashsum::uumain);\n");
|
util_map.push_str("map.insert(\"sha512sum\", hashsum::uumain);\n");
|
||||||
hashsum = true;
|
hashsum = true;
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
"true" => util_map.push_str("fn uutrue(_: Vec<String>) -> i32 { 0 }\nmap.insert(\"true\", uutrue);\n"),
|
"true" => {
|
||||||
"false" => util_map.push_str("fn uufalse(_: Vec<String>) -> i32 { 1 }\nmap.insert(\"false\", uufalse);\n"),
|
util_map.push_str("fn uutrue(_: Vec<String>) -> i32 { 0 }\n");
|
||||||
|
util_map.push_str("map.insert(\"true\", uutrue as fn(Vec<String>) -> i32);\n");
|
||||||
|
},
|
||||||
|
"false" => {
|
||||||
|
util_map.push_str("fn uufalse(_: Vec<String>) -> i32 { 1 }\n");
|
||||||
|
util_map.push_str("map.insert(\"false\", uufalse as fn(Vec<String>) -> i32);\n");
|
||||||
|
},
|
||||||
_ => {
|
_ => {
|
||||||
crates.push_str(&(format!("extern crate {0} as uu{0};\n", prog))[..]);
|
crates.push_str(&(format!("extern crate {0} as uu{0};\n", prog))[..]);
|
||||||
util_map.push_str(&(format!("map.insert(\"{prog}\", uu{prog}::uumain as fn(Vec<String>) -> i32);\n", prog = prog))[..]);
|
util_map.push_str(&(format!("map.insert(\"{prog}\", uu{prog}::uumain as fn(Vec<String>) -> i32);\n", prog = prog))[..]);
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
* that was distributed with this source code.
|
* that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
extern crate serialize;
|
extern crate rustc_serialize as serialize;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
#[macro_use] extern crate log;
|
#[macro_use] extern crate log;
|
||||||
|
|
1
src/base64/deps.mk
Normal file
1
src/base64/deps.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DEPLIBS += rustc-serialize
|
2
src/chmod/deps.mk
Normal file
2
src/chmod/deps.mk
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
DEPLIBS += regex
|
||||||
|
DEPPLUGS += regex_macros
|
|
@ -8,7 +8,7 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
use std::fs::OpenOptions;
|
use std::fs::File;
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
|
||||||
static CRC_TABLE_LEN: usize = 256;
|
static CRC_TABLE_LEN: usize = 256;
|
||||||
|
@ -18,10 +18,10 @@ fn main() {
|
||||||
for num in (0 .. CRC_TABLE_LEN) {
|
for num in (0 .. CRC_TABLE_LEN) {
|
||||||
table.push(crc_entry(num as u8) as u32);
|
table.push(crc_entry(num as u8) as u32);
|
||||||
}
|
}
|
||||||
let file = OpenOptions::new().truncate(true).write(true).open("crc_table.rs").ok().unwrap();
|
let file = File::create("crc_table.rs").unwrap_or_else(|e| panic!("{}", e));
|
||||||
write!(&file, "/* auto-generated (DO NOT EDIT) */
|
write!(&file, "/* auto-generated (DO NOT EDIT) */
|
||||||
|
|
||||||
pub static CRC_TABLE: [u32; {}] = {:?};", CRC_TABLE_LEN, table);
|
pub static CRC_TABLE: [u32; {}] = {:?};", CRC_TABLE_LEN, table).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
#[inline]
|
#[inline]
|
||||||
|
|
1
src/du/deps.mk
Normal file
1
src/du/deps.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DEPLIBS += time
|
1
src/fmt/deps.mk
Normal file
1
src/fmt/deps.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DEPLIBS += unicode-width
|
|
@ -9,11 +9,12 @@
|
||||||
* file that was distributed with this source code.
|
* file that was distributed with this source code.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#![feature(box_syntax,core,rustc_private,collections,str_char,unicode,str_words)]
|
#![feature(box_syntax,core,rustc_private,collections,str_char,unicode)]
|
||||||
|
|
||||||
extern crate core;
|
extern crate core;
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate unicode;
|
extern crate rustc_unicode;
|
||||||
|
extern crate unicode_width;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::io::{Read, BufReader, BufWriter};
|
use std::io::{Read, BufReader, BufWriter};
|
||||||
|
|
|
@ -10,7 +10,6 @@
|
||||||
use FmtOptions;
|
use FmtOptions;
|
||||||
use parasplit::{Paragraph, ParaWords, WordInfo};
|
use parasplit::{Paragraph, ParaWords, WordInfo};
|
||||||
use std::io::{Write, BufWriter, Stdout};
|
use std::io::{Write, BufWriter, Stdout};
|
||||||
use std::num::{Float, Int, SignedInt};
|
|
||||||
use std::i64;
|
use std::i64;
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
@ -373,7 +372,7 @@ fn compute_demerits(delta_len: isize, stretch: isize, wlen: isize, prev_rat: f32
|
||||||
// we penalize lines that have very different ratios from previous lines
|
// we penalize lines that have very different ratios from previous lines
|
||||||
let bad_delta_r = (DR_MULT * (((ratio - prev_rat) / 2.0).powf(3f32)).abs()) as i64;
|
let bad_delta_r = (DR_MULT * (((ratio - prev_rat) / 2.0).powf(3f32)).abs()) as i64;
|
||||||
|
|
||||||
let demerits = Int::pow(1 + bad_linelen + bad_wordlen + bad_delta_r, 2);
|
let demerits = i64::pow(1 + bad_linelen + bad_wordlen + bad_delta_r, 2);
|
||||||
|
|
||||||
(demerits, ratio)
|
(demerits, ratio)
|
||||||
}
|
}
|
||||||
|
|
|
@ -11,7 +11,8 @@ use core::iter::Peekable;
|
||||||
use std::io::{BufRead, Lines};
|
use std::io::{BufRead, Lines};
|
||||||
use std::slice::Iter;
|
use std::slice::Iter;
|
||||||
use std::str::CharRange;
|
use std::str::CharRange;
|
||||||
use unicode::str::UnicodeStr;
|
use rustc_unicode::str::UnicodeStr;
|
||||||
|
use unicode_width::UnicodeWidthChar;
|
||||||
use FileOrStdReader;
|
use FileOrStdReader;
|
||||||
use FmtOptions;
|
use FmtOptions;
|
||||||
|
|
||||||
|
@ -25,7 +26,7 @@ fn char_width(c: char) -> usize {
|
||||||
// otherwise, get the unicode width
|
// otherwise, get the unicode width
|
||||||
// note that we shouldn't actually get None here because only c < 0xA0
|
// note that we shouldn't actually get None here because only c < 0xA0
|
||||||
// can return None, but for safety and future-proofing we do it this way
|
// can return None, but for safety and future-proofing we do it this way
|
||||||
c.width(false).unwrap_or(1)
|
UnicodeWidthChar::width(c).unwrap_or(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -415,7 +416,7 @@ impl<'a> ParaWords<'a> {
|
||||||
// no extra spacing for mail headers; always exactly 1 space
|
// no extra spacing for mail headers; always exactly 1 space
|
||||||
// safe to trim_left on every line of a mail header, since the
|
// safe to trim_left on every line of a mail header, since the
|
||||||
// first line is guaranteed not to have any spaces
|
// first line is guaranteed not to have any spaces
|
||||||
self.words.extend(self.para.lines.iter().flat_map(|x| x.words()).map(|x| WordInfo {
|
self.words.extend(self.para.lines.iter().flat_map(|x| x.split_whitespace()).map(|x| WordInfo {
|
||||||
word : x,
|
word : x,
|
||||||
word_start : 0,
|
word_start : 0,
|
||||||
word_nchars : x.len(), // OK for mail headers; only ASCII allowed (unicode is escaped)
|
word_nchars : x.len(), // OK for mail headers; only ASCII allowed (unicode is escaped)
|
||||||
|
|
1
src/hashsum/deps.mk
Normal file
1
src/hashsum/deps.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DEPLIBS += regex crypto rand rustc-serialize time
|
2
src/nl/deps.mk
Normal file
2
src/nl/deps.mk
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
DEPLIBS += regex
|
||||||
|
DEPPLUGS += regex_macros
|
|
@ -1,5 +1,5 @@
|
||||||
#![crate_name = "seq"]
|
#![crate_name = "seq"]
|
||||||
#![feature(collections, core, rustc_private)]
|
#![feature(rustc_private)]
|
||||||
|
|
||||||
// TODO: Make -w flag work with decimals
|
// TODO: Make -w flag work with decimals
|
||||||
// TODO: Support -f flag
|
// TODO: Support -f flag
|
||||||
|
@ -8,6 +8,7 @@ extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
|
|
||||||
use std::cmp;
|
use std::cmp;
|
||||||
|
use std::io::Write;
|
||||||
|
|
||||||
#[path = "../common/util.rs"]
|
#[path = "../common/util.rs"]
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -43,7 +44,7 @@ fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<Stri
|
||||||
let mut iter = args.into_iter().skip(1);
|
let mut iter = args.into_iter().skip(1);
|
||||||
loop {
|
loop {
|
||||||
match iter.next() {
|
match iter.next() {
|
||||||
Some(arg) => match arg.as_slice() {
|
Some(arg) => match &arg[..] {
|
||||||
"--help" | "-h" => {
|
"--help" | "-h" => {
|
||||||
print_help(&program);
|
print_help(&program);
|
||||||
return Err(0);
|
return Err(0);
|
||||||
|
@ -72,9 +73,9 @@ fn parse_options(args: Vec<String>, options: &mut SeqOptions) -> Result<Vec<Stri
|
||||||
break;
|
break;
|
||||||
},
|
},
|
||||||
_ => {
|
_ => {
|
||||||
if arg.len() > 1 && arg.as_slice().char_at(0) == '-' {
|
if arg.len() > 1 && arg.chars().next().unwrap() == '-' {
|
||||||
let argptr: *const String = &arg; // escape from the borrow checker
|
let argptr: *const String = &arg; // escape from the borrow checker
|
||||||
let mut chiter = unsafe { (*argptr).as_slice() }.chars().skip(1);
|
let mut chiter = unsafe { &(*argptr)[..] }.chars().skip(1);
|
||||||
let mut ch = ' ';
|
let mut ch = ' ';
|
||||||
while match chiter.next() { Some(m) => { ch = m; true } None => false } {
|
while match chiter.next() { Some(m) => { ch = m; true } None => false } {
|
||||||
match ch {
|
match ch {
|
||||||
|
@ -164,7 +165,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
let mut largest_dec = 0;
|
let mut largest_dec = 0;
|
||||||
let mut padding = 0;
|
let mut padding = 0;
|
||||||
let first = if free.len() > 1 {
|
let first = if free.len() > 1 {
|
||||||
let slice = free[0].as_slice();
|
let slice = &free[0][..];
|
||||||
let len = slice.len();
|
let len = slice.len();
|
||||||
let dec = slice.find('.').unwrap_or(len);
|
let dec = slice.find('.').unwrap_or(len);
|
||||||
largest_dec = len - dec;
|
largest_dec = len - dec;
|
||||||
|
@ -177,7 +178,7 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
1.0
|
1.0
|
||||||
};
|
};
|
||||||
let step = if free.len() > 2 {
|
let step = if free.len() > 2 {
|
||||||
let slice = free[1].as_slice();
|
let slice = &free[1][..];
|
||||||
let len = slice.len();
|
let len = slice.len();
|
||||||
let dec = slice.find('.').unwrap_or(len);
|
let dec = slice.find('.').unwrap_or(len);
|
||||||
largest_dec = cmp::max(largest_dec, len - dec);
|
largest_dec = cmp::max(largest_dec, len - dec);
|
||||||
|
@ -190,16 +191,16 @@ pub fn uumain(args: Vec<String>) -> i32 {
|
||||||
1.0
|
1.0
|
||||||
};
|
};
|
||||||
let last = {
|
let last = {
|
||||||
let slice = free[free.len() - 1].as_slice();
|
let slice = &free[free.len() - 1][..];
|
||||||
padding = cmp::max(padding, slice.find('.').unwrap_or(slice.len()));
|
padding = cmp::max(padding, slice.find('.').unwrap_or(slice.len()));
|
||||||
match parse_float(slice) {
|
match parse_float(slice) {
|
||||||
Ok(n) => n,
|
Ok(n) => n,
|
||||||
Err(s) => { show_error!("{}", s); return 1; }
|
Err(s) => { show_error!("{}", s); return 1; }
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let separator = escape_sequences(options.separator.as_slice());
|
let separator = escape_sequences(&options.separator[..]);
|
||||||
let terminator = match options.terminator {
|
let terminator = match options.terminator {
|
||||||
Some(term) => escape_sequences(term.as_slice()),
|
Some(term) => escape_sequences(&term[..]),
|
||||||
None => separator.clone()
|
None => separator.clone()
|
||||||
};
|
};
|
||||||
print_seq(first, step, last, largest_dec, separator, terminator, options.widths, padding);
|
print_seq(first, step, last, largest_dec, separator, terminator, options.widths, padding);
|
||||||
|
@ -222,9 +223,9 @@ fn print_seq(first: f64, step: f64, last: f64, largest_dec: usize, separator: St
|
||||||
while !done_printing(value, step, last) {
|
while !done_printing(value, step, last) {
|
||||||
let istr = value.to_string();
|
let istr = value.to_string();
|
||||||
let ilen = istr.len();
|
let ilen = istr.len();
|
||||||
let before_dec = istr.as_slice().find('.').unwrap_or(ilen);
|
let before_dec = istr.find('.').unwrap_or(ilen);
|
||||||
if pad && before_dec < padding {
|
if pad && before_dec < padding {
|
||||||
for _ in range(0, padding - before_dec) {
|
for _ in 0..(padding - before_dec) {
|
||||||
if !pipe_print!("0") {
|
if !pipe_print!("0") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -239,7 +240,7 @@ fn print_seq(first: f64, step: f64, last: f64, largest_dec: usize, separator: St
|
||||||
}
|
}
|
||||||
idec += 1;
|
idec += 1;
|
||||||
}
|
}
|
||||||
for _ in range(idec, largest_dec) {
|
for _ in idec..largest_dec {
|
||||||
if !pipe_print!("0") {
|
if !pipe_print!("0") {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
1
src/touch/deps.mk
Normal file
1
src/touch/deps.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DEPLIBS += time
|
1
src/uptime/deps.mk
Normal file
1
src/uptime/deps.mk
Normal file
|
@ -0,0 +1 @@
|
||||||
|
DEPLIBS += time
|
|
@ -16,7 +16,7 @@
|
||||||
|
|
||||||
extern crate getopts;
|
extern crate getopts;
|
||||||
extern crate libc;
|
extern crate libc;
|
||||||
extern crate "time" as rtime;
|
extern crate time as rtime;
|
||||||
|
|
||||||
use std::ffi::CString;
|
use std::ffi::CString;
|
||||||
use std::mem::transmute;
|
use std::mem::transmute;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue