/* update_toggle_modifiers:
 *  Update the state of Num Lock, Caps Lock, and Scroll Lock.
 */
static void update_toggle_modifiers(void)
{
#define ON_OFF(code, on)      \
{                             \
   if (on)                    \
         modifiers |= code;   \
   else                       \
         modifiers &= ~code;  \
}
   /* GetKeyState appears to be the only reliable way of doing this.  GetKeyboardState
    * is updated a bit too late in some cases. Maybe it would work if WM_CHARs were
    * used, since they arrive after the WM_KEYDOWNs that trigger them.
    */
   ON_OFF(ALLEGRO_KEYMOD_NUMLOCK, GetKeyState(VK_NUMLOCK) & 1);
   ON_OFF(ALLEGRO_KEYMOD_CAPSLOCK, GetKeyState(VK_CAPITAL) & 1);
   ON_OFF(ALLEGRO_KEYMOD_SCROLLLOCK, GetKeyState(VK_SCROLL) & 1);

#undef ON_OFF
}
static void ALP_En(void)
{
	#ifdef	L_DEBUG
		Debug_PutString("\n\rALP ENABLED..");
	#endif
	if( ON_OFF() )
	{
		if( SR2 && !SR3 )
			Ph_R_ON();
		Reset_Z();
	}											
	else
	{
		if(SR3 || SR4)
			Ph_R_OFF();
		Reset_Z();	 
	}					
	
	if( ON_OFF_Y() )
	{
		if(SY2 && !SY3)
			Ph_Y_ON();
		Reset_Z();
	}											
	else
	{
		if(SY3 || SY4)
			Ph_Y_OFF();
		Reset_Z();	 
	}							
	
	if( ON_OFF_B() )
	{
		if(SB2 && !SB3)
				Ph_B_ON();
			Reset_Z();
	}									
	else
	{
		if(SB3 || SB4)
			Ph_B_OFF();	
		Reset_Z();	 
	}							
}
Esempio n. 3
0
void CEngine::printStacks()
{
    char line[2048];
    QByteArray s;

    send_to_user(" -----------------------------\n");

    sprintf(line,
	    "Conf: Mapping %s, AutoChecks [Desc %s, Exits %s, Terrain %s],\r\n"
            "      AutoRefresh settings %s (RName/Desc quotes %i/%i), \r\n"
            "      AngryLinker %s DualLinker %s\r\n",
            ON_OFF(mapping), ON_OFF(conf->getAutomerge()),
            ON_OFF(conf->getExitsCheck() ), ON_OFF(conf->getTerrainCheck() ),
            ON_OFF(conf->getAutorefresh() ), conf->getNameQuote(), conf->getDescQuote(),
            ON_OFF(conf->getAngrylinker() ),ON_OFF(conf->getDuallinker() )              );

    send_to_user(line);
    stacker.printStacks();
}
Esempio n. 4
0
int main(int argc, char **argv)
{
  int c;
  int     sockfd;
  struct sockaddr_in servaddr, cliaddr;
  int n;
  socklen_t len;
  char msg[MAX_MSG_LENGTH];
  int i;

  settings_init();

  /* process arguments */
  while (-1 != (c = getopt(argc, argv, "hp:dl:Lc:n:e:v"))) {
    switch (c) {
    case 'h':
      showusage();
      exit(EXIT_SUCCESS);
      break;
    case 'p':
      settings.port = atoi(optarg);
      break;
    case 'd':
      settings.daemon = 1;
      break;
    case 'l':
      settings.ipaddr = strdup(optarg);
      break;
    case 'L':
      settings.localonly = 1;
      break;
    case 'c':
      settings.workernum = atoi(optarg);
      break;
    case 'n':
      settings.queuesize = atoi(optarg);
      break;
    case 'e':
      settings.exepath = strdup(optarg);
      break;
    case 'v':
      settings.verbose++;
      break;
    default:
      //fprintf(stderr, "unknown option -- '%c'\n", c);
      return 1;
    }
  }

  if (settings.port < 1) {
    fprintf(stderr, "please use '-p' to specify a port(>1) to listen to\n");
    exit(-1);
  }

  if (settings.workernum < 1) {
    fprintf(stderr, "please use '-c' to specify max num(>1) of concurrent workers\n");
    exit(-1);
  }

  if (settings.queuesize < 1) {
    fprintf(stderr, "please use '-n' to specify queue size(>1)\n");
    exit(-1);
  }

  
  if (settings.exepath == NULL || settings.exepath[0] == '\0') {
    fprintf(stderr, "empty 'script path', use '-e' to specify it\n");
    exit(-1);
  }
  if (access(settings.exepath, R_OK | X_OK) != 0) {
    fprintf(stderr, "script not readble or executable: %s\n", strerror(errno));
    exit(-1);
  }
  
  /* print setttngs */
  printf("settings:\n");
  printf("\tlisten port:  %d\n", settings.port);
  printf("\tdaemon mode:  %s\n", ON_OFF(settings.daemon));
  printf("\tlisten addr:  %s\n",
         (settings.ipaddr != NULL) ? settings.ipaddr : "INADDR_ANY");
  printf("\tlocal only:   %s\n", ON_OFF(settings.localonly));
  printf("\tworker num    %d\n", settings.workernum);
  printf("\tqueue size    %d\n", settings.queuesize);
  printf("\tscript path:  '%s'\n", settings.exepath);
  printf("\tverbose:      %s\n", ON_OFF(settings.verbose));

  /* allocate space for queue */
  id_queue = (int*)malloc(sizeof(int) * settings.queuesize);
  if (id_queue == NULL) {
    fprintf(stderr, "can not allocate memory for id queue\n");
    exit(-1);
  }
  
  for (i = 0; i < MAX_IFNUM; i++) {
    ipaddrs[i] = (char*)malloc(20);
    bzero(ipaddrs[i], 20);
  }
  ifnum = getaddrs(ipaddrs);
  if (ifnum <= 0) {
    fprintf(stderr, "can not get ip address of interface(s)\n");
    exit(EXIT_FAILURE);
  } else if (settings.verbose > 0) {
    printf("ip address of interface(s):\n");
    for (i = 0; i < ifnum; i++) {
      printf("\t%s\n", ipaddrs[i]);
    }
  }

  if (settings.daemon) {
    if (daemonize()) {
      fprintf(stderr, "can't run as daemon\n");
      exit(EXIT_FAILURE);
    }
    printf("run as daemon\n");
  }

  sockfd = socket(AF_INET, SOCK_DGRAM, 0);
  if (sockfd == -1) {
    perror("socket error: ");
    exit(EXIT_FAILURE);
  }

  bzero(&servaddr, sizeof(servaddr));
  servaddr.sin_family = AF_INET;
  if (settings.ipaddr != NULL) {
    if (inet_aton(settings.ipaddr, &(servaddr.sin_addr)) == 0) {
      fprintf(stderr, "invalid ip address to listen: %s\n", settings.ipaddr);
      exit(EXIT_FAILURE);
    }
  } else {
    servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
  }
  servaddr.sin_port = htons(settings.port);

  if (bind(sockfd, (struct sockaddr *) &servaddr, sizeof(servaddr))) {
    perror("bind error: ");
    exit(EXIT_FAILURE);
  }

  pthread_mutex_init(&lock, NULL);
  pthread_cond_init(&cond, NULL);
  pthread_mutex_init(&workerlock, NULL);
  pthread_cond_init(&workercond, NULL);
  pthread_mutex_init(&reaperlock, NULL);
  pthread_cond_init(&reapercond, NULL);
  
  /* start thread to reap children */
  do {
    pthread_t t;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    if (pthread_create(&t, &attr, reaper_worker, NULL) != 0) {
      perror("pthread_create error: ");
      exit(EXIT_FAILURE);
    }
  } while (0);

  /* start thread to scan queue */
  do {
    pthread_t t;
    pthread_attr_t attr;
    pthread_attr_init(&attr);
    if (pthread_create(&t, &attr, scan_worker, NULL) != 0) {
      perror("pthread_create error: ");
      exit(EXIT_FAILURE);
    }
  } while (0);

  /* close stdio if verbose == 0*/
  if (close_stdio(settings.verbose)) {
    fprintf(stderr, "can't close fd: 0, 1, 2\n");
    exit(EXIT_FAILURE);
  }

  len = sizeof(cliaddr);
  while (1) {
    n = recvfrom(sockfd, msg, MAX_MSG_LENGTH, 0, (struct sockaddr *)&cliaddr, &len);
    if (n < 1) {
      if (settings.verbose > 0) {
        fprintf(stderr, "recvfrom error\n");
      }
      continue;
    }
    if (settings.localonly) {
      char *from = inet_ntoa(cliaddr.sin_addr);
      if (is_local_ip(from)) {
        if (settings.verbose > 0) {
          fprintf(stderr, "deny msg from %s\n", from);
        }
        continue;        
      }
    }
    msg[n] = '\0';
    if (settings.verbose > 0) {
      handle_msg(msg, n, inet_ntoa(cliaddr.sin_addr));
    } else {
      handle_msg(msg, n, NULL);
    }
    /*
    sendto(sockfd, msg, n, 0, (struct sockaddr *)&cliaddr, len);
    */
  }

  return 0;
}
static void ALP_Dis(void)
{
	if( ON_OFF() )
	{
		#ifdef	L_DEBUG
				Debug_PutString("*!*!*!*!*!..");				
		#endif	
		
		if( (SR2 && !SR3) || (SY2 && !SY3) || (SB2 && !SB3) )
		{
			#ifdef	L_DEBUG
				Debug_PutString("\n\rON..");
			#endif	
			if(SR2 && !SR3)
				Ph_R_ON();
			if(SY2 && !SY3)
				Ph_Y_ON();
			if(SB2 && !SB3)
				Ph_B_ON();
			Reset_Z();
		}					//	Close if()	
	}						//	Close if(ON_OFF)						
	else
	{
		#ifdef	L_DEBUG
				Debug_PutString("*$$*$$*$$..");				
		#endif	
	
		if(SR3 || SR4 || SY3 || SY4 || SB3 || SB4 )
		{
			#ifdef	L_DEBUG
				Debug_PutString("\n\rOFF..");
			#endif
			if(SR3 || SR4)
				Ph_R_OFF();
			if(SY3 || SY4)
				Ph_Y_OFF();
			if(SB3 || SB4)
				Ph_B_OFF();	
			Reset_Z();	 
		}					//	Close if()	
	}						//	Close else(ON_OFF)	
	#ifdef	L_DEBUG
		Debug_PutString("\n\n\r\t\t********************************");	
		Debug_PutString("\n\n\r HH:MM:SS ");
		Debug_PutInt(Hour);
		Debug_PutChar(':'); 
		Debug_PutInt(Min);
		Debug_PutChar(':'); 
		Debug_PutInt(Sec);
		Debug_PutString("\t Sys_Time ");
		Debug_PutInt(Sys_Time.StructTime.Hrs); 
		Debug_PutChar(':'); 
		Debug_PutInt(Sys_Time.StructTime.Mins); 
		Debug_PutChar(':'); 
		Debug_PutInt(Sys_Time.StructTime.Secs); 									
		Debug_PutString("\t   ON Time ");
		Debug_PutInt(ONTime.StructTime.Hrs); 
		Debug_PutChar(':'); 
		Debug_PutInt(ONTime.StructTime.Mins); 
		Debug_PutChar(':'); 
		Debug_PutInt(ONTime.StructTime.Secs); 
		Debug_PutString("\t OFF Time ");
		Debug_PutInt(OFFTime.StructTime.Hrs); 
		Debug_PutChar(':'); 
		Debug_PutInt(OFFTime.StructTime.Mins); 
		Debug_PutChar(':'); 
		Debug_PutInt(OFFTime.StructTime.Secs); 	
		Debug_PutString("\n\r\t\t********************************\n");
	#endif	
			
}