Compare commits

..

3 Commits

Author SHA1 Message Date
Nakidai 9bddfa7a68 Add some compatibility
- Use GetTickCount64 function on Windows to get uptime
- Try to get Windows version from NetServerGetInfo function
2023-12-16 15:03:10 +03:00
Nakidai 5cf683e05f Change constants from const to define 2023-12-16 14:16:56 +03:00
Nakidai 322ee8417a Add CMake & Attempt to make it compile for Windows 2023-12-16 01:48:09 +03:00
7 changed files with 84 additions and 135 deletions

3
.gitignore vendored
View File

@ -1,3 +1,2 @@
mycfetch mycfetch
compile_commands.json build
.cache/

4
CMakeLists.txt Normal file
View File

@ -0,0 +1,4 @@
cmake_minimum_required(VERSION 3.5)
project(mycfetch LANGUAGES C)
add_executable(mycfetch mycfetch.c)

View File

@ -1,21 +1,11 @@
PREFIX ?= /usr/local PREFIX ?= /usr/local
BINDIR ?= ${PREFIX}/bin
MANDIR ?= ${PREFIX}/share/man
all: mycfetch all: mycfetch
mycfetch: config.h defs.h install: mycfetch
install -m 555 mycfetch $(PREFIX)/bin/
clean: clean:
rm -f mycfetch rm -f mycfetch
install: mycfetch mycfetch.1
install -d ${DESTDIR}${BINDIR} ${DESTDIR}${MANDIR}/man1
install mycfetch ${DESTDIR}${BINDIR}
install -m 644 mycfetch.1 ${DESTDIR}${MANDIR}/man1
uninstall:
rm -f ${DESTDIR}${BINDIR}/mycfetch
rm -f ${DESTDIR}${MANDIR}/man1/mycfetch.1
.PHONY: all install clean .PHONY: all install clean

View File

@ -1,25 +1,11 @@
# mycfetch # mycfetch
Simple fetch Simple neofetch.
```
$ mycfetch cat
|、 naki@nakidai
(˚ˎ。7 --
| 、˜〵 Linux 6.10.0-rc3-ga3e18a540541
じしˍ,) Up 2 hours, 20 minutes
```
Usage Usage
-- --
Use first argument as art name. If no arguments given or name is invalid, Use argument to select art. If not argument provided, mycfetch uses first entry in arts list.
mycfetch will use first one from the `arts` For convenience, you can set alias for needed art.
For convenience, you can set alias for needed art
Install
--
mycfetch is available on [AUR](https://aur.archlinux.org/packages/mycfetch)
List of arts List of arts
-- --

View File

@ -1,10 +1,10 @@
#include "defs.h" #include "defs.h"
static const int max_username_length = 128; #define MAX_USERNAME_LENGTH 128
static const int max_hostname_length = 128; #define MAX_HOSTNAME_LENGTH 128
static const int max_uptime_length = 40; #define MAX_UPTIME_LENGTH 40
static struct art_entry arts[] = { struct art_entry arts[] = {
{ {
"cat", "cat",
{ {
@ -26,19 +26,19 @@ static struct art_entry arts[] = {
{ {
"gentoo", "gentoo",
{ {
"\033[35m /‾\\ \033[0m", " /‾\\ ",
"\033[35m( \033[37mo \033[35m\\\033[0m", "( o \\",
"\033[35m/ /\033[0m", "/ /",
"\033[35m\\__/ \033[0m" "\\__/ "
} }
}, },
{ {
"arch", "arch",
{ {
"\033[34m /\\ \033[0m", " /\\ ",
"\033[34m /\\ \\ \033[0m", " /\\ \\ ",
"\033[34m / \\ \033[0m", " / \\ ",
"\033[34m/__/\\__\\\033[0m" "/__/\\__\\"
} }
} }
}; };

View File

@ -1,62 +0,0 @@
.Dd August 23, 2024
.Dt MYCFETCH 1
.Os
.
.Sh NAME
.Nm mycfetch
.Nd System info fetcher
.Sh SYNOPSIS
.Nm
.Op Ar artname
.
.Sh DESCRIPTION
.Nm
shows you some information about computer. On the left you will see some cute
ascii art, on the right -
.Ql user@host ,
kernel name and version, and current uptime.
.Pp
.
Arts are added to
.Nm
through
.Ql config.h
file.
.
.Bl -tag -width Ds
.It Ar artname
Name of the art to show on the left.
.
.Sh EXIT STATUS
.Nm
returns 0 if done without errors or 69 if art is not found.
.
.Sh EXAMPLES
For example,
.Bd -literal -offset indent
$ mycfetch cat
.Ed
Will show cat on the left with some system info.
.Ql cat
can be ommited because it's the first entry in the config.
.Bd -literal -offset indent
|、 naki@nakidai
(˚ˎ。7 --
| 、˜〵 Linux 6.10.4-arch2-1
じしˍ,) Up 1 days, 5 hours, 23 minutes
.Ed
.
.Sh STANDARDS
.Nm
is
.St -p1003.1-2004
compatible, while also uses
.Fn "int clock_gettime" "clockid_t" "struct timespec *"
from
.St -p1003.1b
.Sy TMR
extension.
.
.Sh AUTHORS
.An Nakidai Perumenei Aq Mt plaza521@inbox.ru
.

View File

@ -1,19 +1,40 @@
#define _POSIX_C_SOURCE 200112L
#include <stdio.h> #include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdarg.h>
#include <string.h>
#ifdef _WIN32
#include <sysinfoapi.h>
#include <winsock.h>
#include <Lm.h>
#include <winbase.h>
#else
#include <sys/utsname.h> #include <sys/utsname.h>
#include <unistd.h> #include <unistd.h>
#include <time.h> #endif /* _WIN32 */
#include <string.h>
#include <stdbool.h>
#include "config.h" #include "config.h"
#include "defs.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) void getuptime(char *buffer, int max_length)
{ {
#ifdef _WIN32
#define uptime.tv_sec uptime_seconds
long long uptime_seconds = GetTickCount64() / 1000;
#else
struct timespec uptime; struct timespec uptime;
clock_gettime(CLOCK_BOOTTIME, &uptime); clock_gettime(CLOCK_BOOTTIME, &uptime);
#endif /* _WIN32 */
int days = uptime.tv_sec / 86400; int days = uptime.tv_sec / 86400;
int hours = uptime.tv_sec / 3600 % 24; int hours = uptime.tv_sec / 3600 % 24;
int minutes = uptime.tv_sec / 60 % 60; int minutes = uptime.tv_sec / 60 % 60;
@ -28,39 +49,50 @@ void getuptime(char *buffer, int max_length)
else else
snprintf(buffer, max_length, "Up %d days, %d hours, %d minutes", days, hours, minutes); snprintf(buffer, max_length, "Up %d days, %d hours, %d minutes", days, hours, minutes);
} }
#ifdef _WIN32
#undef uptime.tv_sec
#endif /* _WIN32 */
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
char **art = arts[0].art, *name = argv[1]; char **art = NULL;
int ret = 0; if (argc > 2)
if (name)
{ {
bool found = false; die(1, "usage: %s [artname]\n", argv[0]);
for (int i = 0; i < sizeof(arts) / sizeof(*arts); ++i) }
if (!strcmp(arts[i].name, name)) else if (argc == 2)
{ art = arts[i].art; found = true; break; } {
if (!found) ret = 69; for (int 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;
} }
char hostname[MAX_HOSTNAME_LENGTH];
char username[MAX_USERNAME_LENGTH];
char uptime[MAX_UPTIME_LENGTH];
#ifdef _WIN32
SERVER_INFO_101 host_info;
NetServerGetInfo(NULL, 101, &host_info);
GetUserNameA(username, MAX_USERNAME_LENGTH);
#else
struct utsname uname_buf; struct utsname uname_buf;
char hostname[max_hostname_length];
char username[max_username_length];
char uptime[max_uptime_length];
gethostname(hostname, max_hostname_length); getlogin_r(username, MAX_USERNAME_LENGTH);
getlogin_r(username, max_username_length);
getuptime(uptime, max_uptime_length);
uname(&uname_buf); uname(&uname_buf);
#endif /* _WIN32 */
gethostname(hostname, MAX_HOSTNAME_LENGTH);
getuptime(uptime, MAX_UPTIME_LENGTH);
printf( printf("%s %s@%s\n", art[0], username, hostname);
"%s %s@%s\n" printf("%s --\n", art[1]);
"%s --\n" #ifdef _WIN32
"%s %s %s\n" printf("%s NT %d.%d\n", art[2], host_info.sv101_version_major & MAJOR_VERSION_MASK, host_info.sv101_version_minor);
"%s %s\n", #else
art[0], username, hostname, printf("%s %s %s\n", art[2], uname_buf.sysname, uname_buf.release);
art[1], #endif /* _WIN32 */
art[2], uname_buf.sysname, uname_buf.release, printf("%s %s\n", art[3], uptime);
art[3], uptime return 0;
);
return ret;
} }