void cellophane_new(WsHandler * ws_handler, char * tcp_protocol , char * address, int port, char * path, int protocol, int read, int  checkSslPeer, enum cellophane_debug_level debug){

    int url_size = (int)(strlen(tcp_protocol) + strlen(address) + strlen(path) + findn(port) + findn(protocol) ) + 3;
    ws_handler->socketIOUrl = malloc(url_size);
    sprintf(ws_handler->socketIOUrl,"%s%s:%d/%s/%d", tcp_protocol, address, port, path, protocol);
    ws_handler->serverHost = address;
    ws_handler->serverPort = port;
    int path_size = (int)(strlen(path) + findn(protocol) ) + 2;
    ws_handler->serverPath = malloc(path_size);
    sprintf(ws_handler->serverPath,"/%s/%d",path, protocol);
    ws_handler->read = read;
    ws_handler->checkSslPeer = checkSslPeer;

    ws_handler->lastId = 0;
    ws_handler->keep_alive_flag = 0;
    ws_handler->checkSslPeer = 1;
    ws_handler->handshakeTimeout = NULL;
    if(ws_handler->debug_level == NULL){
        ws_handler->debug_level = debug;
    }

    ws_handler->user_events_len = 0;

    cellophane_reset_default_events(ws_handler);

}
Example #2
0
File: n5.c Project: aksr/heirloom
static void
_casewh(struct d *dp)
{
	register int i, j, k;

	lgf++;
	skip(1);
	i = vnumb((int *)0);
	if (nonumb)
		return;
	skip(0);
	j = getrq(1);
	if ((k = findn(dp, i)) != NTRAP) {
		dp->mlist[k] = j;
		return;
	}
	for (k = 0; k < NTRAP; k++)
		if (dp->mlist[k] == 0)
			break;
	if (k == NTRAP) {
		flusho();
		errprint("cannot plant trap.");
		return;
	}
	dp->mlist[k] = j;
	dp->nlist[k] = i;
	chkt(dp, i);
}
void cellophane_new(WsHandler * ws_handler, char * tcp_protocol , char * address, int port, char * path, int protocol, int read, int  checkSslPeer, enum cellophane_debug_level debug){

	char *trans_protocol_query = "transport=polling";
    int url_size = (int)(strlen(tcp_protocol) + strlen(address) + strlen(path) + findn(port) + strlen(trans_protocol_query) ) + 4;
    ws_handler->socketIOUrl = malloc(url_size);
    sprintf(ws_handler->socketIOUrl,"%s%s:%d/%s/?%s", tcp_protocol, address, port, path, trans_protocol_query);
	fprintf(stderr, "URL : %s \n", ws_handler->socketIOUrl);
    ws_handler->serverHost = address;
    ws_handler->serverPort = port;
    int path_size = (int)(strlen(path) ) + 1;
    ws_handler->serverPath = malloc(path_size);
    sprintf(ws_handler->serverPath, "/%s", path);
    ws_handler->read = read;
    ws_handler->checkSslPeer = checkSslPeer;
    ws_handler->lastId = 0;
    ws_handler->keep_alive_flag = 0;
    ws_handler->checkSslPeer = 1;
    ws_handler->handshakeTimeout = 1000;
    if(ws_handler->debug_level == NULL){
        ws_handler->debug_level = debug;
    }

    ws_handler->user_events_len = 0;
    cellophane_reset_default_events(ws_handler);

}
Example #4
0
int main(void)
{
    int w, h, n;

    while (scanf("%d %d", &h, &w) == 2) {
        if (!h && !w)
            break;
        if (h == 1) {
            printf("0 1\n");
            continue;
        }
        if (w == 1) {
            while ((h >> w) != 1)
                w++;
            printf("%d %d\n", w, 2 * h - 1);
            continue;
        }
        if (w + 1 == h) {
            printf("1 %d\n", w + h);
            continue;
        }
        n = findn(h, w);
        printf("%d %d\n", (w - 1) / (n - 1), (n + 1) * h - w * n);
    }
    return 0;
}
Example #5
0
File: aidp3.c Project: punu92/aidp
void curve(int start, int end)
{
vertx st,en,vprev;
vertx *c;
int i,j,k,l,cnt=0,prev=0;
float avg;

st=v[start];
en=v[end];

c=(vertx *)malloc(vcount*sizeof(vertx));

findn(c,&cnt,st.i,st.j,en);

if(cnt)
   {if(cnt!=1)
	   avg=(totvd/(cnt-1));                                //Get the Avg. Vertical Dist.
   else avg=totvd;
if(cnt<10)
	{
	for(i=0;i<cnt;i++)
		{c[i].yes=1;}	
	}

   for(i=0;i<vdcount;i++)                           //Calculate the mean deviation
      vdev+=abs(vd[i]-avg);
   printf("vdev before division=%f and vdcount=%d\n",vdev,vdcount);
   if(cnt!=1) vdev/=(cnt-1);

   ep = avg + alpha*vdev;                           //Vertical dist. threshold Epsilon for A
   omega=(totrd/cnt)+beta*vdev;                             
   printf("cnt=%d\tavg=%f\nvdev=%f\tep=%f\ntotvd=%f\ttotrd=%f\n",cnt,avg,vdev,ep,totvd,totrd);
   }
else
   {ep=0;omega=0;}

aidp(c,0,cnt);
c[cnt-1].yes=1;

    for(k=0;k<cnt;k++)
    {
    for(l=0;l<mark;l++)
	if(v[l].i==c[k].i && v[l].j==c[k].j && c[k].yes==1)
		{prev++;v[l].yes=1;
		if(prev>1)
		bresenham_line(vprev.i,vprev.j,c[k].i,c[k].j,col);
		vprev=c[k];}
    }

free(c);
}
Example #6
0
int main(){
    int t;
    scanf("%d",&t);
    for(int a0 = 0; a0 < t; a0++){
        int n,size_n,count=0,digit,number;
        scanf("%d",&n);
        number=n;
        size_n=findn(n);
        for(int a1=0;a1<size_n;a1++){
            digit=n%10;
            if(digit!=0)
            {
            if(number%digit==0)
            {
                count++;
            }
            }
           n=n/10;
        }
      printf("%d\n",count);
    }
    return 0;
}
Example #7
0
File: aidp.c Project: punu92/aidp
//----------------------------------------------------------------------------------------------------------------------------
float findPath(vertx *cvA,vertx *cvB,int *acnt,int *bcnt,int i, int j, vertx p2)//Traverse the curves A and B
{
int a=0,err=0,next1row,next1col,next2row,next2col,dir1,dir2;
float epA=0, epB=0, avA=0, avB=0;
int cntA,cntB;

cntA=*(acnt);
cntB=*(bcnt);
if(j>0 && *(mat+i*col+j-1)==0){a++;   next1row=i; next1col=j-1; dir1=4;}
   
if(*(mat+i*col+j+1)==0 && *(taken+i*col+j+1)){if(a==1){next2row=i;next2col=j+1;dir2=0;} else{next1row=i;next1col=j+1;dir1=0;} a++;}

if(i>0 && *(mat+(i-1)*col+j+1)==0 && *(taken+(i-1)*col+j+1) && a<=2){if(a==1){next2row=i-1;next2col=j+1;dir2=1;} else{next1row=i-1;next1col=j+1;dir1=1;} a++;}

if(i>0 && j>0 && *(mat+(i-1)*col+j-1)==0 && *(taken+(i-1)*col+j-1) && a<=2){if(a==1){next2row=i-1;next2col=j-1;dir2=3;} else{next1row=i-1;next1col=j-1;dir1=3;} a++;}

if(i>0 && *(mat+(i-1)*col+j)==0 && *(taken+(i-1)*col+j) && a<=2){if(a==1){next2row=i-1;next2col=j;dir2=2;} else{next1row=i-1;next1col=j;dir1=2;} a++;}

if(j>0 && *(mat+(i+1)*col+j-1)==0 && *(taken+(i+1)*col+j-1) && a<=2){if(a==1){next2row=i+1;next2col=j-1;dir2=5;} else{next1row=i+1;next1col=j-1;dir1=5;} a++;}

if(*(mat+(i+1)*col+j)==0 && *(taken+(i+1)*col+j) && a<=2){if(a==1){next2row=i+1;next2col=j;dir2=6;} else{next1row=i+1;next1col=j;dir1=6;} a++;}

if(*(mat+(i+1)*col+j+1)==0 && *(taken+(i+1)*col+j+1) && a<=2){if(a==1){next2row=i+1;next2col=j+1;dir2=7;} else{next1row=i+1;next1col=j+1;dir1=7;} a++;}

printf("next1row:%d\tnext1col:%d\nnext2row:%d\tnext2col:%d\n",next1row,next1col,next2row,next2col);
if(a>2)
       return -1;
//------------------Traverse curve A
if(p2.i!=next1row && p2.j!=next1col)
   {
   *(visited+next1row*col+next1col)=1;
   //printf("entered 1st call\n");
   findn(cvA,&cntA,next1row,next1col,dir1,p2);}

if(cntA)
   {
   avA=(totvd/(cntA-1));                                //Get the Avg. Vertical Dist.
   
   for(i=0;i<vdcount;i++)                           //Calculate the mean deviation
      vdev+=abs(vd[i]-avA);
   printf("vdev before division=%f and vdcount=%d",vdev,vdcount);
   vdev/=(cntA-1);

   epA = avA + alpha*vdev;                           //Vertical dist. threshold Epsilon for A
   omega=totrd;                             
   printf("cntA=%d\tavA=%f\nvdev=%f\tepA=%f\ntotvd=%f\ttotrd=%f",cntA,avA,vdev,epA,totvd,totrd);
   }
else
   {epA=0;omega=0;}

//--------------------Traverse curve B
totvd=0;totrd=0;
if(p2.i!=next2row && p2.j!=next2col)
   {
   *(visited+next2row*col+next2col)=1;
   findn(cvB,&cntB,next2row,next2col,dir2,p2);
   }

if(cntB)
   {   
   avB=(totvd/(cntB-1));                                 //Get the Avg. Vertical Dist.
   vdev=0.0;
   for(i=0;i<vdcount;i++)                             //Calculate the mean deviation
      vdev+=abs(vd[i]-avB);
   printf("vdev before division=%f and vdcount=%d",vdev,vdcount);
   vdev/=(cntB-1);

   epB = avB + alpha*vdev;                            //Vertical dist. threshold Epsilon for B
   omega+=totrd;
   omega/=(cntA+cntB-1);                               
   printf("cntB=%d\tavB=%f\nvdev=%f\tepB=%f\tomega=%f\ntotvd=%f\ttotrd=%f\n",cntB,avB,vdev,epB,omega,totvd,totrd);
   }

else
   {epB=0;omega=0;}

*(acnt)=cntA; *(bcnt)=cntB;

if(epA>epB) return epA;
return epB;

}
Example #8
0
File: n7.c Project: 99years/plan9
void newline(int a)
{
	int i, j, nlss;
	int opn;

	nlss = 0;
	if (a)
		goto nl1;
	if (dip != d) {
		j = lss;
		pchar1((Tchar)FLSS);
		if (flss)
			lss = flss;
		i = lss + dip->blss;
		dip->dnl += i;
		pchar1((Tchar)i);
		pchar1((Tchar)'\n');
		lss = j;
		dip->blss = flss = 0;
		if (dip->alss) {
			pchar1((Tchar)FLSS);
			pchar1((Tchar)dip->alss);
			pchar1((Tchar)'\n');
			dip->dnl += dip->alss;
			dip->alss = 0;
		}
		if (dip->ditrap && !dip->ditf && dip->dnl >= dip->ditrap && dip->dimac)
			if (control(dip->dimac, 0)) {
				trap++; 
				dip->ditf++;
			}
		return;
	}
	j = lss;
	if (flss)
		lss = flss;
	nlss = dip->alss + dip->blss + lss;
	numtabp[NL].val += nlss;
	if (TROFF && ascii) {
		dip->alss = dip->blss = 0;
	}
	pchar1((Tchar)'\n');
	flss = 0;
	lss = j;
	if (numtabp[NL].val < pl)
		goto nl2;
nl1:
	ejf = dip->hnl = numtabp[NL].val = 0;
	ejl = frame;
	if (donef) {
		if ((!nc && !wch) || ndone)
			done1(0);
		ndone++;
		donef = 0;
		if (frame == stk)
			nflush++;
	}
	opn = numtabp[PN].val;
	numtabp[PN].val++;
	if (npnflg) {
		numtabp[PN].val = npn;
		npn = npnflg = 0;
	}
nlpn:
	if (numtabp[PN].val == pfrom) {
		print++;
		pfrom = -1;
	} else if (opn == pto) {
		print = 0;
		opn = -1;
		chkpn();
		goto nlpn;
	}
	if (print)
		ptpage(numtabp[PN].val);	/* supposedly in a clean state so can pause */
	if (stop && print) {
		dpn++;
		if (dpn >= stop) {
			dpn = 0;
			ptpause();
		}
	}
nl2:
	trap = 0;
	if (numtabp[NL].val == 0) {
		if ((j = findn(0)) != NTRAP)
			trap = control(mlist[j], 0);
	} else if ((i = findt(numtabp[NL].val - nlss)) <= nlss) {
		if ((j = findn1(numtabp[NL].val - nlss + i)) == NTRAP) {
			flusho();
			ERROR "Trap botch." WARN;
			done2(-5);
		}
		trap = control(mlist[j], 0);
	}
}
Example #9
0
File: aidp3.c Project: punu92/aidp
//----------------------------------------------------------------------------------------------------------------------------
float findPath(vertx *cvA,vertx *cvB,int *acnt,int *bcnt,vertx p1, vertx p2)//Traverse the curves A and B
{
int i,j;
int a=0,err=0,next1row,next1col,next2row,next2col,dir1,dir2;
float epA=0, epB=0, avA=0, avB=0;
int cntA,cntB;

i=p1.i;j=p1.j;

cntA=*(acnt);
cntB=*(bcnt);

for(a=0;a<mark && (v[a].i!=i || v[a].j!=j);a++);

printf("fP: a=%d row=%d col=%d\n",a,i,j);

next1row=v[(a+1)%mark].i;
next1col=v[(a+1)%mark].j;

next2row=v[(mark+a-1)%mark].i;
next2col=v[(mark+a-1)%mark].j;

printf("next1row:%d\tnext1col:%d\nnext2row:%d\tnext2col:%d\n",next1row,next1col,next2row,next2col);


//------------------Traverse curve A
if(p2.i!=next1row || p2.j!=next1col)
   {
   *(visited+next1row*col+next1col)=1;
   printf("entered 1st call\n");
   findn(cvA,&cntA,next1row,next1col,p2);}
else printf("couldn't enter");

if(cntA)
   {if(cntA!=1)
	   avA=(totvd/(cntA-1));                                //Get the Avg. Vertical Dist.
   else avA=totvd;

if(cntA<10)
	{
	for(i=0;i<cntA;i++)
		{cvA[i].yes=1;}	
	}
   for(i=0;i<vdcount;i++)                           //Calculate the mean deviation
      vdev+=abs(vd[i]-avA);
   printf("vdev before division=%f and vdcount=%d\n",vdev,vdcount);
   if(cntA!=1) vdev/=(cntA-1);

   epA = avA + alpha*vdev;                           //Vertical dist. threshold Epsilon for A
   omega=totrd;                             
   printf("cntA=%d\tavA=%f\nvdev=%f\tepA=%f\ntotvd=%f\ttotrd=%f\n",cntA,avA,vdev,epA,totvd,totrd);
   }
else
   {epA=0;omega=0;}

//--------------------Traverse curve B
totvd=0;totrd=0;
if(p2.i!=next2row || p2.j!=next2col)
   {
   *(visited+next2row*col+next2col)=1;
   findn(cvB,&cntB,next2row,next2col,p2);
   }

if(cntB)
   {if(cntB!=1)
	   avB=(totvd/(cntB-1));                                 //Get the Avg. Vertical Dist.
    else
	avB=totvd;

if(cntB<10)
	{
	for(i=0;i<cntB;i++)
		{cvB[i].yes=1;}	
	}
   vdev=0.0;
   for(i=0;i<vdcount;i++)                             //Calculate the mean deviation
      vdev+=abs(vd[i]-avB);
   printf("vdev before division=%f and vdcount=%d\n",vdev,vdcount);
   if(cntB!=1) vdev/=(cntB-1);

   epB = avB + alpha*vdev;                            //Vertical dist. threshold Epsilon for B
   omega+=totrd;
   omega/=(cntA+cntB-1);                               
   printf("cntB=%d\tavB=%f\nvdev=%f\tepB=%f\tomega=%f\ntotvd=%f\ttotrd=%f\n",cntB,avB,vdev,epB,omega,totvd,totrd);
   }

else
   {epB=0;omega=0;}

*(acnt)=cntA; *(bcnt)=cntB;

if(epA>epB) return epA;
return epB;

}