Пример #1
0
    if (cygwin_conv_path (flags, in, SDATA (converted), converted_len))
        error ("cygwin_conv_path: %s", strerror (errno));

    return unbind_to (count, DECODE_FILE (converted));
}

DEFUN ("cygwin-convert-file-name-to-windows",
       Fcygwin_convert_file_name_to_windows,
       Scygwin_convert_file_name_to_windows,
       1, 2, 0,
       doc: /* Convert PATH to a Windows path.  If ABSOLUTE-P is
non-nil, return an absolute path.*/)
(Lisp_Object path, Lisp_Object absolute_p)
{
    return from_unicode (
               conv_filename_to_w32_unicode (path, EQ (absolute_p, Qnil) ? 0 : 1));
}

DEFUN ("cygwin-convert-file-name-from-windows",
       Fcygwin_convert_file_name_from_windows,
       Scygwin_convert_file_name_from_windows,
       1, 2, 0,
       doc: /* Convert a Windows path to a Cygwin path.  If ABSOLUTE-P
is non-nil, return an absolute path.*/)
(Lisp_Object path, Lisp_Object absolute_p)
{
    return conv_filename_from_w32_unicode (to_unicode (path, &path),
                                           EQ (absolute_p, Qnil) ? 0 : 1);
}

void
Пример #2
0
static void
single_menu_item (Lisp_Object key, Lisp_Object item, Lisp_Object dummy, void *skp_v)
{
  Lisp_Object map, item_string, enabled;
  struct gcpro gcpro1, gcpro2;
  int res;
  struct skp *skp = skp_v;

  /* Parse the menu item and leave the result in item_properties.  */
  GCPRO2 (key, item);
  res = parse_menu_item (item, 0);
  UNGCPRO;
  if (!res)
    return;			/* Not a menu item.  */

  map = AREF (item_properties, ITEM_PROPERTY_MAP);

  enabled = AREF (item_properties, ITEM_PROPERTY_ENABLE);
  item_string = AREF (item_properties, ITEM_PROPERTY_NAME);

  if (!NILP (map) && SREF (item_string, 0) == '@')
    {
      if (!NILP (enabled))
	/* An enabled separate pane. Remember this to handle it later.  */
	skp->pending_maps = Fcons (Fcons (map, Fcons (item_string, key)),
				   skp->pending_maps);
      return;
    }

#if defined (HAVE_X_WINDOWS) || defined (MSDOS)
#ifndef HAVE_BOXES
  /* Simulate radio buttons and toggle boxes by putting a prefix in
     front of them.  */
  {
    Lisp_Object prefix = Qnil;
    Lisp_Object type = AREF (item_properties, ITEM_PROPERTY_TYPE);
    if (!NILP (type))
      {
	Lisp_Object selected
	  = AREF (item_properties, ITEM_PROPERTY_SELECTED);

	if (skp->notbuttons)
	  /* The first button. Line up previous items in this menu.  */
	  {
	    int idx = skp->notbuttons; /* Index for first item this menu.  */
	    int submenu = 0;
	    Lisp_Object tem;
	    while (idx < menu_items_used)
	      {
		tem
		  = AREF (menu_items, idx + MENU_ITEMS_ITEM_NAME);
		if (NILP (tem))
		  {
		    idx++;
		    submenu++;		/* Skip sub menu.  */
		  }
		else if (EQ (tem, Qlambda))
		  {
		    idx++;
		    submenu--;		/* End sub menu.  */
		  }
		else if (EQ (tem, Qt))
		  idx += 3;		/* Skip new pane marker. */
		else if (EQ (tem, Qquote))
		  idx++;		/* Skip a left, right divider. */
		else
		  {
		    if (!submenu && SREF (tem, 0) != '\0'
			&& SREF (tem, 0) != '-')
		      ASET (menu_items, idx + MENU_ITEMS_ITEM_NAME,
                           concat2 (build_string ("    "), tem));
		    idx += MENU_ITEMS_ITEM_LENGTH;
		  }
	      }
	    skp->notbuttons = 0;
	  }

	/* Calculate prefix, if any, for this item.  */
	if (EQ (type, QCtoggle))
	  prefix = build_string (NILP (selected) ? "[ ] " : "[X] ");
	else if (EQ (type, QCradio))
	  prefix = build_string (NILP (selected) ? "( ) " : "(*) ");
      }
    /* Not a button. If we have earlier buttons, then we need a prefix.  */
    else if (!skp->notbuttons && SREF (item_string, 0) != '\0'
	     && SREF (item_string, 0) != '-')
      prefix = build_string ("    ");

    if (!NILP (prefix))
      item_string = concat2 (prefix, item_string);
  }
#endif /* not HAVE_BOXES */

#if ! defined (USE_X_TOOLKIT) && ! defined (USE_GTK)
  if (!NILP (map))
    /* Indicate visually that this is a submenu.  */
    item_string = concat2 (item_string, build_string (" >"));
#endif

#endif /* HAVE_X_WINDOWS || MSDOS */

  push_menu_item (item_string, enabled, key,
		  AREF (item_properties, ITEM_PROPERTY_DEF),
		  AREF (item_properties, ITEM_PROPERTY_KEYEQ),
		  AREF (item_properties, ITEM_PROPERTY_TYPE),
		  AREF (item_properties, ITEM_PROPERTY_SELECTED),
		  AREF (item_properties, ITEM_PROPERTY_HELP));

#if defined (USE_X_TOOLKIT) || defined (USE_GTK) || defined (HAVE_NS) || defined (HAVE_NTGUI)
  /* Display a submenu using the toolkit.  */
  if (! (NILP (map) || NILP (enabled)))
    {
      push_submenu_start ();
      single_keymap_panes (map, Qnil, key, skp->maxdepth - 1);
      push_submenu_end ();
    }
#endif
}
Пример #3
0
void
find_and_call_menu_selection (FRAME_PTR f, int menu_bar_items_used, Lisp_Object vector, void *client_data)
{
  Lisp_Object prefix, entry;
  Lisp_Object *subprefix_stack;
  int submenu_depth = 0;
  int i;

  entry = Qnil;
  subprefix_stack = alloca (menu_bar_items_used * sizeof *subprefix_stack);
  prefix = Qnil;
  i = 0;

  while (i < menu_bar_items_used)
    {
      if (EQ (AREF (vector, i), Qnil))
	{
	  subprefix_stack[submenu_depth++] = prefix;
	  prefix = entry;
	  i++;
	}
      else if (EQ (AREF (vector, i), Qlambda))
	{
	  prefix = subprefix_stack[--submenu_depth];
	  i++;
	}
      else if (EQ (AREF (vector, i), Qt))
	{
	  prefix = AREF (vector, i + MENU_ITEMS_PANE_PREFIX);
	  i += MENU_ITEMS_PANE_LENGTH;
	}
      else
	{
	  entry = AREF (vector, i + MENU_ITEMS_ITEM_VALUE);
	  /* Treat the pointer as an integer.  There's no problem
	     as long as pointers have enough bits to hold small integers.  */
	  if ((intptr_t) client_data == i)
	    {
	      int j;
	      struct input_event buf;
	      Lisp_Object frame;
	      EVENT_INIT (buf);

	      XSETFRAME (frame, f);
	      buf.kind = MENU_BAR_EVENT;
	      buf.frame_or_window = frame;
	      buf.arg = frame;
	      kbd_buffer_store_event (&buf);

	      for (j = 0; j < submenu_depth; j++)
		if (!NILP (subprefix_stack[j]))
		  {
		    buf.kind = MENU_BAR_EVENT;
		    buf.frame_or_window = frame;
		    buf.arg = subprefix_stack[j];
		    kbd_buffer_store_event (&buf);
		  }

	      if (!NILP (prefix))
		{
		  buf.kind = MENU_BAR_EVENT;
		  buf.frame_or_window = frame;
		  buf.arg = prefix;
		  kbd_buffer_store_event (&buf);
		}

	      buf.kind = MENU_BAR_EVENT;
	      buf.frame_or_window = frame;
	      buf.arg = entry;
	      kbd_buffer_store_event (&buf);

	      return;
	    }
	  i += MENU_ITEMS_ITEM_LENGTH;
	}
    }
}
Пример #4
0
void unintern1(CL_FORM *base)
{
	LOAD_NIL(ARG(2));
	LOAD_NIL(ARG(3));
	if(CL_SYMBOLP(ARG(0)))
	{
		LOAD_SMSTR(SYM_NAME(ARG(0)), ARG(4));
	}
	else
	{
		if(CL_TRUEP(ARG(0)))
		{
			COPY(SYMVAL(Slisp, 676), ARG(4));	/* SYM_EXPECTED */
			COPY(ARG(0), ARG(5));
			Ferror(ARG(4), 2);
		}
		else
		{
			LOAD_SMSTR((CL_FORM *)&KClisp[266], ARG(4));	/* NIL */
		}
	}
	LOAD_NIL(ARG(5));
	COPY(ARG(1), ARG(6));
	coerce_to_package(ARG(6));
	COPY(ARG(6), ARG(1));
	COPY(ARG(4), ARG(6));
	COPY(ARG(1), ARG(7));
	find_symbol1(ARG(6));
	COPY(&mv_buf[0], ARG(7));
	{
		int nargs;
		nargs = 2;
		mv_count = 1;
		{
			switch(nargs)
			{
				case 0:
				LOAD_NIL(ARG(6));
				case 1:
				LOAD_NIL(ARG(7));
				nargs = 2;
			}
			COPY(ARG(6), ARG(2));
			COPY(ARG(7), ARG(3));
		}
	}
	if(EQ(ARG(2), ARG(0)))
	{
		LOAD_BOOL(CL_SYMBOLP(ARG(3)) && GET_SYMBOL(ARG(3)) == SYMBOL(Slisp, 384), ARG(6));	/* INTERNAL */
		if(CL_TRUEP(ARG(6)))
		{
			goto THEN1;
		}
		else
		{
		}	/* EXTERNAL */
	}
	else
	{
		goto ELSE2;
	}
	if(CL_SYMBOLP(ARG(3)) && GET_SYMBOL(ARG(3)) == SYMBOL(Slisp, 385))
	{
		THEN1:;
		if(CL_SYMBOLP(ARG(3)) && GET_SYMBOL(ARG(3)) == SYMBOL(Slisp, 385))	/* EXTERNAL */
		{
			COPY(ARG(1), ARG(6));
			COPY(ARG(6), ARG(7));
			COPY(ARG(7), ARG(8));
			LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(9));	/* PACKAGE */
			rt_struct_typep(ARG(8));
			if(CL_TRUEP(ARG(8)))
			{
				COPY(OFFSET(AR_BASE(GET_FORM(ARG(7))), 3 + 1), ARG(5));
			}
			else
			{
				COPY(SYMVAL(Slisp, 352), ARG(5));	/* NO_STRUCT */
				COPY(ARG(7), ARG(6));
				LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(7));	/* PACKAGE */
				Ferror(ARG(5), 3);
			}
		}
		else
		{
			COPY(ARG(1), ARG(6));
			COPY(ARG(6), ARG(7));
			COPY(ARG(7), ARG(8));
			LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(9));	/* PACKAGE */
			rt_struct_typep(ARG(8));
			if(CL_TRUEP(ARG(8)))
			{
				COPY(OFFSET(AR_BASE(GET_FORM(ARG(7))), 2 + 1), ARG(5));
			}
			else
			{
				COPY(SYMVAL(Slisp, 352), ARG(5));	/* NO_STRUCT */
				COPY(ARG(7), ARG(6));
				LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(7));	/* PACKAGE */
				Ferror(ARG(5), 3);
			}
		}
		COPY(ARG(1), ARG(6));
		LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(7));	/* PACKAGE */
		rt_struct_typep(ARG(6));
		if(CL_TRUEP(ARG(6)))
		{
			COPY(OFFSET(AR_BASE(GET_FORM(ARG(1))), 4 + 1), ARG(6));
		}
		else
		{
			COPY(SYMVAL(Slisp, 352), ARG(6));	/* NO_STRUCT */
			COPY(ARG(1), ARG(7));
			LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(8));	/* PACKAGE */
			Ferror(ARG(6), 3);
		}
		COPY(ARG(0), ARG(7));
		COPY(ARG(6), ARG(8));
		LOAD_NIL(ARG(9));
		LOAD_NIL(ARG(10));
		LOAD_NIL(ARG(11));
		member1(ARG(7));
		if(CL_TRUEP(ARG(7)))
		{
			LOAD_FIXNUM(ARG(6), 0, ARG(6));
			LOAD_NIL(ARG(7));
			COPY(ARG(1), ARG(8));
			LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(9));	/* PACKAGE */
			rt_struct_typep(ARG(8));
			if(CL_TRUEP(ARG(8)))
			{
				COPY(OFFSET(AR_BASE(GET_FORM(ARG(1))), 5 + 1), ARG(8));
			}
			else
			{
				COPY(SYMVAL(Slisp, 352), ARG(8));	/* NO_STRUCT */
				COPY(ARG(1), ARG(9));
				LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(10));	/* PACKAGE */
				Ferror(ARG(8), 3);
			}
			M1_1:;
			if(CL_ATOMP(ARG(8)))
			{
				LOAD_NIL(ARG(7));
				goto RETURN1;
			}
			COPY(ARG(8), ARG(9));
			COPY(GET_CAR(ARG(9)), ARG(7));
			COPY(ARG(4), ARG(9));
			COPY(ARG(7), ARG(10));
			find_symbol1(ARG(9));
			COPY(&mv_buf[0], ARG(10));
			{
				int nargs;
				nargs = 2;
				mv_count = 1;
				{
					switch(nargs)
					{
						case 0:
						LOAD_NIL(ARG(9));
						case 1:
						LOAD_NIL(ARG(10));
						nargs = 2;
					}
					COPY(ARG(9), ARG(2));
					COPY(ARG(10), ARG(3));
				}
			}
			if(CL_SYMBOLP(ARG(3)) && GET_SYMBOL(ARG(3)) == SYMBOL(Slisp, 385))	/* EXTERNAL */
			{
				if(CL_FIXNUMP(ARG(6)) && GET_FIXNUM(ARG(6)) == 0)
				{
					COPY(ARG(2), ARG(6));
				}
				else
				{
					if(EQ(ARG(2), ARG(6)))
					{
					}
					else
					{
						LOAD_SMSTR((CL_FORM *)&Kunintern1[0], ARG(9));	/* ~S and ~S will cause a name conflict */
						COPY(ARG(6), ARG(10));
						COPY(ARG(2), ARG(11));
						Ferror(ARG(9), 3);
					}
				}
			}
			COPY(ARG(8), ARG(9));
			COPY(GET_CDR(ARG(9)), ARG(8));
			goto M1_1;
			RETURN1:;
			COPY(ARG(1), ARG(6));
			LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(7));	/* PACKAGE */
			rt_struct_typep(ARG(6));
			if(CL_TRUEP(ARG(6)))
			{
				COPY(OFFSET(AR_BASE(GET_FORM(ARG(1))), 4 + 1), ARG(6));
			}
			else
			{
				COPY(SYMVAL(Slisp, 352), ARG(6));	/* NO_STRUCT */
				COPY(ARG(1), ARG(7));
				LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(8));	/* PACKAGE */
				Ferror(ARG(6), 3);
			}
			LOAD_SYMBOL(SYMBOL(Slisp, 392), ARG(7));	/* COUNT */
			LOAD_FIXNUM(ARG(8), 1, ARG(8));
			Flist(ARG(7), 2);
			LOAD_GLOBFUN(&CFremove, ARG(8));
			COPY(ARG(0), ARG(9));
			COPY(ARG(6), ARG(10));
			COPY(ARG(7), ARG(11));
			Fapply(ARG(8), 4);
			mv_count = 1;
			COPY(ARG(8), ARG(6));
			LOAD_FIXNUM(ARG(7), 4, ARG(7));
			COPY(ARG(1), ARG(8));
			LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(9));	/* PACKAGE */
			rt_struct_typep(ARG(8));
			if(CL_TRUEP(ARG(8)))
			{
				COPY(ARG(6), OFFSET(AR_BASE(GET_FORM(ARG(1))), 4 + 1));
			}
			else
			{
				COPY(SYMVAL(Slisp, 352), ARG(8));	/* NO_STRUCT */
				COPY(ARG(1), ARG(9));
				LOAD_SYMBOL(SYMBOL(Slisp, 354), ARG(10));	/* PACKAGE */
				Ferror(ARG(8), 3);
			}
		}
		COPY(ARG(0), ARG(6));
		COPY(ARG(5), ARG(7));
		LOAD_FIXNUM(ARG(8), 101, ARG(8));
		COPY(ARG(4), ARG(9));
		string_to_simple_string(ARG(9));
		rt_sxhash_string(ARG(9));
		COPY(ARG(9), ARG(10));
		LOAD_FIXNUM(ARG(11), 101, ARG(11));
		rt_floor(ARG(10));
		COPY(&mv_buf[0], ARG(11));
		mv_count = 1;
		{
			COPY(ARG(11), ARG(8));
		}
		del_pack_sym(ARG(6));
		if(CL_SYMBOLP(ARG(0)))
		{
			COPY(SYM_PACKAGE(ARG(0)), ARG(6));
		}
		else
		{
			if(CL_TRUEP(ARG(0)))
			{
				COPY(SYMVAL(Slisp, 676), ARG(6));	/* SYM_EXPECTED */
				COPY(ARG(0), ARG(7));
				Ferror(ARG(6), 2);
			}
			else
			{
				COPY(SYMVAL(Slisp, 679), ARG(6));	/* *NIL-PACKAGE* */
			}
		}
		if(EQ(ARG(6), ARG(1)))
		{
			COPY(ARG(0), ARG(6));
			LOAD_NIL(ARG(7));
			set_symbol_package(ARG(6));
		}
		LOAD_SYMBOL(SYMBOL(Slisp, 48), ARG(0));	/* T */
	}
	else
	{
		ELSE2:;
		LOAD_NIL(ARG(0));
	}
}
Пример #5
0
static int
do_mouse_event (MOUSE_EVENT_RECORD *event,
		struct input_event *emacs_ev)
{
  static DWORD button_state = 0;
  static Lisp_Object last_mouse_window;
  DWORD but_change, mask, flags = event->dwEventFlags;
  int i;

  switch (flags)
    {
    case MOUSE_MOVED:
      {
	struct frame *f = get_frame ();
	Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
	int mx = event->dwMousePosition.X, my = event->dwMousePosition.Y;

	mouse_moved_to (mx, my);

	if (f->mouse_moved)
	  {
	    if (hlinfo->mouse_face_hidden)
	      {
		hlinfo->mouse_face_hidden = 0;
		clear_mouse_face (hlinfo);
	      }

	    /* Generate SELECT_WINDOW_EVENTs when needed.  */
	    if (!NILP (Vmouse_autoselect_window))
	      {
		Lisp_Object mouse_window = window_from_coordinates (f, mx, my,
								    0, 0);
		/* A window will be selected only when it is not
		   selected now, and the last mouse movement event was
		   not in it.  A minibuffer window will be selected iff
		   it is active.  */
		if (WINDOWP (mouse_window)
		    && !EQ (mouse_window, last_mouse_window)
		    && !EQ (mouse_window, selected_window))
		  {
		    struct input_event event;

		    EVENT_INIT (event);
		    event.kind = SELECT_WINDOW_EVENT;
		    event.frame_or_window = mouse_window;
		    event.arg = Qnil;
		    event.timestamp = movement_time;
		    kbd_buffer_store_event (&event);
		  }
		last_mouse_window = mouse_window;
	      }
	    else
	      last_mouse_window = Qnil;

	    previous_help_echo_string = help_echo_string;
	    help_echo_string = help_echo_object = help_echo_window = Qnil;
	    help_echo_pos = -1;
	    note_mouse_highlight (f, mx, my);
	    /* If the contents of the global variable help_echo has
	       changed (inside note_mouse_highlight), generate a HELP_EVENT.  */
	    if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
	      gen_help_event (help_echo_string, selected_frame,
			      help_echo_window, help_echo_object,
			      help_echo_pos);
	  }
	/* We already called kbd_buffer_store_event, so indicate the
	   the caller it shouldn't.  */
	return 0;
      }
    case MOUSE_WHEELED:
    case MOUSE_HWHEELED:
      {
	struct frame *f = get_frame ();
	int mx = event->dwMousePosition.X, my = event->dwMousePosition.Y;
	bool down_p = (event->dwButtonState & 0x10000000) != 0;

	emacs_ev->kind =
	  flags == MOUSE_HWHEELED ? HORIZ_WHEEL_EVENT : WHEEL_EVENT;
	emacs_ev->code = 0;
	emacs_ev->modifiers = down_p ? down_modifier : up_modifier;
	emacs_ev->modifiers |=
	  w32_kbd_mods_to_emacs (event->dwControlKeyState, 0);
	XSETINT (emacs_ev->x, mx);
	XSETINT (emacs_ev->y, my);
	XSETFRAME (emacs_ev->frame_or_window, f);
	emacs_ev->arg = Qnil;
	emacs_ev->timestamp = GetTickCount ();
	return 1;
      }
    case DOUBLE_CLICK:
    default:	/* mouse pressed or released */
      /* It looks like the console code sends us a button-release
	 mouse event with dwButtonState == 0 when a window is
	 activated and when the mouse is first clicked.  Ignore this
	 case.  */
      if (event->dwButtonState == button_state)
	return 0;

      emacs_ev->kind = MOUSE_CLICK_EVENT;

      /* Find out what button has changed state since the last button
	 event.  */
      but_change = button_state ^ event->dwButtonState;
      mask = 1;
      for (i = 0; mask; i++, mask <<= 1)
	if (but_change & mask)
	  {
	    if (i < NUM_TRANSLATED_MOUSE_BUTTONS)
	      emacs_ev->code = emacs_button_translation[i];
	    else
	      emacs_ev->code = i;
	    break;
	  }

      button_state = event->dwButtonState;
      emacs_ev->modifiers =
	w32_kbd_mods_to_emacs (event->dwControlKeyState, 0)
	| ((event->dwButtonState & mask) ? down_modifier : up_modifier);

      XSETFASTINT (emacs_ev->x, event->dwMousePosition.X);
      XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y);
      XSETFRAME (emacs_ev->frame_or_window, get_frame ());
      emacs_ev->arg = Qnil;
      emacs_ev->timestamp = GetTickCount ();

      return 1;
    }
}
Пример #6
0
/*
 - fast - step through the string at top speed
 */
static char *			/* where tentative match ended, or NULL */
fast(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
{
	states st = m->st;
	states fresh = m->fresh;
	states tmp = m->tmp;
	char *p = start;
	int c = (start == m->beginp) ? OUT : *(start-1);
	int lastc;	/* previous c */
	int flagch;
	int i;
	char *coldp;	/* last p after which no match was underway */

	CLEAR(st);
	SET1(st, startst);
	st = step(m->g, startst, stopst, st, NOTHING, st);
	ASSIGN(fresh, st);
	SP("start", st, *p);
	coldp = NULL;
	for (;;) {
		/* next character */
		lastc = c;
		c = (p == m->endp) ? OUT : *p;
		if (EQ(st, fresh))
			coldp = p;

		/* is there an EOL and/or BOL between lastc and c? */
		flagch = '\0';
		i = 0;
		if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
				(lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
			flagch = BOL;
			i = m->g->nbol;
		}
		if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
				(c == OUT && !(m->eflags&REG_NOTEOL)) ) {
			flagch = (flagch == BOL) ? BOLEOL : EOL;
			i += m->g->neol;
		}
		if (i != 0) {
			for (; i > 0; i--)
				st = step(m->g, startst, stopst, st, flagch, st);
			SP("boleol", st, c);
		}

		/* how about a word boundary? */
		if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
					(c != OUT && ISWORD(c)) ) {
			flagch = BOW;
		}
		if ( (lastc != OUT && ISWORD(lastc)) &&
				(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
			flagch = EOW;
		}
		if (flagch == BOW || flagch == EOW) {
			st = step(m->g, startst, stopst, st, flagch, st);
			SP("boweow", st, c);
		}

		/* are we done? */
		if (ISSET(st, stopst) || p == stop)
			break;		/* NOTE BREAK OUT */

		/* no, we must deal with this character */
		ASSIGN(tmp, st);
		ASSIGN(st, fresh);
		assert(c != OUT);
		st = step(m->g, startst, stopst, tmp, c, st);
		SP("aft", st, c);
		assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
		p++;
	}

	assert(coldp != NULL);
	m->coldp = coldp;
	if (ISSET(st, stopst))
		return(p+1);
	else
		return(NULL);
}
Пример #7
0
/*
inline float getAxisElem4( cl_float4 vec, int axis )
{
    if( axis == 0 )
        return vec.x;
    else if( axis == 1 )
        return vec.y;
    else if( axis == 2 )
        return vec.z;
    else
        return -1;
}

bool checkRange( const cl_float4 intersect, const cl_float4 range, const int axis )
{
    bool result = false;
    switch( axis )
    {
    case 0: // X axis range
        if( intersect.y >= range.x && intersect.y <= range.y &&
                intersect.z >= range.z && intersect.z <= range.w )
          result = true;
        break;
    case 1: // Y axis range
        if( intersect.x >= range.x && intersect.x <= range.y &&
                intersect.z >= range.z && intersect.z <= range.w )
          result = true;
        break;
    case 2: // Z axis range
        if( intersect.x >= range.x && intersect.x <= range.y &&
                intersect.y >= range.z && intersect.y <= range.w )
          result = true;
        break;
    default:
        break;
    }
    return result;
}

float dot( cl_float3 f1, cl_float3 f2 )
{
    return f1.x*f2.x + f1.y*f2.y + f1.z*f2.z;
}

float doIntersectPlane( cl_float3 point, cl_float3 norm, cl_float4 eyePos, cl_float4 d)
{

    float t = -1;
    float denominator = (norm.x*d.x+norm.y*d.y+norm.z*d.z);
    if(fabs(denominator)>EPSILON)
    {
        cl_float3 eye3;
        eye3.x  =eyePos.x;
        eye3.y = eyePos.y;
        eye3.z = eyePos.z;
        t = (dot(norm, point)-dot(norm, eye3))/(denominator);
    }

    return t;
}

void doIntersectRayKdBox2(
        const cl_float4 eyePos,
        const cl_float4 d,
        float* near,
        float* far,
        const cl_float3 boxStart,
        const cl_float3 boxSize
    )
{
    *near = -1;
    *far = -1;
    cl_float3 start = boxStart;
    cl_float3 end;
    end .x = boxStart.x + boxSize.x;
    end .y = boxStart.y + boxSize.y;
    end .z = boxStart.z + boxSize.z;

    cl_float3 norm[3];
//    = {(cl_float3)(1,0,0), (cl_float3)(0,1,0), (cl_float3)(0,0,1) };
    norm[0].x = 1, norm[0].y = 0, norm[0].z = 0;
    norm[1].x = 0, norm[1].y = 1, norm[1].z = 0;
    norm[2].x = 0, norm[2].y = 0, norm[2].z = 1;

    cl_float4 range[3];
    range[0].x = start.y, range[0].y = end.y, range[0].z = start.z, range[0].w = end.z;
     range[1].x = start.x, range[1].y = end.x, range[1].z = start.z, range[1].w = end.z;
      range[2].x = start.x, range[2].y = end.x, range[2].z = start.y, range[2].w = end.y;
    float t[6];
    t[0] = doIntersectPlane( start, norm[0], eyePos, d );
    t[1] = doIntersectPlane( end, norm[0], eyePos, d );
    t[2] = doIntersectPlane( start, norm[1], eyePos, d );
    t[3] = doIntersectPlane( end, norm[1], eyePos, d );
    t[4] = doIntersectPlane( start, norm[2], eyePos, d );
    t[5] = doIntersectPlane( end, norm[2], eyePos, d );

    cl_float4 intersectPoint[6];
    float min = POS_INF;
    float max = -POS_INF;
    for( int i = 0; i < 6; i++ )
    {
        intersectPoint[i].x = eyePos.x + t[i]*d.x;
        intersectPoint[i].y = eyePos.y + t[i]*d.y;
        intersectPoint[i].z = eyePos.z + t[i]*d.z;
        intersectPoint[i].w = eyePos.w + t[i]*d.w;
        if( t[i] > 0 && checkRange( intersectPoint[i], range[i/2], i/2 ) && min > t[i] )
        {
            min = t[i];
            *near = t[i];
        }
        if( t[i] > 0 && checkRange( intersectPoint[i], range[i/2], i/2 ) && max < t[i] )
        {
            max = t[i];
            *far = t[i];
        }
    }
}

bool boxContain( const cl_float3 start, const cl_float3 size, const cl_float3 pos )
{
    cl_float3 v1 = start;
    cl_float3 v2;
    v2.x  = start.x  + size.x;
    v2.y  = start.y  + size.y;
    v2.z  = start.z  + size.z;
        return ((pos.x >= v1.x) && (pos.x <= v2.x) &&
                (pos.y >= v1.y) && (pos.y <= v2.y) &&
                (pos.z >= v1.z) && (pos.z <= v2.z));
}

cl_float4 add4( cl_float4 v1, cl_float4 v2 )
{
    cl_float4 result;
    result.x = v1.x + v2.x;
    result.y = v1.y + v2.y;
    result.z = v1.z + v2.z;
    result.w = v1.w + v2.w;
    return result;
}

cl_float3 add3( cl_float3 v1, cl_float3 v2 )
{
    cl_float3 result;
    result.x = v1.x + v2.x;
    result.y = v1.y + v2.y;
    result.z = v1.z + v2.z;
    return result;
}

cl_float3 mult3( float s,  cl_float3 v )
{
    cl_float3 result;
    result.x = s*v.x;
    result.y = s*v.y;
    result.z = s*v.z;
    return result;
}

cl_float4 mult4( float s,  cl_float4 v )
{
    cl_float4 result;
    result.x = s*v.x;
    result.y = s*v.y;
    result.z = s*v.z;
    result.w = s*v.w;
    return result;
}

*/
REAL
intersect( const Vector4& eyePos,
           const QVector<SceneObject>& objects,
           const Vector4& d,
           int& objectIndex,
           int& faceIndex,
           KdTree* tree,
           AABB extends,
           bool refract
           )
{
        REAL minT = POS_INF;
        REAL resultT = -1;
        int tempFaceIndex = -1;
        if( settings.useKdTree && tree && !refract )
        {
            assert( EQ( eyePos.w, 1) && EQ(d.w, 0) );

            REAL near, far;
            doIntersectRayKdBox( eyePos, d, near, far, extends );
            if( near <= 0&&far <= 0 )
                return -1;

            QVector<KdTreeNode*> nodeStack;
            KdTreeNode* current = tree->getRoot();
            while( current )
            {
                while( !current->isLeaf() )
                {
                    AABB curBox = current->getAABB();
                    REAL near, far;
                    doIntersectRayKdBox( eyePos, d, near, far, curBox );
                    int axis = current->getAxis();
                    float splitPos = current->getSplitPos();
                    if( near == far )  // inside the box
                        near = 0;
                    Vector4 nearPos = eyePos + d*near;
                    Vector4 farPos = eyePos + d*far;
                    if( nearPos.data[axis] <= splitPos  )
                    {
                        if( farPos.data[axis] <= splitPos )
                        {
                            current = current->getLeft();
                            continue;
                        }
                        KdTreeNode* right = current->getRight();
                        current = current->getLeft();

                        // Preserve the right
                        nodeStack.push_back( right );
                    }
                    else
                    {
                        if( farPos.data[axis] > splitPos )
                        {
                            current=current->getRight();
                            continue;
                        }
                        KdTreeNode* left = current->getLeft();
                        current = current->getRight();
                        nodeStack.push_back( left );
                    }
                }

                // Then we found an near leaf, find if there is intersect
                ObjectNode* objList = current->getObjectList();
                minT = POS_INF;
                while( objList )
                {
                    SceneObject* curObj =objList->getObject();
                    Matrix4x4 invCompMat = (*curObj).m_invTransform;

                    Vector4 eyePosObjSpace = invCompMat*eyePos;
                    Vector4 dObjSpace = invCompMat*d;

                    REAL t = doIntersect( *curObj, eyePosObjSpace, dObjSpace, tempFaceIndex);
                    if( t>0 && t < minT )
                    {
                        minT = t;
                        objectIndex = curObj->m_arrayID;
                        faceIndex = tempFaceIndex;
                    }
                    objList = objList->getNext();
                }
                Vector4 dst = (eyePos + minT*d);
                // Here we need to enlarge the bounding box a little bit
                AABB curBox = AABB( current->getAABB().getPos() - Vector3( EPSILON, EPSILON, EPSILON ),
                               current->getAABB().getSize() + 2*Vector3( EPSILON, EPSILON, EPSILON ));
                if( minT != POS_INF && curBox.contains(Vector3(dst.x, dst.y, dst.z ) ) )
                {
                    resultT = minT;
                    break;
                }
                // Else we need to get one node from the stack
                if( nodeStack.empty() )
                {
                    // No more nodes, meaning there is no intersect
                    break;
                }
                else
                {
                    current = nodeStack.at(nodeStack.size()-1);
                    nodeStack.pop_back();
                }
            }
            /**
                GPU code, preserve for future test
              **/
            /*
            float near, far;
            KdTreeNodeHost root = kdnode_test[0];
            cl_float4 eye4;
            eye4.x = eyePos.x;
            eye4.y = eyePos.y;
            eye4.z = eyePos.z;
            eye4.w = eyePos.w;
            cl_float4 d4;
            d4.x = d.x;
            d4.y = d.y;
            d4.z = d.z;
            d4.w = d.w;
            doIntersectRayKdBox2( eye4, d4, &near, &far, root.boxBegin, root.boxSize );
            if( near <= 0 && far <= 0 )
                return -1;
        //    else
         //      return 1;
            int nodeStack[1024];
            int stackTop = 0;
            int nextIndex = 0;

            while( nextIndex != -1 )
            {
                KdTreeNodeHost current = kdnode_test[nextIndex];

                while( !current.leaf )
                {
                    cl_float3 curBoxStart = current.boxBegin;
                    cl_float3 curBoxSize = current.boxSize;
                    float near, far;
                    doIntersectRayKdBox2( eye4, d4, &near, &far, curBoxStart, curBoxSize );
                    int axis = current.axis;
                    float splitPos = current.split;
                    if( near == far )  // inside the box
                        near = 0;
                    cl_float4 nearPos = add4(eye4, mult4(near, d4));
                    cl_float4 farPos = add4(eye4, mult4(far, d4));
                    if( getAxisElem4(nearPos, axis) <= splitPos  )
                    {
                        if( getAxisElem4(farPos, axis) <= splitPos )
                        {
                            //nextIndex = current.leftIndex;
                            current = kdnode_test[current.leftIndex];
                            continue;
                        }
                        nodeStack[stackTop++] = current.rightIndex;
                        current = kdnode_test[current.leftIndex];

                        // Preserve the right

                    }
                    else
                    {
                        if( getAxisElem4(farPos, axis) > splitPos )
                        {
                         //   nextIndex = current.rightIndex;
                            current = kdnode_test[current.rightIndex];
                            continue;
                        }
                        //KdTreeNodeHost left = kdnode_test[current.leftIndex];
                        nodeStack[stackTop++] = current.leftIndex;
                        current = kdnode_test[current.rightIndex];

                    }
                }

                // Then we found an near leaf, find if there is intersect
                int objIndex = current.objIndex;

                minT = POS_INF;

                while( objIndex != -1 )
                {
                    ObjectNodeHost objList = objnode_test[objIndex];
                    int sceneObjIndex = objList.objectIndex;

                    const SceneObject& curSceneObj = objects[sceneObjIndex];

                    Matrix4x4 invCompMat = curSceneObj.m_invTransform;

                    Vector4 eyePosObjSpace = invCompMat*eyePos;
                    Vector4 dObjSpace = invCompMat*d;

                    REAL t = doIntersect( curSceneObj, eyePosObjSpace, dObjSpace, tempFaceIndex);

                    if( t>0 && t < minT )
                    {
                        minT = t;
                        objectIndex = sceneObjIndex;
                        faceIndex = tempFaceIndex;
                    }
                    objIndex = objList.nextNodeIndex;
                  }


                //cl_float4 dst = add4(eye4,  mult4(minT, d4));
                Vector4 dst = eyePos + minT*d;
                // Here we need to enlarge the bounding box a little bit
                cl_float3 ep1;
                ep1.x = -EPSILON; ep1.y = -EPSILON; ep1.z = -EPSILON;
                cl_float3 ep2;
                ep2.x = 2*EPSILON; ep2.y = 2*EPSILON; ep2.z = 2*EPSILON;
                cl_float3 boxStart = add3(current.boxBegin , ep1);
                cl_float3 boxSize = add3(current.boxSize, ep2 );
                cl_float3 dst3;
                dst3.x = dst.x;
                dst3.y = dst.y;
                dst3.z = dst.z;

                if( minT != POS_INF && boxContain( boxStart, boxSize, dst3 ) )
                {
                    resultT = minT;
                    //resultT = 1;
                    break;
                }
                // Else we need to get one node from the stack
                if( stackTop == 0 )
                {
                    // No more nodes, meaning there is no intersect
                    int a = 0;
                    break;
                }
                else
                {
                    nextIndex = nodeStack[--stackTop];
                }
            }*/
        }
        else
        {
            for( int i = 0; i < objects.size(); i++ )
            {
                const SceneObject& curObj = objects[i];
                Matrix4x4 invCompMat = curObj.m_invTransform;

                Vector4 eyePosObjSpace = invCompMat*eyePos;
                Vector4 dObjSpace = invCompMat*d;

                REAL t = doIntersect( curObj, eyePosObjSpace, dObjSpace, tempFaceIndex);
                if( t>0 && t < minT )
                {
                    minT = t;
                    objectIndex = i;
                    faceIndex = tempFaceIndex;
                }
            }
            if( minT != POS_INF  )
            {
                resultT = minT;
            }
        }
        return resultT;
}
Пример #8
0
bool disque_job::init(const redis_result& rr)
{
	size_t n;
	const redis_result** children = rr.get_children(&n);
	if (n == 0)
		return false;
	if (n % 2 != 0)
		return false;

	string name;
	for (size_t i = 0; i < n;)
	{
		const redis_result* r1 = children[i];
		i++;
		const redis_result* r2 = children[i];
		i++;
		if (r1->get_type() != REDIS_RESULT_STRING)
			continue;
		name.clear();
		r1->argv_to_string(name);
		if (name.empty())
			continue;

		redis_result_t type = r2->get_type();

#define EQ(x, y) !strcasecmp((x).c_str(), (y))
#define IS_NUMBER(x) (x) == REDIS_RESULT_INTEGER
#define IS_STRING(x) (x) == REDIS_RESULT_STRING
#define IS_ARRAY(x)  (x) == REDIS_RESULT_ARRAY

		if (EQ(name, "id") && IS_STRING(type))
			r2->argv_to_string(id_);
		else if (EQ(name, "queue") && IS_STRING(type))
			r2->argv_to_string(queue_);
		else if (EQ(name, "state") && IS_STRING(type))
			r2->argv_to_string(state_);
		else if (EQ(name, "repl") && IS_NUMBER(type))
			repl_ = r2->get_integer();
		else if (EQ(name, "ttl") && IS_NUMBER(type))
			ttl_ = r2->get_integer();
		else if (EQ(name, "ctime") && IS_NUMBER(type))
			ctime_ = r2->get_integer64();
		else if (EQ(name, "delay") && IS_NUMBER(type))
			delay_ = r2->get_integer();
		else if (EQ(name, "retry") && IS_NUMBER(type))
			retry_ = r2->get_integer();
		else if (EQ(name, "nodes-delivered") && IS_ARRAY(type))
			set_nodes_delivered(*r2);
		else if (EQ(name, "nodes-confirmed") && IS_ARRAY(type))
			set_nodes_confirmed(*r2);
		else if (EQ(name, "next-requeue-within") && IS_NUMBER(type))
			next_requeue_within_ = r2->get_integer();
		else if (EQ(name, "next-awake-within") && IS_NUMBER(type))
			next_awake_within_ = r2->get_integer();
		else if (EQ(name, "body") && IS_STRING(type))
			r2->argv_to_string(body_);
	}

	return true;
}
Пример #9
0
static json_t *
lisp_to_json_toplevel_1 (Lisp_Object lisp)
{
  json_t *json;
  ptrdiff_t count;

  if (VECTORP (lisp))
    {
      ptrdiff_t size = ASIZE (lisp);
      json = json_check (json_array ());
      count = SPECPDL_INDEX ();
      record_unwind_protect_ptr (json_release_object, json);
      for (ptrdiff_t i = 0; i < size; ++i)
        {
          int status
            = json_array_append_new (json, lisp_to_json (AREF (lisp, i)));
          if (status == -1)
            json_out_of_memory ();
        }
      eassert (json_array_size (json) == size);
    }
  else if (HASH_TABLE_P (lisp))
    {
      struct Lisp_Hash_Table *h = XHASH_TABLE (lisp);
      json = json_check (json_object ());
      count = SPECPDL_INDEX ();
      record_unwind_protect_ptr (json_release_object, json);
      for (ptrdiff_t i = 0; i < HASH_TABLE_SIZE (h); ++i)
        if (!NILP (HASH_HASH (h, i)))
          {
            Lisp_Object key = json_encode (HASH_KEY (h, i));
            /* We can't specify the length, so the string must be
               null-terminated.  */
            check_string_without_embedded_nulls (key);
            const char *key_str = SSDATA (key);
            /* Reject duplicate keys.  These are possible if the hash
               table test is not `equal'.  */
            if (json_object_get (json, key_str) != NULL)
              wrong_type_argument (Qjson_value_p, lisp);
            int status = json_object_set_new (json, key_str,
                                              lisp_to_json (HASH_VALUE (h, i)));
            if (status == -1)
              {
                /* A failure can be caused either by an invalid key or
                   by low memory.  */
                json_check_utf8 (key);
                json_out_of_memory ();
              }
          }
    }
  else if (NILP (lisp))
    return json_check (json_object ());
  else if (CONSP (lisp))
    {
      Lisp_Object tail = lisp;
      json = json_check (json_object ());
      count = SPECPDL_INDEX ();
      record_unwind_protect_ptr (json_release_object, json);
      bool is_plist = !CONSP (XCAR (tail));
      FOR_EACH_TAIL (tail)
        {
          const char *key_str;
          Lisp_Object value;
          Lisp_Object key_symbol;
          if (is_plist)
            {
              key_symbol = XCAR (tail);
              tail = XCDR (tail);
              CHECK_CONS (tail);
              value = XCAR (tail);
              if (EQ (tail, li.tortoise)) circular_list (lisp);
            }
          else
            {
              Lisp_Object pair = XCAR (tail);
              CHECK_CONS (pair);
              key_symbol = XCAR (pair);
              value = XCDR (pair);
            }
          CHECK_SYMBOL (key_symbol);
          Lisp_Object key = SYMBOL_NAME (key_symbol);
          /* We can't specify the length, so the string must be
             null-terminated.  */
          check_string_without_embedded_nulls (key);
          key_str = SSDATA (key);
          /* In plists, ensure leading ":" in keys is stripped.  It
             will be reconstructed later in `json_to_lisp'.*/
          if (is_plist && ':' == key_str[0] && key_str[1])
            {
              key_str = &key_str[1];
            }
          /* Only add element if key is not already present.  */
          if (json_object_get (json, key_str) == NULL)
            {
              int status
                = json_object_set_new (json, key_str, lisp_to_json (value));
              if (status == -1)
                json_out_of_memory ();
            }
        }
      CHECK_LIST_END (tail, lisp);
    }
  else
Пример #10
0
static void
setup_config (void)
{
  const char *coding_name;
  const char *cp;
  char *end;
  int slen;
  Lisp_Object coding_system;
  Lisp_Object dos_coding_system;

  CHECK_SYMBOL (Vselection_coding_system);

  coding_system = NILP (Vnext_selection_coding_system) ?
    Vselection_coding_system : Vnext_selection_coding_system;

  dos_coding_system = validate_coding_system (coding_system);
  if (NILP (dos_coding_system))
    Fsignal (Qerror,
	     list2 (build_string ("Coding system is invalid or doesn't have "
				  "an eol variant for dos line ends"),
		    coding_system));

  /* Check if we have it cached */
  if (!NILP (cfg_coding_system)
      && EQ (cfg_coding_system, dos_coding_system))
    return;
  cfg_coding_system = dos_coding_system;

  /* Set some sensible fallbacks */
  cfg_codepage = ANSICP;
  cfg_lcid = LOCALE_NEUTRAL;
  cfg_clipboard_type = CF_TEXT;

  /* Interpret the coding system symbol name */
  coding_name = SDATA (SYMBOL_NAME (cfg_coding_system));

  /* "(.*-)?utf-16.*" -> CF_UNICODETEXT */
  cp = strstr (coding_name, "utf-16");
  if (cp != NULL && (cp == coding_name || cp[-1] == '-'))
    {
      cfg_clipboard_type = CF_UNICODETEXT;
      return;
    }

  /* "cp[0-9]+.*" or "windows-[0-9]+.*" -> CF_TEXT or CF_OEMTEXT */
  slen = strlen (coding_name);
  if (slen >= 4 && coding_name[0] == 'c' && coding_name[1] == 'p')
    cp = coding_name + 2;
  else if (slen >= 10 && memcmp (coding_name, "windows-", 8) == 0)
    cp = coding_name + 8;
  else
    return;

  end = (char*)cp;
  cfg_codepage = strtol (cp, &end, 10);

  /* Error return from strtol() or number of digits < 2 -> Restore the
     default and drop it. */
  if (cfg_codepage == 0 || (end-cp) < 2 )
    {
      cfg_codepage = ANSICP;
      return;
    }

  /* Is it the currently active system default? */
  if (cfg_codepage == ANSICP)
    {
      /* cfg_clipboard_type = CF_TEXT; */
      return;
    }
  if (cfg_codepage == OEMCP)
    {
      cfg_clipboard_type = CF_OEMTEXT;
      return;
    }

  /* Else determine a suitable locale the hard way. */
  EnumSystemLocales (enum_locale_callback, LCID_INSTALLED);
}
Пример #11
0
static int
do_mouse_event (MOUSE_EVENT_RECORD *event,
		struct input_event *emacs_ev)
{
  static DWORD button_state = 0;
  static Lisp_Object last_mouse_window;
  DWORD but_change, mask;
  int i;

  if (event->dwEventFlags == MOUSE_MOVED)
    {
      FRAME_PTR f = SELECTED_FRAME ();
      Mouse_HLInfo *hlinfo = MOUSE_HL_INFO (f);
      int mx = event->dwMousePosition.X, my = event->dwMousePosition.Y;

      mouse_moved_to (mx, my);

      if (f->mouse_moved)
	{
	  if (hlinfo->mouse_face_hidden)
	    {
	      hlinfo->mouse_face_hidden = 0;
	      clear_mouse_face (hlinfo);
	    }

	  /* Generate SELECT_WINDOW_EVENTs when needed.  */
	  if (!NILP (Vmouse_autoselect_window))
	    {
	      Lisp_Object mouse_window = window_from_coordinates (f, mx, my,
								  0, 0);
	      /* A window will be selected only when it is not
		 selected now, and the last mouse movement event was
		 not in it.  A minibuffer window will be selected iff
		 it is active.  */
	      if (WINDOWP (mouse_window)
		  && !EQ (mouse_window, last_mouse_window)
		  && !EQ (mouse_window, selected_window))
		{
		  struct input_event event;

		  EVENT_INIT (event);
		  event.kind = SELECT_WINDOW_EVENT;
		  event.frame_or_window = mouse_window;
		  event.arg = Qnil;
		  event.timestamp = movement_time;
		  kbd_buffer_store_event (&event);
		}
	      last_mouse_window = mouse_window;
	    }
	  else
	    last_mouse_window = Qnil;

	  previous_help_echo_string = help_echo_string;
	  help_echo_string = help_echo_object = help_echo_window = Qnil;
	  help_echo_pos = -1;
	  note_mouse_highlight (f, mx, my);
	  /* If the contents of the global variable help_echo has
	     changed (inside note_mouse_highlight), generate a HELP_EVENT.  */
	  if (!NILP (help_echo_string) || !NILP (previous_help_echo_string))
	    gen_help_event (help_echo_string, selected_frame, help_echo_window,
			    help_echo_object, help_echo_pos);
	}
      return 0;
    }

  /* It looks like the console code sends us a mouse event with
     dwButtonState == 0 when a window is activated.  Ignore this case.  */
  if (event->dwButtonState == button_state)
    return 0;

  emacs_ev->kind = MOUSE_CLICK_EVENT;

  /* Find out what button has changed state since the last button event.  */
  but_change = button_state ^ event->dwButtonState;
  mask = 1;
  for (i = 0; mask; i++, mask <<= 1)
    if (but_change & mask)
      {
        if (i < NUM_TRANSLATED_MOUSE_BUTTONS)
          emacs_ev->code = emacs_button_translation[i];
        else
          emacs_ev->code = i;
	break;
      }

  button_state = event->dwButtonState;
  emacs_ev->timestamp = GetTickCount ();
  emacs_ev->modifiers = w32_kbd_mods_to_emacs (event->dwControlKeyState, 0) |
    ((event->dwButtonState & mask) ? down_modifier : up_modifier);

  XSETFASTINT (emacs_ev->x, event->dwMousePosition.X);
  XSETFASTINT (emacs_ev->y, event->dwMousePosition.Y);
/* for Mule 2.2 (Based on Emacs 19.28 */
#ifdef MULE
  XSET (emacs_ev->frame_or_window, Lisp_Frame, get_frame ());
#else
  XSETFRAME (emacs_ev->frame_or_window, get_frame ());
#endif

  return 1;
}
Пример #12
0
int
i_may_read_forum(const unsigned int forum)
{
    room_t quad;

    read_forum(forum, &quad);

    if (forum == DOCKING_BAY_FORUM)
	return 1;

    if (forum >= MAXQUADS)	/* Uhh-ohh.. */
	return 0;

    if (usersupp->priv & PRIV_DELETED)
	return 0;

    if (usersupp->priv & PRIV_TWIT) {
	if (forum == CURSE_FORUM || forum == MAIL_FORUM)
	    return 1;
	else
	    return 0;
    }
    if (usersupp->priv >= PRIV_WIZARD)
	return 1;		/* emps can read anywhere */

    else if (forum == GARBAGE_FORUM || forum == EMPEROR_FORUM)
	return 0;		/* only emps in Garbage & Emps */

    else if (usersupp->priv >= PRIV_SYSOP)
	return 1;

    else if (forum == YELL_FORUM || forum == SYSOP_FORUM)
	return 0;		/* Only Sysops and higher */

    /* don't allow guest in mail */
    if (forum == MAIL_FORUM && EQ(usersupp->username, "Guest"))
	return 0;

    else if ((forum == QL_FORUM) && !(usersupp->flags & US_ROOMAIDE))
	return 0;

    else if ((forum == HT_FORUM) && !(usersupp->flags & US_GUIDE))
	return 0;

    else if ((forum == POLICY_FORUM) && !(usersupp->priv & PRIV_PREFERRED))
	return 0;

    else if ((forum == LOWER_ADMIN_FORUM) &&
	     !(usersupp->flags & (US_ROOMAIDE | US_GUIDE)))
	return 0;

    else if (!(quad.flags & QR_INUSE))
	return 0;

    else if (usersupp->generation[forum] == (-5))	/* kicked */
	return 0;

    else if (forum == CURSE_FORUM && (!(usersupp->priv & PRIV_TWIT)))
	return 0;

    else if ((quad.flags & QR_PRIVATE) && quad.generation !=
	     usersupp->generation[forum])
	return 0;

    else if ((quad.flags & QR_GUESSNAME) && quad.generation !=
	     usersupp->generation[forum])
	return 0;

    return 1;
}
Пример #13
0
char *
known_rooms_list(const user_t * user, int long_k_list)
{

    int quad_num, i;
    int unseen_ctr = 0, zapped_ctr = 0;
    char room_type[8], line[200];
    room_t scratch;
    char *textPtr;



    curr_line = 2;
    line_total = -1;		/* don't want any percentages at the -- more -- */

    textPtr = (char *) xmalloc(200 * (MAXQUADS + CATEGORIES));
    strcpy(textPtr, "");

    for (i = 0; i < CATEGORIES; i++) {

	sprintf(line, "\n%s%s%s%s:\n\n", BOLD, YELLOW, fish[i], WHITE);
	strcat(textPtr, line);

	for (quad_num = 0; quad_num < MAXQUADS; quad_num++) {

	    scratch = readquad(quad_num);

	    /* match all these conditions no matter what function
	     */
	    if (!i_may_read_forum(quad_num))
		continue;
	    if (!(scratch.flags & QR_INUSE))
		continue;
	    if (!long_k_list)
		if (is_zapped(quad_num, &scratch))
		    continue;

	    if (EQ(scratch.category, fish[i])) {

		if (((scratch.flags & QR_ANONONLY) || (scratch.flags & QR_ANON2))
		    && (scratch.flags & QR_PRIVATE)) {
		    sprintf(room_type, "%sA%sI", ANON_COL, PRIVATE_COL);
		} else if (scratch.flags & (QR_ANONONLY | QR_ANON2)) {
		    sprintf(room_type, "%sA ", ANON_COL);
		} else if (scratch.flags & QR_PRIVATE) {
		    sprintf(room_type, " %sI", PRIVATE_COL);
		} else if (scratch.flags & QR_GUESSNAME) {
		    sprintf(room_type, " %sG", GUESSNAME_COL);
		} else {
		    sprintf(room_type, "  ");
		}

		sprintf(line, "    \1w%3d %s \1g%-36s", quad_num, room_type, scratch.name);
		strcat(textPtr, line);

		if (user->forget[quad_num] == scratch.generation) {
		    sprintf(line, "  \1w[\1rZapped\1w]\n");
		    zapped_ctr++;
		} else {
		    if (user->lastseen[quad_num] == scratch.highest)
			sprintf(line, "  \1w[\1c%ld \1gmessages\1w]\n", scratch.highest - scratch.lowest);
		    else {
			sprintf(line, "  \1w[\1c%ld \1gmessages, \1c%ld \1gunread\1w]\n", scratch.highest, scratch.highest - user->lastseen[quad_num]);
			unseen_ctr++;
		    }
		}
		strcat(textPtr, line);
	    }
	}
    }
    sprintf(line, "\n\1f\1g           You have \1c%d \1g%s with unread messages", unseen_ctr,
     (unseen_ctr == 1) ? config.forum : config.forum_pl );

    if (long_k_list)
	sprintf(line, ".\n");
    else
	sprintf(line, " and \1c%d \1gzapped %s.\n", zapped_ctr, (zapped_ctr == 1) ? config.forum : config.forum_pl);

    strcat(textPtr, line);
    return textPtr;
}
Пример #14
0
 extern void
 test_point()
    {
    if( ! EQ( 64.3, 64.3 ) ) printf(" error EQ\n");
    if( ! NE( 64.3, 30.4 ) ) printf(" error NE\n");

    if(   pnt_EQ( 64.3, 30.4, 67.3, 40.4 ) ) printf(" error pnt_EQ 1\n");
    if( ! pnt_EQ( 64.3, 30.4, 64.3, 30.4 ) ) printf(" error pnt_EQ 2\n");

    pnt_setbox( -65.0, 100.0, -60.0, 105.0 );
    if( ! pnt_BOX( -65.0, 103.0 ) ) printf(" error pnt_BOX 1\n");
    if( ! pnt_BOX( -63.0, 100.0 ) ) printf(" error pnt_BOX 2\n");
    if( ! pnt_BOX( -60.0, 103.0 ) ) printf(" error pnt_BOX 3\n");
    if( ! pnt_BOX( -63.0, 105.0 ) ) printf(" error pnt_BOX 4\n");

    pnt_setseuil( 0.000001 );
    if( ! pnt_almostEQ( -5.0,3.0,-5.0,3.0 ) ) printf(" error pnt_almostEQ 1\n");
    if(   pnt_almostEQ( -5.0,3.0,-4.0,3.0 ) ) printf(" error pnt_almostEQ 2\n");
    if(   pnt_almostEQ( -5.0,3.0,-5.0,4.0 ) ) printf(" error pnt_almostEQ 3\n");
    pnt_setseuil( 0.5 );
    if( ! pnt_almostEQ( -5.0,3.0,-4.7,3.0 ) ) printf(" error pnt_almostEQ 4\n");
    if( ! pnt_almostEQ( -5.0,3.0,-5.3,3.0 ) ) printf(" error pnt_almostEQ 5\n");
    if( ! pnt_almostEQ( -5.0,3.0,-5.0,3.3 ) ) printf(" error pnt_almostEQ 6\n");
    if( ! pnt_almostEQ( -5.0,3.0,-5.0,2.7 ) ) printf(" error pnt_almostEQ 7\n");

    if(!pnt_almostEQ( 3.0,-180.0,3.0,179.7) ) printf(" error pnt_almostEQ 8\n");
    if(!pnt_almostEQ( 3.0,180.0,3.0,-179.7) ) printf(" error pnt_almostEQ 9\n");

    pnt_setseuil( 0.000001 );
    if(!pnt_almostEQ( 3.0,-180.0,3.0,179.999999) )
                                              printf(" error pnt_almostEQ a\n");
    if(!pnt_almostEQ( 3.0,180.0,3.0,-179.999999) )
                                              printf(" error pnt_almostEQ b\n");

    pnt_setbox( -65.0, 100.0, -60.0, 105.0 );
    pnt_setseuil( 0.0001 );
    if( ! pnt_almostBOX( -65.0, 103.0 ) ) printf(" error pnt_almostBOX 1\n");
    if( ! pnt_almostBOX( -63.0, 100.0 ) ) printf(" error pnt_almostBOX 2\n");
    if( ! pnt_almostBOX( -60.0, 103.0 ) ) printf(" error pnt_almostBOX 3\n");
    if( ! pnt_almostBOX( -63.0, 105.0 ) ) printf(" error pnt_almostBOX 4\n");

    pnt_setbox( -65.0, 100.0, -60.0, 105.0 );
    pnt_setseuil( 0.5 );
    if( ! pnt_almostBOX( -65.3, 103.0 ) ) printf(" error pnt_almostBOX 1\n");
    if( ! pnt_almostBOX( -64.7, 103.0 ) ) printf(" error pnt_almostBOX 2\n");
    if( ! pnt_almostBOX( -63.0, 104.7 ) ) printf(" error pnt_almostBOX 3\n");
    if( ! pnt_almostBOX( -63.0, 105.3 ) ) printf(" error pnt_almostBOX 4\n");
    if( ! pnt_almostBOX( -60.3, 103.0 ) ) printf(" error pnt_almostBOX 5\n");
    if( ! pnt_almostBOX( -59.7, 103.0 ) ) printf(" error pnt_almostBOX 6\n");
    if( ! pnt_almostBOX( -63.0,  99.7 ) ) printf(" error pnt_almostBOX 7\n");
    if( ! pnt_almostBOX( -63.0, 100.3 ) ) printf(" error pnt_almostBOX 8\n");

    pnt_setbox( -65.0, -180.0, -60.0, -175.0 );
    if( ! pnt_almostBOX( -63.0, 179.8 ) ) printf(" error pnt_almostBOX 9\n");
    if( ! pnt_almostBOX( -63.0,-179.8 ) ) printf(" error pnt_almostBOX a\n");
    pnt_setbox( -65.0,  175.0, -60.0,  180.0 );
    if( ! pnt_almostBOX( -63.0, 179.8 ) ) printf(" error pnt_almostBOX b\n");
    if( ! pnt_almostBOX( -63.0,-179.8 ) ) printf(" error pnt_almostBOX c\n");

    {
    float qlat =  46.802071;
    float qlon = -71.244926;

    float mlat =  45.541019;
    float mlon = -73.653526;

    if( pnt_distance(mlat,mlon,qlat,qlon) !=  232492.468750 )
        printf(" error pnt_distance mtl que \n" );
    if( pnt_distance(qlat,qlon,mlat,mlon) !=  232492.468750 )
        printf(" error pnt_distance que mtl \n" );
    }
   }
Пример #15
0
Lisp_Object
directory_files_internal (Lisp_Object directory, Lisp_Object full, Lisp_Object match, Lisp_Object nosort, int attrs, Lisp_Object id_format)
{
  DIR *d;
  int directory_nbytes;
  Lisp_Object list, dirfilename, encoded_directory;
  struct re_pattern_buffer *bufp = NULL;
  int needsep = 0;
  int count = SPECPDL_INDEX ();
  struct gcpro gcpro1, gcpro2, gcpro3, gcpro4, gcpro5;
  DIRENTRY *dp;
#ifdef WINDOWSNT
  Lisp_Object w32_save = Qnil;
#endif

  /* Because of file name handlers, these functions might call
     Ffuncall, and cause a GC.  */
  list = encoded_directory = dirfilename = Qnil;
  GCPRO5 (match, directory, list, dirfilename, encoded_directory);
  dirfilename = Fdirectory_file_name (directory);

  if (!NILP (match))
    {
      CHECK_STRING (match);

      /* MATCH might be a flawed regular expression.  Rather than
	 catching and signaling our own errors, we just call
	 compile_pattern to do the work for us.  */
      /* Pass 1 for the MULTIBYTE arg
	 because we do make multibyte strings if the contents warrant.  */
# ifdef WINDOWSNT
      /* Windows users want case-insensitive wildcards.  */
      bufp = compile_pattern (match, 0,
			      buffer_defaults.case_canon_table, 0, 1);
# else	/* !WINDOWSNT */
      bufp = compile_pattern (match, 0, Qnil, 0, 1);
# endif	 /* !WINDOWSNT */
    }

  /* Note: ENCODE_FILE and DECODE_FILE can GC because they can run
     run_pre_post_conversion_on_str which calls Lisp directly and
     indirectly.  */
  if (STRING_MULTIBYTE (dirfilename))
    dirfilename = ENCODE_FILE (dirfilename);
  encoded_directory = (STRING_MULTIBYTE (directory)
		       ? ENCODE_FILE (directory) : directory);

  /* Now *bufp is the compiled form of MATCH; don't call anything
     which might compile a new regexp until we're done with the loop!  */

  BLOCK_INPUT;
  d = opendir (SDATA (dirfilename));
  UNBLOCK_INPUT;
  if (d == NULL)
    report_file_error ("Opening directory", Fcons (directory, Qnil));

  /* Unfortunately, we can now invoke expand-file-name and
     file-attributes on filenames, both of which can throw, so we must
     do a proper unwind-protect.  */
  record_unwind_protect (directory_files_internal_unwind,
			 make_save_value (d, 0));

#ifdef WINDOWSNT
  if (attrs)
    {
      extern int is_slow_fs (const char *);

      /* Do this only once to avoid doing it (in w32.c:stat) for each
	 file in the directory, when we call Ffile_attributes below.  */
      record_unwind_protect (directory_files_internal_w32_unwind,
			     Vw32_get_true_file_attributes);
      w32_save = Vw32_get_true_file_attributes;
      if (EQ (Vw32_get_true_file_attributes, Qlocal))
	{
	  /* w32.c:stat will notice these bindings and avoid calling
	     GetDriveType for each file.  */
	  if (is_slow_fs (SDATA (dirfilename)))
	    Vw32_get_true_file_attributes = Qnil;
	  else
	    Vw32_get_true_file_attributes = Qt;
	}
    }
#endif

  directory_nbytes = SBYTES (directory);
  re_match_object = Qt;

  /* Decide whether we need to add a directory separator.  */
  if (directory_nbytes == 0
      || !IS_ANY_SEP (SREF (directory, directory_nbytes - 1)))
    needsep = 1;

  /* Loop reading blocks until EOF or error.  */
  for (;;)
    {
      errno = 0;
      dp = readdir (d);

      if (dp == NULL && (0
#ifdef EAGAIN
			 || errno == EAGAIN
#endif
#ifdef EINTR
			 || errno == EINTR
#endif
			 ))
	{ QUIT; continue; }

      if (dp == NULL)
	break;

      if (DIRENTRY_NONEMPTY (dp))
	{
	  int len;
	  int wanted = 0;
	  Lisp_Object name, finalname;
	  struct gcpro gcpro1, gcpro2;

	  len = NAMLEN (dp);
	  name = finalname = make_unibyte_string (dp->d_name, len);
	  GCPRO2 (finalname, name);

	  /* Note: DECODE_FILE can GC; it should protect its argument,
	     though.  */
	  name = DECODE_FILE (name);
	  len = SBYTES (name);

	  /* Now that we have unwind_protect in place, we might as well
             allow matching to be interrupted.  */
	  immediate_quit = 1;
	  QUIT;

	  if (NILP (match)
	      || (0 <= re_search (bufp, SDATA (name), len, 0, len, 0)))
	    wanted = 1;

	  immediate_quit = 0;

	  if (wanted)
	    {
	      if (!NILP (full))
		{
		  Lisp_Object fullname;
		  int nbytes = len + directory_nbytes + needsep;
		  int nchars;

		  fullname = make_uninit_multibyte_string (nbytes, nbytes);
		  memcpy (SDATA (fullname), SDATA (directory),
			  directory_nbytes);

		  if (needsep)
		    SSET (fullname, directory_nbytes, DIRECTORY_SEP);

		  memcpy (SDATA (fullname) + directory_nbytes + needsep,
			  SDATA (name), len);

		  nchars = chars_in_text (SDATA (fullname), nbytes);

		  /* Some bug somewhere.  */
		  if (nchars > nbytes)
		    abort ();

		  STRING_SET_CHARS (fullname, nchars);
		  if (nchars == nbytes)
		    STRING_SET_UNIBYTE (fullname);

		  finalname = fullname;
		}
	      else
		finalname = name;

	      if (attrs)
		{
		  /* Construct an expanded filename for the directory entry.
		     Use the decoded names for input to Ffile_attributes.  */
		  Lisp_Object decoded_fullname, fileattrs;
		  struct gcpro gcpro1, gcpro2;

		  decoded_fullname = fileattrs = Qnil;
		  GCPRO2 (decoded_fullname, fileattrs);

		  /* Both Fexpand_file_name and Ffile_attributes can GC.  */
		  decoded_fullname = Fexpand_file_name (name, directory);
		  fileattrs = Ffile_attributes (decoded_fullname, id_format);

		  list = Fcons (Fcons (finalname, fileattrs), list);
		  UNGCPRO;
		}
	      else
		list = Fcons (finalname, list);
	    }

	  UNGCPRO;
	}
    }

  BLOCK_INPUT;
  closedir (d);
  UNBLOCK_INPUT;
#ifdef WINDOWSNT
  if (attrs)
    Vw32_get_true_file_attributes = w32_save;
#endif

  /* Discard the unwind protect.  */
  specpdl_ptr = specpdl + count;

  if (NILP (nosort))
    list = Fsort (Fnreverse (list),
		  attrs ? Qfile_attributes_lessp : Qstring_lessp);

  RETURN_UNGCPRO (list);
}
Пример #16
0
int mps_lib_callback_register(const char *name, mps_lib_function_t f)
{
  if(NULL == name) {
    return MPS_RES_FAIL;
  }
  if(EQ(name, "mps_lib_get_EOF")) {
    mps_lib_callback_global.lib_get_EOF = (int(*)(void))f;
  } else if(EQ(name, "mps_lib_get_stderr")) {
    mps_lib_callback_global.lib_get_stderr = (mps_lib_FILE *(*)(void))f;
  } else if(EQ(name, "mps_lib_get_stdout")) {
    mps_lib_callback_global.lib_get_stdout = (mps_lib_FILE *(*)(void))f;
  } else if(EQ(name, "mps_lib_fputc")) {
    mps_lib_callback_global.lib_fputc = (int(*)(int, mps_lib_FILE *))f;
  } else if(EQ(name, "mps_lib_fputs")) {
    mps_lib_callback_global.lib_fputs =
      (int(*)(const char *, mps_lib_FILE *))f;
  } else if(EQ(name, "mps_lib_assert_fail")) {
    mps_lib_callback_global.lib_assert_fail = (void(*)(const char *))f;
  } else if(EQ(name, "mps_lib_memset")) {
    mps_lib_callback_global.lib_memset = (void *(*)(void *, int, size_t))f;
  } else if(EQ(name, "mps_lib_memcpy")) {
    mps_lib_callback_global.lib_memcpy =
      (void *(*)(void *, const void *, size_t))f;
  } else if(EQ(name, "mps_lib_memcmp")) {
    mps_lib_callback_global.lib_memcmp =
      (int(*)(const void *, const void *, size_t))f;
  } else if(EQ(name, "mps_clock")) {
    mps_lib_callback_global.clock = (mps_clock_t(*)(void))f;
  } else if(EQ(name, "mps_clocks_per_sec")) {
    mps_lib_callback_global.clocks_per_sec = (mps_clock_t(*)(void))f;
  } else if(EQ(name, "mps_lib_telemetry_control")) {
    mps_lib_callback_global.lib_telemetry_control =
      (unsigned long(*)(void))f;
  } else {
    return MPS_RES_UNIMPL;
  }
  return MPS_RES_OK;
}
Пример #17
0
int enif_is_identical(Eterm lhs, Eterm rhs)
{
    return EQ(lhs,rhs);
}
Пример #18
0
// this main function contains some
int main(int argc, char* argv[]){

    DynArr *dyn;
    dyn = createDynArr(2);

    printf("\n\nTesting addDynArr...\n");
    addDynArr(dyn, 3);
    addDynArr(dyn, 4);
    addDynArr(dyn, 10);
    addDynArr(dyn, 5);
    addDynArr(dyn, 6);

    printf("The array's content: [3,4,10,5,6]\n");
    assertTrue(EQ(getDynArr(dyn, 0), 3), "Test 1st element == 3");
    assertTrue(EQ(getDynArr(dyn, 1), 4), "Test 2nd element == 4");
    assertTrue(EQ(getDynArr(dyn, 2), 10), "Test 3rd element == 10");
    assertTrue(EQ(getDynArr(dyn, 3), 5), "Test 4th element == 5");
    assertTrue(EQ(getDynArr(dyn, 4), 6), "Test 5th element == 6");
    assertTrue(sizeDynArr(dyn) == 5, "Test size = 5");

    printf("\n\nTesting putDynArr...\nCalling putDynArr(dyn, 2, 7)\n");
    putDynArr(dyn, 2, 7);
    printf("The array's content: [3,4,7,5,6]\n");
    assertTrue(EQ(getDynArr(dyn, 2), 7), "Test 3rd element == 7");
    assertTrue(sizeDynArr(dyn) == 5, "Test size = 5");

    printf("\n\nTesting swapDynArr...\nCalling swapDynArr(dyn, 2, 4)\n");
    swapDynArr(dyn, 2, 4);
    printf("The array's content: [3,4,6,5,7]\n");
    assertTrue(EQ(getDynArr(dyn, 2), 6), "Test 3rd element == 6");
    assertTrue(EQ(getDynArr(dyn, 4), 7), "Test 5th element == 7");

    printf("\n\nTesting removeAtDynArr...\nCalling removeAtDynArr(dyn, 1)\n");
    removeAtDynArr(dyn, 1);
    printf("The array's content: [3,6,5,7]\n");
    assertTrue(EQ(getDynArr(dyn, 0), 3), "Test 1st element == 3");
    assertTrue(EQ(getDynArr(dyn, 3), 7), "Test 4th element == 7");
    assertTrue(sizeDynArr(dyn) == 4, "Test size = 4");

    printf("\n\nTesting stack interface...\n");
    printf("The stack's content: [3,6,5,7] <- top\n");
    assertTrue(!isEmptyDynArr(dyn), "Testing isEmptyDynArr");
    assertTrue(EQ(topDynArr(dyn), 7), "Test topDynArr == 7");

    popDynArr(dyn);
    printf("Poping...\nThe stack's content: [3,6,5] <- top\n");
    assertTrue(EQ(topDynArr(dyn), 5), "Test topDynArr == 5");

    pushDynArr(dyn, 9);
    printf("Pushing 9...\nThe stack's content: [3,6,5,9] <- top\n");
    assertTrue(EQ(topDynArr(dyn), 9), "Test topDynArr == 9");

    printf("\n\nTesting bag interface...\n");
    printf("The bag's content: [3,6,5,9]\n");
    assertTrue(containsDynArr(dyn, 3), "Test containing 3");
    assertTrue(containsDynArr(dyn, 6), "Test containing 6");
    assertTrue(containsDynArr(dyn, 5), "Test containing 5");
    assertTrue(containsDynArr(dyn, 9), "Test containing 9");
    assertTrue(!containsDynArr(dyn, 7), "Test not containing 7");

    removeDynArr(dyn, 3);
    printf("Removing 3...\nThe stack's content: [6,5,9]\n");
    assertTrue(!containsDynArr(dyn, 3), "Test not containing 3");

    return 0;
}
Пример #19
0
/*
 - slow - step through the string more deliberately
 */
static char *			/* where it ended */
slow(struct match *m, char *start, char *stop, sopno startst, sopno stopst)
{
	states st = m->st;
	states empty = m->empty;
	states tmp = m->tmp;
	char *p = start;
	int c = (start == m->beginp) ? OUT : *(start-1);
	int lastc;	/* previous c */
	int flagch;
	int i;
	char *matchp;	/* last p at which a match ended */

	AT("slow", start, stop, startst, stopst);
	CLEAR(st);
	SET1(st, startst);
	SP("sstart", st, *p);
	st = step(m->g, startst, stopst, st, NOTHING, st);
	matchp = NULL;
	for (;;) {
		/* next character */
		lastc = c;
		c = (p == m->endp) ? OUT : *p;

		/* is there an EOL and/or BOL between lastc and c? */
		flagch = '\0';
		i = 0;
		if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
				(lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
			flagch = BOL;
			i = m->g->nbol;
		}
		if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
				(c == OUT && !(m->eflags&REG_NOTEOL)) ) {
			flagch = (flagch == BOL) ? BOLEOL : EOL;
			i += m->g->neol;
		}
		if (i != 0) {
			for (; i > 0; i--)
				st = step(m->g, startst, stopst, st, flagch, st);
			SP("sboleol", st, c);
		}

		/* how about a word boundary? */
		if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
					(c != OUT && ISWORD(c)) ) {
			flagch = BOW;
		}
		if ( (lastc != OUT && ISWORD(lastc)) &&
				(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
			flagch = EOW;
		}
		if (flagch == BOW || flagch == EOW) {
			st = step(m->g, startst, stopst, st, flagch, st);
			SP("sboweow", st, c);
		}

		/* are we done? */
		if (ISSET(st, stopst))
			matchp = p;
		if (EQ(st, empty) || p == stop)
			break;		/* NOTE BREAK OUT */

		/* no, we must deal with this character */
		ASSIGN(tmp, st);
		ASSIGN(st, empty);
		assert(c != OUT);
		st = step(m->g, startst, stopst, tmp, c, st);
		SP("saft", st, c);
		assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
		p++;
	}

	return(matchp);
}
	int *stringToPtr_Classic(const char *str)
	{
		if (EQ("Up"))
			return &Gui::gui->np->JoystickHats[0];
		if (EQ("Down"))
			return &Gui::gui->np->JoystickHats[1];
		if (EQ("Left"))
			return &Gui::gui->np->JoystickHats[2];
		if (EQ("Right"))
			return &Gui::gui->np->JoystickHats[3];
		if (EQ("LAH"))
			return &Gui::gui->np->JoystickAxes[0];
		if (EQ("LAV"))
			return &Gui::gui->np->JoystickAxes[1];
		if (EQ("RAH"))
			return &Gui::gui->np->JoystickAxes[2];
		if (EQ("RAV"))
			return &Gui::gui->np->JoystickAxes[3];
		if (EQ("RA"))
			return &Gui::gui->np->JoystickAxes[4];
		if (EQ("LA"))
			return &Gui::gui->np->JoystickAxes[5];
		if (EQ("a"))
			return &Gui::gui->np->JoystickButtons[9];
		if (EQ("b"))
			return &Gui::gui->np->JoystickButtons[10];
		if (EQ("x"))
			return &Gui::gui->np->JoystickButtons[11];
		if (EQ("y"))
			return &Gui::gui->np->JoystickButtons[12];
		if (EQ("L"))
			return &Gui::gui->np->JoystickButtons[13];
		if (EQ("R"))
			return &Gui::gui->np->JoystickButtons[14];
		if (EQ("Zl"))
			return &Gui::gui->np->JoystickButtons[15];
		if (EQ("Zr"))
			return &Gui::gui->np->JoystickButtons[16];
		if (EQ("-"))
			return &Gui::gui->np->JoystickButtons[17];
		if (EQ("+"))
			return &Gui::gui->np->JoystickButtons[18];
		if (EQ("Home"))
			return &Gui::gui->np->JoystickButtons[19];

		/* Shound never happen! */
		panic("Illegal string %s\n", str);

		return NULL;
	}
Пример #21
0
/* This is the callback function for arriving signals from
   g_file_monitor.  It shall create a Lisp event, and put it into
   Emacs input queue.  */
static gboolean
dir_monitor_callback (GFileMonitor *monitor,
		      GFile *file,
		      GFile *other_file,
		      GFileMonitorEvent event_type,
		      gpointer user_data)
{
  Lisp_Object symbol, monitor_object, watch_object, flags;
  char *name = g_file_get_parse_name (file);
  char *oname = other_file ? g_file_get_parse_name (other_file) : NULL;

  /* Determine event symbol.  */
  switch (event_type)
    {
    case G_FILE_MONITOR_EVENT_CHANGED:
      symbol = Qchanged;
      break;
    case G_FILE_MONITOR_EVENT_CHANGES_DONE_HINT:
      symbol = Qchanges_done_hint;
      break;
    case G_FILE_MONITOR_EVENT_DELETED:
      symbol = Qdeleted;
      break;
    case G_FILE_MONITOR_EVENT_CREATED:
      symbol = Qcreated;
      break;
    case G_FILE_MONITOR_EVENT_ATTRIBUTE_CHANGED:
      symbol = Qattribute_changed;
      break;
    case G_FILE_MONITOR_EVENT_PRE_UNMOUNT:
      symbol = Qpre_unmount;
      break;
    case G_FILE_MONITOR_EVENT_UNMOUNTED:
      symbol = Qunmounted;
      break;
    case G_FILE_MONITOR_EVENT_MOVED:
      symbol = Qmoved;
      break;
    default:
      goto cleanup;
    }

  /* Determine callback function.  */
  monitor_object = make_pointer_integer (monitor);
  eassert (INTEGERP (monitor_object));
  watch_object = assq_no_quit (monitor_object, watch_list);

  if (CONSP (watch_object))
    {
      struct input_event event;
      Lisp_Object otail = oname ? list1 (build_string (oname)) : Qnil;

      /* Check, whether event_type is expected.  */
      flags = XCAR (XCDR (XCDR (watch_object)));
      if ((!NILP (Fmember (Qchange, flags)) &&
	   !NILP (Fmember (symbol, list5 (Qchanged, Qchanges_done_hint,
					  Qdeleted, Qcreated, Qmoved)))) ||
	  (!NILP (Fmember (Qattribute_change, flags)) &&
	   ((EQ (symbol, Qattribute_changed)))))
	{
	  /* Construct an event.  */
	  EVENT_INIT (event);
	  event.kind = FILE_NOTIFY_EVENT;
	  event.frame_or_window = Qnil;
	  event.arg = list2 (Fcons (monitor_object,
				    Fcons (symbol,
					   Fcons (build_string (name),
						  otail))),
			     XCAR (XCDR (XCDR (XCDR (watch_object)))));

	  /* Store it into the input event queue.  */
	  kbd_buffer_store_event (&event);
	  /* XD_DEBUG_MESSAGE ("%s", XD_OBJECT_TO_STRING (event.arg));  */
	}

      /* Cancel monitor if file or directory is deleted.  */
      if (!NILP (Fmember (symbol, list2 (Qdeleted, Qmoved))) &&
	  (strcmp (name, SSDATA (XCAR (XCDR (watch_object)))) == 0) &&
	  !g_file_monitor_is_cancelled (monitor))
	g_file_monitor_cancel (monitor);
    }

  /* Cleanup.  */
 cleanup:
  g_free (name);
  g_free (oname);

  return TRUE;
}
	int *stringToPtr_Wiimote(const char *str)
	{
		if (EQ("Up"))
			return &Gui::gui->np->JoystickHats[0];
		if (EQ("Down"))
			return &Gui::gui->np->JoystickHats[1];
		if (EQ("Left"))
			return &Gui::gui->np->JoystickHats[2];
		if (EQ("Right"))
			return &Gui::gui->np->JoystickHats[3];
		if (EQ("A"))
			return &Gui::gui->np->JoystickButtons[0];
		if (EQ("B"))
			return &Gui::gui->np->JoystickButtons[1];
		if (EQ("1"))
			return &Gui::gui->np->JoystickButtons[2];
		if (EQ("2"))
			return &Gui::gui->np->JoystickButtons[3];
		if (EQ("-"))
			return &Gui::gui->np->JoystickButtons[4];
		if (EQ("+"))
			return &Gui::gui->np->JoystickButtons[5];
		if (EQ("Home"))
			return &Gui::gui->np->JoystickButtons[6];

		/* Shound never happen! */
		panic("Illegal string %s\n", str);

		return NULL;
	}
Пример #23
0
boolean NEQ (POINT P1, POINT P2)
/* Mengirimkan true jika P1 tidak sama dengan P2 */
{	//Algoritma
	return !EQ(P1, P2);
}
Пример #24
0
//
// Callback that's invoked once the main JSON file is downloaded.
//
// If the SoupMessage returns a successful response then this callback will
// trigger the processing of the users asynchronously. It will also register a
// a callback that will process all new buddies that are added while Pidgin is
// running.
//
static void
budicons_got_json_response (SoupSession *session, SoupMessage *message, gpointer data) {
	BudiconsPlugin *plugin = (BudiconsPlugin *) data;

	{
		char *url = soup_uri_to_string(soup_message_get_uri(message), FALSE);
		g_print("Downloaded URL %s: %d\n", url, message->status_code);
		g_free(url);
	}

	if (! SOUP_STATUS_IS_SUCCESSFUL (message->status_code)) {
		g_print("SOUP Message was not successful (%d)\n", message->status_code);
		return;
	}


	const char *buffer = message->response_body->data;
	gsize length = (gsize) message->response_body->length;

	const char *mime = soup_message_headers_get_content_type(message->response_headers, NULL);
	if (! (EQ(mime, "application/json") || EQ(mime, "text/plain"))) {
		g_print("Got the wrong mime type (%s) for the JSON file\n", mime);
		return;
	}


	// Parse the JSON file
	GError *error = NULL;
	plugin->users = budicons_json_parse_users(buffer, length, &error);
	if (plugin->users == NULL) {
		char *url = soup_uri_to_string(soup_message_get_uri(message), FALSE);
		g_print("Failed to parse URL %s: %s\n", url, error->message);
		g_free(url);
		g_error_free(error);
		return;
	}


	// Register a callback for every new buddy added
	purple_signal_connect(
		purple_blist_get_handle(),
		"buddy-added",
		plugin->purple,
		PURPLE_CALLBACK(budicons_buddy_added_callback),
		plugin
	);


	// Collect the buddies to process
	PurpleBuddyList *list = purple_get_blist();
	if (list == NULL) {return;}

	plugin->buddies = NULL;
	for (PurpleBlistNode *group = list->root; group; group = group->next) {
		if (! PURPLE_BLIST_NODE_IS_GROUP(group)) {continue;}

		for (PurpleBlistNode *contact = group->child; contact; contact = contact->next) {
			if (! PURPLE_BLIST_NODE_IS_CONTACT(contact)) {continue;}

			for (PurpleBlistNode *blist = contact->child; blist; blist = blist->next) {
				if (! PURPLE_BLIST_NODE_IS_BUDDY(blist)) {continue;}

				PurpleBuddy *buddy = (PurpleBuddy *) blist;
				plugin->buddies = g_slist_prepend(plugin->buddies, buddy);
			}
		}
	}


	// Start a few workers that will process the buddies registered so far
	plugin->buddy_iter = plugin->buddies;
	guint workers = budicons_prefs_get_workers();
	for (guint i = 0; i < workers; ++i) {

		// No more buddies to process
		if (plugin->buddy_iter == NULL) {break;}

		// Create a new worker
		BudiconsWorker *worker = g_new0(BudiconsWorker, 1);
		worker->plugin = plugin;
		worker->id = i;
		g_print("[%d] Started a new worker\n", worker->id);

		budicons_worker_iter(worker);
	}
}
Пример #25
0
/*
 * Convert value x (0..63) to corresponding Base64 character.
 */
static int b64_byte_to_char(unsigned x) {
    return (LT(x, 26) & (x + 'A')) |
           (GE(x, 26) & LT(x, 52) & (x + ('a' - 26))) |
           (GE(x, 52) & LT(x, 62) & (x + ('0' - 52))) | (EQ(x, 62) & '+') |
           (EQ(x, 63) & '/');
}
Пример #26
0
bool
DirectoryEntry::operator==(const DirectoryEntry& other) const
{
    if (this == &other)
    {
        return true;
    }
    else
    {

#define EQ(x)                                   \
    (x == other.x)

        LOCK();

        return
            EQ(oid_) and
            EQ(type_) and
            EQ(inode_) and
            EQ(permissions_) and
            EQ(user_id_) and
            EQ(group_id_) and
            EQ(atime_.tv_sec) and
            EQ(atime_.tv_usec) and
            EQ(ctime_.tv_sec) and
            EQ(ctime_.tv_usec) and
            EQ(mtime_.tv_sec) and
            EQ(mtime_.tv_usec);

#undef EQ

    }
}
Пример #27
0
widget_value *
digest_single_submenu (int start, int end, int top_level_items)
{
  widget_value *wv, *prev_wv, *save_wv, *first_wv;
  int i;
  int submenu_depth = 0;
  widget_value **submenu_stack;
  int panes_seen = 0;

  submenu_stack = alloca (menu_items_used * sizeof *submenu_stack);
  wv = xmalloc_widget_value ();
  wv->name = "menu";
  wv->value = 0;
  wv->enabled = 1;
  wv->button_type = BUTTON_TYPE_NONE;
  wv->help = Qnil;
  first_wv = wv;
  save_wv = 0;
  prev_wv = 0;

  /* Loop over all panes and items made by the preceding call
     to parse_single_submenu and construct a tree of widget_value objects.
     Ignore the panes and items used by previous calls to
     digest_single_submenu, even though those are also in menu_items.  */
  i = start;
  while (i < end)
    {
      if (EQ (AREF (menu_items, i), Qnil))
	{
	  submenu_stack[submenu_depth++] = save_wv;
	  save_wv = prev_wv;
	  prev_wv = 0;
	  i++;
	}
      else if (EQ (AREF (menu_items, i), Qlambda))
	{
	  prev_wv = save_wv;
	  save_wv = submenu_stack[--submenu_depth];
	  i++;
	}
      else if (EQ (AREF (menu_items, i), Qt)
	       && submenu_depth != 0)
	i += MENU_ITEMS_PANE_LENGTH;
      /* Ignore a nil in the item list.
	 It's meaningful only for dialog boxes.  */
      else if (EQ (AREF (menu_items, i), Qquote))
	i += 1;
      else if (EQ (AREF (menu_items, i), Qt))
	{
	  /* Create a new pane.  */
	  Lisp_Object pane_name;
	  const char *pane_string;

	  panes_seen++;

	  pane_name = AREF (menu_items, i + MENU_ITEMS_PANE_NAME);

#ifdef HAVE_NTGUI
	  if (STRINGP (pane_name))
	    {
	      if (unicode_append_menu)
		/* Encode as UTF-8 for now.  */
		pane_name = ENCODE_UTF_8 (pane_name);
	      else if (STRING_MULTIBYTE (pane_name))
		pane_name = ENCODE_SYSTEM (pane_name);

	      ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
	    }
#elif defined (USE_LUCID) && defined (HAVE_XFT)
	  if (STRINGP (pane_name))
            {
              pane_name = ENCODE_UTF_8 (pane_name);
	      ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
            }
#elif !defined (HAVE_MULTILINGUAL_MENU)
	  if (STRINGP (pane_name) && STRING_MULTIBYTE (pane_name))
	    {
	      pane_name = ENCODE_MENU_STRING (pane_name);
	      ASET (menu_items, i + MENU_ITEMS_PANE_NAME, pane_name);
	    }
#endif

	  pane_string = (NILP (pane_name)
			 ? "" : SSDATA (pane_name));
	  /* If there is just one top-level pane, put all its items directly
	     under the top-level menu.  */
	  if (menu_items_n_panes == 1)
	    pane_string = "";

	  /* If the pane has a meaningful name,
	     make the pane a top-level menu item
	     with its items as a submenu beneath it.  */
	  if (strcmp (pane_string, ""))
	    {
	      wv = xmalloc_widget_value ();
	      if (save_wv)
		save_wv->next = wv;
	      else
		first_wv->contents = wv;
	      wv->lname = pane_name;
              /* Set value to 1 so update_submenu_strings can handle '@'  */
	      wv->value = (char *)1;
	      wv->enabled = 1;
	      wv->button_type = BUTTON_TYPE_NONE;
	      wv->help = Qnil;
	      save_wv = wv;
	    }
	  else
	    save_wv = first_wv;

	  prev_wv = 0;
	  i += MENU_ITEMS_PANE_LENGTH;
	}
      else
	{
	  /* Create a new item within current pane.  */
	  Lisp_Object item_name, enable, descrip, def, type, selected;
	  Lisp_Object help;

	  /* All items should be contained in panes.  */
	  if (panes_seen == 0)
	    abort ();

	  item_name = AREF (menu_items, i + MENU_ITEMS_ITEM_NAME);
	  enable = AREF (menu_items, i + MENU_ITEMS_ITEM_ENABLE);
	  descrip = AREF (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY);
	  def = AREF (menu_items, i + MENU_ITEMS_ITEM_DEFINITION);
	  type = AREF (menu_items, i + MENU_ITEMS_ITEM_TYPE);
	  selected = AREF (menu_items, i + MENU_ITEMS_ITEM_SELECTED);
	  help = AREF (menu_items, i + MENU_ITEMS_ITEM_HELP);

#ifdef HAVE_NTGUI
	  if (STRINGP (item_name))
	    {
	      if (unicode_append_menu)
		item_name = ENCODE_UTF_8 (item_name);
	      else if (STRING_MULTIBYTE (item_name))
		item_name = ENCODE_SYSTEM (item_name);

	      ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name);
	    }

	  if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
	    {
	      descrip = ENCODE_SYSTEM (descrip);
	      ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
	    }
#elif USE_LUCID
	  if (STRINGP (item_name))
	    {
              item_name = ENCODE_UTF_8 (item_name);
	      ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name);
	    }

	  if (STRINGP (descrip))
	    {
	      descrip = ENCODE_UTF_8 (descrip);
	      ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
	    }
#elif !defined (HAVE_MULTILINGUAL_MENU)
          if (STRING_MULTIBYTE (item_name))
	    {
	      item_name = ENCODE_MENU_STRING (item_name);
	      ASET (menu_items, i + MENU_ITEMS_ITEM_NAME, item_name);
	    }

          if (STRINGP (descrip) && STRING_MULTIBYTE (descrip))
	    {
	      descrip = ENCODE_MENU_STRING (descrip);
	      ASET (menu_items, i + MENU_ITEMS_ITEM_EQUIV_KEY, descrip);
	    }
#endif

	  wv = xmalloc_widget_value ();
	  if (prev_wv)
	    prev_wv->next = wv;
	  else
	    save_wv->contents = wv;

	  wv->lname = item_name;
	  if (!NILP (descrip))
	    wv->lkey = descrip;
	  wv->value = 0;
	  /* The intptr_t cast avoids a warning.  There's no problem
	     as long as pointers have enough bits to hold small integers.  */
	  wv->call_data = (!NILP (def) ? (void *) (intptr_t) i : 0);
	  wv->enabled = !NILP (enable);

	  if (NILP (type))
	    wv->button_type = BUTTON_TYPE_NONE;
	  else if (EQ (type, QCradio))
	    wv->button_type = BUTTON_TYPE_RADIO;
	  else if (EQ (type, QCtoggle))
	    wv->button_type = BUTTON_TYPE_TOGGLE;
	  else
	    abort ();

	  wv->selected = !NILP (selected);
	  if (! STRINGP (help))
	    help = Qnil;

	  wv->help = help;

	  prev_wv = wv;

	  i += MENU_ITEMS_ITEM_LENGTH;
	}
    }

  /* If we have just one "menu item"
     that was originally a button, return it by itself.  */
  if (top_level_items && first_wv->contents && first_wv->contents->next == 0)
    {
      wv = first_wv->contents;
      free_widget_value (first_wv);
      return wv;
    }

  return first_wv;
}
Пример #28
0
CS123SceneColor
recursiveTrace(
      const Vector4& pos,
      const Vector4& d,
      const CS123SceneGlobalData& global,
      QVector<SceneObject>& objects,
      const QList<CS123SceneLightData>& lights,
      KdTree* tree,
      AABB extends,
      int curIndex,
      int count
      )
{
    CS123SceneColor result;
    result.a = result.r = result.g = result.b = 0;
    // if count is less than 0,  it's maximum recursion
    if( count <= 0 )
        return result;

    count--;

    Vector3 norm;
    int objectIndex = -1;
    int faceIndex = -1;
    CS123SceneColor texColor;
    texColor.a = 0; texColor.r = 0; texColor.g = 0; texColor.b = 0;
    REAL t = intersect( pos, objects, d, objectIndex, faceIndex, tree, extends );
    // if t > 0, then compute the intersect point and blend the color
    if( t > 0)
    {
        if( t==1)
         {
            CS123SceneColor r;
            r.a = r.b = r.r = r.g = 1;
            return r;
        }
        Vector4 intersectPoint = pos + t*d;
        Vector4 eyeSpaceIntersectPoint = objects[objectIndex].m_invTransform*pos
                + t*objects[objectIndex].m_invTransform*d;
        switch( objects[objectIndex].m_primitive.type )
        {
        case PRIMITIVE_CUBE: norm = getCubeNorm( faceIndex);break;
        case PRIMITIVE_CYLINDER: norm = getCylinderNorm( eyeSpaceIntersectPoint, faceIndex);break;
        case PRIMITIVE_CONE: norm = getConeNorm( eyeSpaceIntersectPoint,  faceIndex);break;
        case PRIMITIVE_SPHERE: norm= getSphereNorm( eyeSpaceIntersectPoint );break;
        case PRIMITIVE_MESH: break;
        case PRIMITIVE_TORUS: break;
        default:assert(0);break;
        }
        if( objects[objectIndex].m_texture.m_textureHandle
                && settings.showTexture
                && objects[objectIndex].m_texture.m_texPointer
                )
        {
            switch( objects[objectIndex].m_primitive.type )
            {
            case PRIMITIVE_CUBE: texColor = getCubeIntersectTexColor( objects[objectIndex], faceIndex, eyeSpaceIntersectPoint );break;
            case PRIMITIVE_CYLINDER: texColor = getCylinderIntersectTexColor( objects[objectIndex], faceIndex, eyeSpaceIntersectPoint );break;
            case PRIMITIVE_CONE: texColor = getConeIntersectTexColor( objects[objectIndex], faceIndex, eyeSpaceIntersectPoint );break;
            case PRIMITIVE_SPHERE: texColor = getSphereIntersectTexColor( objects[objectIndex],  eyeSpaceIntersectPoint );break;
            case PRIMITIVE_MESH: break;
            case PRIMITIVE_TORUS: break;
            default:assert(0);break;
            }
        }
        CS123SceneColor colorNormal;
        colorNormal.a = colorNormal.r = colorNormal.g = colorNormal.b = 0;
        CS123SceneColor colorReflection;
        colorReflection.a = colorReflection.r = colorReflection.g = colorReflection.b = 0;
        CS123SceneColor colorRefraction;
        colorRefraction.a = colorRefraction.r = colorRefraction.g = colorRefraction.b = 0;


        Vector4 tempNorm = Vector4( norm.x, norm.y, norm.z, 0 );
        tempNorm = objects[objectIndex].m_invTTransformWithoutTrans*tempNorm;

        // nomalize the new norm
        norm = Vector3( tempNorm.x, tempNorm.y, tempNorm.z ).unit();
        colorNormal = computeObjectColor( objectIndex,objects, global, lights, tree, extends, intersectPoint, norm, pos, texColor );

        // if refecltion is enabled then do recursive retracing
        if( settings.useReflection  )
        {
            //  Vector4 sight = pos - intersectPoint;
            //  sight = sight.getNormalized();

            REAL projection = -(d.x*norm.x + d.y*norm.y + d.z*norm.z);
            bool zeroReflection = EQ(objects[objectIndex].m_primitive.material.cReflective.a,0) &&
                    EQ(objects[objectIndex].m_primitive.material.cReflective.r,0) &&
                    EQ(objects[objectIndex].m_primitive.material.cReflective.g,0) &&
                    EQ(objects[objectIndex].m_primitive.material.cReflective.b,0);
            if( projection > 0 && global.ks > 0 && !zeroReflection )
            {
                Vector4 reflection = getReflectionDir( norm, d );
                intersectPoint.x = intersectPoint.x + reflection.x*EPSILON;
                intersectPoint.y = intersectPoint.y + reflection.y*EPSILON;
                intersectPoint.z = intersectPoint.z + reflection.z*EPSILON;
                intersectPoint.w = 1;

                colorReflection = recursiveTrace( intersectPoint,
                                                  reflection,
                                                  global,
                                                  objects,
                                                  lights,
                                                  tree,
                                                  extends,
                                                  curIndex,
                                                  count );

                colorReflection.a = objects[objectIndex].m_primitive.material.cReflective.a*global.ks*colorReflection.a;
                colorReflection.r = objects[objectIndex].m_primitive.material.cReflective.r*global.ks*colorReflection.r;
                colorReflection.g = objects[objectIndex].m_primitive.material.cReflective.g*global.ks*colorReflection.g;
                colorReflection.b = objects[objectIndex].m_primitive.material.cReflective.b*global.ks*colorReflection.b;
            }


            bool zeroRefraction = EQ(objects[objectIndex].m_primitive.material.cTransparent.a,0) &&
                    EQ(objects[objectIndex].m_primitive.material.cTransparent.r,0) &&
                    EQ(objects[objectIndex].m_primitive.material.cTransparent.g,0) &&
                    EQ(objects[objectIndex].m_primitive.material.cTransparent.b,0);
            if( !zeroRefraction )
            {
                // Refracetion part
                float n1,n2;
                if( curIndex != -1 )
                {
                    // The ray may be inside an object
                    n1 = objects[curIndex].m_primitive.material.ior;
                    Vector3 normFace;
                    // bump the start point to be a little bit
                    if( d.x*norm.x + d.y*norm.y + d.z*norm.z > 0 )
                        normFace = Vector3( -norm.x, -norm.y, -norm.z );
                    else
                        normFace = norm;
                    Vector4 bumpPos =intersectPoint + Vector4( -normFace.x, -normFace.y, -normFace.z, 0 )*EPSILON*2;
                    QMap<int, int> indexMap;
                    QVector<SceneObject> list = checkPos( objects, bumpPos, indexMap );
                    int dummyObjectIndex = -1, dummyFaceindex = -1;
                    REAL t2 = -1;
                    if( list.size() != 0 )
                        t2 = intersect( bumpPos, list, Vector4( -normFace.x, -normFace.y, -normFace.z, 0) , dummyObjectIndex,
                                        dummyFaceindex, tree, extends, true );
                    if( t2 > 0 )
                    {
                        n2 = list[dummyObjectIndex].m_primitive.material.ior;
                        curIndex = indexMap[dummyObjectIndex];
                    }
                    else
                    {
                        // The ray is towards air
                        n2 = 1;
                        curIndex = -1;
                    }
                }
                else
                {
                    // If curIndex == -1, then the ray is from air
                    n1 = 1;
                    n2 =objects[objectIndex].m_primitive.material.ior;
                    curIndex = objectIndex;
                }

                Vector4 refraction;
                // Check the angle between incident ray and norm
                if( d.x*norm.x + d.y*norm.y + d.z*norm.z > 0 )
                    refraction = getRefracetionDir( -norm, d, n1, n2 );
                else
                    refraction = getRefracetionDir( norm, d, n1, n2 );
                if( refraction != Vector4::zero() )
                {
                    //               Vector4 norm4 = Vector4(norm.x, norm.y, norm.z, 0);
                    intersectPoint.x = intersectPoint.x + refraction.x*EPSILON*2;
                    intersectPoint.y = intersectPoint.y + refraction.y*EPSILON*2;
                    intersectPoint.z = intersectPoint.z + refraction.z*EPSILON*2;
                    intersectPoint.w = 1;
                    colorRefraction = recursiveTrace( intersectPoint,
                                                      refraction,
                                                      global,
                                                      objects,
                                                      lights,
                                                      tree,
                                                      extends,
                                                      curIndex,
                                                      count
                                                      );

                    colorRefraction.a = objects[objectIndex].m_primitive.material.cTransparent.a*colorRefraction.a;
                    colorRefraction.r = objects[objectIndex].m_primitive.material.cTransparent.r*colorRefraction.r;
                    colorRefraction.g = objects[objectIndex].m_primitive.material.cTransparent.g*colorRefraction.g;
                    colorRefraction.b = objects[objectIndex].m_primitive.material.cTransparent.b*colorRefraction.b;
                }
            }
        }
        result.a = colorNormal.a + colorReflection.a + colorRefraction.a;
        result.r = colorNormal.r + colorReflection.r+ colorRefraction.r;
        result.g = colorNormal.g + colorReflection.g+ colorRefraction.g;
        result.b = colorNormal.b + colorReflection.b+ colorRefraction.b;

     /*   result.a = 1;
        result.r = 1;
        result.g = 1;
        result.b = 1;*/
    }
    return result;
}
Пример #29
0
/*
 - fast - step through the string at top speed
 == static const char *fast(struct match *m, const char *start, \
 ==	const char *stop, sopno startst, sopno stopst);
 */
static const char *		/* where tentative match ended, or NULL */
fast(	struct match *m,
	const char *start,
	const char *stop,
	sopno startst,
	sopno stopst)
{
	states st = m->st;
	states fresh = m->fresh;
	states tmp = m->tmp;
	const char *p = start;
	wint_t c;
	wint_t lastc;		/* previous c */
	wint_t flagch;
	int i;
	const char *coldp;	/* last p after which no match was underway */
	size_t clen;

	CLEAR(st);
	SET1(st, startst);
	SP("fast", st, *p);
	st = step(m->g, startst, stopst, st, NOTHING, st);
	ASSIGN(fresh, st);
	SP("start", st, *p);
	coldp = NULL;
	if (start == m->beginp)
		c = OUT;
	else {
		/*
		 * XXX Wrong if the previous character was multi-byte.
		 * Newline never is (in encodings supported by FreeBSD),
		 * so this only breaks the ISWORD tests below.
		 */
		c = (uch)*(start - 1);
	}
	for (;;) {
		/* next character */
		lastc = c;
		if (p == m->endp) {
			clen = 0;
			c = OUT;
		} else
			clen = XMBRTOWC(&c, p, m->endp - p, &m->mbs, BADCHAR);
		if (EQ(st, fresh))
			coldp = p;

		/* is there an EOL and/or BOL between lastc and c? */
		flagch = '\0';
		i = 0;
		if ( (lastc == '\n' && m->g->cflags&REG_NEWLINE) ||
				(lastc == OUT && !(m->eflags&REG_NOTBOL)) ) {
			flagch = BOL;
			i = m->g->nbol;
		}
		if ( (c == '\n' && m->g->cflags&REG_NEWLINE) ||
				(c == OUT && !(m->eflags&REG_NOTEOL)) ) {
			flagch = (flagch == BOL) ? BOLEOL : EOL;
			i += m->g->neol;
		}
		if (i != 0) {
			for (; i > 0; i--)
				st = step(m->g, startst, stopst, st, flagch, st);
			SP("boleol", st, c);
		}

		/* how about a word boundary? */
		if ( (flagch == BOL || (lastc != OUT && !ISWORD(lastc))) &&
					(c != OUT && ISWORD(c)) ) {
			flagch = BOW;
		}
		if ( (lastc != OUT && ISWORD(lastc)) &&
				(flagch == EOL || (c != OUT && !ISWORD(c))) ) {
			flagch = EOW;
		}
		if (flagch == BOW || flagch == EOW) {
			st = step(m->g, startst, stopst, st, flagch, st);
			SP("boweow", st, c);
		}

		/* are we done? */
		if (ISSET(st, stopst) || p == stop || clen > stop - p)
			break;		/* NOTE BREAK OUT */

		/* no, we must deal with this character */
		ASSIGN(tmp, st);
		ASSIGN(st, fresh);
		assert(c != OUT);
		st = step(m->g, startst, stopst, tmp, c, st);
		SP("aft", st, c);
		assert(EQ(step(m->g, startst, stopst, st, NOTHING, st), st));
		p += clen;
	}

	assert(coldp != NULL);
	m->coldp = coldp;
	if (ISSET(st, stopst))
		return(p+XMBRTOWC(NULL, p, stop - p, &m->mbs, 0));
	else
		return(NULL);
}
Пример #30
0
void SphereEntity::collideWithSurface(WaterSurface *surface)
{
	if(m_center.y - m_radius > MAXIMUM_VELOCITY-WATER_PLANE_HEIGHT) //ball is too high up
		return;

	glm::vec2 upperLeft = surface->closestDiscretePoint(m_center - glm::vec3(m_radius+surface->getResolution()));
	glm::vec2 lowerRight = surface->closestDiscretePoint(m_center + glm::vec3(m_radius+surface->getResolution()));

	int supportingPoints = 0;
	int possiblePoints = 0;
	glm::vec3 supportingVector;

	//x2+y2+z2=r2
	for(int x_i = (int)upperLeft.x; x_i <= (int)lowerRight.x; x_i++)
	{
		const float x = -.5f + x_i*surface->getResolution();
		const float x_dist = (x - m_center.x)*(x - m_center.x);

		for(int z_i = (int)upperLeft.y; z_i <= (int)lowerRight.y; z_i++)
		{
			float z = -.5f + z_i*surface->getResolution();
			float z_dist = (z - m_center.z)*(z - m_center.z);

			if(glm::sqrt(x_dist+z_dist) > m_radius)
				continue; //inside square, not circle here

			float y = surface->heightAt(glm::vec2(x_i,z_i))+WATER_PLANE_HEIGHT;
			float y_dist = m_center.y >= y ? (y - m_center.y)*(y - m_center.y) : 0;
			possiblePoints++;

			if(glm::sqrt(x_dist + y_dist + z_dist) > m_radius)
				continue; // ball is not touching or above water here

			float ball_y = -glm::sqrt(m_radius*m_radius - x_dist - z_dist) + m_center.y;
			if(glm::isnan(ball_y)) ball_y = m_center.y;

			supportingPoints++;
			supportingVector += (m_center - glm::vec3(x,y,z));

			surface->setPoint(glm::vec2(x_i,z_i), ball_y-WATER_PLANE_HEIGHT);
		}
	}

	if(supportingPoints > 0)
	{
		if(!(EQ(supportingVector.y,0)))
			supportingVector /= supportingVector.y;

		glm::vec2 closestImpulseLocation = surface->closestDiscretePoint(m_center - supportingVector*m_radius);

		const float maximumArea = M_PI * m_radius * m_radius;
		const float requiredArea =  maximumArea * (1-m_buoyancy/MAX_BUOYANCY);

		const float proportionOfCircleSampled = float(supportingPoints)/float(possiblePoints);
		const float areaOfCircleSampled = M_PI * (m_radius+surface->getResolution()) * (m_radius+surface->getResolution());
		const float areaUsed = proportionOfCircleSampled*areaOfCircleSampled;

		const float support = 2.f /
				(1.f + glm::exp((requiredArea-areaUsed)/requiredArea*SUPPORT_COEFFICIENT));

		if(areaUsed >= requiredArea)
		{
			//We should support the velocity as much as we are allowed.
			applyImpulseAt(-SUPPORTED_VELOCITY_COEFFICIENT * m_velocity.y * m_mass * supportingVector
						   * (1.f-.5f*float(m_velocity.y > 0)), m_center);
			//We should experience an upwards force relative to how much area is used
			applyForceAt(-GRAVITY * m_mass * support, m_center);
		}
		else
		{
			applyImpulseAt(-SUPPORTED_VELOCITY_COEFFICIENT * m_velocity.y * m_mass * support * supportingVector, m_center);
			applyForceAt(-GRAVITY * m_mass * support * SUPPORTED_VELOCITY_COEFFICIENT, m_center);
		}

		//we apply an impulse to the water
		surface->applyImpulseAt(glm::vec3(0,-m_velocity.y*SURFACE_IMPULSE_COEFFICIENT,0),
								glm::vec3(closestImpulseLocation.x, 0, closestImpulseLocation.y));
		surface->applyImpulseAt(glm::vec3(0,-m_velocity.y/4.f*SURFACE_IMPULSE_COEFFICIENT,0),
								glm::vec3(closestImpulseLocation.x+1, 0, closestImpulseLocation.y+1));
		surface->applyImpulseAt(glm::vec3(0,-m_velocity.y/4.f*SURFACE_IMPULSE_COEFFICIENT,0),
								glm::vec3(closestImpulseLocation.x+1, 0, closestImpulseLocation.y-1));
		surface->applyImpulseAt(glm::vec3(0,-m_velocity.y/4.f*SURFACE_IMPULSE_COEFFICIENT,0),
								glm::vec3(closestImpulseLocation.x-1, 0, closestImpulseLocation.y+1));
		surface->applyImpulseAt(glm::vec3(0,-m_velocity.y/4.f*SURFACE_IMPULSE_COEFFICIENT,0),
								glm::vec3(closestImpulseLocation.x-1, 0, closestImpulseLocation.y-1));

		glm::vec3 vxz = glm::vec3(m_velocity.x, 0, m_velocity.z);
		applyImpulseAt(-SURFACE_SIDEWAYS_COEFFICIENT * m_mass * (1-(m_center.y-WATER_PLANE_HEIGHT)/m_radius) *
					   (1-(m_center.y-WATER_PLANE_HEIGHT)/m_radius) * vxz,
					   m_center);

		if(m_center.y-WATER_PLANE_HEIGHT < 0)
			this->applyForceAt(-GRAVITY * m_mass * (1-m_center.y+WATER_PLANE_HEIGHT) * 5.f, m_center);
	}
}