newlines fixed
This commit is contained in:
parent
7830940da6
commit
59cce31e75
1121 changed files with 717537 additions and 717537 deletions
78
lcc/tst/8q.c
78
lcc/tst/8q.c
|
@ -1,39 +1,39 @@
|
|||
int up[15], down[15], rows[8], x[8];
|
||||
int queens(), print();
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 15; i++)
|
||||
up[i] = down[i] = 1;
|
||||
for (i = 0; i < 8; i++)
|
||||
rows[i] = 1;
|
||||
queens(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
queens(c)
|
||||
{
|
||||
int r;
|
||||
|
||||
for (r = 0; r < 8; r++)
|
||||
if (rows[r] && up[r-c+7] && down[r+c]) {
|
||||
rows[r] = up[r-c+7] = down[r+c] = 0;
|
||||
x[c] = r;
|
||||
if (c == 7)
|
||||
print();
|
||||
else
|
||||
queens(c + 1);
|
||||
rows[r] = up[r-c+7] = down[r+c] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
print()
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; k < 8; k++)
|
||||
printf("%c ", x[k]+'1');
|
||||
printf("\n");
|
||||
}
|
||||
int up[15], down[15], rows[8], x[8];
|
||||
int queens(), print();
|
||||
|
||||
main()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < 15; i++)
|
||||
up[i] = down[i] = 1;
|
||||
for (i = 0; i < 8; i++)
|
||||
rows[i] = 1;
|
||||
queens(0);
|
||||
return 0;
|
||||
}
|
||||
|
||||
queens(c)
|
||||
{
|
||||
int r;
|
||||
|
||||
for (r = 0; r < 8; r++)
|
||||
if (rows[r] && up[r-c+7] && down[r+c]) {
|
||||
rows[r] = up[r-c+7] = down[r+c] = 0;
|
||||
x[c] = r;
|
||||
if (c == 7)
|
||||
print();
|
||||
else
|
||||
queens(c + 1);
|
||||
rows[r] = up[r-c+7] = down[r+c] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
print()
|
||||
{
|
||||
int k;
|
||||
|
||||
for (k = 0; k < 8; k++)
|
||||
printf("%c ", x[k]+'1');
|
||||
printf("\n");
|
||||
}
|
||||
|
|
|
@ -1,48 +1,48 @@
|
|||
int x[3][4], *y[3];
|
||||
|
||||
main() {
|
||||
int z[3][4];
|
||||
int i, j, *p;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 4; j++)
|
||||
x[i][j] = 1000*i + j;
|
||||
y[i] = x[i];
|
||||
}
|
||||
f();
|
||||
for (i = 0; i < 3; i++) {
|
||||
y[i] = p = &z[i][0];
|
||||
for (j = 0; j < 4; j++)
|
||||
p[j] = x[i][j];
|
||||
}
|
||||
g(z, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f() {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", x[i][j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
g(x, y)
|
||||
int x[][4], *y[];
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", x[i][j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
int x[3][4], *y[3];
|
||||
|
||||
main() {
|
||||
int z[3][4];
|
||||
int i, j, *p;
|
||||
|
||||
for (i = 0; i < 3; i++) {
|
||||
for (j = 0; j < 4; j++)
|
||||
x[i][j] = 1000*i + j;
|
||||
y[i] = x[i];
|
||||
}
|
||||
f();
|
||||
for (i = 0; i < 3; i++) {
|
||||
y[i] = p = &z[i][0];
|
||||
for (j = 0; j < 4; j++)
|
||||
p[j] = x[i][j];
|
||||
}
|
||||
g(z, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f() {
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", x[i][j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
||||
g(x, y)
|
||||
int x[][4], *y[];
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", x[i][j]);
|
||||
printf("\n");
|
||||
for (i = 0; i < 3; i++)
|
||||
for (j = 0; j < 4; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
|
|
64
lcc/tst/cf.0
64
lcc/tst/cf.0
|
@ -1,32 +1,32 @@
|
|||
/* cf - print character frequencies */
|
||||
float f[128];
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i, c, nc;
|
||||
float cutoff, atof();
|
||||
|
||||
if (argc <= 1)
|
||||
cutoff = 0.0;
|
||||
else
|
||||
cutoff = atof(argv[1])/100;
|
||||
for (i = 0; i <= 127; )
|
||||
f[i++] = 0.0;
|
||||
nc = 0;
|
||||
while ((c = getchar()) != -1) {
|
||||
f[c] += 1;
|
||||
nc++;
|
||||
}
|
||||
printf("char\tfreq\n");
|
||||
for (i = 0; i <= 127; ++i)
|
||||
if (f[i] && f[i]/nc >= cutoff) {
|
||||
if (i <= ' ')
|
||||
printf("%03o", i);
|
||||
else
|
||||
printf("%c", i);
|
||||
printf("\t%.1f\n", 100*f[i]/nc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* cf - print character frequencies */
|
||||
float f[128];
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i, c, nc;
|
||||
float cutoff, atof();
|
||||
|
||||
if (argc <= 1)
|
||||
cutoff = 0.0;
|
||||
else
|
||||
cutoff = atof(argv[1])/100;
|
||||
for (i = 0; i <= 127; )
|
||||
f[i++] = 0.0;
|
||||
nc = 0;
|
||||
while ((c = getchar()) != -1) {
|
||||
f[c] += 1;
|
||||
nc++;
|
||||
}
|
||||
printf("char\tfreq\n");
|
||||
for (i = 0; i <= 127; ++i)
|
||||
if (f[i] && f[i]/nc >= cutoff) {
|
||||
if (i <= ' ')
|
||||
printf("%03o", i);
|
||||
else
|
||||
printf("%c", i);
|
||||
printf("\t%.1f\n", 100*f[i]/nc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
64
lcc/tst/cf.c
64
lcc/tst/cf.c
|
@ -1,32 +1,32 @@
|
|||
/* cf - print character frequencies */
|
||||
float f[128];
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i, c, nc;
|
||||
float cutoff, atof();
|
||||
|
||||
if (argc <= 1)
|
||||
cutoff = 0.0;
|
||||
else
|
||||
cutoff = atof(argv[1])/100;
|
||||
for (i = 0; i <= 127; )
|
||||
f[i++] = 0.0;
|
||||
nc = 0;
|
||||
while ((c = getchar()) != -1) {
|
||||
f[c] += 1;
|
||||
nc++;
|
||||
}
|
||||
printf("char\tfreq\n");
|
||||
for (i = 0; i <= 127; ++i)
|
||||
if (f[i] && f[i]/nc >= cutoff) {
|
||||
if (i <= ' ')
|
||||
printf("%03o", i);
|
||||
else
|
||||
printf("%c", i);
|
||||
printf("\t%.1f\n", 100*f[i]/nc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
/* cf - print character frequencies */
|
||||
float f[128];
|
||||
|
||||
main(argc, argv)
|
||||
int argc;
|
||||
char *argv[];
|
||||
{
|
||||
int i, c, nc;
|
||||
float cutoff, atof();
|
||||
|
||||
if (argc <= 1)
|
||||
cutoff = 0.0;
|
||||
else
|
||||
cutoff = atof(argv[1])/100;
|
||||
for (i = 0; i <= 127; )
|
||||
f[i++] = 0.0;
|
||||
nc = 0;
|
||||
while ((c = getchar()) != -1) {
|
||||
f[c] += 1;
|
||||
nc++;
|
||||
}
|
||||
printf("char\tfreq\n");
|
||||
for (i = 0; i <= 127; ++i)
|
||||
if (f[i] && f[i]/nc >= cutoff) {
|
||||
if (i <= ' ')
|
||||
printf("%03o", i);
|
||||
else
|
||||
printf("%c", i);
|
||||
printf("\t%.1f\n", 100*f[i]/nc);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
|
10632
lcc/tst/cq.c
10632
lcc/tst/cq.c
File diff suppressed because it is too large
Load diff
|
@ -1,35 +1,35 @@
|
|||
signed char c;
|
||||
signed short s;
|
||||
signed int i;
|
||||
signed long int l;
|
||||
unsigned char C;
|
||||
unsigned short S;
|
||||
unsigned int I;
|
||||
unsigned long int L;
|
||||
float f;
|
||||
double d;
|
||||
long double D;
|
||||
void *p;
|
||||
void (*P)(void);
|
||||
|
||||
void print(void) {
|
||||
printf("%d %d %d %ld %u %u %u %lu %f %f %lf\n",c,s,i,l,C,S,I,L,f,d,D);
|
||||
}
|
||||
|
||||
main() {
|
||||
c= 1; s=c;i=c;l=c;C=c;S=c;I=c;L=c;f=c;d=c;D=c; print();
|
||||
s= 2; c=s; i=s;l=s;C=s;S=s;I=s;L=s;f=s;d=s;D=s; print();
|
||||
i= 3; c=i;s=i; l=i;C=i;S=i;I=i;L=i;f=i;d=i;D=i; print();
|
||||
l= 4; c=l;s=l;i=l; C=l;S=l;I=l;L=l;f=l;d=l;D=l; print();
|
||||
C= 5; c=C;s=C;i=C;l=C; S=C;I=C;L=C;f=C;d=C;D=C; print();
|
||||
S= 6; c=S;s=S;i=S;l=S;C=S; I=S;L=S;f=S;d=S;D=S; print();
|
||||
I= 7; c=I;s=I;i=I;l=I;C=I;S=I; L=I;f=I;d=I;D=I; print();
|
||||
L= 8; c=L;s=L;i=L;l=L;C=L;S=L;I=S; f=L;d=L;D=L; print();
|
||||
f= 9; c=f;s=f;i=f;l=f;C=f;S=f;I=f;L=f; d=f;D=f; print();
|
||||
d=10; c=d;s=d;i=d;l=d;C=d;S=d;I=d;L=d;f=d; D=d; print();
|
||||
D=11; c=D;s=D;i=D;l=D;C=D;S=D;I=D;L=D;f=D;d=D; print();
|
||||
|
||||
p=0; p=0L; p=0U; p=0UL; p=P;
|
||||
P=0; P=0L; P=0U; P=0UL; P=p;
|
||||
return 0;
|
||||
}
|
||||
signed char c;
|
||||
signed short s;
|
||||
signed int i;
|
||||
signed long int l;
|
||||
unsigned char C;
|
||||
unsigned short S;
|
||||
unsigned int I;
|
||||
unsigned long int L;
|
||||
float f;
|
||||
double d;
|
||||
long double D;
|
||||
void *p;
|
||||
void (*P)(void);
|
||||
|
||||
void print(void) {
|
||||
printf("%d %d %d %ld %u %u %u %lu %f %f %lf\n",c,s,i,l,C,S,I,L,f,d,D);
|
||||
}
|
||||
|
||||
main() {
|
||||
c= 1; s=c;i=c;l=c;C=c;S=c;I=c;L=c;f=c;d=c;D=c; print();
|
||||
s= 2; c=s; i=s;l=s;C=s;S=s;I=s;L=s;f=s;d=s;D=s; print();
|
||||
i= 3; c=i;s=i; l=i;C=i;S=i;I=i;L=i;f=i;d=i;D=i; print();
|
||||
l= 4; c=l;s=l;i=l; C=l;S=l;I=l;L=l;f=l;d=l;D=l; print();
|
||||
C= 5; c=C;s=C;i=C;l=C; S=C;I=C;L=C;f=C;d=C;D=C; print();
|
||||
S= 6; c=S;s=S;i=S;l=S;C=S; I=S;L=S;f=S;d=S;D=S; print();
|
||||
I= 7; c=I;s=I;i=I;l=I;C=I;S=I; L=I;f=I;d=I;D=I; print();
|
||||
L= 8; c=L;s=L;i=L;l=L;C=L;S=L;I=S; f=L;d=L;D=L; print();
|
||||
f= 9; c=f;s=f;i=f;l=f;C=f;S=f;I=f;L=f; d=f;D=f; print();
|
||||
d=10; c=d;s=d;i=d;l=d;C=d;S=d;I=d;L=d;f=d; D=d; print();
|
||||
D=11; c=D;s=D;i=D;l=D;C=D;S=D;I=D;L=D;f=D;d=D; print();
|
||||
|
||||
p=0; p=0L; p=0U; p=0UL; p=P;
|
||||
P=0; P=0L; P=0U; P=0UL; P=p;
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -1,34 +1,34 @@
|
|||
struct foo {
|
||||
int a;
|
||||
char b;
|
||||
int x : 12, y : 4, : 0, : 4, z : 3;
|
||||
char c;
|
||||
} x = { 1, 2, 3, 4, 5, 6 };
|
||||
int i = 16;
|
||||
struct baz { unsigned int a:2, b:4, c:32;} y = { 7, 8, 9};
|
||||
|
||||
main()
|
||||
{
|
||||
printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
|
||||
printf("y = %d %d %d\n", y.a, y.b, y.c);
|
||||
x.y = i;
|
||||
x.z = 070;
|
||||
printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
|
||||
y.a = 2;
|
||||
y.c = i;
|
||||
printf("y = %d %d %d\n", y.a, y.b, y.c);
|
||||
f2(&x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f1(struct baz *p) {
|
||||
p->a = p->b = 0;
|
||||
if (p->b)
|
||||
printf("p->b != 0!\n");
|
||||
p->a = 0x3; p->b = 0xf;
|
||||
printf("p->a = 0x%x, p->b = 0x%x\n", p->a, p->b);
|
||||
}
|
||||
f2(struct baz *p) {
|
||||
p->a = (i==0);
|
||||
p->b = (f1(p),0);
|
||||
}
|
||||
struct foo {
|
||||
int a;
|
||||
char b;
|
||||
int x : 12, y : 4, : 0, : 4, z : 3;
|
||||
char c;
|
||||
} x = { 1, 2, 3, 4, 5, 6 };
|
||||
int i = 16;
|
||||
struct baz { unsigned int a:2, b:4, c:32;} y = { 7, 8, 9};
|
||||
|
||||
main()
|
||||
{
|
||||
printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
|
||||
printf("y = %d %d %d\n", y.a, y.b, y.c);
|
||||
x.y = i;
|
||||
x.z = 070;
|
||||
printf("x = %d %d %d %d %d %d\n", x.a, x.b, x.x, x.y, x.z, x.c);
|
||||
y.a = 2;
|
||||
y.c = i;
|
||||
printf("y = %d %d %d\n", y.a, y.b, y.c);
|
||||
f2(&x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f1(struct baz *p) {
|
||||
p->a = p->b = 0;
|
||||
if (p->b)
|
||||
printf("p->b != 0!\n");
|
||||
p->a = 0x3; p->b = 0xf;
|
||||
printf("p->a = 0x%x, p->b = 0x%x\n", p->a, p->b);
|
||||
}
|
||||
f2(struct baz *p) {
|
||||
p->a = (i==0);
|
||||
p->b = (f1(p),0);
|
||||
}
|
||||
|
|
240
lcc/tst/front.c
240
lcc/tst/front.c
|
@ -1,120 +1,120 @@
|
|||
main() {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
nested(a,b) {
|
||||
if ((a<4 && b == 'r')
|
||||
|| (a == 1 && (b == 'h' || b == 'i'))
|
||||
|| (a == 2 && (b == 'o' || b == 'y'))
|
||||
) a=b;
|
||||
}
|
||||
|
||||
/* type name scope */
|
||||
|
||||
void s(struct D *d) {} /* this struct D differs from the one below */
|
||||
typedef struct D D;
|
||||
struct D {int x, y;} Dy={0};
|
||||
D Dz={1};
|
||||
Dfunc(){
|
||||
D a; a.y=1;
|
||||
s(&Dy); /* error */
|
||||
}
|
||||
|
||||
/* qualifiers */
|
||||
|
||||
const a; int b;
|
||||
const int a, *x; int b, *y;
|
||||
volatile unsigned z;
|
||||
|
||||
f() {
|
||||
x = y;
|
||||
z = z + z; /* should be 2 references to z's r-value */
|
||||
}
|
||||
f1() {
|
||||
x = &a;
|
||||
x = &b;
|
||||
y = &a; /* error */
|
||||
y = &b;
|
||||
}
|
||||
f2(int **a, int **b) {
|
||||
f(&x, &y);
|
||||
**a = 0;
|
||||
return **b;
|
||||
}
|
||||
g(const int *p) {
|
||||
g(&a);
|
||||
g(&b);
|
||||
return *p;
|
||||
}
|
||||
h(int *p) {
|
||||
f(&a);
|
||||
f(&b);
|
||||
return *p;
|
||||
}
|
||||
h1(const int x, int y) {
|
||||
h1(a,b);
|
||||
h1(b,a);
|
||||
return x + y;
|
||||
}
|
||||
h2() {
|
||||
char *b; const void *p;
|
||||
p = b;
|
||||
b = p; /* error */
|
||||
}
|
||||
|
||||
|
||||
/* static naming */
|
||||
|
||||
extern int yy; set1() { { static yy=1; yy=2;} yy=4;}
|
||||
static int yy; set2() { yy=5; {static yy=2; yy=3; }}
|
||||
static void goo() {}
|
||||
sss() { int goo; { static int goo();} goo=1;}
|
||||
rrr(p) float *p; { extern int xr;
|
||||
{ static float xr;
|
||||
{ extern int *xr; } p=&xr; }}
|
||||
|
||||
/* local extern */
|
||||
|
||||
static int ss1;
|
||||
int ss3;
|
||||
extern int ss5;
|
||||
setstatic() { extern int ss1,ss2,ss3,ss4; ss1 = ss2; ss3 = ss4; ss5 = 0;}
|
||||
static int ss2;
|
||||
int ss4;
|
||||
static int ss5;
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int fx1(void);
|
||||
int fx1();
|
||||
|
||||
int gx1(double x);
|
||||
int gx1(x) double x; { gx1(&x); } /* error */
|
||||
|
||||
int hx1();
|
||||
int hx1(double x,...); /* error */
|
||||
|
||||
int ff1(double x, int *y);
|
||||
int ff1(x,y) float x; int y[]; {x=y[0];}
|
||||
|
||||
int gg1(int a);
|
||||
int gg1(a,b){a=b;}
|
||||
|
||||
int hh1(const int x);
|
||||
hh1(a) {return a;}
|
||||
|
||||
extern int strcmp(const char*, const char*);
|
||||
extern void qsort(void*, int, int, int (*)(const void*, const void*));
|
||||
extern int cmp(char**a, char**b) { return strcmp(*a,*b); }
|
||||
sort() {
|
||||
int n; char *a[100];
|
||||
qsort(a, n, sizeof(char*), (int (*)(const void*, const void*))cmp);
|
||||
qsort(a, n, sizeof(char*), cmp); /* error */
|
||||
}
|
||||
|
||||
/* nasty calls */
|
||||
|
||||
onearg(){
|
||||
int a,b,c,d;
|
||||
f( ( (a? (b = 1): (c = 2)), (d ? 3 : 4) ) ); /* 1 argument */
|
||||
}
|
||||
main() {
|
||||
exit(0);
|
||||
}
|
||||
|
||||
nested(a,b) {
|
||||
if ((a<4 && b == 'r')
|
||||
|| (a == 1 && (b == 'h' || b == 'i'))
|
||||
|| (a == 2 && (b == 'o' || b == 'y'))
|
||||
) a=b;
|
||||
}
|
||||
|
||||
/* type name scope */
|
||||
|
||||
void s(struct D *d) {} /* this struct D differs from the one below */
|
||||
typedef struct D D;
|
||||
struct D {int x, y;} Dy={0};
|
||||
D Dz={1};
|
||||
Dfunc(){
|
||||
D a; a.y=1;
|
||||
s(&Dy); /* error */
|
||||
}
|
||||
|
||||
/* qualifiers */
|
||||
|
||||
const a; int b;
|
||||
const int a, *x; int b, *y;
|
||||
volatile unsigned z;
|
||||
|
||||
f() {
|
||||
x = y;
|
||||
z = z + z; /* should be 2 references to z's r-value */
|
||||
}
|
||||
f1() {
|
||||
x = &a;
|
||||
x = &b;
|
||||
y = &a; /* error */
|
||||
y = &b;
|
||||
}
|
||||
f2(int **a, int **b) {
|
||||
f(&x, &y);
|
||||
**a = 0;
|
||||
return **b;
|
||||
}
|
||||
g(const int *p) {
|
||||
g(&a);
|
||||
g(&b);
|
||||
return *p;
|
||||
}
|
||||
h(int *p) {
|
||||
f(&a);
|
||||
f(&b);
|
||||
return *p;
|
||||
}
|
||||
h1(const int x, int y) {
|
||||
h1(a,b);
|
||||
h1(b,a);
|
||||
return x + y;
|
||||
}
|
||||
h2() {
|
||||
char *b; const void *p;
|
||||
p = b;
|
||||
b = p; /* error */
|
||||
}
|
||||
|
||||
|
||||
/* static naming */
|
||||
|
||||
extern int yy; set1() { { static yy=1; yy=2;} yy=4;}
|
||||
static int yy; set2() { yy=5; {static yy=2; yy=3; }}
|
||||
static void goo() {}
|
||||
sss() { int goo; { static int goo();} goo=1;}
|
||||
rrr(p) float *p; { extern int xr;
|
||||
{ static float xr;
|
||||
{ extern int *xr; } p=&xr; }}
|
||||
|
||||
/* local extern */
|
||||
|
||||
static int ss1;
|
||||
int ss3;
|
||||
extern int ss5;
|
||||
setstatic() { extern int ss1,ss2,ss3,ss4; ss1 = ss2; ss3 = ss4; ss5 = 0;}
|
||||
static int ss2;
|
||||
int ss4;
|
||||
static int ss5;
|
||||
|
||||
/* function prototypes */
|
||||
|
||||
int fx1(void);
|
||||
int fx1();
|
||||
|
||||
int gx1(double x);
|
||||
int gx1(x) double x; { gx1(&x); } /* error */
|
||||
|
||||
int hx1();
|
||||
int hx1(double x,...); /* error */
|
||||
|
||||
int ff1(double x, int *y);
|
||||
int ff1(x,y) float x; int y[]; {x=y[0];}
|
||||
|
||||
int gg1(int a);
|
||||
int gg1(a,b){a=b;}
|
||||
|
||||
int hh1(const int x);
|
||||
hh1(a) {return a;}
|
||||
|
||||
extern int strcmp(const char*, const char*);
|
||||
extern void qsort(void*, int, int, int (*)(const void*, const void*));
|
||||
extern int cmp(char**a, char**b) { return strcmp(*a,*b); }
|
||||
sort() {
|
||||
int n; char *a[100];
|
||||
qsort(a, n, sizeof(char*), (int (*)(const void*, const void*))cmp);
|
||||
qsort(a, n, sizeof(char*), cmp); /* error */
|
||||
}
|
||||
|
||||
/* nasty calls */
|
||||
|
||||
onearg(){
|
||||
int a,b,c,d;
|
||||
f( ( (a? (b = 1): (c = 2)), (d ? 3 : 4) ) ); /* 1 argument */
|
||||
}
|
||||
|
|
|
@ -1,39 +1,39 @@
|
|||
main() {}
|
||||
|
||||
memchar() {
|
||||
char x, *p;
|
||||
|
||||
&x, &p;
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
memint() {
|
||||
int x, *p;
|
||||
|
||||
&x, &p;
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
regchar() {
|
||||
register char x, *p;
|
||||
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
regint() {
|
||||
register int x, *p;
|
||||
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
main() {}
|
||||
|
||||
memchar() {
|
||||
char x, *p;
|
||||
|
||||
&x, &p;
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
memint() {
|
||||
int x, *p;
|
||||
|
||||
&x, &p;
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
regchar() {
|
||||
register char x, *p;
|
||||
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
||||
regint() {
|
||||
register int x, *p;
|
||||
|
||||
x = *p++;
|
||||
x = *++p;
|
||||
x = *p--;
|
||||
x = *--p;
|
||||
}
|
||||
|
|
118
lcc/tst/init.c
118
lcc/tst/init.c
|
@ -1,59 +1,59 @@
|
|||
|
||||
typedef struct { int codes[3]; char name[6]; } Word;
|
||||
|
||||
Word words[] = {
|
||||
1, 2, 3, "if",
|
||||
{ { 4, 5 }, { 'f', 'o', 'r' } },
|
||||
6, 7, 8, {"else"},
|
||||
{ { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', },
|
||||
{ 0 },
|
||||
}, *wordlist = words;
|
||||
|
||||
int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };
|
||||
int *y[] = { x[0], x[1], x[2], 0 };
|
||||
|
||||
|
||||
main()
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; y[i]; i++) {
|
||||
for (j = 0; y[i][j]; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
f();
|
||||
g(wordlist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f() {
|
||||
static char *keywords[] = {"if", "for", "else", "while", 0, };
|
||||
char **p;
|
||||
|
||||
for (p = keywords; *p; p++)
|
||||
printf("%s\n", *p);
|
||||
}
|
||||
|
||||
g(p)
|
||||
Word *p;
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( ; p->codes[0]; p++) {
|
||||
for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++)
|
||||
printf("%d ", p->codes[i]);
|
||||
printf("%s\n", p->name);
|
||||
}
|
||||
h();
|
||||
}
|
||||
|
||||
h()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(words)/sizeof(Word); i++)
|
||||
printf("%d %d %d %s\n", words[i].codes[0],
|
||||
words[i].codes[1], words[i].codes[2],
|
||||
&words[i].name[0]);
|
||||
}
|
||||
|
||||
typedef struct { int codes[3]; char name[6]; } Word;
|
||||
|
||||
Word words[] = {
|
||||
1, 2, 3, "if",
|
||||
{ { 4, 5 }, { 'f', 'o', 'r' } },
|
||||
6, 7, 8, {"else"},
|
||||
{ { 9, 10, 11,}, 'w', 'h', 'i', 'l', 'e', },
|
||||
{ 0 },
|
||||
}, *wordlist = words;
|
||||
|
||||
int x[][5] = { 1, 2, 3, 4, 0, { 5, 6 }, { 7 } };
|
||||
int *y[] = { x[0], x[1], x[2], 0 };
|
||||
|
||||
|
||||
main()
|
||||
{
|
||||
int i, j;
|
||||
|
||||
for (i = 0; y[i]; i++) {
|
||||
for (j = 0; y[i][j]; j++)
|
||||
printf(" %d", y[i][j]);
|
||||
printf("\n");
|
||||
}
|
||||
f();
|
||||
g(wordlist);
|
||||
return 0;
|
||||
}
|
||||
|
||||
f() {
|
||||
static char *keywords[] = {"if", "for", "else", "while", 0, };
|
||||
char **p;
|
||||
|
||||
for (p = keywords; *p; p++)
|
||||
printf("%s\n", *p);
|
||||
}
|
||||
|
||||
g(p)
|
||||
Word *p;
|
||||
{
|
||||
int i;
|
||||
|
||||
for ( ; p->codes[0]; p++) {
|
||||
for (i = 0; i < sizeof p->codes/sizeof(p->codes[0]); i++)
|
||||
printf("%d ", p->codes[i]);
|
||||
printf("%s\n", p->name);
|
||||
}
|
||||
h();
|
||||
}
|
||||
|
||||
h()
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i = 0; i < sizeof(words)/sizeof(Word); i++)
|
||||
printf("%d %d %d %s\n", words[i].codes[0],
|
||||
words[i].codes[1], words[i].codes[2],
|
||||
&words[i].name[0]);
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
#include <limits.h>
|
||||
|
||||
main() {
|
||||
printf("UCHAR_MAX: %08x=%d\n", UCHAR_MAX, UCHAR_MAX);
|
||||
printf("USHRT_MAX: %08x=%d\n", USHRT_MAX, USHRT_MAX);
|
||||
printf("UINT_MAX: %08x=%d\n", UINT_MAX, UINT_MAX);
|
||||
printf("ULONG_MAX: %08lx=%ld\n", ULONG_MAX, ULONG_MAX);
|
||||
printf("CHAR_MAX: %08x=%d\n", CHAR_MAX, CHAR_MAX);
|
||||
printf("SCHAR_MAX: %08x=%d\n", SCHAR_MAX, SCHAR_MAX);
|
||||
printf("SHRT_MAX: %08x=%d\n", SHRT_MAX, SHRT_MAX);
|
||||
printf("INT_MAX: %08x=%d\n", INT_MAX, INT_MAX);
|
||||
printf("LONG_MAX: %08lx=%ld\n", LONG_MAX, LONG_MAX);
|
||||
printf("CHAR_MIN: %08x=%d\n", CHAR_MIN, CHAR_MIN);
|
||||
printf("SCHAR_MIN: %08x=%d\n", SCHAR_MIN, SCHAR_MIN);
|
||||
printf("SHRT_MIN: %08x=%d\n", SHRT_MIN, SHRT_MIN);
|
||||
printf("INT_MIN: %08x=%d\n", INT_MIN, INT_MIN);
|
||||
printf("LONG_MIN: %08lx=%ld\n", LONG_MIN, LONG_MIN);
|
||||
return 0;
|
||||
}
|
||||
#include <limits.h>
|
||||
|
||||
main() {
|
||||
printf("UCHAR_MAX: %08x=%d\n", UCHAR_MAX, UCHAR_MAX);
|
||||
printf("USHRT_MAX: %08x=%d\n", USHRT_MAX, USHRT_MAX);
|
||||
printf("UINT_MAX: %08x=%d\n", UINT_MAX, UINT_MAX);
|
||||
printf("ULONG_MAX: %08lx=%ld\n", ULONG_MAX, ULONG_MAX);
|
||||
printf("CHAR_MAX: %08x=%d\n", CHAR_MAX, CHAR_MAX);
|
||||
printf("SCHAR_MAX: %08x=%d\n", SCHAR_MAX, SCHAR_MAX);
|
||||
printf("SHRT_MAX: %08x=%d\n", SHRT_MAX, SHRT_MAX);
|
||||
printf("INT_MAX: %08x=%d\n", INT_MAX, INT_MAX);
|
||||
printf("LONG_MAX: %08lx=%ld\n", LONG_MAX, LONG_MAX);
|
||||
printf("CHAR_MIN: %08x=%d\n", CHAR_MIN, CHAR_MIN);
|
||||
printf("SCHAR_MIN: %08x=%d\n", SCHAR_MIN, SCHAR_MIN);
|
||||
printf("SHRT_MIN: %08x=%d\n", SHRT_MIN, SHRT_MIN);
|
||||
printf("INT_MIN: %08x=%d\n", INT_MIN, INT_MIN);
|
||||
printf("LONG_MIN: %08lx=%ld\n", LONG_MIN, LONG_MIN);
|
||||
return 0;
|
||||
}
|
||||
|
|
4406
lcc/tst/paranoia.c
4406
lcc/tst/paranoia.c
File diff suppressed because it is too large
Load diff
130
lcc/tst/sort.c
130
lcc/tst/sort.c
|
@ -1,65 +1,65 @@
|
|||
int in[] = {10, 32, -1, 567, 3, 18, 1, -51, 789, 0};
|
||||
|
||||
main() {
|
||||
int i;
|
||||
|
||||
sort(in, (sizeof in)/(sizeof in[0]));
|
||||
for (i = 0; i < (sizeof in)/(sizeof in[0]); i++) {
|
||||
putd(in[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* putd - output decimal number */
|
||||
putd(n) {
|
||||
if (n < 0) {
|
||||
putchar('-');
|
||||
n = -n;
|
||||
}
|
||||
if (n/10)
|
||||
putd(n/10);
|
||||
putchar(n%10 + '0');
|
||||
}
|
||||
|
||||
int *xx;
|
||||
|
||||
/* sort - sort a[0..n-1] into increasing order */
|
||||
sort(a, n) int a[]; {
|
||||
quick(xx = a, 0, --n);
|
||||
}
|
||||
|
||||
/* quick - quicksort a[lb..ub] */
|
||||
quick(a, lb, ub) int a[]; {
|
||||
int k, partition();
|
||||
|
||||
if (lb >= ub)
|
||||
return;
|
||||
k = partition(a, lb, ub);
|
||||
quick(a, lb, k - 1);
|
||||
quick(a, k + 1, ub);
|
||||
}
|
||||
|
||||
/* partition - partition a[i..j] */
|
||||
int partition(a, i, j) int a[]; {
|
||||
int v, k;
|
||||
|
||||
j++;
|
||||
k = i;
|
||||
v = a[k];
|
||||
while (i < j) {
|
||||
i++; while (a[i] < v) i++;
|
||||
j--; while (a[j] > v) j--;
|
||||
if (i < j) exchange(&a[i], &a[j]);
|
||||
}
|
||||
exchange(&a[k], &a[j]);
|
||||
return j;
|
||||
}
|
||||
|
||||
/* exchange - exchange *x and *y */
|
||||
exchange(x, y) int *x, *y; {
|
||||
int t;
|
||||
|
||||
printf("exchange(%d,%d)\n", x - xx, y - xx);
|
||||
t = *x; *x = *y; *y = t;
|
||||
}
|
||||
int in[] = {10, 32, -1, 567, 3, 18, 1, -51, 789, 0};
|
||||
|
||||
main() {
|
||||
int i;
|
||||
|
||||
sort(in, (sizeof in)/(sizeof in[0]));
|
||||
for (i = 0; i < (sizeof in)/(sizeof in[0]); i++) {
|
||||
putd(in[i]);
|
||||
putchar('\n');
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* putd - output decimal number */
|
||||
putd(n) {
|
||||
if (n < 0) {
|
||||
putchar('-');
|
||||
n = -n;
|
||||
}
|
||||
if (n/10)
|
||||
putd(n/10);
|
||||
putchar(n%10 + '0');
|
||||
}
|
||||
|
||||
int *xx;
|
||||
|
||||
/* sort - sort a[0..n-1] into increasing order */
|
||||
sort(a, n) int a[]; {
|
||||
quick(xx = a, 0, --n);
|
||||
}
|
||||
|
||||
/* quick - quicksort a[lb..ub] */
|
||||
quick(a, lb, ub) int a[]; {
|
||||
int k, partition();
|
||||
|
||||
if (lb >= ub)
|
||||
return;
|
||||
k = partition(a, lb, ub);
|
||||
quick(a, lb, k - 1);
|
||||
quick(a, k + 1, ub);
|
||||
}
|
||||
|
||||
/* partition - partition a[i..j] */
|
||||
int partition(a, i, j) int a[]; {
|
||||
int v, k;
|
||||
|
||||
j++;
|
||||
k = i;
|
||||
v = a[k];
|
||||
while (i < j) {
|
||||
i++; while (a[i] < v) i++;
|
||||
j--; while (a[j] > v) j--;
|
||||
if (i < j) exchange(&a[i], &a[j]);
|
||||
}
|
||||
exchange(&a[k], &a[j]);
|
||||
return j;
|
||||
}
|
||||
|
||||
/* exchange - exchange *x and *y */
|
||||
exchange(x, y) int *x, *y; {
|
||||
int t;
|
||||
|
||||
printf("exchange(%d,%d)\n", x - xx, y - xx);
|
||||
t = *x; *x = *y; *y = t;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
main(){}
|
||||
|
||||
f(i){i=f()+f();}
|
||||
|
||||
f2(i){i=f()+(i?f():1);}
|
||||
|
||||
f3(int i,int *p){register r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r7=0,r8=0,r9=0,r10=0;*p++=i?f():0;}
|
||||
|
||||
double a[10],b[10];int i;f4(){register r6=0,r7=0,r8=0,r9=0,r10=0,r11=0;i=a[i]+b[i] && i && a[i]-b[i];}
|
||||
/* f4 causes parent to spill child on vax when odd double regs are enabled */
|
||||
|
||||
int j, k, m, n;
|
||||
double *A, *B, x;
|
||||
f5(){
|
||||
x=A[k*m]*A[j*m]+B[k*n]*B[j*n];
|
||||
x=A[k*m]*B[j*n]-B[k*n]*A[j*m];
|
||||
}
|
||||
main(){}
|
||||
|
||||
f(i){i=f()+f();}
|
||||
|
||||
f2(i){i=f()+(i?f():1);}
|
||||
|
||||
f3(int i,int *p){register r1=0,r2=0,r3=0,r4=0,r5=0,r6=0,r7=0,r8=0,r9=0,r10=0;*p++=i?f():0;}
|
||||
|
||||
double a[10],b[10];int i;f4(){register r6=0,r7=0,r8=0,r9=0,r10=0,r11=0;i=a[i]+b[i] && i && a[i]-b[i];}
|
||||
/* f4 causes parent to spill child on vax when odd double regs are enabled */
|
||||
|
||||
int j, k, m, n;
|
||||
double *A, *B, x;
|
||||
f5(){
|
||||
x=A[k*m]*A[j*m]+B[k*n]*B[j*n];
|
||||
x=A[k*m]*B[j*n]-B[k*n]*A[j*m];
|
||||
}
|
||||
|
|
102
lcc/tst/stdarg.c
102
lcc/tst/stdarg.c
|
@ -1,51 +1,51 @@
|
|||
#include <stdarg.h>
|
||||
|
||||
struct node { int a[4]; } x = {1,2,3,4};
|
||||
|
||||
print(char *fmt, ...);
|
||||
|
||||
main() {
|
||||
print("test 1\n");
|
||||
print("test %s\n", "2");
|
||||
print("test %d%c", 3, '\n');
|
||||
print("%s%s %w%c", "te", "st", 4, '\n');
|
||||
print("%s%s %f%c", "te", "st", 5.0, '\n');
|
||||
print("%b %b %b %b %b %b\n", x, x, x, x, x, x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
print(char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
for (; *fmt; fmt++)
|
||||
if (*fmt == '%')
|
||||
switch (*++fmt) {
|
||||
case 'b': {
|
||||
struct node x = va_arg(ap, struct node);
|
||||
printf("{%d %d %d %d}", x.a[0], x.a[1], x.a[2], x.a[3]);
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
printf("%c", va_arg(ap, char));
|
||||
break;
|
||||
case 'd':
|
||||
printf("%d", va_arg(ap, int));
|
||||
break;
|
||||
case 'w':
|
||||
printf("%x", va_arg(ap, short));
|
||||
break;
|
||||
case 's':
|
||||
printf("%s", va_arg(ap, char *));
|
||||
break;
|
||||
case 'f':
|
||||
printf("%f", va_arg(ap, double));
|
||||
break;
|
||||
default:
|
||||
printf("%c", *fmt);
|
||||
break;
|
||||
}
|
||||
else
|
||||
printf("%c", *fmt);
|
||||
va_end(ap);
|
||||
}
|
||||
#include <stdarg.h>
|
||||
|
||||
struct node { int a[4]; } x = {1,2,3,4};
|
||||
|
||||
print(char *fmt, ...);
|
||||
|
||||
main() {
|
||||
print("test 1\n");
|
||||
print("test %s\n", "2");
|
||||
print("test %d%c", 3, '\n');
|
||||
print("%s%s %w%c", "te", "st", 4, '\n');
|
||||
print("%s%s %f%c", "te", "st", 5.0, '\n');
|
||||
print("%b %b %b %b %b %b\n", x, x, x, x, x, x);
|
||||
return 0;
|
||||
}
|
||||
|
||||
print(char *fmt, ...) {
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
for (; *fmt; fmt++)
|
||||
if (*fmt == '%')
|
||||
switch (*++fmt) {
|
||||
case 'b': {
|
||||
struct node x = va_arg(ap, struct node);
|
||||
printf("{%d %d %d %d}", x.a[0], x.a[1], x.a[2], x.a[3]);
|
||||
break;
|
||||
}
|
||||
case 'c':
|
||||
printf("%c", va_arg(ap, char));
|
||||
break;
|
||||
case 'd':
|
||||
printf("%d", va_arg(ap, int));
|
||||
break;
|
||||
case 'w':
|
||||
printf("%x", va_arg(ap, short));
|
||||
break;
|
||||
case 's':
|
||||
printf("%s", va_arg(ap, char *));
|
||||
break;
|
||||
case 'f':
|
||||
printf("%f", va_arg(ap, double));
|
||||
break;
|
||||
default:
|
||||
printf("%c", *fmt);
|
||||
break;
|
||||
}
|
||||
else
|
||||
printf("%c", *fmt);
|
||||
va_end(ap);
|
||||
}
|
||||
|
|
138
lcc/tst/struct.c
138
lcc/tst/struct.c
|
@ -1,69 +1,69 @@
|
|||
typedef struct point { int x,y; } point;
|
||||
typedef struct rect { point pt1, pt2; } rect;
|
||||
|
||||
point addpoint(point p1, point p2) { /* add two points */
|
||||
p1.x += p2.x;
|
||||
p1.y += p2.y;
|
||||
return p1;
|
||||
}
|
||||
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
rect canonrect(rect r) { /* canonicalize rectangle coordinates */
|
||||
rect temp;
|
||||
|
||||
temp.pt1.x = min(r.pt1.x, r.pt2.x);
|
||||
temp.pt1.y = min(r.pt1.y, r.pt2.y);
|
||||
temp.pt2.x = max(r.pt1.x, r.pt2.x);
|
||||
temp.pt2.y = max(r.pt1.y, r.pt2.y);
|
||||
return temp;
|
||||
}
|
||||
|
||||
point makepoint(int x, int y) { /* make a point from x and y components */
|
||||
point p;
|
||||
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
return p;
|
||||
}
|
||||
|
||||
rect makerect(point p1, point p2) { /* make a rectangle from two points */
|
||||
rect r;
|
||||
|
||||
r.pt1 = p1;
|
||||
r.pt2 = p2;
|
||||
return canonrect(r);
|
||||
}
|
||||
|
||||
int ptinrect(point p, rect r) { /* is p in r? */
|
||||
return p.x >= r.pt1.x && p.x < r.pt2.x
|
||||
&& p.y >= r.pt1.y && p.y < r.pt2.y;
|
||||
}
|
||||
|
||||
struct odd {char a[3]; } y = {'a', 'b', 0};
|
||||
|
||||
odd(struct odd y) {
|
||||
struct odd x = y;
|
||||
printf("%s\n", x.a);
|
||||
}
|
||||
|
||||
main() {
|
||||
int i;
|
||||
point x, origin = { 0, 0 }, maxpt = { 320, 320 };
|
||||
point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
|
||||
rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)),
|
||||
addpoint(origin, makepoint(10, 10)));
|
||||
|
||||
for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
|
||||
printf("(%d,%d) is ", pts[i].x,
|
||||
(x = makepoint(pts[i].x, pts[i].y)).y);
|
||||
if (ptinrect(x, screen) == 0)
|
||||
printf("not ");
|
||||
printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y,
|
||||
screen.pt2.x, screen.pt2.y);
|
||||
}
|
||||
odd(y);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
typedef struct point { int x,y; } point;
|
||||
typedef struct rect { point pt1, pt2; } rect;
|
||||
|
||||
point addpoint(point p1, point p2) { /* add two points */
|
||||
p1.x += p2.x;
|
||||
p1.y += p2.y;
|
||||
return p1;
|
||||
}
|
||||
|
||||
#define min(a, b) ((a) < (b) ? (a) : (b))
|
||||
#define max(a, b) ((a) > (b) ? (a) : (b))
|
||||
|
||||
rect canonrect(rect r) { /* canonicalize rectangle coordinates */
|
||||
rect temp;
|
||||
|
||||
temp.pt1.x = min(r.pt1.x, r.pt2.x);
|
||||
temp.pt1.y = min(r.pt1.y, r.pt2.y);
|
||||
temp.pt2.x = max(r.pt1.x, r.pt2.x);
|
||||
temp.pt2.y = max(r.pt1.y, r.pt2.y);
|
||||
return temp;
|
||||
}
|
||||
|
||||
point makepoint(int x, int y) { /* make a point from x and y components */
|
||||
point p;
|
||||
|
||||
p.x = x;
|
||||
p.y = y;
|
||||
return p;
|
||||
}
|
||||
|
||||
rect makerect(point p1, point p2) { /* make a rectangle from two points */
|
||||
rect r;
|
||||
|
||||
r.pt1 = p1;
|
||||
r.pt2 = p2;
|
||||
return canonrect(r);
|
||||
}
|
||||
|
||||
int ptinrect(point p, rect r) { /* is p in r? */
|
||||
return p.x >= r.pt1.x && p.x < r.pt2.x
|
||||
&& p.y >= r.pt1.y && p.y < r.pt2.y;
|
||||
}
|
||||
|
||||
struct odd {char a[3]; } y = {'a', 'b', 0};
|
||||
|
||||
odd(struct odd y) {
|
||||
struct odd x = y;
|
||||
printf("%s\n", x.a);
|
||||
}
|
||||
|
||||
main() {
|
||||
int i;
|
||||
point x, origin = { 0, 0 }, maxpt = { 320, 320 };
|
||||
point pts[] = { -1, -1, 1, 1, 20, 300, 500, 400 };
|
||||
rect screen = makerect(addpoint(maxpt, makepoint(-10, -10)),
|
||||
addpoint(origin, makepoint(10, 10)));
|
||||
|
||||
for (i = 0; i < sizeof pts/sizeof pts[0]; i++) {
|
||||
printf("(%d,%d) is ", pts[i].x,
|
||||
(x = makepoint(pts[i].x, pts[i].y)).y);
|
||||
if (ptinrect(x, screen) == 0)
|
||||
printf("not ");
|
||||
printf("within [%d,%d; %d,%d]\n", screen.pt1.x, screen.pt1.y,
|
||||
screen.pt2.x, screen.pt2.y);
|
||||
}
|
||||
odd(y);
|
||||
exit(0);
|
||||
}
|
||||
|
||||
|
|
274
lcc/tst/switch.c
274
lcc/tst/switch.c
|
@ -1,137 +1,137 @@
|
|||
main()
|
||||
{
|
||||
int i; char *s;
|
||||
|
||||
for (s = "bfnrtvx"; *s; s++)
|
||||
printf("%c = 0x%x\n", *s, backslash(*s));
|
||||
f();
|
||||
g();
|
||||
h();
|
||||
for (i = 0x1000000; i&0x7000000; i += 0x1000000)
|
||||
big(i);
|
||||
limit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
backslash(c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'b':
|
||||
return '\b';
|
||||
case 'f':
|
||||
return '\f';
|
||||
case 'n':
|
||||
return '\n';
|
||||
case 'r':
|
||||
return '\r';
|
||||
case 't':
|
||||
return '\t';
|
||||
case 'v':
|
||||
return '\v';
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
f() {
|
||||
int i, x = 0, y;
|
||||
|
||||
printf("f:\n");
|
||||
for (i = 0; i <= 20; i++) {
|
||||
y = i;
|
||||
switch (i) {
|
||||
case 1: x = i; break;
|
||||
case 2: x = i; break;
|
||||
case 7: x = i; break;
|
||||
case 8: x = i; break;
|
||||
case 9: x = i; break;
|
||||
case 16: x = i; break;
|
||||
case 17: x = i; break;
|
||||
case 18: x = i; break;
|
||||
case 19: x = i; break;
|
||||
case 20: x = i; break;
|
||||
}
|
||||
printf("x = %d\n", x);
|
||||
}
|
||||
}
|
||||
|
||||
g() {
|
||||
int i;
|
||||
|
||||
printf("g:\n");
|
||||
for (i = 1; i <= 10; i++)
|
||||
switch (i) {
|
||||
case 1: case 2: printf("1 %d\n", i); break;
|
||||
case 3: case 4: case 5: printf("2 %d\n", i); break;
|
||||
case 6: case 7: case 8: printf("3 %d\n", i);
|
||||
default:
|
||||
printf("d %d\n", i); break;
|
||||
case 1001: case 1002: case 1003: case 1004:
|
||||
printf("5 %d\n", i); break;
|
||||
case 3001: case 3002: case 3003: case 3004:
|
||||
printf("6 %d\n", i); break;
|
||||
}
|
||||
}
|
||||
|
||||
h()
|
||||
{
|
||||
int i, n=0;
|
||||
|
||||
printf("h:\n");
|
||||
for (i = 1; i <= 500; i++)
|
||||
switch (i) {
|
||||
default: n++; continue;
|
||||
case 128: printf("i = %d\n", i); break;
|
||||
case 16: printf("i = %d\n", i); break;
|
||||
case 8: printf("i = %d\n", i); break;
|
||||
case 120: printf("i = %d\n", i); break;
|
||||
case 280: printf("i = %d\n", i); break;
|
||||
case 264: printf("i = %d\n", i); break;
|
||||
case 248: printf("i = %d\n", i); break;
|
||||
case 272: printf("i = %d\n", i); break;
|
||||
case 304: printf("i = %d\n", i); break;
|
||||
case 296: printf("i = %d\n", i); break;
|
||||
case 288: printf("i = %d\n", i); break;
|
||||
case 312: printf("i = %d\n", i); break;
|
||||
}
|
||||
printf("%d defaults\n", n);
|
||||
}
|
||||
|
||||
big(x) unsigned x; {
|
||||
switch(x&0x6000000){
|
||||
case -1:
|
||||
case -2:
|
||||
case 0x0000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
case 0x2000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
case 0x4000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
default:
|
||||
printf("x = 0x%x (default)\n", x); break;
|
||||
}
|
||||
}
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
limit() {
|
||||
int i;
|
||||
|
||||
for (i = INT_MIN; i <= INT_MIN+5; i++)
|
||||
switch (i) {
|
||||
case INT_MIN: printf("0\n"); break;
|
||||
case INT_MIN+1: printf("1\n"); break;
|
||||
case INT_MIN+2: printf("2\n"); break;
|
||||
case INT_MIN+3: printf("3\n"); break;
|
||||
case INT_MIN+4: printf("4\n"); break;
|
||||
default: printf("5\n"); break;
|
||||
}
|
||||
for (i = INT_MAX; i >= INT_MAX-5; i--)
|
||||
switch (i) {
|
||||
case INT_MAX: printf("0\n"); break;
|
||||
case INT_MAX-1: printf("1\n"); break;
|
||||
case INT_MAX-2: printf("2\n"); break;
|
||||
case INT_MAX-3: printf("3\n"); break;
|
||||
case INT_MAX-4: printf("4\n"); break;
|
||||
default: printf("5\n"); break;
|
||||
}
|
||||
}
|
||||
main()
|
||||
{
|
||||
int i; char *s;
|
||||
|
||||
for (s = "bfnrtvx"; *s; s++)
|
||||
printf("%c = 0x%x\n", *s, backslash(*s));
|
||||
f();
|
||||
g();
|
||||
h();
|
||||
for (i = 0x1000000; i&0x7000000; i += 0x1000000)
|
||||
big(i);
|
||||
limit();
|
||||
return 0;
|
||||
}
|
||||
|
||||
backslash(c)
|
||||
{
|
||||
switch (c) {
|
||||
case 'b':
|
||||
return '\b';
|
||||
case 'f':
|
||||
return '\f';
|
||||
case 'n':
|
||||
return '\n';
|
||||
case 'r':
|
||||
return '\r';
|
||||
case 't':
|
||||
return '\t';
|
||||
case 'v':
|
||||
return '\v';
|
||||
}
|
||||
return c;
|
||||
}
|
||||
|
||||
f() {
|
||||
int i, x = 0, y;
|
||||
|
||||
printf("f:\n");
|
||||
for (i = 0; i <= 20; i++) {
|
||||
y = i;
|
||||
switch (i) {
|
||||
case 1: x = i; break;
|
||||
case 2: x = i; break;
|
||||
case 7: x = i; break;
|
||||
case 8: x = i; break;
|
||||
case 9: x = i; break;
|
||||
case 16: x = i; break;
|
||||
case 17: x = i; break;
|
||||
case 18: x = i; break;
|
||||
case 19: x = i; break;
|
||||
case 20: x = i; break;
|
||||
}
|
||||
printf("x = %d\n", x);
|
||||
}
|
||||
}
|
||||
|
||||
g() {
|
||||
int i;
|
||||
|
||||
printf("g:\n");
|
||||
for (i = 1; i <= 10; i++)
|
||||
switch (i) {
|
||||
case 1: case 2: printf("1 %d\n", i); break;
|
||||
case 3: case 4: case 5: printf("2 %d\n", i); break;
|
||||
case 6: case 7: case 8: printf("3 %d\n", i);
|
||||
default:
|
||||
printf("d %d\n", i); break;
|
||||
case 1001: case 1002: case 1003: case 1004:
|
||||
printf("5 %d\n", i); break;
|
||||
case 3001: case 3002: case 3003: case 3004:
|
||||
printf("6 %d\n", i); break;
|
||||
}
|
||||
}
|
||||
|
||||
h()
|
||||
{
|
||||
int i, n=0;
|
||||
|
||||
printf("h:\n");
|
||||
for (i = 1; i <= 500; i++)
|
||||
switch (i) {
|
||||
default: n++; continue;
|
||||
case 128: printf("i = %d\n", i); break;
|
||||
case 16: printf("i = %d\n", i); break;
|
||||
case 8: printf("i = %d\n", i); break;
|
||||
case 120: printf("i = %d\n", i); break;
|
||||
case 280: printf("i = %d\n", i); break;
|
||||
case 264: printf("i = %d\n", i); break;
|
||||
case 248: printf("i = %d\n", i); break;
|
||||
case 272: printf("i = %d\n", i); break;
|
||||
case 304: printf("i = %d\n", i); break;
|
||||
case 296: printf("i = %d\n", i); break;
|
||||
case 288: printf("i = %d\n", i); break;
|
||||
case 312: printf("i = %d\n", i); break;
|
||||
}
|
||||
printf("%d defaults\n", n);
|
||||
}
|
||||
|
||||
big(x) unsigned x; {
|
||||
switch(x&0x6000000){
|
||||
case -1:
|
||||
case -2:
|
||||
case 0x0000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
case 0x2000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
case 0x4000000:
|
||||
printf("x = 0x%x\n", x); break;
|
||||
default:
|
||||
printf("x = 0x%x (default)\n", x); break;
|
||||
}
|
||||
}
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
limit() {
|
||||
int i;
|
||||
|
||||
for (i = INT_MIN; i <= INT_MIN+5; i++)
|
||||
switch (i) {
|
||||
case INT_MIN: printf("0\n"); break;
|
||||
case INT_MIN+1: printf("1\n"); break;
|
||||
case INT_MIN+2: printf("2\n"); break;
|
||||
case INT_MIN+3: printf("3\n"); break;
|
||||
case INT_MIN+4: printf("4\n"); break;
|
||||
default: printf("5\n"); break;
|
||||
}
|
||||
for (i = INT_MAX; i >= INT_MAX-5; i--)
|
||||
switch (i) {
|
||||
case INT_MAX: printf("0\n"); break;
|
||||
case INT_MAX-1: printf("1\n"); break;
|
||||
case INT_MAX-2: printf("2\n"); break;
|
||||
case INT_MAX-3: printf("3\n"); break;
|
||||
case INT_MAX-4: printf("4\n"); break;
|
||||
default: printf("5\n"); break;
|
||||
}
|
||||
}
|
||||
|
|
230
lcc/tst/wf1.0
230
lcc/tst/wf1.0
|
@ -1,115 +1,115 @@
|
|||
/* wf1 - print word frequencies; uses structures */
|
||||
|
||||
struct node {
|
||||
int count; /* frequency count */
|
||||
struct node *left; /* left subtree */
|
||||
struct node *right; /* right subtree */
|
||||
char *word; /* word itself */
|
||||
} words[2000];
|
||||
int next; /* index of next free entry in words */
|
||||
|
||||
struct node *lookup();
|
||||
|
||||
main()
|
||||
{
|
||||
struct node *root;
|
||||
char word[20];
|
||||
|
||||
root = 0;
|
||||
next = 0;
|
||||
while (getword(word))
|
||||
lookup(word, &root)->count++;
|
||||
tprint(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* err - print error message s and die */
|
||||
err(s)
|
||||
char *s;
|
||||
{
|
||||
printf("? %s\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* getword - get next input word into buf, return 0 on EOF */
|
||||
int getword(buf)
|
||||
char *buf;
|
||||
{
|
||||
char *s;
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) != -1 && isletter(c) == 0)
|
||||
;
|
||||
for (s = buf; c = isletter(c); c = getchar())
|
||||
*s++ = c;
|
||||
*s = 0;
|
||||
if (s > buf)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* isletter - return folded version of c if it is a letter, 0 otherwise */
|
||||
int isletter(c)
|
||||
int c;
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* lookup - lookup word in tree; install if necessary */
|
||||
struct node *lookup(word, p)
|
||||
char *word;
|
||||
struct node **p;
|
||||
{
|
||||
int cond;
|
||||
char *malloc();
|
||||
|
||||
if (*p) {
|
||||
cond = strcmp(word, (*p)->word);
|
||||
if (cond < 0)
|
||||
return lookup(word, &(*p)->left);
|
||||
else if (cond > 0)
|
||||
return lookup(word, &(*p)->right);
|
||||
else
|
||||
return *p;
|
||||
}
|
||||
if (next >= 2000)
|
||||
err("out of node storage");
|
||||
words[next].count = 0;
|
||||
words[next].left = words[next].right = 0;
|
||||
words[next].word = malloc(strlen(word) + 1);
|
||||
if (words[next].word == 0)
|
||||
err("out of word storage");
|
||||
strcpy(words[next].word, word);
|
||||
return *p = &words[next++];
|
||||
}
|
||||
|
||||
/* tprint - print tree */
|
||||
tprint(tree)
|
||||
struct node *tree;
|
||||
{
|
||||
if (tree) {
|
||||
tprint(tree->left);
|
||||
printf("%d\t%s\n", tree->count, tree->word);
|
||||
tprint(tree->right);
|
||||
}
|
||||
}
|
||||
|
||||
/* strcmp - compare s1 and s2, return <0, 0, or >0 */
|
||||
int strcmp(s1, s2)
|
||||
char *s1, *s2;
|
||||
{
|
||||
while (*s1 == *s2) {
|
||||
if (*s1++ == 0)
|
||||
return 0;
|
||||
++s2;
|
||||
}
|
||||
if (*s1 == 0)
|
||||
return -1;
|
||||
else if (*s2 == 0)
|
||||
return 1;
|
||||
return *s1 - *s2;
|
||||
}
|
||||
/* wf1 - print word frequencies; uses structures */
|
||||
|
||||
struct node {
|
||||
int count; /* frequency count */
|
||||
struct node *left; /* left subtree */
|
||||
struct node *right; /* right subtree */
|
||||
char *word; /* word itself */
|
||||
} words[2000];
|
||||
int next; /* index of next free entry in words */
|
||||
|
||||
struct node *lookup();
|
||||
|
||||
main()
|
||||
{
|
||||
struct node *root;
|
||||
char word[20];
|
||||
|
||||
root = 0;
|
||||
next = 0;
|
||||
while (getword(word))
|
||||
lookup(word, &root)->count++;
|
||||
tprint(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* err - print error message s and die */
|
||||
err(s)
|
||||
char *s;
|
||||
{
|
||||
printf("? %s\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* getword - get next input word into buf, return 0 on EOF */
|
||||
int getword(buf)
|
||||
char *buf;
|
||||
{
|
||||
char *s;
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) != -1 && isletter(c) == 0)
|
||||
;
|
||||
for (s = buf; c = isletter(c); c = getchar())
|
||||
*s++ = c;
|
||||
*s = 0;
|
||||
if (s > buf)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* isletter - return folded version of c if it is a letter, 0 otherwise */
|
||||
int isletter(c)
|
||||
int c;
|
||||
{
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* lookup - lookup word in tree; install if necessary */
|
||||
struct node *lookup(word, p)
|
||||
char *word;
|
||||
struct node **p;
|
||||
{
|
||||
int cond;
|
||||
char *malloc();
|
||||
|
||||
if (*p) {
|
||||
cond = strcmp(word, (*p)->word);
|
||||
if (cond < 0)
|
||||
return lookup(word, &(*p)->left);
|
||||
else if (cond > 0)
|
||||
return lookup(word, &(*p)->right);
|
||||
else
|
||||
return *p;
|
||||
}
|
||||
if (next >= 2000)
|
||||
err("out of node storage");
|
||||
words[next].count = 0;
|
||||
words[next].left = words[next].right = 0;
|
||||
words[next].word = malloc(strlen(word) + 1);
|
||||
if (words[next].word == 0)
|
||||
err("out of word storage");
|
||||
strcpy(words[next].word, word);
|
||||
return *p = &words[next++];
|
||||
}
|
||||
|
||||
/* tprint - print tree */
|
||||
tprint(tree)
|
||||
struct node *tree;
|
||||
{
|
||||
if (tree) {
|
||||
tprint(tree->left);
|
||||
printf("%d\t%s\n", tree->count, tree->word);
|
||||
tprint(tree->right);
|
||||
}
|
||||
}
|
||||
|
||||
/* strcmp - compare s1 and s2, return <0, 0, or >0 */
|
||||
int strcmp(s1, s2)
|
||||
char *s1, *s2;
|
||||
{
|
||||
while (*s1 == *s2) {
|
||||
if (*s1++ == 0)
|
||||
return 0;
|
||||
++s2;
|
||||
}
|
||||
if (*s1 == 0)
|
||||
return -1;
|
||||
else if (*s2 == 0)
|
||||
return 1;
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
|
202
lcc/tst/wf1.c
202
lcc/tst/wf1.c
|
@ -1,101 +1,101 @@
|
|||
/* wf1 - print word frequencies; uses structures */
|
||||
|
||||
struct node {
|
||||
int count; /* frequency count */
|
||||
struct node *left; /* left subtree */
|
||||
struct node *right; /* right subtree */
|
||||
char *word; /* word itself */
|
||||
} words[2000];
|
||||
int next; /* index of next free entry in words */
|
||||
|
||||
struct node *lookup();
|
||||
|
||||
main() {
|
||||
struct node *root;
|
||||
char word[20];
|
||||
|
||||
root = 0;
|
||||
next = 0;
|
||||
while (getword(word))
|
||||
lookup(word, &root)->count++;
|
||||
tprint(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* err - print error message s and die */
|
||||
err(s) char *s; {
|
||||
printf("? %s\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* getword - get next input word into buf, return 0 on EOF */
|
||||
int getword(buf) char *buf; {
|
||||
char *s;
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) != -1 && isletter(c) == 0)
|
||||
;
|
||||
for (s = buf; c = isletter(c); c = getchar())
|
||||
*s++ = c;
|
||||
*s = 0;
|
||||
if (s > buf)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* isletter - return folded version of c if it is a letter, 0 otherwise */
|
||||
int isletter(c) {
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* lookup - lookup word in tree; install if necessary */
|
||||
struct node *lookup(word, p) char *word; struct node **p; {
|
||||
int cond;
|
||||
char *malloc();
|
||||
|
||||
if (*p) {
|
||||
cond = strcmp(word, (*p)->word);
|
||||
if (cond < 0)
|
||||
return lookup(word, &(*p)->left);
|
||||
else if (cond > 0)
|
||||
return lookup(word, &(*p)->right);
|
||||
else
|
||||
return *p;
|
||||
}
|
||||
if (next >= 2000)
|
||||
err("out of node storage");
|
||||
words[next].count = 0;
|
||||
words[next].left = words[next].right = 0;
|
||||
words[next].word = malloc(strlen(word) + 1);
|
||||
if (words[next].word == 0)
|
||||
err("out of word storage");
|
||||
strcpy(words[next].word, word);
|
||||
return *p = &words[next++];
|
||||
}
|
||||
|
||||
/* tprint - print tree */
|
||||
tprint(tree) struct node *tree; {
|
||||
if (tree) {
|
||||
tprint(tree->left);
|
||||
printf("%d\t%s\n", tree->count, tree->word);
|
||||
tprint(tree->right);
|
||||
}
|
||||
}
|
||||
|
||||
/* strcmp - compare s1 and s2, return <0, 0, or >0 */
|
||||
int strcmp(s1, s2) char *s1, *s2; {
|
||||
while (*s1 == *s2) {
|
||||
if (*s1++ == 0)
|
||||
return 0;
|
||||
++s2;
|
||||
}
|
||||
if (*s1 == 0)
|
||||
return -1;
|
||||
else if (*s2 == 0)
|
||||
return 1;
|
||||
return *s1 - *s2;
|
||||
}
|
||||
/* wf1 - print word frequencies; uses structures */
|
||||
|
||||
struct node {
|
||||
int count; /* frequency count */
|
||||
struct node *left; /* left subtree */
|
||||
struct node *right; /* right subtree */
|
||||
char *word; /* word itself */
|
||||
} words[2000];
|
||||
int next; /* index of next free entry in words */
|
||||
|
||||
struct node *lookup();
|
||||
|
||||
main() {
|
||||
struct node *root;
|
||||
char word[20];
|
||||
|
||||
root = 0;
|
||||
next = 0;
|
||||
while (getword(word))
|
||||
lookup(word, &root)->count++;
|
||||
tprint(root);
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* err - print error message s and die */
|
||||
err(s) char *s; {
|
||||
printf("? %s\n", s);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* getword - get next input word into buf, return 0 on EOF */
|
||||
int getword(buf) char *buf; {
|
||||
char *s;
|
||||
int c;
|
||||
|
||||
while ((c = getchar()) != -1 && isletter(c) == 0)
|
||||
;
|
||||
for (s = buf; c = isletter(c); c = getchar())
|
||||
*s++ = c;
|
||||
*s = 0;
|
||||
if (s > buf)
|
||||
return (1);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* isletter - return folded version of c if it is a letter, 0 otherwise */
|
||||
int isletter(c) {
|
||||
if (c >= 'A' && c <= 'Z')
|
||||
c += 'a' - 'A';
|
||||
if (c >= 'a' && c <= 'z')
|
||||
return (c);
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* lookup - lookup word in tree; install if necessary */
|
||||
struct node *lookup(word, p) char *word; struct node **p; {
|
||||
int cond;
|
||||
char *malloc();
|
||||
|
||||
if (*p) {
|
||||
cond = strcmp(word, (*p)->word);
|
||||
if (cond < 0)
|
||||
return lookup(word, &(*p)->left);
|
||||
else if (cond > 0)
|
||||
return lookup(word, &(*p)->right);
|
||||
else
|
||||
return *p;
|
||||
}
|
||||
if (next >= 2000)
|
||||
err("out of node storage");
|
||||
words[next].count = 0;
|
||||
words[next].left = words[next].right = 0;
|
||||
words[next].word = malloc(strlen(word) + 1);
|
||||
if (words[next].word == 0)
|
||||
err("out of word storage");
|
||||
strcpy(words[next].word, word);
|
||||
return *p = &words[next++];
|
||||
}
|
||||
|
||||
/* tprint - print tree */
|
||||
tprint(tree) struct node *tree; {
|
||||
if (tree) {
|
||||
tprint(tree->left);
|
||||
printf("%d\t%s\n", tree->count, tree->word);
|
||||
tprint(tree->right);
|
||||
}
|
||||
}
|
||||
|
||||
/* strcmp - compare s1 and s2, return <0, 0, or >0 */
|
||||
int strcmp(s1, s2) char *s1, *s2; {
|
||||
while (*s1 == *s2) {
|
||||
if (*s1++ == 0)
|
||||
return 0;
|
||||
++s2;
|
||||
}
|
||||
if (*s1 == 0)
|
||||
return -1;
|
||||
else if (*s2 == 0)
|
||||
return 1;
|
||||
return *s1 - *s2;
|
||||
}
|
||||
|
|
|
@ -1 +1 @@
|
|||
a=-b+5*c
|
||||
a=-b+5*c
|
||||
|
|
1182
lcc/tst/yacc.c
1182
lcc/tst/yacc.c
File diff suppressed because it is too large
Load diff
Loading…
Add table
Add a link
Reference in a new issue