aboutsummaryrefslogtreecommitdiff
path: root/sys
diff options
context:
space:
mode:
authorNicholas Noll <nbnoll@eml.cc>2021-04-22 10:29:35 -0700
committerNicholas Noll <nbnoll@eml.cc>2021-04-22 10:29:35 -0700
commit4b0ef5bf1644520bcec05a7b2f59d6787eb616f8 (patch)
tree0d92e510096020202a50c177db802dab77fba118 /sys
parent4bee1c911c0a710da47b62a31e84535d2e0b7c76 (diff)
chore(refactor): explicit definition of useful interfaces
Diffstat (limited to 'sys')
-rw-r--r--sys/cmd/dwm/util.c2
-rw-r--r--sys/cmd/term/config.h3
-rw-r--r--sys/libbio/newick.c4
-rw-r--r--sys/libn/gz.c17
-rw-r--r--sys/libn/io.c91
-rw-r--r--sys/libn/mmap.c4
6 files changed, 97 insertions, 24 deletions
diff --git a/sys/cmd/dwm/util.c b/sys/cmd/dwm/util.c
index 445d479..c64e652 100644
--- a/sys/cmd/dwm/util.c
+++ b/sys/cmd/dwm/util.c
@@ -35,7 +35,7 @@ getparentprocess(pid_t p)
uint v = 0;
#if defined(__linux__)
- Stream *f;
+ io·Stream *f;
char buf[256];
snprintf(buf, sizeof(buf) - 1, "/proc/%u/stat", (unsigned)p);
diff --git a/sys/cmd/term/config.h b/sys/cmd/term/config.h
index 1e4603a..f638e8a 100644
--- a/sys/cmd/term/config.h
+++ b/sys/cmd/term/config.h
@@ -6,8 +6,7 @@
*
* font: see http://freedesktop.org/software/fontconfig/fontconfig-user.html
*/
-// static char *font = "consolas:pixelsize=16:antialias=true";
-static char *font = "FiraCode:pixelsize=16:antialias=true";
+static char *font = "consolas:pixelsize=16:antialias=true";
static int borderpx = 2;
/*
diff --git a/sys/libbio/newick.c b/sys/libbio/newick.c
index 164516f..a838278 100644
--- a/sys/libbio/newick.c
+++ b/sys/libbio/newick.c
@@ -395,13 +395,13 @@ dump(bio·Node *node, void *impl, io·Putter out)
out.put(impl, ')');
}
if (node->name) {
- out.putstr(impl, node->name);
+ out.puts(impl, node->name);
}
if (node->parent) {
out.put(impl, ':');
snprintf(b, arrlen(b), "%f", node->dist);
- out.putstr(impl, b);
+ out.puts(impl, b);
}
return 0;
diff --git a/sys/libn/gz.c b/sys/libn/gz.c
index c1dda9e..79bc13f 100644
--- a/sys/libn/gz.c
+++ b/sys/libn/gz.c
@@ -3,6 +3,23 @@
#include <zlib.h>
+// -----------------------------------------------------------------------
+// interface implementations
+
+/* actual interfaces */
+io·Reader gz·FileReader = (io·Reader){ gz·read };
+io·Peeker gz·FilePeeker = (io·Peeker){ gz·getbyte, gz·ungetbyte };
+io·FullReader gz·FullFileReader = (io·FullReader){ gz·read, gz·getbyte, gz·ungetbyte };
+
+io·Writer gz·FileWriter = (io·Writer){ gz·write };
+io·Putter gz·FilePutter = (io·Putter){ gz·putbyte, gz·putstring };
+io·FullWriter gz·FullFileWriter = (io·FullWriter){ gz·write, gz·putbyte, gz·putstring };
+
+io·ReadWriter gz·FileReadWriter = (io·ReadWriter){ gz·read, gz·write };
+
+// -----------------------------------------------------------------------
+// functions implementations
+
gz·Stream*
gz·open(byte *path, byte *mode)
{
diff --git a/sys/libn/io.c b/sys/libn/io.c
index 8aa4aa0..f0d270e 100644
--- a/sys/libn/io.c
+++ b/sys/libn/io.c
@@ -2,55 +2,112 @@
#include <libn.h>
// -----------------------------------------------------------------------
-// Open/Close
+// interface implementations
-Stream*
+/* casting functions */
+static
+int
+·read(void *rdr, int size, int n, void *buf)
+{
+ return io·read((io·Stream *)rdr, size, n, buf);
+}
+
+static
+byte
+·get(void *rdr)
+{
+ return io·getbyte((io·Stream *)rdr);
+}
+
+static
+error
+·unget(void *rdr, byte c)
+{
+ return io·ungetbyte((io·Stream *)rdr, c);
+}
+
+static
+int
+·write(void *wtr, int sz, int n, void *buf)
+{
+ return io·write((io·Stream *)wtr, sz, n, buf);
+}
+
+static
+error
+·put(void *wtr, byte c)
+{
+ return io·putbyte((io·Stream *)wtr, c);
+}
+
+static
+int
+·puts(void *wtr, string s)
+{
+ return io·putstring((io·Stream *)wtr, s);
+}
+
+/* actual interfaces */
+io·Reader sys·Reader = (io·Reader){ ·read };
+io·Peeker sys·Peeker = (io·Peeker){ ·get, ·unget };
+io·FullReader sys·FullReader = (io·FullReader){ ·read, ·get, ·unget };
+
+io·Writer sys·Writer = (io·Writer){ ·write };
+io·Putter sys·Putter = (io·Putter){ ·put, ·puts };
+io·FullWriter sys·FullWriter = (io·FullWriter){ ·write, ·put, ·puts };
+
+io·ReadWriter sys·ReadWriter = (io·ReadWriter){ ·read, ·write };
+
+// -----------------------------------------------------------------------
+// open/close
+
+io·Stream*
io·open(byte *name, byte *mode)
{
return fopen(name, mode);
}
int
-io·fd(Stream *s)
+io·fd(io·Stream *s)
{
return fileno(s);
}
error
-io·stat(Stream *s, io·Stat *buf)
+io·stat(io·Stream *s, io·Stat *buf)
{
return fstat(fileno(s), buf);
}
error
-io·close(Stream *s)
+io·close(io·Stream *s)
{
return fclose(s);
}
// -----------------------------------------------------------------------
-// Reading
+// reading
byte
-io·getbyte(Stream *s)
+io·getbyte(io·Stream *s)
{
return fgetc(s);
}
error
-io·ungetbyte(Stream *s, byte c)
+io·ungetbyte(io·Stream *s, byte c)
{
return ungetc(c, s);
}
int
-io·read(Stream *s, int sz, int n, void *buf)
+io·read(io·Stream *s, int sz, int n, void *buf)
{
return fread(buf, sz, n, s);
}
int
-io·readln(Stream *s, int n, byte* buf)
+io·readln(io·Stream *s, int n, byte* buf)
{
byte* b;
b = fgets(buf, n+1, s);
@@ -61,37 +118,37 @@ io·readln(Stream *s, int n, byte* buf)
}
// -----------------------------------------------------------------------
-// Writing
+// writing
error
-io·putbyte(Stream *s, byte c)
+io·putbyte(io·Stream *s, byte c)
{
return fputc(c, s);
}
int
-io·putstring(Stream *s, string str)
+io·putstring(io·Stream *s, string str)
{
return fputs(str, s);
}
int
-io·write(Stream *s, int sz, int n, void *buf)
+io·write(io·Stream *s, int sz, int n, void *buf)
{
return fwrite(buf, sz, n, s);
}
int
-io·flush(Stream *s)
+io·flush(io·Stream *s)
{
return fflush(s);
}
// -----------------------------------------------------------------------
-// Seek
+// seek
int
-io·seek(Stream *s, long off, enum SeekPos origin)
+io·seek(io·Stream *s, long off, enum SeekPos origin)
{
return fseek(s, off, origin);
}
diff --git a/sys/libn/mmap.c b/sys/libn/mmap.c
index 89b7519..b2c436c 100644
--- a/sys/libn/mmap.c
+++ b/sys/libn/mmap.c
@@ -9,8 +9,8 @@ mmap·open(byte *filename)
int fd;
int err;
void *buf;
- Stream *s;
- io·Stat st;
+ io·Stream *s;
+ io·Stat st;
s = io·open(filename, "r");
fd = io·fd(s);