Example #1
0
INLINE_FUN SEXP lang6(SEXP s, SEXP t, SEXP u, SEXP v, SEXP w, SEXP x)
{
    PROTECT(s);
    s = LCONS(s, list5(t, u, v, w, x));
    UNPROTECT(1);
    return s;
}
Example #2
0
/* Generate a list from the directory_files_internal output.
   Items are (INODE FILE-NAME LAST-MOD LAST-STATUS-MOD SIZE).  */
Lisp_Object
kqueue_directory_listing (Lisp_Object directory_files)
{
  Lisp_Object dl, result = Qnil;

  for (dl = directory_files; ! NILP (dl); dl = XCDR (dl)) {
    /* We ignore "." and "..".  */
    if ((strcmp (".", SSDATA (XCAR (XCAR (dl)))) == 0) ||
	(strcmp ("..", SSDATA (XCAR (XCAR (dl)))) == 0))
      continue;

    result = Fcons
      (list5 (/* inode.  */
	      Fnth (make_number (11), XCAR (dl)),
	      /* filename.  */
	      XCAR (XCAR (dl)),
	      /* last modification time.  */
	      Fnth (make_number (6), XCAR (dl)),
	      /* last status change time.  */
	      Fnth (make_number (7), XCAR (dl)),
	      /* size.  */
	      Fnth (make_number (8), XCAR (dl))),
       result);
  }
  return result;
}
Example #3
0
static _Noreturn void
json_parse_error (const json_error_t *error)
{
  Lisp_Object symbol;
#if JSON_HAS_ERROR_CODE
  switch (json_error_code (error))
    {
    case json_error_premature_end_of_input:
      symbol = Qjson_end_of_file;
      break;
    case json_error_end_of_input_expected:
      symbol = Qjson_trailing_content;
      break;
    default:
      symbol = Qjson_parse_error;
      break;
    }
#else
  if (json_has_suffix (error->text, "expected near end of file"))
    symbol = Qjson_end_of_file;
  else if (json_has_prefix (error->text, "end of file expected"))
    symbol = Qjson_trailing_content;
  else
    symbol = Qjson_parse_error;
#endif
  xsignal (symbol,
           list5 (json_build_string (error->text),
                  json_build_string (error->source), make_natnum (error->line),
                  make_natnum (error->column), make_natnum (error->position)));
}
/*
	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);
}
Example #5
0
int main() {
    SEXP obj;
    SEXP stream;
    SEXP op, args;
    
    obj = R_NilValue;
    
    PROTECT(op = mkChar("file"));
    PROTECT(args = list5(
        PROTECT(mkChar("./data.Rdata")),
        PROTECT(mkChar("w")),
        PROTECT(ScalarLogical(1)),
        PROTECT(mkChar("native.enc")),
        PROTECT(ScalarLogical(0))
    ));
    PROTECT(stream = do_url(R_NilValue, op, args, R_NilValue));
    
    R_serialize(
        obj,
        stream,
        PROTECT(ScalarLogical(1)),
        R_NilValue,
        R_NilValue,
        PROTECT(mkChar("base"))
    );
    
    do_close(
        R_NilValue,
        PROTECT(mkChar("close")),
        PROTECT(list2(
            stream,
            PROTECT(mkChar("rw"))
        ))
    );
    
    UNPROTECT(13);
}
Example #6
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))) &&
	  !g_file_monitor_is_cancelled (monitor))
	g_file_monitor_cancel (monitor);
    }

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

  return TRUE;
}
Example #7
0
static void
x_own_selection (Lisp_Object selection_name, Lisp_Object selection_value,
		 Lisp_Object frame)
{
  struct frame *f = XFRAME (frame);
  struct mac_display_info *dpyinfo = FRAME_MAC_DISPLAY_INFO (f);
  Time timestamp = last_event_timestamp;
  OSStatus err;
  Selection sel;
  struct gcpro gcpro1, gcpro2;
  Lisp_Object rest, handler_fn, value, target_type;

  GCPRO2 (selection_name, selection_value);

  block_input ();

  err = mac_get_selection_from_symbol (selection_name, 1, &sel);
  if (err == noErr && sel)
    {
      /* Don't allow a quit within the converter.
	 When the user types C-g, he would be surprised
	 if by luck it came during a converter.  */
      ptrdiff_t count = SPECPDL_INDEX ();
      specbind (Qinhibit_quit, Qt);

      for (rest = Vselection_converter_alist; CONSP (rest); rest = XCDR (rest))
	{
	  if (!(CONSP (XCAR (rest))
		&& (target_type = XCAR (XCAR (rest)),
		    SYMBOLP (target_type))
		&& mac_valid_selection_target_p (target_type)
		&& (handler_fn = XCDR (XCAR (rest)),
		    SYMBOLP (handler_fn))))
	    continue;

	  if (!NILP (handler_fn))
	    value = call3 (handler_fn, selection_name,
			   target_type, selection_value);
	  else
	    value = Qnil;

	  if (NILP (value))
	    continue;

	  if (mac_valid_selection_value_p (value, target_type))
	    err = mac_put_selection_value (sel, target_type, value);
	  else if (CONSP (value)
		   && EQ (XCAR (value), target_type)
		   && mac_valid_selection_value_p (XCDR (value), target_type))
	    err = mac_put_selection_value (sel, target_type, XCDR (value));
	}

      unbind_to (count, Qnil);
    }

  unblock_input ();

  UNGCPRO;

  if (sel && err != noErr)
    error ("Can't set selection");

  /* Now update the local cache */
  {
    Lisp_Object selection_data;
    Lisp_Object ownership_info;
    Lisp_Object prev_value;

    if (sel)
      {
	block_input ();
	ownership_info = mac_get_selection_ownership_info (sel);
	unblock_input ();
      }
    else
      ownership_info = Qnil; 	/* dummy value for local-only selection */
    selection_data = list5 (selection_name, selection_value,
			    INTEGER_TO_CONS (timestamp), frame, ownership_info);
    prev_value = LOCAL_SELECTION (selection_name, dpyinfo);

    tset_selection_alist
      (dpyinfo->terminal,
       Fcons (selection_data, dpyinfo->terminal->Vselection_alist));

    /* If we already owned the selection, remove the old selection
       data.  Don't use Fdelq as that may QUIT.  */
    if (!NILP (prev_value))
      {
	/* We know it's not the CAR, so it's easy.  */
	Lisp_Object rest = dpyinfo->terminal->Vselection_alist;
	for (; CONSP (rest); rest = XCDR (rest))
	  if (EQ (prev_value, Fcar (XCDR (rest))))
	    {
	      XSETCDR (rest, XCDR (XCDR (rest)));
	      break;
	    }
      }
  }
}
Example #8
0
/**
****************************************************************************************************
* @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;
}
Example #9
0
SEXP call_slra( SEXP _p, SEXP _s, SEXP _r, SEXP _opt, 
                SEXP _compute_ph, SEXP _compute_Rh ) {
  char str_buf[STR_MAX_LEN];
  
  /* Required parameters */
  gsl_vector vec_ml = SEXP2vec(getListElement(_s, ML_STR)), 
      p_in = SEXP2vec(_p), vec_nk = SEXP2vec(getListElement(_s, NK_STR)),
      vec_wk = SEXP2vec(getListElement(_s, WK_STR));
  gsl_matrix phi = SEXP2mat(getListElement(_s, PERM_STR));
  int np = compute_np(&vec_ml, &vec_nk);
  int r = *INTEGER(_r), compute_ph = !!(*INTEGER(_compute_ph)),
      compute_Rh = !!(*INTEGER(_compute_Rh)), compute_vh = 1;
  /* Optional parameters */
  OptimizationOptions opt;
  getRSLRADispOption(_opt);
  getRSLRAMethodOption(&opt, _opt);
  getRSLRAOption(opt, _opt, maxiter, asInteger);
  getRSLRAOption(opt, _opt, epsabs, asReal);
  getRSLRAOption(opt, _opt, epsrel, asReal);
  getRSLRAOption(opt, _opt, epsgrad, asReal);
  getRSLRAOption(opt, _opt, epsx, asReal);
  getRSLRAOption(opt, _opt, step, asReal);
  getRSLRAOption(opt, _opt, tol, asReal);
  getRSLRAOption(opt, _opt, reggamma, asReal);
  getRSLRAOption(opt, _opt, ls_correction, asReal);
  getRSLRAOption(opt, _opt, maxx, asReal);
  SEXP _r_ini = getListElement(_opt, RINI_STR);

  /* Create output values */  
  SEXP _p_out = R_NilValue, _r_out = R_NilValue, _v_out = R_NilValue;
  
  Structure *myStruct = NULL;
  VarproFunction *myF = NULL;
  int was_error = 0;
  try {
    /* Create output info */
    myStruct = createMosaicStructure(&vec_ml, &vec_nk, vecChkNIL(vec_wk));  
    int m = phi.size2;
    if (compute_ph) {
      PROTECT(_p_out = allocVector(REALSXP, np));
    }
    if (compute_Rh) {
      PROTECT(_r_out = allocMatrix(REALSXP, (m-r), m));
    }
    if (compute_vh) {
      PROTECT(_v_out = allocMatrix(REALSXP, (m-r)*r, (m-r)*r));
    }    
    gsl_matrix rini = SEXP2mat(_r_ini), r_out = SEXP2mat(_r_out),
               v_out = SEXP2mat(_v_out);
    gsl_vector p_out = SEXP2vec(_p_out);
    
    if (rini.data != NULL && (rini.size2 != (m - r) || rini.size1 != m)) {
      throw new Exception("Incorrect Rini\n");   
    }
 
    myF = new VarproFunction(vecChkNIL(p_in), myStruct, m-r, &phi);
    
    slra(myF, &opt, matChkNIL(rini), NULL, 
         vecChkNIL(p_out), matChkNIL(r_out), matChkNIL(v_out));
  } catch (Exception *e) {
    strncpy(str_buf, e->getMessage(), STR_MAX_LEN - 1);
    str_buf[STR_MAX_LEN - 1] = 0;
    was_error = 1;
    delete e;
  }   
  
  if (myStruct != NULL) {
    delete myStruct;
  }
  
  if (myF != NULL) {
    delete myF;
  }
  
  if (was_error) {
    error(str_buf);
  }

  SEXP _res, _info;
  PROTECT(_info = list5(ScalarInteger(opt.iter), ScalarReal(opt.time), 
                        ScalarReal(opt.fmin), _r_out, _v_out));
  {
    const char *names[] = { FMIN_STR, ITER_STR, TIME_STR, RH_STR, VH_STR };
    for (int i = 0; i < sizeof(names) / sizeof(names[0]); i++) {
      SET_TAG(nthcdr(_info, i), install(names[i]));
    }  
  }                        
                          
  PROTECT(_res = list2(_p_out, _info));
  SET_TAG(_res, install(PH_STR));
  SET_TAG(CDR(_res), install(INFO_STR));
  UNPROTECT(2 + compute_ph + compute_Rh + compute_vh);
  
  Log::deleteLog();
  
  return _res;
}