Mercurial > hg > CbC > old > device
view test/obsf2.c @ 560:d6ff45d719a5 string-shared
string sharing
author | kono |
---|---|
date | Sat, 07 Jan 2006 18:11:53 +0900 |
parents | 2f577690bcfb |
children | c55337499f96 |
line wrap: on
line source
int printf(const char *format, ...); typedef struct { char x,y; } s; char c[]={' ','\'','.',':',0x1b,'[','H'} , M[ 1843]={4,5,6,} , *m=&M[3], e; int a,b; s P[15],Q[15]; void o(int x,int y){ a=80*(y/2)+x,b= 1+(y&1); e?(m[a]|=b):(m[a]&=~b); printf("#0018:x %02x y %02x a %04x m[a] %02x\n",x,y,a,m[a]); } void W(s*p,s*q){ s t; t=*p; *p=*q; *q=t; } void l(s p, s q){ s t; int x=p.x-q.x, y=p.y-q.y, w, v; printf("#0035:p.x %02x p.y %02x q.x %02x q.y %02x\n",p.x,p.y,q.x,q.y); x=x<0?-x:x; y=y<0?-y:y; if(y<x){ if( q.x<p.x) W(&p,&q); v=p.y<=q.y?1:-1; w=(y%x)/2; for(; p.x<=q.x; p.x++){ o(p.x, p.y); if((w-=y)<=0) w+=x,p.y+=v; } } else if(y){ if(q.y<p.y) W(&p,&q); v=!(p. x>q.x)?1:-1; w=(x%y)/2; for(; p.y<=q.y; p.y++){ o(p.x,q.y); if((w-=x)<=0) w+= y, p.x+=v; } } } extern int rand(); void r(s*p,s q){ p->x=((rand()%80)-q.x)/11; p->y=((rand()%48)-q.y)/11; printf("#0066:r: p->x %02x p->y %02x\n",p->x,p->y); } void d(s*p,s q,s r){ printf("#0070:d0: q->x %02x q->y %02x\n",q.x,q.y); printf("#0071:d1: r->x %02x r->y %02x\n",r.x,r.y); p->x=q.x+r.x; p->y=q.y+r.y; printf("#0074:d2: p->x %02x p->y %02x\n",p->x,p->y); } extern void srand(int); int main(int i,int j,int k){ s R,S; int count; i=0, k=0; srand(512); for(count=0;count<400 ;count++){ j=(i+1)%10; e=0; l(P[j],Q[j]); printf("#0087:main0: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[j].x,Q[j].y); if(--k<=0){ r(&R,P[i]); r(&S,Q[i ]); printf("#0091:main1: R.x %02x R.y %02x S.x %02x S.y %02x\n",R.x,R.y,S.x,S.y); k=10; } d(&P[j],P[i],R); printf("#0095:main2: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y); d(&Q[j],Q[i],S); printf("#0097:main3: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y); i=j; e=1; l(P[j],Q[j]); printf("#0101:main4: p.x %02x p.y %02x q.x %02x q.y %02x\n",P[j].x,P[j].y,Q[i].x,Q[i].y); b=83; if (0) for (a=0; a<sizeof M; a++){ if(--b<=0) b=80,putchar('\n'); putchar(c[M[a]]); } } return 0; }