static void f_cache_status(INT32 args) { struct cache *c = LTHIS->cache; pop_n_elems(args); push_constant_text("hits"); push_int64(c->hits); push_constant_text("misses"); push_int64(c->misses); push_constant_text("stale"); push_int64(c->stale); push_constant_text("size"); push_int64(c->size); push_constant_text("entries"); push_int64(c->entries); push_constant_text("max_size"); push_int64(c->max_size); /* Relative from last call */ push_constant_text("sent_bytes"); push_int(c->sent_data); c->sent_data=0; push_constant_text("num_request"); push_int(c->num_requests); c->num_requests=0; push_constant_text("received_bytes"); push_int(c->received_data); c->received_data=0; f_aggregate_mapping( 18 ); }
/*! @decl string _sprintf() */ static void f_path_element_sprintf(INT32 args) { INT_TYPE mode; struct mapping *opts; cairo_path_data_t* data = THIS->element; get_all_args("_sprintf", args, "%i%m", &mode, &opts); pop_n_elems (args); if (mode == 'O') { switch (data->header.type) { case CAIRO_PATH_MOVE_TO: push_constant_text ("%O(CAIRO_PATH_MOVE_TO(%f,%f))"); ref_push_object(Pike_fp->current_object); f_object_program (1); push_float(data[1].point.x); push_float(data[1].point.y); f_sprintf(4); break; case CAIRO_PATH_LINE_TO: push_constant_text ("%O(CAIRO_PATH_LINE_TO(%f,%f))"); ref_push_object(Pike_fp->current_object); f_object_program (1); push_float(data[1].point.x); push_float(data[1].point.y); f_sprintf(4); break; case CAIRO_PATH_CURVE_TO: push_constant_text ("%O(CAIRO_PATH_CURVE_TO(%f,%f,%f,%f,%f))"); ref_push_object(Pike_fp->current_object); f_object_program (1); push_float(data[1].point.x); push_float(data[1].point.y); push_float(data[2].point.x); push_float(data[2].point.y); push_float(data[3].point.x); push_float(data[3].point.y); f_sprintf(8); break; case CAIRO_PATH_CLOSE_PATH: push_constant_text ("%O(CAIRO_PATH_CLOSE_PATH()"); ref_push_object(Pike_fp->current_object); f_object_program (1); f_sprintf(2); break; default: push_undefined(); return; } } else push_undefined(); }
void pgtk2_get_image_module() { push_constant_text("Image"); SAFE_APPLY_MASTER("resolv_or_error",1); }
static rgba_group decode_color( struct buffer *s ) { static struct svalue _parse_color; static struct svalue *parse_color; rgba_group res; res.alpha = 255; if(!s->len) { res.r=res.g=res.b = 0; return res; } if(s->str[0] == '#' && s->len>3) { switch(s->len) { default: res.r = hextoint(s->str[1])*0x10; res.g = hextoint(s->str[2])*0x10; res.b = hextoint(s->str[3])*0x10; break; case 7: res.r = hextoint(s->str[1])*0x10 + hextoint(s->str[2]); res.g = hextoint(s->str[3])*0x10 + hextoint(s->str[4]); res.b = hextoint(s->str[5])*0x10 + hextoint(s->str[6]); break; case 13: res.r = hextoint(s->str[1])*0x10 + hextoint(s->str[2]); res.g = hextoint(s->str[5])*0x10 + hextoint(s->str[6]); res.b = hextoint(s->str[9])*0x10 + hextoint(s->str[10]); break; } return res; } if(s->len==4&&(!strncmp(s->str,"None",4)||!strncmp(s->str,"none",4))) { #ifdef HIDE_WARNINGS res.r = res.g = res.b = 0; #endif res.alpha = 0; return res; } if(!parse_color) { push_text("Image.Color"); SAFE_APPLY_MASTER( "resolv_or_error", 1 ); _parse_color = sp[-1]; parse_color = &_parse_color; sp--; } push_svalue( parse_color ); push_string(make_shared_binary_string(s->str,s->len)); f_index( 2 ); if(sp[-1].type != T_OBJECT) { push_int(0); stack_swap(); } else { push_constant_text( "array" ); apply( sp[-2].u.object, "cast", 1 ); } if(sp[-1].type == T_ARRAY && sp[-1].u.array->size == 3) { res.r = sp[-1].u.array->item[0].u.integer; res.g = sp[-1].u.array->item[1].u.integer; res.b = sp[-1].u.array->item[2].u.integer; } else { res.r = res.g = res.b = 0; } pop_stack(); /* array */ pop_stack(); /* object */ return res; }
/*! @decl mapping _decode(string data) *! Low level decoding of the NEO file contents in @[data]. *! @returns *! @mapping *! @member Image.Image "image" *! The decoded bitmap *! @member array(Image.Image) "images" *! Coler cycled images. *! @member string "filename" *! The filename stored into the file. *! @member int(0..15) "right_limit" *! @member int(0..15) "left_limit" *! The palette color range to be color cycled. *! @member int(0..255) "speed" *! The animation speed, expressed as the number of VBLs *! per animation frame. *! @member string "direction" *! Color cycling direction. Can be either @expr{"left"@} *! or @expr{"right"@}. *! @member array(array(int(0..255))) "palette" *! The palette to be used for color cycling. *! @endmapping */ void image_neo_f__decode(INT32 args) { unsigned int i, res, size = 0; struct atari_palette *pal=0; struct object *img; struct pike_string *s, *fn; unsigned char *q; ONERROR err; get_all_args( "decode", args, "%S", &s ); if(s->len!=32128) Pike_error("This is not a NEO file (wrong file size).\n"); q = (unsigned char *)s->str; res = q[3]; if(q[2]!=0 || (res!=0 && res!=1 && res!=2)) Pike_error("This is not a NEO file (invalid resolution).\n"); /* Checks done... */ add_ref(s); pop_n_elems(args); if(res==0) pal = decode_atari_palette(q+4, 16); else if(res==1) pal = decode_atari_palette(q+4, 4); SET_ONERROR(err, free_atari_palette, pal); push_constant_text("palette"); for( i=0; i<pal->size; i++ ) { push_int(pal->colors[i].r); push_int(pal->colors[i].g); push_int(pal->colors[i].b); f_aggregate(3); } f_aggregate(pal->size); size += 2; img = decode_atari_screendump(q+128, res, pal); push_constant_text("image"); push_object(img); size += 2; if(q[48]&128) { int rl, ll, i; rl = q[49]&0xf; ll = (q[49]&0xf0)>>4; push_constant_text("right_limit"); push_int( rl ); push_constant_text("left_limit"); push_int( ll ); push_constant_text("speed"); push_int( q[51] ); push_constant_text("direction"); if( q[50]&128 ) push_constant_text("right"); else push_constant_text("left"); push_constant_text("images"); for(i=0; i<rl-ll+1; i++) { if( q[50]&128 ) rotate_atari_palette(pal, ll, rl); else rotate_atari_palette(pal, rl, ll); img = decode_atari_screendump(q+128, res, pal); push_object(img); } f_aggregate(rl-ll+1); size += 10; }
/*! @decl program load_module(string module_name) *! *! Load a binary module. *! *! This function loads a module written in C or some other language *! into Pike. The module is initialized and any programs or constants *! defined will immediately be available. *! *! When a module is loaded the C function @tt{pike_module_init()@} will *! be called to initialize it. When Pike exits @tt{pike_module_exit()@} *! will be called. These two functions @b{must@} be available in the module. *! *! @note *! The current working directory is normally not searched for *! dynamic modules. Please use @expr{"./name.so"@} instead of just *! @expr{"name.so"@} to load modules from the current directory. */ void f_load_module(INT32 args) { extern int global_callable_flags; void *module; modfun init, exit; struct module_list *new_module; struct pike_string *module_name; ONERROR err; module_name = Pike_sp[-args].u.string; if((Pike_sp[-args].type != T_STRING) || (module_name->size_shift) || string_has_null(module_name)) { Pike_error("Bad argument 1 to load_module()\n"); } { struct module_list *mp; for (mp = dynamic_module_list; mp; mp = mp->next) if (mp->name == module_name && mp->module_prog) { pop_n_elems(args); ref_push_program(mp->module_prog); return; } } /* Removing RTLD_GLOBAL breaks some PiGTK themes - Hubbe */ /* Using RTLD_LAZY is faster, but makes it impossible to * detect linking problems at runtime.. */ module=dlopen(module_name->str, RTLD_NOW /*|RTLD_GLOBAL*/ ); if(!module) { struct object *err_obj = low_clone (module_load_error_program); #define LOADERR_STRUCT(OBJ) \ ((struct module_load_error_struct *) (err_obj->storage + module_load_error_offset)) const char *err = dlerror(); if (err) { if (err[strlen (err) - 1] == '\n') push_string (make_shared_binary_string (err, strlen (err) - 1)); else push_text (err); } else push_constant_text ("Unknown reason"); add_ref (LOADERR_STRUCT (err_obj)->path = Pike_sp[-args - 1].u.string); add_ref (LOADERR_STRUCT (err_obj)->reason = Pike_sp[-1].u.string); if (Pike_sp[-args].u.string->len < 1024) { throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args, "load_module(\"%s\") failed: %s\n", module_name->str, Pike_sp[-1].u.string->str); } else { throw_error_object (err_obj, "load_module", Pike_sp - args - 1, args, "load_module() failed: %s\n", Pike_sp[-1].u.string->str); } } #ifdef PIKE_DEBUG { struct module_list *mp; for (mp = dynamic_module_list; mp; mp = mp->next) if (mp->module == module && mp->module_prog) { fprintf(stderr, "load_module(): Module loaded twice:\n" "Old name: %s\n" "New name: %s\n", mp->name->str, module_name->str); pop_n_elems(args); ref_push_program(mp->module_prog); return; } } #endif /* PIKE_DEBUG */ init = CAST_TO_FUN(dlsym(module, "pike_module_init")); if (!init) { init = CAST_TO_FUN(dlsym(module, "_pike_module_init")); if (!init) { dlclose(module); Pike_error("pike_module_init missing in dynamic module \"%S\".\n", module_name); } } exit = CAST_TO_FUN(dlsym(module, "pike_module_exit")); if (!exit) { exit = CAST_TO_FUN(dlsym(module, "_pike_module_exit")); if (!exit) { dlclose(module); Pike_error("pike_module_exit missing in dynamic module \"%S\".\n", module_name); } } #if defined(__NT__) && defined(_M_IA64) { fprintf(stderr, "pike_module_init: 0x%p\n" " func: 0x%p\n" " gp: 0x%p\n", init, ((void **)init)[0], ((void **)init)[1]); fprintf(stderr, "pike_module_exit: 0x%p\n" " func: 0x%p\n" " gp: 0x%p\n", exit, ((void **)exit)[0], ((void **)exit)[1]); } #endif /* __NT__ && _M_IA64 */ new_module=ALLOC_STRUCT(module_list); new_module->next=dynamic_module_list; dynamic_module_list=new_module; new_module->module=module; copy_shared_string(new_module->name, Pike_sp[-args].u.string); new_module->module_prog = NULL; new_module->init=init; new_module->exit=exit; enter_compiler(new_module->name, 1); start_new_program(); global_callable_flags|=CALLABLE_DYNAMIC; #ifdef PIKE_DEBUG { struct svalue *save_sp=Pike_sp; #endif SET_ONERROR(err, cleanup_compilation, NULL); #if defined(__NT__) && defined(_M_IA64) fprintf(stderr, "Calling pike_module_init()...\n"); #endif /* __NT__ && _M_IA64 */ (*(modfun)init)(); #if defined(__NT__) && defined(_M_IA64) fprintf(stderr, "pike_module_init() done.\n"); #endif /* __NT__ && _M_IA64 */ UNSET_ONERROR(err); #ifdef PIKE_DEBUG if(Pike_sp != save_sp) Pike_fatal("load_module(%s) left %ld droppings on stack!\n", module_name->str, PTRDIFF_T_TO_LONG(Pike_sp - save_sp)); } #endif pop_n_elems(args); { struct program *p = end_program(); exit_compiler(); if (p) { if ( #if 0 p->num_identifier_references #else /* !0 */ 1 #endif /* 0 */ ) { push_program(p); add_ref(new_module->module_prog = Pike_sp[-1].u.program); } else { /* No identifier references -- Disabled module. */ free_program(p); push_undefined(); } } else { /* Initialization failed. */ new_module->exit(); dlclose(module); dynamic_module_list = new_module->next; free_string(new_module->name); free(new_module); Pike_error("Failed to initialize dynamic module \"%S\".\n", module_name); } } }
static void image_xbm__decode( INT32 args ) { struct array *fg = NULL; struct array *bg = NULL; int invert=0, ele; struct pike_string *data; struct object *i=NULL, *a; get_all_args( "Image.XBM.decode", args, "%S", &data ); if (args>1) { if (Pike_sp[1-args].type!=PIKE_T_MAPPING) Pike_error("Image.XBM._decode: illegal argument 2\n"); push_svalue(Pike_sp+1-args); ref_push_string(param_fg); f_index(2); if(!UNSAFE_IS_ZERO(Pike_sp-1)) { if(Pike_sp[-1].type != PIKE_T_ARRAY || Pike_sp[-1].u.array->size != 3) Pike_error("Wrong type for foreground. Should be array(int(0..255))" " with 3 elements\n"); for(ele=0; ele<3; ele++) if(Pike_sp[-1].u.array->item[ele].type != PIKE_T_INT ||Pike_sp[-1].u.array->item[ele].u.integer < 0 ||Pike_sp[-1].u.array->item[ele].u.integer > 255) Pike_error("Wrong type for foreground. Should be array(int(0..255))" " with 3 elements\n"); fg = Pike_sp[-1].u.array; } Pike_sp--; push_svalue(Pike_sp+1-args); ref_push_string(param_bg); f_index(2); if(!UNSAFE_IS_ZERO(Pike_sp-1)) { if(Pike_sp[-1].type != PIKE_T_ARRAY || Pike_sp[-1].u.array->size != 3) Pike_error("Wrong type for background. Should be array(int(0..255))" " with 3 elements\n"); for(ele=0; ele<3; ele++) if(Pike_sp[-1].u.array->item[ele].type != PIKE_T_INT ||Pike_sp[-1].u.array->item[ele].u.integer < 0 ||Pike_sp[-1].u.array->item[ele].u.integer > 255) Pike_error("Wrong type for background. Should be array(int(0..255))" " with 3 elements\n"); bg = Pike_sp[-1].u.array; } Pike_sp--; push_svalue(Pike_sp+1-args); ref_push_string(param_invert); f_index(2); invert = !UNSAFE_IS_ZERO(Pike_sp-1); Pike_sp--; } a = load_xbm( data ); if(!fg) { if(invert) { apply(a, "invert", 0); i = (struct object *)debug_malloc_pass(Pike_sp[-1].u.object); Pike_sp--; } else { i = a; add_ref(a); } } else { if(!bg) { push_int(255); push_int(255); push_int(255); f_aggregate(3); bg = (struct array *)debug_malloc_pass(Pike_sp[-1].u.array); Pike_sp--; } if(invert) { struct array *tmp = fg; fg = bg; bg = fg; } apply(a, "xsize", 0); apply(a, "ysize", 0); push_int( bg->item[0].u.integer ); push_int( bg->item[1].u.integer ); push_int( bg->item[2].u.integer ); i = clone_object( image_program, 5 ); ref_push_object( i ); push_int( fg->item[0].u.integer ); push_int( fg->item[1].u.integer ); push_int( fg->item[2].u.integer ); apply( i, "paste_alpha_color", 4 ); } pop_n_elems(args); push_constant_text( "alpha" ); push_object( a ); push_constant_text( "image" ); if(i) push_object( i ); else push_int( 0 ); f_aggregate_mapping(4); }