From 806f176ab03f7b4b0182691f7ed440febd43b93e Mon Sep 17 00:00:00 2001 From: Nakidai Date: Wed, 15 Nov 2023 20:56:56 +0300 Subject: [PATCH] Add *argument* --- README.md | 14 ++++++++++++- config.h | 63 ++++++++++++++++++++++++++++++++++--------------------- defs.h | 10 +++++++++ main.c | 32 +++++++++++++++++++++++++--- 4 files changed, 91 insertions(+), 28 deletions(-) create mode 100644 defs.h diff --git a/README.md b/README.md index daf2b1f..417151d 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,15 @@ # mycfetch -Simle neofetch. +Simple neofetch. + +Usage +-- +Use argument to select art. If not argument provided, mycfetch uses first entry in arts list. +For your convenience, you can set alias for needed art. + +List of arts +-- +- `cat` +- `freebsd` +- `gentoo` +- `arch` diff --git a/config.h b/config.h index 1e51588..e95d8a4 100644 --- a/config.h +++ b/config.h @@ -1,29 +1,44 @@ +#include "defs.h" + const int max_username_length = 128; const int max_hostname_length = 128; const int max_uptime_length = 40; -char *art[] = { -// FreeBSD - "\033[31m_ _\033[0m", - "\033[31m\\‾‾‾‾/\033[0m", - "\033[31m|^ww^|\033[0m", - "\033[31m\\____/\033[0m" - -// Gentoo -// "\x1B[38;5;135m /‾\\", -// "\x1B[38;5;135m( \x1B[38;5;183mo \x1B[38;5;135m\\", -// "\x1B[38;5;135m/ /", -// "\x1B[38;5;135m\\__/" - -// Arch -// " /\\ ", -// " /\\ \\ ", -// " / \\ ", -// "/__/\\__\\" - -// Just cute cat -// " ╱|、 ", -// "(˚ˎ。7 ", -// " |、˜〵 ", -// "じしˍ,)ノ" +struct art_entry arts[] = { + { + "cat", + { + " ╱|、 ", + "(˚ˎ。7 ", + "| 、˜〵 ", + "じしˍ,)ノ" + } + }, + { + "freebsd", + { + "\033[31m_ _\033[0m", + "\033[31m\\‾‾‾‾/\033[0m", + "\033[31m|^vv^|\033[0m", + "\033[31m\\____/\033[0m" + } + }, + { + "gentoo", + { + " /‾\\ ", + "( o \\", + "/ /", + "\\__/ " + } + }, + { + "arch", + { + " /\\ ", + " /\\ \\ ", + " / \\ ", + "/__/\\__\\" + } + } }; diff --git a/defs.h b/defs.h new file mode 100644 index 0000000..cf22476 --- /dev/null +++ b/defs.h @@ -0,0 +1,10 @@ +#ifndef __DEFS_H__ +#define __DEFS_H__ + +struct art_entry +{ + char *name; + char *art[4]; +}; + +#endif /* __DEFS_H__ */ diff --git a/main.c b/main.c index 69443f8..1cd3362 100644 --- a/main.c +++ b/main.c @@ -1,9 +1,22 @@ #include +#include #include #include #include +#include +#include #include "config.h" +#include "defs.h" + +void die(int code, char *fmt, ...) +{ + va_list args; + va_start(args, fmt); + vfprintf(stderr, fmt, args); + va_end(args); + exit(code); +} void getuptime(char *buffer, int max_length) { @@ -26,21 +39,34 @@ void getuptime(char *buffer, int max_length) int main(int argc, char **argv) { + if (argc > 2) die(1, "usage: %s [artname]\n", argv[0]); + struct utsname uname_buf; - struct timespec uptime_buf; char hostname[max_hostname_length]; char username[max_username_length]; char uptime[max_uptime_length]; + int i; + char **art = NULL; + gethostname(hostname, max_hostname_length); getlogin_r(username, max_username_length); getuptime(uptime, max_uptime_length); + if (argc == 2) + { + for (i = 0; i < sizeof(arts)/sizeof(struct art_entry); ++i) + if (!strcmp(arts[i].name, argv[1])) { art = arts[i].art; break; } + if (!art) die(1, "Art %s not found\n", argv[1]); + } else + { + art = arts[0].art; + } + uname(&uname_buf); printf("%s %s@%s\n", art[0], username, hostname); printf("%s --\n", art[1]); printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release); printf("%s %s\n", art[3], uptime); - // #include "order.c" - return 0; + return 0; }