GNUmakefile, fop(1): added sysexits support
This commit is contained in:
parent
5d9f6f3245
commit
3355cb3dc3
16
GNUmakefile
16
GNUmakefile
@ -20,8 +20,9 @@ CC=cc
|
|||||||
CFLAGS=-O3 -Lbuild/lib -idirafter include
|
CFLAGS=-O3 -Lbuild/lib -idirafter include
|
||||||
|
|
||||||
RUSTC=rustc +nightly
|
RUSTC=rustc +nightly
|
||||||
RUSTCFLAGS=-Zlocation-detail=none -Copt-level=z -Ccodegen-units=1 -Cpanic=abort
|
RUSTCFLAGS=-Zlocation-detail=none -Copt-level=z -Ccodegen-units=1 \
|
||||||
-Clto=y -Cstrip=symbols -Ctarget-cpu=native
|
-Cpanic=abort -Clto=y -Cstrip=symbols -Ctarget-cpu=native \
|
||||||
|
--extern sysexits=build/o/libsysexits.rlib
|
||||||
|
|
||||||
ifeq ($(CC), gcc)
|
ifeq ($(CC), gcc)
|
||||||
CFLAGS=-O3 -s -Wl,-z,noseparate-code,-z,nosectionheader -flto -Lbuild/lib \
|
CFLAGS=-O3 -s -Wl,-z,noseparate-code,-z,nosectionheader -flto -Lbuild/lib \
|
||||||
@ -39,7 +40,7 @@ endif
|
|||||||
build: build_dir false intcmp scrut str strcmp true
|
build: build_dir false intcmp scrut str strcmp true
|
||||||
|
|
||||||
build_dir:
|
build_dir:
|
||||||
mkdir -p build/o build/lib build/bin
|
mkdir -p build/bin build/lib build/o
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -rf build/
|
rm -rf build/
|
||||||
@ -56,10 +57,16 @@ test: build
|
|||||||
tests/cc-compat.sh
|
tests/cc-compat.sh
|
||||||
tests/posix-compat.sh
|
tests/posix-compat.sh
|
||||||
|
|
||||||
|
sysexits: build_dir
|
||||||
|
bindgen --default-macro-constant-type signed \
|
||||||
|
"$$(printf '#include <sysexits.h>\n' | cpp -M -idirafter include - \
|
||||||
|
| sed 's/ /\n/g' | grep sysexits.h)" \
|
||||||
|
| $(RUSTC) $(RUSTCFLAGS) --crate-type lib -o build/o/libsysexits.rlib -
|
||||||
|
|
||||||
false: src/false.rs build_dir
|
false: src/false.rs build_dir
|
||||||
$(RUSTC) $(RUSTCFLAGS) -o build/bin/false src/false.rs
|
$(RUSTC) $(RUSTCFLAGS) -o build/bin/false src/false.rs
|
||||||
|
|
||||||
fop: src/fop.rs build_dir
|
fop: src/fop.rs build_dir sysexits
|
||||||
$(RUSTC) $(RUSTCFLAGS) -o build/bin/fop src/fop.rs
|
$(RUSTC) $(RUSTCFLAGS) -o build/bin/fop src/fop.rs
|
||||||
|
|
||||||
intcmp: src/intcmp.c build_dir
|
intcmp: src/intcmp.c build_dir
|
||||||
@ -76,4 +83,3 @@ strcmp: src/strcmp.c build_dir
|
|||||||
|
|
||||||
true: src/true.rs build_dir
|
true: src/true.rs build_dir
|
||||||
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs
|
$(RUSTC) $(RUSTCFLAGS) -o build/bin/true src/true.rs
|
||||||
|
|
||||||
|
23
src/fop.rs
23
src/fop.rs
@ -18,13 +18,18 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
env::args,
|
env::args,
|
||||||
io::{ Read, stdin, Write },
|
io::{ stdin, Write },
|
||||||
process::{ Command, exit, Stdio },
|
process::{ Command, exit, Stdio },
|
||||||
};
|
};
|
||||||
|
|
||||||
|
extern crate sysexits;
|
||||||
|
use sysexits::EX_USAGE;
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let argv = args().collect::<Vec<String>>();
|
let argv = args().collect::<Vec<String>>();
|
||||||
|
|
||||||
|
let usage = format!("Usage: {} index command [args...]", argv[0]);
|
||||||
|
|
||||||
let index = match argv.get(1) {
|
let index = match argv.get(1) {
|
||||||
Some(i) => {
|
Some(i) => {
|
||||||
i.parse::<usize>().unwrap_or_else(|_| {
|
i.parse::<usize>().unwrap_or_else(|_| {
|
||||||
@ -33,18 +38,18 @@ fn main() {
|
|||||||
})
|
})
|
||||||
},
|
},
|
||||||
None => {
|
None => {
|
||||||
eprintln!("Usage: {} index command args...", argv[0]);
|
eprintln!("{}", usage);
|
||||||
exit(1);
|
exit(EX_USAGE);
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut buf = String::new();
|
let mut buf = String::new();
|
||||||
stdin().read_to_string(&mut buf).unwrap();
|
stdin().read_line(&mut buf).unwrap();
|
||||||
let mut fields = buf.split('␞').collect::<Vec<&str>>();
|
let mut fields = buf.split('␞').collect::<Vec<&str>>();
|
||||||
|
|
||||||
argv.get(2).unwrap_or_else(|| {
|
argv.get(2).unwrap_or_else(|| {
|
||||||
eprintln!("Usage: {} index command args...", argv[0]);
|
eprintln!("{}", usage);
|
||||||
exit(1);
|
exit(EX_USAGE);
|
||||||
});
|
});
|
||||||
|
|
||||||
let opts = argv.iter().clone().skip(3).collect::<Vec<&String>>();
|
let opts = argv.iter().clone().skip(3).collect::<Vec<&String>>();
|
||||||
@ -57,7 +62,11 @@ fn main() {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let field = fields.get(index).unwrap_or_else(|| {
|
let field = fields.get(index).unwrap_or_else(|| {
|
||||||
eprintln!("{}: {}: No such index in input.", argv[0], index.to_string());
|
eprintln!(
|
||||||
|
"{}: {}: No such index in input.",
|
||||||
|
argv[0],
|
||||||
|
index.to_string()
|
||||||
|
);
|
||||||
exit(1);
|
exit(1);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user