From 1be35009bec0e46defcd8a4b5a1871168f30c735 Mon Sep 17 00:00:00 2001 From: Michael Shalayeff Date: Wed, 14 Mar 2001 02:49:24 +0000 Subject: allow listing and soon deleting fonts; aaron@ ok --- sys/dev/ic/pcdisplay_subr.c | 3 +- sys/dev/ic/vga.c | 35 ++++++++++++------ sys/dev/ic/vgareg.h | 20 ++++++---- sys/dev/wscons/wsconsio.h | 27 ++++++++------ sys/dev/wscons/wsdisplay.c | 73 +++++++++++++++---------------------- sys/dev/wscons/wsdisplayvar.h | 6 ++- sys/dev/wscons/wsemul_vt100_chars.c | 3 +- sys/dev/wscons/wsemul_vt100_subr.c | 3 +- sys/dev/wscons/wsemulconf.c | 7 ++-- sys/dev/wscons/wsemulvar.h | 4 +- 10 files changed, 95 insertions(+), 86 deletions(-) (limited to 'sys') diff --git a/sys/dev/ic/pcdisplay_subr.c b/sys/dev/ic/pcdisplay_subr.c index 52833fb2f37..3b294330d31 100644 --- a/sys/dev/ic/pcdisplay_subr.c +++ b/sys/dev/ic/pcdisplay_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: pcdisplay_subr.c,v 1.2 2001/02/02 20:25:39 aaron Exp $ */ +/* $OpenBSD: pcdisplay_subr.c,v 1.3 2001/03/14 02:49:22 mickey Exp $ */ /* $NetBSD: pcdisplay_subr.c,v 1.16 2000/06/08 07:01:19 cgd Exp $ */ /* @@ -37,6 +37,7 @@ #include #include +#include #include void diff --git a/sys/dev/ic/vga.c b/sys/dev/ic/vga.c index e7d55f77799..f4aa8088384 100644 --- a/sys/dev/ic/vga.c +++ b/sys/dev/ic/vga.c @@ -1,4 +1,4 @@ -/* $OpenBSD: vga.c,v 1.18 2001/02/28 16:48:28 mickey Exp $ */ +/* $OpenBSD: vga.c,v 1.19 2001/03/14 02:49:22 mickey Exp $ */ /* $NetBSD: vga.c,v 1.28.2.1 2000/06/30 16:27:47 simonb Exp $ */ /* @@ -53,7 +53,7 @@ #endif static struct vgafont { - char name[16]; + char name[WSFONT_NAME_SIZE]; int height; int encoding; #ifdef notyet @@ -113,7 +113,7 @@ static struct vgascreen vga_console_screen; static struct vga_config vga_console_vc; int vga_selectfont __P((struct vga_config *, struct vgascreen *, - char *, char *)); + const char *, const char *)); void vga_init_screen __P((struct vga_config *, struct vgascreen *, const struct wsscreen_descr *, int, long *)); @@ -341,7 +341,7 @@ int vga_selectfont(vc, scr, name1, name2) struct vga_config *vc; struct vgascreen *scr; - char *name1, *name2; /* NULL: take first found */ + const char *name1, *name2; /* NULL: take first found */ { const struct wsscreen_descr *type = scr->pcs.type; struct vgafont *f1, *f2; @@ -355,13 +355,15 @@ vga_selectfont(vc, scr, name1, name2) continue; if (!f1 && vga_valid_primary_font(f) && - (!name1 || !strcmp(name1, f->name))) { + (!name1 || !*name1 || + !strncmp(name1, f->name, WSFONT_NAME_SIZE))) { f1 = f; continue; } if (!f2 && VGA_SCREEN_CANTWOFONTS(type) && - (!name2 || !strcmp(name2, f->name))) { + (!name2 || !*name2 || + !strncmp(name2, f->name, WSFONT_NAME_SIZE))) { f2 = f; continue; } @@ -371,7 +373,7 @@ vga_selectfont(vc, scr, name1, name2) * The request fails if no primary font was found, * or if a second font was requested but not found. */ - if (f1 && (!name2 || f2)) { + if (f1 && (!name2 || !*name2 || f2)) { #ifdef VGAFONTDEBUG if (scr != &vga_console_screen || vga_console_attached) { printf("vga (%s): font1=%s (slot %d)", type->name, @@ -866,13 +868,20 @@ vga_load_font(v, cookie, data) } #endif - for (slot = 0; slot < 8; slot++) - if (!vc->vc_fonts[slot]) - break; - if (slot == 8) + if (data->index < 0) { + for (slot = 0; slot < 8; slot++) + if (!vc->vc_fonts[slot]) + break; + } else + slot = data->index; + + if (slot >= 8) return (ENOSPC); - f = malloc(sizeof(struct vgafont), M_DEVBUF, M_WAITOK); + if (!vc->vc_fonts[slot]) + f = malloc(sizeof(struct vgafont), M_DEVBUF, M_WAITOK); + if (!f) + return (ENOMEM); strncpy(f->name, data->name, sizeof(f->name)); f->height = data->fontheight; f->encoding = data->encoding; @@ -887,6 +896,8 @@ vga_load_font(v, cookie, data) vga_loadchars(&vc->hdl, slot, 0, 256, f->height, data->data); f->slot = slot; vc->vc_fonts[slot] = f; + data->cookie = f; + data->index = slot; return (0); } diff --git a/sys/dev/ic/vgareg.h b/sys/dev/ic/vgareg.h index 216b22ebdb5..931fa9e1940 100644 --- a/sys/dev/ic/vgareg.h +++ b/sys/dev/ic/vgareg.h @@ -1,4 +1,4 @@ -/* $OpenBSD: vgareg.h,v 1.1 2000/11/15 20:17:38 aaron Exp $ */ +/* $OpenBSD: vgareg.h,v 1.2 2001/03/14 02:49:22 mickey Exp $ */ /* $NetBSD: vgareg.h,v 1.2 1998/05/28 16:48:41 drochner Exp $ */ /* @@ -33,25 +33,29 @@ * */ +#pragma pack(1) + struct reg_vgaattr { /* indexed via port 0x3c0 */ - char palette[16]; - char mode, overscan, colplen, horpixpan; - char colreset, misc; + u_int8_t palette[16]; + u_int8_t mode, overscan, colplen, horpixpan; + u_int8_t colreset, misc; }; #define VGA_ATC_INDEX 0 #define VGA_ATC_DATAW 0 #define VGA_ATC_DATAR 1 struct reg_vgats { /* indexed via port 0x3c4 */ - char syncreset, mode, wrplmask, fontsel, memmode; + u_int8_t syncreset, mode, wrplmask, fontsel, memmode; }; #define VGA_TS_INDEX 4 #define VGA_TS_DATA 5 struct reg_vgagdc { /* indexed via port 0x3ce */ - char setres, ensetres, colorcomp, rotfunc; - char rdplanesel, mode, misc, colorcare; - char bitmask; + u_int8_t setres, ensetres, colorcomp, rotfunc; + u_int8_t rdplanesel, mode, misc, colorcare; + u_int8_t bitmask; }; #define VGA_GDC_INDEX 0xe #define VGA_GDC_DATA 0xf + +#pragma pack() diff --git a/sys/dev/wscons/wsconsio.h b/sys/dev/wscons/wsconsio.h index 784806831e8..983a595bc4c 100644 --- a/sys/dev/wscons/wsconsio.h +++ b/sys/dev/wscons/wsconsio.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsconsio.h,v 1.7 2001/03/03 08:53:46 maja Exp $ */ +/* $OpenBSD: wsconsio.h,v 1.8 2001/03/14 02:49:22 mickey Exp $ */ /* $NetBSD: wsconsio.h,v 1.31.2.1 2000/07/07 09:49:17 hannken Exp $ */ /* @@ -48,6 +48,9 @@ #include #include +#define WSSCREEN_NAME_SIZE 16 +#define WSEMUL_NAME_SIZE 16 +#define WSFONT_NAME_SIZE 16 /* * Common event structure (used by keyboard and mouse) @@ -299,7 +302,8 @@ struct wsdisplay_cursor { * XXX to be changed without care about backwards compatibility! */ struct wsdisplay_font { - char *name; + char name[WSFONT_NAME_SIZE]; + int index; int firstchar, numchars; int encoding; #define WSDISPLAY_FONTENC_ISO 0 @@ -312,28 +316,27 @@ struct wsdisplay_font { #define WSDISPLAY_FONTORDER_KNOWN 0 /* i.e, no need to convert */ #define WSDISPLAY_FONTORDER_L2R 1 #define WSDISPLAY_FONTORDER_R2L 2 + void *cookie; void *data; }; -#define WSDISPLAYIO_LDFONT _IOW('W', 77, struct wsdisplay_font) +#define WSDISPLAYIO_LDFONT _IOW ('W', 77, struct wsdisplay_font) +#define WSDISPLAYIO_LSFONT _IOWR('W', 78, struct wsdisplay_font) +#define WSDISPLAYIO_DELFONT _IOW ('W', 79, struct wsdisplay_font) +#define WSDISPLAYIO_USEFONT _IOW ('W', 80, struct wsdisplay_font) struct wsdisplay_addscreendata { int idx; /* screen index */ - char *screentype; - char *emul; + char screentype[WSSCREEN_NAME_SIZE]; + char emul[WSEMUL_NAME_SIZE]; }; -#define WSDISPLAYIO_ADDSCREEN _IOW('W', 78, struct wsdisplay_addscreendata) +#define WSDISPLAYIO_ADDSCREEN _IOW('W', 82, struct wsdisplay_addscreendata) struct wsdisplay_delscreendata { int idx; /* screen index */ int flags; #define WSDISPLAY_DELSCR_FORCE 1 }; -#define WSDISPLAYIO_DELSCREEN _IOW('W', 79, struct wsdisplay_delscreendata) - -struct wsdisplay_usefontdata { - char *name; -}; -#define WSDISPLAYIO_USEFONT _IOW('W', 80, struct wsdisplay_usefontdata) +#define WSDISPLAYIO_DELSCREEN _IOW('W', 83, struct wsdisplay_delscreendata) /* Display information: number of bytes per row, may be same as pixels */ #define WSDISPLAYIO_LINEBYTES _IOR('W', 95, u_int) diff --git a/sys/dev/wscons/wsdisplay.c b/sys/dev/wscons/wsdisplay.c index f6d7436928b..b028225bef4 100644 --- a/sys/dev/wscons/wsdisplay.c +++ b/sys/dev/wscons/wsdisplay.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsdisplay.c,v 1.16 2001/03/05 22:16:41 millert Exp $ */ +/* $OpenBSD: wsdisplay.c,v 1.17 2001/03/14 02:49:22 mickey Exp $ */ /* $NetBSD: wsdisplay.c,v 1.37.4.1 2000/06/30 16:27:53 simonb Exp $ */ /* @@ -107,7 +107,8 @@ static void wsdisplay_closescreen __P((struct wsdisplay_softc *, struct wsscreen *)); int wsdisplay_delscreen __P((struct wsdisplay_softc *, int, int)); -#define WSDISPLAY_MAXSCREEN 12 +#define WSDISPLAY_MAXSCREEN 12 +#define WSDISPLAY_MAXFONT 8 struct wsdisplay_softc { struct device sc_dv; @@ -121,6 +122,8 @@ struct wsdisplay_softc { int sc_focusidx; /* available only if sc_focus isn't null */ struct wsscreen *sc_focus; + struct wsdisplay_font sc_fonts[WSDISPLAY_MAXFONT]; + int sc_isconsole; int sc_flags; @@ -308,12 +311,12 @@ wsdisplay_screentype_pick(scrdata, name) KASSERT(scrdata->nscreens > 0); - if (name == NULL) + if (name == NULL || *name == '\0') return (scrdata->screens[0]); for (i = 0; i < scrdata->nscreens; i++) { scr = scrdata->screens[i]; - if (!strcmp(name, scr->name)) + if (!strncmp(name, scr->name, WSSCREEN_NAME_SIZE)) return (scr); } @@ -672,7 +675,7 @@ wsdisplay_cnattach(type, cookie, ccol, crow, defattr) wsdisplay_console_conf.emulcookie = cookie; wsdisplay_console_conf.scrdata = type; - wsemul = wsemul_pick(0); /* default */ + wsemul = wsemul_pick(""); /* default */ wsdisplay_console_conf.wsemul = wsemul; wsdisplay_console_conf.wsemulcookie = (*wsemul->cnattach)(type, cookie, ccol, crow, @@ -953,8 +956,6 @@ wsdisplay_internal_ioctl(sc, scr, cmd, data, flag, p) struct proc *p; { int error; - char namebuf[16]; - struct wsdisplay_font fd; #if NWSKBD > 0 #ifdef WSDISPLAY_COMPAT_RAWKBD @@ -1000,19 +1001,12 @@ wsdisplay_internal_ioctl(sc, scr, cmd, data, flag, p) #undef d case WSDISPLAYIO_USEFONT: -#define d ((struct wsdisplay_usefontdata *)data) +#define d ((struct wsdisplay_font *)data) if (!sc->sc_accessops->load_font) return (EINVAL); - if (d->name) { - error = copyinstr(d->name, namebuf, sizeof(namebuf), 0); - if (error) - return (error); - fd.name = namebuf; - } else - fd.name = 0; - fd.data = 0; + d->data = 0; error = (*sc->sc_accessops->load_font)(sc->sc_accesscookie, - scr->scr_dconf->emulcookie, &fd); + scr->scr_dconf->emulcookie, d); if (!error && WSSCREEN_HAS_EMULATOR(scr)) (*scr->scr_dconf->wsemul->reset) (scr->scr_dconf->wsemulcookie, WSEMUL_SYNCFONT); @@ -1034,7 +1028,6 @@ wsdisplay_cfg_ioctl(sc, cmd, data, flag, p) struct proc *p; { int error; - char *type, typebuf[16], *emul, emulbuf[16]; void *buf; #if defined(COMPAT_14) && NWSKBD > 0 struct wsmux_device wsmuxdata; @@ -1043,23 +1036,8 @@ wsdisplay_cfg_ioctl(sc, cmd, data, flag, p) switch (cmd) { case WSDISPLAYIO_ADDSCREEN: #define d ((struct wsdisplay_addscreendata *)data) - if (d->screentype) { - error = copyinstr(d->screentype, typebuf, - sizeof(typebuf), 0); - if (error) - return (error); - type = typebuf; - } else - type = 0; - if (d->emul) { - error = copyinstr(d->emul, emulbuf, sizeof(emulbuf), 0); - if (error) - return (error); - emul = emulbuf; - } else - emul = 0; - - if ((error = wsdisplay_addscreen(sc, d->idx, type, emul)) == 0) + if ((error = wsdisplay_addscreen(sc, d->idx, + d->screentype, d->emul)) == 0) wsdisplay_addscreen_print(sc, d->idx, 0); return (error); #undef d @@ -1071,13 +1049,8 @@ wsdisplay_cfg_ioctl(sc, cmd, data, flag, p) #define d ((struct wsdisplay_font *)data) if (!sc->sc_accessops->load_font) return (EINVAL); - if (d->name) { - error = copyinstr(d->name, typebuf, sizeof(typebuf), 0); - if (error) - return (error); - d->name = typebuf; - } else - d->name = "loaded"; /* ??? */ + if (d->index >= WSDISPLAY_MAXFONT) + return (EINVAL); buf = malloc(d->fontheight * d->stride * d->numchars, M_DEVBUF, M_WAITOK); error = copyin(d->data, buf, @@ -1089,10 +1062,22 @@ wsdisplay_cfg_ioctl(sc, cmd, data, flag, p) d->data = buf; error = (*sc->sc_accessops->load_font)(sc->sc_accesscookie, 0, d); - free(buf, M_DEVBUF); -#undef d + if (error || d->index < 0) + free(buf, M_DEVBUF); + else + sc->sc_fonts[d->index] = *d; return (error); + case WSDISPLAYIO_LSFONT: + if (d->index < 0 || d->index >= WSDISPLAY_MAXFONT) + return (EINVAL); + *d = sc->sc_fonts[d->index]; + return (0); + + case WSDISPLAYIO_DELFONT: + return (EINVAL); +#undef d + #if NWSKBD > 0 #ifdef COMPAT_14 case _O_WSDISPLAYIO_SETKEYBOARD: diff --git a/sys/dev/wscons/wsdisplayvar.h b/sys/dev/wscons/wsdisplayvar.h index e9c08cf2430..b9b7d5e0225 100644 --- a/sys/dev/wscons/wsdisplayvar.h +++ b/sys/dev/wscons/wsdisplayvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsdisplayvar.h,v 1.7 2001/02/10 19:42:06 mickey Exp $ */ +/* $OpenBSD: wsdisplayvar.h,v 1.8 2001/03/14 02:49:22 mickey Exp $ */ /* $NetBSD: wsdisplayvar.h,v 1.14.4.1 2000/06/30 16:27:53 simonb Exp $ */ /* @@ -80,8 +80,10 @@ struct wsdisplay_emulops { /* XXX need a free_attr() ??? */ }; +#define WSSCREEN_NAME_SIZE 16 + struct wsscreen_descr { - char *name; + char name[WSSCREEN_NAME_SIZE]; int ncols, nrows; const struct wsdisplay_emulops *textops; int fontwidth, fontheight; diff --git a/sys/dev/wscons/wsemul_vt100_chars.c b/sys/dev/wscons/wsemul_vt100_chars.c index ec15af2d7fc..a26d2335151 100644 --- a/sys/dev/wscons/wsemul_vt100_chars.c +++ b/sys/dev/wscons/wsemul_vt100_chars.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemul_vt100_chars.c,v 1.2 2001/02/10 19:42:06 mickey Exp $ */ +/* $OpenBSD: wsemul_vt100_chars.c,v 1.3 2001/03/14 02:49:22 mickey Exp $ */ /* $NetBSD: wsemul_vt100_chars.c,v 1.4 1999/02/20 18:20:02 drochner Exp $ */ /* @@ -35,6 +35,7 @@ #include #include +#include #include #include #include diff --git a/sys/dev/wscons/wsemul_vt100_subr.c b/sys/dev/wscons/wsemul_vt100_subr.c index 1a0720df3ba..1cd76b97820 100644 --- a/sys/dev/wscons/wsemul_vt100_subr.c +++ b/sys/dev/wscons/wsemul_vt100_subr.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemul_vt100_subr.c,v 1.4 2001/03/07 17:55:43 aaron Exp $ */ +/* $OpenBSD: wsemul_vt100_subr.c,v 1.5 2001/03/14 02:49:23 mickey Exp $ */ /* $NetBSD: wsemul_vt100_subr.c,v 1.7 2000/04/28 21:56:16 mycroft Exp $ */ /* @@ -36,6 +36,7 @@ #include #include +#include #include #include #include diff --git a/sys/dev/wscons/wsemulconf.c b/sys/dev/wscons/wsemulconf.c index e745cd2873e..af99b61a66d 100644 --- a/sys/dev/wscons/wsemulconf.c +++ b/sys/dev/wscons/wsemulconf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemulconf.c,v 1.2 2001/02/13 14:50:34 deraadt Exp $ */ +/* $OpenBSD: wsemulconf.c,v 1.3 2001/03/14 02:49:23 mickey Exp $ */ /* $NetBSD: wsemulconf.c,v 1.4 2000/01/05 11:19:37 drochner Exp $ */ /* @@ -36,6 +36,7 @@ #include #include +#include #include #include #include /* pulls in opt_wsemul.h */ @@ -60,7 +61,7 @@ wsemul_pick(name) { const struct wsemul_ops **ops; - if (name == NULL) { + if (name == NULL || *name == '\0') { /* default */ #ifdef WSEMUL_DEFAULT name = WSEMUL_DEFAULT; @@ -70,7 +71,7 @@ wsemul_pick(name) } for (ops = &wsemul_conf[0]; *ops != NULL; ops++) - if (strcmp(name, (*ops)->name) == 0) + if (strncmp(name, (*ops)->name, WSEMUL_NAME_SIZE) == 0) break; return (*ops); diff --git a/sys/dev/wscons/wsemulvar.h b/sys/dev/wscons/wsemulvar.h index 255dae92d92..3a5cf858ac3 100644 --- a/sys/dev/wscons/wsemulvar.h +++ b/sys/dev/wscons/wsemulvar.h @@ -1,4 +1,4 @@ -/* $OpenBSD: wsemulvar.h,v 1.2 2001/02/13 14:50:34 deraadt Exp $ */ +/* $OpenBSD: wsemulvar.h,v 1.3 2001/03/14 02:49:23 mickey Exp $ */ /* $NetBSD: wsemulvar.h,v 1.6 1999/01/17 15:46:15 drochner Exp $ */ /* @@ -41,7 +41,7 @@ enum wsemul_resetops { }; struct wsemul_ops { - const char *name; + char name[WSEMUL_NAME_SIZE]; void *(*cnattach) __P((const struct wsscreen_descr *, void *, int, int, long)); -- cgit v1.2.3