struct xmlnode *xmlnode_create() { struct xmlnode *node; node = xmalloc(sizeof(struct xmlnode)); node->tag = NULL; node->val = NULL; node->attributes = plist_create(); plist_setnodefree(node->attributes, (plist_nodefree) keyval_free); node->childs = plist_create(); plist_setnodefree(node->childs, (plist_nodefree) xmlnode_free); return node; }
PList* plist_clone(PList* plist) { if (!plist) { return 0; } PList* p = plist_create(); int j; for (j = 0; j < plist->ulen; ++j) { plist_grow(p); p->data[j].ptr = plist->data[j].ptr; ++p->ulen; } return p; }
/* * TODO: leave this as pure lookup, move insert and delete to the caller functions? */ static HNode* hlist_lookup(HList* hlist, const char* name, int type, int add, int del) { if (!hlist) { return 0; } int j = 0; HNode* n = 0; for (j = 0; j < hlist->ulen; ++j) { n = &hlist->data[j]; if (header_matches_type_or_name(n->header, type, name)) { break; } } if (j >= hlist->ulen) { n = 0; } do { if (add) { if (n) { break; } hlist_grow(hlist); n = &hlist->data[hlist->ulen++]; Header* h = header_create(name); n->header = h; n->values = plist_create(); HLIST_FLAG_CLR(hlist, HLIST_FLAGS_SORTED); break; } if (del) { if (!n) { break; } hlist_del_pos(hlist, j, 1); n = 0; break; } } while (0); return n; }
HNode* hlist_add(HList* hlist, const char* name, const void* obj) { if (!hlist) { return 0; } HNode* n = hlist_lookup(hlist, name, HEADER_TYPE_NONE, 0, 0); if (!n) { Header* h = header_lookup_standard(HEADER_TYPE_NONE, name); if (!h) { h = header_create(name); } hlist_grow(hlist); n = &hlist->data[hlist->ulen++]; n->header = h; n->values = plist_create(); HLIST_FLAG_CLR(hlist, HLIST_FLAGS_SORTED); } plist_add(n->values, obj); GLOG(("=C= Added [%s] => %p (%d)", name, obj, n->header->order)); return n; }
static void load_plugin_conf(conf_llist *plugin) { DIR *d; /* init plugin list */ plist_create(plugin); /* read configs */ d = opendir(plugin_dir); if (d) { struct dirent *e; while ((e = readdir(d))) { plugin_conf_t config; char fname[PATH_MAX]; // Don't run backup files, hidden files, or dirs if (e->d_name[0] == '.' || count_dots(e->d_name) > 1) continue; snprintf(fname, sizeof(fname), "%s%s", plugin_dir, e->d_name); clear_pconfig(&config); if (load_pconfig(&config, fname) == 0) { /* Push onto config list only if active */ if (config.active == A_YES) plist_append(plugin, &config); else free_pconfig(&config); } else syslog(LOG_ERR, "Skipping %s plugin due to errors", e->d_name); } closedir(d); } }
static Bool init_x11( char * error_buf ) { /*XXX*/ /* Namely, support for -display host:0.0 etc. */ XrmQuark common_quarks_list[20]; /*XXX change number of elements if necessary */ XrmQuarkList ql = common_quarks_list; XGCValues gcv; char *common_quarks = "String." "Blinkinvisibletime.blinkinvisibletime." "Blinkvisibletime.blinkvisibletime." "Clicktimeframe.clicktimeframe." "Doubleclicktimeframe.doubleclicktimeframe." "Wheeldown.wheeldown." "Wheelup.wheelup." "Submenudelay.submenudelay." "Scrollfirst.scrollfirst." "Scrollnext.scrollnext"; char * atom_names[AI_count] = { "RESOLUTION_X", "RESOLUTION_Y", "PIXEL_SIZE", "SPACING", "RELATIVE_WEIGHT", "FOUNDRY", "AVERAGE_WIDTH", "CHARSET_REGISTRY", "CHARSET_ENCODING", "CREATE_EVENT", "WM_DELETE_WINDOW", "WM_PROTOCOLS", "WM_TAKE_FOCUS", "_NET_WM_STATE", "_NET_WM_STATE_SKIP_TASKBAR", "_NET_WM_STATE_MAXIMIZED_VERT", "_NET_WM_STATE_MAXIMIZED_HORZ", "_NET_WM_NAME", "_NET_WM_ICON_NAME", "UTF8_STRING", "TARGETS", "INCR", "PIXEL", "FOREGROUND", "BACKGROUND", "_MOTIF_WM_HINTS", "_NET_WM_STATE_MODAL", "_NET_SUPPORTED", "_NET_WM_STATE_MAXIMIZED_HORIZ", "text/plain;charset=UTF-8", "_NET_WM_STATE_STAYS_ON_TOP", "_NET_CURRENT_DESKTOP", "_NET_WORKAREA", "_NET_WM_STATE_ABOVE" }; char hostname_buf[256], *hostname = hostname_buf; guts. click_time_frame = 200; guts. double_click_time_frame = 200; guts. visible_timeout = 500; guts. invisible_timeout = 500; guts. insert = true; guts. last_time = CurrentTime; guts. ri_head = guts. ri_tail = 0; DISP = XOpenDisplay( do_display); if (!DISP) { char * disp = getenv("DISPLAY"); snprintf( error_buf, 256, "Error: Can't open display '%s'", do_display ? do_display : (disp ? disp : "")); free( do_display); do_display = nil; return false; } free( do_display); do_display = nil; XSetErrorHandler( x_error_handler); guts.main_error_handler = x_error_handler; (void)x_io_error_handler; XCHECKPOINT; guts.connection = ConnectionNumber( DISP); { struct sockaddr name; unsigned int l = sizeof( name); guts. local_connection = getsockname( guts.connection, &name, &l) >= 0 && l == 0; } #ifdef HAVE_X11_EXTENSIONS_SHAPE_H if ( XShapeQueryExtension( DISP, &guts.shape_event, &guts.shape_error)) { guts. shape_extension = true; } else { guts. shape_extension = false; } #else guts. shape_extension = false; #endif #ifdef USE_MITSHM if ( !do_no_shmem && XShmQueryExtension( DISP)) { guts. shared_image_extension = true; guts. shared_image_completion_event = XShmGetEventBase( DISP) + ShmCompletion; } else { guts. shared_image_extension = false; guts. shared_image_completion_event = -1; } #else guts. shared_image_extension = false; guts. shared_image_completion_event = -1; #endif guts. randr_extension = false; #ifdef HAVE_X11_EXTENSIONS_XRANDR_H { int dummy; if ( XRRQueryExtension( DISP, &dummy, &dummy)) guts. randr_extension = true; } #endif #ifdef HAVE_X11_EXTENSIONS_XRENDER_H { int dummy; if ( XRenderQueryExtension( DISP, &dummy, &dummy)) guts. render_extension = true; } #endif #ifdef HAVE_X11_EXTENSIONS_XCOMPOSITE_H { int dummy; if (XQueryExtension(DISP, COMPOSITE_NAME, &guts.composite_opcode, &dummy, &dummy)) guts. composite_extension = true; } #endif XrmInitialize(); guts.db = get_database(); XrmStringToQuarkList( common_quarks, common_quarks_list); guts.qString = *ql++; guts.qBlinkinvisibletime = *ql++; guts.qblinkinvisibletime = *ql++; guts.qBlinkvisibletime = *ql++; guts.qblinkvisibletime = *ql++; guts.qClicktimeframe = *ql++; guts.qclicktimeframe = *ql++; guts.qDoubleclicktimeframe = *ql++; guts.qdoubleclicktimeframe = *ql++; guts.qWheeldown = *ql++; guts.qwheeldown = *ql++; guts.qWheelup = *ql++; guts.qwheelup = *ql++; guts.qSubmenudelay = *ql++; guts.qsubmenudelay = *ql++; guts.qScrollfirst = *ql++; guts.qscrollfirst = *ql++; guts.qScrollnext = *ql++; guts.qscrollnext = *ql++; guts. mouse_buttons = XGetPointerMapping( DISP, guts. buttons_map, 256); XCHECKPOINT; guts. limits. request_length = XMaxRequestSize( DISP); guts. limits. XDrawLines = guts. limits. request_length - 3; guts. limits. XFillPolygon = guts. limits. request_length - 4; guts. limits. XDrawSegments = (guts. limits. request_length - 3) / 2; guts. limits. XDrawRectangles = (guts. limits. request_length - 3) / 2; guts. limits. XFillRectangles = (guts. limits. request_length - 3) / 2; guts. limits. XFillArcs = guts. limits. XDrawArcs = (guts. limits. request_length - 3) / 3; XCHECKPOINT; SCREEN = DefaultScreen( DISP); /* XXX - return code? */ guts. root = RootWindow( DISP, SCREEN); guts. displaySize. x = DisplayWidth( DISP, SCREEN); guts. displaySize. y = DisplayHeight( DISP, SCREEN); XQueryBestCursor( DISP, guts. root, guts. displaySize. x, /* :-) */ guts. displaySize. y, &guts. cursor_width, &guts. cursor_height); XCHECKPOINT; TAILQ_INIT( &guts.paintq); TAILQ_INIT( &guts.peventq); TAILQ_INIT( &guts.bitmap_gc_pool); TAILQ_INIT( &guts.screen_gc_pool); TAILQ_INIT( &guts.argb_gc_pool); guts. currentFocusTime = CurrentTime; guts. windows = hash_create(); guts. menu_windows = hash_create(); guts. ximages = hash_create(); gcv. graphics_exposures = false; guts. menugc = XCreateGC( DISP, guts. root, GCGraphicsExposures, &gcv); guts. resolution. x = 25.4 * guts. displaySize. x / DisplayWidthMM( DISP, SCREEN) + .5; guts. resolution. y = 25.4 * DisplayHeight( DISP, SCREEN) / DisplayHeightMM( DISP, SCREEN) + .5; guts. depth = DefaultDepth( DISP, SCREEN); guts. idepth = get_idepth(); if ( guts.depth == 1) guts. qdepth = 1; else if ( guts.depth <= 4) guts. qdepth = 4; else if ( guts.depth <= 8) guts. qdepth = 8; else guts. qdepth = 24; guts. byte_order = ImageByteOrder( DISP); guts. bit_order = BitmapBitOrder( DISP); if ( BYTEORDER == LSB32 || BYTEORDER == LSB64) guts. machine_byte_order = LSBFirst; else if ( BYTEORDER == MSB32 || BYTEORDER == MSB64) guts. machine_byte_order = MSBFirst; else { sprintf( error_buf, "UAA_001: weird machine byte order: %08x", BYTEORDER); return false; } XInternAtoms( DISP, atom_names, AI_count, 0, guts. atoms); guts. null_pointer = nilHandle; guts. pointer_invisible_count = 0; guts. files = plist_create( 16, 16); prima_rebuild_watchers(); guts. wm_event_timeout = 100; guts. menu_timeout = 200; guts. scroll_first = 200; guts. scroll_next = 50; apc_timer_create( CURSOR_TIMER); apc_timer_set_timeout(CURSOR_TIMER, 2); apc_timer_create( MENU_TIMER); apc_timer_set_timeout( MENU_TIMER, guts. menu_timeout); apc_timer_create( MENU_UNFOCUS_TIMER); apc_timer_set_timeout( MENU_UNFOCUS_TIMER, 50); if ( !prima_init_clipboard_subsystem( error_buf)) return false; if ( !prima_init_color_subsystem( error_buf)) return false; if ( !prima_init_font_subsystem( error_buf)) return false; #ifdef WITH_GTK2 if (!prima_gtk_init()) return false; #endif bzero( &guts. cursor_gcv, sizeof( guts. cursor_gcv)); guts. cursor_gcv. cap_style = CapButt; guts. cursor_gcv. function = GXcopy; gethostname( hostname, 256); hostname[255] = '\0'; XStringListToTextProperty((char **)&hostname, 1, &guts. hostname); guts. net_wm_maximization = prima_wm_net_state_read_maximization( guts. root, NET_SUPPORTED); if ( do_sync) XSynchronize( DISP, true); return true; }
char * prima_gtk_openfile( char * params) { if ( strncmp( params, "version", 7) == 0) return duplicate_string( GTK_VERSION); if ( !DISP) return NULL; if( !prima_gtk_init()) return NULL; if ( strncmp( params, "directory", 9) == 0) { params += 9; if ( *params == '=') { params++; if ( *params == 0) { gtk_current_folder_ptr = NULL; } else { gtk_current_folder_ptr = gtk_current_folder; strncpy( gtk_current_folder, params, MAXPATHLEN); gtk_current_folder[MAXPATHLEN] = 0; } } else return duplicate_string( gtk_current_folder_ptr); } else if ( strncmp( params, "filters=", 8) == 0) { params += 8; if ( gtk_filters) { int i; for ( i = 0; i < gtk_filters-> count; i++) g_object_unref(( GObject*) gtk_filters-> items[i]); plist_destroy( gtk_filters); gtk_filters = NULL; } if ( *params != 0) { gtk_filters = plist_create(8, 8); /* copy \0\0-terminated string */ while ( *params) { char * pattern; GtkFileFilter * f = gtk_file_filter_new(); /* name */ gtk_file_filter_set_name( f, params); while ( *params) params++; params++; /* semicolon-separated shell globs */ pattern = ( char *) params; while ( *params) { if ( *params == ';') { *params = 0; gtk_file_filter_add_pattern( f, pattern); pattern = params + 1; } params++; } gtk_file_filter_add_pattern( f, pattern); list_add( gtk_filters, (Handle) f); params++; } } } else if ( strncmp( params, "filterindex", 11) == 0) { params += 11; if ( *params == '=') { int fi = 0; sscanf( params + 1, "%d", &fi); gtk_filter_index = fi; } else { char buf[25]; sprintf( buf, "%d", gtk_filter_index); return duplicate_string( buf); } } else if ( strncmp( params, "multi_select=", 13) == 0) { params += 13; gtk_select_multiple = (*params != '0'); } else if ( strncmp( params, "overwrite_prompt=", 17) == 0) { params += 17; gtk_overwrite_prompt = (*params != '0'); } else if ( ( strncmp( params, "open", 4) == 0) || ( strncmp( params, "save", 4) == 0) ) { return gtk_openfile( strncmp( params, "open", 4) == 0); } else if ( strncmp( params, "show_hidden=", 12) == 0) { params += 12; gtk_show_hidden_files = (*params != '0'); } else if ( strncmp( params, "title=", 6) == 0) { params += 6; if ( *params == 0) { gtk_dialog_title_ptr = NULL; } else { gtk_dialog_title_ptr = gtk_dialog_title; strncpy( gtk_dialog_title, params, 255); gtk_dialog_title[255] = 0; } } else { warn("gtk2.OpenFile: Unknown function %s", params); } return NULL; }
static PFontABC query_abc_range( Handle self, TextWrapRec * t, unsigned int base) { PFontABC abc; /* find if present in cache */ if ( t-> utf8_text) { if ( *(t-> unicode)) { int i; PList p; if (( p = *(t-> unicode))) for ( i = 0; i < p-> count; i += 2) if (( unsigned int) p-> items[ i] == base) return ( PFontABC) p-> items[i + 1]; } } else if ( *( t-> ascii)) return *(t-> ascii); /* query ABC information */ if ( !self) { abc = apc_gp_get_font_abc( self, base * 256, base * 256 + 255, t-> utf8_text); if ( !abc) return nil; } else if ( my-> get_font_abc == Drawable_get_font_abc) { gpARGS; gpENTER(nil); abc = apc_gp_get_font_abc( self, base * 256, base * 256 + 255, t-> utf8_text); gpLEAVE; if ( !abc) return nil; } else { SV * sv; if ( !( abc = malloc( 256 * sizeof( FontABC)))) return nil; sv = my-> get_font_abc( self, base * 256, base * 256 + 255, t-> utf8_text); if ( SvOK( sv) && SvROK( sv) && SvTYPE( SvRV( sv)) == SVt_PVAV) { AV * av = ( AV*) SvRV( sv); int i, j = 0, n = av_len( av) + 1; if ( n > 256 * 3) n = 256 * 3; n = ( n / 3) * 3; if ( n < 256) memset( abc, 0, 256 * sizeof( FontABC)); for ( i = 0; i < n; i += 3) { SV ** holder = av_fetch( av, i, 0); if ( holder) abc[j]. a = ( float) SvNV( *holder); holder = av_fetch( av, i + 1, 0); if ( holder) abc[j]. b = ( float) SvNV( *holder); holder = av_fetch( av, i + 2, 0); if ( holder) abc[j]. c = ( float) SvNV( *holder); j++; } } else memset( abc, 0, 256 * sizeof( FontABC)); sv_free( sv); } /* store in cache */ if ( t-> utf8_text) { PList p; if ( !*(t-> unicode)) *(t-> unicode) = plist_create( 8, 8); if (( p = *(t-> unicode))) { list_add( p, ( Handle) base); list_add( p, ( Handle) abc); } else { free( abc); return nil; } } else *(t-> ascii) = abc; return abc; }