2024-06-17 22:41:46 +09:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2024-06-20 02:36:38 +09:00
|
|
|
#include <stdlib.h>
|
2024-06-17 22:41:46 +09:00
|
|
|
|
|
|
|
#include "src/user.h"
|
|
|
|
#include "src/os.h"
|
2024-06-22 03:13:21 +09:00
|
|
|
#if defined(__linux__) || defined(__sun)
|
2024-06-17 22:41:46 +09:00
|
|
|
#include "src/distro.h"
|
|
|
|
#endif
|
2024-06-18 14:06:43 +09:00
|
|
|
#include "src/host.h"
|
|
|
|
#include "src/uptime.h"
|
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
#include "src/recording.h"
|
|
|
|
#endif
|
2024-06-18 19:12:24 +09:00
|
|
|
#include "src/packages.h"
|
2024-06-19 22:53:46 +09:00
|
|
|
#include "src/resolution.h"
|
2024-06-18 13:39:02 +09:00
|
|
|
#include "src/cpu.h"
|
2024-06-18 19:23:34 +09:00
|
|
|
#include "src/gpu.h"
|
2024-06-18 00:16:45 +09:00
|
|
|
#include "src/memory.h"
|
2024-06-17 22:41:46 +09:00
|
|
|
|
|
|
|
const char *sofname = "farfetch";
|
|
|
|
const char *version = "0.0.1";
|
|
|
|
|
2024-06-18 17:48:32 +09:00
|
|
|
int main(int argc, char *argv[]) {
|
2024-06-18 15:59:14 +09:00
|
|
|
int lc = 0;
|
2024-06-18 17:48:32 +09:00
|
|
|
int issmall = 0;
|
|
|
|
if (argc == 2 && strncmp(argv[1], "-s", strlen("-s")) == 0) {
|
|
|
|
issmall = 1;
|
|
|
|
}
|
2024-06-18 15:25:34 +09:00
|
|
|
#if defined(__OpenBSD__)
|
|
|
|
#include "src/logo/openbsd.h"
|
2024-06-19 19:38:19 +09:00
|
|
|
getOS();
|
2024-06-18 15:59:14 +09:00
|
|
|
#elif defined(__NetBSD__)
|
|
|
|
#include "src/logo/netbsd.h"
|
2024-06-19 19:38:19 +09:00
|
|
|
getOS();
|
2024-06-18 15:59:14 +09:00
|
|
|
#elif defined(__FreeBSD__)
|
|
|
|
#include "src/logo/freebsd.h"
|
2024-06-19 19:38:19 +09:00
|
|
|
getOS();
|
2024-06-18 22:04:27 +09:00
|
|
|
#elif defined(__linux__)
|
2024-06-19 19:57:33 +09:00
|
|
|
get_distro();
|
2024-06-18 22:04:27 +09:00
|
|
|
#include "src/logo/linux.h"
|
2024-06-19 19:38:19 +09:00
|
|
|
getDistro(distroname);
|
2024-06-22 03:13:21 +09:00
|
|
|
#elif defined(__sun)
|
|
|
|
get_distro();
|
|
|
|
#include "src/logo/sunos.h"
|
|
|
|
getDistro(distroname);
|
2024-06-18 15:25:34 +09:00
|
|
|
#else
|
2024-06-20 14:58:37 +09:00
|
|
|
#include "src/logo/colors.h"
|
2024-06-20 00:47:11 +09:00
|
|
|
const char *color = MAGENTA;
|
|
|
|
const char *titlecolor = MAGENTA;
|
|
|
|
size_t logosize = 11;
|
2024-06-18 15:25:34 +09:00
|
|
|
char *LOGO[] = {
|
|
|
|
" ⢀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⣠⠾⠛⠶⣄⢀⣠⣤⠴⢦⡀⠀⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⢠⡿⠉⠉⠉⠛⠶⠶⠖⠒⠒⣾⠋⠀⢀⣀⣙⣯⡁⠀⠀⠀⣿⠀⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢸⡏⠀⠀⢯⣼⠋⠉⠙⢶⠞⠛⠻⣆⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⢸⣧⠆⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⣤⡤⢿⡀⠀⢀⣼⣷⠀⠀⣽⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢏⡉⠁⣠⡾⣇⠀⠀⠀",
|
|
|
|
"⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠋⠉⠀⢻⡀⠀⠀",
|
|
|
|
"⣀⣠⣼⣧⣤⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⠀⠀⠐⠖⢻⡟⠓⠒",
|
|
|
|
"⠀⠀⠈⣷⣀⡀⠀⠘⠿⠇⠀⠀⠀⢀⣀⣀⠀⠀⠀⠀⠿⠟⠀⠀⠀⠲⣾⠦⢤⠀",
|
|
|
|
"⠀⠀⠋⠙⣧⣀⡀⠀⠀⠀⠀⠀⠀⠘⠦⠼⠃⠀⠀⠀⠀⠀⠀⠀⢤⣼⣏⠀⠀⠀",
|
|
|
|
"⠀⠀⢀⠴⠚⠻⢧⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠞⠉⠉⠓⠀⠀",
|
2024-06-18 19:28:14 +09:00
|
|
|
"⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠶⠶⠶⣶⣤⣴⡶⠶⠶⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀"
|
|
|
|
};
|
|
|
|
char *LOGO_SMALL[] = {
|
|
|
|
" ⢀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⣠⠾⠛⠶⣄⢀⣠⣤⠴⢦⡀⠀⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⢠⡿⠉⠉⠉⠛⠶⠶⠖⠒⠒⣾⠋⠀⢀⣀⣙⣯⡁⠀⠀⠀⣿⠀⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢸⡏⠀⠀⢯⣼⠋⠉⠙⢶⠞⠛⠻⣆⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⢸⣧⠆⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⣤⡤⢿⡀⠀⢀⣼⣷⠀⠀⣽⠀⠀⠀",
|
|
|
|
"⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢏⡉⠁⣠⡾⣇⠀⠀⠀",
|
|
|
|
"⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠋⠉⠀⢻⡀⠀⠀",
|
|
|
|
"⣀⣠⣼⣧⣤⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⠀⠀⠐⠖⢻⡟⠓⠒",
|
|
|
|
"⠀⠀⠈⣷⣀⡀⠀⠘⠿⠇⠀⠀⠀⢀⣀⣀⠀⠀⠀⠀⠿⠟⠀⠀⠀⠲⣾⠦⢤⠀",
|
|
|
|
"⠀⠀⠋⠙⣧⣀⡀⠀⠀⠀⠀⠀⠀⠘⠦⠼⠃⠀⠀⠀⠀⠀⠀⠀⢤⣼⣏⠀⠀⠀",
|
|
|
|
"⠀⠀⢀⠴⠚⠻⢧⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠞⠉⠉⠓⠀⠀",
|
2024-06-18 15:25:34 +09:00
|
|
|
"⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠶⠶⠶⣶⣤⣴⡶⠶⠶⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀"
|
|
|
|
};
|
|
|
|
#endif
|
|
|
|
|
2024-06-20 01:19:20 +09:00
|
|
|
int minsize = MIN_SIZE;
|
2024-06-20 05:43:26 +09:00
|
|
|
|
|
|
|
const char *res = display_resolution();
|
|
|
|
if (!res) minsize--;
|
|
|
|
else free((void *)res);
|
|
|
|
|
2024-06-19 23:52:56 +09:00
|
|
|
const char *reset = RESET;
|
2024-06-20 01:19:20 +09:00
|
|
|
size_t ls = logosize <= (size_t)minsize ? (size_t)minsize : logosize;
|
2024-06-18 17:48:32 +09:00
|
|
|
if (issmall) {
|
|
|
|
size_t ne = sizeof(LOGO_SMALL) / sizeof(LOGO_SMALL[0]);
|
|
|
|
for (size_t i = 0; i < ne; i++) {
|
|
|
|
LOGO[i] = LOGO_SMALL[i];
|
|
|
|
}
|
2024-06-20 01:19:20 +09:00
|
|
|
ls = ne >= (size_t)minsize ? (size_t)minsize : ne;
|
2024-06-18 17:48:32 +09:00
|
|
|
}
|
|
|
|
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *name = display_user_name();
|
|
|
|
const char *host = display_user_host();
|
|
|
|
if (name || host) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-20 05:52:29 +09:00
|
|
|
if (name) printf("%s%s%s",titlecolor, name, reset);
|
|
|
|
if (name && host) printf("@");
|
|
|
|
if (host) printf("%s%s%s", titlecolor, host, reset);
|
|
|
|
printf("\n");
|
2024-06-20 05:43:26 +09:00
|
|
|
if (name) free((void *)name);
|
|
|
|
if (host) free((void *)host);
|
2024-06-19 23:52:56 +09:00
|
|
|
lc++;
|
|
|
|
}
|
|
|
|
|
2024-06-18 15:59:14 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-18 00:44:43 +09:00
|
|
|
printf("------------------\n");
|
2024-06-18 15:59:14 +09:00
|
|
|
lc++;
|
2024-06-17 22:41:46 +09:00
|
|
|
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *os = display_os();
|
|
|
|
if (os) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-20 05:43:26 +09:00
|
|
|
printf("%sOS%s: %s\n", color, reset, os);
|
|
|
|
free((void *)os);
|
2024-06-19 23:52:56 +09:00
|
|
|
lc++;
|
|
|
|
}
|
2024-06-17 22:41:46 +09:00
|
|
|
|
2024-06-22 03:13:21 +09:00
|
|
|
#if defined(__linux__) || defined(__sun)
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *distroo = display_distro();
|
|
|
|
if (distroo) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-20 05:43:26 +09:00
|
|
|
printf("%sDistro%s: %s\n", color, reset, distroo);
|
2024-06-19 22:53:46 +09:00
|
|
|
lc++;
|
2024-06-20 05:43:26 +09:00
|
|
|
free((void *)distroo);
|
2024-06-19 22:53:46 +09:00
|
|
|
}
|
2024-06-17 22:41:46 +09:00
|
|
|
#endif
|
|
|
|
|
2024-06-18 15:59:14 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-19 23:52:56 +09:00
|
|
|
printf("%s%s%s%s", color, "Host", reset, ": ");
|
2024-06-18 00:16:45 +09:00
|
|
|
display_host_model();
|
|
|
|
printf("\n");
|
2024-06-18 15:59:14 +09:00
|
|
|
lc++;
|
2024-06-18 00:16:45 +09:00
|
|
|
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *days = display_days();
|
|
|
|
const char *time = display_time();
|
|
|
|
if (days || time) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
|
|
|
printf("%s%s%s%s", color, "Uptime", reset, ": ");
|
2024-06-20 05:43:26 +09:00
|
|
|
if (days) {
|
|
|
|
printf("%s", days);
|
|
|
|
if (time) printf(" ");
|
2024-06-20 00:47:11 +09:00
|
|
|
}
|
2024-06-20 05:43:26 +09:00
|
|
|
if (time) {
|
|
|
|
printf("%s", time);
|
2024-06-20 00:47:11 +09:00
|
|
|
}
|
|
|
|
printf("\n");
|
2024-06-20 05:43:26 +09:00
|
|
|
if (days) free((void *)days);
|
|
|
|
if (time) free((void *)time);
|
2024-06-20 00:47:11 +09:00
|
|
|
lc++;
|
|
|
|
}
|
2024-06-18 13:39:02 +09:00
|
|
|
|
2024-06-18 14:06:43 +09:00
|
|
|
#if defined(__OpenBSD__)
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *audio = display_recording_audio();
|
|
|
|
const char *video = display_recording_video();
|
|
|
|
if (audio || video) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-19 23:52:56 +09:00
|
|
|
printf("%sRecording%s: ", color, reset);
|
2024-06-20 05:43:26 +09:00
|
|
|
if (audio) {
|
|
|
|
printf("audio = %s", audio);
|
|
|
|
if (video) printf(", ");
|
2024-06-19 23:52:56 +09:00
|
|
|
}
|
2024-06-20 05:43:26 +09:00
|
|
|
if (video) {
|
|
|
|
printf("video = %s", video);
|
2024-06-19 23:52:56 +09:00
|
|
|
}
|
|
|
|
printf("\n");
|
2024-06-20 05:43:26 +09:00
|
|
|
if (audio) free((void *)audio);
|
|
|
|
if (video) free((void *)video);
|
2024-06-19 23:52:56 +09:00
|
|
|
lc++;
|
|
|
|
}
|
2024-06-18 14:06:43 +09:00
|
|
|
#endif
|
|
|
|
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *packages = display_packages();
|
|
|
|
if (packages) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-20 05:43:26 +09:00
|
|
|
printf("%sPackages%s: %s\n", color, reset, packages);
|
2024-06-19 23:52:56 +09:00
|
|
|
lc++;
|
2024-06-20 05:43:26 +09:00
|
|
|
free((void *)packages);
|
2024-06-19 23:52:56 +09:00
|
|
|
}
|
2024-06-18 19:12:24 +09:00
|
|
|
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *resolution = display_resolution();
|
|
|
|
if (resolution) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-20 05:43:26 +09:00
|
|
|
printf("%sResolution%s: %s\n", color, reset, resolution);
|
2024-06-19 22:53:46 +09:00
|
|
|
lc++;
|
2024-06-20 05:43:26 +09:00
|
|
|
free((void *)resolution);
|
2024-06-19 22:53:46 +09:00
|
|
|
}
|
|
|
|
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *cpu = display_cpu();
|
|
|
|
if (cpu) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-20 05:43:26 +09:00
|
|
|
printf("%sCPU%s: %s\n", color, reset, cpu);
|
2024-06-19 23:52:56 +09:00
|
|
|
lc++;
|
2024-06-20 05:43:26 +09:00
|
|
|
free((void *)cpu);
|
2024-06-19 23:52:56 +09:00
|
|
|
}
|
2024-06-18 13:39:02 +09:00
|
|
|
|
2024-06-20 05:43:26 +09:00
|
|
|
const char *gpu = display_gpu();
|
|
|
|
if (gpu) {
|
2024-06-20 00:47:11 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-20 05:43:26 +09:00
|
|
|
printf("%sGPU%s: %s\n", color, reset, gpu);
|
2024-06-19 15:44:06 +09:00
|
|
|
lc++;
|
2024-06-20 05:43:26 +09:00
|
|
|
free((void *)gpu);
|
2024-06-19 15:44:06 +09:00
|
|
|
}
|
2024-06-18 19:23:34 +09:00
|
|
|
|
2024-06-18 15:59:14 +09:00
|
|
|
printf("%s ", LOGO[lc]);
|
2024-06-19 23:52:56 +09:00
|
|
|
printf("%s%s%s%s", color, "Memory", reset, ": ");
|
2024-06-18 00:16:45 +09:00
|
|
|
display_memory();
|
|
|
|
printf("\n");
|
2024-06-18 15:59:14 +09:00
|
|
|
lc++;
|
2024-06-18 00:16:45 +09:00
|
|
|
|
2024-06-18 17:48:32 +09:00
|
|
|
for (size_t i = lc; i < ls; i++) {
|
2024-06-18 15:25:34 +09:00
|
|
|
printf("%s\n", LOGO[i]);
|
|
|
|
}
|
|
|
|
|
2024-06-17 22:41:46 +09:00
|
|
|
// TODO:
|
|
|
|
// * libc
|
|
|
|
// * シェル
|
|
|
|
// * 端末
|
|
|
|
// * ストレージ
|
2024-06-19 19:38:19 +09:00
|
|
|
|
2024-06-17 22:41:46 +09:00
|
|
|
return 0;
|
|
|
|
}
|