static void append_basic_info (NemoImagePropertiesPage *page) { GdkPixbufFormat *format; char *name; char *desc; char *value; format = gdk_pixbuf_loader_get_format (page->details->loader); name = gdk_pixbuf_format_get_name (format); desc = gdk_pixbuf_format_get_description (format); value = g_strdup_printf ("%s (%s)", name, desc); g_free (name); g_free (desc); append_item (page, _("Image Type"), value); g_free (value); value = g_strdup_printf (ngettext ("%d pixel", "%d pixels", page->details->width), page->details->width); append_item (page, _("Width"), value); g_free (value); value = g_strdup_printf (ngettext ("%d pixel", "%d pixels", page->details->height), page->details->height); append_item (page, _("Height"), value); g_free (value); }
int db_put_script(int node_no, const char *app, const char *buffer, size_t size) { struct databases db; char *key; int e, ret = -1; if (open_env(&db, APP_DB | MODEL_DB | CODE_DB)) goto out; key = make_key(node_no, app); if (!key) goto out; e = append_item(db.app, app, model_get_path(node_no)); if (e) goto out; e = put_data(db.code, key, buffer, size); if (e) goto out; e = append_item(db.model, model_get_path(node_no), app); if (e) goto out; ret = 0; out: close_env(&db); return ret; }
void add_event(pthread_t tid, msg_t * data) { if (strlen(data->sender) == 0 || index(data->sender, '!') == NULL) return; field_t field = get_nick(data->sender); seen_t * seen_data = been_seen(tid, field.field); seen_t * kick_data = NULL; if (is_value(data->command, "KICK")) { field_t knick = get_kicked_nick(data->message); kick_data = been_seen(tid, knick.field); } if (seen_data == NULL) { seen_data = malloc(sizeof(seen_t)); memset(seen_data, 0, sizeof(seen_t)); llist_t * result = append_item(seen_list, seen_data); if (result == NULL) free(seen_data); else { time(&(seen_data->time)); memcpy(&(seen_data->msg), data, sizeof(msg_t)); seen_data->tid = tid; seen_list = result; } } else { time(&(seen_data->time)); memcpy(&(seen_data->msg), data, sizeof(msg_t)); } if (kick_data == NULL && is_value(data->command, "KICK")) { kick_data = malloc(sizeof(seen_t)); memset(kick_data, 0, sizeof(seen_t)); llist_t * result = append_item(seen_list, kick_data); if (result == NULL) free(kick_data); else { time(&(kick_data->time)); memcpy(&(kick_data->msg), data, sizeof(msg_t)); kick_data->tid = tid; seen_list = result; } } else if (kick_data != NULL) { time(&(kick_data->time)); memcpy(&(kick_data->msg), data, sizeof(msg_t)); } }
static gboolean append_tag_value_pair (NemoImagePropertiesPage *page, ExifData *data, ExifTag tag, char *description) { char *utf_attribute; char *utf_value; utf_attribute = exifdata_get_tag_name_utf8 (tag); utf_value = exifdata_get_tag_value_utf8 (data, tag); if ((utf_attribute == NULL) || (utf_value == NULL)) { g_free (utf_attribute); g_free (utf_value); return FALSE; } append_item (page, description ? description : utf_attribute, utf_value); g_free (utf_attribute); g_free (utf_value); return TRUE; }
Item * insert_item(Item *list, Item *item, int position) { assert(list != NULL); assert(item != NULL); assert(position >= 0); if (position == 0) { return prepend_item(list, item); } Item *current_item = list; // In order to insert a new item, we must find the item 1 position before the // desired insert position. int i = position - 1; while(--i && current_item != NULL) { current_item = current_item->next_item; } if (current_item == NULL) { return append_item(list, item); } // Insert the new item Item *temp = current_item->next_item; current_item->next_item = item; item->next_item = temp; return list; }
int add_to_queue(list_t *list, uint8_t *buf, const int buf_size, ssize_t bytes_read) { struct inotify_event *event = NULL; const static int event_size = sizeof(struct inotify_event); uint32_t name_length = 0; uint8_t *pos = buf; int num_events = 0; ssize_t processed_bytes = 0; if (event_size * (bytes_read / event_size) != bytes_read) fprintf(log_file, "Sanity check failed: The number of bytes in the queue contains a partial event. Bytes = %zd\n", bytes_read); while (processed_bytes < bytes_read) { name_length = ((struct inotify_event *)pos)->len; event = (struct inotify_event *) malloc (event_size + name_length); print("event struct + length = %d\n", event_size + name_length); memcpy(event, pos, event_size + name_length); pos += event_size + name_length; processed_bytes += event_size + name_length; print("processed_bytes = %zd, bytes_read = %zd, event_size = %d\n", processed_bytes, bytes_read, event_size); append_item(list, event); num_events++; if (event->mask & IN_MODIFY) print("Inotify: Modify event.\n"); else if (event->mask & IN_ATTRIB) print("Inotify: Attribute event.\n"); else if (event->mask & IN_MOVED_FROM) { print("Inotify: Move out event.\n"); print("Event name length: %d\n", event->len); print("Event: %s\n", event->name); print("Tracker path: %s, wd = %d\n", get_tracker(event->wd), event->wd); } else if (event->mask & IN_MOVED_TO) { print("Inotify: Move in event.\n"); print("Event name length: %d\n", event->len); print("Event: %s\n", event->name); print("Tracker path: %s, wd = %d\n", get_tracker(event->wd), event->wd); } else if (event->mask & IN_CREATE) { print("Inotify: Create event.\n"); print("Event name length: %d\n", event->len); print("Event: %s\n", event->name); } else if (event->mask & IN_DELETE) { print("Inotify: Delete event.\n"); } else { print("Unknown event.\n"); } } return num_events; }
void z_store(Poly *l) { Zdatum *d = NEWSTRUCT(Zdatum); d->zmax = MIN(l->v[0].z, MIN(l->v[1].z, l->v[2].z)); d->l = l; d->o = o; append_item(z, new_item(d)); }
static void generate_bz_comment(struct strbuf *result, problem_data_t *pd, GList *comment_fmt_spec) { bool last_line_is_empty = true; GList *l = comment_fmt_spec; while (l) { section_t *sec = l->data; l = l->next; /* Skip special sections such as "%attach" */ if (sec->name[0] == '%') continue; if (sec->items) { /* "Text: item[,item]..." */ struct strbuf *output = strbuf_new(); GList *item = sec->items; while (item) { const char *str = item->data; item = item->next; if (str[0] == '-') /* "-name", ignore it */ continue; append_item(output, str, pd, comment_fmt_spec); } if (output->len != 0) { strbuf_append_strf(result, sec->name[0] ? "%s:\n%s" : "%s%s", sec->name, output->buf ); last_line_is_empty = false; } strbuf_free(output); } else { /* Just "Text" (can be "") */ /* Filter out consecutive empty lines */ if (sec->name[0] != '\0' || !last_line_is_empty) strbuf_append_strf(result, "%s\n", sec->name); last_line_is_empty = (sec->name[0] == '\0'); } } /* Nuke any trailing empty lines */ while (result->len >= 1 && result->buf[result->len-1] == '\n' && (result->len == 1 || result->buf[result->len-2] == '\n') ) { result->buf[--result->len] = '\0'; } }
static void append_xmp_value_pair (NemoImagePropertiesPage *page, XmpPtr xmp, const char *ns, const char *propname, char *descr) { uint32_t options; XmpStringPtr value; value = xmp_string_new(); if (xmp_get_property (xmp, ns, propname, value, &options)) { if (XMP_IS_PROP_SIMPLE (options)) { append_item (page, descr, xmp_string_cstr (value)); } else if (XMP_IS_PROP_ARRAY (options)) { XmpIteratorPtr iter; iter = xmp_iterator_new (xmp, ns, propname, XMP_ITER_JUSTLEAFNODES); if (iter) { GString *str; gboolean first = TRUE; str = g_string_new (NULL); while (xmp_iterator_next (iter, NULL, NULL, value, &options) && !XMP_IS_PROP_QUALIFIER(options)) { if (!first) { g_string_append_printf (str, ", "); } else { first = FALSE; } g_string_append_printf (str, "%s", xmp_string_cstr(value)); } xmp_iterator_free(iter); append_item (page, descr, g_string_free (str, FALSE)); } } } xmp_string_free(value); }
int db_put_script(int node_no, const char *app, const char *buffer, size_t size) { struct databases db; int e, ret = -1; if (open_env(&db, APP_DB | MODEL_DB)) goto out; e = append_item(db.app, app, model_get_path(node_no)); if (e) goto out; e = append_item(db.model, model_get_path(node_no), app); if (e) goto out; ret = 0; out: close_env(&db); if (ret == 0) { ret = db_save_code(node_no, app, buffer); } return ret; }
const char* test_list() { gc_list list; initialize_list(&list); for(long i = 1; i < 17; ++i) append_item((os_pointer)i, &list); gc_list_iterator itr; begin_list_iteration(&list, &itr); os_pointer item = 0; long expected = 1; while((item = current_item(&itr))) { if((long)item != expected) return "append item failed"; if((long)item % 2 == 0 || (long)item < 7) remove_item(&itr); advance_item(&itr); ++expected; } for(long i = 16; i < 19; ++i) append_item((os_pointer)i, &list); long expected2[] = {7, 9, 11, 13, 15, 16, 17, 18}; int expected2_idx = 0; begin_list_iteration(&list, &itr); while((item = current_item(&itr))) { if((long)item != expected2[expected2_idx++]) return "remove item failed"; advance_item(&itr); } finalize_list(&list); return "passed"; }
int main() { sll_t list; list.head = NULL; list.last = &list.head; append_item(&list); append_item(&list); #if TRIGGER_INV_BUG append_item(&list); #endif /* destroy list in reverse order - complexity (n^2 / 2) */ while (list.head) { sll_item_t **tmp = &list.head; while ((*tmp)->next) tmp = &(*tmp)->next; free(*tmp); *tmp = NULL; } return 0; }
static gboolean append_option_value_pair (NemoImagePropertiesPage *page, GdkPixbuf *pixbuf, const char *key, char *description) { const char *value; value = gdk_pixbuf_get_option (pixbuf, key); if (value == NULL) return FALSE; append_item (page, description, value); return TRUE; }
int main(int argc, char **argv) { unsigned int i; unsigned int limit = 10; // Think of `list` as an array variable. In C, an array variable is // actually a pointer to the first element of the array. Item *list, *current_item; // Initialize the list current_item = list = allocate_item(); //printf("\n Got here. \n"); init_list(list); // Create list items for(i = 0; i < limit; i ++) { // When creating a new item, set the new item's address to the struct // memeber `next_item` and then set `next_item` to `current_item` to advance // the list. Item *item = allocate_item(); append_item(current_item, item); current_item->value = i; current_item = current_item->next_item; } // Reset the current item pointer to the start of the list so we can print the // list to stdout current_item = list; find_middle(list); printf(" Full list"); print_list(list); list = reverse_list(list); //delete_item(list, 5); printf("\n\n Full list"); print_list(list); current_item = find_item(list, 4); printf(" Searched item: %d", current_item->value); // Leak memory. }
static void format_section(section_t *section, problem_data_t *pd, GList *comment_fmt_spec, FILE *result, problem_report_settings_t *settings) { int empty_lines = -1; for (GList *iter = section->children; iter; iter = g_list_next(iter)) { section_t *child = (section_t *)iter->data; if (child->items) { /* "Text: item[,item]..." */ struct strbuf *output = strbuf_new(); GList *item = child->items; while (item) { const char *str = item->data; item = item->next; if (str[0] == '-') /* "-name", ignore it */ continue; append_item(output, str, pd, comment_fmt_spec, settings); } if (output->len != 0) add_to_section_output((child->name[0] ? "%s:\n%s" : "%s%s"), child->name, output->buf); strbuf_free(output); } else { /* Just "Text" (can be "") */ /* Filter out trailint empty lines */ if (child->name[0] != '\0') add_to_section_output("%s\n", child->name); /* Do not count empty lines, if output wasn't yet produced */ else if (empty_lines >= 0) ++empty_lines; } } }
static void append_items (GladeEditorTable *table, GladeWidgetAdaptor *adaptor, GladeEditorPageType type) { GladeEditorProperty *property; GladePropertyClass *property_class; GList *list, *sorted_list; sorted_list = get_sorted_properties (adaptor, type); for (list = sorted_list; list != NULL; list = list->next) { property_class = (GladePropertyClass *) list->data; property = append_item (table, property_class, type == GLADE_PAGE_QUERY); table->priv->properties = g_list_prepend (table->priv->properties, property); } g_list_free (sorted_list); table->priv->properties = g_list_reverse (table->priv->properties); }
static void load_finished (NemoImagePropertiesPage *page) { GtkWidget *label; label = gtk_grid_get_child_at (GTK_GRID (page->details->grid), 0, 0); gtk_container_remove (GTK_CONTAINER (page->details->grid), label); if (page->details->loader != NULL) { gdk_pixbuf_loader_close (page->details->loader, NULL); } if (page->details->got_size) { append_basic_info (page); append_options_info (page); append_exif_info (page); append_xmp_info (page); } else { append_item (page, _("Failed to load image information"), NULL); } if (page->details->loader != NULL) { g_object_unref (page->details->loader); page->details->loader = NULL; } #ifdef HAVE_EXIF if (page->details->exifldr != NULL) { exif_loader_unref (page->details->exifldr); page->details->exifldr = NULL; } #endif /*HAVE_EXIF*/ #ifdef HAVE_EXEMPI if (page->details->xmp != NULL) { xmp_free (page->details->xmp); page->details->xmp = NULL; } #endif }
void kbest(id_type v, const hypergraph_type& graph_in, hypergraph_type& graph_out) { //std::cerr << "kbest node: " << v << std::endl; // clear candidates! candidates.clear(); const node_type& node = graph_in.nodes[v]; const bool is_goal(v == graph_in.goal); // for each incoming e, cand \leftarrow { <e, 1>} cand.clear(); cand.reserve(node.edges.size() * cube_size_max); // we don't need this for alg. 2 //cand_unique.clear(); node_type::edge_set_type::const_iterator eiter_end = node.edges.end(); for (node_type::edge_set_type::const_iterator eiter = node.edges.begin(); eiter != eiter_end; ++ eiter) { const edge_type& edge = graph_in.edges[*eiter]; const index_set_type j(edge.tails.size(), 0); const candidate_type* item = make_candidate(edge, j, is_goal); cand.push(item); // for faster cube pruning (alg 2, 3), we do not insert here! //cand_unique.insert(item); } //std::cerr << "perform cube-prune" << std::endl; state_node_map_type buf(cand.size(), model_type::state_hash(model.state_size()), model_type::state_equal(model.state_size())); score_type score_max; for (size_type num_pop = 0; !cand.empty() && num_pop != cube_size_max; /**/) { // pop-best... const candidate_type* item = cand.top(); cand.pop(); push_succ(*item, is_goal, cand); score_max = std::max(score_max, item->score); // perform rejection here! if (sampler.bernoulli(item->score / score_max)) { append_item(*item, is_goal, buf, graph_out); ++ num_pop; } } //std::cerr << "finished" << std::endl; // sort buf to D(v) D[v].reserve(buf.size()); typename state_node_map_type::const_iterator biter_end = buf.end(); for (typename state_node_map_type::const_iterator biter = buf.begin(); biter != biter_end; ++ biter) D[v].push_back(node_score_type(biter->second->out_edge.head, biter->second->score)); std::sort(D[v].begin(), D[v].end(), compare_estimate_type()); typename candidate_heap_type::const_iterator hiter_end = cand.end(); for (typename candidate_heap_type::const_iterator hiter = cand.begin(); hiter != hiter_end; ++ hiter) model.deallocate((*hiter)->state); }
item& item::append(item& other) { return *append_item(parent_item?(new item(other,parent_item)):(new item(other,relation_ptr))); }
item& item::append() { return *append_item(parent_item?(new item(parent_item)):(new item(relation_ptr))); }
/* Start watching all subdirectories of the mount point */ void add_subdir_watchers(char *dir, int inotify_fd, int inotify_mask) { FTSENT *f; char *main_dir[] = { dir, NULL }; list_t *dir_list = create_list(); FTS *tree = fts_open(main_dir, FTS_LOGICAL | FTS_NOSTAT, entry_cmp); bool has_skipped_first = false; char *item = NULL; int path_length = 0; while ((f = fts_read(tree))) { // The first directory returned is the current directory which // we already have a watcher for if (!has_skipped_first) { has_skipped_first = true; continue; } switch (f->fts_info) { case FTS_D: // We have a directory path_length = strlen(f->fts_path); /* item = (char *) malloc((path_length+1) * sizeof(char)); */ /* strcpy(item, f->fts_path); */ item = strdup(f->fts_path); print("Dir item: %s\n", item); append_item(dir_list, item); break; case FTS_DNR: // Cannot read directory break; case FTS_ERR: // Miscellaneous error fprintf(log_file, "There was a general error at %s\n", f->fts_path); break; case FTS_NS: fprintf(log_file, "There was a stat error at %s\n", f->fts_path); continue; default: continue; } // Symbolic link cycle if (f->fts_info == FTS_DC) fprintf(log_file, "%s: cycle in directory tree", f->fts_path); } /* fts_read() sets errno = 0 unless it has error. */ if (errno != 0) fprintf(log_file, "fts_read failed."); else { print("Iterating...\n"); iterate(dir_list, printer, NULL); inotify_info_t inotify_info; inotify_info.inotify_fd = inotify_fd; inotify_info.mask = inotify_mask; int watcher_error = 0; if ((watcher_error = iterate(dir_list, add_watcher, &inotify_info)) != 0) { if (watcher_error != -1) { fprintf(log_file, "There was problem adding file watchers. Terminating Daemon.\n"); exit(watcher_error); } } destroy_list_and_items(dir_list); } if (fts_close(tree) < 0) fprintf(log_file, "fts_close failed.\n"); }
mazeNode* maze::traversegraph() { // traverses the maze using a breadth-first search algorithm // start at the start node int x = start[0]; int y = start[1]; mazeNode* start_node = new mazeNode(x, y); nodearray[x][y] = start_node; // std::cout << "traversing, starting at: " << x << ", " << y << std::endl; // make a to-do list to_do_item* to_do_list = NULL; //to_do_list->node = NULL; to_do_list->next = NULL; // put the start node in the to-do list append_item(&to_do_list, start_node); // std::cout << "starting the huge loop" << std::endl; // the meat of this algorithm: // pull an item off the front of the to do list // if its neighbors have not yet been visited, // add them onto the end of our to do list // repeat until we find the solution finish or run out of items // while the to-do list is not empty: while (to_do_list != NULL) { // pull the first item off the to-do list, call it cur_node mazeNode* cur_node = to_do_list->node; // std::cout << "pulled an item off the list" << std::endl; to_do_list = to_do_list->next; // find all its neighbors // get ready to search in all 4 directions int x = cur_node->coords[0]; int y = cur_node->coords[1]; // std::cout << "currently visiting: " << x << ", " << y << std::endl; int up[2] = {x, y - 1}; int down[2] = {x, y + 1}; int left[2] = {x - 1, y}; int right[2] = {x + 1, y}; int* dirarray[4] = {left, up, right, down}; // check each direction for (int i = 0; i < 4; i++) { int nextx = dirarray[i][0]; int nexty = dirarray[i][1]; // make sure we are checking a valid location if (!isvalid(nextx, nexty)) { continue; } // make sure it has not yet been visited if (nodearray[nextx][nexty] != NULL) { continue; } // mark them as visited and make their prev_nodes point to cur_node // std::cout << "constructing a new node at: " << nextx << ", " << nexty << std::endl; mazeNode* new_node = new mazeNode(nextx, nexty); new_node->prev_node = cur_node; nodearray[nextx][nexty] = new_node; // if we found the finish, we're done! if (mazearray[nextx][nexty] == '$') { return new_node; } // otherwise, append it to the to-do list append_item(&to_do_list, new_node); } } return NULL; }