From d1907edd651439cd555bbdfab38003a4f2e479e1 Mon Sep 17 00:00:00 2001 From: Tyler Date: Sat, 24 Jul 2021 16:38:08 -0700 Subject: [PATCH] Adds additional words to exclude list. Improves documentation in dd.rs. --- src/uu/dd/src/dd.rs | 48 ++++++++++++++----- .../src/dd_unit_tests/block_unblock_tests.rs | 2 +- .../dd/src/dd_unit_tests/conv_sync_tests.rs | 2 +- .../dd/src/dd_unit_tests/conversion_tests.rs | 2 +- src/uu/dd/src/dd_unit_tests/mod.rs | 2 +- src/uu/dd/src/dd_unit_tests/sanity_tests.rs | 2 +- src/uu/dd/src/parseargs/unit_tests.rs | 2 +- tests/by-util/test_dd.rs | 2 +- 8 files changed, 43 insertions(+), 19 deletions(-) diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 6eef1350e..ef250c67c 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -5,6 +5,8 @@ // For the full copyright and license information, please view the LICENSE // file that was distributed with this source code. +// spell-checker:ignore fname, tname, fpath, specfile, testfile, unspec, ifile, ofile, outfile, fullblock, urand, fileio, atoe, atoibm, availible, behaviour, bmax, bremain, btotal, cflags, creat, ctable, ctty, datastructures, doesnt, etoa, fileout, fname, gnudd, iconvflags, nocache, noctty, noerror, nofollow, nolinks, nonblock, oconvflags, outfile, parseargs, rlen, rmax, rposition, rremain, rsofar, rstat, sigusr, sigval, wlen, wstat + #[macro_use] extern crate uucore; use uucore::InvalidEncodingHandling; @@ -41,7 +43,6 @@ use std::sync::{atomic::AtomicUsize, mpsc, Arc}; use std::thread; use std::time; -// const SYNTAX: &str = "dd [OPERAND]...\ndd OPTION"; const ABOUT: &str = "copy, and optionally convert, a file system resource"; const BUF_INIT_BYTE: u8 = 0xDD; const RTN_SUCCESS: i32 = 0; @@ -428,6 +429,7 @@ impl Write for Output { } impl Output { + /// Write all data in the given buffer in writes of size obs. fn write_blocks(&mut self, buf: Vec) -> io::Result { let mut writes_complete = 0; let mut writes_partial = 0; @@ -455,6 +457,7 @@ impl Output { } impl Output { + /// Write all data in the given buffer in writes of size obs. fn write_blocks(&mut self, buf: Vec) -> io::Result { let mut writes_complete = 0; let mut writes_partial = 0; @@ -483,6 +486,7 @@ impl Output { /// Splits the content of buf into cbs-length blocks /// Appends padding as specified by conv=block and cbs=N +/// Expects ascii encoded data fn block(buf: Vec, cbs: usize, rstat: &mut ReadStat) -> Vec> { let mut blocks = buf .split(|&e| e == b'\n') @@ -508,6 +512,7 @@ fn block(buf: Vec, cbs: usize, rstat: &mut ReadStat) -> Vec> { /// Trims padding from each cbs-length partition of buf /// as specified by conv=unblock and cbs=N +/// Expects ascii encoded data fn unblock(buf: Vec, cbs: usize) -> Vec { buf.chunks(cbs).fold(Vec::new(), |mut acc, block| { if let Some(last_char_idx) = block.iter().rposition(|&e| e != b' ') { @@ -523,6 +528,13 @@ fn unblock(buf: Vec, cbs: usize) -> Vec { }) } +/// A helper for teasing out which options must be applied and in which order. +/// Some user options, such as the presence of conversion tables, will determine whether the input is assumed to be ascii. The parser sets the Input::non_ascii flag accordingly. +/// Examples: +/// - If conv=ebcdic or conv=ibm is specified then block, unblock or swab must be performed before the conversion happens since the source will start in ascii. +/// - If conv=ascii is specified then block, unblock or swab must be performed after the conversion since the source starts in ebcdic. +/// - If no conversion is specified then the source is assumed to be in ascii. +/// For more info see `info dd` fn conv_block_unblock_helper( mut buf: Vec, i: &mut Input, @@ -615,6 +627,7 @@ fn conv_block_unblock_helper( } } +/// Read helper performs read operations common to all dd reads, and dispatches the buffer to relevent helper functions as dictated by the operations requested by the user. fn read_helper( i: &mut Input, bsize: usize, @@ -659,6 +672,9 @@ fn read_helper( } } +// Print io lines of a status update: +// + records in +// + records out fn print_io_lines(update: &ProgUpdate) { eprintln!( "{}+{} records in", @@ -672,6 +688,8 @@ fn print_io_lines(update: &ProgUpdate) { update.write_stat.writes_complete, update.write_stat.writes_partial ); } +// Print the progress line of a status update: +// bytes (, ) copied,