mirror of https://git.cro.wtf/kip.git
liba:xcd
This commit is contained in:
parent
ba5bc4cc2e
commit
9b85fb2c56
2
a.c
2
a.c
|
@ -3,9 +3,11 @@
|
|||
#undef realloc
|
||||
#undef free
|
||||
#undef fopen
|
||||
#undef chdir
|
||||
NR V die(IM C*f,...)VA(f,vfprintf(stderr,f,ap),fputc('\n',stderr),exit(1))
|
||||
V asrt(B b,IM C*m){N(b,die(m))}
|
||||
V*mk(W sz){V*p;N(p=calloc(1,sz),die("oom"))R p;}
|
||||
V*remk(V*p,W sz){N(p=realloc(p,sz),die("oom"))R p;}
|
||||
V del(V*p){free(p);}
|
||||
F xopen(IM C*n,IM C*p){F f;N(f=fopen(n,p),die("unable to open file `%s`",n))R f;}
|
||||
V xcd(IM C*n){Q(chdir(n),die("unable to cd into directory `%s`",n));}
|
||||
|
|
8
a.h
8
a.h
|
@ -29,7 +29,9 @@ V*mk(W);
|
|||
V*remk(V*,W);
|
||||
V del(V*);
|
||||
F xopen(IM C*,IM C*);
|
||||
#define malloc B use_mk_instead[-1]
|
||||
V xcd(IM C*);
|
||||
#define malloc B use_mk_instead[-1]
|
||||
#define realloc B use_remk_instead[-1]
|
||||
#define free B use_del_instead[-1]
|
||||
#define fopen B use_xopen_instead[-1]
|
||||
#define free B use_del_instead[-1]
|
||||
#define fopen B use_xopen_instead[-1]
|
||||
#define chdir B use_xcd_instead[-1]
|
||||
|
|
2
as.c
2
as.c
|
@ -64,6 +64,6 @@ I main(I ac,C**av){FILE *f;
|
|||
Q(3!=ac,die("usage: as INPUT.ASM OUTPUT.ROM"))
|
||||
/*todo:this is undefined behaviour for binary streams (SEEK_END)*/
|
||||
WIF(f,av[1],"rb",fseek(f,0,SEEK_END),inl=ftell(f),fseek(f,0,SEEK_SET),inb=mk(inl+1),fread(inb,1,inl,f))
|
||||
WIF(f,av[2],"wb",Q(chdir(dirname(av[1])),die("?"))inb[inl]=0,run(),del(inb),fwrite(meb+0x100,1,mel-0x100,f))
|
||||
WIF(f,av[2],"wb",xcd(dirname(av[1])),inb[inl]=0,run(),del(inb),fwrite(meb+0x100,1,mel-0x100,f))
|
||||
printf("done: %d bytes wrote\n",mel-0x100);
|
||||
R 0;}
|
||||
|
|
Loading…
Reference in New Issue