Example #1
0
static int cmp4(const char* a, const char* b) {
#if defined(__i386__) || defined(__x86_64__)
  return *(uint32_t*)a == *(uint32_t*)b;
#else
  return cmp3(a,b) && a[3]==b[3];
#endif
}
Example #2
0
//! int *
int icompare (const void *v1, const void *v2)
{
        const int *i1 = v1;
        const int *i2 = v2;

        return cmp3 (*i1, *i2);
}
Example #3
0
File: sh_cmp.c Project: jalcim/42sh
int			cmp2(t_linez *linez, t_sh *term)
{
	if (!ft_strncmp("setenv", linez->ep_l, 6)
		|| !ft_strncmp("unsetenv", linez->ep_l, 8))
	{
		if (linez->ep_l[6] != ' ' && linez->ep_l[8] != ' ')
			return (0);
		term->status = modif_env(term, linez, 0);
		return (1);
	}
	else if (!ft_strncmp("cd", linez->ep_l, 2))
	{
		term->status = modif_cd(linez, term, 2);
		return (1);
	}
	else if (!ft_strncmp("echo", linez->ep_l, 4))
		return (term->status = ft_echo(linez->ep_l));
	return (cmp3(linez, term));
}
Example #4
0
int main()
{
	int a = A, b = B;
	unsigned ua = uA;
	unsigned ub = uB;
	unsigned uc = uC;

	printf("cmp1(%d, %d) = %d\n", a, b, cmp1(a, b));
	printf("cmp2(%d, %d) = %d\n", a, b, cmp2(a, b));
	printf("cmp3(%d) = %d\n", a, cmp3(a));
	printf("cmp4(%d) = %d\n", a, cmp4(a));
	printf("cmp5(%d) = %d\n", a, cmp5(a));
	printf("cmp6(%d) = %d\n", a, cmp6(a));
	printf("cmp7(%d) = %d\n", a, cmp7(a));
	printf("cmp8(%d) = %d\n", a, cmp8(a));
	printf("cmp9(%d, %d) = %d\n", a, b, cmp9(a, b));
	printf("cmp10(%d, %d) = %d\n", a, b, cmp10(a, b));
	printf("cmp11(%d) = %d\n", a, cmp11(a));
	printf("cmp12(%d) = %d\n", a, cmp12(a));
	printf("cmp13(%d) = %d\n", a, cmp13(a));
	printf("cmp14(%d) = %d\n", a, cmp14(a));
	printf("cmp15(%d) = %d\n", a, cmp15(a));
	printf("cmp16(%d) = %d\n", a, cmp16(a));
	printf("cmp17(%d, %d) = %d\n", a, b, cmp17(a, b));
	printf("cmp18(%d, %d) = %d\n", a, b, cmp18(a, b));

	printf("cmp19(%u, %u) = %d\n", ua, ub, cmp19(ua, ub));
	printf("cmp20(%u, %u) = %d\n", ua, ub, cmp20(ua, ub));
	printf("cmp21(%u, %u) = %d\n", ua, ub, cmp21(ua, ub));
	printf("cmp22(%u, %u) = %d\n", ua, ub, cmp22(ua, ub));
	printf("cmp23(%u, %u) = %d\n", ua, ub, cmp23(ua, ub));

	printf("cmp19(%u, %u) = %d\n", ua, uc, cmp19(ua, uc));
	printf("cmp20(%u, %u) = %d\n", ua, uc, cmp20(ua, uc));
	printf("cmp21(%u, %u) = %d\n", ua, uc, cmp21(ua, uc));
	printf("cmp22(%u, %u) = %d\n", ua, uc, cmp22(ua, uc));
	printf("cmp23(%u, %u) = %d\n", ua, uc, cmp23(ua, uc));

	return 0;
}
Example #5
0
int main()
{
    int ball[12],cmp2_result,cmp3_result,diff=12,err,i;
    char w=' ';
    FILE *fin=fopen("input.txt","r");
    FILE *fout=fopen("output.txt","w");
    for(i=0; i<12; i++)
    ball[i]=fgetc(fin);
    fclose(fin);
        switch(cmp1(ball))
        {
        case 0:
            cmp2_result=cmp2(ball,0,0,0,&err);
            break;
        case 1:
            cmp2_result=cmp2(ball,0,4,1,&err);
            break;
        case 2:
            cmp2_result=cmp2(ball,4,0,1,&err);
            break;
        default:
            break;
        }

        switch(cmp2_result)
        {
        case 0:
            w='l';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        case 1:
            w='h';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        case 2:
            cmp3_result=cmp3(ball,err,0,w);
            break;
        case 3:
            w='h';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        case 4:
            cmp3_result=cmp3(ball,err,0,w);
            break;
        case 5:
            w='l';
            cmp3_result=cmp3(ball,err,1,w);
            break;
        default:
            break;
        }

        switch(cmp3_result)
        {
        case 0:
            diff=11;
            w='h';
            break;
        case 1:
            if(err)
                diff=3;
            else
                diff=7;
            w='h';
            break;
        case 2:
            diff=err+2;
            break;
        case 3:
            diff=err+1;
            break;
        case 4:
            diff=err;
            break;
        case 5:
            diff=err;
            w='l';
            break;
        default:
            break;
        }

       fputs("the error ball is:",fout);
       fprintf(fout,"%d\n",(diff+1));
       fputs("It is ",fout);
        if(w=='h')
               fputs("heavy\n",fout);
        else
               fputs("light\n",fout);
    fclose(fout);
    return 0;
}
Example #6
0
int timer_cmp(const void *v1, const void *v2)
{
        const struct timer *t1  = v1, *t2 = v2;
        return cmp3(t1->time, t2->time);
}
Example #7
0
int main() {
  char line[8192];
  char* dat;
  char* timestamp;
#ifdef oldandslow
  setvbuf(stdout,printfbuf,_IOFBF,sizeof printfbuf);
  while (fgets(line,sizeof(line),stdin)) {
    int tslen;
    /* chomp */
    {
      int i;
      for (i=0; i<sizeof(line) && line[i]; ++i)
	if (line[i]=='\n') break;
      line[i]=0;
    }
#else
  buffer_init(buffer_1,write,1,printfbuf,sizeof printfbuf);
  while (myfgets(line,sizeof(line))+1>1) {
    int tslen;
#endif
    /* find out what kind of time stamp there is */
    tslen=0;
    if (line[0]=='@') {
      /* multilog timestamp */
      char* x=strchr(line,' ');
      if (x) {
	tslen=x-line;
	if (tslen!=25) tslen=0;
      }
    } else if (isdigit(line[0])) {
      char* x=strchr(line,' ');
      if (x && x==line+10) {
	x=strchr(x+1,' ');
	if (x && x==line+29) tslen=29;
      }
    }
    if (tslen) {
      dat=line+tslen+1;
      line[tslen]=0;
      timestamp=line;
    } else {
      dat=line;
      timestamp="";
    }
    /* element two is the unique key */
    {
      char* fields[21];
      char* x=dat;
      int i;

      /* early-out skip the field splitting if we are not interested in
       * the line anyway */
      if (*x != 'a' && *x != 'c' && *x != 'G' && *x != 'P' && *x != 'H')
	continue;

      /* split into fields */
      for (i=0; i<20; ++i) {
	char* y=strchr(x,' ');
	if (!y) break;
	*y=0;
	fields[i]=x;
	x=y+1;
      }
      fields[i]=x; ++i;
      if (!strcmp(fields[0],"accept")) {
	struct node** N;
	struct node* x;
	if (i<2) continue;
	N=lookup(fields[1]);
	if (!(x=*N)) {
	  *N=malloc(sizeof(**N));
	  (*N)->next=0;
	  x=*N;
	} else {
	  free(x->word);
#ifdef oldandslow
	  free(x->ip);
	  free(x->port);
	  free(x->timestamp);
#endif
	}
#ifndef oldandslow
	/* reduce allocations */
	x->word=allocassert(malloc((fields[4]-fields[1])+(fields[0]-line)));
	memcpy(x->word,fields[1],fields[4]-fields[1]);
	x->ip=x->word+(fields[2]-fields[1]);
	x->port=x->ip+(fields[3]-fields[2]);
	x->timestamp=x->port+(fields[4]-fields[3]);
	memcpy(x->timestamp,line,fields[0]-line);
#else
	x->word=allocassert(strdup(fields[1]));
	x->ip=allocassert(strdup(fields[2]));
	x->port=allocassert(strdup(fields[3]));
	x->timestamp=allocassert(strdup(line));
#endif
      } else if (!strncmp(fields[0],"close/",6)) {
	struct node** N;
	N=lookup(fields[1]);
	if (*N) {
	  struct node* y=(*N)->next;
	  struct node* x=*N;
	  free(x->word);
#ifdef oldandslow
	  free(x->ip);
	  free(x->port);
	  free(x->timestamp);
#endif
	  free(x);
	  *N=y;
	}
      } else if (cmp3(fields[0],"GET") || cmp4(fields[0],"POST") || cmp4(fields[0],"HEAD")) {
	if (i>6) {	/* otherwise it's a format violation and we ignore the line */
	  struct node** N;
	  N=lookup(fields[1]);
#ifdef oldandslow
	  printf("%s %s %s http%s://%s%s %s %s %s\n",
		 timestamp,fields[0],*N?(*N)->ip:"::",
		 strstr(fields[0],"SSL")?"s":"",fields[6],fields[2],fields[3],fields[4],fields[5]);
#else
	  buffer_putm(buffer_1,timestamp," ",fields[0]," ",*N?(*N)->ip:"::"," http",
		      strstr(fields[0],"SSL")?"s":"","://",fields[6],fields[2]," ",
		      fields[3]," ",fields[4]," ",fields[5],"\n");
#endif
	}
      }
    }
  }
#ifndef oldandslow
  buffer_flush(buffer_1);
#endif
  return 0;
}
Example #8
0
//! void *
int vcompare (const void *v1, const void *v2)
{
        return cmp3 (v1, v2);
}
Example #9
0
//! void **
int pcompare (const void *pv1, const void *pv2)
{
        const void **v1 = (const void **) pv1;
        const void **v2 = (const void **) pv2;
        return cmp3 (*v1, *v2);
}