Cell* keyfs_open() { return alloc_int(1); }
SEXP print_result_R(Sites *site,int nsites,int numSeq,char **seq,char **rseq,int *seqLen, double logev,double **opwm,int pwmLen,int id,char *sdyad,char *pwmConsensus,int numCycle, double pvalueCutoff,double maxpFactor,int *geneID) { register int i,j; int cn[4];//maxHeaderLen; int *seqCn; SEXP PWM; SEXP seqConsencus; SEXP motifname; SEXP motifname2; SEXP returnData; SEXP LengthSequence; SEXP SequencesIdent; SEXP StrandIdent; SEXP AccessionIdent; SEXP PositionIdent; SEXP SeqIden; SEXP PValue; SEXP GADEMList; PROTECT(returnData=NEW_LIST(5)); PROTECT(GADEMList=NEW_LIST(6)); PROTECT(PWM=allocMatrix(REALSXP,4,pwmLen)); PROTECT(seqConsencus=NEW_CHARACTER(1)); PROTECT(motifname=NEW_INTEGER(1)); PROTECT(motifname2=NEW_CHARACTER(1)); PROTECT(SequencesIdent=NEW_CHARACTER(nsites)); PROTECT(PositionIdent=NEW_INTEGER(nsites)); PROTECT(SeqIden=NEW_INTEGER(nsites)); PROTECT(StrandIdent=NEW_CHARACTER(nsites)); PROTECT(AccessionIdent=NEW_INTEGER(nsites)); PROTECT(PValue=NEW_NUMERIC(nsites)); PROTECT(LengthSequence=NEW_INTEGER(nsites)); int increment_sequence=0; int compt=0; seqCn=alloc_int(numSeq); //maxHeaderLen=min(maxHeaderLen,MAX_SEQ_HEADER); for (i=0; i<numSeq; i++) seqCn[i]=0; for (i=0; i<nsites; i++) seqCn[site[i].seq]++; for (i=0; i<4; i++) cn[i]=0; for (i=0; i<numSeq; i++) { if (seqCn[i]==0) cn[0]++; if (seqCn[i]==1) cn[1]++; if (seqCn[i]==2) cn[2]++; if (seqCn[i]>2) cn[3]++; } if (seqCn) { free(seqCn); seqCn=NULL; } for (i=0; i<nsites; i++) { //SET_STRING_ELT(AccessionIdent,increment_sequence,mkChar(geneID[site[i].seq])); INTEGER(AccessionIdent)[increment_sequence]=(geneID[site[i].seq]); if (site[i].rev=='0') { if (site[i].pos<0) { char sequence_conca[100]=""; for (j=0; j<pwmLen+site[i].pos; j++) { switch(seq[site[i].seq][j]) { case 'a': strcat(sequence_conca,"A"); break; case 'c': strcat(sequence_conca,"C"); break; case 'g': strcat(sequence_conca,"G"); break; case 't': strcat(sequence_conca,"T"); break; case 'n': strcat(sequence_conca,"N"); break; default: break; } } } else { char sequence_conca[100]=""; for (j=site[i].pos; j<min(seqLen[site[i].seq],site[i].pos+pwmLen); j++) { switch(seq[site[i].seq][j]) { case 'a': strcat(sequence_conca,"A"); break; case 'c': strcat(sequence_conca,"C"); break; case 'g': strcat(sequence_conca,"G"); break; case 't': strcat(sequence_conca,"T"); break; case 'n': strcat(sequence_conca,"N"); break; default: break; } } SET_STRING_ELT(SequencesIdent,increment_sequence,mkChar(sequence_conca)); } // print flanking region for (j=site[i].pos+pwmLen; j<min(site[i].pos+pwmLen+FLANKING_BASES,seqLen[site[i].seq]); j++) SET_STRING_ELT(StrandIdent,increment_sequence,mkChar("+")); INTEGER(SeqIden)[increment_sequence]=site[i].seq+1; INTEGER(PositionIdent)[increment_sequence]=site[i].pos+1; DOUBLE_DATA(PValue)[increment_sequence]=site[i].pvalue; increment_sequence=increment_sequence+1; } else { if (site[i].pos<0) { char sequence_conca[50]=""; //for (j=site[i].pos; j<0; j++) fprintf(fq,"X"); for (j=0; j<pwmLen+site[i].pos; j++) { switch(rseq[site[i].seq][j]) { case 'a': strcat(sequence_conca,"A"); break; case 'c': strcat(sequence_conca,"C"); break; case 'g': strcat(sequence_conca,"G"); break; case 't': strcat(sequence_conca,"T"); break; case 'n': strcat(sequence_conca,"N"); break; default: break; } } } else { char sequence_conca[50]=""; for (j=site[i].pos; j<min(seqLen[site[i].seq],site[i].pos+pwmLen); j++) { switch(rseq[site[i].seq][j]) { case 'a': strcat(sequence_conca,"A"); break; case 'c': strcat(sequence_conca,"C"); break; case 'g': strcat(sequence_conca,"G"); break; case 't': strcat(sequence_conca,"T"); break; case 'n': strcat(sequence_conca,"N"); break; default: break; } } SET_STRING_ELT(SequencesIdent,increment_sequence,mkChar(sequence_conca)); } if (site[i].pos+pwmLen-seqLen[site[i].seq]>0) { //for (j=seqLen[site[i].seq]; j<site[i].pos+pwmLen; j++) fprintf(fq,"X"); } // print flanking region for (j=site[i].pos+pwmLen; j<min(site[i].pos+pwmLen+FLANKING_BASES,seqLen[site[i].seq]); j++) SET_STRING_ELT(StrandIdent,increment_sequence,mkChar("-")); INTEGER(SeqIden)[increment_sequence]=site[i].seq+1; INTEGER(PositionIdent)[increment_sequence]=seqLen[site[i].seq]-site[i].pos; DOUBLE_DATA(PValue)[increment_sequence]=site[i].pvalue; increment_sequence=increment_sequence+1; } } for (int aa=0; aa<pwmLen; aa++) { for(int bb=0; bb<4; bb++) { NUMERIC_DATA(PWM)[compt]=opwm[aa][bb]; compt++; } } SET_STRING_ELT(seqConsencus,0,mkChar(pwmConsensus)); INTEGER(LengthSequence)[0]=125; INTEGER(motifname)[0]=id; const char base[] = "m"; char filename [ FILENAME_MAX ]; int number = id; sprintf(filename, "%s%d", base, number); SET_STRING_ELT(motifname2,0,mkChar(filename)); SET_VECTOR_ELT(returnData,0,seqConsencus); SET_VECTOR_ELT(returnData,2,LengthSequence); SET_VECTOR_ELT(returnData,4,motifname2); SET_VECTOR_ELT(returnData,1,PWM); SET_VECTOR_ELT(GADEMList,0,SequencesIdent); SET_VECTOR_ELT(GADEMList,1,StrandIdent); SET_VECTOR_ELT(GADEMList,2,PositionIdent); SET_VECTOR_ELT(GADEMList,3,PValue); SET_VECTOR_ELT(GADEMList,4,AccessionIdent); SET_VECTOR_ELT(GADEMList,5,SeqIden); SET_VECTOR_ELT(returnData,3,GADEMList); UNPROTECT(13); return (returnData); }
value nme_display_object_get_z(value inHandle) { return alloc_int(0); }
/** parse_multipart_data : onpart:function:2 -> ondata:function:3 -> void <doc> Incrementally parse the multipart data. call [onpart(name,filename)] for each part found and [ondata(buf,pos,len)] when some data is available </doc> **/ static value parse_multipart_data( value onpart, value ondata ) { value buf; int len = 0; mcontext *c = CONTEXT(); const char *ctype = ap_table_get(c->r->headers_in,"Content-Type"); value boundstr; val_check_function(onpart,2); val_check_function(ondata,3); buf = alloc_empty_string(BUFSIZE); if( !ctype || strstr(ctype,"multipart/form-data") == NULL ) return val_null; // extract boundary value { const char *boundary, *bend; if( (boundary = strstr(ctype,"boundary=")) == NULL ) neko_error(); boundary += 9; PARSE_HEADER(boundary,bend); len = (int)(bend - boundary); boundstr = alloc_empty_string(len+2); if( val_strlen(boundstr) > BUFSIZE / 2 ) neko_error(); val_string(boundstr)[0] = '-'; val_string(boundstr)[1] = '-'; memcpy(val_string(boundstr)+2,boundary,len); } len = 0; if( !ap_should_client_block(c->r) ) neko_error(); while( true ) { char *name, *end_name, *filename, *end_file_name, *data; int pos; // refill buffer // we assume here that the the whole multipart header can fit in the buffer fill_buffer(c,buf,&len); // is boundary at the beginning of buffer ? if( len < val_strlen(boundstr) || memcmp(val_string(buf),val_string(boundstr),val_strlen(boundstr)) != 0 ) return discard_body(c); name = memfind(val_string(buf),len,"Content-Disposition:"); if( name == NULL ) break; name = memfind(name,len - (int)(name - val_string(buf)),"name="); if( name == NULL ) return discard_body(c); name += 5; PARSE_HEADER(name,end_name); data = memfind(end_name,len - (int)(end_name - val_string(buf)),"\r\n\r\n"); if( data == NULL ) return discard_body(c); filename = memfind(name,(int)(data - name),"filename="); if( filename != NULL ) { filename += 9; PARSE_HEADER(filename,end_file_name); } data += 4; pos = (int)(data - val_string(buf)); // send part name val_call2(onpart,copy_string(name,(int)(end_name - name)),filename?copy_string(filename,(int)(end_file_name - filename)):val_null); // read data while( true ) { const char *boundary; // recall buffer memmove(val_string(buf),val_string(buf)+pos,len - pos); len -= pos; pos = 0; fill_buffer(c,buf,&len); // lookup bounds boundary = memfind(val_string(buf),len,val_string(boundstr)); if( boundary == NULL ) { if( len == 0 ) return discard_body(c); // send as much buffer as possible to client if( len < BUFSIZE ) pos = len; else pos = len - val_strlen(boundstr) + 1; val_call3(ondata,buf,alloc_int(0),alloc_int(pos)); } else { // send remaining data pos = (int)(boundary - val_string(buf)); val_call3(ondata,buf,alloc_int(0),alloc_int(pos-2)); // recall memmove(val_string(buf),val_string(buf)+pos,len - pos); len -= pos; break; } } } return val_null; }
value api_alloc_array(int arg1) { if (!gNekoNewArray) return alloc_array(arg1); return val_call1(*gNekoNewArray,alloc_int(arg1)); }
// FIXME: assume GLenum is always integral // DECL: const GLenum getType() const; value hx_Uniform_getType(value thisObj) { Uniform *_thisObj; ValueToObject(thisObj, _thisObj); return alloc_int(_thisObj->getType()); }
static value misc_get_key_state( value key ) { int r; val_check(key,int); r = systools_misc_get_key_state(val_int(key)); return alloc_int(r); }
// DECL: inline unsigned int getWidth() const; value hx_Image_getWidth(value thisObj) { Image *_thisObj; ValueToObject(thisObj, _thisObj); return alloc_int(_thisObj->getWidth()); }
#define ERASE 0 #define address_int(a) (((int_val)(a)) | 1) #define int_address(a) (int_val*)(a & ~1) extern field id_add, id_radd, id_sub, id_rsub, id_mult, id_rmult, id_div, id_rdiv, id_mod, id_rmod; extern field id_get, id_set; extern value neko_alloc_module_function( void *m, int_val pos, int nargs ); extern char *jit_boot_seq; extern char *jit_handle_trap; typedef void (*jit_handle)( neko_vm * ); extern int neko_can_jit(); value NEKO_TYPEOF[] = { alloc_int(0), alloc_int(2), alloc_int(3), alloc_int(4), alloc_int(5), alloc_int(6), alloc_int(7), alloc_int(8) }; static void default_printer( const char *s, int len, void *out ) { while( len > 0 ) { int p = (int)fwrite(s,1,len,(FILE*)out); if( p <= 0 ) { fputs("[ABORTED]",(FILE*)out); break;
value createProgram( ) { return alloc_int( glCreateProgram( ) ); }
value createShader( value shaderType ) { return alloc_int( glCreateShader( (GLenum)val_int( shaderType ) ) ); }
//WebGL style bind value createBuffer( ) { GLuint bID; glGenBuffers( 1, &bID ); return alloc_int (bID); }
Cell* fbfs_read() { return alloc_int(0); }
Cell* fbfs_open() { sdl_init(0); return alloc_int(1); }
// DECL: unsigned int getPassCount() const; value hx_Technique_getPassCount(value thisObj) { Technique *_thisObj; ValueToObject(thisObj, _thisObj); return alloc_int(_thisObj->getPassCount()); }
static value unserialize_rec( sbuffer *b, value loader ) { switch( read_char(b) ) { case 'N': return val_null; case 'T': return val_true; case 'F': return val_false; case 'i': return alloc_int(read_int(b)); case 'I': return alloc_int32(read_int(b)); case 'f': { tfloat d; read_str(b,sizeof(tfloat),&d); return alloc_float(d); } case 's': { int l = read_int(b); value v; if( l < 0 || l > max_string_size ) ERROR(); v = alloc_empty_string(l); add_ref(b,v); read_str(b,l,(char*)val_string(v)); return v; } case 'o': { int f; value o = alloc_object(NULL); add_ref(b,o); while( (f = read_int(b)) != 0 ) { value fval = unserialize_rec(b,loader); alloc_field(o,(field)f,fval); } switch( read_char(b) ) { case 'p': { value v = unserialize_rec(b,loader); if( !val_is_object(v) ) ERROR(); ((vobject*)o)->proto = (vobject*)v; } break; case 'z': break; default: ERROR(); } return o; } case 'r': { int n = read_int(b); if( n < 0 || n >= b->nrefs ) ERROR(); return b->trefs[b->nrefs - n - 1]; } case 'a': { int i; int n = read_int(b); value o; value *t; if( n < 0 || n > max_array_size ) ERROR(); o = alloc_array(n); t = val_array_ptr(o); add_ref(b,o); for(i=0;i<n;i++) t[i] = unserialize_rec(b,loader); return o; } case 'p': { int nargs = read_int(b); vfunction *f = (vfunction*)alloc_function((void*)1,nargs,NULL); vfunction *f2; value name; add_ref(b,(value)f); name = unserialize_rec(b,loader); f2 = (vfunction*)val_ocall2(loader,id_loadprim,name,alloc_int(nargs)); if( !val_is_function(f2) || val_fun_nargs(f2) != nargs ) failure("Loader returned not-a-function"); f->t = f2->t; f->addr = f2->addr; f->module = f2->module; return (value)f; } case 'L': { vfunction *f = (vfunction*)alloc_function((void*)1,0,NULL); value mname; int pos; int nargs; value env; add_ref(b,(value)f); mname = unserialize_rec(b,loader); pos = read_int(b); nargs = read_int(b); env = unserialize_rec(b,loader); if( !val_is_array(env) ) ERROR(); { value exp = val_ocall2(loader,id_loadmodule,mname,loader); value mval; unsigned int i; int_val *mpos; neko_module *m; if( !val_is_object(exp) ) { buffer b = alloc_buffer("module "); val_buffer(b,mname); buffer_append(b," is not an object"); bfailure(b); } mval = val_field(exp,id_module); if( !val_is_kind(mval,neko_kind_module) ) { buffer b = alloc_buffer("module "); val_buffer(b,mname); buffer_append(b," has invalid type"); bfailure(b); } m = (neko_module*)val_data(mval); mpos = m->code + pos; for(i=0;i<m->nglobals;i++) { vfunction *g = (vfunction*)m->globals[i]; if( val_is_function(g) && g->addr == mpos && g->module == m && g->nargs == nargs ) { f->t = VAL_FUNCTION; f->env = env; f->addr = mpos; f->nargs = nargs; f->module = m; return (value)f; } } { buffer b = alloc_buffer("module "); val_buffer(b,mname); buffer_append(b," has been modified"); bfailure(b); } } return val_null; } case 'x': { value mname = unserialize_rec(b,loader); value data = unserialize_rec(b,loader); value exports = val_ocall2(loader,id_loadmodule,mname,loader); value s; if( !val_is_object(exports) ) { buffer b = alloc_buffer("module "); val_buffer(b,mname); buffer_append(b," is not an object"); bfailure(b); } s = val_field(exports,id_unserialize); if( !val_is_function(s) || (val_fun_nargs(s) != 1 && val_fun_nargs(s) != VAR_ARGS) ) { buffer b = alloc_buffer("module "); val_buffer(b,mname); buffer_append(b," has invalid __unserialize function"); } s = val_call1(s,data); add_ref(b,s); return s; } case 'h': { int i; vhash *h = (vhash*)alloc(sizeof(vhash)); h->ncells = read_int(b); h->nitems = read_int(b); h->cells = (hcell**)alloc(sizeof(hcell*)*h->ncells); for(i=0;i<h->ncells;i++) h->cells[i] = NULL; for(i=0;i<h->nitems;i++) { hcell **p; hcell *c = (hcell*)alloc(sizeof(hcell)); c->hkey = read_int(b); c->key = unserialize_rec(b,loader); c->val = unserialize_rec(b,loader); c->next = NULL; p = &h->cells[c->hkey % h->ncells]; while( *p != NULL ) p = &(*p)->next; *p = c; } return alloc_abstract(k_hash,h); } default: ERROR(); return val_null; } }
value JObjectToHaxe (JNIEnv *inEnv, JNIType inType, jobject inObject) { if (inObject == 0) { return alloc_null (); } if (inType.isUnknownType ()) { jclass cls = inEnv->GetObjectClass (inObject); if (cls) { for (int i = 0; i < jniELEMENTS; i++) { if (JNIType::elementClass[i] == 0) continue; if (inEnv->IsSameObject (cls, JNIType::elementClass[i])) { inType = JNIType ((JNIElement)i, 0); break; } } if (inType.isUnknownType ()) { for (int i = 0; i < jniELEMENTS; i++) { if (JNIType::elementArrayClass[i] == 0) continue; if (inEnv->IsSameObject (cls, JNIType::elementArrayClass[i])) { inType = JNIType ((JNIElement)i, 1); break; } } } if (inType.isUnknownType ()) { if (inEnv->CallBooleanMethod (cls, isArrayClass)) { inType = JNIType (jniUnknown, 1); } } } if (inType.isUnknownType ()) { inType = JNIType (jniObject, 0); } } if (inType.arrayDepth > 1 || (inType.arrayDepth == 1 && inType.element < jniPODStart)) { int len = inEnv->GetArrayLength ((jarray)inObject); value result = alloc_array (len); JNIType child = inType.elemType (); for (int i = 0; i < len; i++) { val_array_set_i (result, i, JObjectToHaxe (inEnv, child, inEnv->GetObjectArrayElement ((jobjectArray)inObject, i))); } return result; } else if (inType.arrayDepth == 1) { int len = inEnv->GetArrayLength ((jarray)inObject); value result = alloc_array (len); switch (inType.element) { ARRAY_SET (Boolean, jboolean, alloc_bool) //ARRAY_SET (Byte, jbyte, alloc_int) ARRAY_SET (Char, jchar, alloc_int) ARRAY_SET (Short, jshort, alloc_int) ARRAY_SET (Int, jint, alloc_int) ARRAY_SET (Long, jlong, alloc_int) ARRAY_SET (Float, jfloat, alloc_float) ARRAY_SET (Double, jdouble, alloc_float) case jniByte: { if (len > 0) { jboolean copy; jbyte *data = inEnv->GetByteArrayElements ((jbyteArray)inObject, ©); for (int i = 0; i < len; i++) { val_array_set_i (result, i, alloc_int (data[i])); } inEnv->ReleaseByteArrayElements ((jbyteArray)inObject, data, JNI_ABORT); } } break; } return result; } else {
value System::GetDisplay (int id) { if (!init) { id_bounds = val_id ("bounds"); id_currentMode = val_id ("currentMode"); id_height = val_id ("height"); id_name = val_id ("name"); id_pixelFormat = val_id ("pixelFormat"); id_refreshRate = val_id ("refreshRate"); id_supportedModes = val_id ("supportedModes"); id_width = val_id ("width"); init = true; } int numDisplays = GetNumDisplays (); if (id < 0 || id >= numDisplays) { return alloc_null (); } value display = alloc_empty_object (); alloc_field (display, id_name, alloc_string (SDL_GetDisplayName (id))); SDL_Rect bounds = { 0, 0, 0, 0 }; SDL_GetDisplayBounds (id, &bounds); alloc_field (display, id_bounds, Rectangle (bounds.x, bounds.y, bounds.w, bounds.h).Value ()); SDL_DisplayMode currentDisplayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; SDL_DisplayMode displayMode = { SDL_PIXELFORMAT_UNKNOWN, 0, 0, 0, 0 }; SDL_GetCurrentDisplayMode (id, ¤tDisplayMode); int numDisplayModes = SDL_GetNumDisplayModes (id); value supportedModes = alloc_array (numDisplayModes); value mode; for (int i = 0; i < numDisplayModes; i++) { SDL_GetDisplayMode (id, i, &displayMode); if (displayMode.format == currentDisplayMode.format && displayMode.w == currentDisplayMode.w && displayMode.h == currentDisplayMode.h && displayMode.refresh_rate == currentDisplayMode.refresh_rate) { alloc_field (display, id_currentMode, alloc_int (i)); } mode = alloc_empty_object (); alloc_field (mode, id_height, alloc_int (displayMode.h)); switch (displayMode.format) { case SDL_PIXELFORMAT_ARGB8888: alloc_field (mode, id_pixelFormat, alloc_int (ARGB32)); break; case SDL_PIXELFORMAT_BGRA8888: case SDL_PIXELFORMAT_BGRX8888: alloc_field (mode, id_pixelFormat, alloc_int (BGRA32)); break; default: alloc_field (mode, id_pixelFormat, alloc_int (RGBA32)); } alloc_field (mode, id_refreshRate, alloc_int (displayMode.refresh_rate)); alloc_field (mode, id_width, alloc_int (displayMode.w)); val_array_set_i (supportedModes, i, mode); } alloc_field (display, id_supportedModes, supportedModes); return display; }
static value clipboard_set_text( value text ) { val_check(text, string); return alloc_int(systools_clipboard_set_text(val_string(text))); }
value rtmidi_out_getportcount(value obj) { RtMidiOut *midiout = (RtMidiOut *)(intptr_t)val_float(obj); return alloc_int(midiout->getPortCount()); }
static value win_show_popup_menu( value w, value m ) { val_check_kind(m,k_menu); return alloc_int(systools_popup_menu_show( val_hwnd(w), val_menu(m) )); }
value rtmidi_in_getportcount(value obj) { RtMidiIn *midiin = (RtMidiIn *)(intptr_t)val_float(obj); return alloc_int(midiin->getPortCount()); }
value api_alloc_int(int arg1) { // TODO int32 ? return alloc_int(arg1); }
/** result_get_length : 'result -> int <doc>Return the number of rows returned or affected</doc> **/ static value result_get_length( value o ) { if( val_is_int(o) ) return o; val_check_kind(o,k_result); return alloc_int( (int)mysql_num_rows(RESULT(o)->r) ); }
static value read_bytecode( value str, value pos, value len ) { size_t rlen = fread(val_string(str)+val_int(pos),1,val_int(len),self); return alloc_int(rlen); }
/** result_get_nfields : 'result -> int <doc>Return the number of fields in a result row</doc> **/ static value result_get_nfields( value o ) { val_check_kind(o,k_result); return alloc_int(RESULT(o)->nfields); }
//---------------------------------------------------- inline void ofImage::allocatePixels(ofPixels &pix, int width, int height, int bpp){ bool bNeedToAllocate = false; if (pix.bAllocated == true){ if ( (pix.width == width) && (pix.height == height) && (pix.bitsPerPixel == bpp)){ //ofLog(OF_LOG_NOTICE,"we are good, no reallocation needed"); bNeedToAllocate = false; } else { //delete[] pix.pixels; bNeedToAllocate = true; } } else { bNeedToAllocate = true; } int byteCount = bpp / 8; if (bNeedToAllocate == true){ pix.width = width; pix.height = height; pix.bitsPerPixel = bpp; pix.bytesPerPixel = bpp / 8; switch (pix.bitsPerPixel){ case 8: pix.glDataType = GL_LUMINANCE; pix.ofImageType = OF_IMAGE_GRAYSCALE; break; case 24: pix.glDataType = GL_RGB; pix.ofImageType = OF_IMAGE_COLOR; break; case 32: pix.glDataType = GL_RGBA; pix.ofImageType = OF_IMAGE_COLOR_ALPHA; break; } //pix.pixels = new unsigned char[pix.width*pix.height*byteCount]; pix.pixels = (unsigned char *) buffer_data(val_to_buffer(val_ocall1(handler, val_id("__newByteData"), alloc_int(pix.width*pix.height*byteCount)))); pix.bAllocated = true; } }
/** result_next : 'result -> object? <doc> Return the next row if available. A row is represented as an object, which fields have been converted to the corresponding Neko value (int, float or string). For Date and DateTime you can specify your own conversion function using [result_set_conv_date]. By default they're returned as plain strings. Additionally, the TINYINT(1) will be converted to either true or false if equal to 0. </doc> **/ static value result_next( value o ) { result *r; unsigned long *lengths = NULL; MYSQL_ROW row; val_check_kind(o,k_result); r = RESULT(o); row = mysql_fetch_row(r->r); if( row == NULL ) return val_null; { int i; value cur = alloc_object(NULL); r->current = row; for(i=0;i<r->nfields;i++) if( row[i] != NULL ) { value v; switch( r->fields_convs[i] ) { case CONV_INT: v = alloc_int(atoi(row[i])); break; case CONV_STRING: v = alloc_string(row[i]); if( r->conv_string != NULL ) v = val_call1(r->conv_string,v); break; case CONV_BOOL: v = alloc_bool( *row[i] != '0' ); break; case CONV_FLOAT: v = alloc_float(atof(row[i])); break; case CONV_BINARY: if( lengths == NULL ) { lengths = mysql_fetch_lengths(r->r); if( lengths == NULL ) val_throw(alloc_string("mysql_fetch_lengths")); } v = copy_string(row[i],lengths[i]); if( r->conv_bytes != NULL ) v = val_call1(r->conv_bytes,v); break; case CONV_DATE: if( r->conv_date == NULL ) v = alloc_string(row[i]); else { struct tm t; sscanf(row[i],"%4d-%2d-%2d",&t.tm_year,&t.tm_mon,&t.tm_mday); t.tm_hour = 0; t.tm_min = 0; t.tm_sec = 0; t.tm_isdst = -1; t.tm_year -= 1900; t.tm_mon--; v = val_call1(r->conv_date,alloc_int32((int)mktime(&t))); } break; case CONV_DATETIME: if( r->conv_date == NULL ) v = alloc_string(row[i]); else { struct tm t; sscanf(row[i],"%4d-%2d-%2d %2d:%2d:%2d",&t.tm_year,&t.tm_mon,&t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); t.tm_isdst = -1; t.tm_year -= 1900; t.tm_mon--; v = val_call1(r->conv_date,alloc_int32((int)mktime(&t))); } break; default: v = val_null; break; } alloc_field(cur,r->fields_ids[i],v); } return cur; } }
void importGlyphPoints( FT_Vector *points, int n, value callbacks, field lineTo, field curveTo, bool cubic ) { value arg[4]; int i; if( n==0 ) { val_ocall2( callbacks, lineTo, alloc_int( points[0].x ), alloc_int( points[0].y ) ); } else if( n==1 ) { arg[0] = alloc_int( points[0].x ); arg[1] = alloc_int( points[0].y ); arg[2] = alloc_int( points[1].x ); arg[3] = alloc_int( points[1].y ); val_ocallN( callbacks, curveTo, arg, 4 ); } else if( n>=2 ) { if( cubic ) { // printf(stderr,"ERROR: cubic beziers in fonts are not yet implemented.\n"); } else { int x1, y1, x2, y2, midx, midy; for( i=0; i<n-1; i++ ) { x1 = points[i].x; y1 = points[i].y; x2 = points[i+1].x; y2 = points[i+1].y; midx = x1 + ((x2-x1)/2); midy = y1 + ((y2-y1)/2); arg[0] = alloc_int( x1 ); arg[1] = alloc_int( y1 ); arg[2] = alloc_int( midx ); arg[3] = alloc_int( midy ); val_ocallN( callbacks, curveTo, arg, 4 ); } arg[0] = alloc_int( x2 ); arg[1] = alloc_int( y2 ); arg[2] = alloc_int( points[n].x ); arg[3] = alloc_int( points[n].y ); val_ocallN( callbacks, curveTo, arg, 4 ); } } else { } }
/** deflate_bound : 'dstream -> n:int -> int <doc>Return the maximum buffer size needed to write [n] bytes</doc> **/ static value deflate_bound( value s, value size ) { val_check_kind(s,k_stream_def); val_check(size,int); return alloc_int(deflateBound(val_stream(s),val_int(size))); }