commit a169bc9ed6aad8ecf8e6ce1e89b2924f5c46b072
parent 5944cd9eec718dbaa0c48f56be9a0ffd4bf34a94
Author: glenda <glenda@9front.local>
Date: Thu, 12 Aug 2021 16:46:42 +0000
add new Array datatype, switch Fonts over to it
Diffstat:
5 files changed, 21 insertions(+), 33 deletions(-)
diff --git a/devfs.c b/devfs.c
@@ -5,6 +5,7 @@
#include <draw.h>
#include <9p.h>
+#include "array.h"
#include "richterm.h"
File *cons, *consctl;
diff --git a/fs.c b/fs.c
@@ -5,6 +5,7 @@
#include <draw.h>
#include <9p.h>
+#include "array.h"
#include "richterm.h"
File *new, *ctl;
@@ -119,7 +120,9 @@ fs_write(Req *r)
r->ofcall.count = r->ifcall.count;
if (aux->type == FT_FONT) {
- aux->obj->font = getfont(&fonts, aux->data->p);
+ char *path;
+ tokenize(aux->data->p, &path, 1);
+ aux->obj->font = getfont(fonts, path);
}
qunlock(rich.l);
diff --git a/mkfile b/mkfile
@@ -1,7 +1,7 @@
</$objtype/mkfile
TARG=richterm
-OFILES=richterm.$O devfs.$O fs.$O
+OFILES=richterm.$O devfs.$O fs.$O array.$O
HFILES=richterm.h
</sys/src/cmd/mkone
diff --git a/richterm.c b/richterm.c
@@ -8,6 +8,7 @@
#include <cursor.h>
#include <9p.h>
+#include "array.h"
#include "richterm.h"
Rich rich;
@@ -15,7 +16,7 @@ int hostpid = -1;
Channel *pidchan;
Devfsctl *dctl;
Fsctl *fsctl;
-Fonts fonts;
+Array *fonts;
Image *Iscrollbar, *Ilink, *Inormbg, *Iselbg;
Object *olast;
@@ -45,6 +46,7 @@ usage(void)
void
threadmain(int argc, char **argv)
{
+ Font **fp;
Mousectl *mctl;
Keyboardctl *kctl;
int rv[2], mmode;
@@ -79,6 +81,10 @@ threadmain(int argc, char **argv)
if (initdraw(0, 0, "richterm") < 0)
sysfatal("%s: %r", argv0);
+ fonts = arraycreate(sizeof(Font *), 2, nil);
+ fp = arrayadd(fonts);
+ *fp = font;
+
olast = newobject(&rich, nil);
mmode = MM_NONE;
@@ -515,38 +521,25 @@ generatepage(Rich *rich)
}
Font *
-getfont(Fonts *fonts, char *name)
+getfont(Array *fonts, char *name)
{
int i;
- Font *newfont;
+ Font *newfont, **fp;
for (i = 0; i < fonts->count; i++){
- if (strcmp(fonts->data[i]->name, name) == 0) return fonts->data[i];
+ fp = arrayget(fonts, i);
+ if (strcmp((*fp)->name, name) == 0) return *fp;
}
if ((newfont = openfont(display, name)) == nil) {
fprint(2, "%r\n");
newfont = font;
} else {
- addfont(fonts, newfont);
+ fp = arrayadd(fonts);
+ *fp = newfont;
}
return newfont;
}
void
-addfont(Fonts *fonts, Font *font)
-{
- if (fonts->data == nil) {
- fonts->data = mallocz(16 * sizeof(Font*), 1);
- fonts->size = 16;
- }
- if (fonts->count >= fonts->size) {
- fonts->size = fonts->size * 2;
- fonts->data = realloc(fonts->data, fonts->size * sizeof(Font*));
- }
- fonts->data[fonts->count] = font;
- fonts->count++;
-}
-
-void
scroll(Point p, Rich *r)
{
if (p.x < 0) p.x = 0;
diff --git a/richterm.h b/richterm.h
@@ -29,18 +29,9 @@ extern Object *olast;
Object * mkobjectftree(Object *, File *);
void rmobjectftree(Object *);
-typedef struct Fonts Fonts;
+extern Array *fonts;
-struct Fonts {
- Font **data;
- int size;
- int count;
-};
-
-extern Fonts fonts;
-
-Font* getfont(Fonts *, char *);
-void addfont(Fonts *, Font *);
+Font* getfont(Array *, char *);
typedef struct View View;