Compare commits
10 Commits
Author | SHA1 | Date |
---|---|---|
Kasianov Nikolai Alekseevich | d903919a9f | 2 years ago |
Kasianov Nikolai Alekseevich | ee12c7a74c | 2 years ago |
Gitea | 51d60b44b5 | 3 years ago |
Unbewohnte | 4a76264f92 | 3 years ago |
Unbewohnte | 8eb8961e50 | 3 years ago |
Unbewohnte | 28cfbbf623 | 3 years ago |
Unbewohnte | 5c81826406 | 3 years ago |
Unbewohnte | 8f8ee5eb6e | 3 years ago |
Unbewohnte | 96c2b70897 | 3 years ago |
Unbewohnte | 1fbd8f7e2e | 3 years ago |
11 changed files with 172 additions and 284 deletions
@ -1,4 +1,2 @@
|
||||
/target |
||||
.cargo/ |
||||
releasefiles/ |
||||
fumosay |
||||
fumosay |
||||
|
@ -1,19 +0,0 @@
|
||||
# Thank you for being interested in contributing to fumosay ! |
||||
|
||||
Fumosay is very small, so it's not like there's a lot work involved to ask for help, but |
||||
I will be very thankful to you if you decide to add some new fumos in fumofiles ! |
||||
|
||||
If you don`t know what steps to follow in order to start contributing: [consider to look here](https://www.dataschool.io/how-to-contribute-on-github/) |
||||
|
||||
``` |
||||
__ __ <Thank you !> |
||||
| \ / | () |
||||
| \____/ | () |
||||
|__// V \\__| |
||||
/|| ᗜ ᗜ || \ |
||||
\_\\_︶_//_/ |
||||
jj⑨lll |
||||
()_/@V@V@V\_() |
||||
/@V@V@V@V\ |
||||
(_)-----(_) |
||||
``` |
@ -1,115 +0,0 @@
|
||||
# This file is automatically @generated by Cargo. |
||||
# It is not intended for manual editing. |
||||
version = 3 |
||||
|
||||
[[package]] |
||||
name = "ansi_term" |
||||
version = "0.11.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ee49baf6cb617b853aa8d93bf420db2383fab46d314482ca2803b40d5fde979b" |
||||
dependencies = [ |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "atty" |
||||
version = "0.2.14" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d9b39be18770d11421cdb1b9947a45dd3f37e93092cbf377614828a319d5fee8" |
||||
dependencies = [ |
||||
"hermit-abi", |
||||
"libc", |
||||
"winapi", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "bitflags" |
||||
version = "1.3.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" |
||||
|
||||
[[package]] |
||||
name = "clap" |
||||
version = "2.33.3" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "37e58ac78573c40708d45522f0d80fa2f01cc4f9b4e2bf749807255454312002" |
||||
dependencies = [ |
||||
"ansi_term", |
||||
"atty", |
||||
"bitflags", |
||||
"strsim", |
||||
"textwrap", |
||||
"unicode-width", |
||||
"vec_map", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "fumosay" |
||||
version = "0.4.0" |
||||
dependencies = [ |
||||
"clap", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "hermit-abi" |
||||
version = "0.1.19" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "62b467343b94ba476dcb2500d242dadbb39557df889310ac77c5d99100aaac33" |
||||
dependencies = [ |
||||
"libc", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "libc" |
||||
version = "0.2.99" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "a7f823d141fe0a24df1e23b4af4e3c7ba9e5966ec514ea068c93024aa7deb765" |
||||
|
||||
[[package]] |
||||
name = "strsim" |
||||
version = "0.8.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "8ea5119cdb4c55b55d432abb513a0429384878c15dde60cc77b1c99de1a95a6a" |
||||
|
||||
[[package]] |
||||
name = "textwrap" |
||||
version = "0.11.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "d326610f408c7a4eb6f51c37c330e496b08506c9457c9d34287ecc38809fb060" |
||||
dependencies = [ |
||||
"unicode-width", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "unicode-width" |
||||
version = "0.1.8" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "9337591893a19b88d8d87f2cec1e73fad5cdfd10e5a6f349f498ad6ea2ffb1e3" |
||||
|
||||
[[package]] |
||||
name = "vec_map" |
||||
version = "0.8.2" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "f1bddf1187be692e79c5ffeab891132dfb0f236ed36a43c7ed39f1165ee20191" |
||||
|
||||
[[package]] |
||||
name = "winapi" |
||||
version = "0.3.9" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "5c839a674fcd7a98952e593242ea400abe93992746761e38641405d28b00f419" |
||||
dependencies = [ |
||||
"winapi-i686-pc-windows-gnu", |
||||
"winapi-x86_64-pc-windows-gnu", |
||||
] |
||||
|
||||
[[package]] |
||||
name = "winapi-i686-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" |
||||
|
||||
[[package]] |
||||
name = "winapi-x86_64-pc-windows-gnu" |
||||
version = "0.4.0" |
||||
source = "registry+https://github.com/rust-lang/crates.io-index" |
||||
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f" |
@ -1,13 +0,0 @@
|
||||
[package] |
||||
name = "fumosay" |
||||
version = "0.4.1" |
||||
edition = "2018" |
||||
authors = ["Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>"] |
||||
description = "Like cowsay, but with soft friends" |
||||
readme = "README.md" |
||||
license = "MIT" |
||||
|
||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html |
||||
|
||||
[dependencies] |
||||
clap = "~2.33.3" |
@ -1,9 +1,7 @@
|
||||
The MIT License (MIT) |
||||
|
||||
Copyright © 2021 Unbewohne | Nikolay Kasyanov |
||||
Copyright © 2021 Kasyanov Nikolay Alexeevich (Unbewohnte (me@unbewohnte.xyz)) |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
@ -0,0 +1,17 @@
|
||||
SRC_DIR := src
|
||||
FUMOSAY_BIN_NAME := fumosay
|
||||
FUMOFILES := fumofiles
|
||||
FUMOSAY_INSTALLATION_DIR := /usr/local/bin
|
||||
FUMOFILES_DST_DIR := /usr/local/share/fumosay
|
||||
|
||||
all: |
||||
g++ -O2 -Wall -Werror -static src/fumosay.cpp -o fumosay
|
||||
|
||||
install: all |
||||
mkdir -p $(FUMOSAY_INSTALLATION_DIR) && \
|
||||
mkdir -p $(FUMOSAY_INSTALLATION_DIR) && \
|
||||
cp -r $(FUMOFILES) $(FUMOFILES_DST_DIR) && \
|
||||
cp $(FUMOSAY_BIN_NAME) $(FUMOSAY_INSTALLATION_DIR)
|
||||
|
||||
clean: |
||||
rm fumosay
|
@ -1,34 +1,26 @@
|
||||
#!/bin/bash |
||||
# fumosay installation script |
||||
|
||||
FUMOSAY_BIN_DIR_PATH=/usr/bin/ |
||||
FUMOFILES_DIR_PATH=/usr/share/fumosay/fumofiles/ |
||||
FUMOSAY_BIN_DIR_PATH=/usr/local/bin/ |
||||
FUMOFILES_DIR_PATH=/usr/local/share/fumosay/fumofiles/ |
||||
|
||||
# create directories |
||||
mkdir -p $FUMOSAY_BIN_DIR_PATH && mkdir -p $FUMOFILES_DIR_PATH |
||||
|
||||
# copy fumosay binary |
||||
if [ -e fumosay ] |
||||
if [ -e fumosay ] |
||||
then |
||||
cp fumosay $FUMOSAY_BIN_DIR_PATH && echo "Copied binary file" |
||||
elif [ -e target/x86_64-unknown-linux-musl/release/fumosay ] # For debug purposes. The binary file should be in the same directory as the script !!! |
||||
then |
||||
cp target/x86_64-unknown-linux-musl/release/fumosay $FUMOSAY_BIN_DIR_PATH && echo "Copied binary from linux-musl directory" |
||||
cp fumosay $FUMOSAY_BIN_DIR_PATH |
||||
else |
||||
echo "Could not find a fumosay binary file" |
||||
echo "Could not find fumosay in current directory" |
||||
exit 1 |
||||
fi |
||||
|
||||
# copy fumofiles |
||||
if [ -d fumofiles ] |
||||
then |
||||
cp -r fumofiles/* $FUMOFILES_DIR_PATH && echo "Copied fumofiles" |
||||
cp -r fumofiles/* $FUMOFILES_DIR_PATH |
||||
else |
||||
echo "Could not find fumofiles directory" |
||||
exit 1 |
||||
fi |
||||
|
||||
|
||||
echo "Installation completed" |
||||
|
||||
|
||||
fi |
@ -0,0 +1,136 @@
|
||||
/*
|
||||
Copyright © 2021, 2022 Kasyanov Nikolay Alexeyevich (Unbewohntes) |
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: |
||||
|
||||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. |
||||
|
||||
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||||
*/ |
||||
|
||||
#include <string.h> |
||||
#include <iostream> |
||||
#include <fstream> |
||||
#include <filesystem> |
||||
|
||||
class Fumo { |
||||
private: |
||||
const std::string m_message_identificator = "!message"; |
||||
const std::string m_default_fumofile = "cirno.fumo"; |
||||
|
||||
std::string m_fumotext; |
||||
|
||||
public: |
||||
// Opens specified fumofile
|
||||
Fumo(std::string fumo_path) { |
||||
std::fstream m_fumofile; |
||||
m_fumofile.open(fumo_path, std::ios_base::in); |
||||
if (!m_fumofile) { |
||||
throw "Could not open fumofile"; |
||||
}; |
||||
|
||||
// read whole fumofile
|
||||
std::string line; |
||||
while (std::getline(m_fumofile, line)) { |
||||
m_fumotext += line + "\n"; |
||||
}; |
||||
|
||||
m_fumofile.close(); |
||||
}; |
||||
|
||||
~Fumo() {}; |
||||
|
||||
// Inserts given message and prints it to the standart output
|
||||
void say(std::string message) { |
||||
if (m_fumotext.find(m_message_identificator) == std::string::npos) { |
||||
// no identificator found. Inserting message on the first line
|
||||
m_fumotext.insert(0, message + "\n"); |
||||
} else { |
||||
// identificator found. Inserting message in the appropriate place
|
||||
const unsigned int message_index = m_fumotext.find(m_message_identificator); |
||||
m_fumotext.replace(message_index, m_message_identificator.length(), message); |
||||
}; |
||||
|
||||
// print fumosay
|
||||
std::cout << m_fumotext << std::endl; |
||||
}; |
||||
}; |
||||
|
||||
int main(int argc, char *argv[]) { |
||||
const std::string VERSION = "0.4.5"; |
||||
|
||||
const std::string ABOUT = "\
|
||||
fumosay\n\
|
||||
cowsay, but with soft friends\n\n\
|
||||
(c) Kasyanov Nikolay Alexeyevich (Unbewohnte)"; |
||||
|
||||
const std::string HELP = "\
|
||||
fumosay [OPTION(s)...] [MESSAGE]\n\n\
|
||||
Options:\n\
|
||||
-v --version - print version text and exit\n\
|
||||
-l --list - list available fumos and exit\n\
|
||||
-h --help - print this message and exit\n\
|
||||
-f --fumo - specify path to another fumo to print\n"; |
||||
|
||||
std::string fumofiles_dir; |
||||
#ifdef _WIN32 |
||||
fumofiles_dir = ".\\fumofiles"; |
||||
#else |
||||
fumofiles_dir = "/usr/local/share/fumosay/fumofiles";
|
||||
#endif |
||||
std::string fumoname = "cirno.fumo"; |
||||
|
||||
if (argc < 2) { |
||||
return 0; |
||||
}; |
||||
|
||||
std::string message; |
||||
for (int i = 1; i < argc; i++) { |
||||
if (strcmp(argv[i], "-v") == 0 || strcmp(argv[i], "--version") == 0) { |
||||
// print version info
|
||||
std::cout << VERSION << std::endl << std::endl << ABOUT << std::endl; |
||||
return 0; |
||||
} |
||||
else if (strcmp(argv[i], "-l") == 0 || strcmp(argv[i], "--list") == 0) { |
||||
// print available fumos in the default fumofiles directory
|
||||
for (const auto &entry : std::filesystem::directory_iterator(fumofiles_dir)) { |
||||
std::cout << entry.path().filename() << std::endl; |
||||
}; |
||||
return 0; |
||||
}
|
||||
else if (strcmp(argv[i], "-h") == 0 || strcmp(argv[i], "--help") == 0) { |
||||
// print help infos
|
||||
std::cout << HELP << std::endl; |
||||
return 0; |
||||
} |
||||
else if (strcmp(argv[i], "-f") == 0 || strcmp(argv[i], "--fumo") == 0) { |
||||
// use another fumo
|
||||
if (i+1 >= argc-1) { |
||||
return 1; |
||||
}; |
||||
|
||||
fumoname = argv[i+1]; |
||||
i++; |
||||
} |
||||
else if (strcmp(argv[i], "-d") == 0 || strcmp(argv[i], "--directory") == 0) { |
||||
// temporarily change fumofiles directory to look fumofiles in
|
||||
if (i+1 >= argc-1 || !std::filesystem::exists(std::filesystem::path(argv[i+1]))){ |
||||
return 1; |
||||
}; |
||||
|
||||
fumofiles_dir = argv[i+1]; |
||||
i++; |
||||
} |
||||
else { |
||||
message += argv[i]; |
||||
if (i != argc-1) { |
||||
message += " "; |
||||
}; |
||||
} |
||||
}; |
||||
|
||||
Fumo fumo(std::filesystem::path(fumofiles_dir) / fumoname); |
||||
fumo.say(message); |
||||
|
||||
return 0; |
||||
} |
@ -1,101 +0,0 @@
|
||||
use std::fs; |
||||
use std::path::Path; |
||||
use clap::{Arg, App};
|
||||
|
||||
/// Indicator of where the message should be in fumofile
|
||||
const MESSAGE_INDICATOR: &str = "!message"; |
||||
/// Fumofile name of the default fumo
|
||||
const FUMO_DEFAULT: &str = "cirno.fumo";
|
||||
/// Default directory where fumofiles are placed
|
||||
const DEFAULT_FUMOFILES_DIR: &str = "/usr/share/fumosay/fumofiles/"; |
||||
|
||||
/// Returns a resulting string with `MESSAGE_INDICATOR` replaced with given
|
||||
/// `message`. If `MESSAGE_INDICATOR` is not present in fumofile - the
|
||||
/// `message` will be added on the new line at the end of the fumofile.
|
||||
fn process_message(fumofile_contents: &mut String, message: &str) -> String { |
||||
if fumofile_contents.contains(MESSAGE_INDICATOR) { |
||||
return fumofile_contents.replace(MESSAGE_INDICATOR,message); |
||||
} |
||||
return format!("{}\n{}", fumofile_contents, message); |
||||
} |
||||
|
||||
fn main() { |
||||
// get command line arguments
|
||||
let matches = App::new("fumosay") |
||||
.version("0.4.1") |
||||
.author("Unbewohnte | Nikolay Kasyanov <https://github.com/Unbewohnte>") |
||||
.about("cowsay, but with soft friends") |
||||
.arg( |
||||
Arg::with_name("fumo") |
||||
.short("f") |
||||
.long("fumo") |
||||
.value_name("fumofile") |
||||
.help("Choose another fumofumo to print") |
||||
.takes_value(true) |
||||
.required(false) |
||||
.default_value(FUMO_DEFAULT) |
||||
) |
||||
.arg( |
||||
Arg::with_name("fumofiles_directory") |
||||
.short("d") |
||||
.long("fumofiles_directory") |
||||
.value_name("fumofiles_directory_path") |
||||
.help("Look for fumofiles in given directory") |
||||
.takes_value(true) |
||||
.required(false) |
||||
.default_value(DEFAULT_FUMOFILES_DIR) |
||||
) |
||||
.arg( |
||||
Arg::with_name("list_fumos") |
||||
.short("l") |
||||
.long("list_fumos") |
||||
.help("Lists all fumofiles in the default directory instead") |
||||
.takes_value(false) |
||||
.required(false) |
||||
) |
||||
.arg( |
||||
Arg::with_name("message") |
||||
.short("m") |
||||
.long("message") |
||||
.help("Message to print") |
||||
.takes_value(true) |
||||
.index(1) |
||||
.multiple(true) |
||||
).get_matches(); |
||||
|
||||
// check for list_fumos flag.
|
||||
if matches.is_present("list_fumos") { |
||||
// list fumofiles and exit
|
||||
let fumofiles = fs::read_dir(DEFAULT_FUMOFILES_DIR).expect("Could not read default fumofiles directory"); |
||||
for entry in fumofiles { |
||||
let file = entry.unwrap(); |
||||
let filename = file.file_name(); |
||||
print!("{:?}\n", filename); |
||||
} |
||||
std::process::exit(0); |
||||
} |
||||
|
||||
// process fumofiles directory
|
||||
|
||||
// directory with all fumofiles
|
||||
let new_fumofiles_dir = matches.value_of("fumofiles_directory").unwrap(); |
||||
// name of the fumofile to work with
|
||||
let fumofile_name = matches.value_of("fumo").unwrap(); |
||||
// the whole path to the selected fumo
|
||||
let fumofile_path = Path::new(&new_fumofiles_dir).join(fumofile_name); |
||||
|
||||
// read fumofile
|
||||
let mut fumofile_contents: String = fs::read_to_string(fumofile_path).expect("Could not find a fumofile!"); |
||||
|
||||
// process the message
|
||||
let message_values = matches.values_of("message").expect("No message provided"); |
||||
let message_vec: Vec<&str> = message_values.collect(); |
||||
let joined_message = message_vec.join(" "); |
||||
|
||||
// parse the file, insert fiven message and get the resulting string
|
||||
let fumosay: String = process_message(&mut fumofile_contents, joined_message.as_str()); |
||||
|
||||
println!("{}", fumosay); |
||||
} |
||||
|
||||
|
Loading…
Reference in new issue