Compare commits
6 Commits
helix-conf
...
09d9c93ff3
| Author | SHA1 | Date | |
|---|---|---|---|
| 09d9c93ff3 | |||
| f4514592bd | |||
| 87b063f7bd | |||
| 1c6e2970f7 | |||
| 46f0d4955f | |||
| a8c40de747 |
12
Makefile
12
Makefile
@@ -32,7 +32,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 str strcmp swab true
|
all: dj false fop hru intcmp mm npc pschdir retval rpn scrut str strcmp swab true
|
||||||
|
|
||||||
# keep build/include until bindgen(1) has stdin support
|
# keep build/include until bindgen(1) has stdin support
|
||||||
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
# https://github.com/rust-lang/rust-bindgen/issues/2703
|
||||||
@@ -122,6 +122,16 @@ npc: build/bin/npc
|
|||||||
build/bin/npc: src/npc.c build
|
build/bin/npc: src/npc.c build
|
||||||
$(CC) $(CFLAGAS) -o $@ src/npc.c
|
$(CC) $(CFLAGAS) -o $@ src/npc.c
|
||||||
|
|
||||||
|
.PHONY: pschdir
|
||||||
|
pschdir: build/bin/pschdir
|
||||||
|
build/bin/pschdir: src/pschdir.c build
|
||||||
|
$(CC) $(CFLAGS) -o $@ src/pschdir.c
|
||||||
|
|
||||||
|
.PHONY: retval
|
||||||
|
retval: build/bin/retval
|
||||||
|
build/bin/retval: src/retval.rs build rustlibs
|
||||||
|
$(RUSTC) $(RUSTFLAGS) $(RUSTLIBS) -o $@ src/retval.rs
|
||||||
|
|
||||||
.PHONY: rpn
|
.PHONY: rpn
|
||||||
rpn: build/bin/rpn
|
rpn: build/bin/rpn
|
||||||
build/bin/rpn: src/rpn.rs build rustlibs
|
build/bin/rpn: src/rpn.rs build rustlibs
|
||||||
|
|||||||
48
src/pschdir.c
Normal file
48
src/pschdir.c
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/*
|
||||||
|
* 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/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <errno.h> /* EACCESS, ELOOP, ENAMETOOLONG, ENOENT, ENOTDIR, errno */
|
||||||
|
#include <stdio.h> /* fprintf(3), stderr */
|
||||||
|
#include <string.h> /* strerror(3) */
|
||||||
|
#include <sysexits.h> /* EX_OSERR, EX_NOPERM, EX_NOINPUT, EX_UNAVAILABLE,
|
||||||
|
* EX_USAGE */
|
||||||
|
#include <unistd.h> /* chdir(2) */
|
||||||
|
|
||||||
|
char *program_name = "pschdir";
|
||||||
|
|
||||||
|
int main(int argc, char *argv[]){
|
||||||
|
if (argc < 3) {
|
||||||
|
fprintf(stderr, "Usage: %s directory command [argument...]\n",
|
||||||
|
argv[0] == NULL ? program_name : argv[0]);
|
||||||
|
return EX_USAGE;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(chdir(argv[1]) != 0){
|
||||||
|
fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1], strerror(errno));
|
||||||
|
|
||||||
|
switch (errno) {
|
||||||
|
case ENAMETOOLONG: return EX_OSERR;
|
||||||
|
case EACCES: return EX_NOPERM;
|
||||||
|
case ENOENT:
|
||||||
|
case ENOTDIR: return EX_NOINPUT;
|
||||||
|
default: return EX_UNAVAILABLE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
execvp(argv[2], &argv[2]);
|
||||||
|
}
|
||||||
39
src/retval.rs
Normal file
39
src/retval.rs
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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 };
|
||||||
|
|
||||||
|
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::<Vec<String>>();
|
||||||
|
|
||||||
|
match argv.len() {
|
||||||
|
2 => match argv[1].parse::<u8>() {
|
||||||
|
Ok(e) => ExitCode::from(e),
|
||||||
|
_ => usage(&argv[0])
|
||||||
|
},
|
||||||
|
_ => usage(&argv[0])
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user