コード例 #1
0
ファイル: inlined_fastr.c プロジェクト: graalvm/fastr
INLINE_FUN SEXP lang5(SEXP s, SEXP t, SEXP u, SEXP v, SEXP w)
{
    PROTECT(s);
    s = LCONS(s, list4(t, u, v, w));
    UNPROTECT(1);
    return s;
}
コード例 #2
0
ファイル: inotify.c プロジェクト: davidswelt/aquamacs-emacs
/* Add a new watch to watch-descriptor WD watching FILENAME and using
   IMASK and CALLBACK.  Return a cons (DESCRIPTOR . ID) uniquely
   identifying the new watch.  */
static Lisp_Object
add_watch (int wd, Lisp_Object filename,
	   uint32_t imask, Lisp_Object callback)
{
  Lisp_Object descriptor = INTEGER_TO_CONS (wd);
  Lisp_Object tail = assoc_no_quit (descriptor, watch_list);
  Lisp_Object watch, watch_id;
  Lisp_Object mask = INTEGER_TO_CONS (imask);

  EMACS_INT id = 0;
  if (NILP (tail))
    {
      tail = list1 (descriptor);
      watch_list = Fcons (tail, watch_list);
    }
  else
    {
      /* Assign a watch ID that is not already in use, by looking
	 for a gap in the existing sorted list.  */
      for (; ! NILP (XCDR (tail)); tail = XCDR (tail), id++)
	if (!EQ (XCAR (XCAR (XCDR (tail))), make_number (id)))
	  break;
      if (MOST_POSITIVE_FIXNUM < id)
	emacs_abort ();
    }

  /* Insert the newly-assigned ID into the previously-discovered gap,
     which is possibly at the end of the list.  Inserting it there
     keeps the list sorted.  */
  watch_id = make_number (id);
  watch = list4 (watch_id, filename, callback, mask);
  XSETCDR (tail, Fcons (watch, XCDR (tail)));

  return Fcons (descriptor, watch_id);
}
コード例 #3
0
ファイル: inotify.c プロジェクト: davidswelt/aquamacs-emacs
static Lisp_Object
inotifyevent_to_event (Lisp_Object watch, struct inotify_event const *ev)
{
  Lisp_Object name;
  uint32_t mask;
  CONS_TO_INTEGER (Fnth (make_number (3), watch), uint32_t, mask);

  if (! (mask & ev->mask))
    return Qnil;

  if (ev->len > 0)
    {
      size_t const len = strlen (ev->name);
      name = make_unibyte_string (ev->name, min (len, ev->len));
      name = DECODE_FILE (name);
    }
  else
    name = XCAR (XCDR (watch));

  return list2 (list4 (Fcons (INTEGER_TO_CONS (ev->wd), XCAR (watch)),
                       mask_to_aspects (ev->mask),
                       name,
		       INTEGER_TO_CONS (ev->cookie)),
		Fnth (make_number (2), watch));
}
コード例 #4
0
ファイル: gui-msw.c プロジェクト: boukeversteegh/chise
/*
 * Return value is Qt if we have dispatched the command,
 * or Qnil if id has not been mapped to a callback.
 * Window procedure may try other targets to route the
 * command if we return nil
 */
Lisp_Object
mswindows_handle_gui_wm_command (struct frame* f, HWND ctrl, LPARAM id)
{
  /* Try to map the command id through the proper hash table */
  Lisp_Object callback, callback_ex, image_instance, frame, event;

  XSETFRAME (frame, f);

  /* #### make_int should assert that --kkm */
  assert (XINT (make_int (id)) == id);

  image_instance = Fgethash (make_int (id), 
			     FRAME_MSWINDOWS_WIDGET_HASH_TABLE1 (f), Qnil);
  /* It is possible for a widget action to cause it to get out of sync
     with its instantiator. Thus it is necessary to signal this
     possibility. */
  if (IMAGE_INSTANCEP (image_instance))
    XIMAGE_INSTANCE_WIDGET_ACTION_OCCURRED (image_instance) = 1;
  callback = Fgethash (make_int (id), 
		       FRAME_MSWINDOWS_WIDGET_HASH_TABLE2 (f), Qnil);
  callback_ex = Fgethash (make_int (id), 
			  FRAME_MSWINDOWS_WIDGET_HASH_TABLE3 (f), Qnil);

  if (!NILP (callback_ex) && !UNBOUNDP (callback_ex))
    {
      event = Fmake_event (Qnil, Qnil);

      XEVENT (event)->event_type = misc_user_event;
      XEVENT (event)->channel = frame;
      XEVENT (event)->timestamp = GetTickCount ();
      XEVENT (event)->event.eval.function = Qeval;
      XEVENT (event)->event.eval.object =
	list4 (Qfuncall, callback_ex, image_instance, event);
    }
  else if (NILP (callback) || UNBOUNDP (callback))
    return Qnil;
  else
    {
      Lisp_Object fn, arg;

      event = Fmake_event (Qnil, Qnil);

      get_gui_callback (callback, &fn, &arg);
      XEVENT (event)->event_type = misc_user_event;
      XEVENT (event)->channel = frame;
      XEVENT (event)->timestamp = GetTickCount ();
      XEVENT (event)->event.eval.function = fn;
      XEVENT (event)->event.eval.object = arg;
    }

  mswindows_enqueue_dispatch_event (event);
  /* The result of this evaluation could cause other instances to change so 
     enqueue an update callback to check this. */
  enqueue_magic_eval_event (update_widget_instances, frame);
  return Qt;
}
コード例 #5
0
ファイル: menu.c プロジェクト: ueno/emacs
void
save_menu_items (void)
{
  Lisp_Object saved = list4 (!NILP (menu_items_inuse) ? menu_items : Qnil,
			     make_number (menu_items_used),
			     make_number (menu_items_n_panes),
			     make_number (menu_items_submenu_depth));
  record_unwind_protect (restore_menu_items, saved);
  menu_items_inuse = Qnil;
  menu_items = Qnil;
}
コード例 #6
0
Layout * ArithmeticError::get_layout_for_class()
{
  static Layout * layout;
  if (layout == NULL)
    layout = new Layout(the_class(C_arithmetic_error),
                        list4(S_format_control,
                              S_format_arguments,
                              S_operation,
                              S_operands),
                        NIL);
  return layout;
}
コード例 #7
0
static emacs_value
module_make_function (emacs_env *env, ptrdiff_t min_arity, ptrdiff_t max_arity,
		      emacs_subr subr, const char *documentation,
		      void *data)
{
  MODULE_FUNCTION_BEGIN (module_nil);

  if (! (0 <= min_arity
	 && (max_arity < 0
	     ? max_arity == emacs_variadic_function
	     : min_arity <= max_arity)))
    xsignal2 (Qinvalid_arity, make_number (min_arity), make_number (max_arity));

  /* FIXME: This should be freed when envobj is GC'd.  */
  struct module_fun_env *envptr = xmalloc (sizeof *envptr);
  envptr->min_arity = min_arity;
  envptr->max_arity = max_arity;
  envptr->subr = subr;
  envptr->data = data;

  Lisp_Object envobj = make_save_ptr (envptr);
  Lisp_Object doc
    = (documentation
       ? code_convert_string_norecord (build_unibyte_string (documentation),
				       Qutf_8, false)
       : Qnil);
  /* FIXME: Use a bytecompiled object, or even better a subr.  */
  Lisp_Object ret = list4 (Qlambda,
                           list2 (Qand_rest, Qargs),
                           doc,
                           list4 (Qapply,
                                  list2 (Qfunction, Qinternal__module_call),
                                  envobj,
                                  Qargs));

  return lisp_to_value (ret);
}
コード例 #8
0
/*
	void GetAppList(const char *signature, BList *teamIDList) const
	@case 3			teamIDList is not NULL and not empty, signature is not
					NULL and app(s) with this signature is (are) running
	@results		Should append the team IDs of all running apps with the
					supplied signature to teamIDList.
*/
void GetAppListTester::GetAppListTestB3()
{
	const char *signature = "application/x-vnd.obos-app-run-testapp1";
	// create a list with some dummy entries
	BList list;
	list.AddItem((void*)-7);
	list.AddItem((void*)-42);
	// get a list of running applications for reference
	BRoster roster;
	BList list1(list);
	roster.GetAppList(signature, &list1);
	check_list(list1, list);
	// run some apps
	AppRunner runner1(true);
	AppRunner runner2(true);
	AppRunner runner3(true);
	CHK(runner1.Run("AppRunTestApp1") == B_OK);
	CHK(runner2.Run("AppRunTestApp2") == B_OK);
	CHK(runner3.Run("BMessengerTestApp1") == B_OK);
	BList expectedApps;
	expectedApps.AddItem((void*)runner1.Team());
	expectedApps.AddItem((void*)runner2.Team());
	// get a new app list and check it
	BList list2(list);
	roster.GetAppList(signature, &list2);
	check_list(list2, list, expectedApps);
	// quit app 1
	runner1.WaitFor(true);
	expectedApps.RemoveItem((void*)runner1.Team());
	BList list3(list);
	roster.GetAppList(signature, &list3);
	check_list(list3, list, expectedApps);
	// quit app 2
	runner2.WaitFor(true);
	expectedApps.RemoveItem((void*)runner2.Team());
	BList list4(list);
	roster.GetAppList(signature, &list4);
	check_list(list4, list, expectedApps);
	// quit app 3
	runner3.WaitFor(true);
	BList list5(list);
	roster.GetAppList(signature, &list5);
	check_list(list5, list, expectedApps);
}
コード例 #9
0
ファイル: inotify.c プロジェクト: 7696122/emacs
static Lisp_Object
inotifyevent_to_event (Lisp_Object watch_object, struct inotify_event const *ev)
{
  Lisp_Object name = Qnil;
  if (ev->len > 0)
    {
      size_t const len = strlen (ev->name);
      name = make_unibyte_string (ev->name, min (len, ev->len));
      name = DECODE_FILE (name);
    }
  else
    name = XCAR (XCDR (watch_object));

  return list2 (list4 (make_watch_descriptor (ev->wd),
                       mask_to_aspects (ev->mask),
                       name,
                       make_number (ev->cookie)),
		Fnth (make_number (2), watch_object));
}
コード例 #10
0
/* =========== CompareLists ================*/
TEST(LinkedListExcercisesTestSuite, CompareLists)
{
    int data1[5] = { 2, 4, 6, 7, 8 };
    LinkedList<int> list1(data1, 5);

    //test identical list
    LinkedList<int> list2(data1, 5);
    EXPECT_TRUE(LinkedListExercises::CompareLists(list1, list2));
    //test identical but shorter list
    LinkedList<int> list3(data1, 4);
    EXPECT_FALSE(LinkedListExercises::CompareLists(list1, list3));
    //test diffrent list
    int data2[4] = { 1, 3, 6, 7 };
    LinkedList<int> list4(data2, 4);
    EXPECT_FALSE(LinkedListExercises::CompareLists(list1, list4));
    //test empty
    LinkedList<int> empty_list1;
    LinkedList<int> empty_list2;
    EXPECT_TRUE(LinkedListExercises::CompareLists(empty_list1, empty_list2));
}
コード例 #11
0
static void
munge_file_in_editor(const char *filename, int lineno, int colno)
{

  int ret;
  char *editor_command1, *editor_command2, *editor_command3,
       *editor_command4, *line_number_as_string, *column_number_as_string,  **possible_editor_commands;

  /* find out which editor command we have to use */
  possible_editor_commands = list4(getenv("RLWRAP_EDITOR"), getenv("EDITOR"), getenv("VISUAL"), "vi +%L");
  editor_command1 = first_of(possible_editor_commands);
  line_number_as_string = as_string(lineno);
  column_number_as_string = as_string(colno);
  editor_command2 = search_and_replace("%L", line_number_as_string, editor_command1, 0, NULL, NULL);
  editor_command3 = search_and_replace("%C", column_number_as_string, editor_command2, 0, NULL, NULL);
  editor_command4 = strstr(editor_command3, "%F") ?
    search_and_replace("%F", filename, editor_command3, 0, NULL, NULL) :
    add3strings(editor_command3, " ", filename);
  

  /* call editor, temporarily restoring terminal settings */    
  if (terminal_settings_saved && (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_terminal_settings) < 0))    /* reset terminal */
    myerror(FATAL|USE_ERRNO, "tcsetattr error on stdin");
  DPRINTF1(DEBUG_READLINE, "calling %s", editor_command4);
  if ((ret = system(editor_command4))) {
    if (WIFSIGNALED(ret)) {
      fprintf(stderr, "\n"); 
      myerror(FATAL|NOERRNO, "editor killed by signal");
    } else {    
      myerror(FATAL|USE_ERRNO, "failed to invoke editor with '%s'", editor_command4);
    }
  }
  completely_mirror_slaves_terminal_settings();
  ignore_queued_input = TRUE;  

  free_multiple(possible_editor_commands, editor_command2, editor_command3,
                editor_command4, line_number_as_string, column_number_as_string, FMEND);
}
コード例 #12
0
ファイル: boxes.cpp プロジェクト: Ace17/faust
Tree boxNumEntry(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
{
  return tree(BOXNUMENTRY, lbl, list4(cur, min, max, step));
}
コード例 #13
0
ファイル: boxes.cpp プロジェクト: Ace17/faust
Tree boxVSlider(Tree lbl, Tree cur, Tree min, Tree max, Tree step)
{
  return tree(BOXVSLIDER, lbl, list4(cur, min, max, step));
}
コード例 #14
0
ファイル: gui-x.c プロジェクト: hroptatyr/sxemacs
void
popup_selection_callback(Widget widget, LWLIB_ID ignored_id,
			 XtPointer client_data)
{
	Lisp_Object data, image_instance, callback, callback_ex;
	Lisp_Object frame, event;
	int update_subwindows_p = 0;
	struct device *d = get_device_from_display(XtDisplay(widget));
	struct frame *f = x_any_widget_or_parent_to_frame(d, widget);

	/* set in lwlib to the time stamp associated with the most recent menu
	   operation */
	extern Time x_focus_timestamp_really_sucks_fix_me_better;

	if (!f)
		return;
	if (((EMACS_INT) client_data) == 0)
		return;
	VOID_TO_LISP(data, client_data);
	XSETFRAME(frame, f);

#if 0
	/* #### What the hell?  I can't understand why this call is here,
	   and doing it is really courting disaster in the new event
	   model, since popup_selection_callback is called from
	   within next_event_internal() and Faccept_process_output()
	   itself calls next_event_internal().  --Ben */

	/* Flush the X and process input */
	Faccept_process_output(Qnil, Qnil, Qnil);
#endif

	if (((EMACS_INT) client_data) == -1) {
		event = Fmake_event(Qnil, Qnil);

		XEVENT(event)->event_type = misc_user_event;
		XEVENT(event)->channel = frame;
		XEVENT(event)->event.eval.function = Qrun_hooks;
		XEVENT(event)->event.eval.object = Qmenu_no_selection_hook;
	} else {
		image_instance = XCAR(data);
		callback = XCAR(XCDR(data));
		callback_ex = XCDR(XCDR(data));
		update_subwindows_p = 1;
		/* It is possible for a widget action to cause it to get out of
		   sync with its instantiator. Thus it is necessary to signal
		   this possibility. */
		if (IMAGE_INSTANCEP(image_instance))
			XIMAGE_INSTANCE_WIDGET_ACTION_OCCURRED(image_instance) =
			    1;

		if (!NILP(callback_ex) && !UNBOUNDP(callback_ex)) {
			event = Fmake_event(Qnil, Qnil);

			XEVENT(event)->event_type = misc_user_event;
			XEVENT(event)->channel = frame;
			XEVENT(event)->event.eval.function = Qeval;
			XEVENT(event)->event.eval.object =
			    list4(Qfuncall, callback_ex, image_instance, event);
		} else if (NILP(callback) || UNBOUNDP(callback))
			event = Qnil;
		else {
			Lisp_Object fn, arg;

			event = Fmake_event(Qnil, Qnil);

			get_gui_callback(callback, &fn, &arg);
			XEVENT(event)->event_type = misc_user_event;
			XEVENT(event)->channel = frame;
			XEVENT(event)->event.eval.function = fn;
			XEVENT(event)->event.eval.object = arg;
		}
	}

	/* This is the timestamp used for asserting focus so we need to get an
	   up-to-date value event if no events have been dispatched to emacs
	 */
#if defined(HAVE_MENUBARS)
	DEVICE_X_MOUSE_TIMESTAMP(d) =
	    x_focus_timestamp_really_sucks_fix_me_better;
#else
	DEVICE_X_MOUSE_TIMESTAMP(d) = DEVICE_X_GLOBAL_MOUSE_TIMESTAMP(d);
#endif
	if (!NILP(event))
		enqueue_Xt_dispatch_event(event);
	/* The result of this evaluation could cause other instances to change so
	   enqueue an update callback to check this. */
	if (update_subwindows_p && !NILP(event))
		enqueue_magic_eval_event(update_widget_instances, frame);
}
コード例 #15
0
ファイル: main.c プロジェクト: SvenDowideit/clearlinux
/* browser(text = "", condition = NULL, expr = TRUE, skipCalls = 0L)
 * ------- but also called from ./eval.c */
SEXP attribute_hidden do_browser(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    RCNTXT *saveToplevelContext;
    RCNTXT *saveGlobalContext;
    RCNTXT thiscontext, returncontext, *cptr;
    int savestack, browselevel;
    SEXP ap, topExp, argList;

    /* argument matching */
    PROTECT(ap = list4(R_NilValue, R_NilValue, R_NilValue, R_NilValue));
    SET_TAG(ap,  install("text"));
    SET_TAG(CDR(ap), install("condition"));
    SET_TAG(CDDR(ap), install("expr"));
    SET_TAG(CDDDR(ap), install("skipCalls"));
    argList = matchArgs(ap, args, call);
    UNPROTECT(1);
    PROTECT(argList);
    /* substitute defaults */
    if(CAR(argList) == R_MissingArg)
	SETCAR(argList, mkString(""));
    if(CADR(argList) == R_MissingArg)
	SETCAR(CDR(argList), R_NilValue);
    if(CADDR(argList) == R_MissingArg) 
	SETCAR(CDDR(argList), ScalarLogical(1));
    if(CADDDR(argList) == R_MissingArg) 
	SETCAR(CDDDR(argList), ScalarInteger(0));

    /* return if 'expr' is not TRUE */
    if( !asLogical(CADDR(argList)) ) {
        UNPROTECT(1);
        return R_NilValue;
    }

    /* Save the evaluator state information */
    /* so that it can be restored on exit. */

    browselevel = countContexts(CTXT_BROWSER, 1);
    savestack = R_PPStackTop;
    PROTECT(topExp = R_CurrentExpr);
    saveToplevelContext = R_ToplevelContext;
    saveGlobalContext = R_GlobalContext;

    if (!RDEBUG(rho)) {
        int skipCalls = asInteger(CADDDR(argList));
	cptr = R_GlobalContext;
	while ( ( !(cptr->callflag & CTXT_FUNCTION) || skipCalls--) 
		&& cptr->callflag )
	    cptr = cptr->nextcontext;
	Rprintf("Called from: ");
	int tmp = asInteger(GetOption(install("deparse.max.lines"), R_BaseEnv));
	if(tmp != NA_INTEGER && tmp > 0) R_BrowseLines = tmp;
        if( cptr != R_ToplevelContext ) {
	    PrintValueRec(cptr->call, rho);
	    SET_RDEBUG(cptr->cloenv, 1);
        } else
            Rprintf("top level \n");

	R_BrowseLines = 0;
    }

    R_ReturnedValue = R_NilValue;

    /* Here we establish two contexts.  The first */
    /* of these provides a target for return */
    /* statements which a user might type at the */
    /* browser prompt.  The (optional) second one */
    /* acts as a target for error returns. */

    begincontext(&returncontext, CTXT_BROWSER, call, rho,
		 R_BaseEnv, argList, R_NilValue);
    if (!SETJMP(returncontext.cjmpbuf)) {
	begincontext(&thiscontext, CTXT_RESTART, R_NilValue, rho,
		     R_BaseEnv, R_NilValue, R_NilValue);
	if (SETJMP(thiscontext.cjmpbuf)) {
	    SET_RESTART_BIT_ON(thiscontext.callflag);
	    R_ReturnedValue = R_NilValue;
	    R_Visible = FALSE;
	}
	R_GlobalContext = &thiscontext;
	R_InsertRestartHandlers(&thiscontext, TRUE);
	R_ReplConsole(rho, savestack, browselevel+1);
	endcontext(&thiscontext);
    }
    endcontext(&returncontext);

    /* Reset the interpreter state. */

    R_CurrentExpr = topExp;
    UNPROTECT(1);
    R_PPStackTop = savestack;
    UNPROTECT(1);
    R_CurrentExpr = topExp;
    R_ToplevelContext = saveToplevelContext;
    R_GlobalContext = saveGlobalContext;
    return R_ReturnedValue;
}
コード例 #16
0
ファイル: MojListTest.cpp プロジェクト: ctbrowser/db8
/**
****************************************************************************************************
* @run              MojList is similar to standard C++ template library list.
                    MojList uses double linked list to store the data.
                    MojList provides facilities to access data from both front and back of the list.
                    MojList provides additional functionalities like contains() which checks for the
                    object in the list. This testcase verifies all list operations for inserting,
                    retrieving of data using const, non const iterators.

                    List functionalities tested:
                    * Populating list using 'push' utility and checking for empty test.
                    * Adding data to the list using pushBack() utility.
                    * Using const and non-const iterators to ensure integrity of data.
                    * Erasing data using erase().
                    * popBack() and popFront() to retrieve data from front and back of the list.
                    * Deleting the entire list using clear() utility.
* @param         :  None
* @retval        :  MojErr
****************************************************************************************************
**/
MojErr MojListTest::run()
{
	// create a bunch of TestItems
	typedef MojVector<MojRefCountedPtr<TestItem> > TestVec;
	TestVec vec;
	for (int i = 0; i < 100; ++i) {
		MojErr err = vec.push(new TestItem(i));
		MojTestErrCheck(err);
	}

	// empty test
	MojList<TestItem, &TestItem::m_entry1> list1;
	MojTestAssert(list1.empty());
	MojTestAssert(list1.size() == 0);
	TestItem item1(0);
	MojTestAssert(!list1.contains(&item1));
	MojTestAssert(list1.begin() == list1.end());
	const MojList<TestItem, &TestItem::m_entry1>& clist1 = list1;
	MojTestAssert(clist1.begin() == clist1.end());

	// push back
	TestVec::Iterator vecIter;
	MojErr err = vec.begin(vecIter);
	MojTestErrCheck(err);
	for (; vecIter != vec.end(); ++vecIter) {
		MojTestAssert(list1.size() == (MojSize) (*vecIter)->m_val);
		list1.pushBack(vecIter->get());
		MojTestAssert(!list1.empty());
		MojTestAssert(list1.contains(vecIter->get()));
		MojTestAssert(list1.back() == vecIter->get());
		MojTestAssert(list1.front() == clist1.front());
		MojTestAssert(list1.back() == clist1.back());
		if (list1.size() == 1)
			MojTestAssert(list1.front() == vecIter->get());
	}

	// const iterator
	int count = 0;
	for (MojList<TestItem, &TestItem::m_entry1>::ConstIterator i = list1.begin();
		 i != list1.end();
		 ++i, ++count) {
		MojAssert((*i)->m_val == count);
	}
	MojAssert(count == 100);

	// non-const iterator
	for (MojList<TestItem, &TestItem::m_entry1>::Iterator i = list1.begin();
		 i != list1.end();
		 ++i) {
		(*i)->m_val = -(*i)->m_val;
	}

	// iterator erase
	count = 0;
	MojList<TestItem, &TestItem::m_entry1>::Iterator listIter = list1.begin();
	while (listIter != list1.end()) {
		if (count++ % 2 == 0) {
			(listIter++).erase();
		} else {
			listIter++;
		}
	}
	MojTestAssert(list1.size() == 50);
	count = -1;
	listIter = list1.begin();
	for (MojList<TestItem, &TestItem::m_entry1>::ConstIterator i = list1.begin();
		 i != list1.end();
		 ++i) {
		MojTestAssert((*i)->m_val == count);
		count -=2;
	}
	MojTestAssert(count == -101);

	// list erase
	listIter = list1.begin();
	while (listIter != list1.end()) {
		list1.erase(*(listIter++));
	}
	MojTestAssert(list1.size() == 0);
	MojTestAssert(list1.empty());

	// add to two lists (front and back)
	MojList<TestItem, &TestItem::m_entry2> list2;
	err = vec.begin(vecIter);
	MojTestErrCheck(err);
	count = 0;
	for (; vecIter != vec.end(); ++vecIter) {
		(*vecIter)->m_val = count++;
		list1.pushBack(vecIter->get());
		list2.pushFront(vecIter->get());
	}
	// verify order
	count = 0;
	listIter = list1.begin();
	MojList<TestItem, &TestItem::m_entry2>::Iterator listIter2 = list2.begin();
	while (listIter != list1.end() && listIter2 != list2.end()) {
		int val1 = (*listIter)->m_val;
		int val2 = (*listIter2)->m_val;
		MojTestAssert(val1 == count);
		MojTestAssert(val2 == 99 - count);
		++count;
		++listIter;
		++listIter2;
	}
	MojTestAssert(count == 100);

	// popFront/popBack
	count = 0;
	while (!list1.empty() && !list2.empty()) {
		TestItem* item1 = list1.popFront();
		TestItem* item2 = list2.popBack();
		MojTestAssert(item1 == item2);
		++count;
	}
	MojTestAssert(count == 100);
	MojTestAssert(list1.empty() && list2.empty());

	// assignment
	MojList<TestItem, &TestItem::m_entry1> list3(list1);
	MojTestAssert(list1.begin() == list1.end() && list3.begin() == list3.end());
	list1.swap(list3);
	MojTestAssert(list1.begin() == list1.end() && list3.begin() == list3.end());
	list3 = list1;
	MojTestAssert(list1.begin() == list1.end() && list3.begin() == list3.end());
	MojList<TestItem, &TestItem::m_entry1> list4(list1);
	MojTestAssert(list1.begin() == list1.end() && list4.begin() == list4.end());

	err = vec.begin(vecIter);
	MojTestErrCheck(err);
	for (; vecIter != vec.end(); ++vecIter) {
		list1.pushBack(vecIter->get());
	};
	MojTestAssert(list1.size() == 100);
	MojList<TestItem, &TestItem::m_entry1> list5(list1);
	MojTestAssert(list1.size() == 0 && list5.size() == 100);
	MojTestAssert(list1.begin() == list1.end());
	count = 0;
	for (MojList<TestItem, &TestItem::m_entry1>::ConstIterator i = list5.begin();
		 i != list5.end();
		 ++i) {
		MojTestAssert((*i)->m_val == count);
		++count;
	}
	MojTestAssert(count == 100);
	list5 = list5;
	MojTestAssert(list5.size() == 100);
	list1 = list5;
	MojTestAssert(list5.empty() && list1.size() == 100);
	count = 0;
	for (MojList<TestItem, &TestItem::m_entry1>::ConstIterator i = list1.begin();
		 i != list1.end();
		 ++i) {
		MojTestAssert((*i)->m_val == count);
		++count;
	}
	MojTestAssert(count == 100);
	list5.swap(list1);
	MojTestAssert(list1.empty() && list5.size() == 100);
	TestItem* item = list5.popFront();
	list1.pushBack(item);
	MojTestAssert(list1.size() == 1 && list5.size() == 99);
	list1 = list5;
	MojTestAssert(list1.size() == 99 && list5.size() == 0);
	item = list1.popFront();
	list5.pushBack(item);
	MojTestAssert(list1.size() == 98 && list5.size() == 1);
	list5.swap(list1);
	MojTestAssert(list1.size() == 1 && list5.size() == 98);

	// clear
	list5.clear();

	return MojErrNone;
}
コード例 #17
0
ファイル: readline.c プロジェクト: andreyvit/rlwrap
static int
munge_line_in_editor(int count, int key)
{
  int line_number = 0, column_number = 0, tmpfile_OK, ret, tmpfile_fd, bytes_read;
  size_t tmpfilesize;
  char *p, *tmpdir, *tmpfilename, *text_to_edit;
  char *editor_command1, *editor_command2, *editor_command3, *editor_command4,
    *line_number_as_string, *column_number_as_string;
  char *input, *rewritten_input, *rewritten_input2, **possible_tmpdirs, **possible_editor_commands;


  if (!multiline_separator)
    return 0;

  possible_tmpdirs = list4(getenv("TMPDIR"), getenv("TMP"), getenv("TEMP"), "/tmp");
  possible_editor_commands = list4(getenv("RLWRAP_EDITOR"), getenv("EDITOR"), getenv("VISUAL"), "vi +%L");

  /* create temporary filename */
#ifdef HAVE_MKSTEMP
  tmpdir = first_of(possible_tmpdirs);
  tmpfilename = add3strings(tmpdir, "/rlwrap_", "XXXXXX");
  tmpfile_OK = mkstemp(tmpfilename);
#else
  tmpfilename = mymalloc(L_tmpnam);
  tmpfile_OK = (int)tmpnam(tmpfilename); /* manpage says: Never use this function. Use mkstemp(3) instead */
#endif
  if (!tmpfile_OK)
    myerror("could not find unique temporary file name");

  /* write current input to it, replacing the newline substitute (multiline_separator) with the real thing */
  tmpfile_fd = open(tmpfilename, O_CREAT | O_WRONLY, S_IRUSR | S_IWUSR);
  if (tmpfile_fd < 0)
    myerror("could not create temporary file %s", tmpfilename);
  text_to_edit =
    search_and_replace(multiline_separator, "\n", rl_line_buffer, rl_point,
                       &line_number, &column_number);
  write_patiently(tmpfile_fd, text_to_edit, strlen(text_to_edit), "to temporary file");

  if (close(tmpfile_fd) != 0) /* improbable */
    myerror("couldn't close temporary file %s", tmpfilename); 

  /* find out which editor command we have to use */

  editor_command1 = first_of(possible_editor_commands);
  line_number_as_string = as_string(line_number);
  column_number_as_string = as_string(column_number);
  editor_command2 =
    search_and_replace("%L", line_number_as_string, editor_command1, 0, NULL,
                       NULL);
  editor_command3 =
    search_and_replace("%C", column_number_as_string, editor_command2, 0,
                       NULL, NULL);
  editor_command4 = add3strings(editor_command3, " ", tmpfilename);

  
  
  

  /* call editor, temporarily restoring terminal settings */    
  if (terminal_settings_saved && (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_terminal_settings) < 0))    /* reset terminal */
    myerror("tcsetattr error on stdin");
  DPRINTF1(DEBUG_READLINE, "calling %s", editor_command4);
  if ((ret = system(editor_command4))) {
    if (WIFSIGNALED(ret)) {
      fprintf(stderr, "\n"); errno = 0;
      myerror("editor killed by signal");
    } else {    
      myerror("failed to invoke editor with '%s'", editor_command4);
    }
  }
  completely_mirror_slaves_terminal_settings();
  ignore_queued_input = TRUE;  

  /* read back edited input, replacing real newline with substitute */
  tmpfile_fd = open(tmpfilename, O_RDONLY);
  if (tmpfile_fd < 0)
    myerror("could not read temp file %s", tmpfilename);
  tmpfilesize = filesize(tmpfilename);
  input = mymalloc(tmpfilesize + 1);
  bytes_read = read(tmpfile_fd, input, tmpfilesize);
  if (bytes_read < 0)
    myerror("unreadable temp file %s", tmpfilename);
  input[bytes_read] = '\0';
  rewritten_input = search_and_replace("\t", "    ", input, 0, NULL, NULL);     /* rlwrap cannot handle tabs in input lines */
  rewritten_input2 =
    search_and_replace("\n", multiline_separator, rewritten_input, 0, NULL,
                       NULL);
  for(p = rewritten_input2; *p ;p++)
    if(*p < ' ')
      *p = ' ';        /* replace all control characters (like \r) by spaces */


  rl_delete_text(0, strlen(rl_line_buffer));
  rl_point = 0;  
  clear_line();
  cr();
  my_putstr(saved_rl_state.cooked_prompt);
  rl_insert_text(rewritten_input2);
  rl_point = 0;                 /* leave cursor on predictable place */
  rl_done = 1;                  /* accept line immediately */

  


  /* wash those dishes */
  if (unlink(tmpfilename))
    myerror("could not delete temporary file %s", tmpfilename);
  free(editor_command2);
  free(editor_command3);
  free(editor_command4);
  free(line_number_as_string);
  free(column_number_as_string);
  free(tmpfilename);
  free(text_to_edit);
  free(input);
  free(rewritten_input);
  free(rewritten_input2);
  
  return_key = (char)'\n';
  return 0;
}
コード例 #18
0
ファイル: signals.cpp プロジェクト: EBone/faust-1
Tree sigNumEntry   (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
											{ return tree(SIGNUMENTRY, lbl, list4(cur,min,max,step));		}
コード例 #19
0
ファイル: signals.cpp プロジェクト: EBone/faust-1
Tree sigVSlider   (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
											{ return tree(SIGVSLIDER, lbl, list4(cur,min,max,step));		}
コード例 #20
0
int main() {

    DLL<std::string> list1;
    list1.add_node_end("jack").add_node_end("alex");
    list1.add_node_end("sam").add_node_end("tim").add_node_end("jimmy");
    list1.add_node_end("michael").add_node_end("steve");
    list1.add_node_front("thom").add_node_front("bryan");
    
    std::cout << "list1: " << std::endl;
    list1.print_forward(std::cout);
    list1.print_reverse(std::cout);
    
    DLL<std::string> list2(list1);
    list2.update_node("steve","ANTHONY");
    list2.update_node("PETER",1);
    
    std::cout << "list2: " << std::endl;
    list2.print_forward(std::cout);
    list2.print_reverse(std::cout);
    
    DLL<std::string> list3;
    list3 = list2;
    list3.add_node_middle("FRANK",2).add_node_middle("ROBERT",6);
    
    std::cout << "list3: " << std::endl;
    list3.print_forward(std::cout);
    list3.print_reverse(std::cout);
    
    list3.rem_node("bryan").rem_node("sam").rem_node("ANTHONY");
    
    std::cout << "list3: " << std::endl;
    list3.print_forward(std::cout);
    list3.print_reverse(std::cout);
    
    DLL<std::string> list4(std::move(list1));
    std::cout << "list4: " << std::endl;
    list4.print_forward(std::cout);
    list4.print_reverse(std::cout);
    std::cout << "list1: " << std::endl;
    list1.print_forward(std::cout);

    DLL<std::string> list5;
    list5.add_node_end("sara").add_node_end("lily");
    list5.add_node_end("angela").add_node_end("tina");
    list5.add_node_front("rose").add_node_middle("susan",3);
    
    std::cout << "list5: " << std::endl;
    list5.print_forward(std::cout);
    
    list5.print_data_at_index(2);
    list5.print_index_by_data("tina");
    
    DLL<std::string> list6;
    
    list6 = std::move(list5);
    std::cout << "list6: " << std::endl;
    list6.print_forward(std::cout);

    list6.reverse_list();
    std::cout << "list6: " << std::endl;
    list6.print_forward(std::cout);
    
    std::cout << "list5: " << std::endl;
    list5.print_forward(std::cout);
    
    list3.splice(0,list6);
    std::cout << "list3: " << std::endl;
    list3.print_forward(std::cout);
    
    list3.splice(11,list6);
    std::cout << "list3: " << std::endl;
    list3.print_forward(std::cout);

    return 0;
}
コード例 #21
0
ファイル: boxes.cpp プロジェクト: EBone/Faust
Tree boxHSlider   (Tree lbl, Tree cur, Tree min, Tree max, Tree step)
											{ return tree(gGlobal->BOXHSLIDER, lbl, list4(cur,min,max,step));		}
コード例 #22
0
ファイル: seq.c プロジェクト: kalibera/rexp
/* This is a primitive SPECIALSXP with internal argument matching */
SEXP attribute_hidden do_rep(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    SEXP ans, x, times = R_NilValue /* -Wall */;
    int each = 1, nprotect = 3;
    R_xlen_t i, lx, len = NA_INTEGER, nt;
    static SEXP do_rep_formals = NULL;

    /* includes factors, POSIX[cl]t, Date */
    if (DispatchOrEval(call, op, R_RepCharSXP, args, rho, &ans, 0, 0))
	return(ans);

    /* This has evaluated all the non-missing arguments into ans */
    PROTECT(args = ans);

    /* This is a primitive, and we have not dispatched to a method
       so we manage the argument matching ourselves.  We pretend this is
       rep(x, times, length.out, each, ...)
    */
    if (do_rep_formals == NULL) {
        do_rep_formals = CONS(R_NilValue, list4(R_NilValue, R_NilValue, R_NilValue, R_NilValue));
        R_PreserveObject(do_rep_formals);
        SET_TAG(do_rep_formals, R_XSymbol);
        SET_TAG(CDR(do_rep_formals), install("times"));
        SET_TAG(CDDR(do_rep_formals), R_LengthOutSymbol);
        SET_TAG(CDR(CDDR(do_rep_formals)), install("each"));
        SET_TAG(CDDR(CDDR(do_rep_formals)), R_DotsSymbol);
    }
    PROTECT(args = matchArgs(do_rep_formals, args, call));

    x = CAR(args);
    /* supported in R 2.15.x */
    if (TYPEOF(x) == LISTSXP)
	errorcall(call, "replication of pairlists is defunct");

    lx = xlength(x);

    double slen = asReal(CADDR(args));
    if (R_FINITE(slen)) {
	if(slen < 0)
	    errorcall(call, _("invalid '%s' argument"), "length.out");
	len = (R_xlen_t) slen;
    } else {
	len = asInteger(CADDR(args));
	if(len != NA_INTEGER && len < 0)
	    errorcall(call, _("invalid '%s' argument"), "length.out");
    }
    if(length(CADDR(args)) != 1)
	warningcall(call, _("first element used of '%s' argument"), 
		    "length.out");

    each = asInteger(CADDDR(args));
    if(each != NA_INTEGER && each < 0)
	errorcall(call, _("invalid '%s' argument"), "each");
    if(length(CADDDR(args)) != 1)
	warningcall(call, _("first element used of '%s' argument"), "each");
    if(each == NA_INTEGER) each = 1;

    if(lx == 0) {
	if(len > 0 && x == R_NilValue) 
	    warningcall(call, "'x' is NULL so the result will be NULL");
	SEXP a;
	PROTECT(a = duplicate(x));
	if(len != NA_INTEGER && len > 0) a = xlengthgets(a, len);
	UNPROTECT(3);
	return a;
    }
    if (!isVector(x))
	errorcall(call, "attempt to replicate an object of type '%s'",
		  type2char(TYPEOF(x)));

    /* So now we know x is a vector of positive length.  We need to
       replicate it, and its names if it has them. */

    /* First find the final length using 'times' and 'each' */
    if(len != NA_INTEGER) { /* takes precedence over times */
	nt = 1;
    } else {
	R_xlen_t sum = 0;
	if(CADR(args) == R_MissingArg) PROTECT(times = ScalarInteger(1));
	else PROTECT(times = coerceVector(CADR(args), INTSXP));
	nprotect++;
	nt = XLENGTH(times);
	if(nt != 1 && nt != lx * each)
	    errorcall(call, _("invalid '%s' argument"), "times");
	if(nt == 1) {
	    int it = INTEGER(times)[0];
	    if (it == NA_INTEGER || it < 0)
		errorcall(call, _("invalid '%s' argument"), "times");
	    len = lx * it * each;
	} else {
	    for(i = 0; i < nt; i++) {
		int it = INTEGER(times)[i];
		if (it == NA_INTEGER || it < 0)
		    errorcall(call, _("invalid '%s' argument"), "times");
		sum += it;
	    }
            len = sum;
	}
    }

    if(len > 0 && each == 0)
	errorcall(call, _("invalid '%s' argument"), "each");

    SEXP xn = getNamesAttrib(x);

    PROTECT(ans = rep4(x, times, len, each, nt));
    if (length(xn) > 0)
	setAttrib(ans, R_NamesSymbol, rep4(xn, times, len, each, nt));

#ifdef _S4_rep_keepClass
    if(IS_S4_OBJECT(x)) { /* e.g. contains = "list" */
	setAttrib(ans, R_ClassSymbol, getClassAttrib(x));
	SET_S4_OBJECT(ans);
    }
#endif
    UNPROTECT(nprotect);
    return ans;
}
コード例 #23
0
ファイル: filter.c プロジェクト: rubicks/rlwrap
void spawn_filter(const char *filter_command) {
    int input_pipe_fds[2];
    int output_pipe_fds[2];

    mypipe(input_pipe_fds);
    filter_input_fd = input_pipe_fds[1]; /* rlwrap writes filter input to this */

    mypipe(output_pipe_fds);
    filter_output_fd = output_pipe_fds[0]; /* rlwrap  reads filter output from here */
    DPRINTF1(DEBUG_FILTERING, "preparing to spawn filter <%s>", filter_command);
    assert(!command_pid || signal_handlers_were_installed);  /* if there is a command, then signal handlers are installed */

    if ((filter_pid = fork()) < 0)
        myerror(FATAL|USE_ERRNO, "Cannot spawn filter '%s'", filter_command);
    else if (filter_pid == 0) {           /* child */
        int signals_to_allow[] = {SIGPIPE, SIGCHLD, SIGALRM, SIGUSR1, SIGUSR2};
        char **argv;
        unblock_signals(signals_to_allow);  /* when we run a pager from a filter we want to catch these */


        DEBUG_RANDOM_SLEEP;
        i_am_child =  TRUE;
        /* set environment for filter (it needs to know at least the file descriptors for its input and output) */

        if (!getenv("RLWRAP_FILTERDIR"))
            mysetenv("RLWRAP_FILTERDIR", add2strings(DATADIR,"/rlwrap/filters"));
        mysetenv("PATH", add3strings(getenv("RLWRAP_FILTERDIR"),":",getenv("PATH")));
        mysetenv("RLWRAP_VERSION", VERSION);
        mysetenv("RLWRAP_COMMAND_PID",  as_string(command_pid));
        mysetenv("RLWRAP_COMMAND_LINE", command_line);
        if (impatient_prompt)
            mysetenv("RLWRAP_IMPATIENT", "1");
        mysetenv("RLWRAP_INPUT_PIPE_FD", as_string(input_pipe_fds[0]));
        mysetenv("RLWRAP_OUTPUT_PIPE_FD", as_string(output_pipe_fds[1]));
        mysetenv("RLWRAP_MASTER_PTY_FD", as_string(master_pty_fd));

        close(filter_input_fd);
        close(filter_output_fd);


        if (scan_metacharacters(filter_command, "'|\"><"))  { /* if filter_command contains shell metacharacters, let the shell unglue them */
            char *exec_command = add3strings("exec", " ", filter_command);
            argv = list4("sh", "-c", exec_command, NULL);
        } else {                                              /* if not, split and feed to execvp directly (cheaper, better error message) */
            argv = split_with(filter_command, " ");
        }
        assert(argv[0]);
        if(execvp(argv[0], argv) < 0) {
            char *sorry = add3strings("Cannot exec filter '", argv[0], add2strings("': ", strerror(errno)));
            write_message(output_pipe_fds[1], TAG_ERROR, sorry, "to stdout"); /* this will kill rlwrap */
            mymicrosleep(100 * 1000); /* 100 sec for rlwrap to go away should be enough */
            exit (-1);
        }
        assert(!"not reached");

    } else {
        DEBUG_RANDOM_SLEEP;
        signal(SIGPIPE, SIG_IGN); /* ignore SIGPIPE - we have othere ways to deal with filter death */
        DPRINTF1(DEBUG_FILTERING, "spawned filter with pid %d", filter_pid);
        close (input_pipe_fds[0]);
        close (output_pipe_fds[1]);
    }
}
コード例 #24
0
ファイル: seq.c プロジェクト: kalibera/rexp
/* to match seq.default */
SEXP attribute_hidden do_seq(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    SEXP ans = R_NilValue /* -Wall */, tmp, from, to, by, len, along;
    int nargs = length(args), lf;
    Rboolean One = nargs == 1;
    R_xlen_t i, lout = NA_INTEGER;
    static SEXP do_seq_formals = NULL;    

    if (DispatchOrEval(call, op, R_SeqCharSXP, args, rho, &ans, 0, 1))
	return(ans);

    /* This is a primitive and we manage argument matching ourselves.
       We pretend this is
       seq(from, to, by, length.out, along.with, ...)
    */
    if (do_seq_formals == NULL) {
        do_seq_formals = CONS(R_NilValue, CONS(R_NilValue, list4(R_NilValue, R_NilValue, R_NilValue, R_NilValue)));
        R_PreserveObject(do_seq_formals);
        tmp = do_seq_formals;
        SET_TAG(tmp, install("from")); tmp = CDR(tmp);
        SET_TAG(tmp, install("to")); tmp = CDR(tmp);
        SET_TAG(tmp, install("by")); tmp = CDR(tmp);
        SET_TAG(tmp, R_LengthOutSymbol); tmp = CDR(tmp);
        SET_TAG(tmp, R_AlongWithSymbol); tmp = CDR(tmp);
        SET_TAG(tmp, R_DotsSymbol);
    }
    
    PROTECT(args = matchArgs(do_seq_formals, args, call));

    from = CAR(args); args = CDR(args);
    to = CAR(args); args = CDR(args);
    by = CAR(args); args = CDR(args);
    len = CAR(args); args = CDR(args);
    along = CAR(args);

    if(One && from != R_MissingArg) {
	lf = length(from);
	if(lf == 1 && (TYPEOF(from) == INTSXP || TYPEOF(from) == REALSXP)) {
	    double rfrom = asReal(from);
	    if (!R_FINITE(rfrom))
		errorcall(call, "'from' cannot be NA, NaN or infinite");
	    ans = seq_colon(1.0, rfrom, call);
	}
	else if (lf)
	    ans = seq_colon(1.0, (double)lf, call);
	else
	    ans = allocVector(INTSXP, 0);
	goto done;
    }
    if(along != R_MissingArg) {
	lout = XLENGTH(along);
	if(One) {
	    ans = lout ? seq_colon(1.0, (double)lout, call) : allocVector(INTSXP, 0);
	    goto done;
	}
    } else if(len != R_MissingArg && len != R_NilValue) {
	double rout = asReal(len);
	if(ISNAN(rout) || rout <= -0.5)
	    errorcall(call, _("'length.out' must be a non-negative number"));
	if(length(len) != 1)
	    warningcall(call, _("first element used of '%s' argument"), 
			"length.out");
	lout = (R_xlen_t) ceil(rout);
    }

    if(lout == NA_INTEGER) {
	double rfrom = asReal(from), rto = asReal(to), rby = asReal(by), *ra;
	if(from == R_MissingArg) rfrom = 1.0;
	else if(length(from) != 1) error("'from' must be of length 1");
	if(to == R_MissingArg) rto = 1.0;
	else if(length(to) != 1) error("'to' must be of length 1");
	if (!R_FINITE(rfrom))
	    errorcall(call, "'from' cannot be NA, NaN or infinite");
	if (!R_FINITE(rto))
	    errorcall(call, "'to' cannot be NA, NaN or infinite");
	if(by == R_MissingArg)
	    ans = seq_colon(rfrom, rto, call);
	else {
	    if(length(by) != 1) error("'by' must be of length 1");
	    double del = rto - rfrom, n, dd;
	    R_xlen_t nn;
	    if(!R_FINITE(rfrom))
		errorcall(call, _("'from' must be finite"));
	    if(!R_FINITE(rto))
		errorcall(call, _("'to' must be finite"));
	    if(del == 0.0 && rto == 0.0) {
		ans = to;
		goto done;
	    }
	    /* printf("from = %f, to = %f, by = %f\n", rfrom, rto, rby); */
	    n = del/rby;
	    if(!R_FINITE(n)) {
		if(del == 0.0 && rby == 0.0) {
		    ans = from;
		    goto done;
		} else
		    errorcall(call, _("invalid '(to - from)/by' in 'seq'"));
	    }
	    dd = fabs(del)/fmax2(fabs(rto), fabs(rfrom));
	    if(dd < 100 * DBL_EPSILON) {
		ans = from;
		goto done;
	    }
#ifdef LONG_VECTOR_SUPPORT
	    if(n > 100 * (double) INT_MAX)
#else
	    if(n > (double) INT_MAX)
#endif
		errorcall(call, _("'by' argument is much too small"));
	    if(n < - FEPS)
		errorcall(call, _("wrong sign in 'by' argument"));
	    if(TYPEOF(from) == INTSXP &&
	       TYPEOF(to) == INTSXP &&
	       TYPEOF(by) == INTSXP) {
		int *ia, ifrom = asInteger(from), iby = asInteger(by);
		/* With the current limits on integers and FEPS
		   reduced below 1/INT_MAX this is the same as the
		   next, so this is future-proofing against longer integers.
		*/
		/* seq.default gives integer result from
		   from + (0:n)*by
		*/
		nn = (R_xlen_t) n;
		ans = allocVector(INTSXP, nn+1);
		ia = INTEGER(ans);
		for(i = 0; i <= nn; i++)
		    ia[i] = (int)(ifrom + i * iby);
	    } else {
		nn = (int)(n + FEPS);
		ans = allocVector(REALSXP, nn+1);
		ra = REAL(ans);
		for(i = 0; i <= nn; i++)
		    ra[i] = rfrom + (double)i * rby;
		/* Added in 2.9.0 */
		if (nn > 0)
		    if((rby > 0 && ra[nn] > rto) || (rby < 0 && ra[nn] < rto))
			ra[nn] = rto;
	    }
	}
    } else if (lout == 0) {
	ans = allocVector(INTSXP, 0);
    } else if (One) {
	ans = seq_colon(1.0, (double)lout, call);
    } else if (by == R_MissingArg) {
	double rfrom = asReal(from), rto = asReal(to), rby;
	if(to == R_MissingArg) rto = rfrom + (double)lout - 1;
	if(from == R_MissingArg) rfrom = rto - (double)lout + 1;
	if(!R_FINITE(rfrom))
	    errorcall(call, _("'from' must be finite"));
	if(!R_FINITE(rto))
	    errorcall(call, _("'to' must be finite"));
	ans = allocVector(REALSXP, lout);
	if(lout > 0) REAL(ans)[0] = rfrom;
	if(lout > 1) REAL(ans)[lout - 1] = rto;
	if(lout > 2) {
	    rby = (rto - rfrom)/(double)(lout - 1);
	    for(i = 1; i < lout-1; i++) {
//		if ((i+1) % NINTERRUPT == 0) R_CheckUserInterrupt();
		REAL(ans)[i] = rfrom + (double)i*rby;
	    }
	}
    } else if (to == R_MissingArg) {
	double rfrom = asReal(from), rby = asReal(by), rto;
	if(from == R_MissingArg) rfrom = 1.0;
	if(!R_FINITE(rfrom))
	    errorcall(call, _("'from' must be finite"));
	if(!R_FINITE(rby))
	    errorcall(call, _("'by' must be finite"));
	rto = rfrom + (double)(lout-1)*rby;
	if(rby == (int)rby && rfrom <= INT_MAX && rfrom >= INT_MIN
	   && rto <= INT_MAX && rto >= INT_MIN) {
	    ans = allocVector(INTSXP, lout);
	    for(i = 0; i < lout; i++) {
//		if ((i+1) % NINTERRUPT == 0) R_CheckUserInterrupt();
		INTEGER(ans)[i] = (int)(rfrom + (double)i*rby);
	    }
	} else {
	    ans = allocVector(REALSXP, lout);
	    for(i = 0; i < lout; i++) {
//		if ((i+1) % NINTERRUPT == 0) R_CheckUserInterrupt();
		REAL(ans)[i] = rfrom + (double)i*rby;
	    }
	}
    } else if (from == R_MissingArg) {
	double rto = asReal(to), rby = asReal(by),
	    rfrom = rto - (double)(lout-1)*rby;
	if(!R_FINITE(rto))
	    errorcall(call, _("'to' must be finite"));
	if(!R_FINITE(rby))
	    errorcall(call, _("'by' must be finite"));
	if(rby == (int)rby && rfrom <= INT_MAX && rfrom >= INT_MIN
	   && rto <= INT_MAX && rto >= INT_MIN) {
	    ans = allocVector(INTSXP, lout);
	    for(i = 0; i < lout; i++) {
//		if ((i+1) % NINTERRUPT == 0) R_CheckUserInterrupt();
		INTEGER(ans)[i] = (int)(rto - (double)(lout - 1 - i)*rby);
	    }
	} else {
	    ans = allocVector(REALSXP, lout);
	    for(i = 0; i < lout; i++) {
//		if ((i+1) % NINTERRUPT == 0) R_CheckUserInterrupt();
		REAL(ans)[i] = rto - (double)(lout - 1 - i)*rby;
	    }
	}
    } else
	errorcall(call, _("too many arguments"));

done:
    UNPROTECT(1);
    return ans;
}
コード例 #25
0
ファイル: readline.c プロジェクト: bobbyzhu/rlwrap
static int
munge_line_in_editor(int count, int key)
{
  int line_number = 0, column_number = 0,  ret, tmpfile_fd, bytes_read;
  size_t tmpfilesize;
  char *p, *tmpfilename, *text_to_edit;
  char *editor_command1, *editor_command2, *editor_command3, *editor_command4,
    *line_number_as_string, *column_number_as_string;
  char *input, *rewritten_input, *rewritten_input2,  **possible_editor_commands;


  if (!multiline_separator)
    return 0;

  tmpfile_fd = open_unique_tempfile(multi_line_tmpfile_ext, &tmpfilename);

  text_to_edit =
    search_and_replace(multiline_separator, "\n", rl_line_buffer, rl_point,
                       &line_number, &column_number);
  write_patiently(tmpfile_fd, text_to_edit, strlen(text_to_edit), "to temporary file");

  if (close(tmpfile_fd) != 0) /* improbable */
    myerror(FATAL|USE_ERRNO, "couldn't close temporary file %s", tmpfilename); 

  /* find out which editor command we have to use */
  possible_editor_commands = list4(getenv("RLWRAP_EDITOR"), getenv("EDITOR"), getenv("VISUAL"), "vi +%L");
  editor_command1 = first_of(possible_editor_commands);
  line_number_as_string = as_string(line_number);
  column_number_as_string = as_string(column_number);
  editor_command2 =
    search_and_replace("%L", line_number_as_string, editor_command1, 0, NULL,
                       NULL);
  editor_command3 =
    search_and_replace("%C", column_number_as_string, editor_command2, 0,
                       NULL, NULL);
  editor_command4 = add3strings(editor_command3, " ", tmpfilename);
  

  /* call editor, temporarily restoring terminal settings */    
  if (terminal_settings_saved && (tcsetattr(STDIN_FILENO, TCSAFLUSH, &saved_terminal_settings) < 0))    /* reset terminal */
    myerror(FATAL|USE_ERRNO, "tcsetattr error on stdin");
  DPRINTF1(DEBUG_READLINE, "calling %s", editor_command4);
  if ((ret = system(editor_command4))) {
    if (WIFSIGNALED(ret)) {
      fprintf(stderr, "\n"); 
      myerror(FATAL|NOERRNO, "editor killed by signal");
    } else {    
      myerror(FATAL|USE_ERRNO, "failed to invoke editor with '%s'", editor_command4);
    }
  }
  completely_mirror_slaves_terminal_settings();
  ignore_queued_input = TRUE;  

  /* read back edited input, replacing real newline with substitute */
  tmpfile_fd = open(tmpfilename, O_RDONLY);
  if (tmpfile_fd < 0)
    myerror(FATAL|USE_ERRNO, "could not read temp file %s", tmpfilename);
  tmpfilesize = filesize(tmpfilename);
  input = mymalloc(tmpfilesize + 1);
  bytes_read = read(tmpfile_fd, input, tmpfilesize);
  if (bytes_read < 0)
    myerror(FATAL|USE_ERRNO, "unreadable temp file %s", tmpfilename);
  input[bytes_read] = '\0';
  rewritten_input = search_and_replace("\t", "    ", input, 0, NULL, NULL);     /* rlwrap cannot handle tabs in input lines */
  rewritten_input2 =
    search_and_replace("\n", multiline_separator, rewritten_input, 0, NULL, NULL);
  for(p = rewritten_input2; *p ;p++)
    if(*p >= 0 && *p < ' ') /* @@@FIXME: works for UTF8, but not UTF16 or UTF32 (Mention this in manpage?)*/ 
      *p = ' ';        /* replace all control characters (like \r) by spaces */


  rl_delete_text(0, strlen(rl_line_buffer));
  rl_point = 0;  
  clear_line();
  cr();
  my_putstr(saved_rl_state.cooked_prompt);
  rl_insert_text(rewritten_input2);
  rl_point = 0;                 /* leave cursor on predictable place */
  rl_done = 1;                  /* accept line immediately */

  


  /* wash those dishes */
  if (unlink(tmpfilename))
    myerror(FATAL|USE_ERRNO, "could not delete temporary file %s", tmpfilename);
  free(editor_command2);
  free(editor_command3);
  free(editor_command4);
  free(line_number_as_string);
  free(column_number_as_string);
  free(tmpfilename);
  free(text_to_edit);
  free(input);
  free(rewritten_input);
  free(rewritten_input2);
  
  return_key = (char)'\n';
  return 0;
}