Exemple #1
0
void *setupUFO() {
	char* string = "<--->";
	pthread_t      thrds[MAXSAUCER];

	int i = 0;
	int j;
	
	/* assign rows and velocities to each saucer */
	srand(getpid());
	while(1) {
		usleep(40*TUNIT);
		if (rand()%9 >= 7) {
			j = i % MAXSAUCER;
			if (ufoInfo[j].live == false && 
				pthread_mutex_lock(&ufo_mx) == 0) {
				strcpy(ufoInfo[j].str, string);	/* the saucer*/
				ufoInfo[j].col = 0;
				ufoInfo[j].row = (rand()%3);	/* the row */
				ufoInfo[j].delay = 5+(rand()%8); /* a speed */
				ufoInfo[j].live = true;
				logMSG(&ufoInfo[j], i, j);
				pthread_create(&thrds[j], NULL, 
				animateSaucer, &ufoInfo[j]);
				pthread_mutex_unlock(&ufo_mx);
			}
		}
		i++;
	}
}
Exemple #2
0
static int daylight_saving(time_t time) {
    	int 		dst_region=0; 
    	int 		last_left_day,last_left_hour; 
    	int 		current_year = 2000; 
 	int 		startDay;
 	int 		endDay;
 	int 		bSaveFlag = 0;
//	time_t 		t;
	struct tm 	*st;
	
//	t = time(NULL);
	st = localtime(&time);
	
    	current_year = 1900 + st->tm_year;
    	last_left_day = st->tm_yday;
	last_left_hour = st->tm_hour;
    	
	dst_region = TimeZone[tzone].dst;
    		
	switch(dst_region){
	        case NA_DST:
			//======================================================================
                	// Daylight Saving Time in the United States and Canada are changing. The
                	// period of Daylight Savings Time will be a total of 4 weeks longer than
                	// before - beginning 3 weeks earlier in Spring and ending 1 week later
                	// in the Fall.                                       (sync with wag325n)
		       {
				int is_leap_year=0;       
				if( (current_year%4==0 && current_year%100!=0) 
					||(current_year%100==0 && current_year%400==0))
					is_leap_year=1;
					startDay = 72 + is_leap_year - (current_year-2002 + (current_year-2004)/4 -2 )%7;										   
					endDay = 309 + is_leap_year - (current_year-2002 + (current_year-2004)/4 - 2)%7;				        
                 	}
  	        	//======================================================================
	            	break;
	        case EU_DST:
			{
			       	int is_leap_year=0;
				if( (current_year%4==0 && current_year%100!=0) 
					||(current_year%100==0 && current_year%400==0))
					is_leap_year=1;

	       	    		startDay = 90 + is_leap_year - (current_year - 2002 + ((current_year - 2000) / 4)) % 7;
	       	    		endDay = 304 + is_leap_year - (current_year - 1999 + ((current_year - 1996) / 4)) % 7;
			}
	            	break;            
	        case AU_DST:
	       	    	startDay = 304 - (current_year - 1999 + ((current_year - 1996) / 4)) % 7;
	       	    	endDay = 90 - (current_year - 2002 + ((current_year - 2000) / 4)) % 7;
	            	break;
	        case CHILE_DST:
	            	startDay = 287 - (current_year - 2000 + ((current_year - 2000) / 4)) % 7;
		    	endDay = 73 - (current_year - 1998 + ((current_year - 1996) / 4)) % 7;
		    	break;  
	        case SA_DST:
	            	startDay = 311 - (current_year-2004 + ((current_year - 2004) / 4)) % 7;
		    	endDay = 52 - (current_year - 1999 + ((current_year - 1996) / 4)) % 7;
		    	break;  
	        case AF_DST:
	            	startDay = 120 - (current_year - 2004 + ((current_year - 2004) / 4)) % 7;
		    	endDay = 273 - (current_year - 2004 + ((current_year - 2004) / 4)) %7;
		    	break;  
	        case IRAQ_DST:
	        	if (current_year%4 != 0){
	            		startDay = 91;
		    		endDay = 274;
		    	}else{
	            		startDay = 92;
		    		endDay = 275;
		    	}
		    	break;  
	        case AU2_DST:
	            	startDay = 280 - (current_year - 2001 + ((current_year - 2000) / 4)) % 7;
		    	endDay = 90 - (current_year - 2002 + ((current_year - 2000) / 4)) % 7;
		    	break;  
	        case AU3_DST:
	            	startDay = 280 - (current_year - 2001 + ((current_year - 2000) / 4)) % 7;
		    	endDay = 80 - (current_year - 1999 + ((current_year - 1996) / 4)) % 7;
		    	break;  
	        default:
	            break;                    
	}
	
	bSaveFlag = 0;	/* The other area can't use daylight saving, so default is 0 */
       	if(dst_region == AU_DST || dst_region == AU2_DST || dst_region == AU3_DST) {    /* AU in south */            
	   	if(current_year == 2006) {
	   		last_left_day++;
	   		if(dst_region == AU_DST)
		   		last_left_day += 2;	   			   	
	  	}
	
	  	if(current_year == 2007 && last_left_day+2 > endDay) {
	  	 	last_left_day++;	   	
	  	}

	  	if(last_left_day >= startDay || last_left_day <= endDay)
    			bSaveFlag = 1;
            	else
    			bSaveFlag = 0;
	} else if (dst_region == IRAQ_DST || dst_region == AF_DST || dst_region == SA_DST
			|| dst_region == CHILE_DST){
	    	if(last_left_day >= startDay-1 && last_left_day <= endDay-1)
			bSaveFlag = 1;
	    	else
	        	bSaveFlag = 0;
	} else if(dst_region == EU_DST) {
	    		if((last_left_day >= (startDay-1)) && (last_left_day <= (endDay-1)))
			{
				bSaveFlag = 1;
				if(((last_left_day == (startDay-1)) && (last_left_hour < 1)) || ((last_left_day == (endDay-1)) && (last_left_hour >= 1)))
				{
					bSaveFlag = 0;
				}
			}
			else {
				bSaveFlag = 0;
			}
	} else if (dst_region == NA_DST) {// GMT-8 --> USA & Canada
	  		if(current_year == 2005) {
				startDay = 92;
				endDay = 302;	
			} else if(current_year == 2006) {
				startDay = 91;
				endDay = 301;	
			} else {
				endDay += 1;	
			}

			
	    		if(last_left_day >= startDay && last_left_day <= endDay)
			{
				bSaveFlag = 1;
				if(((last_left_day == startDay) && (last_left_hour < 2)) || ((last_left_day == endDay) && (last_left_hour >= 2)))
				{
					bSaveFlag = 0;
				}
			}
			else {
				bSaveFlag = 0;
			}
	}
	
#ifdef DEBUG_LOGFILE
	sprintf(logmsg,"bSaveFlag:%d",bSaveFlag);
	logMSG(logmsg);
	sprintf(logmsg,"SD:%d,ED:%d LD:%d LH:%d",startDay,endDay,last_left_day,last_left_hour);
	logMSG(logmsg);
#endif
    	return  bSaveFlag;               
}