aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-12-02 09:18:24 -0800
committerNicholas Noll <nbnoll@eml.cc>2021-12-02 09:18:24 -0800
commitf7a916f7620c749d440cb6a76010641675217689 (patch)
treea77f29c25f6143645f11cefa6f30c22daa1c6549
parentabd5a5b67e5b87a1de73761172ff51cf2f8e1213 (diff)
many small updates
-rwxr-xr-xbin/status6
-rw-r--r--include/base/io.h3
-rw-r--r--include/base/string.h3
-rw-r--r--src/base/bufio/init.c4
-rw-r--r--src/base/bufio/readline.c11
-rw-r--r--src/base/bufio/readuntil.c15
-rw-r--r--src/base/bufio/rules.mk1
-rw-r--r--src/base/fmt/vfprint.c2
-rw-r--r--src/base/mem/rules.mk1
-rw-r--r--src/base/string/atoi.c11
-rw-r--r--src/base/string/rules.mk1
-rw-r--r--src/rules.mk3
12 files changed, 47 insertions, 14 deletions
diff --git a/bin/status b/bin/status
index df787a1..77937a5 100755
--- a/bin/status
+++ b/bin/status
@@ -111,7 +111,7 @@ refresh_time() {
refresh_all() {
refresh_volume
- refresh_battery
+ #refresh_battery
refresh_ip
refresh_cpu
refresh_mail
@@ -128,7 +128,7 @@ trap "refresh_weather" 40
trap "refresh_time" 41
trap "refresh_all" 42
-while true # ip address
+while true
do
sleep 2h
refresh_ip
@@ -140,7 +140,7 @@ refresh_weather
refresh_ip
while true
do
- refresh_battery
+ #refresh_battery
refresh_memory
refresh_cpu
refresh_mail
diff --git a/include/base/io.h b/include/base/io.h
index 22606ad..5c8fdd9 100644
--- a/include/base/io.h
+++ b/include/base/io.h
@@ -115,7 +115,7 @@ struct io·Header
int state, fd, flag;
int ilen; /* negative number of bytes at end of buffer */
int olen; /* number of bytes at start of buffer */
- int line; /* number of bytes after last readline */
+ int nread; /* number of bytes after last readline */
int runesz; /* number of bytes of last getrune */
int cap; /* size of buffer */
intptr pos; /* position in file */
@@ -138,6 +138,7 @@ int bio·initcap(io·Header *io, int fd, int mode, int cap, uchar *buf);
int bio·flush(io·Header *io);
intptr bio·read(io·Header *io, intptr len, void *buf);
void *bio·readuntil(io·Header *io, int delim);
+void *bio·readline(io·Header *io, int null);
intptr bio·write(io·Header *io, intptr len, void *buf);
int bio·getc(io·Header *io);
diff --git a/include/base/string.h b/include/base/string.h
index 08466fa..157129f 100644
--- a/include/base/string.h
+++ b/include/base/string.h
@@ -28,3 +28,6 @@ string str·join(vlong len, byte** fields, const byte* sep);
/* raw C string functions */
char *str·copyn(char *dst, char *src, int n);
+
+/* string parsing */
+int str·atoi(char *s);
diff --git a/src/base/bufio/init.c b/src/base/bufio/init.c
index 7e6dcee..b6814e1 100644
--- a/src/base/bufio/init.c
+++ b/src/base/bufio/init.c
@@ -75,14 +75,14 @@ bio·initcap(io·Header *io, int fd, int mode, int cap, uchar *buf)
io->g = io->e;
io->fd = fd;
io->cap = cap;
- io->pos = io->runesz = io->flag = io->ilen = io->line = 0;
+ io->pos = io->runesz = io->flag = io->ilen = io->nread = 0;
return 0;
}
int
bio·init(io·Buffer *io, int fd, int mode)
{
- return bio·initcap(header(io), fd, mode, io·BufLen + io·BufUngets, io->b);
+ return bio·initcap(header(io), fd, mode, io·BufLen + io·BufUngets, io->bytes);
}
int
diff --git a/src/base/bufio/readline.c b/src/base/bufio/readline.c
new file mode 100644
index 0000000..0a50098
--- /dev/null
+++ b/src/base/bufio/readline.c
@@ -0,0 +1,11 @@
+#include "internal.h"
+
+void *
+bio·readline(io·Header *io, int null)
+{
+ char *start = bio·readuntil(io, '\n');
+ if(null && start)
+ start[io->nread-1] = 0;
+
+ return start;
+}
diff --git a/src/base/bufio/readuntil.c b/src/base/bufio/readuntil.c
index 8084cca..1a0faaf 100644
--- a/src/base/bufio/readuntil.c
+++ b/src/base/bufio/readuntil.c
@@ -11,7 +11,7 @@ bio·readuntil(io·Header *io, int delim)
if(io->state != io·BufRdr){
if(io->state == io·BufEnd)
io->state = io·BufRdr;
- io->line = 0;
+ io->nread = 0;
io->g = io->e;
return nil;
}
@@ -21,7 +21,7 @@ bio·readuntil(io·Header *io, int delim)
b = (char*)io->e - i;
if((e = mem·findc(b, i, delim)) != nil){
j = (e - b)+1;
- io->line = j;
+ io->nread = j;
io->ilen += j;
return b;
}
@@ -29,12 +29,13 @@ bio·readuntil(io·Header *io, int delim)
if(i < io->cap)
mem·move(io->b, b, i);
io->g = io->b;
+
/* write to the buffer while we search for delim */
b = (char *)io->b + i;
while(i < io->cap){
- if(sys·read(io->fd, io->cap-i, b, &j)){
+ if(sys·read(io->fd, io->cap-i, b, &j) || j == 0){
mem·move(io->e-i, io->b, i);
- io->line = +i;
+ io->nread = +i;
io->ilen = -i;
io->g = io->e - i;
return 0;
@@ -50,15 +51,15 @@ bio·readuntil(io·Header *io, int delim)
io->g = (uchar *)b;
}
j = (e - (char*)io->b) + 1;
- io->line = j;
+ io->nread = j;
io->ilen = j - i;
return b;
}
b += j;
}
- io->line = +io->cap;
+ io->nread = +io->cap;
io->ilen = -io->cap;
io->g = io->b;
- return 0;
+ return nil;
}
diff --git a/src/base/bufio/rules.mk b/src/base/bufio/rules.mk
index 4546aeb..f367b8e 100644
--- a/src/base/bufio/rules.mk
+++ b/src/base/bufio/rules.mk
@@ -9,6 +9,7 @@ SRCS_$(d)+=\
$(d)/bufio/print.c\
$(d)/bufio/putc.c\
$(d)/bufio/read.c\
+ $(d)/bufio/readline.c\
$(d)/bufio/readuntil.c\
$(d)/bufio/seek.c\
$(d)/bufio/ungetc.c\
diff --git a/src/base/fmt/vfprint.c b/src/base/fmt/vfprint.c
index 4306ea7..4cefcb7 100644
--- a/src/base/fmt/vfprint.c
+++ b/src/base/fmt/vfprint.c
@@ -3,7 +3,7 @@
int
fmt·vfprint(int fd, char *fmt, va_list args)
{
- int n;
+ int n;
fmt·State io;
char buf[256];
diff --git a/src/base/mem/rules.mk b/src/base/mem/rules.mk
index fda54e1..a4d9f10 100644
--- a/src/base/mem/rules.mk
+++ b/src/base/mem/rules.mk
@@ -4,5 +4,6 @@ SRCS_$(d)+=\
$(d)/mem/interface.c\
$(d)/mem/set.c\
$(d)/mem/set64.c\
+ $(d)/mem/findc.c\
$(d)/mem/copy.c\
$(d)/mem/move.c
diff --git a/src/base/string/atoi.c b/src/base/string/atoi.c
new file mode 100644
index 0000000..dba057a
--- /dev/null
+++ b/src/base/string/atoi.c
@@ -0,0 +1,11 @@
+#include "internal.h"
+
+int
+str·atoi(char *s)
+{
+ int n = 0;
+ while(*s)
+ n = 10*n + (*s++ - '0');
+
+ return n;
+}
diff --git a/src/base/string/rules.mk b/src/base/string/rules.mk
index e517ca5..0352f54 100644
--- a/src/base/string/rules.mk
+++ b/src/base/string/rules.mk
@@ -1,4 +1,5 @@
SRCS_$(d)+=\
+ $(d)/string/atoi.c\
$(d)/string/append.c\
$(d)/string/appendf.c\
$(d)/string/clear.c\
diff --git a/src/rules.mk b/src/rules.mk
index 368479c..5e848ae 100644
--- a/src/rules.mk
+++ b/src/rules.mk
@@ -8,6 +8,9 @@ include $(DIR)/rules.mk
DIR := $(d)/base
include $(DIR)/rules.mk
+DIR := $(d)/etc
+include $(DIR)/rules.mk
+
DIR := $(d)/libmath
include $(DIR)/rules.mk