swab(1) #73

Closed
trinity wants to merge 0 commits from swab into main
Owner

Implements #22.

Implements #22.
trinity added the
enhancement
label 2024-02-24 03:25:03 -07:00
trinity added 3 commits 2024-02-24 03:25:03 -07:00
trinity requested review from emma 2024-02-24 03:26:50 -07:00
emma approved these changes 2024-02-24 14:44:25 -07:00
emma left a comment
Owner

Looks really good!

Looks really good!
@ -102,2 +102,4 @@
$(CC) $(CFLAGS) -o $@ src/strcmp.c
.PHONY: swab
swab: build/bin/swab
Owner

Don’t forget to add swab to the all target!

Don’t forget to add swab to the all target!
trinity marked this conversation as resolved
src/swab.rs Outdated
@ -0,0 +1,72 @@
use std::{
Owner

Needs a copyright header :)

Needs a copyright header :)
trinity marked this conversation as resolved
src/swab.rs Outdated
@ -0,0 +51,4 @@
buf.resize(wordsize, 0);
loop {
match input.read(&mut buf) {
Owner

This seems cleaner to me, but it doesn’t really matter:

		match input.read(&mut buf) {
			Ok(0) => break ExitCode::from(EX_OK as u8),
			Ok(v)  => {
				if v == wordsize {
					let (left, right) = buf.split_at(v/2);
					if let Err(e) = output.write(&right)
							.and_then(|_| output.write(&left)) {
						break oserr(&argv[0], e)
					}
				} else {
					if let Err(e) = output.write(&buf[..v]) {
						break oserr(&argv[0], e)
					}
				}
			},
			Err(e) => {
				if e.kind() == ErrorKind::Interrupted && force { continue }
				else { break oserr(&argv[0], e) }
			},
		}
This seems cleaner to me, but it doesn’t really matter: ```rs match input.read(&mut buf) { Ok(0) => break ExitCode::from(EX_OK as u8), Ok(v) => { if v == wordsize { let (left, right) = buf.split_at(v/2); if let Err(e) = output.write(&right) .and_then(|_| output.write(&left)) { break oserr(&argv[0], e) } } else { if let Err(e) = output.write(&buf[..v]) { break oserr(&argv[0], e) } } }, Err(e) => { if e.kind() == ErrorKind::Interrupted && force { continue } else { break oserr(&argv[0], e) } }, } ```
Author
Owner

I prefer my style of mostly using the match statement.

I prefer my style of mostly using the match statement.
trinity marked this conversation as resolved
trinity added 2 commits 2024-02-26 17:04:47 -07:00
trinity requested review from emma 2024-02-27 04:06:02 -07:00
emma approved these changes 2024-02-28 00:10:04 -07:00
emma closed this pull request 2024-03-18 20:54:50 -06:00

Pull request closed

Sign in to join this conversation.
No reviewers
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: bonsai/harakit#73
No description provided.