Exemplo n.º 1
0
Arquivo: dump.c Projeto: barak/lush
void undump(char *s)
{
   at *atf = OPEN_READ(s,0);
   FILE *f = Gptr(atf);

   int magic = readmagic32(f);
   int version = read32(f);
   if ( magic != DUMPMAGIC )
      error(NIL, "incorrect dump file format", NIL);
   if ( version > DUMPVERSION )
      error(NIL, "dump file format version not supported", NIL);
   
   /* The macro character map */
   size_t sr = fread(char_map,1,256,f);
   if (sr < 256 || feof(f) || ferror(f))
      error(NIL, "corrupted dump file (1)",NIL);
   
   /* The unified list */
   at *val, *sym, *p = bread(f, NIL);
   while (CONSP(p)) {
      if (CONSP(Car(p))) {
         sym = Caar(p);
         val = Cdar(p);
         ifn (SYMBOLP(sym))
            error(NIL, "corrupted dump file (4)", NIL);
         var_SET(sym, val);
      } else if (SYMBOLP(Car(p)))
         var_lock(Car(p));
      val = p;
      p = Cdr(p);
      Cdr(val) = NIL;
   }
   /* define special symbols */
   at_NULL = var_get(named("NULL"));
}
Exemplo n.º 2
0
/* timer_fire --
   Sends all current timer events.
   Returns number of milliseconds until
   next timer event (or a large number)
*/
int
timer_fire(void)
{
  evtime_t now;
  evtime_now(&now);
  while (timers && evtime_cmp(&now,&timers->date)>=0)
    {
      struct event_timer *ti = timers;
      at *p = cons(named("timer"), cons(new_gptr(ti), NIL));
      timers = ti->next;
      event_add(ti->handler, p);
      UNLOCK(p);
      if (ti->period.sec>0 || ti->period.msec>0)
        {
          /* Periodic timer shoot only once per call */
          while(evtime_cmp(&now,&ti->date) >= 0)
            evtime_add(&ti->date,&ti->period,&ti->date);
          ti_insert(ti);
        }
      else
        {
          /* One shot timer */
          free(ti);
        }
    }
  if (timers)
    {
      evtime_t diff;
      evtime_sub(&timers->date, &now, &diff);
      if (diff.sec < 24*3600)
        return diff.sec * 1000 + diff.msec;
    }
  return 24*3600*1000;
}
Exemplo n.º 3
0
TypePtr Parser::maybeType(bool se)
{
	if(token == TIdent)
	{
		TypePtr t = resolveIdentType(tokenStr);
		if(t)
			next(se);
		return t;
	}
	else if(token == TTypeIdent)
	{
		IntrusiveRefCntPtr<TypeDataNamed> named(
			new TypeDataNamed(nextIdent(se)));

		if(test(TLParen))
		{
			do
			{
				named->typeAssignment.push_back(typeName(false));
			}
			while(test(TComma));

			expect(TRParen);
		}

		return TypePtr(named);
	}

	parseError();
	return TypePtr();
}
Exemplo n.º 4
0
void Argv::startGroup(const std::string& groupdesc,bool visible)
{
#ifdef BOOST_PO
	std::shared_ptr<boost::program_options::options_description> named(new boost::program_options::options_description(groupdesc));
	m_options.push_back(std::make_pair(named,visible));
	m_curidx=m_options.size()-1;
#endif
}
Exemplo n.º 5
0
void cg_grad_adaptor(double *g, double *x, int n)
{
   static at *call = NIL;
   static int nx = -1;
   static storage_t *stx = NULL;
   static storage_t *stg = NULL;
   static at *(*listeval)(at *, at *) = NULL;

   if (n == -1) {
      /* initialize */
      at *x0 = var_get(named("x0"));
      at *vargs = var_get(named("vargs"));
      at *g = var_get(named("g"));
      ifn (x0)
         error(NIL, "x0 not found", NIL);
      ifn (INDEXP(x0) && IND_STTYPE((index_t *)Mptr(x0)))
         error(NIL, "x0 not a double index", x0);
      ifn (g)
         error(NIL, "g not found", NIL);
      
      listeval = Class(g)->listeval;
      index_t *ind = Mptr(x0);
      nx = storage_nelems(IND_ST(ind));
      stx = new_storage(ST_DOUBLE);
      stx->flags = STS_FOREIGN;
      stx->size = nx;
      stx->data = (char *)-1;

      stg = new_storage(ST_DOUBLE);
      stg->flags = STS_FOREIGN;
      stg->size = nx;
      stg->data = (char *)-1;
      call = new_cons(g, 
                      new_cons(NEW_INDEX(stg, IND_SHAPE(ind)),
                               new_cons(NEW_INDEX(stx, IND_SHAPE(ind)),
                                        vargs)));
   } else {
      if (n != nx)
         error(NIL, "vector of different size expected", NEW_NUMBER(n));
      stx->data = x;
      stg->data = g;
      listeval(Car(call), call);
   }
}
Exemplo n.º 6
0
double cg_value_adaptor(double *x, int n)
{
   static at *call = NIL;
   static int nx = -1;
   static storage_t *st = NULL;
   static at *(*listeval)(at *, at *) = NULL;

   if (n == -1) {
      /* initialize */
      at *x0 = var_get(named("x0"));
      at *vargs = var_get(named("vargs"));
      at *f = var_get(named("f"));
      ifn (x0)
         error(NIL, "x0 not found", NIL);
      ifn (INDEXP(x0) && IND_STTYPE((index_t *)Mptr(x0)))
         error(NIL, "x0 not a double index", x0);
      ifn (f)
         error(NIL, "f not found", NIL);

      listeval = Class(f)->listeval;
      index_t *ind = Mptr(x0);
      nx = storage_nelems(IND_ST(ind));
      st = new_storage(ST_DOUBLE);
      st->flags = STS_FOREIGN;
      st->size = nx;
      st->data = (char *)-1;

      call = new_cons(f, new_cons(NEW_INDEX(st, IND_SHAPE(ind)), vargs));
      return NAN;
         
   } else {
      if (n != nx)
         error(NIL, "vector of different size expected", NEW_NUMBER(n));
      st->data = x;
      return Number(listeval(Car(call), call));
   }
}
Exemplo n.º 7
0
std::string NBT_Tag_List::serialize()
{
   std::stringstream str;
   
   if(named())
      str << "List(" << name() << "; " << tagNames[itemType]+4 << ") {\n";
   else
      str << "List(" << this << "; " << tagNames[itemType]+4 << ") {\n";
 
   for(auto &item: item_list)
   {
      str << item->serialize() << "; ";
   }
   str << "}\n";
   return str.str();
}
Exemplo n.º 8
0
static at * 
event_to_list(int event, int xd, int yd, int xu, int yu, int *pmods)
{
  *pmods = -1;
  /* events that do not update evshift and evcontrol */
  if (event == EVENT_MOUSE_UP) 
    return cons(named("mouse-up"), four_integers(xd,yd,xu,yu));
  if (event == EVENT_MOUSE_DRAG) 
    return cons(named("mouse-drag"), four_integers(xd,yd,xu,yu));
  if (event == EVENT_RESIZE)
    return cons(named("resize"), two_integers(xd,yd));
  if (event == EVENT_DELETE) 
    return cons(named("delete"),NIL);
  if (event == EVENT_SENDEVENT)
    return cons(named("sendevent"), two_integers(xd,yd));
  if (event == EVENT_EXPOSE)
    return cons(named("expose"), two_integers(xd,yd));
  if (event == EVENT_GLEXPOSE)
    return cons(named("glexpose"), two_integers(xd,yd));
  if (event >= EVENT_ASCII_MIN && event <= EVENT_ASCII_MAX) 
    {
      char keyevent[2];
      keyevent[0] = EVENT_TO_ASCII(event);
      keyevent[1] = 0;
      return cons(new_string(keyevent), two_integers(xd,yd));
    }
  /* events that update evshift and evcontrol */
  *pmods = 0;
  if (xu) 
    *pmods |= 1;  /* shift */
  if (yu) 
    *pmods |= 2;  /* ctrl  */
  if (event == EVENT_MOUSE_DOWN)
    return cons(named("mouse-down"), two_integers(xd,yd)); 
  if (event == EVENT_HELP)
    return cons(named("help"), two_integers(xd,yd)); 
  if (event == EVENT_ARROW_UP)
    return cons(named("arrow-up"), two_integers(xd,yd)); 
  if (event == EVENT_ARROW_RIGHT)
    return cons(named("arrow-right"), two_integers(xd,yd)); 
  if (event == EVENT_ARROW_DOWN)
    return cons(named("arrow-down"), two_integers(xd,yd)); 
  if (event == EVENT_ARROW_LEFT)
    return cons(named("arrow-left"), two_integers(xd,yd)); 
  if (event == EVENT_FKEY)
    return cons(named("fkey"), two_integers(xd,yd)); 
  /* default */
  return NIL;
}
Exemplo n.º 9
0
/*
	Entry point
*/
int main(int argc, char** argv)
{

	/*
	 * Initialize Logging
	 */
	google::InitGoogleLogging("");

	/*
	 * Environment Wrangling
	 */
	const char *home  = std::getenv("HOME");
	boost::program_options::variables_map vm;
	std::string name = "";
	boost::filesystem::path config_file;

	/*
	 *  Define argument parsing description for program_options
	 */

	/*
	 * Parse arguments from command line and configuration file
	 */
	boost::program_options::options_description rr( "World Router" );
	boost::program_options::options_description glb ( "Global Options " );
	boost::program_options::options_description all ( "World Router Options" );
	boost::program_options::options_description named ("Named Options");

	rr.add_options()
			( "help,h", "Display help message" )
			( "name,n", boost::program_options::value<std::string>(),"Name of Router. \nDefault: Required")
			( "config,c", boost::program_options::value<std::string>(), "Config File: \nDefault: Required")
			( "primary,p", boost::program_options::value<std::string>()->implicit_value("true"), "Primary Broker. \nDefault: false")
			;

	glb.add_options()
			( "global.broker", boost::program_options::value<std::string>(), "" )
			;

	/*
	 * Create groups
	 */
	all.add(rr);
	all.add(glb);

	/*
	 * Create WorldRouter Object
	 *
	 */
	WorldRouter router;

    try {

    	/*
    	 *  Checked Argument Wrangling
    	 */
		boost::program_options::store(
				boost::program_options::parse_command_line(argc, argv, all),
				vm
				);

		boost::program_options::notify(vm);

		/*
		 * Special cases
		 */
		if ( vm.count("help") )
		{
			std::cout << rr << std::endl;
			return 1;
		}

		/*
		 * Name / Id must
		 * Might attempt to register with msg broker a named
		 * queue
		 */
		if ( vm.count("name") )
			name = vm["name"].as<std::string>();

		if ( vm.count("config") )
			config_file = vm["config"].as<std::string>();

		if ( name.empty() || name == "" )
			throw std::runtime_error("router name is required, specify with --name");

		if ( ! boost::filesystem::exists(config_file))
			throw std::runtime_error("config file [" + config_file.string() + "] does not exist");

    	/*
    	 * Parse the config file
    	 */
		std::ifstream config_file_stream(config_file.string());

		/*
		 * Because We want to be able to different sections based on name
		 */
		named.add_options()
				( (name+".master.q,i").c_str(), boost::program_options::value<std::string>(), "In Queue. \nDefault: master.q")
				( (name+".internal.wrq,i").c_str(), boost::program_options::value<std::string>(), "In Queue. \nDefault: internal.wrq")
				;
		all.add(named);

		/*
		 * And we want the named to only be available via the config file
		 */
		boost::program_options::store(
				boost::program_options::parse_config_file(config_file_stream, all, true),
				vm
				);
		boost::program_options::notify(vm);

		/*
		 * Register Configuration
		 */
		router.registerConfig(vm);

    	/*
    	 * Create session
    	 *   1) establish connection to broker
    	 *   2) create session
    	 *   3) create queue if primary ( reciever )
    	 *      if primary, queue must not be present
    	 *      if NOT primary, queue MUST be present
    	 *
    	 */
		router.establishSession();

		router.run();

    } catch(const std::exception& error) {
		std::cerr << "Exception: " << error.what() << std::endl;
		google::FlushLogFiles(google::INFO);
    }

    LOG(INFO) << "All Done!";
	google::FlushLogFiles(google::INFO);
	return 0;
}
Exemplo n.º 10
0
void UMLEditor::layout(){
  mainPanel = new QWidget;
  mainLayout = new QHBoxLayout;

  btnGroup = new QButtonGroup(this);
  btnGroup->setExclusive(true);

  SelectButton *btn = new SelectButton(canvas);
  ClassBoxButton *btn2 = new ClassBoxButton(canvas);
  btnGroup->addButton(btn);
  btnGroup->addButton(btn2);
  buttons.push_back(new SelectButton(canvas));
  buttons.push_back(new ClassBoxButton(canvas));
  buttons.push_back(new UseCaseButton(canvas));
  buttons.push_back(new AssLineButton(canvas));
  buttons.push_back(new GenLineButton(canvas));
  buttons.push_back(new ComLineButton(canvas));
  buttons[0]->pressed();

  for(std::vector<Button*>::size_type i = 0; i != buttons.size(); i++) {
    btnGroup->addButton(buttons[i]);
  }

  toolPanel = new QWidget;
  toolPanelLayout = new QGridLayout;
  toolPanelLayout->setAlignment(Qt::AlignTop);

  for(std::vector<QToolButton*>::size_type i = 0; i != buttons.size(); i++) {
    toolPanelLayout->addWidget(buttons[i], i, 0, Qt::AlignHCenter);
  }

  toolPanel->setLayout(toolPanelLayout);
  toolPanel->setMinimumWidth(100);

  menubar = new QMenuBar;
  file =  menubar->addMenu(tr("&File"));
  edit =  menubar->addMenu(tr("&Edit"));

  exit = new QAction(tr("Exit"), mainPanel);
  this->connect(exit, SIGNAL(triggered()), this, SLOT(close()));
  group = new QAction(tr("Group"), mainPanel);
  this->connect(group, SIGNAL(triggered()), canvas, SLOT(group()));
  ungroup = new QAction(tr("UnGroup"), mainPanel);
  this->connect(ungroup, SIGNAL(triggered()), canvas, SLOT(ungroup()));
  named = new QAction(tr("Change Object Name"), mainPanel);
  this->connect(named, SIGNAL(triggered()), canvas, SLOT(named()));

  file->addAction(exit);
  edit->addAction(group);
  edit->addAction(ungroup);
  edit->addAction(named);

  canvas->setSceneRect(QRectF(-200,-200,400,400));
  //view->setDragMode(QGraphicsView::RubberBandDrag);
  view->setScene(canvas);
  view->resize(400,400);

  mainLayout->addWidget(toolPanel,0);
  mainLayout->setAlignment(toolPanel,Qt::AlignTop);
  mainLayout->addWidget(view,1);
  mainLayout->setMenuBar(menubar);

  mainPanel->setLayout(mainLayout);
  setCentralWidget(mainPanel);
}