a
This commit is contained in:
BIN
include/a.out
Normal file
BIN
include/a.out
Normal file
Binary file not shown.
144
include/auth.h
Normal file
144
include/auth.h
Normal file
@ -0,0 +1,144 @@
|
||||
#pragma src "/sys/src/libauth"
|
||||
#pragma lib "libauth.a"
|
||||
|
||||
/*
|
||||
* Interface for typical callers.
|
||||
*/
|
||||
|
||||
typedef struct AuthInfo AuthInfo;
|
||||
typedef struct Chalstate Chalstate;
|
||||
typedef struct Chapreply Chapreply;
|
||||
typedef struct MSchapreply MSchapreply;
|
||||
typedef struct UserPasswd UserPasswd;
|
||||
typedef struct AuthRpc AuthRpc;
|
||||
|
||||
enum
|
||||
{
|
||||
MAXCHLEN= 256, /* max challenge length */
|
||||
MAXNAMELEN= 256, /* maximum name length */
|
||||
MD5LEN= 16,
|
||||
|
||||
ARok = 0, /* rpc return values */
|
||||
ARdone,
|
||||
ARerror,
|
||||
ARneedkey,
|
||||
ARbadkey,
|
||||
ARwritenext,
|
||||
ARtoosmall,
|
||||
ARtoobig,
|
||||
ARrpcfailure,
|
||||
ARphase,
|
||||
|
||||
AuthRpcMax = 4096,
|
||||
};
|
||||
|
||||
struct AuthRpc
|
||||
{
|
||||
int afd;
|
||||
char ibuf[AuthRpcMax];
|
||||
char obuf[AuthRpcMax];
|
||||
char *arg;
|
||||
uint narg;
|
||||
};
|
||||
|
||||
struct AuthInfo
|
||||
{
|
||||
char *cuid; /* caller id */
|
||||
char *suid; /* server id */
|
||||
char *cap; /* capability (only valid on server side) */
|
||||
int nsecret; /* length of secret */
|
||||
uchar *secret; /* secret */
|
||||
};
|
||||
|
||||
struct Chalstate
|
||||
{
|
||||
char *user;
|
||||
char chal[MAXCHLEN];
|
||||
int nchal;
|
||||
void *resp;
|
||||
int nresp;
|
||||
|
||||
/* for implementation only */
|
||||
int afd; /* to factotum */
|
||||
AuthRpc *rpc; /* to factotum */
|
||||
char userbuf[MAXNAMELEN]; /* temp space if needed */
|
||||
int userinchal; /* user was sent to obtain challenge */
|
||||
};
|
||||
|
||||
struct Chapreply /* for protocol "chap" */
|
||||
{
|
||||
uchar id;
|
||||
char resp[MD5LEN];
|
||||
};
|
||||
|
||||
struct MSchapreply /* for protocol "mschap" */
|
||||
{
|
||||
char LMresp[24]; /* Lan Manager response */
|
||||
char NTresp[24]; /* NT response */
|
||||
};
|
||||
|
||||
struct UserPasswd
|
||||
{
|
||||
char *user;
|
||||
char *passwd;
|
||||
};
|
||||
|
||||
extern int newns(char*, char*);
|
||||
extern int addns(char*, char*);
|
||||
|
||||
extern int noworld(char*);
|
||||
extern int amount(int, char*, int, char*);
|
||||
|
||||
/* these two may get generalized away -rsc */
|
||||
extern int login(char*, char*, char*);
|
||||
extern int httpauth(char*, char*);
|
||||
|
||||
typedef struct Attr Attr;
|
||||
typedef struct String String;
|
||||
enum {
|
||||
AttrNameval, /* name=val -- when matching, must have name=val */
|
||||
AttrQuery, /* name? -- when matching, must be present */
|
||||
AttrDefault, /* name:=val -- when matching, if present must match INTERNAL */
|
||||
};
|
||||
struct Attr
|
||||
{
|
||||
int type;
|
||||
Attr *next;
|
||||
char *name;
|
||||
char *val;
|
||||
};
|
||||
|
||||
typedef int AuthGetkey(char*);
|
||||
|
||||
int _attrfmt(Fmt*);
|
||||
Attr *_copyattr(Attr*);
|
||||
Attr *_delattr(Attr*, char*);
|
||||
Attr *_findattr(Attr*, char*);
|
||||
void _freeattr(Attr*);
|
||||
Attr *_mkattr(int, char*, char*, Attr*);
|
||||
Attr *_parseattr(char*);
|
||||
char *_strfindattr(Attr*, char*);
|
||||
#pragma varargck type "A" Attr*
|
||||
|
||||
extern AuthInfo* fauth_proxy(int, AuthRpc *rpc, AuthGetkey *getkey, char *params);
|
||||
extern AuthInfo* auth_proxy(int fd, AuthGetkey *getkey, char *fmt, ...);
|
||||
extern int auth_getkey(char*);
|
||||
extern int (*amount_getkey)(char*);
|
||||
extern void auth_freeAI(AuthInfo *ai);
|
||||
extern int auth_chuid(AuthInfo *ai, char *ns);
|
||||
extern Chalstate *auth_challenge(char*, ...);
|
||||
extern AuthInfo* auth_response(Chalstate*);
|
||||
extern int auth_respond(void*, uint, char*, uint, void*, uint, AuthGetkey *getkey, char*, ...);
|
||||
extern void auth_freechal(Chalstate*);
|
||||
extern AuthInfo* auth_userpasswd(char *user, char *passwd);
|
||||
extern UserPasswd* auth_getuserpasswd(AuthGetkey *getkey, char*, ...);
|
||||
extern AuthInfo* auth_getinfo(AuthRpc *rpc);
|
||||
extern AuthRpc* auth_allocrpc(int afd);
|
||||
extern Attr* auth_attr(AuthRpc *rpc);
|
||||
extern void auth_freerpc(AuthRpc *rpc);
|
||||
extern uint auth_rpc(AuthRpc *rpc, char *verb, void *a, int n);
|
||||
extern int auth_wep(char*, char*, ...);
|
||||
#pragma varargck argpos auth_proxy 3
|
||||
#pragma varargck argpos auth_challenge 1
|
||||
#pragma varargck argpos auth_respond 3
|
||||
#pragma varargck argpos auth_getuserpasswd 2
|
166
include/authsrv.h
Normal file
166
include/authsrv.h
Normal file
@ -0,0 +1,166 @@
|
||||
#pragma src "/sys/src/libauthsrv"
|
||||
#pragma lib "libauthsrv.a"
|
||||
|
||||
/*
|
||||
* Interface for talking to authentication server.
|
||||
*/
|
||||
typedef struct Ticket Ticket;
|
||||
typedef struct Ticketreq Ticketreq;
|
||||
typedef struct Authenticator Authenticator;
|
||||
typedef struct Nvrsafe Nvrsafe;
|
||||
typedef struct Passwordreq Passwordreq;
|
||||
typedef struct OChapreply OChapreply;
|
||||
typedef struct OMSchapreply OMSchapreply;
|
||||
|
||||
enum
|
||||
{
|
||||
ANAMELEN= 28, /* maximum size of name in previous proto */
|
||||
AERRLEN= 64, /* maximum size of errstr in previous proto */
|
||||
DOMLEN= 48, /* length of an authentication domain name */
|
||||
DESKEYLEN= 7, /* length of a des key for encrypt/decrypt */
|
||||
CHALLEN= 8, /* length of a plan9 sk1 challenge */
|
||||
NETCHLEN= 16, /* max network challenge length (used in AS protocol) */
|
||||
CONFIGLEN= 14,
|
||||
SECRETLEN= 32, /* max length of a secret */
|
||||
|
||||
KEYDBOFF= 8, /* length of random data at the start of key file */
|
||||
OKEYDBLEN= ANAMELEN+DESKEYLEN+4+2, /* length of an entry in old key file */
|
||||
KEYDBLEN= OKEYDBLEN+SECRETLEN, /* length of an entry in key file */
|
||||
OMD5LEN= 16,
|
||||
};
|
||||
|
||||
/* encryption numberings (anti-replay) */
|
||||
enum
|
||||
{
|
||||
AuthTreq=1, /* ticket request */
|
||||
AuthChal=2, /* challenge box request */
|
||||
AuthPass=3, /* change password */
|
||||
AuthOK=4, /* fixed length reply follows */
|
||||
AuthErr=5, /* error follows */
|
||||
AuthMod=6, /* modify user */
|
||||
AuthApop=7, /* apop authentication for pop3 */
|
||||
AuthOKvar=9, /* variable length reply follows */
|
||||
AuthChap=10, /* chap authentication for ppp */
|
||||
AuthMSchap=11, /* MS chap authentication for ppp */
|
||||
AuthCram=12, /* CRAM verification for IMAP (RFC2195 & rfc2104) */
|
||||
AuthHttp=13, /* http domain login */
|
||||
AuthVNC=14, /* VNC server login (deprecated) */
|
||||
|
||||
|
||||
AuthTs=64, /* ticket encrypted with server's key */
|
||||
AuthTc, /* ticket encrypted with client's key */
|
||||
AuthAs, /* server generated authenticator */
|
||||
AuthAc, /* client generated authenticator */
|
||||
AuthTp, /* ticket encrypted with client's key for password change */
|
||||
AuthHr, /* http reply */
|
||||
};
|
||||
|
||||
struct Ticketreq
|
||||
{
|
||||
char type;
|
||||
char authid[ANAMELEN]; /* server's encryption id */
|
||||
char authdom[DOMLEN]; /* server's authentication domain */
|
||||
char chal[CHALLEN]; /* challenge from server */
|
||||
char hostid[ANAMELEN]; /* host's encryption id */
|
||||
char uid[ANAMELEN]; /* uid of requesting user on host */
|
||||
};
|
||||
#define TICKREQLEN (3*ANAMELEN+CHALLEN+DOMLEN+1)
|
||||
|
||||
struct Ticket
|
||||
{
|
||||
char num; /* replay protection */
|
||||
char chal[CHALLEN]; /* server challenge */
|
||||
char cuid[ANAMELEN]; /* uid on client */
|
||||
char suid[ANAMELEN]; /* uid on server */
|
||||
char key[DESKEYLEN]; /* nonce DES key */
|
||||
};
|
||||
#define TICKETLEN (CHALLEN+2*ANAMELEN+DESKEYLEN+1)
|
||||
|
||||
struct Authenticator
|
||||
{
|
||||
char num; /* replay protection */
|
||||
char chal[CHALLEN];
|
||||
ulong id; /* authenticator id, ++'d with each auth */
|
||||
};
|
||||
#define AUTHENTLEN (CHALLEN+4+1)
|
||||
|
||||
struct Passwordreq
|
||||
{
|
||||
char num;
|
||||
char old[ANAMELEN];
|
||||
char new[ANAMELEN];
|
||||
char changesecret;
|
||||
char secret[SECRETLEN]; /* new secret */
|
||||
};
|
||||
#define PASSREQLEN (2*ANAMELEN+1+1+SECRETLEN)
|
||||
|
||||
struct OChapreply
|
||||
{
|
||||
uchar id;
|
||||
char uid[ANAMELEN];
|
||||
char resp[OMD5LEN];
|
||||
};
|
||||
|
||||
struct OMSchapreply
|
||||
{
|
||||
char uid[ANAMELEN];
|
||||
char LMresp[24]; /* Lan Manager response */
|
||||
char NTresp[24]; /* NT response */
|
||||
};
|
||||
|
||||
/*
|
||||
* convert to/from wire format
|
||||
*/
|
||||
extern int convT2M(Ticket*, char*, char*);
|
||||
extern void convM2T(char*, Ticket*, char*);
|
||||
extern void convM2Tnoenc(char*, Ticket*);
|
||||
extern int convA2M(Authenticator*, char*, char*);
|
||||
extern void convM2A(char*, Authenticator*, char*);
|
||||
extern int convTR2M(Ticketreq*, char*);
|
||||
extern void convM2TR(char*, Ticketreq*);
|
||||
extern int convPR2M(Passwordreq*, char*, char*);
|
||||
extern void convM2PR(char*, Passwordreq*, char*);
|
||||
|
||||
/*
|
||||
* convert ascii password to DES key
|
||||
*/
|
||||
extern int opasstokey(char*, char*);
|
||||
extern int passtokey(char*, char*);
|
||||
|
||||
/*
|
||||
* Nvram interface
|
||||
*/
|
||||
enum {
|
||||
NVwrite = 1<<0, /* always prompt and rewrite nvram */
|
||||
NVwriteonerr = 1<<1, /* prompt and rewrite nvram when corrupt */
|
||||
};
|
||||
|
||||
struct Nvrsafe
|
||||
{
|
||||
char machkey[DESKEYLEN];
|
||||
uchar machsum;
|
||||
char authkey[DESKEYLEN];
|
||||
uchar authsum;
|
||||
char config[CONFIGLEN];
|
||||
uchar configsum;
|
||||
char authid[ANAMELEN];
|
||||
uchar authidsum;
|
||||
char authdom[DOMLEN];
|
||||
uchar authdomsum;
|
||||
};
|
||||
|
||||
extern uchar nvcsum(void*, int);
|
||||
extern int readnvram(Nvrsafe*, int);
|
||||
|
||||
/*
|
||||
* call up auth server
|
||||
*/
|
||||
extern int authdial(char *netroot, char *authdom);
|
||||
|
||||
/*
|
||||
* exchange messages with auth server
|
||||
*/
|
||||
extern int _asgetticket(int, char*, char*);
|
||||
extern int _asrdresp(int, char*, int);
|
||||
extern int sslnegotiate(int, Ticket*, char**, char**);
|
||||
extern int srvsslnegotiate(int, Ticket*, char**, char**);
|
6
include/cursor.h
Normal file
6
include/cursor.h
Normal file
@ -0,0 +1,6 @@
|
||||
struct Cursor
|
||||
{
|
||||
Point offset;
|
||||
uchar clr[2*16];
|
||||
uchar set[2*16];
|
||||
};
|
519
include/draw.h
Normal file
519
include/draw.h
Normal file
@ -0,0 +1,519 @@
|
||||
#pragma src "/sys/src/libdraw"
|
||||
#pragma lib "libdraw.a"
|
||||
|
||||
typedef struct Cachefont Cachefont;
|
||||
typedef struct Cacheinfo Cacheinfo;
|
||||
typedef struct Cachesubf Cachesubf;
|
||||
typedef struct Display Display;
|
||||
typedef struct Font Font;
|
||||
typedef struct Fontchar Fontchar;
|
||||
typedef struct Image Image;
|
||||
typedef struct Mouse Mouse;
|
||||
typedef struct Point Point;
|
||||
typedef struct Rectangle Rectangle;
|
||||
typedef struct RGB RGB;
|
||||
typedef struct Screen Screen;
|
||||
typedef struct Subfont Subfont;
|
||||
|
||||
#pragma varargck type "R" Rectangle
|
||||
#pragma varargck type "P" Point
|
||||
extern int Rfmt(Fmt*);
|
||||
extern int Pfmt(Fmt*);
|
||||
|
||||
enum
|
||||
{
|
||||
DOpaque = 0xFFFFFFFF,
|
||||
DTransparent = 0x00000000, /* only useful for allocimage, memfillcolor */
|
||||
DBlack = 0x000000FF,
|
||||
DWhite = 0xFFFFFFFF,
|
||||
DRed = 0xFF0000FF,
|
||||
DGreen = 0x00FF00FF,
|
||||
DBlue = 0x0000FFFF,
|
||||
DCyan = 0x00FFFFFF,
|
||||
DMagenta = 0xFF00FFFF,
|
||||
DYellow = 0xFFFF00FF,
|
||||
DPaleyellow = 0xFFFFAAFF,
|
||||
DDarkyellow = 0xEEEE9EFF,
|
||||
DDarkgreen = 0x448844FF,
|
||||
DPalegreen = 0xAAFFAAFF,
|
||||
DMedgreen = 0x88CC88FF,
|
||||
DDarkblue = 0x000055FF,
|
||||
DPalebluegreen= 0xAAFFFFFF,
|
||||
DPaleblue = 0x0000BBFF,
|
||||
DBluegreen = 0x008888FF,
|
||||
DGreygreen = 0x55AAAAFF,
|
||||
DPalegreygreen = 0x9EEEEEFF,
|
||||
DYellowgreen = 0x99994CFF,
|
||||
DMedblue = 0x000099FF,
|
||||
DGreyblue = 0x005DBBFF,
|
||||
DPalegreyblue = 0x4993DDFF,
|
||||
DPurpleblue = 0x8888CCFF,
|
||||
|
||||
DNotacolor = 0xFFFFFF00,
|
||||
DNofill = DNotacolor,
|
||||
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
Displaybufsize = 8000,
|
||||
ICOSSCALE = 1024,
|
||||
Borderwidth = 4,
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/* refresh methods */
|
||||
Refbackup = 0,
|
||||
Refnone = 1,
|
||||
Refmesg = 2
|
||||
};
|
||||
#define NOREFRESH ((void*)-1)
|
||||
|
||||
enum
|
||||
{
|
||||
/* line ends */
|
||||
Endsquare = 0,
|
||||
Enddisc = 1,
|
||||
Endarrow = 2,
|
||||
Endmask = 0x1F
|
||||
};
|
||||
|
||||
#define ARROW(a, b, c) (Endarrow|((a)<<5)|((b)<<14)|((c)<<23))
|
||||
|
||||
typedef enum
|
||||
{
|
||||
/* Porter-Duff compositing operators */
|
||||
Clear = 0,
|
||||
|
||||
SinD = 8,
|
||||
DinS = 4,
|
||||
SoutD = 2,
|
||||
DoutS = 1,
|
||||
|
||||
S = SinD|SoutD,
|
||||
SoverD = SinD|SoutD|DoutS,
|
||||
SatopD = SinD|DoutS,
|
||||
SxorD = SoutD|DoutS,
|
||||
|
||||
D = DinS|DoutS,
|
||||
DoverS = DinS|DoutS|SoutD,
|
||||
DatopS = DinS|SoutD,
|
||||
DxorS = DoutS|SoutD, /* == SxorD */
|
||||
|
||||
Ncomp = 12,
|
||||
} Drawop;
|
||||
|
||||
/*
|
||||
* image channel descriptors
|
||||
*/
|
||||
enum {
|
||||
CRed = 0,
|
||||
CGreen,
|
||||
CBlue,
|
||||
CGrey,
|
||||
CAlpha,
|
||||
CMap,
|
||||
CIgnore,
|
||||
NChan,
|
||||
};
|
||||
|
||||
#define __DC(type, nbits) ((((type)&15)<<4)|((nbits)&15))
|
||||
#define CHAN1(a,b) __DC(a,b)
|
||||
#define CHAN2(a,b,c,d) (CHAN1((a),(b))<<8|__DC((c),(d)))
|
||||
#define CHAN3(a,b,c,d,e,f) (CHAN2((a),(b),(c),(d))<<8|__DC((e),(f)))
|
||||
#define CHAN4(a,b,c,d,e,f,g,h) (CHAN3((a),(b),(c),(d),(e),(f))<<8|__DC((g),(h)))
|
||||
|
||||
#define NBITS(c) ((c)&15)
|
||||
#define TYPE(c) (((c)>>4)&15)
|
||||
|
||||
enum {
|
||||
GREY1 = CHAN1(CGrey, 1),
|
||||
GREY2 = CHAN1(CGrey, 2),
|
||||
GREY4 = CHAN1(CGrey, 4),
|
||||
GREY8 = CHAN1(CGrey, 8),
|
||||
CMAP8 = CHAN1(CMap, 8),
|
||||
RGB15 = CHAN4(CIgnore, 1, CRed, 5, CGreen, 5, CBlue, 5),
|
||||
RGB16 = CHAN3(CRed, 5, CGreen, 6, CBlue, 5),
|
||||
RGB24 = CHAN3(CRed, 8, CGreen, 8, CBlue, 8),
|
||||
BGR24 = CHAN3(CBlue, 8, CGreen, 8, CRed, 8),
|
||||
RGBA32 = CHAN4(CRed, 8, CGreen, 8, CBlue, 8, CAlpha, 8),
|
||||
ARGB32 = CHAN4(CAlpha, 8, CRed, 8, CGreen, 8, CBlue, 8), /* stupid VGAs */
|
||||
XRGB32 = CHAN4(CIgnore, 8, CRed, 8, CGreen, 8, CBlue, 8),
|
||||
XBGR32 = CHAN4(CIgnore, 8, CBlue, 8, CGreen, 8, CRed, 8),
|
||||
};
|
||||
|
||||
extern char* chantostr(char*, ulong);
|
||||
extern ulong strtochan(char*);
|
||||
extern int chantodepth(ulong);
|
||||
|
||||
struct Point
|
||||
{
|
||||
int x;
|
||||
int y;
|
||||
};
|
||||
|
||||
struct Rectangle
|
||||
{
|
||||
Point min;
|
||||
Point max;
|
||||
};
|
||||
|
||||
typedef void (*Reffn)(Image*, Rectangle, void*);
|
||||
|
||||
struct Screen
|
||||
{
|
||||
Display *display; /* display holding data */
|
||||
int id; /* id of system-held Screen */
|
||||
Image *image; /* unused; for reference only */
|
||||
Image *fill; /* color to paint behind windows */
|
||||
};
|
||||
|
||||
struct Display
|
||||
{
|
||||
QLock qlock;
|
||||
int locking; /*program is using lockdisplay */
|
||||
int dirno;
|
||||
int fd;
|
||||
int reffd;
|
||||
int ctlfd;
|
||||
int imageid;
|
||||
int local;
|
||||
void (*error)(Display*, char*);
|
||||
char *devdir;
|
||||
char *windir;
|
||||
char oldlabel[64];
|
||||
ulong dataqid;
|
||||
Image *white;
|
||||
Image *black;
|
||||
Image *opaque;
|
||||
Image *transparent;
|
||||
Image *image;
|
||||
uchar *buf;
|
||||
int bufsize;
|
||||
uchar *bufp;
|
||||
Font *defaultfont;
|
||||
Subfont *defaultsubfont;
|
||||
Image *windows;
|
||||
Image *screenimage;
|
||||
int _isnewdisplay;
|
||||
};
|
||||
|
||||
struct Image
|
||||
{
|
||||
Display *display; /* display holding data */
|
||||
int id; /* id of system-held Image */
|
||||
Rectangle r; /* rectangle in data area, local coords */
|
||||
Rectangle clipr; /* clipping region */
|
||||
int depth; /* number of bits per pixel */
|
||||
ulong chan;
|
||||
int repl; /* flag: data replicates to tile clipr */
|
||||
Screen *screen; /* 0 if not a window */
|
||||
Image *next; /* next in list of windows */
|
||||
};
|
||||
|
||||
struct RGB
|
||||
{
|
||||
ulong red;
|
||||
ulong green;
|
||||
ulong blue;
|
||||
};
|
||||
|
||||
/*
|
||||
* Subfonts
|
||||
*
|
||||
* given char c, Subfont *f, Fontchar *i, and Point p, one says
|
||||
* i = f->info+c;
|
||||
* draw(b, Rect(p.x+i->left, p.y+i->top,
|
||||
* p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
|
||||
* color, f->bits, Pt(i->x, i->top));
|
||||
* p.x += i->width;
|
||||
* to draw characters in the specified color (itself an Image) in Image b.
|
||||
*/
|
||||
|
||||
struct Fontchar
|
||||
{
|
||||
int x; /* left edge of bits */
|
||||
uchar top; /* first non-zero scan-line */
|
||||
uchar bottom; /* last non-zero scan-line + 1 */
|
||||
char left; /* offset of baseline */
|
||||
uchar width; /* width of baseline */
|
||||
};
|
||||
|
||||
struct Subfont
|
||||
{
|
||||
char *name;
|
||||
short n; /* number of chars in font */
|
||||
uchar height; /* height of image */
|
||||
char ascent; /* top of image to baseline */
|
||||
Fontchar *info; /* n+1 character descriptors */
|
||||
Image *bits; /* of font */
|
||||
int ref;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
/* starting values */
|
||||
LOG2NFCACHE = 6,
|
||||
NFCACHE = (1<<LOG2NFCACHE), /* #chars cached */
|
||||
NFLOOK = 5, /* #chars to scan in cache */
|
||||
NFSUBF = 2, /* #subfonts to cache */
|
||||
/* max value */
|
||||
MAXFCACHE = 1024+NFLOOK, /* upper limit */
|
||||
MAXSUBF = 50, /* generous upper limit */
|
||||
/* deltas */
|
||||
DSUBF = 4,
|
||||
/* expiry ages */
|
||||
SUBFAGE = 10000,
|
||||
CACHEAGE = 10000
|
||||
};
|
||||
|
||||
struct Cachefont
|
||||
{
|
||||
Rune min; /* lowest rune value to be taken from subfont */
|
||||
Rune max; /* highest rune value+1 to be taken from subfont */
|
||||
int offset; /* position in subfont of character at min */
|
||||
char *name; /* stored in font */
|
||||
char *subfontname; /* to access subfont */
|
||||
};
|
||||
|
||||
struct Cacheinfo
|
||||
{
|
||||
ushort x; /* left edge of bits */
|
||||
uchar width; /* width of baseline */
|
||||
schar left; /* offset of baseline */
|
||||
Rune value; /* value of character at this slot in cache */
|
||||
ushort age;
|
||||
};
|
||||
|
||||
struct Cachesubf
|
||||
{
|
||||
ulong age; /* for replacement */
|
||||
Cachefont *cf; /* font info that owns us */
|
||||
Subfont *f; /* attached subfont */
|
||||
};
|
||||
|
||||
struct Font
|
||||
{
|
||||
char *name;
|
||||
Display *display;
|
||||
short height; /* max height of image, interline spacing */
|
||||
short ascent; /* top of image to baseline */
|
||||
short width; /* widest so far; used in caching only */
|
||||
short nsub; /* number of subfonts */
|
||||
ulong age; /* increasing counter; used for LRU */
|
||||
int maxdepth; /* maximum depth of all loaded subfonts */
|
||||
int ncache; /* size of cache */
|
||||
int nsubf; /* size of subfont list */
|
||||
Cacheinfo *cache;
|
||||
Cachesubf *subf;
|
||||
Cachefont **sub; /* as read from file */
|
||||
Image *cacheimage;
|
||||
};
|
||||
|
||||
#define Dx(r) ((r).max.x-(r).min.x)
|
||||
#define Dy(r) ((r).max.y-(r).min.y)
|
||||
|
||||
/*
|
||||
* Image management
|
||||
*/
|
||||
extern Image* _allocimage(Image*, Display*, Rectangle, ulong, int, ulong, int, int);
|
||||
extern Image* allocimage(Display*, Rectangle, ulong, int, ulong);
|
||||
extern uchar* bufimage(Display*, int);
|
||||
extern int bytesperline(Rectangle, int);
|
||||
extern void closedisplay(Display*);
|
||||
extern void drawerror(Display*, char*);
|
||||
extern int flushimage(Display*, int);
|
||||
extern int freeimage(Image*);
|
||||
extern int _freeimage1(Image*);
|
||||
extern int geninitdraw(char*, void(*)(Display*, char*), char*, char*, char*, int);
|
||||
extern int initdraw(void(*)(Display*, char*), char*, char*);
|
||||
extern int newwindow(char*);
|
||||
extern Display* initdisplay(char*, char*, void(*)(Display*, char*));
|
||||
extern int loadimage(Image*, Rectangle, uchar*, int);
|
||||
extern int cloadimage(Image*, Rectangle, uchar*, int);
|
||||
extern int getwindow(Display*, int);
|
||||
extern int gengetwindow(Display*, char*, Image**, Screen**, int);
|
||||
extern Image* readimage(Display*, int, int);
|
||||
extern Image* creadimage(Display*, int, int);
|
||||
extern int unloadimage(Image*, Rectangle, uchar*, int);
|
||||
extern int wordsperline(Rectangle, int);
|
||||
extern int writeimage(int, Image*, int);
|
||||
extern Image* namedimage(Display*, char*);
|
||||
extern int nameimage(Image*, char*, int);
|
||||
extern Image* allocimagemix(Display*, ulong, ulong);
|
||||
|
||||
/*
|
||||
* Colors
|
||||
*/
|
||||
extern void readcolmap(Display*, RGB*);
|
||||
extern void writecolmap(Display*, RGB*);
|
||||
extern ulong setalpha(ulong, uchar);
|
||||
|
||||
/*
|
||||
* Windows
|
||||
*/
|
||||
extern Screen* allocscreen(Image*, Image*, int);
|
||||
extern Image* _allocwindow(Image*, Screen*, Rectangle, int, ulong);
|
||||
extern Image* allocwindow(Screen*, Rectangle, int, ulong);
|
||||
extern void bottomnwindows(Image**, int);
|
||||
extern void bottomwindow(Image*);
|
||||
extern int freescreen(Screen*);
|
||||
extern Screen* publicscreen(Display*, int, ulong);
|
||||
extern void topnwindows(Image**, int);
|
||||
extern void topwindow(Image*);
|
||||
extern int originwindow(Image*, Point, Point);
|
||||
|
||||
/*
|
||||
* Geometry
|
||||
*/
|
||||
extern Point Pt(int, int);
|
||||
extern Rectangle Rect(int, int, int, int);
|
||||
extern Rectangle Rpt(Point, Point);
|
||||
extern Point addpt(Point, Point);
|
||||
extern Point subpt(Point, Point);
|
||||
extern Point divpt(Point, int);
|
||||
extern Point mulpt(Point, int);
|
||||
extern int eqpt(Point, Point);
|
||||
extern int eqrect(Rectangle, Rectangle);
|
||||
extern Rectangle insetrect(Rectangle, int);
|
||||
extern Rectangle rectaddpt(Rectangle, Point);
|
||||
extern Rectangle rectsubpt(Rectangle, Point);
|
||||
extern Rectangle canonrect(Rectangle);
|
||||
extern int rectXrect(Rectangle, Rectangle);
|
||||
extern int rectinrect(Rectangle, Rectangle);
|
||||
extern void combinerect(Rectangle*, Rectangle);
|
||||
extern int rectclip(Rectangle*, Rectangle);
|
||||
extern int ptinrect(Point, Rectangle);
|
||||
extern void replclipr(Image*, int, Rectangle);
|
||||
extern int drawreplxy(int, int, int); /* used to be drawsetxy */
|
||||
extern Point drawrepl(Rectangle, Point);
|
||||
extern int rgb2cmap(int, int, int);
|
||||
extern int cmap2rgb(int);
|
||||
extern int cmap2rgba(int);
|
||||
extern void icossin(int, int*, int*);
|
||||
extern void icossin2(int, int, int*, int*);
|
||||
|
||||
/*
|
||||
* Graphics
|
||||
*/
|
||||
extern void draw(Image*, Rectangle, Image*, Image*, Point);
|
||||
extern void drawop(Image*, Rectangle, Image*, Image*, Point, Drawop);
|
||||
extern void gendraw(Image*, Rectangle, Image*, Point, Image*, Point);
|
||||
extern void gendrawop(Image*, Rectangle, Image*, Point, Image*, Point, Drawop);
|
||||
extern void line(Image*, Point, Point, int, int, int, Image*, Point);
|
||||
extern void lineop(Image*, Point, Point, int, int, int, Image*, Point, Drawop);
|
||||
extern void poly(Image*, Point*, int, int, int, int, Image*, Point);
|
||||
extern void polyop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
|
||||
extern void fillpoly(Image*, Point*, int, int, Image*, Point);
|
||||
extern void fillpolyop(Image*, Point*, int, int, Image*, Point, Drawop);
|
||||
extern Point string(Image*, Point, Image*, Point, Font*, char*);
|
||||
extern Point stringop(Image*, Point, Image*, Point, Font*, char*, Drawop);
|
||||
extern Point stringn(Image*, Point, Image*, Point, Font*, char*, int);
|
||||
extern Point stringnop(Image*, Point, Image*, Point, Font*, char*, int, Drawop);
|
||||
extern Point runestring(Image*, Point, Image*, Point, Font*, Rune*);
|
||||
extern Point runestringop(Image*, Point, Image*, Point, Font*, Rune*, Drawop);
|
||||
extern Point runestringn(Image*, Point, Image*, Point, Font*, Rune*, int);
|
||||
extern Point runestringnop(Image*, Point, Image*, Point, Font*, Rune*, int, Drawop);
|
||||
extern Point stringbg(Image*, Point, Image*, Point, Font*, char*, Image*, Point);
|
||||
extern Point stringbgop(Image*, Point, Image*, Point, Font*, char*, Image*, Point, Drawop);
|
||||
extern Point stringnbg(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point);
|
||||
extern Point stringnbgop(Image*, Point, Image*, Point, Font*, char*, int, Image*, Point, Drawop);
|
||||
extern Point runestringbg(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point);
|
||||
extern Point runestringbgop(Image*, Point, Image*, Point, Font*, Rune*, Image*, Point, Drawop);
|
||||
extern Point runestringnbg(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point);
|
||||
extern Point runestringnbgop(Image*, Point, Image*, Point, Font*, Rune*, int, Image*, Point, Drawop);
|
||||
extern Point _string(Image*, Point, Image*, Point, Font*, char*, Rune*, int, Rectangle, Image*, Point, Drawop);
|
||||
extern Point stringsubfont(Image*, Point, Image*, Subfont*, char*);
|
||||
extern int bezier(Image*, Point, Point, Point, Point, int, int, int, Image*, Point);
|
||||
extern int bezierop(Image*, Point, Point, Point, Point, int, int, int, Image*, Point, Drawop);
|
||||
extern int bezspline(Image*, Point*, int, int, int, int, Image*, Point);
|
||||
extern int bezsplineop(Image*, Point*, int, int, int, int, Image*, Point, Drawop);
|
||||
extern int bezsplinepts(Point*, int, Point**);
|
||||
extern int fillbezier(Image*, Point, Point, Point, Point, int, Image*, Point);
|
||||
extern int fillbezierop(Image*, Point, Point, Point, Point, int, Image*, Point, Drawop);
|
||||
extern int fillbezspline(Image*, Point*, int, int, Image*, Point);
|
||||
extern int fillbezsplineop(Image*, Point*, int, int, Image*, Point, Drawop);
|
||||
extern void ellipse(Image*, Point, int, int, int, Image*, Point);
|
||||
extern void ellipseop(Image*, Point, int, int, int, Image*, Point, Drawop);
|
||||
extern void fillellipse(Image*, Point, int, int, Image*, Point);
|
||||
extern void fillellipseop(Image*, Point, int, int, Image*, Point, Drawop);
|
||||
extern void arc(Image*, Point, int, int, int, Image*, Point, int, int);
|
||||
extern void arcop(Image*, Point, int, int, int, Image*, Point, int, int, Drawop);
|
||||
extern void fillarc(Image*, Point, int, int, Image*, Point, int, int);
|
||||
extern void fillarcop(Image*, Point, int, int, Image*, Point, int, int, Drawop);
|
||||
extern void border(Image*, Rectangle, int, Image*, Point);
|
||||
extern void borderop(Image*, Rectangle, int, Image*, Point, Drawop);
|
||||
|
||||
/*
|
||||
* Font management
|
||||
*/
|
||||
extern Font* openfont(Display*, char*);
|
||||
extern Font* buildfont(Display*, char*, char*);
|
||||
extern void freefont(Font*);
|
||||
extern Font* mkfont(Subfont*, Rune);
|
||||
extern int cachechars(Font*, char**, Rune**, ushort*, int, int*, char**);
|
||||
extern void agefont(Font*);
|
||||
extern Subfont* allocsubfont(char*, int, int, int, Fontchar*, Image*);
|
||||
extern Subfont* lookupsubfont(Display*, char*);
|
||||
extern void installsubfont(char*, Subfont*);
|
||||
extern void uninstallsubfont(Subfont*);
|
||||
extern void freesubfont(Subfont*);
|
||||
extern Subfont* readsubfont(Display*, char*, int, int);
|
||||
extern Subfont* readsubfonti(Display*, char*, int, Image*, int);
|
||||
extern int writesubfont(int, Subfont*);
|
||||
extern void _unpackinfo(Fontchar*, uchar*, int);
|
||||
extern Point stringsize(Font*, char*);
|
||||
extern int stringwidth(Font*, char*);
|
||||
extern int stringnwidth(Font*, char*, int);
|
||||
extern Point runestringsize(Font*, Rune*);
|
||||
extern int runestringwidth(Font*, Rune*);
|
||||
extern int runestringnwidth(Font*, Rune*, int);
|
||||
extern Point strsubfontwidth(Subfont*, char*);
|
||||
extern int loadchar(Font*, Rune, Cacheinfo*, int, int, char**);
|
||||
extern char* subfontname(char*, char*, int);
|
||||
extern Subfont* _getsubfont(Display*, char*);
|
||||
extern Subfont* getdefont(Display*);
|
||||
extern void lockdisplay(Display*);
|
||||
extern void unlockdisplay(Display*);
|
||||
extern int drawlsetrefresh(ulong, int, void*, void*);
|
||||
|
||||
/*
|
||||
* Predefined
|
||||
*/
|
||||
extern uchar defontdata[];
|
||||
extern int sizeofdefont;
|
||||
extern Point ZP;
|
||||
extern Rectangle ZR;
|
||||
|
||||
/*
|
||||
* Set up by initdraw()
|
||||
*/
|
||||
extern Display *display;
|
||||
extern Font *font;
|
||||
/* extern Image *screen; */
|
||||
extern Screen *_screen;
|
||||
extern int _cursorfd;
|
||||
extern int _drawdebug; /* set to 1 to see errors from flushimage */
|
||||
extern void _setdrawop(Display*, Drawop);
|
||||
|
||||
#define BGSHORT(p) (((p)[0]<<0) | ((p)[1]<<8))
|
||||
#define BGLONG(p) ((BGSHORT(p)<<0) | (BGSHORT(p+2)<<16))
|
||||
#define BPSHORT(p, v) ((p)[0]=(v), (p)[1]=((v)>>8))
|
||||
#define BPLONG(p, v) (BPSHORT(p, (v)), BPSHORT(p+2, (v)>>16))
|
||||
|
||||
/*
|
||||
* Compressed image file parameters and helper routines
|
||||
*/
|
||||
#define NMATCH 3 /* shortest match possible */
|
||||
#define NRUN (NMATCH+31) /* longest match possible */
|
||||
#define NMEM 1024 /* window size */
|
||||
#define NDUMP 128 /* maximum length of dump */
|
||||
#define NCBLOCK 6000 /* size of compressed blocks */
|
||||
extern void _twiddlecompressed(uchar*, int);
|
||||
extern int _compblocksize(Rectangle, int);
|
||||
|
||||
/* XXX backwards helps; should go */
|
||||
extern int log2[];
|
||||
extern ulong drawld2chan[];
|
||||
extern void drawsetdebug(int);
|
10
include/dtos.h
Normal file
10
include/dtos.h
Normal file
@ -0,0 +1,10 @@
|
||||
#if defined(linux) || defined(IRIX) || defined(SOLARIS) || defined(OSF1) || defined(__FreeBSD__) || defined(__APPLE__)
|
||||
# include "unix.h"
|
||||
# ifdef __APPLE__
|
||||
# define panic dt_panic
|
||||
# endif
|
||||
#elif defined(WINDOWS)
|
||||
# include "winduhz.h"
|
||||
#else
|
||||
# error "Define an OS"
|
||||
#endif
|
110
include/fcall.h
Normal file
110
include/fcall.h
Normal file
@ -0,0 +1,110 @@
|
||||
#define VERSION9P "9P2000"
|
||||
|
||||
#define MAXWELEM 16
|
||||
|
||||
typedef
|
||||
struct Fcall
|
||||
{
|
||||
uchar type;
|
||||
u32int fid;
|
||||
ushort tag;
|
||||
u32int msize; /* Tversion, Rversion */
|
||||
char *version; /* Tversion, Rversion */
|
||||
ushort oldtag; /* Tflush */
|
||||
char *ename; /* Rerror */
|
||||
Qid qid; /* Rattach, Ropen, Rcreate */
|
||||
u32int iounit; /* Ropen, Rcreate */
|
||||
Qid aqid; /* Rauth */
|
||||
u32int afid; /* Tauth, Tattach */
|
||||
char *uname; /* Tauth, Tattach */
|
||||
char *aname; /* Tauth, Tattach */
|
||||
u32int perm; /* Tcreate */
|
||||
char *name; /* Tcreate */
|
||||
uchar mode; /* Tcreate, Topen */
|
||||
u32int newfid; /* Twalk */
|
||||
ushort nwname; /* Twalk */
|
||||
char *wname[MAXWELEM]; /* Twalk */
|
||||
ushort nwqid; /* Rwalk */
|
||||
Qid wqid[MAXWELEM]; /* Rwalk */
|
||||
vlong offset; /* Tread, Twrite */
|
||||
u32int count; /* Tread, Twrite, Rread */
|
||||
char *data; /* Twrite, Rread */
|
||||
ushort nstat; /* Twstat, Rstat */
|
||||
uchar *stat; /* Twstat, Rstat */
|
||||
} Fcall;
|
||||
|
||||
|
||||
#define GBIT8(p) ((p)[0])
|
||||
#define GBIT16(p) ((p)[0]|((p)[1]<<8))
|
||||
#define GBIT32(p) ((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24))
|
||||
#define GBIT64(p) ((vlong)((p)[0]|((p)[1]<<8)|((p)[2]<<16)|((p)[3]<<24)) |\
|
||||
((vlong)((p)[4]|((p)[5]<<8)|((p)[6]<<16)|((p)[7]<<24)) << 32))
|
||||
|
||||
#define PBIT8(p,v) (p)[0]=(v)
|
||||
#define PBIT16(p,v) (p)[0]=(v);(p)[1]=(v)>>8
|
||||
#define PBIT32(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24
|
||||
#define PBIT64(p,v) (p)[0]=(v);(p)[1]=(v)>>8;(p)[2]=(v)>>16;(p)[3]=(v)>>24;\
|
||||
(p)[4]=(v)>>32;(p)[5]=(v)>>40;(p)[6]=(v)>>48;(p)[7]=(v)>>56
|
||||
|
||||
#define BIT8SZ 1
|
||||
#define BIT16SZ 2
|
||||
#define BIT32SZ 4
|
||||
#define BIT64SZ 8
|
||||
#define QIDSZ (BIT8SZ+BIT32SZ+BIT64SZ)
|
||||
|
||||
/* STATFIXLEN includes leading 16-bit count */
|
||||
/* The count, however, excludes itself; total size is BIT16SZ+count */
|
||||
#define STATFIXLEN (BIT16SZ+QIDSZ+5*BIT16SZ+4*BIT32SZ+1*BIT64SZ) /* amount of fixed length data in a stat buffer */
|
||||
|
||||
#define NOTAG (ushort)~0U /* Dummy tag */
|
||||
#define NOFID (u32int)~0U /* Dummy fid */
|
||||
#define IOHDRSZ 24 /* ample room for Twrite/Rread header (iounit) */
|
||||
|
||||
enum
|
||||
{
|
||||
Tversion = 100,
|
||||
Rversion,
|
||||
Tauth = 102,
|
||||
Rauth,
|
||||
Tattach = 104,
|
||||
Rattach,
|
||||
Terror = 106, /* illegal */
|
||||
Rerror,
|
||||
Tflush = 108,
|
||||
Rflush,
|
||||
Twalk = 110,
|
||||
Rwalk,
|
||||
Topen = 112,
|
||||
Ropen,
|
||||
Tcreate = 114,
|
||||
Rcreate,
|
||||
Tread = 116,
|
||||
Rread,
|
||||
Twrite = 118,
|
||||
Rwrite,
|
||||
Tclunk = 120,
|
||||
Rclunk,
|
||||
Tremove = 122,
|
||||
Rremove,
|
||||
Tstat = 124,
|
||||
Rstat,
|
||||
Twstat = 126,
|
||||
Rwstat,
|
||||
Tmax,
|
||||
};
|
||||
|
||||
uint convM2S(uchar*, uint, Fcall*);
|
||||
uint convS2M(Fcall*, uchar*, uint);
|
||||
uint sizeS2M(Fcall*);
|
||||
|
||||
int statcheck(uchar *abuf, uint nbuf);
|
||||
uint convM2D(uchar*, uint, Dir*, char*);
|
||||
uint convD2M(Dir*, uchar*, uint);
|
||||
uint sizeD2M(Dir*);
|
||||
|
||||
int fcallfmt(Fmt*);
|
||||
int dirfmt(Fmt*);
|
||||
int dirmodefmt(Fmt*);
|
||||
|
||||
int read9pmsg(int, void*, uint);
|
||||
|
42
include/keyboard.h
Normal file
42
include/keyboard.h
Normal file
@ -0,0 +1,42 @@
|
||||
#pragma src "/sys/src/libdraw"
|
||||
#pragma lib "libdraw.a"
|
||||
|
||||
typedef struct Keyboardctl Keyboardctl;
|
||||
typedef struct Channel Channel;
|
||||
|
||||
struct Keyboardctl
|
||||
{
|
||||
Channel *c; /* chan(Rune)[20] */
|
||||
|
||||
char *file;
|
||||
int consfd; /* to cons file */
|
||||
int ctlfd; /* to ctl file */
|
||||
int pid; /* of slave proc */
|
||||
};
|
||||
|
||||
|
||||
extern Keyboardctl* initkeyboard(char*);
|
||||
extern int ctlkeyboard(Keyboardctl*, char*);
|
||||
extern void closekeyboard(Keyboardctl*);
|
||||
|
||||
enum {
|
||||
KF= 0xF000, /* Rune: beginning of private Unicode space */
|
||||
Spec= 0xF800,
|
||||
/* KF|1, KF|2, ..., KF|0xC is F1, F2, ..., F12 */
|
||||
Khome= KF|0x0D,
|
||||
Kup= KF|0x0E,
|
||||
Kpgup= KF|0x0F,
|
||||
Kprint= KF|0x10,
|
||||
Kleft= KF|0x11,
|
||||
Kright= KF|0x12,
|
||||
Kdown= Spec|0x00,
|
||||
Kview= Spec|0x00,
|
||||
Kpgdown= KF|0x13,
|
||||
Kins= KF|0x14,
|
||||
Kend= KF|0x18,
|
||||
|
||||
Kalt= KF|0x15,
|
||||
Kshift= KF|0x16,
|
||||
Kctl= KF|0x17,
|
||||
};
|
||||
|
246
include/lib.h
Normal file
246
include/lib.h
Normal file
@ -0,0 +1,246 @@
|
||||
/* avoid name conflicts */
|
||||
#define accept pm_accept
|
||||
#define listen pm_listen
|
||||
#define sleep ksleep
|
||||
#define wakeup kwakeup
|
||||
#define strtod libstrtod
|
||||
#define pow10 libpow10
|
||||
|
||||
/* conflicts on some os's */
|
||||
#define encrypt libencrypt
|
||||
#define decrypt libdecrypt
|
||||
#define oserror liboserror
|
||||
#define clone libclone
|
||||
#define atexit libatexit
|
||||
#define log2 liblog2
|
||||
#define log liblog
|
||||
#define reboot libreboot
|
||||
#define srand dtsrand
|
||||
#define rand dtrand
|
||||
#define nrand dtnrand
|
||||
#define lrand dtlrand
|
||||
#define lnrand dtlnrand
|
||||
#undef timeradd
|
||||
#define timeradd xtimeradd
|
||||
|
||||
|
||||
#define nil ((void*)0)
|
||||
|
||||
typedef unsigned char p9_uchar;
|
||||
typedef unsigned int p9_uint;
|
||||
typedef unsigned int p9_ulong;
|
||||
typedef int p9_long;
|
||||
typedef signed char p9_schar;
|
||||
typedef unsigned short p9_ushort;
|
||||
typedef unsigned short Rune;
|
||||
typedef unsigned int p9_u32int;
|
||||
typedef p9_u32int mpdigit;
|
||||
|
||||
/* make sure we don't conflict with predefined types */
|
||||
#define schar p9_schar
|
||||
#define uchar p9_uchar
|
||||
#define ushort p9_ushort
|
||||
#define uint p9_uint
|
||||
#define u32int p9_u32int
|
||||
|
||||
/* #define long int rather than p9_long so that "unsigned long" is valid */
|
||||
#define long int
|
||||
#define ulong p9_ulong
|
||||
#define vlong p9_vlong
|
||||
#define uvlong p9_uvlong
|
||||
|
||||
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
|
||||
#define USED(x) if(x);else
|
||||
#define SET(x)
|
||||
|
||||
enum
|
||||
{
|
||||
UTFmax = 3, /* maximum bytes per rune */
|
||||
Runesync = 0x80, /* cannot represent part of a UTF sequence (<) */
|
||||
Runeself = 0x80, /* rune and UTF sequences are the same (<) */
|
||||
Runeerror = 0x80 /* decoding error in UTF */
|
||||
};
|
||||
|
||||
/*
|
||||
* new rune routines
|
||||
*/
|
||||
extern int runetochar(char*, Rune*);
|
||||
extern int chartorune(Rune*, char*);
|
||||
extern int runelen(long);
|
||||
extern int fullrune(char*, int);
|
||||
|
||||
extern int wstrtoutf(char*, Rune*, int);
|
||||
extern int wstrutflen(Rune*);
|
||||
|
||||
/*
|
||||
* rune routines from converted str routines
|
||||
*/
|
||||
extern long utflen(char*);
|
||||
extern char* utfrune(char*, long);
|
||||
extern char* utfrrune(char*, long);
|
||||
|
||||
/*
|
||||
* Syscall data structures
|
||||
*/
|
||||
#define MORDER 0x0003 /* mask for bits defining order of mounting */
|
||||
#define MREPL 0x0000 /* mount replaces object */
|
||||
#define MBEFORE 0x0001 /* mount goes before others in union directory */
|
||||
#define MAFTER 0x0002 /* mount goes after others in union directory */
|
||||
#define MCREATE 0x0004 /* permit creation in mounted directory */
|
||||
#define MCACHE 0x0010 /* cache some data */
|
||||
#define MMASK 0x0017 /* all bits on */
|
||||
|
||||
#define OREAD 0 /* open for read */
|
||||
#define OWRITE 1 /* write */
|
||||
#define ORDWR 2 /* read and write */
|
||||
#define OEXEC 3 /* execute, == read but check execute permission */
|
||||
#define OTRUNC 16 /* or'ed in (except for exec), truncate file first */
|
||||
#define OCEXEC 32 /* or'ed in, close on exec */
|
||||
#define ORCLOSE 64 /* or'ed in, remove on close */
|
||||
#define OEXCL 0x1000 /* or'ed in, exclusive create */
|
||||
|
||||
#define NCONT 0 /* continue after note */
|
||||
#define NDFLT 1 /* terminate after note */
|
||||
#define NSAVE 2 /* clear note but hold state */
|
||||
#define NRSTR 3 /* restore saved state */
|
||||
|
||||
#define ERRMAX 128 /* max length of error string */
|
||||
#define KNAMELEN 28 /* max length of name held in kernel */
|
||||
|
||||
/* bits in Qid.type */
|
||||
#define QTDIR 0x80 /* type bit for directories */
|
||||
#define QTAPPEND 0x40 /* type bit for append only files */
|
||||
#define QTEXCL 0x20 /* type bit for exclusive use files */
|
||||
#define QTMOUNT 0x10 /* type bit for mounted channel */
|
||||
#define QTAUTH 0x08 /* type bit for authentication file */
|
||||
#define QTFILE 0x00 /* plain file */
|
||||
|
||||
/* bits in Dir.mode */
|
||||
#define DMDIR 0x80000000 /* mode bit for directories */
|
||||
#define DMAPPEND 0x40000000 /* mode bit for append only files */
|
||||
#define DMEXCL 0x20000000 /* mode bit for exclusive use files */
|
||||
#define DMMOUNT 0x10000000 /* mode bit for mounted channel */
|
||||
#define DMAUTH 0x08000000 /* mode bit for authentication files */
|
||||
#define DMREAD 0x4 /* mode bit for read permission */
|
||||
#define DMWRITE 0x2 /* mode bit for write permission */
|
||||
#define DMEXEC 0x1 /* mode bit for execute permission */
|
||||
|
||||
typedef struct Lock
|
||||
{
|
||||
long key;
|
||||
} Lock;
|
||||
|
||||
typedef struct QLock
|
||||
{
|
||||
Lock lk;
|
||||
struct Proc *hold;
|
||||
struct Proc *first;
|
||||
struct Proc *last;
|
||||
} QLock;
|
||||
|
||||
typedef
|
||||
struct Qid
|
||||
{
|
||||
uvlong path;
|
||||
ulong vers;
|
||||
uchar type;
|
||||
} Qid;
|
||||
|
||||
typedef
|
||||
struct Dir {
|
||||
/* system-modified data */
|
||||
ushort type; /* server type */
|
||||
uint dev; /* server subtype */
|
||||
/* file data */
|
||||
Qid qid; /* unique id from server */
|
||||
ulong mode; /* permissions */
|
||||
ulong atime; /* last read time */
|
||||
ulong mtime; /* last write time */
|
||||
vlong length; /* file length */
|
||||
char *name; /* last element of path */
|
||||
char *uid; /* owner name */
|
||||
char *gid; /* group name */
|
||||
char *muid; /* last modifier name */
|
||||
} Dir;
|
||||
|
||||
typedef
|
||||
struct Waitmsg
|
||||
{
|
||||
int pid; /* of loved one */
|
||||
ulong time[3]; /* of loved one & descendants */
|
||||
char *msg;
|
||||
} Waitmsg;
|
||||
|
||||
/*
|
||||
* print routines
|
||||
*/
|
||||
typedef struct Fmt Fmt;
|
||||
struct Fmt{
|
||||
uchar runes; /* output buffer is runes or chars? */
|
||||
void *start; /* of buffer */
|
||||
void *to; /* current place in the buffer */
|
||||
void *stop; /* end of the buffer; overwritten if flush fails */
|
||||
int (*flush)(Fmt *); /* called when to == stop */
|
||||
void *farg; /* to make flush a closure */
|
||||
int nfmt; /* num chars formatted so far */
|
||||
va_list args; /* args passed to dofmt */
|
||||
int r; /* % format Rune */
|
||||
int width;
|
||||
int prec;
|
||||
ulong flags;
|
||||
};
|
||||
|
||||
enum{
|
||||
FmtWidth = 1,
|
||||
FmtLeft = FmtWidth << 1,
|
||||
FmtPrec = FmtLeft << 1,
|
||||
FmtSharp = FmtPrec << 1,
|
||||
FmtSpace = FmtSharp << 1,
|
||||
FmtSign = FmtSpace << 1,
|
||||
FmtZero = FmtSign << 1,
|
||||
FmtUnsigned = FmtZero << 1,
|
||||
FmtShort = FmtUnsigned << 1,
|
||||
FmtLong = FmtShort << 1,
|
||||
FmtVLong = FmtLong << 1,
|
||||
FmtComma = FmtVLong << 1,
|
||||
FmtByte = FmtComma << 1,
|
||||
|
||||
FmtFlag = FmtByte << 1
|
||||
};
|
||||
|
||||
extern int print(char*, ...);
|
||||
extern char* seprint(char*, char*, char*, ...);
|
||||
extern char* vseprint(char*, char*, char*, va_list);
|
||||
extern int snprint(char*, int, char*, ...);
|
||||
extern int vsnprint(char*, int, char*, va_list);
|
||||
extern char* smprint(char*, ...);
|
||||
extern char* vsmprint(char*, va_list);
|
||||
extern int sprint(char*, char*, ...);
|
||||
extern int fprint(int, char*, ...);
|
||||
extern int vfprint(int, char*, va_list);
|
||||
|
||||
extern int (*doquote)(int);
|
||||
extern int runesprint(Rune*, char*, ...);
|
||||
extern int runesnprint(Rune*, int, char*, ...);
|
||||
extern int runevsnprint(Rune*, int, char*, va_list);
|
||||
extern Rune* runeseprint(Rune*, Rune*, char*, ...);
|
||||
extern Rune* runevseprint(Rune*, Rune*, char*, va_list);
|
||||
extern Rune* runesmprint(char*, ...);
|
||||
extern Rune* runevsmprint(char*, va_list);
|
||||
|
||||
extern int fmtfdinit(Fmt*, int, char*, int);
|
||||
extern int fmtfdflush(Fmt*);
|
||||
extern int fmtstrinit(Fmt*);
|
||||
extern int fmtinstall(int, int (*)(Fmt*));
|
||||
extern char* fmtstrflush(Fmt*);
|
||||
extern int runefmtstrinit(Fmt*);
|
||||
extern Rune* runefmtstrflush(Fmt*);
|
||||
|
||||
extern void* mallocz(ulong, int);
|
||||
|
||||
extern void srand(long);
|
||||
extern int rand(void);
|
||||
extern int nrand(int);
|
||||
extern long lrand(void);
|
||||
extern long lnrand(long);
|
||||
extern double frand(void);
|
3
include/libc.h
Normal file
3
include/libc.h
Normal file
@ -0,0 +1,3 @@
|
||||
#include "lib.h"
|
||||
#include "user.h"
|
||||
|
340
include/libsec.h
Normal file
340
include/libsec.h
Normal file
@ -0,0 +1,340 @@
|
||||
|
||||
#ifndef _MPINT
|
||||
typedef struct mpint mpint;
|
||||
#endif
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// AES definitions
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
enum
|
||||
{
|
||||
AESbsize= 16,
|
||||
AESmaxkey= 32,
|
||||
AESmaxrounds= 14
|
||||
};
|
||||
|
||||
typedef struct AESstate AESstate;
|
||||
struct AESstate
|
||||
{
|
||||
ulong setup;
|
||||
int rounds;
|
||||
int keybytes;
|
||||
uchar key[AESmaxkey]; /* unexpanded key */
|
||||
u32int ekey[4*(AESmaxrounds + 1)]; /* encryption key */
|
||||
u32int dkey[4*(AESmaxrounds + 1)]; /* decryption key */
|
||||
uchar ivec[AESbsize]; /* initialization vector */
|
||||
};
|
||||
|
||||
void setupAESstate(AESstate *s, uchar key[], int keybytes, uchar *ivec);
|
||||
void aesCBCencrypt(uchar *p, int len, AESstate *s);
|
||||
void aesCBCdecrypt(uchar *p, int len, AESstate *s);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// Blowfish Definitions
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
enum
|
||||
{
|
||||
BFbsize = 8,
|
||||
BFrounds = 16
|
||||
};
|
||||
|
||||
// 16-round Blowfish
|
||||
typedef struct BFstate BFstate;
|
||||
struct BFstate
|
||||
{
|
||||
ulong setup;
|
||||
|
||||
uchar key[56];
|
||||
uchar ivec[8];
|
||||
|
||||
u32int pbox[BFrounds+2];
|
||||
u32int sbox[1024];
|
||||
};
|
||||
|
||||
void setupBFstate(BFstate *s, uchar key[], int keybytes, uchar *ivec);
|
||||
void bfCBCencrypt(uchar*, int, BFstate*);
|
||||
void bfCBCdecrypt(uchar*, int, BFstate*);
|
||||
void bfECBencrypt(uchar*, int, BFstate*);
|
||||
void bfECBdecrypt(uchar*, int, BFstate*);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// DES definitions
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
enum
|
||||
{
|
||||
DESbsize= 8
|
||||
};
|
||||
|
||||
// single des
|
||||
typedef struct DESstate DESstate;
|
||||
struct DESstate
|
||||
{
|
||||
ulong setup;
|
||||
uchar key[8]; /* unexpanded key */
|
||||
ulong expanded[32]; /* expanded key */
|
||||
uchar ivec[8]; /* initialization vector */
|
||||
};
|
||||
|
||||
void setupDESstate(DESstate *s, uchar key[8], uchar *ivec);
|
||||
void des_key_setup(uchar[8], ulong[32]);
|
||||
void block_cipher(ulong*, uchar*, int);
|
||||
void desCBCencrypt(uchar*, int, DESstate*);
|
||||
void desCBCdecrypt(uchar*, int, DESstate*);
|
||||
void desECBencrypt(uchar*, int, DESstate*);
|
||||
void desECBdecrypt(uchar*, int, DESstate*);
|
||||
|
||||
// for backward compatibility with 7 byte DES key format
|
||||
void des56to64(uchar *k56, uchar *k64);
|
||||
void des64to56(uchar *k64, uchar *k56);
|
||||
void key_setup(uchar[7], ulong[32]);
|
||||
|
||||
// triple des encrypt/decrypt orderings
|
||||
enum {
|
||||
DES3E= 0,
|
||||
DES3D= 1,
|
||||
DES3EEE= 0,
|
||||
DES3EDE= 2,
|
||||
DES3DED= 5,
|
||||
DES3DDD= 7
|
||||
};
|
||||
|
||||
typedef struct DES3state DES3state;
|
||||
struct DES3state
|
||||
{
|
||||
ulong setup;
|
||||
uchar key[3][8]; /* unexpanded key */
|
||||
ulong expanded[3][32]; /* expanded key */
|
||||
uchar ivec[8]; /* initialization vector */
|
||||
};
|
||||
|
||||
void setupDES3state(DES3state *s, uchar key[3][8], uchar *ivec);
|
||||
void triple_block_cipher(ulong keys[3][32], uchar*, int);
|
||||
void des3CBCencrypt(uchar*, int, DES3state*);
|
||||
void des3CBCdecrypt(uchar*, int, DES3state*);
|
||||
void des3ECBencrypt(uchar*, int, DES3state*);
|
||||
void des3ECBdecrypt(uchar*, int, DES3state*);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// digests
|
||||
/////////////////////////////////////////////////////////
|
||||
|
||||
enum
|
||||
{
|
||||
SHA1dlen= 20, /* SHA digest length */
|
||||
MD4dlen= 16, /* MD4 digest length */
|
||||
MD5dlen= 16 /* MD5 digest length */
|
||||
};
|
||||
|
||||
typedef struct DigestState DigestState;
|
||||
struct DigestState
|
||||
{
|
||||
ulong len;
|
||||
u32int state[5];
|
||||
uchar buf[128];
|
||||
int blen;
|
||||
char malloced;
|
||||
char seeded;
|
||||
};
|
||||
typedef struct DigestState SHAstate; /* obsolete name */
|
||||
typedef struct DigestState SHA1state;
|
||||
typedef struct DigestState MD5state;
|
||||
typedef struct DigestState MD4state;
|
||||
|
||||
DigestState* md4(uchar*, ulong, uchar*, DigestState*);
|
||||
DigestState* md5(uchar*, ulong, uchar*, DigestState*);
|
||||
DigestState* sha1(uchar*, ulong, uchar*, DigestState*);
|
||||
DigestState* hmac_md5(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
|
||||
DigestState* hmac_sha1(uchar*, ulong, uchar*, ulong, uchar*, DigestState*);
|
||||
char* sha1pickle(SHA1state*);
|
||||
SHA1state* sha1unpickle(char*);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// random number generation
|
||||
/////////////////////////////////////////////////////////
|
||||
void genrandom(uchar *buf, int nbytes);
|
||||
void prng(uchar *buf, int nbytes);
|
||||
ulong fastrand(void);
|
||||
ulong nfastrand(ulong);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// primes
|
||||
/////////////////////////////////////////////////////////
|
||||
void genprime(mpint *p, int n, int accuracy); // generate an n bit probable prime
|
||||
void gensafeprime(mpint *p, mpint *alpha, int n, int accuracy); // prime and generator
|
||||
void genstrongprime(mpint *p, int n, int accuracy); // generate an n bit strong prime
|
||||
void DSAprimes(mpint *q, mpint *p, uchar seed[SHA1dlen]);
|
||||
int probably_prime(mpint *n, int nrep); // miller-rabin test
|
||||
int smallprimetest(mpint *p); // returns -1 if not prime, 0 otherwise
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// rc4
|
||||
/////////////////////////////////////////////////////////
|
||||
typedef struct RC4state RC4state;
|
||||
struct RC4state
|
||||
{
|
||||
uchar state[256];
|
||||
uchar x;
|
||||
uchar y;
|
||||
};
|
||||
|
||||
void setupRC4state(RC4state*, uchar*, int);
|
||||
void rc4(RC4state*, uchar*, int);
|
||||
void rc4skip(RC4state*, int);
|
||||
void rc4back(RC4state*, int);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// rsa
|
||||
/////////////////////////////////////////////////////////
|
||||
typedef struct RSApub RSApub;
|
||||
typedef struct RSApriv RSApriv;
|
||||
|
||||
// public/encryption key
|
||||
struct RSApub
|
||||
{
|
||||
mpint *n; // modulus
|
||||
mpint *ek; // exp (encryption key)
|
||||
};
|
||||
|
||||
// private/decryption key
|
||||
struct RSApriv
|
||||
{
|
||||
RSApub pub;
|
||||
|
||||
mpint *dk; // exp (decryption key)
|
||||
|
||||
// precomputed values to help with chinese remainder theorem calc
|
||||
mpint *p;
|
||||
mpint *q;
|
||||
mpint *kp; // dk mod p-1
|
||||
mpint *kq; // dk mod q-1
|
||||
mpint *c2; // (inv p) mod q
|
||||
};
|
||||
|
||||
RSApriv* rsagen(int nlen, int elen, int rounds);
|
||||
RSApriv* rsafill(mpint *n, mpint *e, mpint *d, mpint *p, mpint *q);
|
||||
mpint* rsaencrypt(RSApub *k, mpint *in, mpint *out);
|
||||
mpint* rsadecrypt(RSApriv *k, mpint *in, mpint *out);
|
||||
RSApub* rsapuballoc(void);
|
||||
void rsapubfree(RSApub*);
|
||||
RSApriv* rsaprivalloc(void);
|
||||
void rsaprivfree(RSApriv*);
|
||||
RSApub* rsaprivtopub(RSApriv*);
|
||||
RSApub* X509toRSApub(uchar*, int, char*, int);
|
||||
RSApriv* asn1toRSApriv(uchar*, int);
|
||||
void asn1dump(uchar *der, int len);
|
||||
uchar* decodepem(char *s, char *type, int *len);
|
||||
uchar* X509gen(RSApriv *priv, char *subj, ulong valid[2], int *certlen);
|
||||
uchar* X509req(RSApriv *priv, char *subj, int *certlen);
|
||||
char* X509verify(uchar *cert, int ncert, RSApub *pk);
|
||||
void X509dump(uchar *cert, int ncert);
|
||||
/////////////////////////////////////////////////////////
|
||||
// elgamal
|
||||
/////////////////////////////////////////////////////////
|
||||
typedef struct EGpub EGpub;
|
||||
typedef struct EGpriv EGpriv;
|
||||
typedef struct EGsig EGsig;
|
||||
|
||||
// public/encryption key
|
||||
struct EGpub
|
||||
{
|
||||
mpint *p; // modulus
|
||||
mpint *alpha; // generator
|
||||
mpint *key; // (encryption key) alpha**secret mod p
|
||||
};
|
||||
|
||||
// private/decryption key
|
||||
struct EGpriv
|
||||
{
|
||||
EGpub pub;
|
||||
mpint *secret; // (decryption key)
|
||||
};
|
||||
|
||||
// signature
|
||||
struct EGsig
|
||||
{
|
||||
mpint *r, *s;
|
||||
};
|
||||
|
||||
EGpriv* eggen(int nlen, int rounds);
|
||||
mpint* egencrypt(EGpub *k, mpint *in, mpint *out);
|
||||
mpint* egdecrypt(EGpriv *k, mpint *in, mpint *out);
|
||||
EGsig* egsign(EGpriv *k, mpint *m);
|
||||
int egverify(EGpub *k, EGsig *sig, mpint *m);
|
||||
EGpub* egpuballoc(void);
|
||||
void egpubfree(EGpub*);
|
||||
EGpriv* egprivalloc(void);
|
||||
void egprivfree(EGpriv*);
|
||||
EGsig* egsigalloc(void);
|
||||
void egsigfree(EGsig*);
|
||||
EGpub* egprivtopub(EGpriv*);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// dsa
|
||||
/////////////////////////////////////////////////////////
|
||||
typedef struct DSApub DSApub;
|
||||
typedef struct DSApriv DSApriv;
|
||||
typedef struct DSAsig DSAsig;
|
||||
|
||||
// public/encryption key
|
||||
struct DSApub
|
||||
{
|
||||
mpint *p; // modulus
|
||||
mpint *q; // group order, q divides p-1
|
||||
mpint *alpha; // group generator
|
||||
mpint *key; // (encryption key) alpha**secret mod p
|
||||
};
|
||||
|
||||
// private/decryption key
|
||||
struct DSApriv
|
||||
{
|
||||
DSApub pub;
|
||||
mpint *secret; // (decryption key)
|
||||
};
|
||||
|
||||
// signature
|
||||
struct DSAsig
|
||||
{
|
||||
mpint *r, *s;
|
||||
};
|
||||
|
||||
DSApriv* dsagen(DSApub *opub);
|
||||
DSAsig* dsasign(DSApriv *k, mpint *m);
|
||||
int dsaverify(DSApub *k, DSAsig *sig, mpint *m);
|
||||
DSApub* dsapuballoc(void);
|
||||
void dsapubfree(DSApub*);
|
||||
DSApriv* dsaprivalloc(void);
|
||||
void dsaprivfree(DSApriv*);
|
||||
DSAsig* dsasigalloc(void);
|
||||
void dsasigfree(DSAsig*);
|
||||
DSApub* dsaprivtopub(DSApriv*);
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
// TLS
|
||||
/////////////////////////////////////////////////////////
|
||||
typedef struct Thumbprint{
|
||||
struct Thumbprint *next;
|
||||
uchar sha1[SHA1dlen];
|
||||
} Thumbprint;
|
||||
|
||||
typedef struct TLSconn{
|
||||
char dir[40]; // connection directory
|
||||
uchar *cert; // certificate (local on input, remote on output)
|
||||
uchar *sessionID;
|
||||
int certlen, sessionIDlen;
|
||||
int (*trace)(char*fmt, ...);
|
||||
} TLSconn;
|
||||
|
||||
// tlshand.c
|
||||
extern int tlsClient(int fd, TLSconn *c);
|
||||
extern int tlsServer(int fd, TLSconn *c);
|
||||
|
||||
// thumb.c
|
||||
extern Thumbprint* initThumbprints(char *ok, char *crl);
|
||||
extern void freeThumbprints(Thumbprint *ok);
|
||||
extern int okThumbprint(uchar *sha1, Thumbprint *ok);
|
||||
|
||||
// readcert.c
|
||||
extern uchar *readcert(char *filename, int *pcertlen);
|
200
include/memdraw.h
Normal file
200
include/memdraw.h
Normal file
@ -0,0 +1,200 @@
|
||||
#pragma src "/sys/src/libmemdraw"
|
||||
#pragma lib "libmemdraw.a"
|
||||
|
||||
typedef struct Memimage Memimage;
|
||||
typedef struct Memdata Memdata;
|
||||
typedef struct Memsubfont Memsubfont;
|
||||
typedef struct Memlayer Memlayer;
|
||||
typedef struct Memcmap Memcmap;
|
||||
typedef struct Memdrawparam Memdrawparam;
|
||||
|
||||
/*
|
||||
* Memdata is allocated from main pool, but .data from the image pool.
|
||||
* Memdata is allocated separately to permit patching its pointer after
|
||||
* compaction when windows share the image data.
|
||||
* The first word of data is a back pointer to the Memdata, to find
|
||||
* The word to patch.
|
||||
*/
|
||||
|
||||
struct Memdata
|
||||
{
|
||||
ulong *base; /* allocated data pointer */
|
||||
uchar *bdata; /* pointer to first byte of actual data; word-aligned */
|
||||
int ref; /* number of Memimages using this data */
|
||||
void* imref;
|
||||
int allocd; /* is this malloc'd? */
|
||||
};
|
||||
|
||||
enum {
|
||||
Frepl = 1<<0, /* is replicated */
|
||||
Fsimple = 1<<1, /* is 1x1 */
|
||||
Fgrey = 1<<2, /* is grey */
|
||||
Falpha = 1<<3, /* has explicit alpha */
|
||||
Fcmap = 1<<4, /* has cmap channel */
|
||||
Fbytes = 1<<5, /* has only 8-bit channels */
|
||||
};
|
||||
|
||||
struct Memimage
|
||||
{
|
||||
Rectangle r; /* rectangle in data area, local coords */
|
||||
Rectangle clipr; /* clipping region */
|
||||
int depth; /* number of bits of storage per pixel */
|
||||
int nchan; /* number of channels */
|
||||
ulong chan; /* channel descriptions */
|
||||
Memcmap *cmap;
|
||||
|
||||
Memdata *data; /* pointer to data; shared by windows in this image */
|
||||
int zero; /* data->bdata+zero==&byte containing (0,0) */
|
||||
ulong width; /* width in words of a single scan line */
|
||||
Memlayer *layer; /* nil if not a layer*/
|
||||
ulong flags;
|
||||
|
||||
int shift[NChan];
|
||||
int mask[NChan];
|
||||
int nbits[NChan];
|
||||
|
||||
void *X;
|
||||
};
|
||||
|
||||
struct Memcmap
|
||||
{
|
||||
uchar cmap2rgb[3*256];
|
||||
uchar rgb2cmap[16*16*16];
|
||||
};
|
||||
|
||||
/*
|
||||
* Subfonts
|
||||
*
|
||||
* given char c, Subfont *f, Fontchar *i, and Point p, one says
|
||||
* i = f->info+c;
|
||||
* draw(b, Rect(p.x+i->left, p.y+i->top,
|
||||
* p.x+i->left+((i+1)->x-i->x), p.y+i->bottom),
|
||||
* color, f->bits, Pt(i->x, i->top));
|
||||
* p.x += i->width;
|
||||
* to draw characters in the specified color (itself a Memimage) in Memimage b.
|
||||
*/
|
||||
|
||||
struct Memsubfont
|
||||
{
|
||||
char *name;
|
||||
short n; /* number of chars in font */
|
||||
uchar height; /* height of bitmap */
|
||||
char ascent; /* top of bitmap to baseline */
|
||||
Fontchar *info; /* n+1 character descriptors */
|
||||
Memimage *bits; /* of font */
|
||||
};
|
||||
|
||||
/*
|
||||
* Encapsulated parameters and information for sub-draw routines.
|
||||
*/
|
||||
enum {
|
||||
Simplesrc=1<<0,
|
||||
Simplemask=1<<1,
|
||||
Replsrc=1<<2,
|
||||
Replmask=1<<3,
|
||||
Fullmask=1<<4,
|
||||
};
|
||||
struct Memdrawparam
|
||||
{
|
||||
Memimage *dst;
|
||||
Rectangle r;
|
||||
Memimage *src;
|
||||
Rectangle sr;
|
||||
Memimage *mask;
|
||||
Rectangle mr;
|
||||
int op;
|
||||
|
||||
ulong state;
|
||||
ulong mval; /* if Simplemask, the mask pixel in mask format */
|
||||
ulong mrgba; /* mval in rgba */
|
||||
ulong sval; /* if Simplesrc, the source pixel in src format */
|
||||
ulong srgba; /* sval in rgba */
|
||||
ulong sdval; /* sval in dst format */
|
||||
};
|
||||
|
||||
/*
|
||||
* Memimage management
|
||||
*/
|
||||
|
||||
extern Memimage* allocmemimage(Rectangle, ulong);
|
||||
extern Memimage* _allocmemimage(Rectangle, ulong);
|
||||
extern Memimage* allocmemimaged(Rectangle, ulong, Memdata*, void*);
|
||||
extern Memimage* readmemimage(int);
|
||||
extern Memimage* creadmemimage(int);
|
||||
extern int writememimage(int, Memimage*);
|
||||
extern void freememimage(Memimage*);
|
||||
extern int _loadmemimage(Memimage*, Rectangle, uchar*, int);
|
||||
extern int _cloadmemimage(Memimage*, Rectangle, uchar*, int);
|
||||
extern int _unloadmemimage(Memimage*, Rectangle, uchar*, int);
|
||||
extern int loadmemimage(Memimage*, Rectangle, uchar*, int);
|
||||
extern int cloadmemimage(Memimage*, Rectangle, uchar*, int);
|
||||
extern int unloadmemimage(Memimage*, Rectangle, uchar*, int);
|
||||
extern ulong* wordaddr(Memimage*, Point);
|
||||
extern uchar* byteaddr(Memimage*, Point);
|
||||
extern int drawclip(Memimage*, Rectangle*, Memimage*, Point*, Memimage*, Point*, Rectangle*, Rectangle*);
|
||||
extern void memfillcolor(Memimage*, ulong);
|
||||
extern int memsetchan(Memimage*, ulong);
|
||||
|
||||
/*
|
||||
* Graphics
|
||||
*/
|
||||
extern void memdraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
|
||||
extern void memline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
|
||||
extern void mempoly(Memimage*, Point*, int, int, int, int, Memimage*, Point, int);
|
||||
extern void memfillpoly(Memimage*, Point*, int, int, Memimage*, Point, int);
|
||||
extern void _memfillpolysc(Memimage*, Point*, int, int, Memimage*, Point, int, int, int, int);
|
||||
extern Memdrawparam* _memimagedrawsetup(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
|
||||
extern void _memimagedraw(Memdrawparam*);
|
||||
extern void memimagedraw(Memimage*, Rectangle, Memimage*, Point, Memimage*, Point, int);
|
||||
extern int hwdraw(Memdrawparam*);
|
||||
extern void memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, int);
|
||||
extern void _memimageline(Memimage*, Point, Point, int, int, int, Memimage*, Point, Rectangle, int);
|
||||
extern Point memimagestring(Memimage*, Point, Memimage*, Point, Memsubfont*, char*);
|
||||
extern void memellipse(Memimage*, Point, int, int, int, Memimage*, Point, int);
|
||||
extern void memarc(Memimage*, Point, int, int, int, Memimage*, Point, int, int, int);
|
||||
extern Rectangle memlinebbox(Point, Point, int, int, int);
|
||||
extern int memlineendsize(int);
|
||||
extern void _memmkcmap(void);
|
||||
extern void memimageinit(void);
|
||||
|
||||
/*
|
||||
* Subfont management
|
||||
*/
|
||||
extern Memsubfont* allocmemsubfont(char*, int, int, int, Fontchar*, Memimage*);
|
||||
extern Memsubfont* openmemsubfont(char*);
|
||||
extern void freememsubfont(Memsubfont*);
|
||||
extern Point memsubfontwidth(Memsubfont*, char*);
|
||||
extern Memsubfont* getmemdefont(void);
|
||||
|
||||
/*
|
||||
* Predefined
|
||||
*/
|
||||
extern Memimage* memwhite;
|
||||
extern Memimage* memblack;
|
||||
extern Memimage* memopaque;
|
||||
extern Memimage* memtransparent;
|
||||
extern Memcmap *memdefcmap;
|
||||
|
||||
/*
|
||||
* Kernel interface
|
||||
*/
|
||||
void memimagemove(void*, void*);
|
||||
|
||||
/*
|
||||
* Kernel cruft
|
||||
*/
|
||||
extern void rdb(void);
|
||||
extern int iprint(char*, ...);
|
||||
#pragma varargck argpos iprint 1
|
||||
extern int drawdebug;
|
||||
|
||||
/*
|
||||
* doprint interface: numbconv bit strings
|
||||
*/
|
||||
#pragma varargck type "llb" vlong
|
||||
#pragma varargck type "llb" uvlong
|
||||
#pragma varargck type "lb" long
|
||||
#pragma varargck type "lb" ulong
|
||||
#pragma varargck type "b" int
|
||||
#pragma varargck type "b" uint
|
||||
|
51
include/memlayer.h
Normal file
51
include/memlayer.h
Normal file
@ -0,0 +1,51 @@
|
||||
#pragma src "/sys/src/libmemlayer"
|
||||
#pragma lib "libmemlayer.a"
|
||||
|
||||
typedef struct Memscreen Memscreen;
|
||||
typedef void (*Refreshfn)(Memimage*, Rectangle, void*);
|
||||
|
||||
struct Memscreen
|
||||
{
|
||||
Memimage *frontmost; /* frontmost layer on screen */
|
||||
Memimage *rearmost; /* rearmost layer on screen */
|
||||
Memimage *image; /* upon which all layers are drawn */
|
||||
Memimage *fill; /* if non-zero, picture to use when repainting */
|
||||
};
|
||||
|
||||
struct Memlayer
|
||||
{
|
||||
Rectangle screenr; /* true position of layer on screen */
|
||||
Point delta; /* add delta to go from image coords to screen */
|
||||
Memscreen *screen; /* screen this layer belongs to */
|
||||
Memimage *front; /* window in front of this one */
|
||||
Memimage *rear; /* window behind this one*/
|
||||
int clear; /* layer is fully visible */
|
||||
Memimage *save; /* save area for obscured parts */
|
||||
Refreshfn refreshfn; /* function to call to refresh obscured parts if save==nil */
|
||||
void *refreshptr; /* argument to refreshfn */
|
||||
};
|
||||
|
||||
/*
|
||||
* These functions accept local coordinates
|
||||
*/
|
||||
int memload(Memimage*, Rectangle, uchar*, int, int);
|
||||
int memunload(Memimage*, Rectangle, uchar*, int);
|
||||
|
||||
/*
|
||||
* All these functions accept screen coordinates, not local ones.
|
||||
*/
|
||||
void _memlayerop(void (*fn)(Memimage*, Rectangle, Rectangle, void*, int), Memimage*, Rectangle, Rectangle, void*);
|
||||
Memimage* memlalloc(Memscreen*, Rectangle, Refreshfn, void*, ulong);
|
||||
void memldelete(Memimage*);
|
||||
void memlfree(Memimage*);
|
||||
void memltofront(Memimage*);
|
||||
void memltofrontn(Memimage**, int);
|
||||
void _memltofrontfill(Memimage*, int);
|
||||
void memltorear(Memimage*);
|
||||
void memltorearn(Memimage**, int);
|
||||
int memlsetrefresh(Memimage*, Refreshfn, void*);
|
||||
void memlhide(Memimage*, Rectangle);
|
||||
void memlexpose(Memimage*, Rectangle);
|
||||
void _memlsetclear(Memscreen*);
|
||||
int memlorigin(Memimage*, Point, Point);
|
||||
void memlnorefresh(Memimage*, Rectangle, void*);
|
134
include/mp.h
Normal file
134
include/mp.h
Normal file
@ -0,0 +1,134 @@
|
||||
#define _MPINT 1
|
||||
|
||||
// the code assumes mpdigit to be at least an int
|
||||
// mpdigit must be an atomic type. mpdigit is defined
|
||||
// in the architecture specific u.h
|
||||
|
||||
typedef struct mpint mpint;
|
||||
|
||||
struct mpint
|
||||
{
|
||||
int sign; // +1 or -1
|
||||
int size; // allocated digits
|
||||
int top; // significant digits
|
||||
mpdigit *p;
|
||||
char flags;
|
||||
};
|
||||
|
||||
enum
|
||||
{
|
||||
MPstatic= 0x01,
|
||||
Dbytes= sizeof(mpdigit), // bytes per digit
|
||||
Dbits= Dbytes*8 // bits per digit
|
||||
};
|
||||
|
||||
// allocation
|
||||
void mpsetminbits(int n); // newly created mpint's get at least n bits
|
||||
mpint* mpnew(int n); // create a new mpint with at least n bits
|
||||
void mpfree(mpint *b);
|
||||
void mpbits(mpint *b, int n); // ensure that b has at least n bits
|
||||
void mpnorm(mpint *b); // dump leading zeros
|
||||
mpint* mpcopy(mpint *b);
|
||||
void mpassign(mpint *old, mpint *new);
|
||||
|
||||
// random bits
|
||||
mpint* mprand(int bits, void (*gen)(uchar*, int), mpint *b);
|
||||
|
||||
// conversion
|
||||
mpint* strtomp(char*, char**, int, mpint*); // ascii
|
||||
int mpfmt(Fmt*);
|
||||
char* mptoa(mpint*, int, char*, int);
|
||||
mpint* letomp(uchar*, uint, mpint*); // byte array, little-endian
|
||||
int mptole(mpint*, uchar*, uint, uchar**);
|
||||
mpint* betomp(uchar*, uint, mpint*); // byte array, little-endian
|
||||
int mptobe(mpint*, uchar*, uint, uchar**);
|
||||
uint mptoui(mpint*); // unsigned int
|
||||
mpint* uitomp(uint, mpint*);
|
||||
int mptoi(mpint*); // int
|
||||
mpint* itomp(int, mpint*);
|
||||
uvlong mptouv(mpint*); // unsigned vlong
|
||||
mpint* uvtomp(uvlong, mpint*);
|
||||
vlong mptov(mpint*); // vlong
|
||||
mpint* vtomp(vlong, mpint*);
|
||||
|
||||
// divide 2 digits by one
|
||||
void mpdigdiv(mpdigit *dividend, mpdigit divisor, mpdigit *quotient);
|
||||
|
||||
// in the following, the result mpint may be
|
||||
// the same as one of the inputs.
|
||||
void mpadd(mpint *b1, mpint *b2, mpint *sum); // sum = b1+b2
|
||||
void mpsub(mpint *b1, mpint *b2, mpint *diff); // diff = b1-b2
|
||||
void mpleft(mpint *b, int shift, mpint *res); // res = b<<shift
|
||||
void mpright(mpint *b, int shift, mpint *res); // res = b>>shift
|
||||
void mpmul(mpint *b1, mpint *b2, mpint *prod); // prod = b1*b2
|
||||
void mpexp(mpint *b, mpint *e, mpint *m, mpint *res); // res = b**e mod m
|
||||
void mpmod(mpint *b, mpint *m, mpint *remainder); // remainder = b mod m
|
||||
|
||||
// quotient = dividend/divisor, remainder = dividend % divisor
|
||||
void mpdiv(mpint *dividend, mpint *divisor, mpint *quotient, mpint *remainder);
|
||||
|
||||
// return neg, 0, pos as b1-b2 is neg, 0, pos
|
||||
int mpcmp(mpint *b1, mpint *b2);
|
||||
|
||||
// extended gcd return d, x, and y, s.t. d = gcd(a,b) and ax+by = d
|
||||
void mpextendedgcd(mpint *a, mpint *b, mpint *d, mpint *x, mpint *y);
|
||||
|
||||
// res = b**-1 mod m
|
||||
void mpinvert(mpint *b, mpint *m, mpint *res);
|
||||
|
||||
// bit counting
|
||||
int mpsignif(mpint*); // number of sigificant bits in mantissa
|
||||
int mplowbits0(mpint*); // k, where n = 2**k * q for odd q
|
||||
|
||||
// well known constants
|
||||
extern mpint *mpzero, *mpone, *mptwo;
|
||||
|
||||
// sum[0:alen] = a[0:alen-1] + b[0:blen-1]
|
||||
// prereq: alen >= blen, sum has room for alen+1 digits
|
||||
void mpvecadd(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *sum);
|
||||
|
||||
// diff[0:alen-1] = a[0:alen-1] - b[0:blen-1]
|
||||
// prereq: alen >= blen, diff has room for alen digits
|
||||
void mpvecsub(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *diff);
|
||||
|
||||
// p[0:n] += m * b[0:n-1]
|
||||
// prereq: p has room for n+1 digits
|
||||
void mpvecdigmuladd(mpdigit *b, int n, mpdigit m, mpdigit *p);
|
||||
|
||||
// p[0:n] -= m * b[0:n-1]
|
||||
// prereq: p has room for n+1 digits
|
||||
int mpvecdigmulsub(mpdigit *b, int n, mpdigit m, mpdigit *p);
|
||||
|
||||
// p[0:alen*blen-1] = a[0:alen-1] * b[0:blen-1]
|
||||
// prereq: alen >= blen, p has room for m*n digits
|
||||
void mpvecmul(mpdigit *a, int alen, mpdigit *b, int blen, mpdigit *p);
|
||||
|
||||
// sign of a - b or zero if the same
|
||||
int mpveccmp(mpdigit *a, int alen, mpdigit *b, int blen);
|
||||
|
||||
// divide the 2 digit dividend by the one digit divisor and stick in quotient
|
||||
// we assume that the result is one digit - overflow is all 1's
|
||||
void mpdigdiv(mpdigit *dividend, mpdigit divisor, mpdigit *quotient);
|
||||
|
||||
// playing with magnitudes
|
||||
int mpmagcmp(mpint *b1, mpint *b2);
|
||||
void mpmagadd(mpint *b1, mpint *b2, mpint *sum); // sum = b1+b2
|
||||
void mpmagsub(mpint *b1, mpint *b2, mpint *sum); // sum = b1+b2
|
||||
|
||||
// chinese remainder theorem
|
||||
typedef struct CRTpre CRTpre; // precomputed values for converting
|
||||
// twixt residues and mpint
|
||||
typedef struct CRTres CRTres; // residue form of an mpint
|
||||
|
||||
struct CRTres
|
||||
{
|
||||
int n; // number of residues
|
||||
mpint *r[1]; // residues
|
||||
};
|
||||
|
||||
CRTpre* crtpre(int, mpint**); // precompute conversion values
|
||||
CRTres* crtin(CRTpre*, mpint*); // convert mpint to residues
|
||||
void crtout(CRTpre*, CRTres*, mpint*); // convert residues to mpint
|
||||
void crtprefree(CRTpre*);
|
||||
void crtresfree(CRTres*);
|
||||
|
26
include/u.h
Normal file
26
include/u.h
Normal file
@ -0,0 +1,26 @@
|
||||
#include "dtos.h"
|
||||
|
||||
/* avoid name conflicts */
|
||||
#undef accept
|
||||
#undef listen
|
||||
|
||||
/* sys calls */
|
||||
#undef bind
|
||||
#undef chdir
|
||||
#undef close
|
||||
#undef create
|
||||
#undef dup
|
||||
#undef export
|
||||
#undef fstat
|
||||
#undef fwstat
|
||||
#undef mount
|
||||
#undef open
|
||||
#undef start
|
||||
#undef read
|
||||
#undef remove
|
||||
#undef seek
|
||||
#undef stat
|
||||
#undef write
|
||||
#undef wstat
|
||||
#undef unmount
|
||||
#undef pipe
|
14
include/unix.h
Normal file
14
include/unix.h
Normal file
@ -0,0 +1,14 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include <fcntl.h>
|
||||
#include <setjmp.h>
|
||||
#include <time.h>
|
||||
#include <assert.h>
|
||||
#include <unistd.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
typedef long long p9_vlong;
|
||||
typedef unsigned long long p9_uvlong;
|
65
include/user.h
Normal file
65
include/user.h
Normal file
@ -0,0 +1,65 @@
|
||||
/* sys calls */
|
||||
#define bind sysbind
|
||||
#define chdir syschdir
|
||||
#define close sysclose
|
||||
#define create syscreate
|
||||
#define dup sysdup
|
||||
#define export sysexport
|
||||
#define fstat sysfstat
|
||||
#define fwstat sysfwstat
|
||||
#define mount sysmount
|
||||
#define open sysopen
|
||||
#define read sysread
|
||||
#define remove sysremove
|
||||
#define seek sysseek
|
||||
#define stat sysstat
|
||||
#define write syswrite
|
||||
#define wstat syswstat
|
||||
#define unmount sysunmount
|
||||
#define pipe syspipe
|
||||
#define rendezvous sysrendezvous
|
||||
#define getpid sysgetpid
|
||||
#define time systime
|
||||
#define nsec sysnsec
|
||||
#define pread syspread
|
||||
#define pwrite syspwrite
|
||||
|
||||
extern int bind(char*, char*, int);
|
||||
extern int chdir(char*);
|
||||
extern int close(int);
|
||||
extern int create(char*, int, ulong);
|
||||
extern int dup(int, int);
|
||||
extern int export(int);
|
||||
extern int fstat(int, uchar*, int);
|
||||
extern int fwstat(int, uchar*, int);
|
||||
extern int mount(int, int, char*, int, char*);
|
||||
extern int unmount(char*, char*);
|
||||
extern int open(char*, int);
|
||||
extern int pipe(int*);
|
||||
extern long read(int, void*, long);
|
||||
extern long readn(int, void*, long);
|
||||
extern int remove(char*);
|
||||
extern vlong seek(int, vlong, int);
|
||||
extern int stat(char*, uchar*, int);
|
||||
extern long write(int, void*, long);
|
||||
extern int wstat(char*, uchar*, int);
|
||||
|
||||
extern Dir *dirstat(char*);
|
||||
extern Dir *dirfstat(int);
|
||||
extern int dirwstat(char*, Dir*);
|
||||
extern int dirfwstat(int, Dir*);
|
||||
extern long dirread(int, Dir*, long);
|
||||
|
||||
/*
|
||||
* network dialing and authentication
|
||||
*/
|
||||
#define NETPATHLEN 40
|
||||
extern int accept(int, char*);
|
||||
extern int announce(char*, char*);
|
||||
extern int dial(char*, char*, char*, int*);
|
||||
extern int hangup(int);
|
||||
extern int listen(char*, char*);
|
||||
extern char *netmkaddr(char*, char*, char*);
|
||||
extern int reject(int, char*, char*);
|
||||
|
||||
extern char* argv0;
|
6
include/x.c
Normal file
6
include/x.c
Normal file
@ -0,0 +1,6 @@
|
||||
#include <stdio.h>
|
||||
|
||||
void
|
||||
main(void)
|
||||
{
|
||||
}
|
Reference in New Issue
Block a user