IO_METHOD(IoSeq, replaceFirstSeq) { /*doc Sequence replaceFirstSeq(aSequence, anotherSequence, optionalStartIndex) Returns a new Sequence with the first occurance of aSequence replaced with anotherSequence in the receiver. If optionalStartIndex is provided, the search for aSequence begins at that index. Returns self. */ IoSeq *subSeq = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1); size_t startIndex = 0; if (IoMessage_argCount(m) > 2) { startIndex = IoMessage_locals_longArgAt_(m, locals, 2); } IO_ASSERT_NOT_SYMBOL(self); { UArray *a = DATA(self); UArray *b = DATA(subSeq); UArray *c = DATA(otherSeq); long i = UArray_find_from_(a, b, startIndex); if(i != -1) { UArray_removeRange(a, i, UArray_size(b)); UArray_at_putAll_(a, i, c); } } return self; }
IO_METHOD(IoSeq, replaceSeq) { /*doc Sequence replaceSeq(aSequence, anotherSequence) Returns a new Sequence with all occurances of aSequence replaced with anotherSequence in the receiver. Returns self. */ IoSeq *subSeq = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 1); IO_ASSERT_NOT_SYMBOL(self); UArray_replace_with_(DATA(self), DATA(subSeq), DATA(otherSeq)); return self; }
IoObject *IoSkipDB_atPut(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDB atPut(keySymbol, valueSequence) Sets the value of valueSequence with the key keySymbol. Returns self. */ IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *value = IoMessage_locals_seqArgAt_(m, locals, 1); IOASSERT(SKIPDB(self) && SkipDB_isOpen(SKIPDB(self)), "invalid skipdb"); SkipDB_at_put_(SKIPDB(self), IoSeq_asDatum(key), IoSeq_asDatum(value)); return self; }
IO_METHOD(IoDate, fromString) { /*doc Date fromString(aString, formatString) Sets the receiver to the date specified by aString as parsed according to the given formatString. See the Date asString method for formatting rules. Returns self. */ IoMessage_assertArgCount_receiver_(m, 2, self); { IoSymbol *date_input = IoMessage_locals_seqArgAt_(m, locals, 0); IoSymbol *format = IoMessage_locals_seqArgAt_(m, locals, 1); Date_fromString_format_(DATA(self), CSTRING(date_input), CSTRING(format)); } IoObject_isDirty_(self, 1); return self; }
IoObject *IoLinker_makeCFunction(IoLinker *self, IoObject *locals, IoMessage *m) { /*doc Linker makeCFunction(aSeq, slotName, object) Creates a CFunction which users the beginning address of the data in aSeq as its function pointer and adds the CFunction to the given object on slot slotName. */ IoSeq *buffer = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *slotName = IoMessage_locals_seqArgAt_(m, locals, 1); IoObject *object = IoMessage_locals_valueArgAt_(m, locals, 2); IoCFunction *f; IoUserFunction* fp = (IoUserFunction*)IoSeq_rawBytes(buffer); f = IoCFunction_newWithFunctionPointer_tag_name_(IOSTATE, fp, IoObject_tag(object), CSTRING(slotName)); IoObject_setSlot_to_(f, IOSYMBOL("compiledCode"), buffer); return f; }
IoObject *IoAppleSensors_smsVector(IoAppleSensors *self, IoObject *locals, IoMessage *m) { /*doc AppleSensors smsVector(aVector) Sets aVector to the current x, y and z accelerometer values. Returns true on success and false on failure. */ IoSeq *vector = IoMessage_locals_seqArgAt_(m, locals, 0); float *f = IoSeq_floatPointerOfLength_(vector, 3); int err; if (smsType == -1) { smsType = detect_sms(); } int v[3] = {0, 0, 0}; err = read_sms(smsType, &v[0], &v[1], &v[3]); f[0] = v[0]; f[1] = v[1]; f[2] = v[2]; return err ? IOTRUE(self) : IOFALSE(self); }
IoObject *IoAsyncRequest_write(IoAsyncRequest *self, IoObject *locals, IoMessage *m) { /*doc AsyncRequest write(fileOffset, aSeq, bufferOffset, numberOfBytesToWrite) Submits an async write request. Returns nil on error, self otherwise. */ int r; IoSeq *data; UArray *ba; int bufferOffset; int bytesToWrite; IOCB(self)->aio_offset = (size_t)CNUMBER(IoMessage_locals_numberArgAt_(m, locals, 0)); data = IoMessage_locals_seqArgAt_(m, locals, 1); ba = IoSeq_rawUArray(data); bufferOffset = IoMessage_locals_intArgAt_(m, locals, 2); bytesToWrite = IoMessage_locals_intArgAt_(m, locals, 3); if (bytesToWrite > UArray_size(ba) - bufferOffset) { bytesToWrite = UArray_size(ba) - bufferOffset; } IOCB(self)->aio_nbytes = bytesToWrite; IOCB(self)->aio_buf = realloc(IOCB_BUFFER(self), bytesToWrite); memcpy(IOCB_BUFFER(self), UArray_bytes(ba), bytesToWrite); r = aio_write(IOCB(self)); return r == 0 ? self : IONIL(self); }
IoSecureServer *IoSecureServer_setCRLFile(IoSecureServer *self, IoObject *locals, IoMessage *msg) { SSL_CTX *ctx = OCTX(self); IoSeq *pathSeq = IoMessage_locals_seqArgAt_(msg, locals, 0); char *path = IoSeq_asCString(pathSeq); if(ctx == NULL) { IoState_error_(IOSTATE, msg, "SecureServer has no SSL_CTX"); return IONIL(self); } X509_STORE *store = SSL_CTX_get_cert_store(ctx); X509_STORE_set_verify_cb_func(store, IoSecureSockets_Verify_CRL_Callback); X509_STORE_set_flags (store, X509_V_FLAG_CRL_CHECK | X509_V_FLAG_CRL_CHECK_ALL); X509_LOOKUP *lookup; if (!(lookup = X509_STORE_add_lookup (store, X509_LOOKUP_file ()))) { ERR_print_errors_fp(stderr); IoState_error_(IOSTATE, msg, "Error creating X509_LOOKUP object."); return IONIL(self); } if (X509_load_crl_file(lookup, path, X509_FILETYPE_PEM) != 1) { ERR_print_errors_fp(stderr); IoState_error_(IOSTATE, msg, "Error loading CRL from file %s\n", path); return IONIL(self); } return self; }
IoObject *IoIPAddress_setIp(IoIPAddress *self, IoObject *locals, IoMessage *m) { IoSeq *ip = IoMessage_locals_seqArgAt_(m, locals, 0); char *ipString = IoSeq_asCString(ip); IPAddress_setIp_(IPADDRESS(self), ipString); return self; }
/*doc Memcached replace(key, value[, expiration]) Asks memcached to store the value identified by the key, but only if the server *does* already hold data for this key. Returns true on success, false if there is already data for this key. Otherwise raises an exception. */ IoObject *IoMemcached_replace(IoMemcached *self, IoObject *locals, IoMessage *m) { IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IoObject *value = IoMessage_locals_quickValueArgAt_(m, locals, 1); time_t expiration = IoMessage_argCount(m) == 3 ? IoMessage_locals_intArgAt_(m, locals, 2) : 0; uint32_t flags; size_t size; char *cvalue = IoMemcached_serialize(self, locals, value, &size, &flags); memcached_return_t rc; rc = memcached_replace(DATA(self)->mc, CSTRING(key), IOSEQ_LENGTH(key), cvalue, size, expiration, flags ); free(cvalue); if(rc != MEMCACHED_SUCCESS && rc != MEMCACHED_NOTSTORED) IoState_error_(IOSTATE, m, memcached_strerror(DATA(self)->mc, rc)); // MEMCACHED_NOTSTORED is a legitmate error in the case of a collision. if(rc == MEMCACHED_NOTSTORED) return IOSTATE->ioFalse; return IOSTATE->ioTrue; // MEMCACHED_SUCCESS }
IoObject *IoTagDB_atKeyPutTags(IoTagDB *self, IoObject *locals, IoMessage *m) { /*doc TagDB atKeyPutTags(key, tagNameList) Sets the tags for key to those in tagNameList. Returns self. */ TagDB *tdb = DATA(self); IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IoList *tagNames = IoMessage_locals_listArgAt_(m, locals, 1); symbolid_t keyid = TagDB_idForSymbol_size_(tdb, CSTRING(key), IoSeq_rawSize(key)); // debugging check /* Datum *keyDatum = TagDB_symbolForId_(tdb, keyid); printf("%s -> %i\n", CSTRING(key), (int)keyid); printf("%i -> %s\n", (int)keyid, (char *)(keyDatum->data)); assert(strcmp((char *)(keyDatum->data), (char *)CSTRING(key)) == 0); Datum_free(keyDatum); */ { Uint64Array *tags = IoTagDB_tagArrayForTagNames_(self, m, tagNames); TagDB_begin(tdb); TagDB_atKey_putTags_(tdb, keyid, tags); TagDB_commit(tdb); Uint64Array_free(tags); } return self; }
IoObject *IoFont_lengthOfString(IoFont *self, IoObject *locals, IoMessage *m) { /*doc Font widthOfString(aString) Returns a Number with the width that aString would render to with the receiver's current settings. */ IoSymbol *text = IoMessage_locals_seqArgAt_(m, locals, 0); int startIndex = 0; int max = IoSeq_rawSize(text); int endIndex = max; if (IoMessage_argCount(m) == 2) { startIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1)); if (startIndex > max) startIndex = max; } if (IoMessage_argCount(m) > 2) { endIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 2)); if (startIndex > max) endIndex = max; } return IONUMBER( GLFont_lengthOfString( DATA(self)->font, CSTRING(text), startIndex, endIndex) ); }
IoObject *IoFont_drawString(IoFont *self, IoObject *locals, IoMessage *m) { /*doc Font drawString(aString, optionalStartIndex, optionalEndIndex) Draws aString using the optional start and end indexes, if supplied. Returns self. <p> Note; Fonts are drawn as RGBA pixel maps. These blending options are recommended: <pre> glEnable(GL_BLEND) glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA) </pre> */ IoSymbol *textString = IoMessage_locals_seqArgAt_(m, locals, 0); int startIndex = 0; int endIndex; if (IoMessage_argCount(m) > 1) { startIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 1)); if (startIndex > (int)IoSeq_rawSize(textString)) startIndex = (int)IoSeq_rawSize(textString); } if (IoMessage_argCount(m) > 2) { endIndex = IoNumber_asInt(IoMessage_locals_numberArgAt_(m, locals, 2)); } else { endIndex = IoSeq_rawSize(textString); } GLFont_drawString(DATA(self)->font, CSTRING(textString) , startIndex, endIndex); IoFont_checkError(self, locals, m); return self; }
//doc ClutterColor fromString(str) IO_METHOD(IoClutterColor, fromString) { ClutterColor color; char *seq = CSTRING(IoMessage_locals_seqArgAt_(m, locals, 0)); clutter_color_from_string(&color, seq); return IoClutterColor_newWithColor(IOSTATE, color); }
IO_METHOD(IoFile, write) { /*doc File write(aSequence1, aSequence2, ...) Writes the arguments to the receiver file. Returns self. */ int i; IoFile_assertOpen(self, locals, m); IoFile_assertWrite(self, locals, m); for (i = 0; i < IoMessage_argCount(m); i ++) { IoSymbol *string = IoMessage_locals_seqArgAt_(m, locals, i); UArray_writeToCStream_(IoSeq_rawUArray(string), DATA(self)->stream); if (ferror(DATA(self)->stream) != 0) { IoState_error_(IOSTATE, m, "error writing to file '%s'", UTF8CSTRING(DATA(self)->path)); } } return self; }
/*doc Memcached prepend(key, value) Asks memcached to add this value to an existing key before existing value. Returns true on success, otherwise raises an exception. value should be a Sequence. Supported by memcached 1.2.4+ */ IoObject *IoMemcached_prepend(IoMemcached *self, IoObject *locals, IoMessage *m) { IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *value = IoMessage_locals_seqArgAt_(m, locals, 1); memcached_return_t rc; rc = memcached_prepend(DATA(self)->mc, CSTRING(key), IOSEQ_LENGTH(key), CSTRING(value), IOSEQ_LENGTH(value), 0, 0 ); if(rc != MEMCACHED_SUCCESS) IoState_error_(IOSTATE, m, memcached_strerror(DATA(self)->mc, rc)); return IOSTATE->ioTrue; }
IoObject *IoTagDB_idForSymbol(IoTagDB *self, IoObject *locals, IoMessage *m) { /*doc TagDB idForSymbol(aSeq) Returns the TagDB id Number for the symbol specified by aSeq. */ IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); return IONUMBER(TagDB_idForSymbol_size_(DATA(self), CSTRING(key), IoSeq_rawSize(key))); }
IoObject *IoFont_setPath(IoFont *self, IoObject *locals, IoMessage *m) { /*doc Font setPath(aString) Sets the Font path. Returns self. */ DATA(self)->path = IOREF(IoMessage_locals_seqArgAt_(m, locals, 0)); return self; }
IoObject *IoTagDB_setPath(IoTagDB *self, IoObject *locals, IoMessage *m) { /*doc TagDB setPath(aPath) Sets the path to the tag database. Returns self. */ IoSeq *path = IoMessage_locals_seqArgAt_(m, locals, 0); TagDB_setPath_(DATA(self), CSTRING(path)); return self; }
IoObject *IoEditLine_addHistory(IoEditLine *self, IoObject *locals, IoMessage *m) { IoSeq *line = IoMessage_locals_seqArgAt_(m, locals, 0); HistEvent ev; history(DATA(self)->history, &ev, H_ENTER, CSTRING(line)); return self; }
IoObject *IoLinker_hexSeqToBytes(IoLinker *self, IoObject *locals, IoMessage *m) { /*doc Linker hexSeqToBytes(aSeq) Returns a Sequence containing a binary representation of the hex data in aSeq. */ IoSeq *buffer = IoMessage_locals_seqArgAt_(m, locals, 0); UArray *ba = IoSeq_rawUArray(buffer); return IoSeq_newWithUArray_copy_(IOSTATE, UArray_fromHexStringUArray(ba), 0); }
IoObject *IoSkipDBM_setPath(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDBM setPath(aString) Sets the path to the dbm folder. Returns self. */ IoSeq *v = IoMessage_locals_seqArgAt_(m, locals, 0); SkipDBM_setPath_(SKIPDBM(self), CSTRING(v)); return self; }
IoObject *IoYajlGen_pushNumberString(IoYajlGen *self, IoObject *locals, IoMessage *m) { IoSeq *s = IoMessage_locals_seqArgAt_(m, locals, 0); yajl_gen_number(DATA(self), (const char *)IOSYMBOL_BYTES(s), IOSYMBOL_LENGTH(s)); return self; }
IoObject *IoLinker_bytesToHexSeq(IoLinker *self, IoObject *locals, IoMessage *m) { /*doc Linker bytesToHexSeq(aSeq) Returns a Sequence containing a hex representation of aSeq. */ IoSeq *buffer = IoMessage_locals_seqArgAt_(m, locals, 0); UArray *ba = IoSeq_rawUArray(buffer); return IoSeq_newWithUArray_copy_(IOSTATE, UArray_asNewHexStringUArray(ba), 0); }
IoObject *IoSHA1_hmac(IoSHA1 *self, IoObject *locals, IoMessage *m) { /*doc SHA1 hmac(key, data) Returns a hmac signature sequence or nil on error. */ IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IoSeq *inSeq = IoMessage_locals_seqArgAt_(m, locals, 1); char resbuf[20]; int ok; memset(resbuf, 0x0, 20); ok = hmac_sha1( IOSEQ_BYTES(key), IOSEQ_LENGTH(key), IOSEQ_BYTES(inSeq), IOSEQ_LENGTH(inSeq), (void *)resbuf); if(ok != 0) return IONIL(self); return IOSEQ(resbuf, 20); }
IoObject *IoYajlGen_pushString(IoYajlGen *self, IoObject *locals, IoMessage *m) { IoSeq *s = IoMessage_locals_seqArgAt_(m, locals, 0); yajl_gen_string(DATA(self), (const unsigned char *)IOSYMBOL_BYTES(s), (int)IOSYMBOL_LENGTH(s)); return self; }
IO_METHOD(IoSeq, clipBeforeSeq) { /*doc Sequence clipBeforeSeq(aSequence) Clips receiver before aSequence. */ IoSeq *otherSeq = IoMessage_locals_seqArgAt_(m, locals, 0); IO_ASSERT_NOT_SYMBOL(self); UArray_clipBefore_(DATA(self), DATA(otherSeq)); return self; }
IO_METHOD(IoSeq, removeSeq) { /*doc Sequence removeSeq(aSequence) Removes occurances of aSequence from the receiver. */ IoSeq *subSeq = IoMessage_locals_seqArgAt_(m, locals, 0); IO_ASSERT_NOT_SYMBOL(self); UArray_remove_(DATA(self), DATA(subSeq)); return self; }
IoObject *IoSkipDB_removeAt(IoObject *self, IoObject *locals, IoMessage *m) { /*doc SkipDB atRemove(keySymbol) Removes the specified key. Returns self */ IoSeq *key = IoMessage_locals_seqArgAt_(m, locals, 0); IOASSERT(SKIPDB(self) && SkipDB_isOpen(SKIPDB(self)), "invalid skipdb"); SkipDB_removeAt_(SKIPDB(self), IoSeq_asDatum(key)); return self; }
IO_METHOD(IoSeq, copy) { /*doc Sequence copy(aSequence) Replaces the bytes of the receiver with a copy of those in aSequence. Returns self. */ IO_ASSERT_NOT_SYMBOL(self); IoSeq_rawCopy_(self, IoMessage_locals_seqArgAt_(m, locals, 0)); return self; }