int fifo_test(void) { int size= 10; u8 buf; qb_t *p = malloc(sizeof(qb_t)); p->buffer = (u8 *)malloc(size); p->wptr=p->rptr=p->buffer; p->end = (msg_t *)p->buffer + size; print("fifo test"); buf=1; q_write(p,&buf,1); buf=2; q_write(p,&buf,1); if(!q_read(p,&buf,1)) print("read[%d] qsize[%d]",buf,q_size(p)); if(!q_read(p,&buf,1)) print("read[%d] qsize[%d]",buf,q_size(p)); if(!q_read(p,&buf,1)) print("read[%d] qsize[%d]",buf,q_size(p)); //q_free(p->buffer); q_free(p); return 0; }
/*=========================================================================== FUNCTION Q_PUT DESCRIPTION This function enqueues an item onto a specified queue using a specified link. DEPENDENCIES The specified queue should have been previously initialized via a call to q_init. The specified link field of the item should have been prev- iously initialized via a call to q_init_link. RETURN VALUE None. SIDE EFFECTS The specified item is placed at the tail of the specified queue. ===========================================================================*/ void q_put( q_type *q_ptr, /* Ptr to queue. */ q_link_type *link_ptr /* Ptr to item link to use for queueing. */ ) { q_lock( q_ptr ); link_ptr->next_ptr = (q_link_type *)&q_ptr->link; #ifndef FEATURE_Q_NO_SELF_QPTR link_ptr->q_ptr = q_ptr; #endif #ifndef FEATURE_Q_SINGLE_LINK link_ptr->prev_ptr = q_ptr->link.prev_ptr; #endif q_ptr->link.prev_ptr->next_ptr = link_ptr; q_ptr->link.prev_ptr = link_ptr; q_ptr->cnt++; Q_XCEPT_Q_PUT( q_ptr, link_ptr ); q_free( q_ptr ); return; } /* END q_put */
/*=========================================================================== FUNCTION Q_CHECK DESCRIPTION This function returns a pointer to the data block at the head of the queue. The data block is not removed from the queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE A pointer to the queue item. If the specified queue is empty, then NULL is returned. SIDE EFFECTS None ===========================================================================*/ void* q_check( q_type *q_ptr ) { q_link_type *link_ptr; #ifdef FEATURE_Q_NO_SELF_QPTR q_link_type *ret_ptr = NULL; #endif q_lock( q_ptr ); link_ptr = q_ptr->link.next_ptr; #ifdef FEATURE_Q_NO_SELF_QPTR if( q_ptr->cnt > 0 ) { ret_ptr = link_ptr; } #endif Q_XCEPT_Q_CHECK( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return link_ptr->self_ptr; #endif } /* END q_check */
int q_test(void) { msg_t my_msg; int i=0; int size = 5; print("size of msg_t [%d] sizeof qb_t[%d]",sizeof(msg_t),sizeof(qb_t)); qb_t *p = malloc(sizeof(qb_t)); p->buffer = (msg_t *)malloc(sizeof(msg_t)*size); p->wptr=p->rptr=p->buffer; p->end = (msg_t *)p->buffer + size; my_msg.key=31; my_msg.type=1; q_write(p,&my_msg,sizeof(msg_t)); my_msg.key=32; my_msg.type=2; q_write(p,&my_msg,sizeof(msg_t)); my_msg.key=33; my_msg.type=3; q_write(p,&my_msg,sizeof(msg_t)); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); if(!q_read(p,&my_msg,sizeof(msg_t))) print("q_read %d %d",my_msg.key,my_msg.type); i++; q_free(p); return 0; }
static void test_q_new(void) { Queue* q = q_new(); CU_ASSERT_PTR_NOT_NULL_FATAL(q); CU_ASSERT_PTR_NULL(q_dequeue(q)); CU_ASSERT_EQUAL(q_size(q), 0); q_free(q); }
/*=========================================================================== FUNCTION Q_LAST_GET DESCRIPTION This function returns the item which was most recently enqueued in a queue. Note, this is different from q_get() which returns the oldest item in a queue. DEPENDENCIES None RETURN VALUE None SIDE EFFECTS None ===========================================================================*/ void * q_last_get( q_type* q_ptr ) { q_link_type *link_ptr; #if defined(FEATURE_Q_SINGLE_LINK) || defined(FEATURE_Q_NO_SELF_QPTR) q_link_type *ret_ptr=NULL; #endif /* FEATURE_Q_SINGLE_LINK || FEATURE_Q_NO_SELF_QPTR */ q_lock( q_ptr ); #ifdef FEATURE_Q_SINGLE_LINK for( link_ptr = (q_link_type *)q_ptr; link_ptr->next_ptr != q_ptr->link.prev_ptr; link_ptr = link_ptr->next_ptr ); if( q_ptr->cnt > 0 ) { ret_ptr = link_ptr->next_ptr; q_ptr->link.prev_ptr = link_ptr; link_ptr->next_ptr = (q_link_type *)(&q_ptr->link); q_ptr->cnt--; #ifdef FEATURE_Q_NO_SELF_QPTR ret_ptr->next_ptr = NULL; #else link_ptr = ret_ptr; link_ptr->q_ptr = NULL; #endif } #else link_ptr = q_ptr->link.prev_ptr; if ( q_ptr->cnt > 0 ) { q_ptr->link.prev_ptr = link_ptr->prev_ptr; link_ptr->prev_ptr->next_ptr = &q_ptr->link; q_ptr->cnt--; #ifdef FEATURE_Q_NO_SELF_QPTR link_ptr->next_ptr = NULL; ret_ptr = link_ptr; #else link_ptr->q_ptr = NULL; #endif } #endif Q_XCEPT_Q_LAST_GET( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return link_ptr->self_ptr; #endif } /* q_last_get */
void q_free(Tree *query) { if(query == NULL) return; if(strcmp((char*)query->data,"AND") == 0 || strcmp((char*)query->data,"OR") == 0) { free(query->data); q_free(query->left); q_free(query->right); free(query); } else { info *temp = (info*)(query->data); free(temp->colName); free(temp->conditional); if(temp->valueType == 'S') free(temp->value->str); free(temp->value); free(query->data); free(query); } }
/*=========================================================================== FUNCTION Q_GET DESCRIPTION This function removes an item from the head of a specified queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE A pointer to the dequeued item. If the specified queue is empty, then NULL is returned. SIDE EFFECTS The head item, if any, is removed from the specified queue. ===========================================================================*/ void* q_get( q_type *q_ptr /* Ptr to queue. */ ) { q_link_type *link_ptr; #ifdef FEATURE_Q_NO_SELF_QPTR q_link_type *ret_ptr = NULL; #endif q_lock( q_ptr ); /* Get ptr to 1st queue item. */ link_ptr = q_ptr->link.next_ptr; /* Can only get an item if the queue is non empty */ if( q_ptr->cnt > 0 ) { q_ptr->link.next_ptr = link_ptr->next_ptr; #ifdef FEATURE_Q_SINGLE_LINK if (link_ptr->next_ptr == (q_link_type *)q_ptr) { q_ptr->link.prev_ptr = (q_link_type *)(&q_ptr->link); } #else link_ptr->next_ptr->prev_ptr = &q_ptr->link; #endif q_ptr->cnt--; /* Mark item as no longer in a queue. */ #ifdef FEATURE_Q_NO_SELF_QPTR link_ptr->next_ptr = NULL; ret_ptr = link_ptr; #else link_ptr->q_ptr = NULL; #endif } Q_XCEPT_Q_GET( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return link_ptr->self_ptr; #endif } /* END q_get */
static void test_q_dequeue(void) { Queue* q = q_new(); int first; int status = q_enqueue(q, &first); int second; status = q_enqueue(q, &second); CU_ASSERT_PTR_EQUAL(q_dequeue(q), &first); CU_ASSERT_EQUAL(q_size(q), 1); CU_ASSERT_PTR_EQUAL(q_dequeue(q), &second); CU_ASSERT_EQUAL(q_size(q), 0); q_free(q); }
int check_queue() { QUEUE *queue; char *item; size_t counter; queue = q_init(); if(!queue) { fprintf(stderr, "unable to initialize queue\n"); return 0; } for(counter = 0; datas[counter]; counter ++) q_enqueue(queue, datas[counter], strlen(datas[counter]) + 1); item = (char *)q_front(queue); if(!item) { fprintf(stderr, "got NULL when expecting %s\n", datas[counter]); return 1; } if(strcmp(item, datas[0])) { fprintf(stderr, "q_front() returned %s, expecting %s\n", item, datas[0]); return 2; } for(counter = 0; datas[counter]; counter ++) { item = (char *)q_dequeue(queue); if(!item || strcmp(item, datas[counter])) { fprintf(stderr, "got %s, expecting %s\n", item, datas[counter]); return 3; } free(item); } item = (char *)q_dequeue(queue); if(item) { fprintf(stderr, "got %s when expecting NULL\n", item); return 4; } q_free(queue, QUEUE_NODEALLOC); return 0; }
/** * This will push objects off a square. * * The methodology is to load all objects on the square into a queue. Replace * the previous square with a type that does not allow for objects. Drop the * objects. Last, put the square back to its original type. */ void push_object(int y, int x) { /* Save the original terrain feature */ struct feature *feat_old = square_feat(cave, y, x); struct object *obj = square_object(cave, y, x); struct queue *queue = q_new(z_info->floor_size); bool glyph = square_iswarded(cave, y, x); /* Push all objects on the square, stripped of pile info, into the queue */ while (obj) { struct object *next = obj->next; q_push_ptr(queue, obj); /* Orphan the object */ obj->next = NULL; obj->prev = NULL; obj->iy = 0; obj->ix = 0; /* Next object */ obj = next; } /* Disassociate the objects from the square */ cave->squares[y][x].obj = NULL; /* Set feature to an open door */ square_force_floor(cave, y, x); square_add_door(cave, y, x, false); /* Drop objects back onto the floor */ while (q_len(queue) > 0) { /* Take object from the queue */ obj = q_pop_ptr(queue); /* Drop the object */ drop_near(cave, &obj, 0, y, x, false); } /* Reset cave feature and rune if needed */ square_set_feat(cave, y, x, feat_old->fidx); if (glyph) square_add_ward(cave, y, x); q_free(queue); }
/*=========================================================================== FUNCTION Q_LAST_CHECK DESCRIPTION This function returns the item which was most recently enqueued in a queue. Note, this is different from q_check() which returns the oldest item in a queue. DEPENDENCIES None RETURN VALUE None SIDE EFFECTS None ===========================================================================*/ void * q_last_check ( q_type* q_ptr /* The queue from which the item will be removed */ ) { q_link_type *link_ptr; /* For returning value. */ #if defined(FEATURE_Q_SINGLE_LINK) || defined(FEATURE_Q_NO_SELF_QPTR) q_link_type *ret_ptr=NULL; /* For returning value. */ #endif /* FEATURE_Q_SINGLE_LINK || FEATURE_Q_NO_SELF_QPTR */ /*- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -*/ q_lock( q_ptr ); #ifdef FEATURE_Q_SINGLE_LINK for( link_ptr = (q_link_type *)q_ptr;link_ptr->next_ptr != q_ptr->link.prev_ptr;link_ptr=link_ptr->next_ptr); if (q_ptr->cnt > 0) { ret_ptr = link_ptr->next_ptr; #ifndef FEATURE_Q_NO_SELF_QPTR link_ptr = ret_ptr; #endif } #else link_ptr = q_ptr->link.prev_ptr; if ( q_ptr->cnt > 0 ) { #ifdef FEATURE_Q_NO_SELF_QPTR ret_ptr = link_ptr; #endif } #endif Q_XCEPT_Q_LAST_CHECK( q_ptr ); q_free( q_ptr ); #ifdef FEATURE_Q_NO_SELF_QPTR return (void *)ret_ptr; #else return ( link_ptr->self_ptr ); #endif } /* q_last_check */
queue q_alloc(int n,enum Q_types type,int (*keycmp)(void *,void *)) { queue q; int i; if(n<0) return NULL; q=(queue) malloc(sizeof(struct qstruct)); if(!q) return NULL; q->type=type; q->kv=NULL; q->ki=NULL; q->kd=NULL; q->kl=NULL; q->keycmp=keycmp; q->x=NULL; q->n=++n; q->f=0; q->b=0; CHECK(type==Qusort || type==Qvoid || type==Qint || type==Qdouble || type==Qlong); if(type==Qvoid) { CHECK(q->kv=(void**) calloc(n,sizeof(void*))); for(i=0;i<n;i++) q->kv[i]=NULL; } else if(type==Qint) { CHECK(q->ki=(int*) calloc(n,sizeof(int))); for(i=0;i<n;i++) q->ki[i]=0; } else if(type==Qdouble) { CHECK(q->kd=(double*) calloc(n,sizeof(double))); for(i=0;i<n;i++) q->kd[i]=0; } else if(type==Qlong) { CHECK(q->kl=(Q_LONGLONG*) calloc(n,sizeof(Q_LONGLONG))); for(i=0;i<n;i++) q->kl[i]=0; } CHECK(q->x=(void**) calloc(n,sizeof(void*))); for(i=0;i<n;i++) q->x[i]=NULL; return q; failure: q_free(q,0,0); return NULL; }
static void pref_plugin_changed(void) { GtkTreeSelection *sel = gtk_tree_view_get_selection(GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window, "plugin_tree"))); GtkTreeModel *model = GTK_TREE_MODEL(plugin_store); GtkTreeIter iter; int id = 0; if (plugin_last >= 0) { gmpc_plugin_preferences_destroy(plugins[plugin_last], (GtkWidget *) gtk_builder_get_object(xml_preferences_window, "plugin_container")); plugin_last = -1; } else if (plugin_last == PLUGIN_STATS) { plugin_stats_destroy((GtkWidget *) gtk_builder_get_object(xml_preferences_window, "plugin_container")); } if (gtk_tree_selection_get_selected(sel, &model, &iter)) { gtk_tree_model_get(GTK_TREE_MODEL(plugin_store), &iter, 0, &id, -1); if (id >= 0 && gmpc_plugin_has_preferences(plugins[id])) { char *buf = NULL; const gchar *translation_domain = gmpc_plugin_get_translation_domain(plugins[id]); if (!gmpc_plugin_is_internal(plugins[id])) { const int *version = gmpc_plugin_get_version(plugins[id]); if (version != NULL) { buf = g_strdup_printf("<span size=\"xx-large\"><b>%s</b></span>\n<i>%s: %i.%i.%i</i>", #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0) g_dgettext(translation_domain, gmpc_plugin_get_name(plugins[id])), #else gmpc_plugin_get_name(plugins[id]), #endif _("Plugin version"), version[0], version[1], version[2]); } else buf = g_strdup_printf("<span size=\"xx-large\"><b>%s</b></span>", gmpc_plugin_get_name(plugins[id])); } else { buf = g_strdup_printf("<span size=\"xx-large\"><b>%s</b></span>", N_(gmpc_plugin_get_name(plugins[id]))); } gmpc_plugin_preferences_construct(plugins[id], (GtkWidget *) gtk_builder_get_object(xml_preferences_window, "plugin_container")); plugin_last = id; gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(xml_preferences_window, "plugin_label")), buf); q_free(buf); return; } else if (id == PLUGIN_STATS) { gchar *value = g_markup_printf_escaped("<span size=\"xx-large\" weight=\"bold\">%s</span>", _("Plugins")); gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(xml_preferences_window, "plugin_label")), value); g_free(value); plugin_stats_construct((GtkWidget *) gtk_builder_get_object(xml_preferences_window, "plugin_container")); plugin_last = id; return; } } gtk_label_set_markup(GTK_LABEL(gtk_builder_get_object(xml_preferences_window, "plugin_label")), "<span size=\"xx-large\"><b>Nothing Selected</b></span>"); }
static void plugin_stats_construct(GtkWidget * container) { gchar *path = gmpc_get_full_glade_path("preferences-plugins.ui"); plugin_stat_xml = gtk_builder_new(); gtk_builder_add_from_file(plugin_stat_xml, path, NULL); q_free(path); if (plugin_stat_xml) { GtkWidget *tree = (GtkWidget *) gtk_builder_get_object(plugin_stat_xml, "plugin_stats_tree"); GtkListStore *store = NULL; GtkTreeIter iter; GtkCellRenderer *renderer = NULL; int i = 0; GtkWidget *vbox = (GtkWidget *) gtk_builder_get_object(plugin_stat_xml, "plugin_stats_vbox"); /** * new */ store = gtk_list_store_new(5, G_TYPE_BOOLEAN, G_TYPE_STRING, G_TYPE_STRING, G_TYPE_POINTER, G_TYPE_STRING); gtk_tree_view_set_model(GTK_TREE_VIEW(tree), GTK_TREE_MODEL(store)); renderer = gtk_cell_renderer_toggle_new(); g_object_set_data(G_OBJECT(renderer), "editable", GINT_TO_POINTER(1)); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree), -1, _("Enabled"), renderer, "active", 0, NULL); g_signal_connect(G_OBJECT(renderer), "toggled", G_CALLBACK(pref_plugin_enabled), store); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree), -1, _("Name"), renderer, "text", 1, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree), -1, _("Function"), renderer, "text", 2, NULL); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_insert_column_with_attributes(GTK_TREE_VIEW(tree), -1, _("Version"), renderer, "text", 4, NULL); for (i = 0; i < num_plugins; i++) { if (!gmpc_plugin_is_internal(plugins[i])) { const gchar *translation_domain = gmpc_plugin_get_translation_domain(plugins[i]); const int *ver = gmpc_plugin_get_version(plugins[i]); gchar *version = (ver) ? g_strdup_printf("%i.%i.%i", ver[0], ver[1], ver[2]) : g_strdup("n/a"); gtk_list_store_append(store, &iter); gtk_list_store_set(store, &iter, 0, TRUE, #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0) 1, g_dgettext(translation_domain, gmpc_plugin_get_name(plugins[i])), #else 1, gmpc_plugin_get_name(plugins[i]), #endif 3, (plugins[i]), 4, version, -1); g_free(version); if (gmpc_plugin_get_enabled(plugins[i])) { gtk_list_store_set(store, &iter, 0, TRUE, -1); } else gtk_list_store_set(store, &iter, 0, FALSE, -1); switch (gmpc_plugin_get_type(plugins[i])) { case GMPC_PLUGIN_DUMMY: gtk_list_store_set(store, &iter, 2, _("Dummy"), -1); break; case GMPC_PLUGIN_PL_BROWSER: gtk_list_store_set(store, &iter, 2, _("Browser Extension"), -1); break; case GMPC_PLUGIN_META_DATA: gtk_list_store_set(store, &iter, 2, _("Metadata Provider"), -1); break; case GMPC_PLUGIN_PL_BROWSER | GMPC_PLUGIN_META_DATA: gtk_list_store_set(store, &iter, 2, _("Metadata Provider and Browser Extension"), -1); break; case GMPC_PLUGIN_NO_GUI: gtk_list_store_set(store, &iter, 2, _("Misc."), -1); break; case GMPC_INTERNALL: case GMPC_DEPRECATED: default: gtk_list_store_set(store, &iter, 2, _("Unknown"), -1); break; } } } gtk_container_add(GTK_CONTAINER(container), vbox); } }
void create_preferences_window(void) { GError *error = NULL; GtkWidget *pl3_win = playlist3_get_window(); GtkWidget *dialog; GtkCellRenderer *renderer; GtkTreeViewColumn *column; GtkWidget *label; int i = 0; char *string = NULL; if (running) { if (xml_preferences_window == NULL) { running = 0; } else { dialog = (GtkWidget *) gtk_builder_get_object(xml_preferences_window, "preferences_window"); gtk_window_present(GTK_WINDOW(dialog)); return; } } plugin_last = -1; string = gmpc_get_full_glade_path("preferences.ui"); xml_preferences_window = gtk_builder_new(); gtk_builder_add_from_file(xml_preferences_window, string, &error); q_free(string); if (error) { g_log(LOG_DOMAIN, G_LOG_LEVEL_ERROR, "Failed to load preferences.ui: %s", error->message); g_error_free(error); } /* set info from struct */ /* hostname */ dialog = (GtkWidget *) gtk_builder_get_object(xml_preferences_window, "preferences_window"); gtk_window_set_transient_for(GTK_WINDOW(dialog), GTK_WINDOW(pl3_win)); gtk_widget_show_all(GTK_WIDGET(dialog)); running = 1; plugin_store_unfiltered = gtk_list_store_new(2, G_TYPE_INT, G_TYPE_STRING); /* Create a filtered list that hides the disabled plugins */ plugin_store = gtk_tree_model_filter_new(GTK_TREE_MODEL(plugin_store_unfiltered), NULL); gtk_tree_model_filter_set_visible_func(GTK_TREE_MODEL_FILTER(plugin_store), pref_model_filter_func, NULL, NULL); column = gtk_tree_view_column_new(); gtk_tree_view_column_set_title(column, _("Plugins")); renderer = gtk_cell_renderer_text_new(); gtk_tree_view_column_pack_start(column, renderer, TRUE); gtk_tree_view_column_set_attributes(column, renderer, "markup", 1, NULL); gtk_tree_view_append_column(GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window, "plugin_tree")), column); g_signal_connect(G_OBJECT (gtk_tree_view_get_selection (GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window, "plugin_tree")))), "changed", G_CALLBACK(pref_plugin_changed), NULL); gtk_tree_view_set_model(GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window, "plugin_tree")), GTK_TREE_MODEL(plugin_store)); /* internals */ for (i = 0; i < num_plugins; i++) { if (gmpc_plugin_has_preferences(plugins[i])) { if (gmpc_plugin_is_internal(plugins[i])) { GtkTreeIter iter; gtk_list_store_append(GTK_LIST_STORE(plugin_store_unfiltered), &iter); gtk_list_store_set(GTK_LIST_STORE(plugin_store_unfiltered), &iter, 0, i, #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0) 1, _(gmpc_plugin_get_name(plugins[i])), #else 1, gmpc_plugin_get_name(plugins[i]), #endif -1); } } } // Select the first row // TODO: Move this outside the loop. if (gtk_tree_selection_count_selected_rows (gtk_tree_view_get_selection (GTK_TREE_VIEW(gtk_builder_get_object(xml_preferences_window, "plugin_tree")))) == 0) { GtkTreeIter iter; if(gtk_tree_model_get_iter_first(GTK_TREE_MODEL(plugin_store), &iter)) { gtk_tree_selection_select_iter(gtk_tree_view_get_selection (GTK_TREE_VIEW (gtk_builder_get_object(xml_preferences_window, "plugin_tree"))), &iter); } } /* plugins */ { GtkTreeIter iter; gchar *value = g_markup_printf_escaped("<b>%s:</b>", _("Plugins")); gtk_list_store_append(GTK_LIST_STORE(plugin_store_unfiltered), &iter); gtk_list_store_set(GTK_LIST_STORE(plugin_store_unfiltered), &iter, 0, PLUGIN_STATS, 1, value, -1); g_free(value); for (i = 0; i < num_plugins; i++) { if (gmpc_plugin_has_preferences(plugins[i]) && !gmpc_plugin_is_internal(plugins[i])) { const gchar *translation_domain = gmpc_plugin_get_translation_domain(plugins[i]); gtk_list_store_append(GTK_LIST_STORE(plugin_store_unfiltered), &iter); gtk_list_store_set(GTK_LIST_STORE(plugin_store_unfiltered), &iter, 0, i, #if defined(ENABLE_NLS) && GLIB_CHECK_VERSION(2,18,0) 1, g_dgettext(translation_domain, gmpc_plugin_get_name(plugins[i])), #else 1, gmpc_plugin_get_name(plugins[i]), #endif -1); } } } { GtkWidget *widget = (GtkWidget *) gtk_builder_get_object(xml_preferences_window, "eventbox_background"); gtk_widget_modify_bg(widget, GTK_STATE_NORMAL, &(dialog->style->base[GTK_STATE_NORMAL])); } label = (GtkWidget *) gtk_builder_get_object(xml_preferences_window, "plugin_label_box"); gtk_widget_set_app_paintable(label, TRUE); g_signal_connect(G_OBJECT(label), "expose-event", G_CALLBACK(misc_header_expose_event), NULL); gtk_widget_set_state(GTK_WIDGET(label), GTK_STATE_SELECTED); gtk_widget_show(dialog); gtk_builder_connect_signals(xml_preferences_window, NULL); }
/* * Run one client loop. Return -1 to exit */ static int do_client(BINKD_CONFIG *config) { FTN_NODE *r; int pid; if (!config->q_present) { q_free (SCAN_LISTED, config); if (config->printq) Log (-1, "scan\r"); q_scan (SCAN_LISTED, config); config->q_present = 1; if (config->printq) { LockSem (&lsem); q_list (stderr, SCAN_LISTED, config); ReleaseSem (&lsem); Log (-1, "idle\r"); } } if (n_clients < config->max_clients) { if ((r = q_next_node (config)) != 0) { struct call_args args; if (!bsy_test (&r->fa, F_BSY, config) || !bsy_test (&r->fa, F_CSY, config)) { char szDestAddr[FTN_ADDR_SZ + 1]; ftnaddress_to_str (szDestAddr, &r->fa); Log (4, "%s busy, skipping", szDestAddr); return 0; /* go to the next node */ } rel_grow_handles (6); threadsafe(++n_clients); lock_config_structure(config); args.node = r; args.config = config; if ((pid = branch (call, &args, sizeof (args))) < 0) { unlock_config_structure(config, 0); rel_grow_handles (-6); threadsafe(--n_clients); PostSem(&eothread); Log (1, "cannot branch out"); unblocksig(); SLEEP(1); blocksig(); check_child(&n_clients); } #if !defined(DEBUGCHILD) else { Log (5, "started client #%i, id=%i", n_clients, pid); #if defined(HAVE_FORK) && !defined(AMIGA) unlock_config_structure(config, 0); /* Forked child has own copy */ #endif } #endif } else { if (poll_flag) { if (n_clients <= 0 && q_not_empty (config) == 0) { Log (4, "the queue is empty, quitting..."); return -1; } } else config->q_present = 0; unblocksig(); SLEEP (config->rescan_delay); blocksig(); check_child(&n_clients); } } else { unblocksig(); SLEEP (config->call_delay); blocksig(); check_child(&n_clients); } return 0; }
/*=========================================================================== FUNCTION Q_INSERT DESCRIPTION This function inserts an item before a specified item on a queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE None. SIDE EFFECTS Input item is inserted before input item. ===========================================================================*/ void q_insert( #ifdef FEATURE_Q_NO_SELF_QPTR q_type *q_ptr, /* Ptr to the queue */ #endif q_link_type *q_insert_ptr, /* Ptr to link of item to insert */ q_link_type *q_item_ptr /* Ptr to link item to insert before */ ) { #ifdef FEATURE_Q_SINGLE_LINK q_link_type *link_ptr; #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_lock( q_ptr ); #else q_lock( q_item_ptr->q_ptr ); #endif q_insert_ptr->next_ptr = q_item_ptr; #ifdef FEATURE_Q_SINGLE_LINK /* Start at beginning of queue and find the item that will be before the ** new item */ #ifdef FEATURE_Q_NO_SELF_QPTR link_ptr = (q_link_type *) q_ptr; #else link_ptr = (q_link_type *) q_item_ptr->q_ptr; #endif while (link_ptr->next_ptr != q_item_ptr) { link_ptr = link_ptr->next_ptr; } link_ptr->next_ptr = q_insert_ptr; #else q_insert_ptr->prev_ptr = q_item_ptr->prev_ptr; q_item_ptr->prev_ptr->next_ptr = q_insert_ptr; q_item_ptr->prev_ptr = q_insert_ptr; #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_ptr->cnt++; #else q_insert_ptr->q_ptr = q_item_ptr->q_ptr; q_item_ptr->q_ptr->cnt++; #endif #ifdef FEATURE_Q_NO_SELF_QPTR Q_XCEPT_Q_INSERT( q_ptr, q_insert_ptr, q_item_ptr ); #else Q_XCEPT_Q_INSERT( q_insert_ptr, q_item_ptr ); #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_free( q_ptr ); #else q_free( q_item_ptr->q_ptr ); #endif return; } /* END q_insert */
/*=========================================================================== FUNCTION Q_DELETE_EXT DESCRIPTION This function removes an item from a specified queue. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. RETURN VALUE FALSE : if the item is not found in the queue. TRUE : if the item is found and removed from the queue. SIDE EFFECTS Input item is deleted from the queue. ===========================================================================*/ boolean q_delete_ext( #ifdef FEATURE_Q_NO_SELF_QPTR q_type *q_ptr, /* Ptr to the Queue */ #endif q_link_type *q_delete_ptr /* Ptr to link of item to delete */ ) { #ifdef FEATURE_Q_SINGLE_LINK q_link_type *link_ptr; q_type *real_q_ptr; #endif int qcount; boolean item_in_q = FALSE; #ifdef FEATURE_Q_NO_SELF_QPTR q_lock( q_ptr ); #else q_lock( q_delete_ptr->q_ptr ); #endif #ifdef FEATURE_Q_SINGLE_LINK #ifdef FEATURE_Q_NO_SELF_QPTR real_q_ptr = q_ptr; #else real_q_ptr = q_delete_ptr->q_ptr; #endif for( qcount = q_ptr->cnt, link_ptr = (q_link_type *) real_q_ptr; link_ptr->next_ptr != q_delete_ptr && qcount > 0; link_ptr = link_ptr->next_ptr, qcount--); if(qcount > 0) { link_ptr->next_ptr = q_delete_ptr->next_ptr; if(link_ptr->next_ptr == (q_link_type *) real_q_ptr) { real_q_ptr->link.prev_ptr = link_ptr; } #else q_delete_ptr->prev_ptr->next_ptr = q_delete_ptr->next_ptr; q_delete_ptr->next_ptr->prev_ptr = q_delete_ptr->prev_ptr; #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_ptr->cnt--; q_delete_ptr->next_ptr = NULL; #else q_delete_ptr->q_ptr->cnt--; q_delete_ptr->q_ptr = NULL; #endif #ifdef FEATURE_Q_NO_SELF_QPTR Q_XCEPT_Q_DELETE( q_ptr, q_delete_ptr ); #else Q_XCEPT_Q_DELETE( q_delete_ptr ); #endif item_in_q = TRUE; #ifdef FEATURE_Q_SINGLE_LINK } #endif #ifdef FEATURE_Q_NO_SELF_QPTR q_free( q_ptr ); #else q_free( q_delete_ptr->q_ptr ); #endif return item_in_q; } /* END q_delete_ext */
/*=========================================================================== FUNCTION Q_LINEAR_DELETE DESCRIPTION Given a comparison function, this function traverses the elements in a queue, calls the compare function, and returns a pointer to the current element being compared if the user passed compare function returns non zero. In addition, the item will be removed from the queue. The user compare function should return 0 if the current element is not the element in which the compare function is interested. DEPENDENCIES The specified queue should have been initialized previously via a call to q_init. The user's queue elements must have q_link_type as the first element of the queued structure. The user's compare function will be passed NULL for the compare value. RETURN VALUE None SIDE EFFECTS None. ===========================================================================*/ void q_linear_delete( q_type *q_ptr, q_compare_func_type compare_func, void *param, q_action_func_type action_func ) { q_generic_item_type *item_ptr = NULL; /* Used in the traversal to point to the current item */ q_generic_item_type *prev_ptr = NULL; /* Used in the traversal to point to the item previous to ** the current item. This makes removing the current item ** a constant time operation */ /* User must provide a compare function, otherwise, this is ** meaningless. */ if( compare_func == NULL ) { return; } q_lock( q_ptr ); /* item_ptr points to the first item on the list */ item_ptr = (q_generic_item_type*)q_check( q_ptr ); prev_ptr = NULL; while( item_ptr != NULL ) { if( compare_func( item_ptr, NULL ) != 0 ) { /* Remove the item */ if( prev_ptr != NULL ) { /* Remove from the middle or tail */ prev_ptr->link.next_ptr = item_ptr->link.next_ptr; item_ptr->link.next_ptr = NULL; } else { /* Remove from the head */ q_get( q_ptr ); } /* Call the action function if there is one */ if( action_func ) { action_func( item_ptr, param ); } break; } /* Move on to the next item */ prev_ptr = item_ptr; item_ptr = (q_generic_item_type*)q_next( q_ptr, &item_ptr->link ); } /* END while traversing the queue */ q_free( q_ptr ); return; } /* END q_linear_delete */
int main( /* int argc, char const *argv[] */ ) { printf("Projet Monoplan, Lenouvel Baptiste\n\n"); printf("======== TEST LIFO ========\n\n"); lifo_t stack; init_lifo(&stack, STACK_SIZE); printf("Push 42\n"); push(&stack, 42.0); printf("Push 1337\n"); push(&stack, 1337.0); printf("Push 31137\n"); push(&stack, 31337.0); printf("pop : %lf \n", pop(&stack)); printf("pop : %lf \n", pop(&stack)); printf("pop : %lf \n", pop(&stack)); printf("pop : %lf \n", pop(&stack)); printf("pop : %lf \n", pop(&stack)); free_lifo(&stack); printf("\n======== TEST QUEUE ======== \n\n"); queue_t * queue; int test = 1337; char * str = "apprenti"; char * str1 = "loick_et_ses_poules"; char * str2 = "limousin"; char * str3 = "ZZtop"; printf("Init queue : "); init_queue(&queue); printf("ok\n\n"); printf("Push %s \n", str); q_push(&queue, str); printf("Push %s \n", str1); q_push(&queue, str1); printf("Push in head : %d \n", test); q_push_head(&queue, &test); printf("Push in head : %s \n\n", str2); q_push_head(&queue, str2); printf("Removing %s ... %s \n\n", str2, q_remove(&queue, str2) ? "ok" : "ko"); // printf("Pop head : %s \n", (char *)(q_pop_head(&queue)) ); printf("Pop head : %d \n", *(int *)(q_pop_head(&queue)) ); printf("Pop head : %s \n", (char *)(q_pop_head(&queue)) ); printf("Pop head : %s \n\n", (char *)(q_pop_head(&queue)) ); printf("Push %s with q_operation \n\n", str3); q_operation(&q_push, &queue, str3); q_free(&queue); return 0; }