Commit 5a68303a authored by Russ Cox's avatar Russ Cox

throw away most of the compat.h compatibility layer

in favor of the lib9 compatibility layer.  no need for two.

now that mycreate is gone, .6 files are 0644 not 0755.

TBR=r
OCL=26679
CL=26679
parent fcd76f7d
...@@ -86,16 +86,13 @@ main(int argc, char *argv[]) ...@@ -86,16 +86,13 @@ main(int argc, char *argv[])
c = 0; c = 0;
nout = 0; nout = 0;
for(;;) { for(;;) {
Waitmsg *w;
while(nout < nproc && argc > 0) { while(nout < nproc && argc > 0) {
i = myfork(); i = fork();
if(i < 0) { if(i < 0) {
i = mywait(&status); fprint(2, "fork: %r\n");
if(i < 0)
errorexit(); errorexit();
if(status)
c++;
nout--;
continue;
} }
if(i == 0) { if(i == 0) {
print("%s:\n", *argv); print("%s:\n", *argv);
...@@ -107,13 +104,13 @@ main(int argc, char *argv[]) ...@@ -107,13 +104,13 @@ main(int argc, char *argv[])
argc--; argc--;
argv++; argv++;
} }
i = mywait(&status); w = wait();
if(i < 0) { if(w == nil) {
if(c) if(c)
errorexit(); errorexit();
exits(0); exits(0);
} }
if(status) if(w->msg[0])
c++; c++;
nout--; nout--;
} }
...@@ -160,7 +157,7 @@ assemble(char *file) ...@@ -160,7 +157,7 @@ assemble(char *file)
} }
} }
of = mycreat(outfile, 0664); of = create(outfile, OWRITE, 0664);
if(of < 0) { if(of < 0) {
yyerror("%ca: cannot create %s", thechar, outfile); yyerror("%ca: cannot create %s", thechar, outfile);
errorexit(); errorexit();
......
...@@ -33,11 +33,30 @@ ...@@ -33,11 +33,30 @@
#include "y.tab.h" #include "y.tab.h"
#include <ctype.h> #include <ctype.h>
enum
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2,
};
int
systemtype(int sys)
{
return sys&Plan9;
}
int
pathchar(void)
{
return '/';
}
void void
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *p; char *p;
int nout, nproc, status, i, c; int nout, nproc, i, c;
thechar = '6'; thechar = '6';
thestring = "amd64"; thestring = "amd64";
...@@ -83,16 +102,13 @@ main(int argc, char *argv[]) ...@@ -83,16 +102,13 @@ main(int argc, char *argv[])
c = 0; c = 0;
nout = 0; nout = 0;
for(;;) { for(;;) {
Waitmsg *w;
while(nout < nproc && argc > 0) { while(nout < nproc && argc > 0) {
i = myfork(); i = fork();
if(i < 0) { if(i < 0) {
i = mywait(&status); fprint(2, "fork: %r\n");
if(i < 0)
errorexit(); errorexit();
if(status)
c++;
nout--;
continue;
} }
if(i == 0) { if(i == 0) {
print("%s:\n", *argv); print("%s:\n", *argv);
...@@ -104,13 +120,13 @@ main(int argc, char *argv[]) ...@@ -104,13 +120,13 @@ main(int argc, char *argv[])
argc--; argc--;
argv++; argv++;
} }
i = mywait(&status); w = wait();
if(i < 0) { if(w == nil) {
if(c) if(c)
errorexit(); errorexit();
exits(0); exits(0);
} }
if(status) if(w->msg[0])
c++; c++;
nout--; nout--;
} }
...@@ -157,7 +173,7 @@ assemble(char *file) ...@@ -157,7 +173,7 @@ assemble(char *file)
} }
} }
of = mycreate(outfile, 0664); of = create(outfile, OWRITE, 0664);
if(of < 0) { if(of < 0) {
yyerror("%ca: cannot create %s", thechar, outfile); yyerror("%ca: cannot create %s", thechar, outfile);
errorexit(); errorexit();
...@@ -1044,9 +1060,9 @@ cinit(void) ...@@ -1044,9 +1060,9 @@ cinit(void)
} }
pathname = allocn(pathname, 0, 100); pathname = allocn(pathname, 0, 100);
if(mygetwd(pathname, 99) == 0) { if(getwd(pathname, 99) == 0) {
pathname = allocn(pathname, 100, 900); pathname = allocn(pathname, 100, 900);
if(mygetwd(pathname, 999) == 0) if(getwd(pathname, 999) == 0)
strcpy(pathname, "/???"); strcpy(pathname, "/???");
} }
} }
......
...@@ -182,7 +182,7 @@ asmb(void) ...@@ -182,7 +182,7 @@ asmb(void)
case 6: case 6:
debug['8'] = 1; /* 64-bit addresses */ debug['8'] = 1; /* 64-bit addresses */
v = HEADR+textsize; v = HEADR+textsize;
myseek(cout, v); seek(cout, v, 0);
v = rnd(v, 4096) - v; v = rnd(v, 4096) - v;
while(v > 0) { while(v > 0) {
cput(0); cput(0);
...@@ -197,7 +197,7 @@ asmb(void) ...@@ -197,7 +197,7 @@ asmb(void)
strtabsize = linuxstrtable(); strtabsize = linuxstrtable();
cflush(); cflush();
v = rnd(HEADR+textsize, INITRND); v = rnd(HEADR+textsize, INITRND);
myseek(cout, v); seek(cout, v, 0);
break; break;
} }
......
...@@ -82,16 +82,13 @@ main(int argc, char *argv[]) ...@@ -82,16 +82,13 @@ main(int argc, char *argv[])
c = 0; c = 0;
nout = 0; nout = 0;
for(;;) { for(;;) {
Waitmsg *w;
while(nout < nproc && argc > 0) { while(nout < nproc && argc > 0) {
i = myfork(); i = fork();
if(i < 0) { if(i < 0) {
i = mywait(&status); fprint(2, "fork: %r\n");
if(i < 0)
errorexit(); errorexit();
if(status)
c++;
nout--;
continue;
} }
if(i == 0) { if(i == 0) {
print("%s:\n", *argv); print("%s:\n", *argv);
...@@ -103,13 +100,13 @@ main(int argc, char *argv[]) ...@@ -103,13 +100,13 @@ main(int argc, char *argv[])
argc--; argc--;
argv++; argv++;
} }
i = mywait(&status); w = wait();
if(i < 0) { if(w == nil) {
if(c) if(c)
errorexit(); errorexit();
exits(0); exits(0);
} }
if(status) if(w->msg[0])
c++; c++;
nout--; nout--;
} }
...@@ -156,7 +153,7 @@ assemble(char *file) ...@@ -156,7 +153,7 @@ assemble(char *file)
} }
} }
of = mycreate(outfile, 0664); of = create(outfile, OWRITE, 0664);
if(of < 0) { if(of < 0) {
yyerror("%ca: cannot create %s", thechar, outfile); yyerror("%ca: cannot create %s", thechar, outfile);
errorexit(); errorexit();
......
...@@ -32,7 +32,6 @@ ...@@ -32,7 +32,6 @@
#include <libc.h> #include <libc.h>
#include <bio.h> #include <bio.h>
#include <ctype.h> #include <ctype.h>
#include "compat.h"
#pragma lib "../cc/cc.a$O" #pragma lib "../cc/cc.a$O"
...@@ -542,17 +541,8 @@ extern uint32 thash[]; ...@@ -542,17 +541,8 @@ extern uint32 thash[];
/* /*
* compat.c/unix.c/windows.c * compat.c/unix.c/windows.c
*/ */
int mywait(int*);
int mycreat(char*, int);
int systemtype(int); int systemtype(int);
int pathchar(void); int pathchar(void);
int myaccess(char*);
char* mygetwd(char*, int);
int myexec(char*, char*[]);
int mydup(int, int);
int myfork(void);
int mypipe(int*);
void* mysbrk(uint32);
/* /*
* parser * parser
...@@ -794,3 +784,14 @@ int machcap(Node*); ...@@ -794,3 +784,14 @@ int machcap(Node*);
#pragma varargck type "O" int #pragma varargck type "O" int
#pragma varargck type "T" Type* #pragma varargck type "T" Type*
#pragma varargck type "|" int #pragma varargck type "|" int
enum
{
Plan9 = 1<<0,
Unix = 1<<1,
Windows = 1<<2,
};
int pathchar(void);
int systemtype(int);
void* alloc(int32 n);
void* allocn(void*, int32, int32);
...@@ -35,6 +35,19 @@ ...@@ -35,6 +35,19 @@
#define CPP "/bin/cpp" #define CPP "/bin/cpp"
#endif #endif
int
systemtype(int sys)
{
return sys&Plan9;
}
int
pathchar(void)
{
return '/';
}
/* /*
* known debug flags * known debug flags
* -a acid declaration output * -a acid declaration output
...@@ -67,7 +80,7 @@ void ...@@ -67,7 +80,7 @@ void
main(int argc, char *argv[]) main(int argc, char *argv[])
{ {
char *defs[50], *p; char *defs[50], *p;
int nproc, nout, status, i, c, ndef; int nproc, nout, i, c, ndef;
memset(debug, 0, sizeof(debug)); memset(debug, 0, sizeof(debug));
tinit(); tinit();
...@@ -132,19 +145,14 @@ main(int argc, char *argv[]) ...@@ -132,19 +145,14 @@ main(int argc, char *argv[])
c = 0; c = 0;
nout = 0; nout = 0;
for(;;) { for(;;) {
Waitmsg *w;
while(nout < nproc && argc > 0) { while(nout < nproc && argc > 0) {
i = myfork(); i = fork();
if(i < 0) {
i = mywait(&status);
if(i < 0) { if(i < 0) {
print("cannot create a process\n"); print("cannot create a process\n");
errorexit(); errorexit();
} }
if(status)
c++;
nout--;
continue;
}
if(i == 0) { if(i == 0) {
fprint(2, "%s:\n", *argv); fprint(2, "%s:\n", *argv);
if (compile(*argv, defs, ndef)) if (compile(*argv, defs, ndef))
...@@ -155,13 +163,13 @@ main(int argc, char *argv[]) ...@@ -155,13 +163,13 @@ main(int argc, char *argv[])
argc--; argc--;
argv++; argv++;
} }
i = mywait(&status); w = wait();
if(i < 0) { if(w == nil) {
if(c) if(c)
errorexit(); errorexit();
exits(0); exits(0);
} }
if(status) if(w->msg[0])
c++; c++;
nout--; nout--;
} }
...@@ -236,7 +244,7 @@ compile(char *file, char **defs, int ndef) ...@@ -236,7 +244,7 @@ compile(char *file, char **defs, int ndef)
dup(2, 1); dup(2, 1);
} }
} else { } else {
c = mycreate(outfile, 0664); c = create(outfile, OWRITE, 0664);
if(c < 0) { if(c < 0) {
diag(Z, "cannot open %s - %r", outfile); diag(Z, "cannot open %s - %r", outfile);
outfile = 0; outfile = 0;
...@@ -254,21 +262,21 @@ compile(char *file, char **defs, int ndef) ...@@ -254,21 +262,21 @@ compile(char *file, char **defs, int ndef)
diag(Z, "-p option not supported on windows"); diag(Z, "-p option not supported on windows");
errorexit(); errorexit();
} }
if(myaccess(file) < 0) { if(access(file, AREAD) < 0) {
diag(Z, "%s does not exist", file); diag(Z, "%s does not exist", file);
errorexit(); errorexit();
} }
if(mypipe(fd) < 0) { if(pipe(fd) < 0) {
diag(Z, "pipe failed"); diag(Z, "pipe failed");
errorexit(); errorexit();
} }
switch(myfork()) { switch(fork()) {
case -1: case -1:
diag(Z, "fork failed"); diag(Z, "fork failed");
errorexit(); errorexit();
case 0: case 0:
close(fd[0]); close(fd[0]);
mydup(fd[1], 1); dup(fd[1], 1);
close(fd[1]); close(fd[1]);
av[0] = CPP; av[0] = CPP;
i = 1; i = 1;
...@@ -296,7 +304,7 @@ compile(char *file, char **defs, int ndef) ...@@ -296,7 +304,7 @@ compile(char *file, char **defs, int ndef)
fprint(2, "%s ", av[c]); fprint(2, "%s ", av[c]);
fprint(2, "\n"); fprint(2, "\n");
} }
myexec(av[0], av); exec(av[0], av);
fprint(2, "can't exec C preprocessor %s: %r\n", CPP); fprint(2, "can't exec C preprocessor %s: %r\n", CPP);
errorexit(); errorexit();
default: default:
...@@ -1266,9 +1274,9 @@ cinit(void) ...@@ -1266,9 +1274,9 @@ cinit(void)
dclstack = D; dclstack = D;
pathname = allocn(pathname, 0, 100); pathname = allocn(pathname, 0, 100);
if(mygetwd(pathname, 99) == 0) { if(getwd(pathname, 99) == 0) {
pathname = allocn(pathname, 100, 900); pathname = allocn(pathname, 100, 900);
if(mygetwd(pathname, 999) == 0) if(getwd(pathname, 999) == 0)
strcpy(pathname, "/???"); strcpy(pathname, "/???");
} }
...@@ -1540,3 +1548,33 @@ setinclude(char *p) ...@@ -1540,3 +1548,33 @@ setinclude(char *p)
p = e+1; p = e+1;
} }
} }
void*
alloc(int32 n)
{
void *p;
p = malloc(n);
if(p == nil) {
print("alloc out of mem\n");
exit(1);
}
memset(p, 0, n);
return p;
}
void*
allocn(void *p, int32 n, int32 d)
{
if(p == nil)
return alloc(d);
p = realloc(p, n+d);
if(p == nil) {
print("allocn out of mem\n");
exit(1);
}
if(d > 0)
memset((char*)p+n, 0, d);
return p;
}
...@@ -579,7 +579,7 @@ macinc(void) ...@@ -579,7 +579,7 @@ macinc(void)
if(strcmp(symb, "./") == 0) if(strcmp(symb, "./") == 0)
symb[0] = 0; symb[0] = 0;
strcat(symb, str); strcat(symb, str);
f = myopen(symb); f = open(symb, OREAD);
if(f >= 0) if(f >= 0)
break; break;
} }
......
...@@ -618,7 +618,6 @@ int Fconv(Fmt*); ...@@ -618,7 +618,6 @@ int Fconv(Fmt*);
/* /*
* subr.c * subr.c
*/ */
void myexit(int);
void* mal(int32); void* mal(int32);
void* remal(void*, int32, int32); void* remal(void*, int32, int32);
void errorexit(void); void errorexit(void);
......
...@@ -45,7 +45,7 @@ mainlex(int argc, char *argv[]) ...@@ -45,7 +45,7 @@ mainlex(int argc, char *argv[])
goto usage; goto usage;
pathname = mal(100); pathname = mal(100);
if(mygetwd(pathname, 99) == 0) if(getwd(pathname, 99) == 0)
strcpy(pathname, "/???"); strcpy(pathname, "/???");
fmtinstall('O', Oconv); // node opcodes fmtinstall('O', Oconv); // node opcodes
...@@ -107,7 +107,7 @@ mainlex(int argc, char *argv[]) ...@@ -107,7 +107,7 @@ mainlex(int argc, char *argv[])
if(nerrors) if(nerrors)
errorexit(); errorexit();
myexit(0); exit(0);
return 0; return 0;
usage: usage:
...@@ -122,7 +122,7 @@ usage: ...@@ -122,7 +122,7 @@ usage:
print(" -p print the assembly language\n"); print(" -p print the assembly language\n");
print(" -w print the parse tree after typing\n"); print(" -w print the parse tree after typing\n");
print(" -x print lex tokens\n"); print(" -x print lex tokens\n");
myexit(0); exit(0);
return 0; return 0;
} }
......
...@@ -10,7 +10,7 @@ errorexit(void) ...@@ -10,7 +10,7 @@ errorexit(void)
{ {
if(outfile) if(outfile)
remove(outfile); remove(outfile);
myexit(1); exit(1);
} }
void void
...@@ -59,7 +59,7 @@ fatal(char *fmt, ...) ...@@ -59,7 +59,7 @@ fatal(char *fmt, ...)
print("\n"); print("\n");
if(debug['h']) if(debug['h'])
*(int*)0 = 0; *(int*)0 = 0;
myexit(1); exit(1);
} }
void void
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment