fileis(1): scrap libfileis(3), work on rewriting scrut(1) in Rust
This commit is contained in:
80
src/fileis.rs
Normal file
80
src/fileis.rs
Normal file
@@ -0,0 +1,80 @@
|
||||
/*
|
||||
* 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,
|
||||
fs::metadata,
|
||||
process::ExitCode,
|
||||
};
|
||||
|
||||
extern crate getopt;
|
||||
use getopt::GetOpt;
|
||||
|
||||
extern crate sysexits;
|
||||
use sysexits::EX_USAGE;
|
||||
|
||||
fn usage(s: &str) -> ExitCode {
|
||||
eprintln!("Usage: {} [-bcdefgkprsuwxLS] file...", s);
|
||||
ExitCode::from(EX_USAGE as u8)
|
||||
}
|
||||
|
||||
fn main() -> ExitCode {
|
||||
let argv = args().collect::<Vec<String>>();
|
||||
|
||||
let mut sel: String; // selected options
|
||||
let mut optind: usize = 1; // argv[0]
|
||||
|
||||
while let Some(opt) = argv.getopt("bcdefgkprsuwxLS") {
|
||||
if let Ok(optchr) = opt.opt() { sel.push(optchr); }
|
||||
else { return usage(&argv[0]); }
|
||||
|
||||
optind = opt.ind();
|
||||
}
|
||||
|
||||
if optind == argv.len() { return usage(&argv[0]); }
|
||||
|
||||
for arg in argv.iter().skip(optind) {
|
||||
}
|
||||
|
||||
// do{
|
||||
// if (!fileis_exists(*argv))
|
||||
// return EXIT_FAILURE;
|
||||
//
|
||||
// for (size_t i = 0; sel[i] != '\0'; ++i) {
|
||||
// if ((sel[i] == 'b' && !fileis_block(*argv))
|
||||
// || (sel[i] == 'c' && !fileis_char(*argv))
|
||||
// || (sel[i] == 'd' && !fileis_dir(*argv))
|
||||
// || (sel[i] != 'e')
|
||||
// || (sel[i] == 'f' && !fileis_regular(*argv))
|
||||
// || (sel[i] == 'g' && !fileis_setgid(*argv))
|
||||
// || (sel[i] == 'k' && !fileis_vtx(*argv))
|
||||
// || (sel[i] == 'p' && !fileis_fifo(*argv))
|
||||
// || (sel[i] == 'r' && access(*argv, R_OK) != 0)
|
||||
// || (sel[i] == 'u' && !fileis_setuid(*argv))
|
||||
// || (sel[i] == 'w' && access(*argv, W_OK) != 0)
|
||||
// || (sel[i] == 'x' && access(*argv, X_OK) != 0)
|
||||
// || (sel[i] == 'L' && !fileis_link(*argv))
|
||||
// || (sel[i] == 'S' && !fileis_socket(*argv))
|
||||
// ) { return EXIT_FAILURE; }
|
||||
// }
|
||||
// } while (*++argv != NULL);
|
||||
//
|
||||
// return EXIT_SUCCESS;
|
||||
|
||||
ExitCode::SUCCESS
|
||||
}
|
||||
Reference in New Issue
Block a user