wc
OS in Rust
Announcements
- Lab Day
- Set up environment
- Building a command line program
Homework
- “CLI” is just this lab but more complete.
- Windows officially no longer supported.
- Due Friday, 23 Jan. at 1440 ET.
- Plan to hang out as a class 1310-1440 on Fridays, probably.
Setup
- If you are stuck setting up Rust, following this
- At the end you should have:
cargo,git, and at least one ofgccorclangon your system.- A repository named
371oson Github that is either (1) public or (2) shared with [cd-public](https://github.com/cd-public
Requirements
-
- That is, you must support
wc src/main.rsbut notwc --files0-from=F src/main.rs - Check out
wcandwc --help(which you don’t need to provide) to get a sense of the task.
- That is, you must support
Exercise
Repository
Crate
- To complete the lab today, create a crate named
my_wcin a folder named01in your371osrepository.
- If you’re stuck, read more here
wc
- Implement the minimal base functionality of
wcusing this crate.
Full functionality
- Here is
wc --help - You do not need to do all of this!
Usage: wc [OPTION]... [FILE]...
or: wc [OPTION]... --files0-from=F
Print newline, word, and byte counts for each FILE, and a total line if
more than one FILE is specified. A word is a non-zero-length sequence of
characters delimited by white space.
With no FILE, or when FILE is -, read standard input.
The options below may be used to select which counts are printed, always in
the following order: newline, word, character, byte, maximum line length.
-c, --bytes print the byte counts
-m, --chars print the character counts
-l, --lines print the newline counts
--files0-from=F read input from the files specified by
NUL-terminated names in file F;
If F is - then read names from standard input
-L, --max-line-length print the maximum display width
-w, --words print the word counts
--help display this help and exit
--version output version information and exit
GNU coreutils online help: <https://www.gnu.org/software/coreutils/>
Report any translation bugs to <https://translationproject.org/team/>
Full documentation <https://www.gnu.org/software/coreutils/wc>
or available locally via: info '(coreutils) wc invocation'Required functionality
- That is more than required, you need only implement:
Usage: wc [FILE]
Print newline, word, and byte counts for each FILE. A word is a
non-zero-length sequence of characters delimited by white space.- This can be trivially tested with some of the following:
$ wc src/main.rs
12 30 229 src/main.rs
$ cargo build release
$ ./target/release/my_wc src/main.rs
12 30 229 src/main.rs- Your
src/main.rsneed not be of any particular size, and you needn’t implement all code withinsrc/main.rs, but you should get the same counts fromwcand from your release binary.
Helpful Reference
- When working on projects like this, I almost always have the following reference material open.
- read_lines - Rust By Example