diff --git a/.gitignore b/.gitignore new file mode 100644 index 000000000..d9b4f015d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +/build/* diff --git a/LICENSE b/LICENSE index bc1cde8ee..0177c4ab7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,4 @@ -The MIT License (MIT) - -Copyright (c) 2013 uutils +Copyright (c) Jordi Boggiano Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..d43b21f12 --- /dev/null +++ b/Makefile @@ -0,0 +1,10 @@ +build: + rm -rf build + mkdir build + # run through the shell since make acting up on windows + sh -c 'rustc --out-dir build/ false/false.rs' + sh -c 'rustc --out-dir build/ printenv/printenv.rs' + sh -c 'rustc --out-dir build/ true/true.rs' + sh -c 'rustc --out-dir build/ yes/yes.rs' + +.PHONY: build diff --git a/README.md b/README.md index 41c2938fb..3bbe469dc 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,139 @@ -coreutils -========= +uutils coreutils +================ + +uutils is an attempt at writing universal (as in cross-platform) CLI +utils in [Rust](http://rust-lang.org). This repo is to aggregate the GNU +coreutils rewrites. + +Why? +---- + +Many GNU, linux and other utils are pretty awesome, and obviously +[some](http://gnuwin32.sourceforge.net) [effort](http://unxutils.sourceforge.net) +has been spent in the past to port them to windows. However those projects +are either old, abandonned, hosted on CVS, written in platform-specific C, etc. + +Rust provides a good platform-agnostic way of writing systems utils that are easy +to compile anywhere, and this is as good a way as any to try and learn it. + +To do +----- + +- base64 +- basename +- cat +- chcon +- chgrp +- chmod +- chown-core +- chown +- chroot +- cksum +- comm +- copy +- cp-hash +- cp +- csplit +- cut +- date +- dd +- df +- dircolors +- dirname +- du +- echo +- env +- expand +- expr +- extent-scan +- factor +- find-mount-point +- fmt +- fold +- getlimits +- group-list +- groups +- head +- hostid +- hostname +- id +- install +- join +- kill +- lbracket +- libstdbuf +- link +- ln +- logname +- ls-dir +- ls-ls +- ls-vdir +- ls +- make-prime-list +- md5sum +- mkdir +- mkfifo +- mknod +- mktemp +- mv +- nice +- nl +- nohup +- nproc +- numfmt +- od +- operand2sig +- paste +- pathchk +- pinky +- pr +- printf +- prog-fprintf +- ptx +- pwd +- readlink +- realpath +- relpath +- remove +- rm +- rmdir +- runcon +- seq +- setuidgid +- shred +- shuf +- sleep +- sort +- split +- stat +- stdbuf +- stty +- sum +- sync +- tac-pipe +- tac +- tail +- tee +- test +- timeout +- touch +- tr +- truncate +- tsort +- tty +- uname-arch +- uname-uname +- uname +- unexpand +- uniq +- unlink +- uptime +- users +- wc +- who +- whoami + +License +------- + +uutils are licensed under the MIT License - see the `LICENSE` file for details diff --git a/false/false.rs b/false/false.rs new file mode 100644 index 000000000..12f63207c --- /dev/null +++ b/false/false.rs @@ -0,0 +1,14 @@ +#[link(name="false", vers="1.0.0", author="Seldaek")]; + +/* + * This file is part of the uutils coreutils package. + * + * (c) Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +fn main() { + std::os::set_exit_status(1); +} diff --git a/printenv/printenv.rs b/printenv/printenv.rs new file mode 100644 index 000000000..248719c39 --- /dev/null +++ b/printenv/printenv.rs @@ -0,0 +1,77 @@ +#[link(name="printenv", vers="1.0.0", author="Seldaek")]; + +/* + * This file is part of the uutils coreutils package. + * + * (c) Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* last synced with: printenv (GNU coreutils) 8.13 */ + +extern mod extra; + +use std::os; +use std::io::stderr; +use extra::getopts::*; + +fn main() { + let args = os::args(); + let program = copy args[0]; + let opts = ~[ + groups::optflag("0", "null", "end each output line with 0 byte rather than newline"), + groups::optflag("h", "help", "display this help and exit"), + groups::optflag("V", "version", "output version information and exit"), + ]; + let matches = match groups::getopts(args.tail(), opts) { + Ok(m) => m, + Err(f) => { + stderr().write_line("Invalid options"); + stderr().write_line(fail_str(f)); + os::set_exit_status(1); + return + } + }; + if opts_present(&matches, [~"h", ~"help"]) { + println("printenv 1.0.0"); + println(""); + println("Usage:"); + println(fmt!(" %s [VARIABLE]... [OPTION]...", program)); + println(""); + print(groups::usage("Prints the given environment VARIABLE(s), otherwise prints them all.", opts)); + return; + } + if opts_present(&matches, [~"V", ~"version"]) { + println("printenv 1.0.0"); + return; + } + let mut separator = "\n"; + if opts_present(&matches, [~"0", ~"null"]) { + separator = "\x00"; + }; + + exec(matches.free, separator); +} + +pub fn exec(args: ~[~str], separator: &str) { + if args.is_empty() { + let vars = os::env(); + for vars.iter().advance |&(env_var, value)| { + print(fmt!("%s=%s", env_var, value)); + print(separator); + } + return; + } + + for args.iter().advance |env_var| { + match os::getenv(*env_var) { + Some(var) => { + print(var); + print(separator); + } + _ => () + } + } +} diff --git a/true/true.rs b/true/true.rs new file mode 100644 index 000000000..b2d785a02 --- /dev/null +++ b/true/true.rs @@ -0,0 +1,13 @@ +#[link(name="true", vers="1.0.0", author="Seldaek")]; + +/* + * This file is part of the uutils coreutils package. + * + * (c) Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +fn main() { +} diff --git a/yes/yes.rs b/yes/yes.rs new file mode 100644 index 000000000..794465299 --- /dev/null +++ b/yes/yes.rs @@ -0,0 +1,61 @@ +#[link(name="yes", vers="1.0.0", author="Seldaek")]; + +/* + * This file is part of the uutils coreutils package. + * + * (c) Jordi Boggiano + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/* last synced with: yes (GNU coreutils) 8.13 */ + +extern mod extra; + +use std::os; +use std::io::stderr; +use extra::getopts::*; + +fn main() { + let args = os::args(); + let program = copy args[0]; + let opts = ~[ + groups::optflag("h", "help", "display this help and exit"), + groups::optflag("V", "version", "output version information and exit"), + ]; + let matches = match groups::getopts(args.tail(), opts) { + Ok(m) => m, + Err(f) => { + stderr().write_line("Invalid options"); + stderr().write_line(fail_str(f)); + os::set_exit_status(1); + return + } + }; + if opts_present(&matches, [~"h", ~"help"]) { + println("yes 1.0.0"); + println(""); + println("Usage:"); + println(fmt!(" %s [STRING]... [OPTION]...", program)); + println(""); + print(groups::usage("Repeatedly output a line with all specified STRING(s), or 'y'.", opts)); + return; + } + if opts_present(&matches, [~"V", ~"version"]) { + println("yes 1.0.0"); + return; + } + let mut string = ~"y"; + if !matches.free.is_empty() { + string = matches.free.connect(" "); + } + + exec(string); +} + +pub fn exec(string: ~str) { + loop { + println(string); + } +}