forked from bonsai/harakit
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
9093b06166
|
|||
|
d8b54fdbf5
|
|||
|
f6aac60aee
|
14
Makefile
14
Makefile
@@ -17,6 +17,8 @@
|
|||||||
DESTDIR ?= dist
|
DESTDIR ?= dist
|
||||||
PREFIX ?= /usr/local
|
PREFIX ?= /usr/local
|
||||||
|
|
||||||
|
MANDIR != [ $(PREFIX) = / ] && printf '/usr/share/man\n' \
|
||||||
|
|| printf '/share/man\n'
|
||||||
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | sed 's/ /\n/g' \
|
SYSEXITS != printf '\043include <sysexits.h>\n' | cpp -M - | sed 's/ /\n/g' \
|
||||||
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
| sed -n 's/sysexits\.h//p' || printf 'include\n'
|
||||||
|
|
||||||
@@ -28,7 +30,7 @@ RUSTLIBS = --extern getopt=build/o/libgetopt.rlib \
|
|||||||
CFLAGS += -I$(SYSEXITS)
|
CFLAGS += -I$(SYSEXITS)
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: dj false fop hru intcmp mm npc rpn scrut sleep str strcmp swab true
|
all: dj false fop hru intcmp mm npc rpn scrut str strcmp swab true
|
||||||
|
|
||||||
build:
|
build:
|
||||||
# keep build/include until bindgen(1) has stdin support
|
# keep build/include until bindgen(1) has stdin support
|
||||||
@@ -42,7 +44,7 @@ clean:
|
|||||||
dist: all
|
dist: all
|
||||||
mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1
|
mkdir -p $(DESTDIR)/$(PREFIX)/bin $(DESTDIR)/$(PREFIX)/share/man/man1
|
||||||
cp build/bin/* $(DESTDIR)/$(PREFIX)/bin
|
cp build/bin/* $(DESTDIR)/$(PREFIX)/bin
|
||||||
cp docs/*.1 $(DESTDIR)/$(PREFIX)/share/man/man1
|
cp docs/*.1 $(DESTDIR)/$(PREFIX)/$(MANDIR)/man1
|
||||||
|
|
||||||
.PHONY: install
|
.PHONY: install
|
||||||
install: dist
|
install: dist
|
||||||
@@ -102,7 +104,6 @@ mm: build/bin/mm
|
|||||||
build/bin/mm: src/mm.c build
|
build/bin/mm: src/mm.c build
|
||||||
$(CC) $(CFLAGS) -o $@ src/mm.c
|
$(CC) $(CFLAGS) -o $@ src/mm.c
|
||||||
|
|
||||||
|
|
||||||
.PHONY: npc
|
.PHONY: npc
|
||||||
npc: build/bin/npc
|
npc: build/bin/npc
|
||||||
build/bin/npc: src/npc.c build
|
build/bin/npc: src/npc.c build
|
||||||
@@ -118,13 +119,6 @@ scrut: build/bin/scrut
|
|||||||
build/bin/scrut: src/scrut.c build
|
build/bin/scrut: src/scrut.c build
|
||||||
$(CC) $(CFLAGS) -o $@ src/scrut.c
|
$(CC) $(CFLAGS) -o $@ src/scrut.c
|
||||||
|
|
||||||
.PHONY: sleep
|
|
||||||
sleep: build/bin/sleep
|
|
||||||
build/bin/sleep: src/sleep.rs build rustlibs
|
|
||||||
$(RUSTC) $(RUSTFLAGS) \
|
|
||||||
--extern sysexits=build/o/libsysexits.rlib \
|
|
||||||
-o $@ src/sleep.rs
|
|
||||||
|
|
||||||
.PHONY: str
|
.PHONY: str
|
||||||
str: build/bin/str
|
str: build/bin/str
|
||||||
build/bin/str: src/str.c build
|
build/bin/str: src/str.c build
|
||||||
|
|||||||
53
docs/sleep.1
53
docs/sleep.1
@@ -1,53 +0,0 @@
|
|||||||
.\" Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
.\"
|
|
||||||
.\" This work is licensed under CC BY-SA 4.0. To see a copy of this license,
|
|
||||||
.\" visit <http://creativecommons.org/licenses/by-sa/4.0/>.
|
|
||||||
|
|
||||||
.TH SLEEP 1
|
|
||||||
|
|
||||||
.SH NAME
|
|
||||||
|
|
||||||
sleep \(en wait a moment
|
|
||||||
|
|
||||||
.SH SYNOPSIS
|
|
||||||
|
|
||||||
sleep
|
|
||||||
.RB [ seconds ]
|
|
||||||
|
|
||||||
.SH DESCRIPTION
|
|
||||||
|
|
||||||
Sleep waits the given amount of seconds before exiting.
|
|
||||||
|
|
||||||
.SH DIAGNOSTICS
|
|
||||||
|
|
||||||
Sleep exits successfully when the time specified has elapsed, or unsuccessfully
|
|
||||||
if the time fails to elapse or if invoked incorrectly. In the latter scenario
|
|
||||||
sleep will also print a usage synopsis.
|
|
||||||
|
|
||||||
.SH BUGS
|
|
||||||
|
|
||||||
User may still be tired after invoking sleep.
|
|
||||||
|
|
||||||
.SH EXAMPLES
|
|
||||||
|
|
||||||
The following invocation sleeps for five seconds.
|
|
||||||
|
|
||||||
.RS
|
|
||||||
.R sleep 5
|
|
||||||
.RE
|
|
||||||
|
|
||||||
The following sh(1p) command line sleeps for five minutes, or for sixty
|
|
||||||
seconds, five times, using rpn(1) and xargs(1p).
|
|
||||||
|
|
||||||
.RS
|
|
||||||
.R $ rpn 60 5 '*' | xargs sleep
|
|
||||||
.RE
|
|
||||||
|
|
||||||
.SH COPYRIGHT
|
|
||||||
|
|
||||||
Copyright (c) 2024 DTB. License AGPLv3+: GNU AGPL version 3 or later
|
|
||||||
<https://gnu.org/licenses/gpl.html>.
|
|
||||||
|
|
||||||
.SH SEE ALSO
|
|
||||||
|
|
||||||
sleep(3)
|
|
||||||
47
src/sleep.rs
47
src/sleep.rs
@@ -1,47 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2024 DTB <trinity@trinity.moe>
|
|
||||||
* 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,
|
|
||||||
thread::sleep,
|
|
||||||
time::Duration
|
|
||||||
};
|
|
||||||
|
|
||||||
extern crate sysexits;
|
|
||||||
use sysexits::EX_USAGE;
|
|
||||||
|
|
||||||
fn usage(s: &str) -> ExitCode {
|
|
||||||
eprintln!("Usage: {} [seconds]", s);
|
|
||||||
ExitCode::from(EX_USAGE as u8)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() -> ExitCode {
|
|
||||||
let argv = args().collect::<Vec<String>>();
|
|
||||||
|
|
||||||
if argv.len() == 2 {
|
|
||||||
if let Ok(s) = argv[1].parse::<u64>() {
|
|
||||||
sleep(Duration::from_secs(s));
|
|
||||||
ExitCode::SUCCESS
|
|
||||||
} else {
|
|
||||||
usage(&argv[0])
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
usage(&argv[0])
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user