Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hacking #20

Merged
merged 5 commits into from
Feb 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 23 additions & 4 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ members = [
"misc",
"pathnames",
"plib",
"sys",
"text",
"tree",
"users",
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -151,9 +151,9 @@ A similar project from the author, written in C++, is https://github.com/jgarzik
- [ ] tr
- [x] true
- [ ] tsort
- [ ] tty
- [x] tty
- [ ] ulimit
- [ ] uname
- [x] uname
- [ ] uncompress (compress cat.)
- [ ] unexpand
- [ ] unget
Expand Down
11 changes: 0 additions & 11 deletions display/NOTES.md

This file was deleted.

9 changes: 7 additions & 2 deletions display/src/echo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,20 @@
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//
// TODO:
// - echo needs to translate backslash-escaped octal numbers:
// ```
// \0num
// Write an 8-bit value that is the 0, 1, 2 or 3-digit octal number _num_.
//

extern crate plib;

use gettextrs::{bind_textdomain_codeset, textdomain};
use plib::PROJECT_NAME;

fn translate_str(s: &str) -> String {
let mut output = String::new();
output.reserve(s.len());
let mut output = String::with_capacity(s.len());

let mut in_bs = false;
let mut nl = true;
Expand Down
10 changes: 0 additions & 10 deletions file/NOTES.md

This file was deleted.

5 changes: 5 additions & 0 deletions file/src/cat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//
// TODO:
// - Bug: if stdout write_all() produces Err, the program will erroneously
// output the filename as the culprit, rather than the string "stdout"
// - Questionable behavior: if write_all() produces Err, the program will
// continue to the next file, rather than stopping.

extern crate clap;
extern crate plib;
Expand Down
1 change: 1 addition & 0 deletions link/src/link.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use gettextrs::{bind_textdomain_codeset, textdomain};
use plib::PROJECT_NAME;
use std::{fs, io};

/// link - call link function
#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
struct Args {
Expand Down
1 change: 1 addition & 0 deletions link/src/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use plib::PROJECT_NAME;
use std::path::{Path, PathBuf};
use std::{fs, io};

/// ln - link files
#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
struct Args {
Expand Down
2 changes: 2 additions & 0 deletions link/src/unlink.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ use gettextrs::{bind_textdomain_codeset, textdomain};
use plib::PROJECT_NAME;
use std::{fs, io};

/// unlink - call the unlink function
#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
struct Args {
/// The pathname of an existing file.
pathname: String,
}

Expand Down
1 change: 1 addition & 0 deletions pathnames/src/basename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use gettextrs::{bind_textdomain_codeset, textdomain};
use plib::PROJECT_NAME;
use std::path::Path;

/// basename - return non-directory portion of a pathname
#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
struct Args {
Expand Down
1 change: 1 addition & 0 deletions pathnames/src/dirname.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use gettextrs::{bind_textdomain_codeset, textdomain};
use plib::PROJECT_NAME;
use std::path::PathBuf;

/// dirname - return the directory portion of a pathname
#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
struct Args {
Expand Down
15 changes: 15 additions & 0 deletions sys/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "posixutils-sys"
version = "0.1.0"
edition = "2021"

[dependencies]
plib = { path = "../plib" }
clap = { version = "4", features = ["derive"] }
gettext-rs = { version = "0.7", features = ["gettext-system"] }
uname = "0.1"

[[bin]]
name = "uname"
path = "src/uname.rs"

98 changes: 98 additions & 0 deletions sys/src/uname.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
//
// Copyright (c) 2024 Jeff Garzik
//
// This file is part of the posixutils-rs project covered under
// the MIT License. For the full license text, please see the LICENSE
// file in the root directory of this project.
// SPDX-License-Identifier: MIT
//
// TODO:
// - the "-v" option is specified by POSIX and cannot be clap default -v
//

extern crate clap;
extern crate plib;
extern crate uname;

use clap::Parser;
use gettextrs::{bind_textdomain_codeset, textdomain};
use plib::PROJECT_NAME;

/// uname - return system name
#[derive(Parser, Debug)]
#[command(author, version, about, long_about)]
struct Args {
/// Behave as though all of the options -mnrsv were specified.
#[arg(short, long)]
all: bool,

/// Write the name of the hardware type on which the system is running to standard output.
#[arg(short, long)]
machine: bool,

/// Write the name of this node within an implementation-defined communications network.
#[arg(short, long)]
node: bool,

/// Write the current release level of the operating system implementation.
#[arg(short, long)]
release: bool,

/// Write the name of the implementation of the operating system.
#[arg(short, long)]
system: bool,

/// Write the current version level of this release of the operating system implementation.
#[arg(short, long)]
osversion: bool,
}

fn print_info(args: &Args, info: uname::Info) {
let mut outs = Vec::new();

if args.system {
outs.push(info.sysname);
}
if args.node {
outs.push(info.nodename);
}
if args.release {
outs.push(info.release);
}
if args.osversion {
outs.push(info.version);
}
if args.machine {
outs.push(info.machine);
}

println!("{}", outs.join(" "));
}

fn main() -> Result<(), Box<dyn std::error::Error>> {
// parse command line arguments
let mut args = Args::parse();

if args.all {
args.machine = true;
args.node = true;
args.release = true;
args.system = true;
args.osversion = true;
}

textdomain(PROJECT_NAME)?;
bind_textdomain_codeset(PROJECT_NAME, "UTF-8")?;

let mut exit_code = 0;

match uname::uname() {
Ok(info) => print_info(&args, info),
Err(e) => {
eprintln!("{}", e);
exit_code = 1;
}
}

std::process::exit(exit_code)
}
Loading