commit 0a068e35ccb5b570828149180378731ee953c03e
parent 612007bf250ae8a0b6280500c78f6de74b135b1c
Author: ssnf <ssnf@ssnf.xyz>
Date: Thu, 10 Jun 2021 18:51:54 +0000
general file cleanup
Diffstat:
M | Makefile | | | 2 | +- |
M | linux.c | | | 130 | ++++++++++++++++++++++++++++++++++++++++--------------------------------------- |
M | sbar.h | | | 30 | ++++++++++++++---------------- |
3 files changed, 81 insertions(+), 81 deletions(-)
diff --git a/Makefile b/Makefile
@@ -10,7 +10,7 @@ OBJ = ${SRC:.c=.o}
all: sbar config.h
config.h:
- cp -n config.def.h $@
+ cp config.def.h $@
%.o: %.c
${CC} ${CFLAGS} -c $<
diff --git a/linux.c b/linux.c
@@ -5,40 +5,56 @@
#include <X11/Xlib.h>
#include <sys/statfs.h>
-void wait(double);
-void Partinit();
+void Batchk();
+void Datechk();
void Partchk();
-void Raminit();
+void Partinit();
void Ramchk();
-void Datechk();
-void Batchk();
+void Raminit();
+void Titleinit();
+void Titleset();
+void wait(double);
static Display* display;
void
-wait(double t)
+Batchk()
{
- usleep((uchar)t * 1000000);
+ FILE* f;
+ uint c;
+
+ if (!(f = fopen("/sys/class/power_supply/BAT0/capacity", "r"))) return;
+ fscanf(f, "%u", &c);
+ fclose(f);
+ if (c == bat.c) return;
+ bat.c = c;
+ snprintf(bat.text, 19, "B(%u%%)", c);
}
void
-Partinit()
+Datechk()
{
- struct statfs stat;
- uint i, size;
+ FILE* f;
+ uint h, m, s, d, M;
- for (i = 0; part[i].path; ++i) {
- statfs(part[i].path, &stat);
- size = (stat.f_blocks * stat.f_bsize) >> 20;
- part[i].size_f = (float)size / 1024.0f;
- }
+ if (!(f = fopen("/sys/class/rtc/rtc0/time", "r"))) return;
+ fscanf(f, "%u:%u:%u", &h, &m, &s);
+ fclose(f);
+ if (s == date.s) return;
+ if (h > 12) h -= 12;
+ date.s = s;
+ if (!(f = fopen("/sys/class/rtc/rtc0/date", "r"))) return;
+ fscanf(f, "%*u-%u-%u", &M, &d);
+ fclose(f);
+ ++title.update;
+ snprintf(date.text, 16, "%u/%u %u:%02u:%02u", M, d, h, m, s);
}
void
Partchk()
{
- struct statfs stat;
- uint i, free;
+ struct statfs stat;
+ uint i, free;
for (i = 0; part[i].path; ++i) {
statfs(part[i].path, &stat);
@@ -52,33 +68,26 @@ Partchk()
}
void
-Raminit()
+Partinit()
{
- FILE* meminfo;
- char buf[32];
- ulong size;
+ struct statfs stat;
+ uint i, size;
- if (!(meminfo = fopen("/proc/meminfo", "r"))) return;
- fread(buf, 32, 1, meminfo);
- fclose(meminfo);
- sscanf(buf, "MemTotal: %lu", &size);
- ram.size = size;
- ram.unit = 'M';
- if (size > 1024*1024) {
- ram.unit = 'G';
- size >>= 10;
+ for (i = 0; part[i].path; ++i) {
+ statfs(part[i].path, &stat);
+ size = (stat.f_blocks * stat.f_bsize) >> 20;
+ part[i].size_f = (float)size / 1024.0f;
}
- ram.size_f = size/1024.0f;
}
void
Ramchk()
{
- FILE* meminfo;
- char buf[1024];
- ulong i, free;
- float used_f;
- uchar unit;
+ FILE* meminfo;
+ char buf[1024];
+ ulong i, free;
+ float used_f;
+ uchar unit;
if (!(meminfo = fopen("/proc/meminfo", "r"))) return;
fread(buf, 1024, 1, meminfo);
@@ -107,36 +116,23 @@ Ramchk()
}
void
-Datechk()
-{
- FILE* f;
- uint h, m, s, d, M;
-
- if (!(f = fopen("/sys/class/rtc/rtc0/time", "r"))) return;
- fscanf(f, "%u:%u:%u", &h, &m, &s);
- fclose(f);
- if (s == date.s) return;
- if (h > 12) h -= 12;
- date.s = s;
- if (!(f = fopen("/sys/class/rtc/rtc0/date", "r"))) return;
- fscanf(f, "%*u-%u-%u", &M, &d);
- fclose(f);
- ++title.update;
- snprintf(date.text, 16, "%u/%u %u:%02u:%02u", M, d, h, m, s);
-}
-
-void
-Batchk()
+Raminit()
{
- FILE* f;
- uint c;
+ FILE* meminfo;
+ char buf[32];
+ ulong size;
- if (!(f = fopen("/sys/class/power_supply/BAT0/capacity", "r"))) return;
- fscanf(f, "%u", &c);
- fclose(f);
- if (c == bat.c) return;
- bat.c = c;
- snprintf(bat.text, 19, "B(%u%%)", c);
+ if (!(meminfo = fopen("/proc/meminfo", "r"))) return;
+ fread(buf, 32, 1, meminfo);
+ fclose(meminfo);
+ sscanf(buf, "MemTotal: %lu", &size);
+ ram.size = size;
+ ram.unit = 'M';
+ if (size > 1024*1024) {
+ ram.unit = 'G';
+ size >>= 10;
+ }
+ ram.size_f = size/1024.0f;
}
void
@@ -151,3 +147,9 @@ Titleset()
XStoreName(display, DefaultRootWindow(display), title.text);
XFlush(display);
}
+
+void
+wait(double t)
+{
+ usleep((uchar)t * 1000000);
+}
diff --git a/sbar.h b/sbar.h
@@ -3,20 +3,23 @@
#include <string.h>
#include <stdarg.h>
-#define LENGTH(a) (sizeof(a)/sizeof(a[0]))
-
typedef unsigned char uchar;
typedef unsigned int uint;
typedef unsigned long ulong;
-typedef struct Title Title;
+typedef struct Bat Bat;
+typedef struct Date Date;
typedef struct Partition Partition;
typedef struct Ram Ram;
-typedef struct Date Date;
-typedef struct Bat Bat;
+typedef struct Title Title;
-struct Title {
- char text[256];
- uchar update;
+struct Bat {
+ char text[8];
+ ulong c;
+};
+
+struct Date {
+ char text[16];
+ uint s;
};
struct Partition {
@@ -34,14 +37,9 @@ struct Ram {
float size_f;
};
-struct Date {
- char text[16];
- uint s;
-};
-
-struct Bat {
- char text[8];
- ulong c;
+struct Title {
+ char text[256];
+ uchar update;
};
void Datechk();