예제 #1
0
VOID Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::RemoveAll()
{
	Node* pNode = m_pRoot;
	while (pNode != m_pNil)
	{
		if (!IsNil(pNode->m_pLeft))
    { 
      pNode = pNode->m_pLeft;
      SetNil( &pNode->m_pParent->m_pLeft );
    }
		else if (!IsNil(pNode->m_pRight))
    {
			pNode = pNode->m_pRight;
      SetNil( &pNode->m_pParent->m_pRight );
    }
    else
		{
      Node* pParent = pNode->m_pParent;
			delete pNode;
			pNode = pParent;
		}
	}
  m_NodeCount = 0;
  SetNil(&m_pRoot);
}
예제 #2
0
int prDirectory_At(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp - 2;
	PyrSlot *b = g->sp - 1;
	PyrSlot *c = g->sp;

	PyrSlot *dirPathSlot = slotRawObject(a)->slots + 0;
	int err, index;
	err = slotIntVal(c, &index);
	if (err) {
		SetNil(a);
		return err;
	}

	char name[256], fullPathName[256];
	int nameLength, creationDate, modificationDate, isDirectory, isVisible, sizeIfFile;
	int dirPathLength = slotRawObject(dirPathSlot)->size;

	err = dir_Lookup(slotRawObject(dirPathSlot)s->s, dirPathLength, index+1,
		name, &nameLength, &creationDate, &modificationDate, &isDirectory, &isVisible, &sizeIfFile);
	if (err == 1) {
		SetNil(a);
		return errNone;
	}
	if (err) {
		error("Invalid path\n");
		SetNil(a);
		return errFailed;
	}

	if (dirPathLength + nameLength + 1 > 255) {
		error("Full path name too long.\n");
		SetNil(a);
		return errFailed;
	}

	PyrSlot *entryName = slotRawObject(b)->slots + 0;
	PyrSlot *entryPath = slotRawObject(b)->slots + 1;
	PyrSlot *entryIsDir = slotRawObject(b)->slots + 2;
	PyrSlot *entryIsVisible = slotRawObject(b)->slots + 3;

	PyrString *nameString = newPyrString(g->gc, name, 0, true);
	SetObject(entryName, nameString);
	g->gc->GCWrite(slotRawObject(b), (PyrObject*)nameString);

	memcpy(fullPathName, slotRawObject(dirPathSlot)s->s, dirPathLength);
	fullPathName[dirPathLength] = DELIMITOR;
	strcpy(fullPathName + dirPathLength + 1, name);

	PyrString *pathString = newPyrString(g->gc, fullPathName, 0, true);
	SetObject(entryPath, pathString);
	g->gc->GCWrite(slotRawObject(b), (PyrObject*)pathString);

	if (isDirectory) { SetTrue(entryIsDir); } else { SetFalse(entryIsDir); }
	if (isVisible) { SetTrue(entryIsVisible); } else { SetFalse(entryIsVisible); }

	slotCopy(a,b);

	return errNone;
}
예제 #3
0
static void _doc_traverse(struct VMGlobals* g, DocNode *n, PyrObject *parent, PyrSlot *slot)
{
    PyrObject *result = instantiateObject( g->gc, s_scdoc_node->u.classobj, 0, false, false );
    result->size = 0;
	SetObject(slot, result);
	if(parent) g->gc->GCWrite(parent, result);

    PyrSymbol *id = getsym(n->id);
    SetSymbol(result->slots+result->size++, id);

    if(n->text) {
        PyrObject *str = (PyrObject*) newPyrString(g->gc, n->text, 0, true);
        SetObject(result->slots+result->size++, str);
        g->gc->GCWrite(result, str);
    } else {
        SetNil(result->slots+result->size++);
    }

    if(n->n_childs) {
        PyrObject *array = newPyrArray(g->gc, n->n_childs, 0, true);
        array->size = 0;
        SetObject(result->slots+result->size++, array);
        g->gc->GCWrite(result, array);
        for(int i=0; i<n->n_childs; i++) {
            array->size++;
            _doc_traverse(g, n->children[i], array, array->slots+i);
        }
    } else {
        SetNil(result->slots+result->size++);
    }
    result->size += 3; // makeDiv, notPrivOnly, sort
}
예제 #4
0
VOID Set<K,ElementTraits>::RemoveAll()
{
	Node* pNode = m_pRoot;
	while (pNode != m_pNil)
	{
		if (!IsNil(pNode->m_pLeft))
    { 
      pNode = pNode->m_pLeft;
      SetNil( &pNode->m_pParent->m_pLeft );
    }
		else if (!IsNil(pNode->m_pRight))
    {
			pNode = pNode->m_pRight;
      SetNil( &pNode->m_pParent->m_pRight );
    }
    else
		{
      Node* pParent = pNode->m_pParent;
			delete pNode;
			pNode = pParent;
		}
	}
  m_NodeCount = 0;
  SetNil(&m_pRoot);
}
예제 #5
0
int prFile_PutFile(struct VMGlobals *g, int numArgsPushed)
{

	PyrSlot *a = g->sp - 2;
	PyrSlot *b = g->sp - 1;
	PyrSlot *c = g->sp;

	NavDialogOptions options;

	int err = NavGetDefaultDialogOptions(&options);
	if (err) return errFailed;

	options.dialogOptionFlags |= kNavNoTypePopup;
	options.dialogOptionFlags |= kNavDontAutoTranslate;
	options.dialogOptionFlags |= kNavDontAddTranslateItems;
	options.dialogOptionFlags |= kNavSelectDefaultLocation;
	options.dialogOptionFlags &= ~kNavAllowPreviews;
	options.dialogOptionFlags &= ~kNavAllowMultipleFiles;

	if (isKindOfSlot(b, class_string)) {
		pstringFromPyrString((PyrString*)slotRawObject(b), options.message, 256);
	}

	if (isKindOfSlot(c, class_string)) {
		pstringFromPyrString((PyrString*)slotRawObject(c), options.savedFileName, 256);
	} else {
		//pstrncpy(options.savedFileName, "\pUntitled", 255);
	}

	NavReplyRecord reply;
	err = NavPutFile(0, &reply, &options, 0, 'TEXT', 'SCjm', 0);

	if (err == noErr && reply.validRecord) {
		AEKeyword keyword;
		DescType actualType;
		Size actualSize;
		FSSpec fsspec;

		err = AEGetNthPtr(&reply.selection, 1, typeFSS, &keyword, &actualType,
							&fsspec, sizeof(FSSpec), &actualSize);

		if (err == noErr) {
			Str255 pathname;
			GetFullPathname(&fsspec, pathname);
			p2cstr(pathname);
			PyrString *string = newPyrString(g->gc, (char*)pathname, 0, true);
			SetObject(a, string);

			err = NavCompleteSave(&reply, kNavTranslateInPlace);
		} else {
			SetNil(a);
		}
		err = NavDisposeReply(&reply);
	} else {
		SetNil(a);
	}
	return errNone;
}
예제 #6
0
파일: GC.cpp 프로젝트: scztt/sc-debug
void PyrGC::Finalize(PyrObject *finalizer)
{
	if (!IsPtr(finalizer->slots+0)) return;
	if (!IsObj(finalizer->slots+1)) return;

	ObjFuncPtr func = (ObjFuncPtr)finalizer->slots[0].ui;
	PyrObject *obj = finalizer->slots[1].uo;
	//post("FINALIZE %s %p\n", obj->classptr->name.us->name, obj);
	(func)(mVMGlobals, obj);

	SetNil(obj->slots+0);
	SetNil(obj->slots+1);
}
예제 #7
0
파일: GC.cpp 프로젝트: ASauer/supercollider
void PyrGC::Finalize(PyrObject *finalizer)
{
	if (!IsPtr(finalizer->slots+0)) return;
	if (!IsObj(finalizer->slots+1)) return;

	ObjFuncPtr func = (ObjFuncPtr)slotRawPtr(&finalizer->slots[0]);
	PyrObject *obj = slotRawObject(&finalizer->slots[1]);
	//post("FINALIZE %s %p\n", slotRawSymbol(&obj->classptr->name)->name, obj);
	(func)(mVMGlobals, obj);

	SetNil(obj->slots+0);
	SetNil(obj->slots+1);
}
예제 #8
0
void PriorityQueuePop(VMGlobals *g, PyrObject *queueobj, PyrSlot *result)
{
	PyrSlot *schedqSlot = queueobj->slots;

	if (IsObj(schedqSlot)) {
		PyrObject *schedq = slotRawObject(schedqSlot);
		double time;
		if (!getheap(g, schedq, &time, result)) {
			SetNil(result);
		}
	} else {
		SetNil(result);
	}
}
예제 #9
0
void PriorityQueueTop(PyrObject *queueobj, PyrSlot *result)
{
	PyrSlot *schedqSlot = queueobj->slots;

	if (IsObj(schedqSlot)) {
		PyrObject *schedq = slotRawObject(schedqSlot);
		if (schedq->size > 1) {
			slotCopy(result,&schedq->slots[1]);
		} else {
			SetNil(result);
		}
	} else {
		SetNil(result);
	}
}
예제 #10
0
파일: GC.cpp 프로젝트: scztt/sc-debug
PyrGC::PyrGC(VMGlobals *g, AllocPool *inPool, PyrClass *mainProcessClass, long poolSize)
{
	mVMGlobals = g;
	mPool = inPool;
	//mCurSet = 0;
	mNumToScan = 0;

	mFlips = 0;
	mCollects = 0;
	mAllocTotal = 0;
	mNumAllocs = 0;
	mScans = 0;
	mStackScans = 0;
	mNumPartialScans = 0;
	mSlotsScanned = 0;

	mGreyColor = 3<<2;
	mBlackColor = 2<<2;
	mWhiteColor = 1<<2;
	mFreeColor = 0;

	mRunning = false;

	mCanSweep = false;
	mPartialScanObj = NULL;
	mPartialScanSlot = 0;

	mGrey.classptr = NULL;
	mGrey.obj_sizeclass = 0;
	mGrey.size = 0;
	mGrey.gc_color = obj_gcmarker;

	mGrey.prev = &mGrey;
	mGrey.next = &mGrey;

	mNumGrey = 0;

	mNewPool.Init(mPool, poolSize, poolSize, 9000);

	// initialize treadmills
	for (int i=0; i<kNumGCSets; ++i) {
		mSets[i].Init(i);
	}

	mProcess = newPyrProcess(g, mainProcessClass);

	mStack = mProcess->mainThread.uot->stack.uo;
	ToBlack(mStack);
	SetNil(&mProcess->mainThread.uot->stack);

	mNumGrey = 0;
	ToGrey2(mProcess);
	g->sp = mStack->slots - 1;
	g->process = mProcess;
	mRunning = true;

	SanityCheck();
	//assert(SanityCheck());

}
예제 #11
0
int prIsPrime(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a;
	int n, p, sqrtn, i;

	a = g->sp;
	n = slotRawInt(a);
	SetNil(a);
	if (n <= 2) {
		if (n == 2) { SetTrue(a); }
		else { SetFalse(a); }
	} else if (n <= nthPrime(NUMPRIMES-1)) {
		// do a search of the primes table
		i = findPrime(n);
		if (i >= 0) { SetTrue(a); }
		else { SetFalse(a); }
	} else {
#ifdef SC_WIN32
		sqrtn = (int)sqrt(static_cast<double>(n));
#else
		sqrtn = (int)sqrt(n);
#endif
		for (i=0; i<NUMPRIMES; ++i) {
			p = nthPrime(i);
			if (n % p == 0) { SetFalse(a); break; }
			if (p >= sqrtn) { SetTrue(a); break; }
		}
	}
	return errNone;
}
예제 #12
0
int prPipeOpen(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a, *b, *c;
	char mode[12];
	PyrFile *pfile;
	FILE *file;

	a = g->sp - 2;
	b = g->sp - 1;
	c = g->sp;

	if (NotObj(c) || !isKindOf(slotRawObject(c), class_string)
		|| NotObj(b) || !isKindOf(slotRawObject(b), class_string))
		return errWrongType;
	if (slotRawObject(c)->size > 11) return errFailed;
	pfile = (PyrFile*)slotRawObject(a);

        char *commandLine = (char*)malloc(slotRawObject(b)->size + 1);
	memcpy(commandLine, slotRawString(b)->s, slotRawObject(b)->size);
	commandLine[slotRawString(b)->size] = 0;

	memcpy(mode, slotRawString(c)->s, slotRawObject(c)->size);
	mode[slotRawString(c)->size] = 0;

	pid_t pid;
	file = sc_popen(commandLine, &pid, mode);
	free(commandLine);
	if (file) {
		SetPtr(&pfile->fileptr, file);
		SetInt(a, pid);
	} else {
		SetNil(a);
	}
	return errNone;
}
예제 #13
0
파일: XML.c 프로젝트: montsuqi/libmondai
extern size_t XML_UnPackValue(CONVOPT *opt, unsigned char *p,
                              ValueStruct *value) {
  ValueContext *ctx;
  unsigned char *pp;

  ctx = New(ValueContext);
  ctx->root = value;
  ctx->buff = (xmlChar *)xmalloc(1);
  ctx->size = 1;
  ctx->fStart = FALSE;
  ctx->opt = opt;
  ctx->value = NULL;
  memset(ctx->longname, 0, SIZE_LONGNAME + 1);

  SetNil(value);
  pp = p;
  switch (ConvXmlType(opt)) {
  case XML_TYPE1:
    xmlSAXUserParseMemory(mondaiSAXHandler1, ctx, (char *)p, strlen((char *)p));
    break;
  case XML_TYPE2:
    xmlSAXUserParseMemory(mondaiSAXHandler2, ctx, (char *)p, strlen((char *)p));
    break;
  }
  xmlCleanupParser();
  xfree(ctx->buff);
  xfree(ctx);
  return (p - pp);
}
예제 #14
0
int prSCDoc_ParseFile(struct VMGlobals* g, int numArgsPushed)
{
	PyrSlot *a, *b, *c;
    char filename[PATH_MAX];
    int mode, err;

	a = g->sp - 2;
	b = g->sp - 1;
	c = g->sp;

    err = slotStrVal(b, filename, PATH_MAX);
    if (err) return err;
    
    err = slotIntVal(c, &mode);
    if (err) return err;

    DocNode *n = scdoc_parse_file(filename, mode);
    if(n) {
//        doc_node_dump(n);
        _doc_traverse(g, n, NULL, a);
        doc_node_free_tree(n);
    } else {
        SetNil(a);
    }
    return errNone;
}
예제 #15
0
typename Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::Node* Map<K,V,KeyElementTraits, ValueElementTraits, ThreadingModel>::Insert( CONST K& Key, CONST V& Value )
{
	Node* pNewNode = InsertImpl( Key, Value );

	Node* pX = pNewNode;
	pX->m_Status = Node::Red;
	Node* pY = 0;
	while (pX != m_pRoot && pX->m_pParent->m_Status == Node::Red)
	{
		if (pX->m_pParent == pX->m_pParent->m_pParent->m_pLeft)
		{
			pY = pX->m_pParent->m_pParent->m_pRight;
			if (pY != NULL && pY->m_Status == Node::Black)
			{
				pX->m_pParent->m_Status = Node::Black;
				pY->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				pX = pX->m_pParent->m_pParent;
			}
			else
			{
				if (pX == pX->m_pParent->m_pRight)
				{
					pX = pX->m_pParent;
					LeftRotate(pX);
				}
				pX->m_pParent->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				RightRotate(pX->m_pParent->m_pParent);
			}
		}
		else
		{
			pY = pX->m_pParent->m_pParent->m_pLeft;
			if (pY != NULL && pY->m_Status == Node::Red)
			{
				pX->m_pParent->m_Status = Node::Black;
				pY->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				pX = pX->m_pParent->m_pParent;
			}
			else
			{
				if (pX == pX->m_pParent->m_pLeft)
				{
					pX = pX->m_pParent;
					RightRotate(pX);
				}
				pX->m_pParent->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				LeftRotate(pX->m_pParent->m_pParent);
			}
		}
	}

	m_pRoot->m_Status = Node::Black;
	SetNil(&m_pRoot->m_pParent);

	return pNewNode;
}
예제 #16
0
파일: SC_HID.cpp 프로젝트: scztt/sc-debug
int prHIDGetValue(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp - 2; //class
	PyrSlot *b = g->sp - 1; //locID device
	PyrSlot *c = g->sp; //element cookie
	int locID, cookieNum;
	int err = slotIntVal(b, &locID);
	if (err) return err;
	err = slotIntVal(c, &cookieNum);
	if (err) return err;
	IOHIDElementCookie cookie = (IOHIDElementCookie) cookieNum;
	//look for the right device:
    pRecDevice  pCurrentHIDDevice = HIDGetFirstDevice ();
	while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=locID))
        pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice);
	if(!pCurrentHIDDevice) return errFailed;
	//look for the right element:
	pRecElement pCurrentHIDElement =  HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeAll);
	// use gElementCookie to find current element
    while (pCurrentHIDElement && (pCurrentHIDElement->cookie != cookie))
        pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeAll);

	if (pCurrentHIDElement)
    {
		SInt32 value = HIDGetElementValue (pCurrentHIDDevice, pCurrentHIDElement);
		 // if it's not a button and it's not a hatswitch then calibrate
		if(( pCurrentHIDElement->type != kIOHIDElementTypeInput_Button ) &&
			( pCurrentHIDElement->usagePage == 0x01 && pCurrentHIDElement->usage != kHIDUsage_GD_Hatswitch))
			value = HIDCalibrateValue ( value, pCurrentHIDElement );
		SetInt(a, value);
	}
	else SetNil(a);
	return errNone;

}
예제 #17
0
int prAscTime(struct VMGlobals *g, int numArgsPushed)
{
        PyrSlot *a = g->sp;
        PyrSlot *slots = a->uo->slots;

        if (IsNil(slots + 0)) {
          SetNil(a);
          return errNone;
        }

        struct tm tm0;

        if (slotIntVal(slots+0, &tm0.tm_year)) return errWrongType;
        tm0.tm_year -= 1900;
        if (slotIntVal(slots+1, &tm0.tm_mon)) return errWrongType;
		tm0.tm_mon -- ;
        if (slotIntVal(slots+2, &tm0.tm_mday)) return errWrongType;
        if (slotIntVal(slots+3, &tm0.tm_hour)) return errWrongType;
        if (slotIntVal(slots+4, &tm0.tm_min)) return errWrongType;
        if (slotIntVal(slots+5, &tm0.tm_sec)) return errWrongType;
        if (slotIntVal(slots+6, &tm0.tm_wday)) return errWrongType;

        const char *text = asctime(&tm0);

        int size = strlen(text) - 1; // Discard trailing newline
        PyrString *strobj = newPyrStringN(g->gc, size, 0, true);
        memcpy(strobj->s, text, size);

        SetObject(a, strobj);

        return errNone;
}
예제 #18
0
파일: VM.cpp 프로젝트: Gwill/luna
    void VM::Return(Value *a, Instruction i)
    {
        // Set stack top when return value count is fixed
        int ret_value_count = Instruction::GetParamsBx(i);
        if (ret_value_count != EXP_VALUE_COUNT_ANY)
            state_->stack_.top_ = a + ret_value_count;

        assert(!state_->calls_.empty());
        auto call = &state_->calls_.back();

        auto src = a;
        auto dst = call->func_;

        int expect_result = call->expect_result_;
        int result_count = state_->stack_.top_ - src;
        if (expect_result == EXP_VALUE_COUNT_ANY)
        {
            for (int i = 0; i < result_count; ++i)
                *dst++ = *src++;
        }
        else
        {
            int i = 0;
            int count = std::min(expect_result, result_count);
            for (; i < count; ++i)
                *dst++ = *src++;
            // No enough results for expect results, set remain as nil
            for (; i < expect_result; ++i, ++dst)
                dst->SetNil();
        }

        // Set new top and pop current CallInfo
        state_->stack_.SetNewTop(dst);
        state_->calls_.pop_back();
    }
예제 #19
0
typename Set<K,ElementTraits>::Node* Set<K,ElementTraits>::Insert( CONST K& Key )
{
	Node* pNewNode = InsertImpl( Key );

	Node* pX = pNewNode;
	pX->m_Status = Node::Red;
	Node* pY = 0;
	while (pX != m_pRoot && pX->m_pParent->m_Status == Node::Red)
	{
		if (pX->m_pParent == pX->m_pParent->m_pParent->m_pLeft)
		{
			pY = pX->m_pParent->m_pParent->m_pRight;
			if (pY != NULL && pY->m_Status == Node::Black)
			{
				pX->m_pParent->m_Status = Node::Black;
				pY->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				pX = pX->m_pParent->m_pParent;
			}
			else
			{
				if (pX == pX->m_pParent->m_pRight)
				{
					pX = pX->m_pParent;
					LeftRotate(pX);
				}
				pX->m_pParent->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				RightRotate(pX->m_pParent->m_pParent);
			}
		}
		else
		{
			pY = pX->m_pParent->m_pParent->m_pLeft;
			if (pY != NULL && pY->m_Status == Node::Red)
			{
				pX->m_pParent->m_Status = Node::Black;
				pY->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				pX = pX->m_pParent->m_pParent;
			}
			else
			{
				if (pX == pX->m_pParent->m_pLeft)
				{
					pX = pX->m_pParent;
					RightRotate(pX);
				}
				pX->m_pParent->m_Status = Node::Black;
				pX->m_pParent->m_pParent->m_Status = Node::Red;
				LeftRotate(pX->m_pParent->m_pParent);
			}
		}
	}

	m_pRoot->m_Status = Node::Black;
	SetNil(&m_pRoot->m_pParent);

	return pNewNode;
}
예제 #20
0
int finalize_image_object( struct VMGlobals *g, struct PyrObject *obj )
{
    SharedImage *shared_image_ptr =
            reinterpret_cast<SharedImage*>( slotRawPtr(obj->slots) );
    delete shared_image_ptr;
    SetNil( obj->slots+0 );
    return errNone;
}
예제 #21
0
void QcTreeWidget::Item::initialize (
  VMGlobals *g, PyrObject *obj, const QcTreeWidget::ItemPtr &ptr )
{
  Q_ASSERT( isKindOf( obj, SC_CLASS(TreeViewItem) ) );
  if( ptr.id() ) {
    // store the SafePtr
    QcTreeWidget::ItemPtr *newPtr = new QcTreeWidget::ItemPtr( ptr );
    SetPtr( obj->slots+0, newPtr );
    // store the id for equality comparison
    SetPtr( obj->slots+1, ptr.id() );
    // install finalizer
  }
  else {
    SetNil( obj->slots+0 );
    SetNil( obj->slots+1 );
  }
  InstallFinalizer( g, obj, 2, &QcTreeWidget::Item::finalize );
}
예제 #22
0
파일: SC_HID.cpp 프로젝트: scztt/sc-debug
int prHIDSetValue(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp - 3; //class
	PyrSlot *b = g->sp - 2; //locID
	PyrSlot *c = g->sp - 1; //element device
	PyrSlot *d = g->sp; //value cookie
	int locID, cookieNum, value;
	int err = slotIntVal(b, &locID);
	if (err) return err;
	err = slotIntVal(c, &cookieNum);
	if (err) return err;
	IOHIDElementCookie cookie = (IOHIDElementCookie) cookieNum;
	err = slotIntVal(d, &value);
	if (err) return err;
	//look for the right device:
    pRecDevice  pCurrentHIDDevice = HIDGetFirstDevice ();
	while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=locID))
        pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice);
	if(!pCurrentHIDDevice) return errFailed;
	//look for the right element:
	pRecElement pCurrentHIDElement =  HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeAll);
	// use gElementCookie to find current element
    while (pCurrentHIDElement && (pCurrentHIDElement->cookie != cookie))
        pCurrentHIDElement = HIDGetNextDeviceElement (pCurrentHIDElement, kHIDElementTypeAll);
//struct IOHIDEventStruct
//{
//    IOHIDElementType	type;
//    IOHIDElementCookie	elementCookie;
//    SInt32		value;
//    AbsoluteTime	timestamp;
//    UInt32		longValueSize;
//    void *		longValue;
//};

	if (pCurrentHIDElement)
    {
		IOHIDEventStruct event =
		{
			kIOHIDElementTypeOutput,
			pCurrentHIDElement->cookie,
			value,
			{0},
			sizeof(int),
			NULL
		};
		SInt32 value = HIDSetElementValue (pCurrentHIDDevice, pCurrentHIDElement, &event);
		 // if it's not a button and it's not a hatswitch then calibrate
	//	if(( pCurrentHIDElement->type != kIOHIDElementTypeInput_Button ) &&
	//		( pCurrentHIDElement->usagePage == 0x01 && pCurrentHIDElement->usage != kHIDUsage_GD_Hatswitch))
	//		value = HIDCalibrateValue ( value, pCurrentHIDElement );
		SetInt(a, value);
	}
	else SetNil(a);
	return errNone;

}
예제 #23
0
int prTempoClock_Free(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a = g->sp;
	TempoClock *clock = (TempoClock*)slotRawPtr(&slotRawObject(a)->slots[1]);
	if (!clock) return errNone;	// not running

	SetNil(slotRawObject(a)->slots + 1);
	clock->StopReq();

	return errNone;
}
예제 #24
0
파일: XML.c 프로젝트: montsuqi/libmondai
static void SetNil(ValueStruct *val) {
  int i;

  switch (ValueType(val)) {
  case GL_TYPE_ARRAY:
    for (i = 0; i < ValueArraySize(val); i++) {
      SetNil(ValueArrayItem(val, i));
    }
    break;
  case GL_TYPE_ROOT_RECORD:
  case GL_TYPE_RECORD:
    for (i = 0; i < ValueRecordSize(val); i++) {
      SetNil(ValueRecordItem(val, i));
    }
    break;
  default:
    ValueIsNil(val);
    break;
  }
}
예제 #25
0
int prSymbolClass(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a;
	PyrClass *classobj;
	//char firstChar;

	a = g->sp;
	if (slotRawSymbol(a)->flags & sym_Class) {
	//firstChar = slotRawSymbol(a)->name[0];
	//if (firstChar >= 'A' && firstChar <= 'Z') {
		classobj = slotRawSymbol(a)->u.classobj;
		if (classobj) {
			SetObject(a, classobj);
		} else {
			SetNil(a);
		}
	} else {
		SetNil(a);
	}
	return errNone;
}
예제 #26
0
int prIdentDict_PutGet(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a, *b, *c, *d, *slot, *newslot;
	int i, index, size;
	PyrObject *dict;
	PyrObject *array;

	a = g->sp - 2;  // dict
	b = g->sp - 1;	// key
	c = g->sp;		// value
	d = ++g->sp;	// push the stack to save the receiver

	slotCopy(d,a);
	dict = slotRawObject(d);
	array = slotRawObject(&dict->slots[ivxIdentDict_array]);
	if (!isKindOf((PyrObject*)array, class_array)) {
		SetNil(a);
		--g->sp;
		return errFailed;
	}

	index = arrayAtIdentityHashInPairs(array, b);
	slot = array->slots + index;
	slotCopy(a,&slot[1]);
	slotCopy(&slot[1],c);
	g->gc->GCWrite(array, c);
	if (IsNil(slot)) {
		slotCopy(slot,b);
		g->gc->GCWrite(array, b);
		size = slotRawInt(&dict->slots[ivxIdentDict_size]) + 1;
		SetRaw(&dict->slots[ivxIdentDict_size], size);
		if (array->size < size*3) {
			PyrObject *newarray;
			newarray = newPyrArray(g->gc, size*3, 0, true);
			newarray->size = ARRAYMAXINDEXSIZE(newarray);
			nilSlots(newarray->slots, newarray->size);
			slot = array->slots;
			for (i=0; i<array->size; i+=2, slot+=2) {
				if (NotNil(slot)) {
					index = arrayAtIdentityHashInPairs(newarray, slot);
					newslot = newarray->slots + index;
					slotCopy(&newslot[0],&slot[0]);
					slotCopy(&newslot[1],&slot[1]);
				}
			}
			SetRaw(&dict->slots[ivxIdentDict_array], newarray);
			g->gc->GCWriteNew(dict, newarray); // we know newarray is white so we can use GCWriteNew
		}
	}
	--g->sp;
	return errNone;
}
예제 #27
0
int prIndexOfPrime(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a;
	int n, p;

	a = g->sp;
	n = slotRawInt(a);
	if (n <= 2) {
		if (n == 2) { SetInt(a, 0); }
		else { SetNil(a); }
	} else if (n <= nthPrime(NUMPRIMES-1)) {
		p = findPrime(n);
		if (p < 0) {
			SetNil(a);
		} else {
			SetInt(a, p);
		}
	} else {
		SetNil(a);
	}
	return errNone;
}
예제 #28
0
int prSFClose(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a;

	a = g->sp;

	SNDFILE *file = (SNDFILE*)slotRawPtr(&slotRawObject(a)->slots[0]);
	if (file) {
		sf_close(file);
		SetNil(slotRawObject(a)->slots + 0);
	}

	return errNone;
}
예제 #29
0
int prNthPrime(VMGlobals *g, int numArgsPushed)
{
	PyrSlot *a;
	int n, p;

	a = g->sp;
	n = slotRawInt(a);
	p = nthPrime(n);
	if (p == 0) {
		SetNil(a);
	} else {
		SetInt(a, p);
	}
	return errNone;
}
예제 #30
0
static int prSerialPort_Cleanup(struct VMGlobals *g, int numArgsPushed)
{
	PyrSlot* self = g->sp;
	SerialPort* port = (SerialPort*)getSerialPort(self);

	if (port == 0) return errFailed;

	port->cleanup();

	post("SerialPort Cleanup\n");

	delete port;
	SetNil(slotRawObject(self)->slots+0);
	return errNone;
}