Exemplo n.º 1
0
int main(int argc,char** argv)
{
	int i;
	que=createqueue();

	for(i=0;i<100;i++){
		element e;
		e.key=100+i;
		addq(e);
	}
	for(i=0;i<50;i++){
		element e;
		e.key=100+i;
		delq(e);
	}
	for(i=0;i<100;i++){
		element e;
		e.key=100-i;
		addq(e);
	}

	element e=queuefront();
	printf("the front element is %d\n",e.key);
	int num=rear-front;
	for(i=front+1;i<=rear;i++){
		printf("the number of position %d is %d\n",i,que[i].key);
	}
	return 0;
}
Exemplo n.º 2
0
int main(int argc,char** argv)
{
	queue *p=createqueue();
	if(p==NULL){
		exit(EXIT_FAILURE);
	}
	else{
		int i;
		for(i=0;i<9;i++){
			element e;
			e.key=i*2;
			addqueue(p,e);
		}

		for(i=0;i<6;i++){
			delqueue(p);
		}
		for(i=0;i<6;i++){
			element e;
			e.key=i*5;
			addqueue(p,e);
		}
		//delnum(p,5);
		element e;
		e.key=100;
		insnum(p,5,e);
		for(i=0;i<10;i++)
			delqueue(p);
	}

	return 0;
}
Exemplo n.º 3
0
Arquivo: 1344_2.c Projeto: gemire/code
int search(void)
{
	int x0,y0,cout,action,i;
	type p,t;
	memset(array,0,sizeof(array));
	p=malloc(sizeof(struct node));
	p->x=x1;
	p->y=y1; 
	p->cout=0;
	p->action=0;
	array[p->x][p->y][p->action]=1;
	createqueue(1000);
	makeempty(Q);
	enqueue(p,Q);
	while( !isempty(Q) )
	{
   		p=dequeue(Q);
   		if( p->x==x2&&p->y==y2)
    		return p->cout;
   		for(i=0;i<5;++i)
   		{
    		x0=p->x+direction[i][0];
    		y0=p->y+direction[i][1];
    		cout=p->cout+1;
    		action=p->action+1;
    		if(legal(x0,y0,action)&&map[x0][y0]!='*'&&x0>=0&&x0<m&&y0>=0&&y0<n)
    		{
     			if(!array[x0][y0][action]&&!(x0==dogpoint[action].x&&y0==dogpoint[action].y))
     			{
      				array[x0][y0][action]=1;
			   		t=malloc(sizeof(struct node));
      				t->x=x0;
				    t->y=y0;
      				if(action==D) 
					  action=0;
      				t->action=action;
      				t->cout=cout;
      				enqueue(t,Q);
     			}
    		}
  		}
	}
return -1;
}	
Exemplo n.º 4
0
void
loop ()
{
  // event interface
  int fd = -1;			/* the file descriptor for the device */
  int i;			/* loop counter */
  size_t read_bytes;		/* how many bytes were read */
  struct input_event ev[64];	/* the events (up to 64 at once) */
  int key;			/*key code */
  /* used if event hit fn */
  int hasSomething;

#ifdef HAVE_LIBXOSD
  // prepare queue handling
  int flag = 0, brightness = 0, sound = 0;
  createqueue ();
#endif
  
  if (strcasecmp(devinput,"AUTO")==0) { // try to figure out rigth event value for keyboard
	  snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));
	  syslog(LOG_INFO,"autodevice determines %s as keyboard event",devinput);
  }
  
  if ((fd = open (devinput, O_RDONLY)) < 0)
    {
      syslog (LOG_CRIT,"event interface (%s) open failed: %m",devinput);
      // shoot auto as LAST chance
      snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));
      syslog(LOG_CRIT,"autodevice determines %s as a last chance keyboard event",devinput);
      if ((fd = open (devinput, O_RDONLY)) < 0)
        {
	      syslog(LOG_CRIT,"Event interface (%s) open failed: %m",devinput);
              cleanExit(EXIT_FAILURE);
	}
    }

  /* handle important signal */
  if (signal(SIGTERM,signal_handler) < 0)
    {
      perror("signal");
      exit(EXIT_FAILURE);
    }
  if (signal(SIGHUP,signal_handler) < 0)
    {
      perror("signal");
      exit(EXIT_FAILURE);
    }

  syslog(LOG_INFO,"fsfn loaded");


  while (1)
    {				/* loop */
      hasSomething = 0;		/* nothing yet */

      /*
       * read the event interface 
       */
      if ( (read_bytes = read (fd, ev, sizeof (struct input_event) * 64))==-1) {
	      //fprintf(stderr,"Error: %d\n",errno);
	      if (errno==ENODEV) { // event is now invalid ? must be back from sleep...
		      syslog(LOG_NOTICE,"Start sleeping...");
		      sleep(10);		      
		      syslog(LOG_NOTICE,"End sleeping...");

		      close(fd); // is this needed ??
		      
		      syslog(LOG_NOTICE,"Input device changed, back from suspend ?: %m");
		      
		      // get new event
		      snprintf(devinput,MAX_DEVINPUT_SIZE,"/dev/input/event%d",getItemEvent(DEFAULT_KEYBOARD_NAME));
      		      syslog(LOG_NOTICE,"autodevice determines %s as new event",devinput);
		      
		      // reopen - seems to be problems after a hibernate :(
      		      if ((fd = open (devinput, O_RDONLY)) < 0)
        	        {
				syslog(LOG_CRIT,"New event interface (%s) open failed: %m",devinput); 
				cleanExit(EXIT_FAILURE);
			}
		      // read it
		      if ((read_bytes = read (fd, ev, sizeof (struct input_event) * 64))==-1) 
		        {
				syslog(LOG_CRIT,"Reading new device (%s) failed: %m",devinput);
				cleanExit(EXIT_FAILURE);
		        }
	      }
	      else {
		      syslog(LOG_CRIT,"Input device reading failed: %m");
		      cleanExit(EXIT_FAILURE);
	      }
	}
      	
      if (read_bytes < (int) sizeof (struct input_event))
	{
	  syslog (LOG_CRIT,"short read: %m");
	  cleanExit(EXIT_FAILURE);
	}
      
      /*
       * Loop for all readed events until we have something
       * interesting.. 
       */
      for (i = 0;
	   !hasSomething
	   && (i < (int) (read_bytes / sizeof (struct input_event))); i++)
	{
	  hasSomething = (ev[i].type == FN_INPUT_TYPE)
	    && (ev[i].code == FN_INPUT_CODE)
	    && (ev[i].value == FN_INPUT_VALUE);
	}
      
      /*
       * If we got a FN event, plz do something... 
       */
      if (hasSomething && (key = getCodes ()))
	{
	  if ((key & FN_F5) == FN_F5)
	    { 
	      	// check config
	      	if (!checkConfig("F5_CMD"))
		  {
	      		// lower brightness
#ifdef HAVE_LIBXOSD
	      		flag = MOD_BRIGHTNESS;
	      		brightness = setBrightness (getBrightness () - 1);
	      		sendmsg (flag, brightness, sound);
			sendcmd (FN_F5);
#else
	      		setBrightness (getBrightness () - 1);
#endif
		  }
	    }
	  if ((key & FN_F6) == FN_F6)
	    {
	    	// check config
		if (!checkConfig("F6_CMD")) 
		  {
		  	
	    		// higher brightness
#ifdef HAVE_LIBXOSD
	      		flag = MOD_BRIGHTNESS;
	      		brightness = setBrightness (getBrightness () + 1);
	      		sendmsg (flag, brightness, sound);
			sendcmd (FN_F6);
#else
	      		setBrightness (getBrightness () + 1);
#endif
		  }
	    }

	  if ((key & FN_F2) == FN_F2)
	    {
		// check config
		if (!checkConfig("F2_CMD"))
		  {
#ifdef HAVE_LIBXOSD
	      		flag = MOD_SOUND;
	      		sound = mute (SOUND_STEP);
	      		sendmsg (flag, brightness, sound);
			sendcmd(FN_F2);
#else
	      		mute (SOUND_STEP);			
#endif
		  }
	    }
	  if ((key & FN_F3) == FN_F3)
	    {
		if (!checkConfig("F3_CMD"))
	          {
#ifdef HAVE_LIBXOSD
	      		flag = MOD_SOUND;
	      		sound = volume_down (SOUND_STEP);	//mod by SilSha
	      		sendmsg (flag, brightness, sound);
			sendcmd(FN_F3);
#else
	      		volume_down (SOUND_STEP);
#endif
		  }
	    }
	  if ((key & FN_F4) == FN_F4)
	    {
	       if (!checkConfig("F4_CMD"))
	         {
#ifdef HAVE_LIBXOSD
	      		flag = MOD_SOUND;
	      		sound = volume_up (SOUND_STEP);		//mod by SilSha
	      		sendmsg (flag, brightness, sound);
			sendcmd(FN_F4);
#else
	      		volume_up (SOUND_STEP);
#endif
		 }	
	    }
	 /* NO built in commands */
	  if ((key & FN_F7) == FN_F7)
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("F7_CMD"))
		sendcmd(FN_F7);
#else
	      sendcmd(FN_F7);
#endif
	    }
	  if ((key & FN_F10) == FN_F10)
	    {
#ifdef HAVE_LIBXOSD
	      if(!checkConfig("F10_CMD"))
		sendcmd(FN_F10);
#else
	      sendcmd(FN_F10);
#endif
	    }
	  if ((key & FN_F12) == FN_F12)
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("F12_CMD"))
		sendcmd(FN_F12);
#else
	      checkConfig("F12_CMD");
#endif
	    }
	  if (( key & S1_BTN) == S1_BTN) 
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("S1_CMD"))
		sendcmd(S1_BTN);
#else
	      checkConfig("S1_CMD");
#endif
	    }
	  if (( key & S2_BTN) == S2_BTN)
	    {
#ifdef HAVE_LIBXOSD
	      if (!checkConfig("S2_CMD"))
		sendcmd(S2_BTN);
#else
	      checkConfig("S2_CMD");
#endif
	    }		  
	}
    }// while
}
Exemplo n.º 5
0
int main()
{
	struct list list;
	createqueue(&list, 100, 0, NULL);
	if (empty(&list))
	{
		// printf("%s\n", "empty");

		printf("%ld %ld %d\n", getcurqueuelen(&list), getmaxqueuelen(&list), full(&list));

		looplist_test(list)
		{
			int *data = (int *)headquenode->data;
			printf("%d", *data);
		}
		printf("\n");

		int array[10] = {0,9,3,7,6,4,1,2,8,0};
		for (int i = 0; i < 1; i++)
		{
			push(&list, &array[i], array[i]);
		}

		printf("%ld %ld %d\n", getcurqueuelen(&list), getmaxqueuelen(&list), full(&list));

		looplist_test(list)
		{
			int *data = (int *)headquenode->data;
			printf("%d", *data);
		}
		printf("\n");

		for (int i = 1; i < 6; i++)
		{
			push(&list, &array[i], array[i]);
		}

		printf("%ld %ld %d\n", getcurqueuelen(&list), getmaxqueuelen(&list), full(&list));

		looplist_test(list)
		{
			int *data = (int *)headquenode->data;
			printf("%d ", *data);
		}
		printf("\n");

		for (int j = 1; j <= 19; j++)
		{
			for (int i = 1; i < 6; i++)
			{
				push(&list, &array[i], array[i]);
			}
		}

		printf("%ld %ld %d\n", getcurqueuelen(&list), getmaxqueuelen(&list), full(&list));

		looplist_test(list)
		{
			int *data = (int *)headquenode->data;
			printf("%d ", *data);
		}
		printf("\n");
	}