コンフィグファイル機能性の追加
このコミットが含まれているのは:
コミット
06bbde54c4
|
@ -9,6 +9,7 @@
|
|||
* Rocky Linuxロゴの追加
|
||||
* CentOSロゴの追加
|
||||
* Red Hatロゴの追加
|
||||
* コンフィグファイル機能性の追加
|
||||
|
||||
# 0.1.1
|
||||
* ストレージ情報の修正(今も元気ハツラツ太郎さん)
|
||||
|
|
22
Makefile
22
Makefile
|
@ -20,15 +20,26 @@ NAME != cat main.c | grep "const char \*sofname" | awk '{print $$5}' |\
|
|||
sed "s/\"//g" | sed "s/;//"
|
||||
VERSION != cat main.c | grep "const char \*version" | awk '{print $$5}' |\
|
||||
sed "s/\"//g" | sed "s/;//"
|
||||
|
||||
PREFIX = /usr/local
|
||||
.if ${UNAME_S} == "Linux"
|
||||
PREFIX = /usr
|
||||
.elif ${UNAME_S} == "Haiku"
|
||||
PREFIX = /boot/home/config/non-packaged
|
||||
.endif
|
||||
|
||||
MANPREFIX = ${PREFIX}/share/man
|
||||
|
||||
.if ${UNAME_S} == "OpenBSD"
|
||||
MANPREFIX = ${PREFIX}/man
|
||||
.elif ${UNAME_S} == "Haiku"
|
||||
MANPREFIX = ${PREFIX}/documentation/man
|
||||
.endif
|
||||
|
||||
CNFPREFIX = /etc
|
||||
.if ${UNAME_S} == "FreeBSD" || ${UNAME_S} == "NetBSD" || ${UNAME_S} == "Dragonfly"
|
||||
CNFPREFIX = ${PREFIX}/etc
|
||||
.elif ${UNAME_S} == "Haiku"
|
||||
CNFPREFIX = /boot/home/config/settings
|
||||
.endif
|
||||
|
||||
CC = cc
|
||||
|
@ -55,7 +66,8 @@ dist:
|
|||
|
||||
man:
|
||||
mkdir -p release/man
|
||||
cp ${NAME}.1 release/man/${NAME}-${VERSION}.1
|
||||
sed "s/VERSION/${VERSION}/g" < ${NAME}.1 > release/man/${NAME}-${VERSION}.1
|
||||
sed "s/VERSION/${VERSION}/g" < ${NAME}.conf.5 > release/man/${NAME}.conf-${VERSION}.5
|
||||
|
||||
depend:
|
||||
${DEPS}
|
||||
|
@ -69,10 +81,14 @@ release:
|
|||
install:
|
||||
mkdir -p ${DESTDIR}${PREFIX}/bin
|
||||
cp -f ${NAME} ${DESTDIR}${PREFIX}/bin
|
||||
cp -f ${NAME}.conf ${DESTDIR}${CNFPREFIX}/examples
|
||||
chmod 755 ${DESTDIR}${PREFIX}/bin/${NAME}
|
||||
mkdir -p ${DESTDIR}${MANPREFIX}/man1
|
||||
mkdir -p ${DESTDIR}${MANPREFIX}/man1 ${DESTDIR}${MANPREFIX}/man5
|
||||
sed "s/VERSION/${VERSION}/g" < ${NAME}.1 > ${DESTDIR}${MANPREFIX}/man1/${NAME}.1
|
||||
chmod 644 ${DESTDIR}${MANPREFIX}/man1/${NAME}.1
|
||||
sed "s/VERSION/${VERSION}/g" < ${NAME}.conf.5 >\
|
||||
${DESTDIR}${MANPREFIX}/man5/${NAME}.conf.5
|
||||
chmod 644 ${DESTDIR}${MANPREFIX}/man5/${NAME}.conf.5
|
||||
|
||||
uninstall:
|
||||
rm -f ${DESTDIR}${PREFIX}/bin/${NAME}
|
||||
|
|
|
@ -1,3 +1,14 @@
|
|||
logo "default"
|
||||
show os
|
||||
show host
|
||||
show distro
|
||||
show uptime
|
||||
show recording
|
||||
show libc
|
||||
show packages
|
||||
show resolution
|
||||
show wm
|
||||
show shell
|
||||
show cpu
|
||||
hide gpu
|
||||
show gpu
|
||||
show memory
|
||||
show storage
|
||||
|
|
|
@ -0,0 +1,15 @@
|
|||
.TH FARFETCH.CONF 5 VERSION
|
||||
.SH NAME
|
||||
.B farfetch.conf
|
||||
.SH DESCRIPTION
|
||||
.PP
|
||||
利用するには、`cp /etc/farfetch.conf ~/.config`を実効して下さい。
|
||||
.br
|
||||
Haikuの場合は不要です。
|
||||
.SH GLOBAL CONFIGURATION
|
||||
\fB\,hide\fR [\fI\,context\fR]
|
||||
.TP
|
||||
隠す
|
||||
.SH AUTHORS
|
||||
.PP
|
||||
テクニカル諏訪子(開発者)
|
274
main.c
274
main.c
|
@ -22,6 +22,8 @@
|
|||
#include "src/memory.h"
|
||||
#include "src/storage.h"
|
||||
|
||||
#include "src/config.h"
|
||||
|
||||
const char *sofname = "farfetch";
|
||||
const char *version = "0.2.0";
|
||||
#if defined(__linux__) || defined(__sun)
|
||||
|
@ -72,6 +74,8 @@ int main(int argc, char *argv[]) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
getconf();
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
#include "src/logo/openbsd.h"
|
||||
getOS();
|
||||
|
@ -127,22 +131,32 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
int minsize = MIN_SIZE;
|
||||
|
||||
const char *res = display_resolution();
|
||||
if (!res) minsize--;
|
||||
else free((void *)res);
|
||||
if (isresolution) {
|
||||
const char *res = display_resolution();
|
||||
if (!res) minsize--;
|
||||
else free((void *)res);
|
||||
} else minsize--;
|
||||
if (iswm) {
|
||||
const char *winman = display_wm();
|
||||
if (!winman) minsize--;
|
||||
#if !defined(__APPLE__)
|
||||
else free((void *)winman);
|
||||
#endif
|
||||
const char *clang = display_libc();
|
||||
if (clang) minsize++;
|
||||
const char *store = display_storage();
|
||||
if (!store) minsize--;
|
||||
else free((void *)store);
|
||||
const char *graph = display_gpu();
|
||||
if (!graph) minsize--;
|
||||
else free((void *)graph);
|
||||
} else minsize--;
|
||||
if (islibc) {
|
||||
const char *clang = display_libc();
|
||||
if (clang) minsize++;
|
||||
}
|
||||
if (isstorage) {
|
||||
const char *store = display_storage();
|
||||
if (!store) minsize--;
|
||||
else free((void *)store);
|
||||
} else minsize--;
|
||||
if (isgpu) {
|
||||
const char *graph = display_gpu();
|
||||
if (!graph) minsize--;
|
||||
else free((void *)graph);
|
||||
} else minsize--;
|
||||
|
||||
const char *reset = RESET;
|
||||
size_t ls = logosize <= (size_t)minsize ? (size_t)minsize : logosize;
|
||||
|
@ -178,137 +192,165 @@ int main(int argc, char *argv[]) {
|
|||
printf("------------------\n");
|
||||
lc++;
|
||||
|
||||
const char *os = display_os();
|
||||
if (os) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sOS%s: %s\n", color, reset, os);
|
||||
free((void *)os);
|
||||
lc++;
|
||||
}
|
||||
if (isos) {
|
||||
const char *os = display_os();
|
||||
if (os) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sOS%s: %s\n", color, reset, os);
|
||||
free((void *)os);
|
||||
lc++;
|
||||
}
|
||||
} else minsize--;
|
||||
|
||||
#if defined(__linux__) || defined(__sun)
|
||||
const char *distroo = display_distro();
|
||||
if (distroo) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sDistro%s: %s\n", color, reset, distroo);
|
||||
lc++;
|
||||
free((void *)distroo);
|
||||
}
|
||||
if (isdistro) {
|
||||
const char *distroo = display_distro();
|
||||
if (distroo) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sDistro%s: %s\n", color, reset, distroo);
|
||||
lc++;
|
||||
free((void *)distroo);
|
||||
}
|
||||
} else minsize--;
|
||||
#endif
|
||||
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%s%s%s%s", color, "Host", reset, ": ");
|
||||
display_host_model();
|
||||
printf("\n");
|
||||
lc++;
|
||||
|
||||
const char *days = display_days();
|
||||
const char *time = display_time();
|
||||
if (days || time) {
|
||||
if (ishost) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%s%s%s%s", color, "Uptime", reset, ": ");
|
||||
if (days) {
|
||||
printf("%s", days);
|
||||
if (time) printf(" ");
|
||||
}
|
||||
if (time) {
|
||||
printf("%s", time);
|
||||
}
|
||||
printf("%s%s%s%s", color, "Host", reset, ": ");
|
||||
display_host_model();
|
||||
printf("\n");
|
||||
if (days) free((void *)days);
|
||||
if (time) free((void *)time);
|
||||
lc++;
|
||||
}
|
||||
} else minsize--;
|
||||
|
||||
if (isuptime) {
|
||||
const char *days = display_days();
|
||||
const char *time = display_time();
|
||||
if (days || time) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%s%s%s%s", color, "Uptime", reset, ": ");
|
||||
if (days) {
|
||||
printf("%s", days);
|
||||
if (time) printf(" ");
|
||||
}
|
||||
if (time) {
|
||||
printf("%s", time);
|
||||
}
|
||||
printf("\n");
|
||||
if (days) free((void *)days);
|
||||
if (time) free((void *)time);
|
||||
lc++;
|
||||
}
|
||||
} else minsize--;
|
||||
|
||||
#if defined(__OpenBSD__)
|
||||
const char *audio = display_recording_audio();
|
||||
const char *video = display_recording_video();
|
||||
if (audio || video) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sRecording%s: ", color, reset);
|
||||
if (audio) {
|
||||
printf("audio = %s", audio);
|
||||
if (video) printf(", ");
|
||||
if (isrecording) {
|
||||
const char *audio = display_recording_audio();
|
||||
const char *video = display_recording_video();
|
||||
if (audio || video) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sRecording%s: ", color, reset);
|
||||
if (audio) {
|
||||
printf("audio = %s", audio);
|
||||
if (video) printf(", ");
|
||||
}
|
||||
if (video) {
|
||||
printf("video = %s", video);
|
||||
}
|
||||
printf("\n");
|
||||
if (audio) free((void *)audio);
|
||||
if (video) free((void *)video);
|
||||
lc++;
|
||||
}
|
||||
if (video) {
|
||||
printf("video = %s", video);
|
||||
}
|
||||
printf("\n");
|
||||
if (audio) free((void *)audio);
|
||||
if (video) free((void *)video);
|
||||
lc++;
|
||||
}
|
||||
} else minsize--;
|
||||
#endif
|
||||
|
||||
const char *packages = display_packages();
|
||||
if (packages) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sPackages%s: %s\n", color, reset, packages);
|
||||
lc++;
|
||||
free((void *)packages);
|
||||
if (ispackages) {
|
||||
const char *packages = display_packages();
|
||||
if (packages) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sPackages%s: %s\n", color, reset, packages);
|
||||
lc++;
|
||||
free((void *)packages);
|
||||
}
|
||||
} else minsize--;
|
||||
|
||||
if (isresolution) {
|
||||
const char *resolution = display_resolution();
|
||||
if (resolution) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sResolution%s: %s\n", color, reset, resolution);
|
||||
lc++;
|
||||
free((void *)resolution);
|
||||
}
|
||||
}
|
||||
|
||||
const char *resolution = display_resolution();
|
||||
if (resolution) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sResolution%s: %s\n", color, reset, resolution);
|
||||
lc++;
|
||||
free((void *)resolution);
|
||||
}
|
||||
|
||||
const char *wm = display_wm();
|
||||
if (wm) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sWM%s: %s\n", color, reset, wm);
|
||||
if (iswm) {
|
||||
const char *wm = display_wm();
|
||||
if (wm) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sWM%s: %s\n", color, reset, wm);
|
||||
#if !defined(__APPLE__)
|
||||
free((void *)wm);
|
||||
free((void *)wm);
|
||||
#endif
|
||||
lc++;
|
||||
lc++;
|
||||
}
|
||||
}
|
||||
|
||||
const char *shell = display_shell();
|
||||
if (shell) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sShell%s: %s\n", color, reset, shell);
|
||||
free((void *)shell);
|
||||
lc++;
|
||||
}
|
||||
|
||||
const char *libc = display_libc();
|
||||
if (libc) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%slibc%s: %s\n", color, reset, libc);
|
||||
lc++;
|
||||
if (isshell) {
|
||||
const char *shell = display_shell();
|
||||
if (shell) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sShell%s: %s\n", color, reset, shell);
|
||||
free((void *)shell);
|
||||
lc++;
|
||||
}
|
||||
} else minsize--;
|
||||
|
||||
if (islibc) {
|
||||
const char *libc = display_libc();
|
||||
if (libc) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%slibc%s: %s\n", color, reset, libc);
|
||||
lc++;
|
||||
}
|
||||
}
|
||||
|
||||
if (iscpu) {
|
||||
const char *cpu = display_cpu();
|
||||
if (cpu) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sCPU%s: %s\n", color, reset, cpu);
|
||||
lc++;
|
||||
free((void *)cpu);
|
||||
if (cpu) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sCPU%s: %s\n", color, reset, cpu);
|
||||
lc++;
|
||||
free((void *)cpu);
|
||||
}
|
||||
} else minsize--;
|
||||
|
||||
if (isgpu) {
|
||||
const char *gpu = display_gpu();
|
||||
if (gpu) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sGPU%s: %s\n", color, reset, gpu);
|
||||
lc++;
|
||||
free((void *)gpu);
|
||||
}
|
||||
}
|
||||
|
||||
const char *gpu = display_gpu();
|
||||
if (gpu) {
|
||||
if (ismemory) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sGPU%s: %s\n", color, reset, gpu);
|
||||
printf("%s%s%s%s", color, "Memory", reset, ": ");
|
||||
display_memory();
|
||||
printf("\n");
|
||||
lc++;
|
||||
free((void *)gpu);
|
||||
}
|
||||
} else minsize--;
|
||||
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%s%s%s%s", color, "Memory", reset, ": ");
|
||||
display_memory();
|
||||
printf("\n");
|
||||
lc++;
|
||||
|
||||
const char *storage = display_storage();
|
||||
if (storage) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sStorage%s: %s\n", color, reset, storage);
|
||||
lc++;
|
||||
free((void *)storage);
|
||||
if (isstorage) {
|
||||
const char *storage = display_storage();
|
||||
if (storage) {
|
||||
printf("%s ", LOGO[lc]);
|
||||
printf("%sStorage%s: %s\n", color, reset, storage);
|
||||
lc++;
|
||||
free((void *)storage);
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = lc; i < ls; i++) {
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <unistd.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "config.h"
|
||||
|
||||
bool isos = true;
|
||||
bool ishost = true;
|
||||
#if defined(__linux__) || defined(__sunos)
|
||||
bool isdistro = true;
|
||||
#endif
|
||||
bool isuptime = true;
|
||||
#if defined(__OpenBSD__)
|
||||
bool isrecording = true;
|
||||
#endif
|
||||
bool ispackages = true;
|
||||
bool islibc = true;
|
||||
bool isresolution = true;
|
||||
bool iswm = true;
|
||||
bool isshell = true;
|
||||
bool iscpu = true;
|
||||
bool isgpu = true;
|
||||
bool ismemory = true;
|
||||
bool isstorage = true;
|
||||
|
||||
void getconf() {
|
||||
char *homedir = getenv("HOME");
|
||||
if (homedir == NULL) {
|
||||
perror("ホームディレクトリを受取に失敗");
|
||||
return;
|
||||
}
|
||||
|
||||
#if defined(__HAIKU__)
|
||||
char *basedir = "/config/settings/";
|
||||
#else
|
||||
char *basedir = "/.config/";
|
||||
#endif
|
||||
|
||||
int alllen = snprintf(NULL, 0, "%s%s%s", homedir, basedir, "farfetch.conf") + 1;
|
||||
char *cnfpath = malloc(alllen);
|
||||
if (cnfpath == NULL) {
|
||||
perror("メモリを割当に失敗");
|
||||
return;
|
||||
}
|
||||
|
||||
snprintf(cnfpath, alllen, "%s%s%s", homedir, basedir, "farfetch.conf");
|
||||
|
||||
if (access(cnfpath, F_OK) != 0) {
|
||||
free(cnfpath);
|
||||
return;
|
||||
}
|
||||
|
||||
FILE *file = fopen(cnfpath, "r");
|
||||
free(cnfpath);
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
|
||||
char line[20];
|
||||
while (fgets(line, sizeof(line), file)) {
|
||||
if (line[0] == '#' || line[0] == '\n') continue;
|
||||
if (strstr(line, "hide ") != NULL) {
|
||||
if (strstr(line, "os") != NULL) isos = false;
|
||||
if (strstr(line, "host") != NULL) ishost = false;
|
||||
#if defined(__linux__) || defined(__sunos)
|
||||
if (strstr(line, "distro") != NULL) isdistro = false;
|
||||
#endif
|
||||
if (strstr(line, "uptime") != NULL) isuptime = false;
|
||||
#if defined (__OpenBSD__)
|
||||
if (strstr(line, "recording") != NULL) isrecording = false;
|
||||
#endif
|
||||
if (strstr(line, "packages") != NULL) ispackages = false;
|
||||
if (strstr(line, "libc") != NULL) islibc = false;
|
||||
if (strstr(line, "resolution") != NULL) isresolution = false;
|
||||
if (strstr(line, "wm") != NULL) iswm = false;
|
||||
if (strstr(line, "shell") != NULL) isshell = false;
|
||||
if (strstr(line, "cpu") != NULL) iscpu = false;
|
||||
if (strstr(line, "gpu") != NULL) isgpu = false;
|
||||
if (strstr(line, "memory") != NULL) ismemory = false;
|
||||
if (strstr(line, "storage") != NULL) isstorage = false;
|
||||
}
|
||||
}
|
||||
|
||||
fclose(file);
|
||||
return;
|
||||
}
|
|
@ -0,0 +1,27 @@
|
|||
#ifndef CONFIG_H
|
||||
#define CONFIG_H
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
extern bool isos;
|
||||
extern bool ishost;
|
||||
#if defined(__linux__) || defined(__sunos)
|
||||
extern bool isdistro;
|
||||
#endif
|
||||
extern bool isuptime;
|
||||
#if defined(__OpenBSD__)
|
||||
extern bool isrecording;
|
||||
#endif
|
||||
extern bool ispackages;
|
||||
extern bool islibc;
|
||||
extern bool isresolution;
|
||||
extern bool iswm;
|
||||
extern bool isshell;
|
||||
extern bool iscpu;
|
||||
extern bool isgpu;
|
||||
extern bool ismemory;
|
||||
extern bool isstorage;
|
||||
|
||||
void getconf();
|
||||
|
||||
#endif
|
読み込み中…
新しいイシューから参照