mirror of
git://git.9front.org/plan9front/plan9front
synced 2025-01-12 11:10:06 +00:00
Compare commits
6 commits
5ea80693ba
...
5a460a150b
Author | SHA1 | Date | |
---|---|---|---|
|
5a460a150b | ||
|
ef5a8a7337 | ||
|
3273db5a84 | ||
|
9e0913fa71 | ||
|
a101561223 | ||
|
e981a26000 |
12 changed files with 168 additions and 64 deletions
|
@ -543,6 +543,7 @@ extern void setnetmtpt(char*, int, char*);
|
|||
extern int hangup(int);
|
||||
extern int listen(char*, char*);
|
||||
extern char* netmkaddr(char*, char*, char*);
|
||||
extern char* netmkaddrbuf(char*, char*, char*, char*, int);
|
||||
extern int reject(int, char*, char*);
|
||||
|
||||
/*
|
||||
|
|
|
@ -80,6 +80,7 @@ struct Memsubfont
|
|||
short n; /* number of chars in font */
|
||||
uchar height; /* height of bitmap */
|
||||
char ascent; /* top of bitmap to baseline */
|
||||
Rune min; /* rune offset for first glyph in subfont */
|
||||
Fontchar *info; /* n+1 character descriptors */
|
||||
Memimage *bits; /* of font */
|
||||
};
|
||||
|
@ -156,7 +157,7 @@ extern int memimageinit(void);
|
|||
* Subfont management
|
||||
*/
|
||||
extern Memsubfont* allocmemsubfont(char*, int, int, int, Fontchar*, Memimage*);
|
||||
extern Memsubfont* openmemsubfont(char*);
|
||||
extern Memsubfont* openmemsubfont(char*, Rune);
|
||||
extern void freememsubfont(Memsubfont*);
|
||||
extern Point memsubfontwidth(Memsubfont*, char*);
|
||||
extern Memsubfont* getmemdefont(void);
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
.TH DIAL 2
|
||||
.SH NAME
|
||||
dial, hangup, announce, listen, accept, reject, netmkaddr, setnetmtpt, getnetconninfo, freenetconninfo \- make and break network connections
|
||||
dial, hangup, announce, listen, accept, reject, netmkaddr, netmkaddrbuf, setnetmtpt, getnetconninfo, freenetconninfo \- make and break network connections
|
||||
.SH SYNOPSIS
|
||||
.B #include <u.h>
|
||||
.br
|
||||
|
@ -25,7 +25,12 @@ int accept(int ctl, char *dir)
|
|||
int reject(int ctl, char *dir, char *cause)
|
||||
.PP
|
||||
.B
|
||||
char* netmkaddr(char *addr, char *defnet, char *defservice)
|
||||
char* netmkaddr(char *addr, char *defnet, char *defsrv)
|
||||
.PP
|
||||
.B
|
||||
char* netmkaddrbuf(char *addr, char *defnet, char *defsrv,
|
||||
.br
|
||||
char *buf, int len)
|
||||
.PP
|
||||
.B
|
||||
void setnetmtpt(char *to, int tolen, char *from)
|
||||
|
@ -171,10 +176,19 @@ returns a file descriptor for the data file opened
|
|||
.BR ORDWR .
|
||||
.PP
|
||||
.I Netmkaddr
|
||||
makes an address suitable for dialing or announcing.
|
||||
It takes an address along with a default network and service to use
|
||||
and
|
||||
.I netmkaddrbuf
|
||||
make an address suitable for dialing or announcing.
|
||||
They take an address along with a default network and service to use
|
||||
if they are not specified in the address.
|
||||
It returns a pointer to static data holding the actual address to use.
|
||||
.I Netmkaddrbuf
|
||||
stores the resulting dialstring in
|
||||
.I buf
|
||||
up to a maximum length of
|
||||
.I len
|
||||
and returns a pointer to it.
|
||||
.I Netmkaddr
|
||||
returns a pointer to a static buffer.
|
||||
.PP
|
||||
.I Getnetconninfo
|
||||
returns a structure containing information about a
|
||||
|
|
|
@ -150,7 +150,7 @@ int memlineendsize(int end)
|
|||
.nf
|
||||
Memsubfont* allocmemsubfont(char *name, int n, int height,
|
||||
int ascent, Fontchar *info, Memimage *i)
|
||||
Memsubfont* openmemsubfont(char *name)
|
||||
Memsubfont* openmemsubfont(char *name, Rune min)
|
||||
void freememsubfont(Memsubfont *f)
|
||||
Point memsubfontwidth(Memsubfont *f, char *s)
|
||||
Memsubfont* getmemdefont(void)
|
||||
|
|
|
@ -75,6 +75,7 @@ netndbauthaddr(void)
|
|||
int
|
||||
_authdial(char *authdom)
|
||||
{
|
||||
char addr[256];
|
||||
int i, fd;
|
||||
|
||||
alarm(30*1000);
|
||||
|
@ -97,9 +98,11 @@ _authdial(char *authdom)
|
|||
if(authaddr[0] == nil)
|
||||
netndbauthaddr();
|
||||
for(i = 0; fd < 0 && authaddr[i] != nil; i++){
|
||||
fd = dial(netmkaddr(authaddr[i], "tcp", "567"), 0, 0, 0);
|
||||
fd = dial(netmkaddrbuf(authaddr[i], "tcp", "567", addr, sizeof(addr)),
|
||||
nil, nil, nil);
|
||||
if(fd < 0)
|
||||
fd = dial(netmkaddr(authaddr[i], "il", "566"), 0, 0, 0);
|
||||
fd = dial(netmkaddrbuf(authaddr[i], "il", "566", addr, sizeof(addr)),
|
||||
nil, nil, nil);
|
||||
}
|
||||
}
|
||||
alarm(0);
|
||||
|
|
|
@ -43,6 +43,7 @@ x ...\n device control functions:
|
|||
#include <u.h>
|
||||
#include <libc.h>
|
||||
#include <draw.h>
|
||||
#include <memdraw.h>
|
||||
#include <bio.h>
|
||||
|
||||
#define hmot(n) hpos += n
|
||||
|
@ -57,12 +58,14 @@ int vpos; /* current vertical position (down positive) */
|
|||
char *fontfile = "/lib/font/bit/pelm/unicode.9x24.font";
|
||||
|
||||
char *pschar(char *, char *hex, int *wid, int *ht);
|
||||
void memopenfont(char *);
|
||||
int kanji(char *);
|
||||
void Bgetstr(Biobuf *bp, char *s);
|
||||
void Bgetline(Biobuf *bp, char *s);
|
||||
void Bgetint(Biobuf *bp, int *n);
|
||||
|
||||
Biobuf bin, bout;
|
||||
Memimage *white;
|
||||
|
||||
void
|
||||
main(void)
|
||||
|
@ -71,12 +74,15 @@ main(void)
|
|||
char str[100], *args[10];
|
||||
int jfont, curfont;
|
||||
|
||||
if(initdraw(0, fontfile, 0) < 0){
|
||||
fprint(2, "mnihongo: can't initialize display: %r\n");
|
||||
exits("open");
|
||||
}
|
||||
Binit(&bin, 0, OREAD);
|
||||
Binit(&bout, 1, OWRITE);
|
||||
memimageinit();
|
||||
white = allocmemimage(Rect(0, 0, 1, 1), GREY1);
|
||||
if(white == nil)
|
||||
sysfatal("allocmemimage: %r");
|
||||
memfillcolor(white, DWhite);
|
||||
white->flags |= Frepl;
|
||||
memopenfont(fontfile);
|
||||
|
||||
jfont = -1;
|
||||
curfont = 1;
|
||||
|
@ -177,7 +183,68 @@ main(void)
|
|||
}
|
||||
}
|
||||
|
||||
int kanji(char *s) /* very special pleading */
|
||||
struct {
|
||||
int s, e;
|
||||
char *path;
|
||||
Memsubfont *f;
|
||||
} fonts[128];
|
||||
static int nfonts;
|
||||
|
||||
void
|
||||
memopenfont(char *name)
|
||||
{
|
||||
Biobuf *b;
|
||||
int i;
|
||||
char *s, *p, *p2;
|
||||
|
||||
b = Bopen(name, OREAD);
|
||||
for(i = 0; s = Brdline(b, '\n'); i++){
|
||||
if(i == 0)
|
||||
continue;
|
||||
s[Blinelen(b)-1] = '\0';
|
||||
fonts[i].s = strtol(s, &p, 0);
|
||||
if(s == p || *p == '\0')
|
||||
goto Invalid;
|
||||
p++;
|
||||
fonts[i].e = strtol(p, &p2, 0);
|
||||
if(p == p2 || *p2 == '\0')
|
||||
goto Invalid;
|
||||
p = p2 + 1;
|
||||
if(*p == '/')
|
||||
fonts[i].path = strdup(p);
|
||||
else {
|
||||
fonts[i].path = smprint("/lib/font/bit/pelm/%s", p);
|
||||
cleanname(fonts[i].path);
|
||||
}
|
||||
}
|
||||
nfonts = i;
|
||||
if(nfonts == 0){
|
||||
Invalid:
|
||||
sysfatal("%s is an invalid font file", name);
|
||||
}
|
||||
Bterm(b);
|
||||
}
|
||||
|
||||
Memsubfont*
|
||||
memgetfont(Rune r)
|
||||
{
|
||||
int i;
|
||||
|
||||
for(i = 0; i < nfonts; i++){
|
||||
if(r >= fonts[i].s && r < fonts[i].e){
|
||||
if(fonts[i].f == nil){
|
||||
fonts[i].f = openmemsubfont(fonts[i].path, fonts[i].s);
|
||||
if(fonts[i].f == nil)
|
||||
sysfatal("failed to open subfont: %r");
|
||||
}
|
||||
return fonts[i].f;
|
||||
}
|
||||
}
|
||||
return nil;
|
||||
}
|
||||
|
||||
int
|
||||
kanji(char *s) /* very special pleading */
|
||||
{ /* dump as kanji char if looks like one */
|
||||
Rune r;
|
||||
char hex[500];
|
||||
|
@ -194,37 +261,47 @@ int kanji(char *s) /* very special pleading */
|
|||
return 1;
|
||||
}
|
||||
|
||||
char *pschar(char *s, char *hex, int *wid, int *ht)
|
||||
char*
|
||||
pschar(char *s, char *hex, int *wid, int *ht)
|
||||
{
|
||||
Point chpt, spt;
|
||||
Image *b;
|
||||
Memimage *b;
|
||||
Memsubfont *f;
|
||||
uchar rowdata[100];
|
||||
char *hp = hex;
|
||||
int y, i;
|
||||
Rune r;
|
||||
|
||||
chpt = stringsize(font, s); /* bounding box of char */
|
||||
chartorune(&r, s);
|
||||
f = memgetfont(r);
|
||||
chpt = memsubfontwidth(f, s); /* bounding box of char */
|
||||
*wid = ((chpt.x+7) / 8) * 8;
|
||||
*ht = chpt.y;
|
||||
/* postscript is backwards to video, so draw white (ones) on black (zeros) */
|
||||
b = allocimage(display, Rpt(ZP, chpt), GREY1, 0, DBlack); /* place to put it */
|
||||
spt = string(b, Pt(0,0), display->white, ZP, font, s); /* put it there */
|
||||
white->clipr = Rpt(ZP, chpt);
|
||||
b = allocmemimage(white->clipr, GREY1);
|
||||
if(b == nil)
|
||||
sysfatal("allocmemimage: %r");
|
||||
memfillcolor(b, DBlack);
|
||||
spt = memimagestring(b, Pt(0,0), white, ZP, f, s); /* put it there */
|
||||
/* Bprint(&bout, "chpt %P, spt %P, wid,ht %d,%d\n", chpt, spt, *wid, *ht);
|
||||
/* Bflush(&bout); */
|
||||
for (y = 0; y < chpt.y; y++) { /* read bits a row at a time */
|
||||
memset(rowdata, 0, sizeof rowdata);
|
||||
unloadimage(b, Rect(0, y, chpt.x, y+1), rowdata, sizeof rowdata);
|
||||
unloadmemimage(b, Rect(0, y, chpt.x, y+1), rowdata, sizeof rowdata);
|
||||
for (i = 0; i < spt.x; i += 8) { /* 8 == byte */
|
||||
sprint(hp, "%2.2x", rowdata[i/8]);
|
||||
hp += 2;
|
||||
}
|
||||
}
|
||||
*hp = 0;
|
||||
freeimage(b);
|
||||
freememimage(b);
|
||||
return hex;
|
||||
}
|
||||
|
||||
|
||||
void Bgetstr(Biobuf *bp, char *s) /* get a string */
|
||||
void
|
||||
Bgetstr(Biobuf *bp, char *s) /* get a string */
|
||||
{
|
||||
int c;
|
||||
|
||||
|
@ -238,7 +315,8 @@ void Bgetstr(Biobuf *bp, char *s) /* get a string */
|
|||
*s = 0;
|
||||
}
|
||||
|
||||
void Bgetline(Biobuf *bp, char *s) /* get a line, including newline */
|
||||
void
|
||||
Bgetline(Biobuf *bp, char *s) /* get a line, including newline */
|
||||
{
|
||||
int c;
|
||||
|
||||
|
@ -250,7 +328,8 @@ void Bgetline(Biobuf *bp, char *s) /* get a line, including newline */
|
|||
*s = 0;
|
||||
}
|
||||
|
||||
void Bgetint(Biobuf *bp, int *n) /* get an integer */
|
||||
void
|
||||
Bgetint(Biobuf *bp, int *n) /* get an integer */
|
||||
{
|
||||
double d;
|
||||
|
||||
|
|
|
@ -252,11 +252,10 @@ lan78xxreceive(Dev *ep)
|
|||
break;
|
||||
if((hd & Rxerror) == 0){
|
||||
if(n == BLEN(b)){
|
||||
b->wp -= 4;
|
||||
etheriq(b);
|
||||
return 0;
|
||||
}
|
||||
etheriq(copyblock(b, n - 4));
|
||||
etheriq(copyblock(b, n));
|
||||
}
|
||||
b->rp = (uchar*)(((uintptr)b->rp + n + 3)&~3);
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ ginit(void)
|
|||
#ifdef PLAN9PORT
|
||||
smallfont = openmemsubfont(unsharp("#9/font/lucsans/lstr.10"));
|
||||
#else
|
||||
smallfont = openmemsubfont("/lib/font/bit/lucidasans/lstr.10");
|
||||
smallfont = openmemsubfont("/lib/font/bit/lucidasans/lstr.10", 0);
|
||||
#endif
|
||||
black = memblack;
|
||||
blue = allocrepl(DBlue);
|
||||
|
|
|
@ -7,13 +7,15 @@
|
|||
int
|
||||
authdial(char *netroot, char *dom)
|
||||
{
|
||||
char addr[256];
|
||||
Ndbtuple *t, *nt;
|
||||
char *p;
|
||||
int rv;
|
||||
|
||||
if(dom == nil)
|
||||
/* look for one relative to my machine */
|
||||
return dial(netmkaddr("$auth", nil, "ticket"), nil, nil, nil);
|
||||
return dial(netmkaddrbuf("$auth", nil, "ticket", addr, sizeof(addr)),
|
||||
nil, nil, nil);
|
||||
|
||||
/* look up an auth server in an authentication domain */
|
||||
p = csgetvalue(netroot, "authdom", dom, "auth", &t);
|
||||
|
@ -41,7 +43,8 @@ authdial(char *netroot, char *dom)
|
|||
rv = -1;
|
||||
for(nt = t; nt != nil; nt = nt->entry) {
|
||||
if(strcmp(nt->attr, "auth") == 0) {
|
||||
rv = dial(netmkaddr(nt->val, nil, "ticket"), nil, nil, nil);
|
||||
rv = dial(netmkaddrbuf(nt->val, nil, "ticket", addr, sizeof(addr)),
|
||||
nil, nil, nil);
|
||||
if(rv >= 0)
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -6,47 +6,48 @@
|
|||
* make an address, add the defaults
|
||||
*/
|
||||
char *
|
||||
netmkaddr(char *linear, char *defnet, char *defsrv)
|
||||
netmkaddrbuf(char *addr, char *defnet, char *defsrv, char *buf, int len)
|
||||
{
|
||||
static char addr[256];
|
||||
char *cp;
|
||||
|
||||
cp = strchr(addr, '!');
|
||||
if(cp == nil){
|
||||
/*
|
||||
* dump network name
|
||||
*/
|
||||
cp = strchr(linear, '!');
|
||||
if(cp == 0){
|
||||
if(defnet==0){
|
||||
if(defsrv)
|
||||
snprint(addr, sizeof(addr), "net!%s!%s",
|
||||
linear, defsrv);
|
||||
if(defnet == nil){
|
||||
if(defsrv != nil)
|
||||
snprint(buf, len, "net!%s!%s", addr, defsrv);
|
||||
else
|
||||
snprint(addr, sizeof(addr), "net!%s", linear);
|
||||
snprint(buf, len, "net!%s", addr);
|
||||
}
|
||||
else {
|
||||
if(defsrv)
|
||||
snprint(addr, sizeof(addr), "%s!%s!%s", defnet,
|
||||
linear, defsrv);
|
||||
if(defsrv != nil)
|
||||
snprint(buf, len, "%s!%s!%s", defnet, addr, defsrv);
|
||||
else
|
||||
snprint(addr, sizeof(addr), "%s!%s", defnet,
|
||||
linear);
|
||||
snprint(buf, len, "%s!%s", defnet, addr);
|
||||
}
|
||||
return addr;
|
||||
}
|
||||
|
||||
/*
|
||||
* if there is already a service, use it
|
||||
*/
|
||||
} else {
|
||||
cp = strchr(cp+1, '!');
|
||||
if(cp)
|
||||
return linear;
|
||||
|
||||
if(cp != nil || defsrv == nil){
|
||||
/*
|
||||
* if there is already a service or no defsrv given
|
||||
*/
|
||||
snprint(buf, len, "%s", addr);
|
||||
} else {
|
||||
/*
|
||||
* add default service
|
||||
*/
|
||||
if(defsrv == 0)
|
||||
return linear;
|
||||
snprint(addr, sizeof(addr), "%s!%s", linear, defsrv);
|
||||
|
||||
return addr;
|
||||
snprint(buf, len,"%s!%s", addr, defsrv);
|
||||
}
|
||||
}
|
||||
return buf;
|
||||
}
|
||||
|
||||
char *
|
||||
netmkaddr(char *addr, char *defnet, char *defsrv)
|
||||
{
|
||||
static char buf[256];
|
||||
|
||||
return netmkaddrbuf(addr, defnet, defsrv, buf, sizeof(buf));
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include <memdraw.h>
|
||||
|
||||
Memsubfont*
|
||||
openmemsubfont(char *name)
|
||||
openmemsubfont(char *name, Rune min)
|
||||
{
|
||||
Memsubfont *sf;
|
||||
Memimage *i;
|
||||
|
@ -45,6 +45,7 @@ openmemsubfont(char *name)
|
|||
free(fc);
|
||||
goto Err;
|
||||
}
|
||||
sf->min = min;
|
||||
close(fd);
|
||||
free(p);
|
||||
return sf;
|
||||
|
|
|
@ -25,6 +25,7 @@ memimagestring(Memimage *b, Point p, Memimage *color, Point cp, Memsubfont *f, c
|
|||
}
|
||||
s += w;
|
||||
}
|
||||
c -= f->min;
|
||||
if(c >= f->n)
|
||||
continue;
|
||||
i = f->info+c;
|
||||
|
@ -58,6 +59,7 @@ memsubfontwidth(Memsubfont *f, char *cs)
|
|||
}
|
||||
s += w;
|
||||
}
|
||||
c -= f->min;
|
||||
if(c >= f->n)
|
||||
continue;
|
||||
i = f->info+c;
|
||||
|
|
Loading…
Reference in a new issue