int prHIDBuildElementList(VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp - 2; //class PyrSlot *b = g->sp - 1; //locID device PyrSlot *c = g->sp; //array int locID; int err = slotIntVal(b, &locID); if (err) return err; //look for the right device: pRecDevice pCurrentHIDDevice = HIDGetFirstDevice (); while (pCurrentHIDDevice && (pCurrentHIDDevice->locID !=locID)) pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); if(!pCurrentHIDDevice) return errFailed; pRecElement devElement = HIDGetFirstDeviceElement (pCurrentHIDDevice, kHIDElementTypeAll ); UInt32 numElements = HIDCountDeviceElements (pCurrentHIDDevice, kHIDElementTypeAll ); // PyrObject* devAllElementsArray = newPyrArray(g->gc, numElements * sizeof(PyrObject), 0 , true); PyrObject *devAllElementsArray = c->uo; // post("numElements: %d\n", numElements); numElements = sc_clip(numElements, 0, devAllElementsArray->size); for(uint i=0; i<numElements; i++){ if(devElement){ char cstrElementName [256]; PyrObject* devElementArray = newPyrArray(g->gc, 8 * sizeof(PyrObject), 0 , true); // type name (1) HIDGetTypeName((IOHIDElementType) devElement->type, cstrElementName); PyrString *devstring = newPyrString(g->gc, cstrElementName, 0, true); SetObject(devElementArray->slots+devElementArray->size++, devstring); //g->gc->GCWrite(devElementArray, (PyrObject*) devstring); //usage (2) HIDGetUsageName (devElement->usagePage, devElement->usage, cstrElementName); PyrString *usestring = newPyrString(g->gc, cstrElementName, 0, true); SetObject(devElementArray->slots+devElementArray->size++, usestring); //g->gc->GCWrite(devElementArray, (PyrObject*) usestring); //cookie (3) SetInt(devElementArray->slots+devElementArray->size++, (long) devElement->cookie); // min (4) SetInt(devElementArray->slots+devElementArray->size++, (long) devElement->min); // max (5) SetInt(devElementArray->slots+devElementArray->size++, (long) devElement->max); // IO type as int: (6) SetInt(devElementArray->slots+devElementArray->size++, (int) devElement->type); // Usage page as int: (7) SetInt(devElementArray->slots+devElementArray->size++, (long) devElement->usagePage); // Usage type as int: (8) SetInt(devElementArray->slots+devElementArray->size++, (long) devElement->usage); SetObject(devAllElementsArray->slots+i, devElementArray); //g->gc->GCWrite(devAllElementsArray, (PyrObject*) devElementArray); } devElement = HIDGetNextDeviceElement (devElement, kHIDElementTypeAll); } SetObject(a, devAllElementsArray); return errNone; }
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; }
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 }
int ScIDE_GetDocTextMirror(struct VMGlobals *g, int numArgsPushed) { if (!gIpcClient) { error("ScIDE not connected\n"); return errFailed; } PyrSlot * returnSlot = g->sp - numArgsPushed + 1; PyrSlot * docIDSlot = g->sp - 2; char id[255]; if (slotStrVal( docIDSlot, id, 255 )) return errWrongType; int pos, range, err = errNone; PyrSlot * posSlot = g->sp-1; err = slotIntVal(posSlot, &pos); if (err) return err; PyrSlot * rangeSlot = g->sp; err = slotIntVal(rangeSlot, &range); if (err) return err; QByteArray key = QByteArray(id); QString docText = gIpcClient->getTextMirrorForDocument(key, pos, range); PyrString* pyrString = newPyrString(g->gc, docText.toLatin1().constData(), 0, true); SetObject(returnSlot, pyrString); return errNone; }
static int prPlatform_ideName(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; PyrString* string = newPyrString(g->gc, SC_Filesystem::instance().getIdeName().c_str(), 0, true); SetObject(a, string); return errNone; }
static int prPlatform_ideName(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; PyrString* string = newPyrString(g->gc, gIdeName, 0, true); SetObject(a, string); return errNone; }
static inline int prPlatform_getDirectory(const struct VMGlobals *g, const DirName dirname) { PyrSlot *a = g->sp; const bfs::path& p = SC_Filesystem::instance().getDirectory(dirname); PyrString* string = newPyrString(g->gc, SC_Codecvt::path_to_utf8_str(p).c_str(), 0, true); SetObject(a, string); return errNone; }
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; }
int prSFOpenRead(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a, *b; char filename[PATH_MAX]; SNDFILE *file; SF_INFO info; const char *headerstr; const char *sampleformatstr; a = g->sp - 1; b = g->sp; PyrObject *obj1 = slotRawObject(a); if (!isKindOfSlot(b, class_string)) return errWrongType; if (slotRawObject(b)->size > PATH_MAX - 1) return errFailed; memcpy(filename, slotRawString(b)->s, slotRawObject(b)->size); filename[slotRawString(b)->size] = 0; info.format = 0; file = sf_open(filename, SFM_READ, &info); if (file) { SetPtr(obj1->slots + 0, file); sndfileFormatInfoToStrings(&info, &headerstr, &sampleformatstr); //headerFormatToString(&info, &headerstr); PyrString *hpstr = newPyrString(g->gc, headerstr, 0, true); SetObject(obj1->slots+1, hpstr); g->gc->GCWriteNew(obj1, (PyrObjectHdr*)hpstr); // we know hpstr is white so we can use GCWriteNew PyrString *smpstr = newPyrString(g->gc, sampleformatstr, 0, true); SetObject(obj1->slots+2, smpstr); g->gc->GCWriteNew(obj1, (PyrObjectHdr*)smpstr); // we know smpstr is white so we can use GCWriteNew SetInt(obj1->slots + 3, info.frames); SetInt(obj1->slots + 4, info.channels); SetInt(obj1->slots + 5, info.samplerate); SetTrue(a); } else { SetNil(a); SetFalse(a); } return errNone; }
static int prWinPlatform_myDocumentsDir(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; char path[PATH_MAX]; win32_GetKnownFolderPath(CSIDL_PERSONAL, path, PATH_MAX); \ PyrString* string = newPyrString(g->gc, path, 0, true); \ SetObject(a, string); return errNone; }
void QcApplication::interpret( const QString &str, bool print ) { QtCollider::lockLang(); if( compiledOK ) { VMGlobals *g = gMainVMGlobals; PyrString *strObj = newPyrString( g->gc, str.toStdString().c_str(), 0, true ); SetObject(&slotRawInterpreter(&g->process->interpreter)->cmdLine, strObj); g->gc->GCWrite(slotRawObject(&g->process->interpreter), strObj); runLibrary( print ? SC_SYM(interpretPrintCmdLine) : SC_SYM(interpretCmdLine) ); } QtCollider::unlockLang(); }
int processstring(char *s) { PyrSlot slot; PyrSlotNode *node; PyrString *string; #if DEBUGLEX if (gDebugLexer) postfl("processstring: '%s'\n",s); #endif int flags = compilingCmdLine ? obj_immutable : obj_permanent | obj_immutable; string = newPyrString(gMainVMGlobals->gc, s+1, flags, false); SetObject(&slot, string); node = newPyrSlotNode(&slot); zzval = (long)node; return STRING; }
int prSFHeaderInfoString(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; a = g->sp; SNDFILE *file = (SNDFILE*)slotRawPtr(&slotRawObject(a)->slots[0]); if(file){ static char strbuffer [(1 << 16)] ; sf_command (file, SFC_GET_LOG_INFO, strbuffer, (1 << 16)) ; PyrString *pstring = newPyrString(g->gc, strbuffer, 0, true); // post(strbuffer); SetObject(a, pstring); return errNone; } return errFailed; }
int SC_TerminalClient::prArgv(struct VMGlobals* g, int) { int argc = ((SC_TerminalClient*)SC_TerminalClient::instance())->options().mArgc; char** argv = ((SC_TerminalClient*)SC_TerminalClient::instance())->options().mArgv; PyrSlot* argvSlot = g->sp; PyrObject* argvObj = newPyrArray(g->gc, argc * sizeof(PyrObject), 0, true); SetObject(argvSlot, argvObj); for (int i=0; i < argc; i++) { PyrString* str = newPyrString(g->gc, argv[i], 0, true); SetObject(argvObj->slots+i, str); argvObj->size++; g->gc->GCWriteNew(argvObj, (PyrObject*)str); // we know str is white so we can use GCWriteNew } return errNone; }
int prFileRealPath(struct VMGlobals* g, int numArgsPushed ) { PyrSlot *a = g->sp - 1, *b = g->sp; char ipath[PATH_MAX]; char opath[PATH_MAX]; int err; err = slotStrVal(b, ipath, PATH_MAX); if (err) return err; bool isAlias = false; if(sc_ResolveIfAlias(ipath, opath, isAlias, PATH_MAX)!=0) { return errFailed; } boost::system::error_code error_code; boost::filesystem::path p = boost::filesystem::canonical(opath,error_code); if(error_code) { SetNil(a); return errNone; } strcpy(opath,p.string().c_str()); #if SC_DARWIN CFStringRef cfstring = CFStringCreateWithCString(NULL, opath, kCFStringEncodingUTF8); err = !CFStringGetFileSystemRepresentation(cfstring, opath, PATH_MAX); CFRelease(cfstring); if (err) return errFailed; #endif // SC_DARWIN PyrString* pyrString = newPyrString(g->gc, opath, 0, true); SetObject(a, pyrString); return errNone; }
int prSignalString(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a; PyrString *string; PyrObject *signal; float *x; char str[128]; a = g->sp; slotString(a, str); signal = slotRawObject(a); if (signal->size) { x = (float*)(signal->slots); sprintf(str, "%s[%g .. %g]", slotRawSymbol(&signal->classptr->name)->name, x[0], x[signal->size-1]); } else { sprintf(str, "%s[none]", slotRawSymbol(&signal->classptr->name)->name); } string = newPyrString(g->gc, str, 0, true); SetObject(a, string); return errNone; }
int prHIDBuildDeviceList(VMGlobals *g, int numArgsPushed) { //build a device list PyrSlot *a = g->sp - 2; PyrSlot *b = g->sp - 1; //usagePage PyrSlot *c = g->sp; //usage int usagePage, usage, err; if(IsNil(b)) usagePage = 0; else { err = slotIntVal(b, &usagePage); if (err) return err; } if(IsNil(c)) usage = 0; else { err = slotIntVal(c, &usage); if (err) return err; } //pass in usage & usagepage //kHIDUsage_GD_Joystick kHIDUsage_GD_GamePad //UInt32 usagePage = kHIDPage_GenericDesktop; //UInt32 usage = NULL; Boolean result = HIDBuildDeviceList (usagePage, usage); // returns false if no device found (ignored in this case) - returns always false ? if(result) post("no HID devices found\n"); int numdevs = HIDCountDevices(); gNumberOfHIDDevices = numdevs; if(!numdevs){ SetNil(a); return errNone; } //post("number of devices: %d", numdevs); char cstrDeviceName [256]; pRecDevice pCurrentHIDDevice = HIDGetFirstDevice (); PyrObject* allDevsArray = newPyrArray(g->gc, numdevs * sizeof(PyrObject), 0 , true); for(int i=0; i<numdevs; i++){ //device: PyrObject* devNameArray = newPyrArray(g->gc, 8 * sizeof(PyrObject), 0 , true); //manufacturer: PyrString *devstring = newPyrString(g->gc, pCurrentHIDDevice->manufacturer, 0, true); SetObject(devNameArray->slots+devNameArray->size++, devstring); g->gc->GCWrite(devNameArray, (PyrObject*) devstring); //product name: devstring = newPyrString(g->gc, pCurrentHIDDevice->product, 0, true); SetObject(devNameArray->slots+devNameArray->size++, devstring); g->gc->GCWrite(devNameArray, (PyrObject*) devstring); //usage HIDGetUsageName (pCurrentHIDDevice->usagePage, pCurrentHIDDevice->usage, cstrDeviceName); devstring = newPyrString(g->gc, cstrDeviceName, 0, true); SetObject(devNameArray->slots+devNameArray->size++, devstring); g->gc->GCWrite(devNameArray, (PyrObject*) devstring); //vendor id SetInt(devNameArray->slots+devNameArray->size++, pCurrentHIDDevice->vendorID); //product id SetInt(devNameArray->slots+devNameArray->size++, pCurrentHIDDevice->productID); //locID SetInt(devNameArray->slots+devNameArray->size++, pCurrentHIDDevice->locID); //version SetInt(devNameArray->slots+devNameArray->size++, pCurrentHIDDevice->version); //serial devstring = newPyrString(g->gc, pCurrentHIDDevice->serial, 0, true); SetObject(devNameArray->slots+devNameArray->size++, devstring); g->gc->GCWrite(devNameArray, (PyrObject*) devstring); SetObject(allDevsArray->slots+allDevsArray->size++, devNameArray); g->gc->GCWrite(allDevsArray, (PyrObject*) devNameArray); pCurrentHIDDevice = HIDGetNextDevice (pCurrentHIDDevice); } //UInt32 outnum = HIDCountDeviceElements (pCurrentHIDDevice, kHIDElementTypeOutput); //post("number of outputs: %d \n", outnum); SetObject(a, allDevsArray); return errNone; }
/* ------------------------------------------------------------- */ int prListMIDIEndpoints(struct VMGlobals *g, int numArgsPushed) { PyrSlot *a = g->sp; int numSrc = gNumMIDIInPorts; int numDst = gNumMIDIOutPorts; PyrObject* idarray = newPyrArray(g->gc, 6 * sizeof(PyrObject), 0 , true); SetObject(a, idarray); // 0 PyrObject* idarraySo = newPyrArray(g->gc, numSrc * sizeof(__int32), 0 , true); SetObject(idarray->slots+idarray->size++, idarraySo); g->gc->GCWrite(idarray, idarraySo); // 1 PyrObject* devarraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarraySo); g->gc->GCWrite(idarray, devarraySo); // 2 PyrObject* namearraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearraySo); g->gc->GCWrite(idarray, namearraySo); // 3 PyrObject* idarrayDe = newPyrArray(g->gc, numDst * sizeof(__int32), 0 , true); SetObject(idarray->slots+idarray->size++, idarrayDe); g->gc->GCWrite(idarray, idarrayDe); // 4 PyrObject* namearrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearrayDe); g->gc->GCWrite(idarray, namearrayDe); // 5 PyrObject* devarrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarrayDe); g->gc->GCWrite(idarray, devarrayDe); for (int i=0; i<numSrc; ++i) { const PmDeviceInfo* devInfo = Pm_GetDeviceInfo(gMidiInputIndexToPmDevIndex[i]); char cendname[1024], cdevname[1024]; // currently, copy both name strings in endpoint name and dev name strncpy(cendname,devInfo->name,1023); cendname[1023] = 0; strncpy(cdevname,devInfo->name,1023); cdevname[1023] = 0; PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearraySo->slots+i, string); namearraySo->size++; g->gc->GCWrite(namearraySo, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarraySo->slots+i, devstring); devarraySo->size++; g->gc->GCWrite(devarraySo, (PyrObject*)devstring); SetInt(idarraySo->slots+i, i); idarraySo->size++; } // post("numDst %d\n", numDst); for (int i=0; i<numDst; ++i) { const PmDeviceInfo* devInfo = Pm_GetDeviceInfo(gMidiOutputIndexToPmDevIndex[i]); char cendname[1024], cdevname[1024]; // currently, copy both name strings in endpoint name and dev name strncpy(cendname,devInfo->name,1023); cendname[1023] = 0; strncpy(cdevname,devInfo->name,1023); cdevname[1023] = 0; PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearrayDe->slots+namearrayDe->size++, string); g->gc->GCWrite(namearrayDe, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarrayDe->slots+devarrayDe->size++, devstring); g->gc->GCWrite(devarrayDe, (PyrObject*)devstring); SetInt(idarrayDe->slots+idarrayDe->size++, i); } return errNone; }
int prListMIDIEndpoints(struct VMGlobals *g, int numArgsPushed) { OSStatus error; PyrSlot *a = g->sp; int numSrc = (int)MIDIGetNumberOfSources(); int numDst = (int)MIDIGetNumberOfDestinations(); PyrObject* idarray = newPyrArray(g->gc, 6 * sizeof(PyrObject), 0 , true); SetObject(a, idarray); PyrObject* idarraySo = newPyrArray(g->gc, numSrc * sizeof(SInt32), 0 , true); SetObject(idarray->slots+idarray->size++, idarraySo); g->gc->GCWrite(idarray, idarraySo); PyrObject* devarraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarraySo); g->gc->GCWrite(idarray, devarraySo); PyrObject* namearraySo = newPyrArray(g->gc, numSrc * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearraySo); g->gc->GCWrite(idarray, namearraySo); PyrObject* idarrayDe = newPyrArray(g->gc, numDst * sizeof(SInt32), 0 , true); SetObject(idarray->slots+idarray->size++, idarrayDe); g->gc->GCWrite(idarray, idarrayDe); PyrObject* namearrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, namearrayDe); g->gc->GCWrite(idarray, namearrayDe); PyrObject* devarrayDe = newPyrArray(g->gc, numDst * sizeof(PyrObject), 0 , true); SetObject(idarray->slots+idarray->size++, devarrayDe); g->gc->GCWrite(idarray, devarrayDe); for (int i=0; i<numSrc; ++i) { MIDIEndpointRef src = MIDIGetSource(i); SInt32 id; MIDIObjectGetIntegerProperty(src, kMIDIPropertyUniqueID, &id); MIDIEntityRef ent; error = MIDIEndpointGetEntity(src, &ent); CFStringRef devname, endname; char cendname[1024], cdevname[1024]; // Virtual sources don't have entities if(error) { MIDIObjectGetStringProperty(src, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } else { MIDIDeviceRef dev; MIDIEntityGetDevice(ent, &dev); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(src, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearraySo->slots+i, string); namearraySo->size++; g->gc->GCWrite(namearraySo, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarraySo->slots+i, devstring); devarraySo->size++; g->gc->GCWrite(devarraySo, (PyrObject*)devstring); SetInt(idarraySo->slots+i, id); idarraySo->size++; CFRelease(devname); CFRelease(endname); } // post("numDst %d\n", numDst); for (int i=0; i<numDst; ++i) { MIDIEndpointRef dst = MIDIGetDestination(i); SInt32 id; MIDIObjectGetIntegerProperty(dst, kMIDIPropertyUniqueID, &id); MIDIEntityRef ent; error = MIDIEndpointGetEntity(dst, &ent); CFStringRef devname, endname; char cendname[1024], cdevname[1024]; // Virtual destinations don't have entities either if(error) { MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } else { MIDIDeviceRef dev; MIDIEntityGetDevice(ent, &dev); MIDIObjectGetStringProperty(dev, kMIDIPropertyName, &devname); MIDIObjectGetStringProperty(dst, kMIDIPropertyName, &endname); CFStringGetCString(devname, cdevname, 1024, kCFStringEncodingUTF8); CFStringGetCString(endname, cendname, 1024, kCFStringEncodingUTF8); } PyrString *string = newPyrString(g->gc, cendname, 0, true); SetObject(namearrayDe->slots+namearrayDe->size++, string); g->gc->GCWrite(namearrayDe, (PyrObject*)string); PyrString *devstring = newPyrString(g->gc, cdevname, 0, true); SetObject(devarrayDe->slots+devarrayDe->size++, devstring); g->gc->GCWrite(devarrayDe, (PyrObject*)devstring); SetInt(idarrayDe->slots+idarrayDe->size++, id); CFRelease(devname); CFRelease(endname); } return errNone; }
int prString_FindRegexp(struct VMGlobals *g, int numArgsPushed) { int err; PyrSlot *a = g->sp - 2; // source string PyrSlot *b = g->sp - 1; // pattern PyrSlot *c = g->sp; // offset if (!isKindOfSlot(b, class_string) || (NotInt(c))) return errWrongType; // post("prString_FindRegexp\n"); int maxfind = MAXREGEXFIND; int offset = slotRawInt(c); int stringsize = slotRawObject(a)->size + 1; int patternsize = slotRawObject(b)->size + 1; char *string = (char*)malloc(slotRawObject(a)->size + 1); err = slotStrVal(a, string, slotRawObject(a)->size + 1); if (err){ free(string); return err; } char *pattern = (char*)malloc(slotRawObject(b)->size + 1); err = slotStrVal(b, pattern, slotRawObject(b)->size + 1); if (err) return err; UParseError uerr; UErrorCode status = (UErrorCode)0; UChar *regexStr; UChar *ustring; regexStr = (UChar*)malloc((patternsize)*sizeof(UChar)); u_charsToUChars (pattern, regexStr, patternsize); ustring = (UChar*)malloc((stringsize)*sizeof(UChar)); u_charsToUChars (string+offset, ustring, stringsize-offset); unsigned flags = UREGEX_MULTILINE; int groupNumber = 0; SCRegExRegion * what; int indx = 0; int size = 0; URegularExpression *expression = uregex_open(regexStr, -1, flags, &uerr, &status); if(U_FAILURE(status)) goto nilout; if(!U_FAILURE(status)) { uregex_setText(expression, ustring, -1, &status); what = (SCRegExRegion*)malloc((maxfind)*sizeof(SCRegExRegion)); for(int i=0; i< maxfind; i++) { SCRegExRegion range; range.matched = false; what[i] = range; } int32_t groups = uregex_groupCount(expression, &status) + 1; if(U_FAILURE(status)) goto nilout; // post("groups: %i\n", groups); while (uregex_findNext(expression, &status) && size<maxfind) { if(U_FAILURE(status)) return errNone; for(int i=0; i< groups; ++i){ what[size].group = i; what[size].start = sc_clip(uregex_start(expression, i, &status), 0, stringsize) ; if(U_FAILURE(status)) goto nilout; what[size].end = sc_clip(uregex_end(expression, i, &status), 0, stringsize); what[size].matched = true; // post("index:%i, size:%i, start %i, end %i\n", i, size, what[i].start, what[i].end); size = indx++ + 1; if(U_FAILURE(status)) goto nilout; } } PyrObject *result_array = newPyrArray(g->gc, size, 0, true); result_array->size = 0; if (size>0) //(matched) { for (int i = 0; i < size; i++) { if (what[0].matched == false) { result_array->size++; SetNil(result_array->slots+i); } else { result_array->size++; int match_start = what[i].start; int match_length = what[i].end - what[i].start; // post("for i:%i, start %i, end %i\n", i, what[i].start, what[i].end); // char *match = (char*)malloc(match_length); char match[match_length]; strncpy(match, string + offset + match_start, match_length); match[match_length] = 0; PyrObject *array = newPyrArray(g->gc, 2, 0, true); array->size = 2; SetInt(array->slots, match_start + offset); PyrObject *matched_string = (PyrObject*)newPyrString(g->gc, match, 0, true); SetObject(array->slots+1, matched_string); g->gc->GCWrite(matched_string, array->slots + 1); SetObject(result_array->slots + i, array); g->gc->GCWrite(array, result_array->slots + i); } } } else { SetNil(a); } free(what); free(pattern); free(regexStr); free(ustring); free(string); SetObject(a, result_array); g->gc->GCWrite(result_array,a); //uregex_close(expression); return errNone; } nilout: free(string); free(what); free(pattern); free(regexStr); free(ustring); SetNil(a); return errNone; }
int prHID_API_GetInfo( VMGlobals* g, int numArgsPushed ){ PyrSlot *args = g->sp - numArgsPushed + 1; PyrSlot* self = args + 0; PyrSlot* arg = args + 1; int err; int joyid; err = slotIntVal( arg, &joyid ); if ( err != errNone ) return err; const char emptyString[] = ""; struct hid_dev_desc * devdesc = SC_HID_APIManager::instance().get_device( joyid ); struct hid_device_info * cur_dev = devdesc->info; if ( cur_dev != NULL ){ PyrObject* devInfo = newPyrArray(g->gc, 9 * sizeof(PyrObject), 0 , true); SetObject( self, devInfo ); SetInt(devInfo->slots+devInfo->size++, cur_dev->vendor_id); SetInt(devInfo->slots+devInfo->size++, cur_dev->product_id); PyrString *dev_path_name = newPyrString(g->gc, cur_dev->path, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_path_name); g->gc->GCWrite(devInfo, dev_path_name); const char * mystring; if ( cur_dev->serial_number != NULL ){ mystring = wchar_to_char( cur_dev->serial_number ); } else { mystring = emptyString; } PyrString *dev_serial = newPyrString(g->gc, mystring, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_serial); g->gc->GCWrite(devInfo, dev_serial); if (mystring != emptyString) free((void*)mystring); if ( cur_dev->manufacturer_string != NULL ){ mystring = wchar_to_char( cur_dev->manufacturer_string ); } else { mystring = emptyString; } PyrString *dev_man_name = newPyrString(g->gc, mystring, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_man_name); g->gc->GCWrite(devInfo, dev_man_name); if (mystring != emptyString) free((void*)mystring); if ( cur_dev->product_string != NULL ){ mystring = wchar_to_char( cur_dev->product_string ); } else { mystring = emptyString; } PyrString *dev_prod_name = newPyrString(g->gc, mystring, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_prod_name); g->gc->GCWrite(devInfo, dev_prod_name); if (mystring != emptyString) free((void*)mystring); SetInt(devInfo->slots+devInfo->size++, cur_dev->release_number); SetInt(devInfo->slots+devInfo->size++, cur_dev->interface_number); } else { SetInt( self, 0 ); } return errNone; }
int prHID_API_BuildDeviceList(VMGlobals* g, int numArgsPushed){ PyrSlot *args = g->sp - numArgsPushed + 1; PyrSlot *self = args + 0; // no arguments int err; const char emptyString[] = ""; // iterate over available devices and return info to language to populate the list there int result = SC_HID_APIManager::instance().build_devicelist(); if ( result > 0 ){ PyrObject* allDevsArray = newPyrArray(g->gc, result * sizeof(PyrObject), 0 , true); SetObject( self, allDevsArray ); struct hid_device_info *cur_dev = SC_HID_APIManager::instance().devinfos; while( cur_dev ){ PyrObject* devInfo = newPyrArray(g->gc, 11 * sizeof(PyrObject), 0 , true); SetInt(devInfo->slots+devInfo->size++, cur_dev->vendor_id); SetInt(devInfo->slots+devInfo->size++, cur_dev->product_id); PyrString *dev_path_name = newPyrString(g->gc, cur_dev->path, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_path_name); g->gc->GCWrite(devInfo, dev_path_name); const char * mystring; if ( cur_dev->serial_number != NULL ) mystring = wchar_to_char( cur_dev->serial_number ); else mystring = emptyString; PyrString *dev_serial = newPyrString(g->gc, mystring, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_serial); g->gc->GCWrite(devInfo, dev_serial); if (mystring != emptyString) free((void*)mystring); if ( cur_dev->manufacturer_string != NULL ) mystring = wchar_to_char( cur_dev->manufacturer_string ); else mystring = emptyString; PyrString *dev_man_name = newPyrString(g->gc, mystring, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_man_name); g->gc->GCWrite(devInfo, dev_man_name); if (mystring != emptyString) free((void*)mystring); if ( cur_dev->product_string != NULL ) mystring = wchar_to_char( cur_dev->product_string ); else mystring = emptyString; PyrString *dev_prod_name = newPyrString(g->gc, mystring, 0, true ); SetObject(devInfo->slots+devInfo->size++, dev_prod_name); g->gc->GCWrite(devInfo, dev_prod_name); if (mystring != emptyString) free((void*)mystring); SetInt(devInfo->slots+devInfo->size++, cur_dev->release_number); SetInt(devInfo->slots+devInfo->size++, cur_dev->interface_number); SetInt(devInfo->slots+devInfo->size++, cur_dev->usage_page); SetInt(devInfo->slots+devInfo->size++, cur_dev->usage); SetObject(allDevsArray->slots+allDevsArray->size++, devInfo ); g->gc->GCWrite(allDevsArray, devInfo); cur_dev = cur_dev->next; } SC_HID_APIManager::instance().free_devicelist(); } else { // send back info that no devices were found, or empty array SetInt( self, 0 ); } return errNone; }