From 1c6e2970f756d9812118a8543ca0bbcf93e8b912 Mon Sep 17 00:00:00 2001 From: DTB Date: Tue, 23 Jul 2024 17:58:49 -0600 Subject: [PATCH] retval(1) sans documentation --- Makefile | 7 ++++++- src/retval.rs | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) create mode 100644 src/retval.rs diff --git a/Makefile b/Makefile index 94d0b78..9e79579 100644 --- a/Makefile +++ b/Makefile @@ -32,7 +32,7 @@ RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \ CFLAGS += -I$(SYSEXITS) .PHONY: all -all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true +all: dj false fop hru intcmp mm npc retval rpn scrut str strcmp swab true # keep build/include until bindgen(1) has stdin support # https://github.com/rust-lang/rust-bindgen/issues/2703 @@ -122,6 +122,11 @@ npc: build/bin/npc build/bin/npc: src/npc.c build $(CC) $(CFLAGAS) -o $@ src/npc.c +.PHONY: retval +retval: build/bin/retval +build/bin/retval: src/retval.rs build rustlibs + $(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/retval.rs + .PHONY: rpn rpn: build/bin/rpn build/bin/rpn: src/rpn.rs build rustlibs diff --git a/src/retval.rs b/src/retval.rs new file mode 100644 index 0000000..3aa3ce4 --- /dev/null +++ b/src/retval.rs @@ -0,0 +1,39 @@ +/* + * Copyright (c) 2024 DTB + * SPDX-License-Identifier: AGPL-3.0-or-later + * + * This program is free software: you can redistribute it and/or modify it under + * the terms of the GNU Affero General Public License as published by the Free + * Software Foundation, either version 3 of the License, or (at your option) any + * later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS + * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more + * details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see https://www.gnu.org/licenses/. + */ + +use std::{ env::args, process::ExitCode }; + +extern crate sysexits; +use sysexits::EX_USAGE; + +fn usage(s: &str) -> ExitCode { + eprintln!("Usage: {} status", s); + ExitCode::from(EX_USAGE) +} + +fn main() -> ExitCode { + let argv = args().collect::>(); + + match argv.len() { + 2 => match argv[1].parse::() { + Ok(e) => ExitCode::from(e), + _ => usage(&argv[0]) + }, + _ => usage(&argv[0]) + } +}