Beispiel #1
0
bool PerfGroup::add(const uint64_t currTime, Buffer *const buffer, const int key, const __u32 type, const __u64 config, const __u64 sample, const __u64 sampleType, const int flags) {
	const int effectiveType = getEffectiveType(type, flags);

	// Does a group exist for this already?
	if (!(flags & PERF_GROUP_LEADER) && mLeaders[effectiveType] < 0) {
		// Create it
		if (effectiveType == PERF_TYPE_HARDWARE) {
			if (!createCpuGroup(currTime, buffer)) {
				return false;
			}
		} else {
			// Non-CPU PMUs are sampled every 100ms for Sample Rate: None and EBS, otherwise they would never be sampled
			const uint64_t timeout = gSessionData.mSampleRate > 0 && !gSessionData.mIsEBS ? 1000000000UL / gSessionData.mSampleRate : 100000000UL;
			mLeaders[effectiveType] = doAdd(currTime, buffer, INT_MAX-effectiveType, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK, timeout, PERF_SAMPLE_READ, PERF_GROUP_LEADER);
			if (mLeaders[effectiveType] < 0) {
				return false;
			}
		}
	}

	if (!(flags & PERF_GROUP_LEADER) && effectiveType != PERF_TYPE_HARDWARE && (flags & PERF_GROUP_PER_CPU)) {
		logg.logError("'uncore' counters are not permitted to be per-cpu");
		handleException();
	}

	return doAdd(currTime, buffer, key, type, config, sample, sampleType, flags) >= 0;
}
Beispiel #2
0
void test_commands(void**) {
    Commands_init();

    g_intValue = 0;

    assert_int_equal(g_intValue, 0);

    doAdd(1);

    assert_int_equal(g_intValue, 1);

    doAdd(1);
    doAdd(1);

    assert_int_equal(g_intValue, 3);

    Commands_undo();

    assert_int_equal(g_intValue, 2);

    Commands_undo();
    Commands_undo();

    assert_int_equal(g_intValue, 0);

    Commands_redo();

    assert_int_equal(g_intValue, 1);

    Commands_redo();

    Commands_clear();
}
bool VirtualizeAddSub(CodeChunk *code, DISASM *disasm, bool isAdd) {

	pushCalculateScaledAddress(code, disasm, &disasm->Argument2);
	if ((disasm->Argument2.ArgType & MEMORY_TYPE) != 0) {
		doDeref(code, disasm);
	}

	pushCalculateScaledAddress(code, disasm, &disasm->Argument1);
	if ((disasm->Argument1.ArgType & MEMORY_TYPE) != 0) {
		doDeref(code, disasm);
	}

	if (isAdd) {
		doAdd(code, disasm);
	}
	else {
		doSub(code, disasm);
	}

	if ((disasm->Argument1.ArgType & MEMORY_TYPE) != 0) {
		pushCalculateScaledAddress(code, disasm, &disasm->Argument1);
		doMove(code, disasm);
	}
	else if ((disasm->Argument1.ArgType & REGISTER_TYPE) != 0) {
		doVmPopReg(code, disasm, getSingleRegister(disasm->Argument1.ArgType));
	}

	return true;
}
Beispiel #4
0
SubTabController::SubTabController(SubTabView* subTabView)
  : OSQObjectController(),
    m_subTabView(subTabView)
{
  addQObject(subTabView);

  bool isConnected = false;
  isConnected = connect(subTabView, SIGNAL(itemSelected(OSItem*)),
                        this, SLOT(selectItem(OSItem*)));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(itemRemoveClicked(OSItem*)),
                        this, SLOT(removeItem(OSItem*)));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(itemReplacementDropped(OSItem*, const OSItemId&)),
                        this, SLOT(replaceItem(OSItem*, const OSItemId&)));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(selectionCleared()),
                        this, SLOT(clearSelection()));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(itemDropped(const OSItemId&)),
                        this, SLOT(handleDrop(const OSItemId&)));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(addClicked()),
                        this, SLOT(doAdd()));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(copyClicked()),
                        this, SLOT(doCopy()));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(removeClicked()),
                        this, SLOT(doRemove()));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(purgeClicked()),
                        this, SLOT(doPurge()));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(openBclDlgClicked()),
                        this, SIGNAL(openBclDlgClicked()));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(openLibDlgClicked()),
                        this, SIGNAL(openLibDlgClicked()));
  BOOST_ASSERT(isConnected);

  isConnected = connect(subTabView, SIGNAL(dropZoneItemClicked(OSItem*)),
                        this, SLOT(inspectItem(OSItem*)));
  BOOST_ASSERT(isConnected);
}
Beispiel #5
0
bool PerfGroup::createCpuGroup(const uint64_t currTime, Buffer *const buffer) {
	if (mSchedSwitchId < 0) {
		DynBuf b;
		mSchedSwitchId = PerfDriver::getTracepointId(SCHED_SWITCH, &b);
		if (mSchedSwitchId < 0) {
			logg.logMessage("Unable to read sched_switch id");
			return false;
		}
	}

	mLeaders[PERF_TYPE_HARDWARE] = doAdd(currTime, buffer, schedSwitchKey, PERF_TYPE_TRACEPOINT, mSchedSwitchId, 1, PERF_SAMPLE_READ | PERF_SAMPLE_RAW, PERF_GROUP_MMAP | PERF_GROUP_COMM | PERF_GROUP_TASK | PERF_GROUP_SAMPLE_ID_ALL | PERF_GROUP_PER_CPU | PERF_GROUP_LEADER | PERF_GROUP_CPU);
	if (mLeaders[PERF_TYPE_HARDWARE] < 0) {
		return false;
	}

	if (gSessionData.mSampleRate > 0 && !gSessionData.mIsEBS && doAdd(currTime, buffer, INT_MAX-PERF_TYPE_HARDWARE, PERF_TYPE_SOFTWARE, PERF_COUNT_SW_CPU_CLOCK, 1000000000UL / gSessionData.mSampleRate, PERF_SAMPLE_TID | PERF_SAMPLE_IP | PERF_SAMPLE_READ, PERF_GROUP_PER_CPU | PERF_GROUP_CPU) < 0) {
		return false;
	}

	return true;
}
Beispiel #6
0
IOperand *TOperand<T>::operator+(const IOperand &other) const
{
    const std::string &left = this->toString();
    const std::string &right = other.toString();

    if (getPrecision() >= other.getPrecision())
        return doAdd(getType(), left, right);
    else
    {
        IOperand *current = SOperandMaker::createOperand(other.getType(), left);
        IOperand *r = (*current + other);
        delete current;
        return r;
    }
}
Beispiel #7
0
os_boolean
in_objectInit(
    in_object _this,
    in_objectKind kind,
    in_objectDeinitFunc deinit)
{
    assert(_this);
    assert(kind > IN_OBJECT_KIND_INVALID);
    assert(kind < IN_OBJECT_KIND_COUNT);
    assert(deinit);

    _this->confidence = IN_OBJECT_CONFIDENCE;
    _this->kind = kind;
    _this->deinit = deinit;
    _this->refCount = 1;

    assert(doAdd(kind));

    return OS_TRUE;
}
Beispiel #8
0
void doTopDown(int a,int b)
{
	printf("Enter Your Choise: \n"
			"1. Add\t 2.Subtract\t 3.Multiply\t4.Divide \n");

	int choise;
	scanf("%d",&choise);
	switch(choise)
	{
		case 1:doAdd(a,b);
			break;
		case 2:doSub(a,b);
			break;
		case 3:doMult(a,b);
			break;
		case 4:doDiv(a,b);
			break;
		default: printf("Wrong Choise \n");
	}
}
Beispiel #9
0
void
d_objectInit(
    d_object object,
    d_kind kind,
    d_objectDeinitFunc deinit)
{
    assert(object);

    if(object){
        object->confidence = D_CONFIDENCE;
        object->kind       = kind;
        object->refCount   = 1;
        object->deinit     = deinit;
#if CHECK_REF
        if (kind == CHECK_REF_TYPE) {
            UT_TRACE("\n\n============ New(%p) =============\n", (void*)object);
        }
#endif
        assert(doAdd(kind));
    }
}
Beispiel #10
0
const Integer Integer::add(const Integer a) const {
	std::stack<int> first;
	std::stack<int> second;
  std::stack<int> val;
  std::stack<int> one;
  std::stack<int> temp;
	std::string ret;

	const int thisLength = this->bytes.length();
	const int aLength = a.bytes.length();
	const int longest = thisLength > aLength ? thisLength : aLength;

	for (int i = 0; i < longest - 1; ++i) {
		one.push(0);
	}
	one.push(1);

	if (this->positive == a.positive) {
		for (int i = longest; i > 0; --i) {
			if (i <= thisLength) {
				first.push(charToInt(this->bytes.at(thisLength - i)));
			} else {
				first.push(0);
			}
			if (i <= aLength) {
				second.push(charToInt(a.bytes.at(aLength - i)));
			} else {
				second.push(0);
			}
	  }
		val = doAdd(first, second);
		if (!val.empty() && val.top() != 1) {
			val.pop();
		}
		ret.push_back(this->positive ? '+' : '-');
	 	while (!val.empty()) {
			ret.push_back(intToChar(val.top()));
			val.pop();
		}
	} else {
		if (this->abs().compareTo(a.abs()) == 0) {
			return Integer::ZERO;
		}
		if (this->positive) {
			for (int i = longest; i > 0; --i) {
				if (i <= thisLength) {
					first.push(ninesComp(charToInt(this->bytes.at(thisLength - i))));
				} else {
					first.push(9);
				}
				if (i <= aLength) {
					second.push(charToInt(a.bytes.at(aLength - i)));
				} else {
					second.push(0);
				}
			}
		} else {
			for (int i = longest; i > 0; --i) {
				if (i <= thisLength) {
					first.push(charToInt(this->bytes.at(thisLength - i)));
				} else {
					first.push(0);
				}
				if (i <= aLength) {
					second.push(ninesComp(charToInt(a.bytes.at(aLength - i))));
				} else {
					second.push(9);
				}		
			}
		}
		val = doAdd(first, second);
		if (!val.empty()) {
			if (val.top() == 1) {
				ret.push_back('-');
				val.pop();
				while (!val.empty()) {
					temp.push(val.top());
					val.pop();
				}
				val = doAdd(temp, one);
				if (!val.empty()) {
					val.pop();
				}
				while (!val.empty()) {
					ret.push_back(intToChar(val.top()));
					val.pop();
				}
			} else {
				ret.push_back('+');
				val.pop();
				while (!val.empty()) {
					ret.push_back(intToChar(ninesComp(val.top())));
					val.pop();
				}
			}
		}
	}
  return Integer(ret);
}
void MechListBoxItem::update()
{
	char text[32];
	int oldMechCount = mechCount;
	if ( !pMech )
	{
		mechCount = 0;
		return;
	}
	mechCount = LogisticsData::instance->getVariantsInInventory( pMech->getVariant(), bIncludeForceGroup );
	if ( oldMechCount != mechCount )
	{
		animTime = .0001f;
	}
	sprintf( text, "%ld", mechCount );
	countText.setText( text );
	if ( animTime )
	{
		if ( animTime < .25f 
			|| ( animTime > .5f && animTime <= .75f ) )
		{
			countText.setColor( 0 );
		}
		else 
			countText.setColor( 0xffffffff );

		animTime += g_deltaTime;
		
		if ( animTime > 1.0f )
			animTime = 0.f;
		
	}

	bool isInside = pointInside( userInput->getMouseX(), userInput->getMouseY() );


	for ( int i = 0; i < ANIMATION_COUNT; i++ )
		animations[bOrange][i].update();

	if ( state == aListItem::SELECTED ) 
	{
		for ( int i = 0; i < ANIMATION_COUNT; i++ )
			animations[bOrange][i].setState( aAnimGroup::PRESSED );

	//	if ( userInput->isLeftClick() && isInside )
	//		setMech();
		
		if ( userInput->isLeftDrag() &&
			pointInside( userInput->getMouseDragX(), userInput->getMouseDragY() ) )
			startDrag();

	}
	else if ( state == aListItem::HIGHLITE )
	{
		for ( int i = 0; i < ANIMATION_COUNT; i++ )
			animations[bOrange][i].setState( aAnimGroup::HIGHLIGHT );

	}
	else if ( state == aListItem::DISABLED &&  isShowing() )
	{
		if ( userInput->isLeftClick() && isInside )
		{
			soundSystem->playDigitalSample( LOG_WRONGBUTTON );	
			setMech(); // need to call explicitly
		}

		for ( int i = 0; i < ANIMATION_COUNT; i++ )
			animations[bOrange][i].setState( aAnimGroup::DISABLED );
	}
	else
	{
		for ( int i = 0; i < ANIMATION_COUNT; i++ )
			animations[bOrange][i].setState( aAnimGroup::NORMAL );
	}

	if ( userInput->isLeftDoubleClick() && isInside && state != aListItem::DISABLED && isShowing() )
		doAdd();

	aObject::update();
}
Beispiel #12
0
void GroundProgramBuilder::add()
{
	switch(stack_->type)
	{
		case LIT:
		{
			stack_->lits.push_back(Lit::create(stack_->type, stack_->vals.size() - stack_->n - 1, stack_->n));
			break;
		}
		case TERM:
		{
			if(stack_->n > 0)
			{
				ValVec vals;
				std::copy(stack_->vals.end() - stack_->n, stack_->vals.end(), std::back_inserter(vals));
				stack_->vals.resize(stack_->vals.size() - stack_->n);
				uint32_t name = stack_->vals.back().index;
				stack_->vals.back()  = Val::func(storage()->index(Func(storage(), name, vals)));
			}
			break;
		}
		case AGGR_SUM:
		case AGGR_COUNT:
		case AGGR_AVG:
		case AGGR_MIN:
		case AGGR_MAX:
		case AGGR_EVEN:
		case AGGR_EVEN_SET:
		case AGGR_ODD:
		case AGGR_ODD_SET:
		case AGGR_DISJUNCTION:
		{
			assert(stack_->type != AGGR_DISJUNCTION || stack_->n > 0);
			std::copy(stack_->lits.end() - stack_->n, stack_->lits.end(), std::back_inserter(stack_->aggrLits));
			stack_->lits.resize(stack_->lits.size() - stack_->n);
			stack_->lits.push_back(Lit::create(stack_->type, stack_->n ? stack_->aggrLits.size() - stack_->n : stack_->vals.size() - 2, stack_->n));
			break;
		}
		case STM_RULE:
		case STM_CONSTRAINT:
		{
			Rule::Printer *printer = output_->printer<Rule::Printer>();
			printer->begin();
			if(stack_->type == STM_RULE)             { printLit(printer, stack_->lits.size() - stack_->n - 1, true); }
			printer->endHead();
			for(uint32_t i = stack_->n; i >= 1; i--) { printLit(printer, stack_->lits.size() - i, false); }
			printer->end();
			pop(stack_->n + (stack_->type == STM_RULE));
			break;
		}
		case STM_SHOW:
		case STM_HIDE:
		{
			Display::Printer *printer = output_->printer<Display::Printer>();
			printLit(printer, stack_->lits.size() - 1, stack_->type == STM_SHOW);
			pop(1);
			break;
		}
		case STM_EXTERNAL:
		{
			External::Printer *printer = output_->printer<External::Printer>();
			printLit(printer, stack_->lits.size() - 1, true);
			pop(1);
			break;
		}
		#pragma message "reimplement this"
		/*
		case STM_MINIMIZE:
		case STM_MAXIMIZE:
		case STM_MINIMIZE_SET:
		case STM_MAXIMIZE_SET:
		{
			Optimize::Printer *printer = output_->printer<Optimize::Printer>();
			bool maximize = (stack_->type == STM_MAXIMIZE || stack_->type == STM_MAXIMIZE_SET);
			bool set = (stack_->type == STM_MINIMIZE_SET || stack_->type == STM_MAXIMIZE_SET);
			printer->begin(maximize, set);
			for(uint32_t i = stack_->n; i >= 1; i--)
			{

				Lit &a     = stack_->lits[stack_->lits.size() - i];
				Val prio   = stack_->vals[a.offset + a.n + 2];
				Val weight = stack_->vals[a.offset + a.n + 1];
				printer->print(predLitRep(a), weight.num, prio.num);
			}
			printer->end();
			pop(stack_->n);
			break;
		}
		*/
		case STM_COMPUTE:
		{
			Compute::Printer *printer = output_->printer<Compute::Printer>();
			for(uint32_t i = stack_->n; i >= 1; i--)
			{
				Lit &a = stack_->lits[stack_->lits.size() - i];
				printer->print(predLitRep(a));
			}
			pop(stack_->n);
			break;
		}
#pragma message "reimplement me!"
		//case META_SHOW:
		//case META_HIDE:
//		case META_EXTERNAL:
//		{
//			Val num = stack_->vals.back();
//			stack_->vals.pop_back();
//			Val id  = stack_->vals.back();
//			stack_->vals.pop_back();
//			assert(id.type == Val::ID);
//			assert(num.type == Val::NUM);
//			storage()->newDomain(id.index, num.num);
//			if(stack_->type == META_EXTERNAL) { output_->external(id.index, num.num); }
//			//else { output_->show(id.index, num.num, stack_->type == META_SHOW); }
//			break;
//		}
#pragma message "reimplement me!"
		//case META_GLOBALSHOW:
		case META_GLOBALHIDE:
		{
			output_->hideAll();
			break;
		}
		default: {
			doAdd();
		}
	}
}
Beispiel #13
0
void execute(pruCPU *cpu) {
	aluInstruction inst;
	fmt2InstructionHeader fmt2Hdr;
	while(1) {
		int didBranch = 0;
		cgc_memcpy(&inst, (aluInstruction *)&cpu->code[cpu->pc], 4);
		switch(inst.opFmt) {
			case 0b000:
				switch(inst.aluOp) {
					case ADD:
						doAdd(cpu, inst);
						break;
					case ADC:
						doAdc(cpu, inst);
						break;
					case SUB:
						doSub(cpu, inst);
						break;
					case SUC:
						doSuc(cpu, inst);
						break;
					case LSL:
						doLsl(cpu, inst);
						break;
					case LSR:
						doLsr(cpu, inst);
						break;
					case RSB:
						doRsb(cpu, inst);
						break;
					case RSC:
						doRsc(cpu, inst);
						break;
					case AND:
						doAnd(cpu, inst);
						break;
					case OR:
						doOr(cpu, inst);
						break;
					case XOR:
						doXor(cpu, inst);
						break;
					case NOT:
						doNot(cpu, inst);
						break;
					case MIN:
						doMin(cpu, inst);
						break;
					case MAX:
						doMax(cpu, inst);
						break;
					case CLR:
						doClr(cpu, inst);
						break;
					case SET:
						doSet(cpu, inst);
						break;
				}
				break;
			case 0b001:
				cgc_memcpy(&fmt2Hdr, &inst, sizeof(fmt2Hdr));
				switch(fmt2Hdr.subOp)
				{
					case JMP:
					case JAL:
						;
						fmt2BranchInstruction fmt2Branch;
						cgc_memcpy(&fmt2Branch, &inst, 4);
						doBranch(cpu, fmt2Branch);
						didBranch = 1;
						break;
					case LDI:
						;
						fmt2LdiInstruction fmt2Ldi;
						cgc_memcpy(&fmt2Ldi, &inst, 4);
						doLdi(cpu, fmt2Ldi);
						break;
					case LMBD:
						;
						fmt2LmbdInstruction fmt2Lmbd;
						cgc_memcpy(&fmt2Lmbd, &inst, 4);
						doLmbd(cpu, fmt2Lmbd);
						break;
					case HALT:
						return;
					case SCAN:
						;
						fmt2ScanInstruction fmt2Scan;
						cgc_memcpy(&fmt2Scan, &inst, 4);
						doScan(cpu, fmt2Scan);
						break;
					case SLP:
					case RESERVED_1:
					case RESERVED_2:
					case RESERVED_3:
					case RESERVED_4:
					case RESERVED_5:
					case RESERVED_6:
					case RESERVED_7:
					case RESERVED_8:
					case RESERVED_9:
						return;
				}
				break;
			case 0b11:
				;
				fmtQatbInstruction qatbInstruction;
				cgc_memcpy(&qatbInstruction, &inst, 4);
				doQATB(cpu, qatbInstruction);			
			default:
				return;
		}
		if(didBranch == 0)
			cpu->pc++;
		cpu->numExecuted++;
		if(cpu->numExecuted >= MAX_INSNS)
			return;

	}
}
Beispiel #14
0
//-----------------------------------------------------------------------------
KMFolderDialog::KMFolderDialog(KMFolder* aFolder, QWidget *parent,
			       const char *name) :
  KMFolderDialogInherited(parent, name, TRUE)
{
  KMAccount* acct;
  QLabel *label;
  QString type;

  folder = (KMAcctFolder*)aFolder;

  label = new QLabel(this);
  label->setGeometry(20,20,60,25);
  label->setText(i18n("Name:"));
  label->setAlignment(290);

  nameEdit = new QLineEdit(this);
  nameEdit->setGeometry(90,20,320,25);
  nameEdit->setFocus();
  nameEdit->setText(folder ? folder->name().data() : i18n("unnamed"));

  if (folder)
  {
    type = folder->type();
    if (!type.isEmpty() && type!="plain")
      nameEdit->setEnabled(false);
  }

  label = new QLabel(this);
  label->setText(i18n("Associated with"));
  label->adjustSize();
  label->move(20,74);

  assocList = new QListBox(this);
  assocList->setGeometry(20,95,160,140);
  connect(assocList,SIGNAL(highlighted(int)),this,SLOT(doAssocHighlighted(int)));
  connect(assocList,SIGNAL(selected(int)),this,SLOT(doAssocSelected(int)));

  label = new QLabel(this);
  label->setText(i18n("Unassociated Accounts"));
  label->adjustSize();
  label->move(250,74);

  accountList = new QListBox(this);
  accountList->setGeometry(250,95,160,140);
  connect(accountList,SIGNAL(highlighted(int)),this,SLOT(doAccountHighlighted(int)));
  connect(accountList,SIGNAL(selected(int)),this,SLOT(doAccountSelected(int)));

  addButton = new QPushButton(this);
  addButton->setGeometry(190,115,50,40);
  addButton->setText("<<");
  addButton->setEnabled(FALSE);
  connect(addButton,SIGNAL(clicked()),this,SLOT(doAdd()));

  removeButton = new QPushButton(this);
  removeButton->setGeometry(190,175,50,40);
  removeButton->setText(">>");
  removeButton->setEnabled(FALSE);
  connect(removeButton,SIGNAL(clicked()),this,SLOT(doRemove()));

  QPushButton *button = new QPushButton(this);
  button->setGeometry(190,260,100,30);
  button->setText(i18n("OK"));
  connect(button,SIGNAL(clicked()),this,SLOT(doAccept()));

  if (type=="Out" || type=="St")
    button->setEnabled(false);

  button = new QPushButton(this);
  button->setGeometry(310,260,100,30);
  button->setText(i18n("Cancel"));
  connect(button,SIGNAL(clicked()),this,SLOT(reject()));

  resize(430,340);
  setFixedSize(430,340);

  if (folder)
  {
    // Grab the list of accounts associated with the given folder.
    for (acct=folder->account(); acct; acct=folder->nextAccount())
    {
      assocList->inSort(acct->name());
    }
  }

  // insert list of available accounts that are not associated with
  // any account
  for (acct=acctMgr->first(); acct; acct=acctMgr->next())
  {
    if (!acct->folder())
      accountList->inSort(acct->name());
  }
}
Beispiel #15
0
//-----------------------------------------------------------------------------
void KMFolderDialog::doAccountSelected(int)
{
  doAdd();
}
Beispiel #16
0
int main (int argc, char **argv)
{
 int dbug=0;
 char *input;
 int ch;
 list *l = lst_create();

 if(argc ==2){
   if(argv[1][0] == '-' && argv[1][1] == 'd'){
     dbug = 1;  // ./a.out -d
     printf("\nDebug mode activated\n");
   }
 }
 
 printf ("Starting Restaurant Wait List Program\n\n");
 printf ("Enter command: ");

 while ((ch = getNextNWSChar ()) != EOF)
   {
    /* check for the various commands */
    if ('q' == ch)
      {
       printf ("Quitting Program\n");
       return (0);
      }
    else if ('?' == ch)
      {
       printCommands();
      }
    else if('a' == ch)
      {
       doAdd(l,dbug);
      } 
    else if('c' == ch)
      {
       doCallAhead(l,dbug);
      } 
    else if('w' == ch)
      {
       doWaiting(l,dbug);
      } 
    else if('r' == ch)
      {
       doRetrieve(l,dbug);
      } 
    else if('l' == ch)
      {
       doList(l,dbug);
      } 
    else if('d' == ch)
      {
       doDisplay(l,dbug);
      } 
    else
      {
       printf ("%c - in not a valid command\n", ch);
       printf ("For a list of valid commands, type ?\n");
       clearToEoln();
      }

    printf ("\nEnter command: ");
   }

 printf ("Quiting Program - EOF reached\n");
 lst_free(l,dbug);
 return 1;
}
Beispiel #17
0
// extern __thread jmp_buf jumpBuf;
int VM::call(Value A, int nEffArgs, Value *regs, Stack *stack) {
    Vector<RetInfo> retInfo; // only used if FAST_CALL

    if (!(IS_O_TYPE(A, O_FUNC) || IS_CF(A) || IS_O_TYPE(A, O_CFUNC))) { return -1; }
    regs  = stack->maybeGrow(regs, 256);
    int nExpectedArgs = IS_O_TYPE(A, O_FUNC) ? ((Func *)GET_OBJ(A))->proto->nArgs : NARGS_CFUNC;
    nEffArgs = prepareStackForCall(regs, nExpectedArgs, nEffArgs, gc);

    if (IS_CF(A) || IS_O_TYPE(A, O_CFUNC)) {
        if (IS_CF(A)) {
            tfunc f = GET_CF(A);
            *regs = f(this, CFunc::CFUNC_CALL, 0, regs, nEffArgs);
        } else {
            ((CFunc *) GET_OBJ(A))->call(this, regs, nEffArgs);
        }
        return 0;
    }

    unsigned code = 0;
    Value B;
    Value *ptrC;
    Func *activeFunc = (Func *) GET_OBJ(A);
    unsigned *pc = (unsigned *) activeFunc->proto->code.buf();

    static void *dispatch[] = {
#define _(name) &&name
#include "opcodes.inc"
#undef _
    };

    assert(sizeof(dispatch)/sizeof(dispatch[0]) == N_OPCODES);

    copyUpvals(activeFunc, regs);

    STEP;

 JMP:  pc += OD(code);    STEP;
 JT:   if (!IS_FALSE(*ptrC)) { pc += OD(code);  } STEP;
 JF:   if ( IS_FALSE(*ptrC)) { pc += OD(code);  } STEP;
 JLT:  if (lessThan(A, B))   { pc += OSC(code); } STEP;
 JNIS: if (A != B)           { pc += OSC(code); } STEP;

 FOR: 
    A = *(ptrC + 1);
    B = *(ptrC + 2);
    if (!IS_NUM(A) || !IS_NUM(B)) { goto error; } // E_FOR_NOT_NUMBER
    *ptrC = B;
    if (!(GET_NUM(B) < GET_NUM(A))) { pc += OD(code); }
    STEP;

 LOOP: {
        const double counter = GET_NUM(*ptrC) + 1;
        if (counter < GET_NUM(*(ptrC+1))) { pc += OD(code); }
        *ptrC = VAL_NUM(counter);
        STEP;
    }

 FUNC:
    assert(IS_PROTO(A));
    *ptrC = VAL_OBJ(Func::alloc(gc, PROTO(A), regs + 256, regs, OB(code)));
    STEP;

    // index, A[B]
 GETI: *ptrC = types->type(A)->indexGet(A, B); if (*ptrC == VERR) { goto error; } STEP;
 GETF: *ptrC = types->type(A)->fieldGet(A, B); if (*ptrC == VERR) { goto error; } STEP;
    
 SETI: if (!types->type(*ptrC)->indexSet(*ptrC, A, B)) { goto error; } STEP;
 SETF: if (!types->type(*ptrC)->fieldSet(*ptrC, A, B)) { goto error; } STEP;
    /*
      const int oa = OA(code);
      const int ob = OB(code);
      int top = max(oa, ob) + 1;
      top = max(top, activeFunc->proto->localsTop);
      Value *base = regs + top;
      printf("top %d\n", top);
      base[0] = A;
      base[1] = B;
      int cPos = ptrC - regs;
      DO_CALL(v, 2, regs, base, stack);
      regs[cPos] = base[0];
      break;
      if (*ptrC == VERR) { goto error; }
    */
        
 GETS: *ptrC = getSlice(gc, A, B, regs[OB(code)+1]); if (*ptrC==VERR) { goto error; } STEP;
 SETS: if (setSlice(*ptrC, A, regs[OA(code)+1], B)) { goto error; } STEP;

 RET: {
        regs[0] = A;
        Value *root = stack->base;
        gc->maybeCollect(root, regs - root + 1);
#if FAST_CALL
        if (!retInfo.size()) {
            return 0;
        }
        RetInfo *ri = retInfo.top();
        pc         = ri->pc;
        regs       = stack->base + ri->base;
        activeFunc = ri->func;
        retInfo.pop();
        copyUpvals(activeFunc, regs);
        STEP;
#else
        return 0;
#endif
    }

CALL: { 
        if (!IS_OBJ(A) && !IS_CF(A)) { goto error; } // E_CALL_NOT_FUNC
        int nEffArgs = OSB(code);
        assert(nEffArgs != 0);
        Value *base = ptrC;
#if FAST_CALL
        if (IS_O_TYPE(A, O_FUNC)) {
            Func *f = (Func *) GET_OBJ(A);
            Proto *proto = f->proto;
            prepareStackForCall(base, proto->nArgs, nEffArgs, gc);
            RetInfo *ret = retInfo.push();
            ret->pc    = pc;
            ret->base  = regs - stack->base;
            ret->func  = activeFunc;
            regs = stack->maybeGrow(base, 256);
            copyUpvals(f, regs);
            pc   = proto->code.buf();
            activeFunc = f;
        } else {
#endif
            int ret = DO_CALL(A, nEffArgs, regs, base, stack);
            if (ret) { goto error; }
#if FAST_CALL
        }
#endif
        STEP;
    }
    
 MOVEUP: {
        const int slot = regs + 256 - ptrC;
        activeFunc->setUp(slot, A);
    }
    
 MOVE_R: *ptrC = A; STEP;
 MOVE_I: *ptrC = VAL_NUM(OD(code)); STEP;
 MOVE_V: {
        int id = OA(code);
        *ptrC =
            id == CONST_NIL          ? VNIL :
            id == CONST_EMPTY_STRING ? EMPTY_STRING :
            id == CONST_EMPTY_ARRAY  ? VAL_OBJ(emptyArray->copy(gc)) :
            VAL_OBJ(emptyMap->copy(gc));
        STEP;
    }
    
 MOVE_C: {
        Value v = *pc | (((u64) *(pc+1)) << 32);
        pc += 2;
        if (IS_ARRAY(v)) {
            v = VAL_OBJ(ARRAY(v)->copy(gc));
        } else if (IS_MAP(v)) {
            v = VAL_OBJ(MAP(v)->copy(gc));
        }
        *ptrC = v;
        STEP;
    }
 LEN:    *ptrC = VAL_NUM(len(A)); STEP;
 NOTL:   *ptrC = IS_FALSE(A) ? TRUE : FALSE; STEP;
    // notb: *ptrC = IS_INT(A)? VAL_INT(~getInteger(A)):ERROR(E_WRONG_TYPE); STEP;

 ADD: *ptrC = doAdd(gc, A, B); if (*ptrC == VERR) { goto error; } STEP;
 SUB: *ptrC = BINOP(-, A, B); STEP;
 MUL: *ptrC = BINOP(*, A, B); STEP;
 DIV: *ptrC = BINOP(/, A, B); STEP;
 MOD: *ptrC = doMod(A, B); if (*ptrC == VERR) { goto error; } STEP;
 POW: *ptrC = doPow(A, B); if (*ptrC == VERR) { goto error; } STEP;

 AND: *ptrC = BITOP(&,  A, B); STEP;
 OR:  *ptrC = BITOP(|,  A, B); STEP;
 XOR: *ptrC = BITOP(^,  A, B); STEP;

 SHL_RR: ERR(!IS_NUM(B), E_WRONG_TYPE); *ptrC = doSHL(A, (int)GET_NUM(B)); STEP;
 SHR_RR: ERR(!IS_NUM(B), E_WRONG_TYPE); *ptrC = doSHR(A, (int)GET_NUM(B)); STEP;
 SHL_RI: *ptrC = doSHL(A, OSB(code));       STEP;
 SHR_RI: *ptrC = doSHR(A, OSB(code));       STEP;

 EQ:  *ptrC = equals(A, B)  ? TRUE : FALSE; STEP;
 NEQ: *ptrC = !equals(A, B) ? TRUE : FALSE; STEP;
 IS:  *ptrC = A == B ? TRUE : FALSE; STEP;
 NIS: *ptrC = A != B ? TRUE : FALSE; STEP;

 LT:  *ptrC = lessThan(A, B) ? TRUE : FALSE; STEP;
 LE:  *ptrC = (equals(A, B) || lessThan(A, B)) ? TRUE : FALSE; STEP;

 error: return pc - (unsigned *) activeFunc->proto->code.buf();
}
void	ComponentListItem::update()
{
	int32_t bCanAdd = MechLabScreen::instance()->canAddComponent(pComponent);
	for(size_t i = 0; i < COMP_ANIMATION_COUNT; i++)
	{
		animations[i].update();
	}
	bool isInside = pointInside(userInput->getMouseX(), userInput->getMouseY());
	if(state == aListItem::SELECTED)
	{
		if((userInput->isLeftClick() && isInside)
				|| (animations[0].getState() != aAnimGroup::PRESSED)
				&& ComponentIconListBox::s_instance->pointInside(userInput->getMouseX(), userInput->getMouseY()))
		{
			setComponent();
			if(bCanAdd)
			{
				soundSystem->playDigitalSample(LOG_WRONGBUTTON);
			}
			::helpTextID = IDS_HELP_COMP0 + pComponent->getID();
		}
		if(!bCanAdd)
		{
			if(animations[0].getState() != aAnimGroup::PRESSED)
			{
				for(size_t i = 0; i < COMP_ANIMATION_COUNT; i++)
				{
					animations[i].setState(aAnimGroup::PRESSED);
				}
			}
			if(isInside && ComponentIconListBox::s_instance->pointInside(userInput->getMouseX(), userInput->getMouseY()))
			{
				::helpTextID = IDS_HELP_COMP0 + pComponent->getID();
			}
			disabledText.setText("");
		}
		else
		{
			for(size_t i = 0; i < COMP_ANIMATION_COUNT; i++)
				animations[i].setState(aAnimGroup::DISABLED);
			if(COMPONENT_TOO_HOT == bCanAdd)
			{
				disabledText.setText(IDS_MC_COMPONENT_TOO_HOT);
			}
			else if(NO_MORE_ARMOR == bCanAdd)
			{
				disabledText.setText(IDS_MC_COMPONENT_TOO_MUCH_ARMOR);
			}
			else
				disabledText.setText("");
		}
		if(!bCanAdd)
		{
			if(userInput->isLeftDrag() && isInside &&
					pointInside(userInput->getMouseDragX(), userInput->getMouseDragY())
					&& ComponentIconListBox::s_instance->pointInside(userInput->getMouseX(), userInput->getMouseY()))
				startDrag();
		}
	}
	else if(isInside && !bCanAdd
			&& ComponentIconListBox::s_instance->pointInside(userInput->getMouseX(), userInput->getMouseY()))
	{
		if(animations[0].getState() != aAnimGroup::HIGHLIGHT)
		{
			for(size_t i = 0; i < COMP_ANIMATION_COUNT; i++)
			{
				animations[i].setState(aAnimGroup::HIGHLIGHT);
			}
			soundSystem->playDigitalSample(LOG_HIGHLIGHTBUTTONS);
		}
		state = aListItem::HIGHLITE;
		::helpTextID = IDS_HELP_COMP0 + pComponent->getID();
	}
	else if(!bCanAdd)
	{
		state = aListItem::ENABLED;
		for(size_t i = 0; i < COMP_ANIMATION_COUNT; i++)
			animations[i].setState(aAnimGroup::NORMAL);
		disabledText.setText("");
	}
	else
	{
		state = DISABLED;
		if(isInside
				&& ComponentIconListBox::s_instance->pointInside(userInput->getMouseX(), userInput->getMouseY()))
			::helpTextID = IDS_HELP_COMP0 + pComponent->getID();
		if((userInput->isLeftClick() && isInside
				&& ComponentIconListBox::s_instance->pointInside(userInput->getMouseX(), userInput->getMouseY())))
		{
			setComponent();
			soundSystem->playDigitalSample(LOG_WRONGBUTTON);
		}
		for(size_t i = 0; i < COMP_ANIMATION_COUNT; i++)
			animations[i].setState(aAnimGroup::DISABLED);
		if(COMPONENT_TOO_HOT == bCanAdd)
		{
			disabledText.setText(IDS_MC_COMPONENT_TOO_HOT);
		}
		else if(NO_MORE_ARMOR == bCanAdd)
		{
			disabledText.setText(IDS_MC_COMPONENT_TOO_MUCH_ARMOR);
		}
		else
			disabledText.setText("");
	}
	if(userInput->isLeftDoubleClick() && isInside
			&& ComponentIconListBox::s_instance->pointInside(userInput->getMouseX(), userInput->getMouseY()))
		doAdd();
	aObject::update();
}
Beispiel #19
0
int main(int argc, char **argv) {
	char *optstring = "c:t:b:";
	int copt;
	char bnlspecified = 0;
	int r;
	char *rptr;
	newtimestamp = time(NULL);
	argv0 = argv[0];
	if(argc < 2) {
		printUsage(argv[0]);
		return 1;
	}
	for(;;) {
		copt = getopt(argc, argv, optstring);
		if(copt == -1) break;
		if(copt == '?') {
			fprintf(stderr, "Invalid option.");
			return 1;
		}
		switch(copt) {
			case 'c':
				strcpy(configfile_dir, optarg);
				break;
			case 't':
				newtimestamp = atoi(optarg);
				break;
			case 'b':
				strcpy(bnl_filename, optarg);
				bnlspecified = 1;
				break;
		}
	}
	// Get orig directory
	rptr = getcwd(configfile_origdir, CONFIGFILE_FILENAME_LEN);
	// cd to the new directory
	r = chdir(configfile_dir);
	if(r != 0) {
		fprintf(stderr, "Error changing to configfile dir");
		return 1;
	}
	// Load config file
	if(configfile_load() != CONFIGFILE_OK) { fprintf(stderr, "Error loading config file.\n"); return 1; }
	// Load SSL error strings
	SSL_load_error_strings();
	// Initialize signatures
	if(sig_init() != SIG_OK) { fprintf(stderr, "Error initializing signatures.\n"); return 1; }
	// Command
	if(argc - optind < 1) {
		printUsage(argv[0]);
		return 1;
	}
	if(bnlspecified) r = chdir(configfile_origdir);
	if(strcmp(argv[optind], "print") == 0) {
		if(argc - optind != 1) {
			printUsage(argv[0]);
			return 1;
		}
		return doPrintBNL();
	}
	if(strcmp(argv[optind], "new") == 0) {
		if(argc - optind != 1) {
			printUsage(argv[0]);
			return 1;
		}
		return doNew(newtimestamp);
	}
	if(strcmp(argv[optind], "add") == 0) {
		return doAdd(argc - optind - 1, &argv[optind + 1], newtimestamp);
	}
	if(strcmp(argv[optind], "modify") == 0) {
		return doModify(argc - optind - 1, &argv[optind + 1], newtimestamp);
	}
	if(strcmp(argv[optind], "remove") == 0) {
		if(argc - optind != 2) {
			printUsage(argv[0]);
			return 1;
		}
		return doRemove(argv[optind + 1], newtimestamp);
	}
	if(strcmp(argv[optind], "addsubnet") == 0) {
		if(argc - optind != 3) {
			printUsage(argv[0]);
			return 1;
		}
		return doAddSubnet(argv[optind + 1], argv[optind + 2], newtimestamp);
	}
	if(strcmp(argv[optind], "delsubnet") == 0) {
		if(argc - optind != 3) {
			printUsage(argv[0]);
			return 1;
		}
		return doDelSubnet(argv[optind + 1], argv[optind + 2], newtimestamp);
	}
	printUsage(argv[0]);
	return 1;
}