ape: move compatibility libc.h to lib9 directory and incooperate needed functions for ape/mp (wip)
This commit is contained in:
parent
ea6910b706
commit
3238f124b8
3
sys/src/ape/lib/9/argv0.c
Normal file
3
sys/src/ape/lib/9/argv0.c
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
#include <lib9.h>
|
||||||
|
|
||||||
|
char *argv0;
|
|
@ -1,6 +1,7 @@
|
||||||
#define _LOCK_EXTENSION
|
#define _LOCK_EXTENSION
|
||||||
#define _QLOCK_EXTENSION
|
#define _QLOCK_EXTENSION
|
||||||
#define _BSD_EXTENSION
|
#define _BSD_EXTENSION
|
||||||
|
#include <stdint.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <lock.h>
|
#include <lock.h>
|
||||||
#include <qlock.h>
|
#include <qlock.h>
|
||||||
|
@ -15,6 +16,8 @@
|
||||||
#include <fmt.h>
|
#include <fmt.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
|
|
||||||
|
#define nelem(x) (sizeof(x)/sizeof((x)[0]))
|
||||||
|
|
||||||
typedef
|
typedef
|
||||||
struct Qid
|
struct Qid
|
||||||
{
|
{
|
||||||
|
@ -97,10 +100,11 @@ extern int _STAT(const char*, unsigned char*, int);
|
||||||
extern Waitmsg* _WAIT(void);
|
extern Waitmsg* _WAIT(void);
|
||||||
extern long _WRITE(int, const void*, long);
|
extern long _WRITE(int, const void*, long);
|
||||||
extern int _WSTAT(const char*, unsigned char*, int);
|
extern int _WSTAT(const char*, unsigned char*, int);
|
||||||
extern void *_MALLOCZ(int, int);
|
extern void* _MALLOCZ(int, int);
|
||||||
extern int _WERRSTR(char*, ...);
|
extern int _WERRSTR(char*, ...);
|
||||||
extern long _READN(int, void*, long);
|
extern long _READN(int, void*, long);
|
||||||
extern int _IOUNIT(int);
|
extern int _IOUNIT(int);
|
||||||
|
extern vlong _NSEC(void);
|
||||||
|
|
||||||
#define dirstat _dirstat
|
#define dirstat _dirstat
|
||||||
#define dirfstat _dirfstat
|
#define dirfstat _dirfstat
|
||||||
|
@ -115,23 +119,35 @@ extern int _IOUNIT(int);
|
||||||
#define AEXEC 1
|
#define AEXEC 1
|
||||||
#define AEXIST 0
|
#define AEXIST 0
|
||||||
|
|
||||||
#define open _OPEN
|
|
||||||
#define close _CLOSE
|
|
||||||
#define read _READ
|
|
||||||
#define write _WRITE
|
|
||||||
#define _exits(s) _exit(s && *(char*)s ? 1 : 0)
|
#define _exits(s) _exit(s && *(char*)s ? 1 : 0)
|
||||||
#define exits(s) exit(s && *(char*)s ? 1 : 0)
|
#define exits(s) exit(s && *(char*)s ? 1 : 0)
|
||||||
#define create _CREATE
|
|
||||||
#define pread _PREAD
|
#define create(file, omode, perm) open(file, (omode) |O_CREAT | O_TRUNC, perm)
|
||||||
|
#define seek(fd, off, dir) lseek(fd, off, dir)
|
||||||
|
|
||||||
#define readn _READN
|
#define readn _READN
|
||||||
|
#define pread _PREAD
|
||||||
|
#define pwrite _PWRITE
|
||||||
#define mallocz _MALLOCZ
|
#define mallocz _MALLOCZ
|
||||||
|
#define nsec _NSEC
|
||||||
#define iounit _IOUNIT
|
#define iounit _IOUNIT
|
||||||
|
|
||||||
/* assume being called as in event.c */
|
#define postnote(who,pid,note) kill(pid,SIGTERM)
|
||||||
#define postnote(x, pid, msg) kill(pid, SIGTERM)
|
#define atnotify(func,in)
|
||||||
#define atnotify(x, y) signal(SIGTERM, ekill)
|
|
||||||
|
|
||||||
#define ERRMAX 128
|
#define ERRMAX 128
|
||||||
|
|
||||||
extern void setmalloctag(void*, ulong);
|
extern void setmalloctag(void*, uintptr_t);
|
||||||
extern ulong getcallerpc(void*);
|
extern void setrealloctag(void*, uintptr_t);
|
||||||
|
extern uintptr_t getcallerpc(void*);
|
||||||
|
|
||||||
|
extern int dec16(uchar *, int, char *, int);
|
||||||
|
extern int enc16(char *, int, uchar *, int);
|
||||||
|
extern int dec32(uchar *, int, char *, int);
|
||||||
|
extern int enc32(char *, int, uchar *, int);
|
||||||
|
extern int dec64(uchar *, int, char *, int);
|
||||||
|
extern int enc64(char *, int, uchar *, int);
|
||||||
|
|
||||||
|
extern int tokenize(char*, char**, int);
|
||||||
|
extern void sysfatal(char*, ...);
|
||||||
|
extern ulong truerand(void); /* uses /dev/random */
|
|
@ -2,7 +2,8 @@ APE=/sys/src/ape
|
||||||
<$APE/config
|
<$APE/config
|
||||||
|
|
||||||
LIB=/$objtype/lib/ape/lib9.a
|
LIB=/$objtype/lib/ape/lib9.a
|
||||||
OFILES=errstr.$O\
|
OFILES=argv0.$O\
|
||||||
|
errstr.$O\
|
||||||
bind.$O\
|
bind.$O\
|
||||||
getcallerpc.$O\
|
getcallerpc.$O\
|
||||||
getfcr.$O\
|
getfcr.$O\
|
||||||
|
@ -14,6 +15,13 @@ OFILES=errstr.$O\
|
||||||
segflush.$O\
|
segflush.$O\
|
||||||
segfree.$O\
|
segfree.$O\
|
||||||
setmalloctag.$O\
|
setmalloctag.$O\
|
||||||
|
setrealloctag.$O\
|
||||||
|
sysfatal.$O\
|
||||||
|
tokenize.$O\
|
||||||
|
truerand.$O\
|
||||||
|
u16.$O\
|
||||||
|
u32.$O\
|
||||||
|
u64.$O\
|
||||||
unmount.$O\
|
unmount.$O\
|
||||||
|
|
||||||
</sys/src/cmd/mksyslib
|
</sys/src/cmd/mksyslib
|
||||||
|
@ -28,3 +36,21 @@ CFLAGS=-c $CFLAGS -D_POSIX_SOURCE -D_PLAN9_SOURCE
|
||||||
|
|
||||||
%.$O: $objtype/%.c
|
%.$O: $objtype/%.c
|
||||||
$CC $CFLAGS $prereq
|
$CC $CFLAGS $prereq
|
||||||
|
|
||||||
|
sysfatal.$O: ../../../libc/9sys/sysfatal.c
|
||||||
|
$CC $CFLAGS -I. ../../../libc/9sys/sysfatal.c
|
||||||
|
|
||||||
|
tokenize.$O: ../../../libc/port/tokenize.c
|
||||||
|
$CC $CFLAGS -I. ../../../libc/port/tokenize.c
|
||||||
|
|
||||||
|
truerand.$O: ../../../libc/9sys/truerand.c
|
||||||
|
$CC $CFLAGS -I. ../../../libc/9sys/truerand.c
|
||||||
|
|
||||||
|
u16.$O: ../../../libc/port/u16.c
|
||||||
|
$CC $CFLAGS -I. ../../../libc/port/u16.c
|
||||||
|
|
||||||
|
u32.$O: ../../../libc/port/u32.c
|
||||||
|
$CC $CFLAGS -I. ../../../libc/port/u32.c
|
||||||
|
|
||||||
|
u64.$O: ../../../libc/port/u64.c
|
||||||
|
$CC $CFLAGS -I. ../../../libc/port/u64.c
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
void
|
void
|
||||||
setmalloctag(void*, unsigned long)
|
setmalloctag(void*, uintptr_t)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
6
sys/src/ape/lib/9/setrealloctag.c
Normal file
6
sys/src/ape/lib/9/setrealloctag.c
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
void
|
||||||
|
setrealloctag(void*, uintptr_t)
|
||||||
|
{
|
||||||
|
}
|
|
@ -1,203 +0,0 @@
|
||||||
#include <u.h>
|
|
||||||
#include <libc.h>
|
|
||||||
#include <draw.h>
|
|
||||||
#include <event.h>
|
|
||||||
|
|
||||||
char *argv0;
|
|
||||||
|
|
||||||
static void
|
|
||||||
_sysfatalimpl(char *fmt, va_list arg)
|
|
||||||
{
|
|
||||||
char buf[1024];
|
|
||||||
|
|
||||||
vseprint(buf, buf+sizeof(buf), fmt, arg);
|
|
||||||
if(argv0)
|
|
||||||
fprint(2, "%s: %s\n", argv0, buf);
|
|
||||||
else
|
|
||||||
fprint(2, "%s\n", buf);
|
|
||||||
exits(buf);
|
|
||||||
}
|
|
||||||
|
|
||||||
void (*_sysfatal)(char *fmt, va_list arg) = _sysfatalimpl;
|
|
||||||
|
|
||||||
void
|
|
||||||
sysfatal(char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list arg;
|
|
||||||
|
|
||||||
va_start(arg, fmt);
|
|
||||||
(*_sysfatal)(fmt, arg);
|
|
||||||
va_end(arg);
|
|
||||||
}
|
|
||||||
|
|
||||||
int nbit, npix;
|
|
||||||
Image *pixel;
|
|
||||||
Rectangle crect[256];
|
|
||||||
|
|
||||||
Image *color[256];
|
|
||||||
|
|
||||||
void
|
|
||||||
eresized(int new)
|
|
||||||
{
|
|
||||||
int x, y, i, n, nx, ny;
|
|
||||||
Rectangle r, b;
|
|
||||||
|
|
||||||
if(new && getwindow(display, Refnone) < 0){
|
|
||||||
fprint(2, "colors: can't reattach to window: %r\n");
|
|
||||||
exits("resized");
|
|
||||||
}
|
|
||||||
if(screen->depth > 8){
|
|
||||||
n = 256;
|
|
||||||
nx = 16;
|
|
||||||
}else{
|
|
||||||
n = 1<<screen->depth;
|
|
||||||
nx = 1<<(screen->depth/2);
|
|
||||||
}
|
|
||||||
|
|
||||||
ny = n/nx;
|
|
||||||
draw(screen, screen->r, display->white, nil, ZP);
|
|
||||||
r = insetrect(screen->r, 5);
|
|
||||||
r.min.y+=20;
|
|
||||||
b.max.y=r.min.y;
|
|
||||||
for(i=n-1, y=0; y!=ny; y++){
|
|
||||||
b.min.y=b.max.y;
|
|
||||||
b.max.y=r.min.y+(r.max.y-r.min.y)*(y+1)/ny;
|
|
||||||
b.max.x=r.min.x;
|
|
||||||
for(x=0; x!=nx; x++, --i){
|
|
||||||
b.min.x=b.max.x;
|
|
||||||
b.max.x=r.min.x+(r.max.x-r.min.x)*(x+1)/nx;
|
|
||||||
crect[i]=insetrect(b, 1);
|
|
||||||
draw(screen, crect[i], color[i], nil, ZP);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
flushimage(display, 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
char *buttons[] =
|
|
||||||
{
|
|
||||||
"exit",
|
|
||||||
0
|
|
||||||
};
|
|
||||||
|
|
||||||
ulong
|
|
||||||
grey(int i)
|
|
||||||
{
|
|
||||||
if(i < 0)
|
|
||||||
return grey(0);
|
|
||||||
if(i > 255)
|
|
||||||
return grey(255);
|
|
||||||
return (i<<16)+(i<<8)+i;
|
|
||||||
}
|
|
||||||
|
|
||||||
Menu menu =
|
|
||||||
{
|
|
||||||
buttons
|
|
||||||
};
|
|
||||||
|
|
||||||
int
|
|
||||||
dither[16] = {
|
|
||||||
0, 8, 2, 10,
|
|
||||||
12, 4, 14, 6,
|
|
||||||
3, 11, 1, 9,
|
|
||||||
15, 7, 13, 5
|
|
||||||
};
|
|
||||||
|
|
||||||
void
|
|
||||||
main(int argc, char *argv[])
|
|
||||||
{
|
|
||||||
Point p;
|
|
||||||
Mouse m;
|
|
||||||
int i, j, k, l, n, ramp, prev;
|
|
||||||
char buf[100];
|
|
||||||
char *fmt;
|
|
||||||
Image *dark;
|
|
||||||
ulong rgb;
|
|
||||||
|
|
||||||
ramp = 0;
|
|
||||||
|
|
||||||
fmt = "index %3d r %3lud g %3lud b %3lud 0x%.8luX ";
|
|
||||||
/*
|
|
||||||
ARGBEGIN{
|
|
||||||
default:
|
|
||||||
goto Usage;
|
|
||||||
case 'x':
|
|
||||||
fmt = "index %2luX r %3luX g %3luX b %3luX 0x%.8luX ";
|
|
||||||
break;
|
|
||||||
case 'r':
|
|
||||||
ramp = 1;
|
|
||||||
break;
|
|
||||||
}ARGEND
|
|
||||||
*/
|
|
||||||
argv0 = argv[0];
|
|
||||||
if(argc != 1){
|
|
||||||
Usage:
|
|
||||||
fprint(2, "Usage: %s [-rx]\n", argv0);
|
|
||||||
exits("usage");
|
|
||||||
}
|
|
||||||
|
|
||||||
if(initdraw(nil, nil, "colors") < 0)
|
|
||||||
sysfatal("initdraw failed: %r");
|
|
||||||
einit(Emouse);
|
|
||||||
|
|
||||||
for(i=0; i<256; i++){
|
|
||||||
if(ramp){
|
|
||||||
if(screen->chan == CMAP8){
|
|
||||||
/* dither the fine grey */
|
|
||||||
j = i-(i%17);
|
|
||||||
dark = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(j)<<8)+0xFF);
|
|
||||||
color[i] = allocimage(display, Rect(0,0,4,4), screen->chan, 1, (grey(j+17)<<8)+0xFF);
|
|
||||||
for(j=0; j<16; j++){
|
|
||||||
k = j%4;
|
|
||||||
l = j/4;
|
|
||||||
if(dither[j] > (i%17))
|
|
||||||
draw(color[i], Rect(k, l, k+1, l+1), dark, nil, ZP);
|
|
||||||
}
|
|
||||||
freeimage(dark);
|
|
||||||
}else
|
|
||||||
color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (grey(i)<<8)+0xFF);
|
|
||||||
}else
|
|
||||||
color[i] = allocimage(display, Rect(0,0,1,1), screen->chan, 1, (cmap2rgb(i)<<8)+0xFF);
|
|
||||||
if(color[i] == nil)
|
|
||||||
sysfatal("can't allocate image: %r");
|
|
||||||
}
|
|
||||||
eresized(0);
|
|
||||||
prev = -1;
|
|
||||||
for(;;){
|
|
||||||
m = emouse();
|
|
||||||
switch(m.buttons){
|
|
||||||
case 1:
|
|
||||||
while(m.buttons){
|
|
||||||
if(screen->depth > 8)
|
|
||||||
n = 256;
|
|
||||||
else
|
|
||||||
n = 1<<screen->depth;
|
|
||||||
for(i=0; i!=n; i++)
|
|
||||||
if(i!=prev && ptinrect(m.xy, crect[i])){
|
|
||||||
if(ramp)
|
|
||||||
rgb = grey(i);
|
|
||||||
else
|
|
||||||
rgb = cmap2rgb(i);
|
|
||||||
sprint(buf, fmt,
|
|
||||||
i,
|
|
||||||
(rgb>>16)&0xFF,
|
|
||||||
(rgb>>8)&0xFF,
|
|
||||||
rgb&0xFF,
|
|
||||||
(rgb<<8) | 0xFF);
|
|
||||||
p = addpt(screen->r.min, Pt(2,2));
|
|
||||||
draw(screen, Rpt(p, addpt(p, stringsize(font, buf))), display->white, nil, p);
|
|
||||||
string(screen, p, display->black, ZP, font, buf);
|
|
||||||
prev=i;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
m = emouse();
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
|
|
||||||
case 4:
|
|
||||||
switch(emenuhit(3, &m, &menu)){
|
|
||||||
case 0:
|
|
||||||
exits(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -70,10 +70,13 @@ UPDATE=\
|
||||||
|
|
||||||
</sys/src/cmd/mksyslib
|
</sys/src/cmd/mksyslib
|
||||||
|
|
||||||
CFLAGS=-c $CFLAGS -D_POSIX_SOURCE -D_PLAN9_SOURCE -I.
|
CFLAGS=-c $CFLAGS -D_POSIX_SOURCE -D_PLAN9_SOURCE -I../9
|
||||||
|
|
||||||
%.$O: /sys/src/libdraw/%.c
|
%.$O: /sys/src/libdraw/%.c
|
||||||
$CC $CFLAGS /sys/src/libdraw/$stem.c
|
$CC $CFLAGS /sys/src/libdraw/$stem.c
|
||||||
|
|
||||||
|
colors.$O: /sys/src/cmd/colors.c
|
||||||
|
$CC $CFLAGS /sys/src/cmd/colors.c
|
||||||
|
|
||||||
$O.colors: colors.$O
|
$O.colors: colors.$O
|
||||||
$LD -o $target colors.$O
|
$LD -o $target colors.$O
|
||||||
|
|
Loading…
Reference in a new issue