Пример #1
0
void hchangelbl(int i)
{
 sprintf (lbl_string, "HScroll Value: %d ", i);
 the_dialog[2].d2 = i;
 SEND_MESSAGE((the_dialog + 2), MSG_DRAW, 0);
 SEND_MESSAGE((the_dialog + 1), MSG_DRAW, 0);
}
Пример #2
0
/* fs_elist_proc:
  *  Dialog procedure for the file selector disk list.
  */
static int fs_elist_proc(int msg, DIALOG *d, int c)
{
    int ret;
    int sel = d->d1;
    char *s, *tok;
    char tmp[80], ext[80];
    static char ext_tokens[] = " ,;";
    
    s = (char *) file_selector[FS_EDIT].dp;
    
    if(msg == MSG_START)
    {
        d->d2 = 0;
    }
    
    ret = jwin_droplist_proc(msg, d, c);
    
    if((sel != d->d1) || (ret & D_CLOSE))
    {
        // change the extension(s)
        fext = fext_list[d->d1].ext;
//    if (fext)// && ugetc(fext))
        {
            parse_extension_string(fext);
        }
        
        // check whether the extension on the current file name is still valid
        if((fext) && (strlen(get_filename(s))))
        {
            strcpy(tmp, fext);
            strcpy(ext, get_extension(s));
            tok = strtok(tmp, ext_tokens);
            
            while(tok)
            {
                if(stricmp(ext, tok) == 0)
                    break;
                    
                tok = strtok(NULL, ext_tokens);
            }
            
            // not valid, replace file name
            if(!tok)
                replace_filename(s, flist->dir, "", 256);
        }
        
        scare_mouse();
        SEND_MESSAGE(file_selector+FS_FILES, MSG_START, 0);
        SEND_MESSAGE(file_selector+FS_FILES, MSG_DRAW, 0);
        SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0);
        SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0);
        unscare_mouse();
        
        if(ret & D_CLOSE)
            return (ret | SEND_MESSAGE(file_selector+FS_EDIT, MSG_KEY, 0)) & ~D_CLOSE;
    }
    
    return ret;
}
Пример #3
0
void vchangelbl(int i)
{
 sprintf (lbl_string, "VScroll Value: %d ", i);
 the_dialog[3].d2 = i;
 the_dialog[4].d2 = i;
 SEND_MESSAGE((the_dialog + 4), MSG_DRAW, 0);
 SEND_MESSAGE((the_dialog + 3), MSG_DRAW, 0);
 SEND_MESSAGE((the_dialog + 1), MSG_DRAW, 0);
}
Пример #4
0
static int d_agup_slider_pro2(int msg, DIALOG * d, int c)
{
    char s[100];
    int v;
    v = d_agup_slider_proc(msg, d, c);
    switch (msg) {
        case MSG_DRAW:
            sprintf(s, "%3d", d->d2);
            text_mode(agup_bg_color);
            gui_textout(screen, s, d->x + d->w, d->y + 4, d->fg, 0);
            break;
        case MSG_CLICK:
        case MSG_CHAR:
            if (d == &sol_dialog[D_STRENGTH])
            {
                if (d->d2 > 40) d->d2 = 40;
                if (d->d2 < 25) d->d2 = 25;
            }
            else
            {
                if (d->d2 > 80) d->d2 = 80;
                if (d->d2 < 50) d->d2 = 50;
            }

            points = sol_dialog[D_TIME].d2 +
                     sol_dialog[D_HEALTH].d2 +
                     sol_dialog[D_FIRE_ACCUR].d2 +
                     sol_dialog[D_THRU_ACCUR].d2 +
                     sol_dialog[D_STAMINA].d2 +
                     (sol_dialog[D_STRENGTH].d2 * 2) +
                     sol_dialog[D_REACTION].d2;

            if (points > MAXPOINTS && d == &sol_dialog[D_STRENGTH]) {
                points -= d->d2 * 2;
                d->d2 = (MAXPOINTS - points) / 2;
                points += d->d2 * 2;
            } else if (points > MAXPOINTS) {
                points -= d->d2;
                d->d2 = MAXPOINTS - points;
                points += d->d2;
            }

            scare_mouse();

            SEND_MESSAGE(d, MSG_DRAW, 0);
            sprintf(points_str, _("Points remain: %2d "), MAXPOINTS - points);
            SEND_MESSAGE(&sol_dialog[D_POINTS], MSG_DRAW, 0);

            unscare_mouse();
            break;
        default:
            break;
    }
    return v;
}
Пример #5
0
int d_number_proc(int msg, DIALOG *d, int c)
{
   TELLER *t = (TELLER *)d->dp;

   switch (msg)
   {
      case MSG_START:
           d->dp = t = new TELLER(d->d1);
           t->set(d->d2);
           break;
      case MSG_END:
           delete t;
           d->dp = NULL;
           break;
      case MSG_IDLE:
           t->turn(d->d2);
           t->proc();
           SEND_MESSAGE(d, MSG_DRAW,  c);
           break;
           // fall through
      case MSG_DRAW:
           t->draw(screen, d->x, d->y);
           break;
   }

   return D_O_K;
}
Пример #6
0
void send_exec_msg(int frame,int slot,int port){
	obj_ref_t          peer;
	int sock;
	msg_t2 msg;
	msg=Execute_Msg(frame,slot);

	CreatSocket(&peer,sock, "127.0.0.1",port);
	SEND_MESSAGE(&peer,"127.0.0.1", msg);
	close(peer.obj_ref.sock_inet_ref.sock_fd);

}
static void SNP_sendAsyncCmd(_npiFrame_t *pPkt)
{
  // Enter Critical Section.
  ENTER_CS();

  // Send command.
  SEND_MESSAGE(pPkt);

  // Exit Critical section
  EXIT_CS();
}
Пример #8
0
// -------------------------------------------------------------------------------------------------
// Keystroke
// -------------------------------------------------------------------------------------------------
// Messaging function
// -------------------------------------------------------------------------------------------------
void Keystroke(void *pComponent, int testMessageIndex)
{
	COMPONENT_TYPE *pComp = pComponent;

//	MESSAGE_DEF(StartInd);
//	MESSAGE_DEF(PauseInd);
//	MESSAGE_DEF(RestartInd);
//	MESSAGE_DEF(QuitInd);


	switch (testMessageIndex )
	{
	case 1:
		PREPARE_MESSAGE(Control,StartInd);
		SEND_MESSAGE(Control,StartInd);
		break;

	case 2:
		PREPARE_MESSAGE(Control,PauseInd);
		SEND_MESSAGE(Control,PauseInd);
		break;

	case 3:
		PREPARE_MESSAGE(Control,RestartInd);
		SEND_MESSAGE(Control,RestartInd);
		break;

	case 4:
		PREPARE_MESSAGE(Control,QuitInd);
		SEND_MESSAGE(Control,QuitInd);
		break;

	case 5:
		PREPARE_MESSAGE(Command,SpeedInd);
		pComp->Command.SpeedInd->acceleration = 99;
		SEND_MESSAGE(Control,QuitInd);
		break;

	}

}
Пример #9
0
static char *break_getter(int index, int *list_size)
{
  int n;
  int cpu = current_cpu & 0xf;
  if (index == -1){ // Nb of indexes
    for (n=0; Z80_memory_rb[cpu][n].memoryCall == break_read; n++);
    *list_size = n;
  } else if (index == -4) { // clic !
    selected_breakpoint = n = *list_size;
    fprintf(stderr,"selected %d\n",n);
    sprintf(fromadr,"%x",Z80_memory_rb[cpu][n].lowAddr);
    sprintf(toadr,"%x",Z80_memory_rb[cpu][n].highAddr);
    SEND_MESSAGE(&break_gui[FROM_FIELD], MSG_DRAW, 0);
    SEND_MESSAGE(&break_gui[TO_FIELD], MSG_DRAW, 0);
  } else if (index >= 0 && index < MAX_BREAK) {
    sprintf(breaklist[index],"%04x %04x",Z80_memory_rb[cpu][index].lowAddr,
	    Z80_memory_rb[cpu][index].highAddr);
    return breaklist[index];
  }
  return NULL;
}
Пример #10
0
/* fs_dlist_proc:
 *  Dialog procedure for the file selector disk list.
 */
static int fs_dlist_proc(int msg, DIALOG *d, int c)
{
   char *s = file_selector[FS_EDIT].dp;
   int ret, i, temp;

   if (msg == MSG_START) {
      d->d1 = d->d2 = 0;
      temp = utoupper(ugetc(s));
      if (((temp >= 'A') && (temp <= 'Z')) && (ugetat(s, 1) == DEVICE_SEPARATOR)) {
	 temp -= 'A';
	 for (i=0; i<temp; i++)
	    if (drive_exists(i))
	       d->d1++;
      }
   }

   ret = d_text_list_proc(msg, d, c);

   if (ret == D_CLOSE) {
      temp = 'A' + get_x_drive(d->d1+1);
      if ((temp < 'A') || (temp > 'Z'))
	 temp = 'C';

      s += usetc(s, temp);
      s += usetc(s, DEVICE_SEPARATOR);
      s += usetc(s, OTHER_PATH_SEPARATOR);
      usetc(s, 0);

      scare_mouse();
      SEND_MESSAGE(file_selector+FS_FILES, MSG_START, 0);
      SEND_MESSAGE(file_selector+FS_FILES, MSG_DRAW, 0);
      SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0);
      SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0);
      unscare_mouse();

      return D_O_K;
   }

   return ret;
}
Пример #11
0
void send_exec_complete(int port){
	obj_ref_t          peer;
	//Soc_t* this  = (Soc_t*)(obj_inst[0].ptr->mem_ref.pointer);
	int sock;

	msg_t2 msg;
	msg=Execute_Msg_Response();

	CreatSocket(&peer,sock, "127.0.0.1",port);
	SEND_MESSAGE(&peer,"127.0.0.1", msg);
	close(peer.obj_ref.sock_inet_ref.sock_fd);

}
Пример #12
0
int my_list_proc( int msg, DIALOG* d, int c )
{
    STACKTRACE;
    int old_d1 = d->d1;
    Fleet *fleet = (Fleet*)d->dp3;
    int ret = d_list_proc2( msg, d, c );
    if ( d->d1 != old_d1 || msg == MSG_START ) {
        ShipType* type = fleet->getShipType(d->d1);

        ASSERT(type != NULL);

        selectDialog[SELECT_DIALOG_TITLE].flags |= D_DIRTY;
        sprintf(selectTitleString, "%s\n%s\n%d of %d points",
                selectShipPrompt,
                (type != NULL) ? type->name : 0,
                (type != NULL) ? type->cost : 0,
                fleet->getCost());

        BITMAP* panel = NULL;
        TW_DATAFILE* data = tw_load_datafile_object( type->data->file, "SHIP_P00_PCX" );

        if ( data ) {
            BITMAP* bmp = (BITMAP*)data->dat;
            panel = create_bitmap_ex( bitmap_color_depth(screen), bmp->w, bmp->h );
            blit( bmp, panel, 0, 0, 0, 0, bmp->w, bmp->h );
            tw_unload_datafile_object( data );
            data = tw_load_datafile_object( type->data->file, "SHIP_P01_PCX" );
            bmp = (BITMAP*)data->dat;
            blit( bmp, panel, 0, 0, 4, 65, bmp->w, bmp->h );
            tw_unload_datafile_object( data );
            color_correct_bitmap( panel, 0 );
        }

        if ( selectDialog[SELECT_DIALOG_PIC].dp ) destroy_bitmap( (BITMAP*)selectDialog[SELECT_DIALOG_PIC].dp );
        selectDialog[SELECT_DIALOG_PIC].dp = panel;
        scare_mouse();
        SEND_MESSAGE( &selectDialog[SELECT_DIALOG_PIC], MSG_DRAW, 0 );
        unscare_mouse();
    }
    return ret;
}
static void SNP_sendSynchronousCmd(_npiFrame_t *pReq, uint8_t opcode,
                                   snp_msg_t *pRsp, uint16_t *rspLen)
{
  // Enter Critical Section.
  ENTER_CS();

  npiRetMsg.pMsg = pRsp;

  // Send command.
  SEND_MESSAGE(pReq);

  // Wait for a response from the NP.
  SNP_waitForResponse();

  // Update Length after response is received
  if (rspLen)
  {
    *rspLen = npiRetMsg.len;
  }

  // Exit Critical Section
  EXIT_CS();
}
Пример #14
0
/* gui object procedure for the color selection sliders */
int my_slider_proc(int msg, DIALOG *d, int c)
{
   int *color = (int *)d->dp3;

   switch (msg) {

      case MSG_START:
	 /* initialise the slider position */
	 d->d2 = *color;
	 break;

      case MSG_IDLE:
	 /* has the slider position changed? */
	 if (d->d2 != *color) {
	    d->d2 = *color;
	    show_mouse(NULL);
	    SEND_MESSAGE(d, MSG_DRAW, 0);
	    show_mouse(screen);
	 }
	 break;
   }

   return d_slider_proc(msg, d, c);
}
Пример #15
0
/* This state machine is based on the one from udhcpc
   written by Russ Dill */
int dhcp_run (options_t *options)
{
  interface_t *iface;
  int mode = SOCKET_CLOSED;
  int state = STATE_INIT;
  struct timeval tv;
  int xid = 0;
  long timeout = 0;
  fd_set rset;
  int maxfd;
  int retval;
  dhcpmessage_t message;
  dhcp_t *dhcp;
  int type = DHCP_DISCOVER;
  int last_type = DHCP_DISCOVER;
  bool daemonised = false;
  unsigned long start = 0;
  unsigned long last_send = 0;
  int sig;
  unsigned char *buffer = NULL;
  int buffer_len = 0;
  int buffer_pos = 0;

  if (! options || (iface = (read_interface (options->interface,
					     options->metric))) == NULL)
    return -1;

  /* Remove all existing addresses.
     After all, we ARE a DHCP client whose job it is to configure the
     interface. We only do this on start, so persistent addresses can be added
     afterwards by the user if needed. */
  flush_addresses (iface->name);

  dhcp = xmalloc (sizeof (dhcp_t));
  memset (dhcp, 0, sizeof (dhcp_t));

  strcpy (dhcp->classid, options->classid);
  if (options->clientid[0])
    strcpy (dhcp->clientid, options->clientid);
  else
    sprintf (dhcp->clientid, "%s", ether_ntoa (&iface->ethernet_address));

  if (options->requestaddress.s_addr != 0)
    dhcp->address.s_addr = options->requestaddress.s_addr;

  signal_setup ();

  while (1)
    {
      if (timeout > 0 || (options->timeout == 0 &&
			  (state != STATE_INIT || xid)))
	{
	  if (options->timeout == 0 || dhcp->leasetime == -1)
	    {
	      logger (LOG_DEBUG, "waiting on select for infinity");
	      maxfd = signal_fd_set (&rset, iface->fd);
	      retval = select (maxfd + 1, &rset, NULL, NULL, NULL);
	    }
	  else
	    {
	      /* Resend our message if we're getting loads of packets
		 that aren't for us. This mainly happens on Linux as it
		 doesn't have a nice BPF filter. */
	      if (iface->fd > -1 && uptime () - last_send >= TIMEOUT_MINI)
		SEND_MESSAGE (last_type);

	      logger (LOG_DEBUG, "waiting on select for %d seconds",
		      timeout);
	      /* If we're waiting for a reply, then we re-send the last
		 DHCP request periodically in-case of a bad line */
	      retval = 0;
	      while (timeout > 0 && retval == 0)
		{
		  if (iface->fd == -1)
		    tv.tv_sec = SELECT_MAX;
		  else
		    tv.tv_sec = TIMEOUT_MINI;
		  if (timeout < tv.tv_sec)
		    tv.tv_sec = timeout;
		  tv.tv_usec = 0;
		  start = uptime ();
		  maxfd = signal_fd_set (&rset, iface->fd);
		  retval = select (maxfd + 1, &rset, NULL, NULL, &tv);
		  timeout -= uptime () - start;
		  if (retval == 0 && iface->fd != -1 && timeout > 0)
		    SEND_MESSAGE (last_type);
		}
	    }
	}
      else
	retval = 0;

      /* We should always handle our signals first */
      if (retval > 0 && (sig = signal_read (&rset)))
	{
	  switch (sig)
	    {
	    case SIGINT:
	      logger (LOG_INFO, "receieved SIGINT, stopping");
	      retval = 0;
	      goto eexit;

	    case SIGTERM:
	      logger (LOG_INFO, "receieved SIGTERM, stopping");
	      retval = 0;
	      goto eexit;

	    case SIGALRM:

	      logger (LOG_INFO, "receieved SIGALRM, renewing lease");
	      switch (state)
		{
		case STATE_BOUND:
		case STATE_RENEWING:
		case STATE_REBINDING:
		  state = STATE_RENEW_REQUESTED;
		  break;
		case STATE_RENEW_REQUESTED:
		case STATE_REQUESTING:
		case STATE_RELEASED:
		  state = STATE_INIT;
		  break;
		}

	      timeout = 0;
	      xid = 0;
	      break;

	    case SIGHUP:
	      if (state == STATE_BOUND || state == STATE_RENEWING
		  || state == STATE_REBINDING)
		{
		  logger (LOG_INFO, "received SIGHUP, releasing lease");
		  SOCKET_MODE (SOCKET_OPEN);
		  xid = random_xid ();
		  if ((open_socket (iface, false)) >= 0)
		    SEND_MESSAGE (DHCP_RELEASE);
		  SOCKET_MODE (SOCKET_CLOSED);
		  unlink (iface->infofile);
		}
	      else
		logger (LOG_ERR,
			"receieved SIGUP, but no we have lease to release");
	      retval = 0;
	      goto eexit;

	    default:
	      logger (LOG_ERR,
		      "received signal %d, but don't know what to do with it",
		      sig);
	    }
	}
      else if (retval == 0) /* timed out */
	{
	  switch (state)
	    {
	    case STATE_INIT:
	      if (iface->previous_address.s_addr != 0)
		{
		  logger (LOG_ERR, "lost lease");
		  xid = 0;
		  SOCKET_MODE (SOCKET_CLOSED);
		  if (! options->persistent)
		    {
		      free_dhcp (dhcp);
		      memset (dhcp, 0, sizeof (dhcp_t));
		      configure (options, iface, dhcp);
		    }
		  if (! daemonised)
		    {
		      retval = -1;
		      goto eexit;
		    }
		  break;
		}

	      if (xid == 0)
		xid = random_xid ();
	      else
		{
		  logger (LOG_ERR, "timed out");
		  if (! daemonised)
		    {
		      retval = -1;
		      goto eexit;
		    }
		}

	      SOCKET_MODE (SOCKET_OPEN);
	      timeout = options->timeout;
	      iface->start_uptime = uptime ();
	      if (dhcp->address.s_addr == 0)
		{
		  logger (LOG_INFO, "broadcasting for a lease");
		  SEND_MESSAGE (DHCP_DISCOVER);
		}
	      else
		{
		  logger (LOG_INFO, "broadcasting for a lease of %s",
			  inet_ntoa (dhcp->address));
		  SEND_MESSAGE (DHCP_REQUEST);
		  state = STATE_REQUESTING;
		}

	      break;
	    case STATE_BOUND:
	    case STATE_RENEW_REQUESTED:
	      state = STATE_RENEWING;
	      xid = random_xid ();
	    case STATE_RENEWING:
	      iface->start_uptime = uptime ();
	      logger (LOG_INFO, "renewing lease of %s", inet_ntoa
		      (dhcp->address));
	      SOCKET_MODE (SOCKET_OPEN);
	      SEND_MESSAGE (DHCP_REQUEST);
	      timeout = dhcp->rebindtime - dhcp->renewaltime;
	      state = STATE_REBINDING;
	      break;
	    case STATE_REBINDING:
	      logger (LOG_ERR, "lost lease, attemping to rebind");
	      SOCKET_MODE (SOCKET_OPEN);
	      SEND_MESSAGE (DHCP_DISCOVER);
	      timeout = dhcp->leasetime - dhcp->rebindtime;
	      state = STATE_INIT;
	      break;
	    case STATE_REQUESTING:
	      logger (LOG_ERR, "timed out");
	      if (! daemonised)
		goto eexit;

	      state = STATE_INIT;
	      SOCKET_MODE (SOCKET_CLOSED);
	      timeout = 0;
	      xid = 0;
	      free_dhcp (dhcp);
	      memset (dhcp, 0, sizeof (dhcp_t));
	      break;

	    case STATE_RELEASED:
	      dhcp->leasetime = -1;
	      break;
	    }
	}
      else if (retval > 0 && mode != SOCKET_CLOSED && FD_ISSET(iface->fd, &rset))
	{

	  /* Allocate our buffer space for BPF.
	     We cannot do this until we have opened our socket as we don't
	     know how much of a buffer we need until then. */
	  if (! buffer)
	    buffer = xmalloc (iface->buffer_length);
	  buffer_len = iface->buffer_length;
	  buffer_pos = -1;

	  /* We loop through until our buffer is empty.
	     The benefit is that if we get >1 DHCP packet in our buffer and
	     the first one fails for any reason, we can use the next. */

	  memset (&message, 0, sizeof (struct dhcpmessage_t));
	  int valid = 0;
	  struct dhcp_t *new_dhcp;
	  new_dhcp = xmalloc (sizeof (dhcp_t));

	  while (buffer_pos != 0)
	    {
	      if (get_packet (iface, (unsigned char *) &message, buffer,
			      &buffer_len, &buffer_pos) < 0)
		break;

	      if (xid != message.xid)
		{
		  logger (LOG_ERR,
			  "ignoring packet with xid %d as it's not ours (%d)",
			  message.xid, xid);
		  continue;
		}

	      logger (LOG_DEBUG, "got a packet with xid %d", message.xid);
	      memset (new_dhcp, 0, sizeof (dhcp_t));
	      if ((type = parse_dhcpmessage (new_dhcp, &message)) < 0)
		{
		  logger (LOG_ERR, "failed to parse packet");
		  free_dhcp (new_dhcp);
		  continue;
		}

	      /* If we got here then the DHCP packet is valid and appears to
		 be for us, so let's clear the buffer as we don't care about
		 any more DHCP packets at this point. */
	      valid = 1;
	      break;
	    }

	  /* No packets for us, so wait until we get one */
	  if (! valid)
	    {
	      free (new_dhcp);
	      continue;
	    }

	  /* new_dhcp is now our master DHCP message */
	  free_dhcp (dhcp);
	  free (dhcp);
	  dhcp = new_dhcp;
	  new_dhcp = NULL;

	  /* We should restart on a NAK */
	  if (type == DHCP_NAK)
	    {
	      logger (LOG_INFO, "received NAK: %s", dhcp->message);
	      state = STATE_INIT;
	      timeout = 0;
	      xid = 0;
	      free_dhcp (dhcp);
	      memset (dhcp, 0, sizeof (dhcp_t));
	      configure (options, iface, dhcp);
	      continue;
	    }

	  switch (state)
	    {
	    case STATE_INIT:
	      if (type == DHCP_OFFER)
		{
		  logger (LOG_INFO, "offered lease of %s",
			  inet_ntoa (dhcp->address));

		  SEND_MESSAGE (DHCP_REQUEST);
		  state = STATE_REQUESTING;
		}
	      break;

	    case STATE_RENEW_REQUESTED:
	    case STATE_REQUESTING:
	    case STATE_RENEWING:
	    case STATE_REBINDING:
	      if (type == DHCP_ACK)
		{
		  SOCKET_MODE (SOCKET_CLOSED);
		  if (options->doarp && iface->previous_address.s_addr !=
		      dhcp->address.s_addr)
		    {
		      if (arp_check (iface, dhcp->address))
			{
			  SOCKET_MODE (SOCKET_OPEN);
			  SEND_MESSAGE (DHCP_DECLINE);
			  SOCKET_MODE (SOCKET_CLOSED);
			  free_dhcp (dhcp);
			  memset (dhcp, 0, sizeof (dhcp));
			  if (daemonised)
			    configure (options, iface, dhcp);

			  xid = 0;
			  state = STATE_INIT;
			  /* RFC 2131 says that we should wait for 10 seconds
			     before doing anything else */
			  sleep (10);
			  continue;
			}
		    }

		  if (! dhcp->leasetime)
		    {
		      dhcp->leasetime = DEFAULT_TIMEOUT;
		      logger(LOG_INFO,
			     "no lease time supplied, assuming %d seconds",
			     dhcp->leasetime);
		    }

		  if (! dhcp->renewaltime) 
		    {
		      dhcp->renewaltime = dhcp->leasetime / 2;
		      logger (LOG_INFO,
			      "no renewal time supplied, assuming %d seconds",
			      dhcp->renewaltime);
		    }

		  if (! dhcp->rebindtime)
		    {
		      dhcp->rebindtime = (dhcp->leasetime * 0x7) >> 3;
		      logger (LOG_INFO,
			      "no rebind time supplied, assuming %d seconds",
			      dhcp->rebindtime);
		    }

		  if (dhcp->leasetime == -1)
		    logger (LOG_INFO, "leased %s for infinity",
			    inet_ntoa (dhcp->address));
		  else
		    logger (LOG_INFO, "leased %s for %u seconds",
			    inet_ntoa (dhcp->address),
			    dhcp->leasetime, dhcp->renewaltime);

		  state = STATE_BOUND;
		  timeout = dhcp->renewaltime;
		  xid = 0;

		  if (configure (options, iface, dhcp) < 0 && ! daemonised)
		    {
		      retval = -1;
		      goto eexit;
		    }

		  if (! daemonised)
		    {
		      if ((daemonise (options->pidfile)) < 0 )
			{
			  retval = -1;
			  goto eexit;
			}
		      daemonised = true;
		    }
		}
	      else if (type == DHCP_OFFER)
		logger (LOG_INFO, "got subsequent offer of %s, ignoring ",
			inet_ntoa (dhcp->address));
	      else
		logger (LOG_ERR,
			"no idea what to do with DHCP type %d at this point",
			type);
	      break;
	    }
Пример #16
0
/* fs_flist_proc:
 *  Dialog procedure for the file selector list.
 */
static int fs_flist_proc(int msg, DIALOG *d, int c)
{
   static int recurse_flag = 0;
   char *s = file_selector[FS_EDIT].dp;
   char tmp[32];
   int sel = d->d1;
   int i, ret;
   int ch, count;

   if (msg == MSG_START) {
      if (!flist) {
	 flist = malloc(sizeof(FLIST));

	 if (!flist) {
	    *allegro_errno = ENOMEM;
	    return D_CLOSE;
	 }
      }
      else {
	 for (i=0; i<flist->size; i++)
	    if (flist->name[i])
	       free(flist->name[i]);
      }

      flist->size = 0;

      replace_filename(flist->dir, s, uconvert_ascii("*.*", tmp), sizeof(flist->dir));

      for_each_file(flist->dir, FA_RDONLY | FA_DIREC | FA_ARCH | FA_HIDDEN | FA_SYSTEM, fs_flist_putter, 0);

      if (*allegro_errno)
	 raine_alert("", "Disk error", NULL, NULL,  "OK", NULL, 13, 0);

      usetc(get_filename(flist->dir), 0);
      d->d1 = d->d2 = 0;
      sel = 0;
   }

   if (msg == MSG_END) {
      if (flist) {
	 for (i=0; i<flist->size; i++)
	    if (flist->name[i])
	       free(flist->name[i]);
	 free(flist);
	 flist = NULL;
      }
   }

   recurse_flag++;
   ret = d_text_list_proc(msg, d, c);     /* call the parent procedure */
   recurse_flag--;

   if (((sel != d->d1) || (ret == D_CLOSE)) && (recurse_flag == 0)) {
      replace_filename(s, flist->dir, flist->name[d->d1], 512);
      /* check if we want to `cd ..' */
      if ((!ustrncmp(flist->name[d->d1], "..", 2)) && (ret == D_CLOSE)) {
	 /* let's remember the previous directory */
	 ustrcpy(updir, empty_string);
	 i = ustrlen(flist->dir);
	 count = 0;
	 while (i>0) {
	    ch = ugetat(flist->dir, i);
	    if ((ch == '/') || (ch == OTHER_PATH_SEPARATOR)) {
	       if (++count == 2)
		  break;
	    }
	    uinsert(updir, 0, ch);
	    i--;
	 }
	 /* ok, we have the dirname in updir */
      }
      else {
	 ustrcpy(updir, empty_string);
      }
      scare_mouse();
      SEND_MESSAGE(file_selector+FS_EDIT, MSG_START, 0);
      SEND_MESSAGE(file_selector+FS_EDIT, MSG_DRAW, 0);
      unscare_mouse();

      if (ret == D_CLOSE)
	 return SEND_MESSAGE(file_selector+FS_EDIT, MSG_KEY, 0);
   }

   return ret;
}
Пример #17
0
/* fs_edit_proc:
 *  Dialog procedure for the file selector editable string.
 */
static int fs_edit_proc(int msg, DIALOG *d, int c)
{
   char *s = d->dp;
   int list_size;
   int found = 0;
   char b[512];
   int ch, attr;
   int i;

   if (msg == MSG_START) {
      fix_filename_path(b, s, sizeof(b));
      ustrcpy(s, b);
   }

   if (msg == MSG_KEY) {
      if ((!ugetc(s)) || (ugetat(s, -1) == DEVICE_SEPARATOR))
	 ustrcat(s, uconvert_ascii("./", NULL));

      fix_filename_path(b, s, sizeof(b));
      ustrcpy(s, b);

      ch = ugetat(s, -1);
      if ((ch != '/') && (ch != OTHER_PATH_SEPARATOR)) {
	 if (file_exists(s, FA_RDONLY | FA_HIDDEN | FA_DIREC, &attr)) {
	    if (attr & FA_DIREC)
	       put_backslash(s);
	    else
	       return D_CLOSE;
	 }
	 else
	    return D_CLOSE;
      }

      scare_mouse();
      SEND_MESSAGE(file_selector+FS_FILES, MSG_START, 0);
      /* did we `cd ..' ? */
      if (ustrlen(updir)) {
	 /* now we have to find a directory name equal to updir */
	 for (i = 0; i<flist->size; i++) {
	    if (!ustrcmp(updir, flist->name[i])) {  /* we got it ! */
	       file_selector[FS_FILES].d1 = i;
	       /* we have to know the number of visible lines in the filelist */
	       /* -1 to avoid an off-by-one problem */
               list_size = (file_selector[FS_FILES].h-4) / text_height(font) - 1;
               if (i>list_size)
		  file_selector[FS_FILES].d2 = i-list_size;
	       else
		  file_selector[FS_FILES].d2 = 0;
               found = 1;
	       break;  /* ok, our work is done... */
	    }
	 }
	 /* by some strange reason, we didn't find the old directory... */
         if (!found) {
            file_selector[FS_FILES].d1 = 0;
            file_selector[FS_FILES].d2 = 0;
         }
      }
      /* and continue... */
      SEND_MESSAGE(file_selector+FS_FILES, MSG_DRAW, 0);
      SEND_MESSAGE(d, MSG_START, 0);
      SEND_MESSAGE(d, MSG_DRAW, 0);
      unscare_mouse();

      return D_O_K;
   }

   if (msg == MSG_UCHAR) {
      if ((c >= 'a') && (c <= 'z')) {
	 if (!ALLEGRO_LFN)
	    c = utoupper(c);
      }
      else if (c == '/') {
	 c = OTHER_PATH_SEPARATOR;
      }
      else if (ALLEGRO_LFN) {
	 if ((c > 127) || (c < 32))
	    return D_O_K;
      }
      else {
	 if ((c != OTHER_PATH_SEPARATOR) && (c != '_') &&
	     (c != DEVICE_SEPARATOR) && (c != '.') &&
	     ((c < 'A') || (c > 'Z')) && ((c < '0') || (c > '9')))
	    return D_O_K;
      }
   }

   return x_edit_proc(msg, d, c);
}
Пример #18
0
int javacall_launch_native_editor(int Constraints, unsigned short* in, int inlen, unsigned short* title, int titlelen, unsigned short* out, int maxoutlen)
{
    /*----------------------------------------------------------------*/
    /* Local Variables                                                */
    /*----------------------------------------------------------------*/
      /************************************************
      IMPORTANT NOTICE:
         Before using this function, remember to pause Java VM.
      *************************************************/
    kal_int32 ime_type = 0;
    int retlen;
    mmiapi_ui_enter_fullscreen_editor_req_struct *msg = NEW_LOCAL_PTR(mmiapi_ui_enter_fullscreen_editor_req_struct);
    
	NativeEditorSemaphore = sxr_NewSemaphore(0);
    SetProtocolEventHandler(
        (PsFuncPtr) mmiapi_ui_enter_fullscreen_editor_req,
        (U16) MSG_ID_MMIAPI_UI_ENTER_FULLSCREEN_EDITOR_REQ);
    
	memset(out, 0, (maxoutlen+1)*2);
    memcpy(out, in, sizeof(unsigned short) * inlen);

    /*----------------------------------------------------------------*/
    /* Code Body                                                      */
    /*----------------------------------------------------------------*/
    switch (Constraints)
    {
        case EMAILADDR:
            ime_type = INPUT_TYPE_ALPHANUMERIC_LOWERCASE | INPUT_TYPE_USE_ONLY_ENGLISH_MODES;
            break;
            
        case NUMERIC:
            ime_type = INPUT_TYPE_DECIMAL_NUMERIC;
            break;

        case PHONENUMBER:
            ime_type = INPUT_TYPE_PHONE_NUMBER;
            break;

        case URL:
            ime_type = INPUT_TYPE_ALPHANUMERIC_LOWERCASE | INPUT_TYPE_USE_ONLY_ENGLISH_MODES;
            break;

        case PASSWORD:
            ime_type = INPUT_TYPE_ALPHANUMERIC_PASSWORD;
            break;

        case DECIMAL:
            ime_type = INPUT_TYPE_DECIMAL_NUMERIC;
            break;

    }
    ime_type |= INPUT_TYPE_OVERRIDE_DEFAULT;

    msg->blocking_data = NULL;
    msg->editor_buffer = (kal_uint8*) out;
    msg->is_must_input = KAL_FALSE;
    msg->maxlen = maxoutlen + 1;
    msg->type = ime_type;
    
    retlen = kal_wstrlen(( WCHAR * )out);

    mmi_trace(1,"javacall_launch_native_editor befor retlen=%d maxoutlen=%d",retlen,maxoutlen);  
 
    g_jam_vm_state = JVM_BG_BLOCKING_STATE;
    
    SEND_MESSAGE(MOD_J2ME, MOD_MMI, MMI_J2ME_SAP, MSG_ID_MMIAPI_UI_ENTER_FULLSCREEN_EDITOR_REQ, msg, NULL);
    
	sxr_TakeSemaphore(NativeEditorSemaphore);
    sxr_FreeSemaphore(NativeEditorSemaphore);
    
    retlen = kal_wstrlen(( WCHAR * )out);

    mmi_trace(1,"javacall_launch_native_editor after retlen=%d",retlen);

    return retlen;

}
Пример #19
0
/** @brief Main loop.
 */
int main(void)
{
#ifdef INIT_CODE
  do{ INIT_CODE }while(0);
#endif

  /* interruptions not used, moving interrupt vector not needed
  IVCR = (1<<IVCE);
  IVCR = (1<<IVSEL);
   */

#ifdef ENABLE_UART
  // UART init (all values have been already computed)
  UBRRxH = UART_UBRR_VAL>>8;
  UBRRxL = UART_UBRR_VAL;
  UCSRxA = UART_U2X_VAL;
  UCSRxB = (1<<RXENx) | (1<<TXENx);
  UCSRxC = UART_NBITS_VAL | UART_PARITY_VAL | UART_STOP_BIT_VAL;
#endif
#ifdef ENABLE_I2C_SLAVE
  // I2C init
  TWAR = I2C_ADDR << 1;
  TWCR = (1<<TWIE)|(1<<TWEN)|(1<<TWINT)|(1<<TWEA);
#endif

#ifdef ENABLE_UART
  SEND_MESSAGE("boot ENTER");
#endif
  // timeout before booting
  uint8_t i = (BOOT_TIMEOUT)*F_CPU/(65536*4*1000);
  for(;;) {
    // detect activity from client
    // set the proto_* method if needed

    // from UART
#ifdef ENABLE_UART
    if( (UCSRxA & (1<<RXCx)) ) {
      // UART is the default for proto_*
      break;
    }
#endif

    // from I2C
#ifdef ENABLE_I2C_SLAVE
    if( (TWCR & (1<<TWINT)) ) {
#ifdef ENABLE_UART
      proto_send = i2cs_send;
      proto_recv = i2cs_recv;
#endif
      break;
    }
#endif

    if( i == 0 ) {
      boot(); // timeout
    }
    i--;
    _delay_loop_2(0); // 65536*4 cycles
  }

  for(;;) {
    const uint8_t c = recv_u8();
    if( c == 0x00 ) {
      continue; // null command: ignore
    } else if( c == 0xff ) {
      // failure command
      reply_failure();
    }
    else if( c == 'i' ) cmd_infos();
    else if( c == 'm' ) cmd_mirror();
#ifndef DISABLE_EXECUTE
    else if( c == 'x' ) cmd_execute();
#endif
#ifndef DISABLE_PROG_PAGE
    else if( c == 'p' ) cmd_prog_page();
#endif
#ifndef DISABLE_MEM_CRC
    else if( c == 'c' ) cmd_mem_crc();
#endif
#ifndef DISABLE_FUSE_READ
    else if( c == 'f' ) cmd_fuse_read();
#endif
#ifndef DISABLE_COPY_PAGES
    else if( c == 'y' ) cmd_copy_pages();
#endif
#ifdef ENABLE_I2C_MASTER
    else if( c == '<' ) cmd_i2c_recv();
    else if( c == '>' ) cmd_i2c_send();
#endif
    else {
      reply_error(STATUS_UNKNOWN_COMMAND);
    }
  }

  return 1;
}