farfetch/main.c

272 行
7.4 KiB
C
Raw 通常表示 履歴

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
#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-21 21:02:43 +09:00
#include "src/wm.h"
2024-06-21 21:34:05 +09:00
#include "src/shell.h"
2024-06-21 21:48:02 +09:00
#include "src/libc.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-21 22:14:36 +09:00
#include "src/storage.h"
2024-06-17 22:41:46 +09:00
const char *sofname = "farfetch";
2024-06-21 23:46:01 +09:00
const char *version = "0.1.0";
const char *avalopt = "s";
void usage() {
printf("%s-%s\nusage: %s [-%s]\n", sofname, version, sofname, avalopt);
}
2024-06-17 22:41:46 +09:00
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;
2024-06-21 23:46:01 +09:00
if (argc == 2) {
if (strncmp(argv[1], "-s", 2) == 0) {
issmall = 1;
} else {
usage();
return 1;
}
} else if (argc > 2) {
usage();
return 1;
2024-06-18 17:48:32 +09:00
}
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__)
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
#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[] = {
" ⢀⣀⣀⡀⠀⠀⠀⠀⠀⠀⠀⣠⠾⠛⠶⣄⢀⣠⣤⠴⢦⡀⠀⠀⠀⠀",
"⠀⠀⠀⢠⡿⠉⠉⠉⠛⠶⠶⠖⠒⠒⣾⠋⠀⢀⣀⣙⣯⡁⠀⠀⠀⣿⠀⠀⠀⠀",
"⠀⠀⠀⢸⡇⠀⠀⠀⠀⠀⠀⠀⠀⢸⡏⠀⠀⢯⣼⠋⠉⠙⢶⠞⠛⠻⣆⠀⠀⠀",
"⠀⠀⠀⢸⣧⠆⠀⠀⠀⠀⠀⠀⠀⠀⠻⣦⣤⡤⢿⡀⠀⢀⣼⣷⠀⠀⣽⠀⠀⠀",
"⠀⠀⠀⣼⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠉⠙⢏⡉⠁⣠⡾⣇⠀⠀⠀",
"⠀⠀⢰⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠙⠋⠉⠀⢻⡀⠀⠀",
"⣀⣠⣼⣧⣤⠀⠀⠀⣀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⡀⠀⠀⠐⠖⢻⡟⠓⠒",
"⠀⠀⠈⣷⣀⡀⠀⠘⠿⠇⠀⠀⠀⢀⣀⣀⠀⠀⠀⠀⠿⠟⠀⠀⠀⠲⣾⠦⢤⠀",
"⠀⠀⠋⠙⣧⣀⡀⠀⠀⠀⠀⠀⠀⠘⠦⠼⠃⠀⠀⠀⠀⠀⠀⠀⢤⣼⣏⠀⠀⠀",
"⠀⠀⢀⠴⠚⠻⢧⣄⣀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⣀⣤⠞⠉⠉⠓⠀⠀",
"⠀⠀⠀⠀⠀⠀⠀⠈⠉⠛⠛⠶⠶⠶⣶⣤⣴⡶⠶⠶⠟⠛⠉⠀⠀⠀⠀⠀⠀⠀"
};
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-21 21:02:43 +09:00
const char *winman = display_wm();
if (!winman) minsize--;
else free((void *)winman);
2024-06-21 23:40:09 +09:00
const char *clang = display_libc();
2024-06-22 00:24:24 +09:00
if (clang) minsize++;
2024-06-20 05:43:26 +09:00
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
#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++;
}
#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-21 21:02:43 +09:00
const char *wm = display_wm();
if (wm) {
printf("%s ", LOGO[lc]);
printf("%sWM%s: %s\n", color, reset, wm);
free((void *)wm);
lc++;
}
2024-06-21 21:34:05 +09:00
const char *shell = display_shell();
if (shell) {
printf("%s ", LOGO[lc]);
printf("%sShell%s: %s\n", color, reset, shell);
free((void *)shell);
lc++;
}
2024-06-21 21:48:02 +09:00
const char *libc = display_libc();
if (libc) {
printf("%s ", LOGO[lc]);
printf("%slibc%s: %s\n", color, reset, libc);
lc++;
}
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);
lc++;
2024-06-20 05:43:26 +09:00
free((void *)gpu);
}
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-21 22:14:36 +09:00
const char *storage = display_storage();
if (storage) {
printf("%s ", LOGO[lc]);
printf("%sStorage%s: %s\n", color, reset, storage);
lc++;
free((void *)storage);
}
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
return 0;
}