Example #1
0
void convert_text_to_ascii(char *text)
{
	int i, j, len = strlen(text);
	for(i = 0, j = 0; i < len; i++, j++)
	{
		if (isascii(text[i]))
		{
			text[j] = text[i];
			continue;
		}

		char new_symbol = get_ascii(&text[i]);
			
		for(; i < len - 1; i++)
		{
			if (isascii(text[i + 1]))
				break;
			if (get_ascii(&text[i + 1]) != NULLSYM)
				break;
		}

		text[j] = new_symbol;
	}

	text[j] = NULLSYM;
}
Example #2
0
static void kbd_int(int irq, void *dummy, struct pt_regs *regs) {
	unsigned long flags;
	unsigned char scancode = 0;
	int i;

	static int upper = 0;

	cli();
	save_flags(flags);

	scancode = read_code();

	keyboard_stop();

	if (scancode == 0xf0 || scancode == 0xe0) {
		scancode = read_code();

	/* only capslock style at the moment */
	} else if ( scancode == 0x12 || scancode == 0x59) {
		upper = upper ? 0 : 1;
	}

	if(get_ascii(scancode) &&  !is_full()) {
		buf[in] = upper ? get_ASCII(scancode) : get_ascii(scancode);
		in = (in+1) % BUFLEN;
		wake_up(&keypress_wait);
	}

	keyboard_start();
	restore_flags(flags);
}
Example #3
0
//---------------------------------------------------------------------------//
unsigned char get_2ascii(char* p) {
  unsigned char tmp, tmpl;

  tmp = get_ascii(p);
  if (tmp > 9) return 0xFF;
  p++;
  tmpl = get_ascii(p);
  if (tmpl > 9) return 0xFF;
  return tmpl + tmp*10;
}
Example #4
0
//---------------------------------------------------------------------------//
unsigned int get_3ascii(char* p) {
  unsigned int tmp, tmp1;

  tmp = get_2ascii(p);
  if (tmp == 0xFF) return 0xFFFF;
  p += 2;
  tmp1 = get_ascii(p);
  if (tmp1 > 9) return 0xFFFF;
  return tmp1 + tmp*10;
}
Example #5
0
static long get_num(const char **s)
{
  if ( (**s) == '$' )
  {
    (*s)++;
    return get_hex(s);
  }
  if ( (**s) == '\'' )
  {
    (*s)++;
    return get_ascii(s);
  }
  
  return get_dec(s);
}
Example #6
0
//---------------------------------------------------------------------------//
// Read unsigned int 0 .. 65535 from text buffer until non-digit character was
//   found
unsigned int read_uint(char const *p) {
   unsigned int tmp, ch;
   char         i;

   tmp = 0;
   for (i=0; i<5; i++ ) {
      ch = get_ascii((char*)p); p++;
      if (ch < 10) {
         tmp = tmp*10 + ch;
      } else {
         return tmp;
      }
   }
   return tmp;
}
Example #7
0
void process_keypress(uint32_t key, int state)
{
	pthread_mutex_lock(&control_mutex);		// called from x thread
	
	if(key >= 256)
		goto end;
	
	void (*func)(int);

	func = controls[key].uifunc;
	if(func)
		func(state);
	
	if(!r_DrawConsole && !server_discovery_started)
	{
		func = controls[key].func;
		if(func)
			func(state);
	//	else
	//		console_print("%u\n", key);
	}
	
	if(key == 42 || key == 54)
	{
		if(state)
			shift = 0x20;
		else
			shift = 0x0;
	}

	if(!state)
		goto end;
	
	if(state)
	{
		char c = get_ascii(key);

		if(c)
		{
			console_keypress(c);
		}
	}

	end:
	pthread_mutex_unlock(&control_mutex);
}
int kbd_notifier(struct notifier_block* nblock, unsigned long code, void* _param) {
	struct keyboard_notifier_param *param = _param;

	if(code == KBD_KEYCODE && param->down) {
		if(param-> value == KEY_BACKSPACE) {
			if(bptr != buffer) {
				--bptr;
				*bptr = '\0';
			}
		}
		else {
			char ch = get_ascii(param->value);
			if(ch != 'X') {
				*bptr = ch;
				bptr++;
				if(bptr == endptr) bptr = buffer;
			}
		}
	}

	return NOTIFY_OK;
}
Example #9
0
static char get_ASCII(unsigned char code) {
	char ascii = get_ascii(code);
	if (ascii >= '0' && ascii <= '9') {
		switch(ascii) {
			case '0': return '=';
			case '1': return '!';
			case '2': return '"';
			case '3': return 'ยง';
			case '4': return '$';
			case '5': return '%';
			case '6': return '&';
			case '7': return '/';
			case '8': return '(';
			case '9': return ')';
		}
	}
	else if (ascii >= 'a' && ascii <= 'z' || ascii >= 'A' && ascii <= 'Z')
		return ascii -32;

	else
		return ascii;

}
Example #10
0
/* Initialize the device */
int ide_init() {
	int dd_off;
	
	//dbglog(DBG_INFO, "ide_init: initializing\n");

	/* Reset */
	outp(0x3f6, 0x0e);
	thd_sleep(10);
	outp(0x3f6, 0x0a);
	thd_sleep(10);

	if(wait_controller() < 0) {
		return -1;
	}
	
	outp(0x1f6,0xa0);	/* get info on first drive. 0xb0 == 2nd */
	outp(0x1f7,0xec);	/* get drive info data */
	
	if(wait_data() < 0) {
		return -1;
	}
	
	for (dd_off=0; dd_off<256; dd_off++) {
		dd[dd_off] = inpw(0x1f0);
	}

	hd_cyls = dd[1];
	hd_heads = dd[3];
	hd_sects = dd[6];

	ds_printf("DS_IDE: Detected %s, %dMB, CHS (%d/%d/%d)\n",
	get_ascii(dd, 27, 46),
	(hd_cyls * hd_heads * hd_sects * 512L) / (1024L*1024L),
	hd_cyls, hd_heads, hd_sects);

	return 0;
}
Example #11
0
/**
 * @brief Handles a keyboard interrupt.
 * 
 * @details Handles a keyboard interrupt, parsing scan codes received from the
 *          keyboard controller to ascii codes.
 */
PUBLIC void do_keyboard_hit(void)
{
	uint8_t ascii_code;
	
	ascii_code = get_ascii();
   
	/* Ignore. */
	if (ascii_code == 0)
		return;
   
	/* Parse ASCII code. */
	switch(ascii_code)
	{
		/* Fall through. */
		case KINS:
        case KDEL:
        case KHOME:
        case KEND:
		case KPGUP:
        case KPGDN:
        case KLEFT:
        case KRIGHT:
        	/*  TODO: implement. */
            break;

		/* Fall through. */
        case KUP:
        case KDOWN:
        	tty_int(ascii_code);
        	break;

		default:
		    tty_int(ascii_code);
        	break;
	}
}
		/**
		 * @brief parse - substruction context
		 * @param[in]    v : value string header pointer
		 * @param[in] conf : configuration
		 * @param[in] line : reading line
		 * @return ==0 : success
		 */
		inline
		int file_stream::unnamed(char *v,configuration *conf, int *line)
		{
			char value[512];
			int ret = 0;
			int sep = 0;
			char sep_token = 0;

			LogDebugf("Begin - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
			LogIndent();

			{ // ----> get value or nesting
				// get separater
				if((sep = find_separater(v)) >= 0){
					sep_token = v[sep];
					v[sep] = '\0';
				}

				// erase blank
				erase_blank(v);
				// check blank
				if(  *v  == '\0'){
					LogDebug("next line\n");
					LogUnindent();
					LogDebugf("End - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
					return 1;
				}
				else if(*v == TokenEndScope ){
					// no value
					LogDebug("end nesting\n");
					LogUnindent();
					LogDebugf("End - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
					return 0;
				}
				else if( *v == TokenEndValue){
					LogDebug("invalid token\n");
					LogUnindent();
					LogDebugf("Fail - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
					return -1;
				}
				else {// ---> get value
					get_ascii(value, v);
					erase_blank(v);

					if( *v  != '\0') return -1;
				}// <--- get value


				// get unnamed value
				if( *value != '\0'){
					conf->child_push_back(0, value);
					if( sep_token == TokenEndValue){
						ret = unnamed(v + sep + 1, conf, line);
					}
				}
			} // <---- get value or nesting

			LogUnindent();
			LogDebugf("End - int FileStream::unnamed(\"%s\", %p, %d)\n", v, conf, *line);
			return ret;
		}
		/**
		 * @brief parse - substruction context
		 * @param[in]    fp : file stream
		 * @param[in]     n : name string header pointer
		 * @param[in]     v : value string header pointer
		 * @param[in]     s : configuration
		 * @param[in]  line : reading line
		 * @return ==0 : success
		 */
		inline
		int file_stream::substitution(FILE *fp, char *n, char *v, configuration *conf, int *line)
		{
			char name[512];
			char value[512];

			LogDebugf("Begin: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);

			{ // ---> get name
				// zero initialize
				::memset(name, 0, sizeof(name));

				get_ascii(name, n);
				erase_blank(n);
				if( *n != '\0'){
					LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
					return -1;
				}
				LogDebugf("     : name \"%s\"\n", name);
			} // <--- get name

			{ // ----> get value or nesting
				erase_blank(v);
				LogDebugf("     : value \"%s\"\n", v);
				if( v[0] != TokenBeginScope ){

					// check error
					if( *v == '\0' ){
						LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
						return -1;
					}

					{// ---> get value
						get_ascii(value, v);
						erase_blank(v);
						if( *value == '\0'){
							LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
							return -1;
						}
						if( *v != '\0'){
							LogDebugf(" Fail: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
							return -1;
						}
						conf->child_push_back(name, value);
					}// <--- get value
				}
				// ---> nesting
				else {
					LogDebug("     : nesting\n");
					::memmove(v, v + 1, ::strlen(v) - 1);
					erase_blank(v);
					LogDebugf("     : nesting \"%s\"\n", v);
					if( *v == '\0' ){
						configuration *p;
						// todo modify to not need search
						conf->child_push_back(name, 0);
						p = conf->child_find(name, 0);
						_parse_(fp, p, line);
					}
					else {
						configuration *p;
						// todo modify to not need search
						conf->child_push_back(name, 0);
						p = conf->child_find(name, 0);
						if( unnamed(v, p, line) == 1) {
							// not end of nesting
							// read next line
							_parse_(fp, p, line);
						}
					}
				} // <--- nesting

			} // <---- get value or nesting


			LogDebugf("  End: int FileStream::substitution(%p, \"%s\", \"%s\", %p, %d)\n", fp, n, v, conf, *line);
			return 0;
		}
Example #14
0
static int
grub_sdl_checkkey (void)
{
  SDL_Event event;

  if (saved_char != -1)
    return saved_char;

  while (SDL_PollEvent (&event))
    {
      if (event.type == SDL_QUIT)
	grub_halt ();

      if (event.type == SDL_KEYDOWN)
	{
	  int key;

	  switch (event.key.keysym.sym)
	    {
	    case SDLK_LEFT:
	      key = GRUB_TERM_LEFT;
	      break;

	    case SDLK_RIGHT:
	      key = GRUB_TERM_RIGHT;
	      break;

	    case SDLK_UP:
	      key = GRUB_TERM_UP;
	      break;

	    case SDLK_DOWN:
	      key = GRUB_TERM_DOWN;
	      break;

	    case SDLK_HOME:
	      key = GRUB_TERM_HOME;
	      break;

	    case SDLK_END:
	      key = GRUB_TERM_END;
	      break;

	    case SDLK_PAGEUP:
	      key = GRUB_TERM_PPAGE;
	      break;

	    case SDLK_PAGEDOWN:
	      key = GRUB_TERM_NPAGE;
	      break;

	    case SDLK_DELETE:
	      key = GRUB_TERM_DC;
	      break;

	    case SDLK_INSERT:
	      key = GRUB_TERM_IC;
	      break;

	    case SDLK_F1:
	      key = GRUB_TERM_F1;
	      break;

	    case SDLK_F2:
	      key = GRUB_TERM_F2;
	      break;

	    case SDLK_F3:
	      key = GRUB_TERM_F3;
	      break;

	    case SDLK_F4:
	      key = GRUB_TERM_F4;
	      break;

	    case SDLK_F5:
	      key = GRUB_TERM_F5;
	      break;

	    case SDLK_F6:
	      key = GRUB_TERM_F6;
	      break;

	    case SDLK_F7:
	      key = GRUB_TERM_F7;
	      break;

	    case SDLK_F8:
	      key = GRUB_TERM_F8;
	      break;

	    case SDLK_F9:
	      key = GRUB_TERM_F9;
	      break;

	    case SDLK_F10:
	      key = GRUB_TERM_F10;
	      break;

	    default:
	      key = (event.key.keysym.sym > 127) ? 0 :
		get_ascii (event.key.keysym.sym, event.key.keysym.mod);
	    }

	  saved_char = key;
	  return key;
	}
    }

  return -1;
}
Example #15
0
static void handle(void)
{
  static long    old_mx, old_my, old_mb;
  static long    update_needed = 0;
  static EVENT   event;

  WIDGET *new_mfocus = NULL;

  old_mx = curr_mx;
  old_my = curr_my;
  old_mb = curr_mb;

  while (input->get_event(&event))
    {
      switch (event.type)
	{
	case EV_REL:
	  if (event.code == REL_X)
	    set_pos(curr_mx + event.value, curr_my);
	  else if (event.code == REL_Y)
	    set_pos(curr_mx, curr_my + event.value);
	  break;

	case EV_ABS:
	  if (event.code == ABS_X)
	    set_pos(event.value, curr_my);
	  else if (event.code == ABS_Y)
	    set_pos(curr_mx, event.value);
	  break;

	case EV_KEY:
	  if (event.value == 1)
	    {
	      press_cnt++;

	      if (event.code == BTN_LEFT)  curr_mb = curr_mb | 0x01;
	      if (event.code == BTN_RIGHT) curr_mb = curr_mb | 0x02;
	      keytab[event.code] = 1;
	      if (get_ascii(event.code)
		  || (event.code >= KEY_UP && event.code <= KEY_DELETE))
		{
		  curr_keystate = USERSTATE_KEY_PRESS;
		  curr_keycode  = event.code;
		  tick->add(key_repeat_delay, tick_handle_delay, (void *)curr_keycode);
		}
	      else
		{
		  curr_keystate = USERSTATE_KEY_IDLE;
		  curr_keycode  = 0;
		}
	    }
	  else if (event.value == 0)
	    {
	      press_cnt--;

	      if (event.code == BTN_LEFT)  curr_mb = curr_mb & 0x00fe;
	      if (event.code == BTN_RIGHT) curr_mb = curr_mb & 0x00fd;
	      keytab[event.code] = 0;
	      curr_keystate = USERSTATE_KEY_IDLE;
	      curr_keycode  = 0;
	    }
	  break;
	}

      update_mfocus();

      if (event.type == EV_KEY)
	{

	  WIDGET *win_kfocus = NULL;

	  /* make clicked window the active one */
	  if (curr_mfocus && key_sets_focus(event.code))
	    {
	      WINDOW *w = (WINDOW *)curr_mfocus->gen->get_window(curr_mfocus);
	      set_active_window(w, 1);
	    }

	  if (curr_window)
	    {
	      win_kfocus = curr_window->win->get_kfocus(curr_window);

	      /* redefine keyboard focus */
	      if (curr_mfocus && key_sets_focus(event.code) && curr_mfocus != win_kfocus)
		curr_mfocus->gen->focus(curr_mfocus);

	      /* request new keyboard focus - just in case it denied the focus */
	      win_kfocus = curr_window->win->get_kfocus(curr_window);
	    }

	  if ((event.value == 1) && (press_cnt == 1))
	    {

	      WIDGET *old_receiver = curr_receiver;

	      /* send keyboard event to actually focused widget if set */
	      if (win_kfocus && !key_sets_focus(event.code))
		{
		  if (win_kfocus) win_kfocus->gen->inc_ref(win_kfocus);
		  curr_receiver = win_kfocus;
		}
	      else
		{
		  if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus);
		  curr_receiver = curr_mfocus;
		}

	      if (old_receiver)
		old_receiver->gen->dec_ref(old_receiver);
	    }

	  if (curr_receiver)
	    curr_receiver->gen->handle_event(curr_receiver, &event, NULL);
      }
  }

  /*
   * Hell! We got more key release events than press events
   * This can happen when a key is pressed during the bootup
   */
  if (press_cnt < 0) press_cnt = 0;

  tick->handle();

  switch (curr_state)
    {

    case USERSTATE_IDLE:

      /* if mouse position changed -> deliver motion event */
      if (old_mx != curr_mx && curr_mfocus)
	{
	  event.type  = EV_ABS;
	  event.code  = ABS_X;
	  event.value  = curr_mx - curr_mfocus->gen->get_abs_x(curr_mfocus);
	  curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL);
	}
      if (old_my != curr_my && curr_mfocus)
	{
	  event.type  = EV_ABS;
	  event.code  = ABS_Y;
	  event.value  = curr_my - curr_mfocus->gen->get_abs_y(curr_mfocus);
	  curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL);
	}
      break;

    case USERSTATE_TOUCH:

      if (curr_tick_callback)
	curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);

      if (press_cnt == 0)
	idle();

      new_mfocus = curr_scr->gen->find((WIDGET *)curr_scr, curr_mx, curr_my);
      if (new_mfocus != curr_mfocus)
	{
	  if (new_mfocus == curr_selected)
	    {
	      curr_selected->gen->set_state(curr_selected,1);
	      curr_selected->gen->update(curr_selected);
	    }
	  else
	    {
	      curr_selected->gen->set_state(curr_selected,0);
	      curr_selected->gen->update(curr_selected);
	    }
	  if (curr_mfocus)
	    curr_mfocus->gen->dec_ref(curr_mfocus);

	  curr_mfocus = new_mfocus;

	  if (curr_mfocus)
	    curr_mfocus->gen->inc_ref(curr_mfocus);
	}
      break;

    case USERSTATE_DRAG:

      if (press_cnt == 0)
	idle();

      if (curr_tick_callback)
	{
	  curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
	}
      if (old_mx != curr_mx || old_my != curr_my || update_needed)
	{
	  update_needed = 1;
	  if (curr_motion_callback && !redraw->is_queued((WIDGET *)curr_scr))
	    {
	      update_needed = 0;
	      curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy);
	    }
	}
      break;

    case USERSTATE_GRAB:
#if 0
      /* if mouse position changed -> deliver motion event */
      if (old_mx != curr_mx || old_my != curr_my)
	{
	  s32 min_x = curr_selected->gen->get_abs_x(curr_selected);
	  s32 min_y = curr_selected->gen->get_abs_y(curr_selected);
	  s32 max_x = min_x + curr_selected->gen->get_w(curr_selected) - 1;
	  s32 max_y = min_y + curr_selected->gen->get_h(curr_selected) - 1;

	  if (curr_mx < min_x || curr_my < min_y ||
	      curr_mx > max_x || curr_my > max_y)
	    {
	      if (curr_mx < min_x) curr_mx = min_x;
	      if (curr_my < min_y) curr_my = min_y;
	      if (curr_mx > max_x) curr_mx = max_x;
	      if (curr_my > max_y) curr_my = max_y;
	      set_pos(curr_mx, curr_my);
	    }

	  event.type  = EVENT_MOTION;
	  event.abs_x = curr_mx - min_x;
	  event.abs_y = curr_my - min_y;
	  event.rel_x = curr_mx - old_mx;
	  event.rel_y = curr_my - old_my;
	  curr_selected->gen->handle_event(curr_selected, &event, NULL);
	}
      if (curr_tick_callback)
	{
	  curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
	}
#endif
      break;
    }
  scrdrv->set_mouse_pos(curr_mx, curr_my);
}
Example #16
0
File: test.c Project: boris-r-v/RIO
show_status() 
{
	
printf("\n* STATUS : COM=%d,", iComPort);
	
printf("Baud_Rate=%5ld,", lBaudRate);
	
if (iChksum == 0)
		printf("Checksum=DISABLE   *");
	
	else
		printf("Checksum=ENABLE    *");
	
printf("\n*---------------------------------------------------*");

}


help() 
{
	
printf("\n*---------------------------------------------------*");
	
printf("\n* Baud Rate: 9600, checksum: disable                *");
	
printf("\n* Module * Addr * Type * Chan * Decription          *");
	
printf("\n* I-7060 * 01   * 40   * 4+4  * 4*relay+4*DI        *");
	
printf("\n* I-7012D* 02   * 08   * 1    * AD, +/- 10V range   *");
	
printf("\n* I-7021 * 03   * 32   * 1    * DA, 0V-10V  range   *");
	
printf("\n* I-7053 * 04   * 40   * 16   * DI, 4V-30V HI       *");
	
printf("\n* I-7043 * 05   * 40   * 16   * DO, 100mA, 30V      *");
	
printf("\n* I-7017 * 06   * 08   * 1    * AD, +/- 10V         *");
	
printf("\n* I-7018 * 07   * 0E   * 1    * AD, J thermocouple  *");
	
printf("\n*---------------------------------------------------*");
	
printf("\nPress Any Key To Continue ");
	
getch();
	getch();

}


	/*
	 * ---- function 0
	 * ------------------------------------------------------- 
	 */ 
	
init() 
{
	
int iRet, iPort;
	
printf(" --> (0):init\n");
	
printf("port (1/2/3/4)=");
	scanf("%d", &iPort);
	
printf("baud rate(1200/2400/4800/9600/19200/38400/57600/115200)=");
	scanf("%ld", &lBaudRate);
	
printf("chksum (0=DISABLE,others=ENABLE)=");
	scanf("%d", &iChksum);
	
iRet = OPEN_COM(iPort, lBaudRate);
	
if (iRet == 0) {
		printf("--> OK");
		iComPort = iPort;
	}
	
	else if (iRet == 1)
		printf("--> port error");
	
	else if (iRet == 2)
		printf("--> baudrate error");

}


	/*
	 * ---- function 1
	 * ------------------------------------------------------- 
	 */ 
char cCmd1[100], cCmd2[100], cCmd3[100];

search() 
{
	
int i, iD1, iD2, iRet, j;
	
long BaudRate;
	
char cFlag;
	
		// printf(" Search address=00 to FF, baudrate=1200 to 115200,
		// press any key to stop\n");
		printf
		(" Search address=00 to FF, baudrate=1200 to 115200, please wait...\n");
	
cCmd1[0] = '$';
	
strcpy(cCmd3, "Test Command\r");
	
for (;;)
		
			// for (i=0; i<256; i++) /* search from adress_00 to adress_FF 
			// 
			// 
			// */
			for (i = 0; i < 4; i++)	/* search from adress_00 to * *
									   * adress_FF */
			
 {
			
printf("\n---------------------------------------------\n");
			
for (j = 3; j <= 10; j++)	/* search from BaudRate_1200 to *
										   * * BaudRate_115200 */
				
 {
				
switch (j)
					
 {
				
case 3:
					BaudRate = 1200L;
					break;
				
case 4:
					BaudRate = 2400L;
					break;
				
case 5:
					BaudRate = 4800L;
					break;
				
case 6:
					BaudRate = 9600L;
Example #17
0
void
hexdump (FILE *fp, u_char *buf, int len)
{
	int i, j = 0, k;
	u_char uc;
	char interp[16];

	if (fp) {
		fprintf (fp, "    ");
	} else {
		printf ("    ");
	}
	for (i = 0; i < len; i++) {
		uc = *buf;
		buf++;
		if (fp) {
			fprintf (fp, "%02x ", uc);
		} else {
			printf ("%02x ", uc);
		}
		interp[j] = (char)uc;
		if (++j >= 16) {
			if (fp) {
				fprintf (fp, "\t");
			} else {
				printf ("\t");
			}
			for (j = 0; j < 16; j++) {
				if (fp) {
					fprintf (fp, "%c", get_ascii(interp[j]));
				} else {
					printf ("%c", get_ascii(interp[j]));
				}
			}
			if (fp) {
				fprintf (fp, "\n    ");
			} else {
				printf ("\n    ");
			}
			j = 0;
		}
	}
	if (j) {
		i = 16-j;
		for (k = 0; k < i; k++) {
			if (fp) {
				fprintf (fp, "   ");
			} else {
				printf ("   ");
			}
		}
		if (fp) {
			fprintf (fp, "\t");
		} else {
			printf ("\t");
		}
		for (k = 0; k < j; k++) {
			if (fp) {
				fprintf (fp, "%c", get_ascii(interp[k]));
			} else {
				printf ("%c", get_ascii(interp[k]));
			}
		}
	}
	if (fp) {
		fprintf (fp, "\n");
	} else {
		printf ("\n");
	}
}
Example #18
0
static void handle(EVENT *e, int count)
{
	int old_mx, old_my, old_mb;
	int i;
	static int update_needed = 0;
	EVENT event;
	WIDGET *new_mfocus = NULL;

	old_mx = curr_mx;
	old_my = curr_my;
	old_mb = curr_mb;

	for(i=0;i<count;i++) {
		switch (e[i].type) {
			case EVENT_MOTION:
				set_pos(curr_mx + e[i].rel_x, curr_my + e[i].rel_y);
				break;

			case EVENT_ABSMOTION:
				set_pos(e[i].abs_x, e[i].abs_y);
				break;

			case EVENT_PRESS:
				press_cnt++;

				if (e[i].code == MTK_BTN_LEFT)  curr_mb = curr_mb | 0x01;
				if (e[i].code == MTK_BTN_RIGHT) curr_mb = curr_mb | 0x02;
				keytab[e[i].code] = 1;
				if (get_ascii(e[i].code)
				 || (e[i].code >= MTK_KEY_UP && e[i].code <= MTK_KEY_DELETE)) {
					curr_keystate = USERSTATE_KEY_PRESS;
					curr_keycode  = e[i].code;
					tick->add(key_repeat_delay, tick_handle_delay, (void *)curr_keycode);
				} else {
					curr_keystate = USERSTATE_KEY_IDLE;
					curr_keycode  = 0;
				}
				break;

			case EVENT_RELEASE:
				press_cnt--;

				if ((curr_state == USERSTATE_DRAG) && curr_motion_callback)
					curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy);

				if (e[i].code == MTK_BTN_LEFT)  curr_mb = curr_mb & 0x00fe;
				if (e[i].code == MTK_BTN_RIGHT) curr_mb = curr_mb & 0x00fd;
				keytab[e[i].code] = 0;
				curr_keystate = USERSTATE_KEY_IDLE;
				curr_keycode  = 0;
				break;
		}

		update_mfocus();

		if ((e[i].type == EVENT_PRESS) || (e[i].type == EVENT_RELEASE)) {
			WIDGET *win_kfocus = NULL;

			/* make clicked window the active one */
			if (curr_mfocus && key_sets_focus(e[i].code)) {
				WINDOW *w = (WINDOW *)curr_mfocus->gen->get_window(curr_mfocus);

				/* ignore clicks on the desktop (last window of window stack) */
				if (w->gen->get_next((WIDGET *)w))
					set_active_window(w, 1);
			}

			if (curr_window) {
				win_kfocus = curr_window->win->get_kfocus(curr_window);

				/* redefine keyboard focus */
				if (curr_mfocus && key_sets_focus(e[i].code) && curr_mfocus != win_kfocus)
					curr_mfocus->gen->focus(curr_mfocus);

				/* request new keyboard focus - just in case it denied the focus */
				win_kfocus = curr_window->win->get_kfocus(curr_window);
			}

			if ((e[i].type == EVENT_PRESS) && (press_cnt == 1)) {
				WIDGET *old_receiver = curr_receiver;

				/* send keyboard event to actually focused widget if set */
				if (win_kfocus && !key_sets_focus(e[i].code)) {
					if (win_kfocus) win_kfocus->gen->inc_ref(win_kfocus);
					curr_receiver = win_kfocus;
				} else {
					if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus);
					curr_receiver = curr_mfocus;
				}

				if (old_receiver)
					old_receiver->gen->dec_ref(old_receiver);
			}

			if (curr_receiver)
				curr_receiver->gen->handle_event(curr_receiver, &e[i], NULL);
		}
	}

	/*
	 * Hell! We got more key release events than press events
	 * This can happen when a key is pressed during the bootup
	 */
	if (press_cnt < 0) press_cnt = 0;

	tick->handle();

	switch (curr_state) {
		case USERSTATE_IDLE:

			/* if mouse position changed -> deliver motion event */
			if (old_mx != curr_mx || old_my != curr_my) {
				if (curr_mfocus) {
					event.type  = EVENT_MOTION;
					event.abs_x = curr_mx - curr_mfocus->gen->get_abs_x(curr_mfocus);
					event.abs_y = curr_my - curr_mfocus->gen->get_abs_y(curr_mfocus);
					event.rel_x = curr_mx - old_mx;
					event.rel_y = curr_my - old_my;
					curr_mfocus->gen->handle_event(curr_mfocus, &event, NULL);
				}
			}
			break;

		case USERSTATE_TOUCH:

			if (!curr_selected)
				break;

			if (curr_tick_callback)
				curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);

			if (press_cnt == 0) idle();

			new_mfocus = curr_scr->gen->find((WIDGET *)curr_scr, curr_mx, curr_my);
			if (new_mfocus != curr_mfocus) {
				if (new_mfocus == curr_selected) {
					if (curr_selected) {
						curr_selected->gen->set_state(curr_selected,1);
						curr_selected->gen->update(curr_selected);
					}
				} else {
					if (curr_selected) {
						curr_selected->gen->set_state(curr_selected,0);
						curr_selected->gen->update(curr_selected);
					}
				}
				if (curr_mfocus) curr_mfocus->gen->dec_ref(curr_mfocus);
				curr_mfocus = new_mfocus;
				if (curr_mfocus) curr_mfocus->gen->inc_ref(curr_mfocus);
			}
			break;

		case USERSTATE_DRAG:

			if (press_cnt == 0) idle();

			if (curr_tick_callback) {
				curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
			}
			if (old_mx != curr_mx || old_my != curr_my || update_needed) {
				update_needed = 1;
				if (curr_motion_callback && !redraw->is_queued((WIDGET *)curr_scr)) {
					update_needed = 0;
					curr_motion_callback(curr_selected, curr_mx - omx, curr_my - omy);
				}
			}
			break;

		case USERSTATE_GRAB:

			/* if mouse position changed -> deliver motion event */
			if (old_mx != curr_mx || old_my != curr_my) {
				s32 min_x = curr_selected->gen->get_abs_x(curr_selected);
				s32 min_y = curr_selected->gen->get_abs_y(curr_selected);
				s32 max_x = min_x + curr_selected->gen->get_w(curr_selected) - 1;
				s32 max_y = min_y + curr_selected->gen->get_h(curr_selected) - 1;

				if (curr_mx < min_x || curr_my < min_y ||
				    curr_mx > max_x || curr_my > max_y) {
					if (curr_mx < min_x) curr_mx = min_x;
					if (curr_my < min_y) curr_my = min_y;
					if (curr_mx > max_x) curr_mx = max_x;
					if (curr_my > max_y) curr_my = max_y;
					set_pos(curr_mx, curr_my);
				}

				event.type  = EVENT_MOTION;
				event.abs_x = curr_mx - min_x;
				event.abs_y = curr_my - min_y;
				event.rel_x = curr_mx - old_mx;
				event.rel_y = curr_my - old_my;
				curr_selected->gen->handle_event(curr_selected, &event, NULL);
			}
			if (curr_tick_callback) {
				curr_tick_callback(curr_selected, curr_mx - omx, curr_my - omy);
			}
			break;
	}
	scrdrv->set_mouse_pos(curr_mx, curr_my);
}