static ret_t table_add_new_entry (cherokee_resolv_cache_t *resolv, cherokee_buffer_t *domain, cherokee_resolv_cache_entry_t **entry) { ret_t ret; cherokee_resolv_cache_entry_t *n = NULL; /* Instance the entry */ ret = entry_new (&n); if (unlikely (ret != ret_ok)) { return ret; } /* Fill it up */ ret = entry_fill_up (n, domain); if (unlikely (ret != ret_ok)) { entry_free (n); return ret; } /* Add it to the table */ CHEROKEE_RWLOCK_WRITER (&resolv->lock); ret = cherokee_avl_add (&resolv->table, domain, (void **)n); CHEROKEE_RWLOCK_UNLOCK (&resolv->lock); *entry = n; return ret_ok; }
void goom_hash_put(GoomHash *_this, const char *key, HashValue value) { _this->number_of_puts += 1; if (_this->root == NULL) _this->root = entry_new(key,value); else entry_put(_this->root,key,value); }
// Retorna la raíz del AVL tras haber insertado (key, val) en nodo. static struct avl_nodo *_avl_insertar(struct avl_nodo *nodo, const char *key, void *val, int valsize){ if (nodo == NULL) { struct avl_nodo *n = malloc(sizeof(struct avl_nodo)); n->der = NULL; n->izq = NULL; n->e = malloc(sizeof(entry)); entry_new(n->e, key, val, valsize); n->altura = 1; return n; } // Estoy en un nodo que ya tiene elemento int cmp = strcmp(key, nodo->e->key); if (cmp < 0) nodo->izq = _avl_insertar(nodo->izq, key, val, valsize); else if(cmp > 0) nodo->der = _avl_insertar(nodo->der, key, val, valsize); else { // cmp == 0 // el elemento ya está: lo reemplazo por lo nuevo y no balanceo. entry_replace_val(nodo->e, val, valsize); return nodo; } // finalmente balanceamos el AVL return _balancear(nodo); }
/* * Lies ein attrval-record nach position `offset' in `s'. * Setze *pos (falls pos != 0). * Liefere 0 bei Erfolg, -1 sonst. * Bei Erfolg: * - pos ist die exakte Anfangsposition. * - Setze *entry auf den gelesenen Eintrag (falls entry != 0). * - Setze *key auf den Schluessel (falls key != 0). * EOF ist kein Fehler und liefert *key = 0 (falls key != 0); */ int ldif_read_entry(FILE *s, long offset, char **key, tentry **entry, long *pos) { GString *tmp1 = g_string_new(""); GString *tmp2 = g_string_new(""); char *dn; char *k = 0; tentry *e = 0; int rc = ldif_read_header(tmp1, tmp2, s, offset, &k, &dn, pos); if (rc || !k) goto cleanup; e = entry_new(dn); rc = ldif_read_attrval_body(tmp1, tmp2, s, e); if (!rc) { if (entry) { *entry = e; e = 0; } if (key) { *key = k; k = 0; } } cleanup: if (k) free(k); if (e) entry_free(e); g_string_free(tmp1, 1); g_string_free(tmp2, 1); return rc; }
static void entry_put(GoomHashEntry *entry, const char *key, HashValue value) { int cmp = strcmp(key,entry->key); if (cmp==0) { entry->value = value; } else if (cmp > 0) { if (entry->upper == NULL) entry->upper = entry_new(key,value); else entry_put(entry->upper, key, value); } else { if (entry->lower == NULL) entry->lower = entry_new(key,value); else entry_put(entry->lower, key, value); } }
block_t *block_load(int32_t fd, int32_t offset, int32_t size) { block_t *l; entry_t *o; int32_t len; int8_t *buffer, *ptr; if (fd < 0 || offset < 0 || size < 0) return(NULL); if ((l = block_new()) == NULL) return(NULL); if ((buffer = malloc(size)) == NULL) __ERROR_LOG(B_ERROR); lseek(fd,offset,SEEK_SET); if (size != read(fd,buffer,size)) __ERROR_LOG(R_ERROR); ptr = buffer; l->magic = *(uint64_t *)ptr; ptr = ptr + sizeof(uint64_t); if (l->magic != crc32_encode(ptr,size - sizeof(uint64_t))) __ERROR_LOG(C_ERROR); while (ptr - buffer < size) { if ((o = entry_new()) == NULL) continue; len = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); o->key = sdsnnew(ptr,len); ptr = ptr + len; len = *(int32_t *)ptr; ptr = ptr + sizeof(int32_t); o->value = sdsnnew(ptr,len); ptr = ptr + len; if (o->key && o->value) { block_add(l,o); continue; } if (o->key) sdsdel(o->key); if (o->value) sdsdel(o->value); } free(buffer); return(l); C_ERROR: R_ERROR: free(buffer); B_ERROR: block_free(l); return(NULL); }
static struct avl_nodo *_avl_borrow(struct avl_nodo *nodo, entry *e){ if (nodo->izq != NULL){ nodo->izq = _avl_borrow(nodo->izq, e); return nodo; } // no hay hijos izquierdos entry_new(e, nodo->e->key, nodo->e->val, nodo->e->val_size); return _avl_eliminar_nodo(nodo); }
void array_append(Array* array, double x) { if(!array->last) { Entry *entry = entry_new(); array->start = entry; array->last = entry; } Entry *old = array->last; array->last = entry_append(array->last, x); if(old != array->last) array->size++; }
Entry* entry_append(Entry* entry, double x) { if(entry->size < BLOCKSIZE) { entry->data[entry->size] = x; entry->size++; return entry; } else { Entry *newentry = entry_new(); entry->next = newentry; entry_append(newentry, x); return newentry; } }
static Entry* dir_make_new_entry(Dir* d, const gchar* relative_key) { Entry* e; g_return_val_if_fail(d->doc != NULL, NULL); g_return_val_if_fail(d->doc->xmlRootNode != NULL, NULL); e = entry_new(relative_key); entry_set_node(e, xmlNewChild(d->doc->xmlRootNode, NULL, (xmlChar *)"entry", NULL)); safe_g_hash_table_insert(d->entry_cache, (gchar*)entry_get_name(e), e); return e; }
static dlist * entry_set(dlist *config, const char *section, char *key, char *value) { dlist *iter = dlist_first(config); ConfigEntry *entry; for(; iter; iter = iter->next) { entry = (ConfigEntry *)iter->data; if(! strcasecmp(entry->section, section) && ! strcasecmp(entry->key, key)) { free(key); free(entry->value); entry->value = value; return config; } } entry = entry_new(section, key, value); return dlist_add(config, entry); }
void history_update(t_server *server) { t_history *history; t_request request; t_entry *entry; request = server->request; history = &(server->history); entry = entry_new(request); if (!history->queue) { history->queue = ft_queuenw((void*)(entry), sizeof(t_entry)); history->last_save = history->queue->head; } else ft_enqueue(history->queue, (void*)(entry), sizeof(t_entry)); free(entry); }
void config_set_string(config_t *config, const char *section, const char *key, const char *value) { section_t *sec = section_find(config, section); if (!sec) { sec = section_new(section); list_append(config->sections, sec); } for (const list_node_t *node = list_begin(sec->entries); node != list_end(sec->entries); node = list_next(node)) { entry_t *entry = list_node(node); if (!strcmp(entry->key, key)) { free(entry->value); entry->value = strdup(value); return; } } entry_t *entry = entry_new(key, value); list_append(sec->entries, entry); }
int pa_autoload_add(pa_core *c, const char*name, pa_namereg_type_t type, const char*module, const char *argument, uint32_t *idx) { pa_autoload_entry *e = NULL; pa_assert(c); pa_assert(name); pa_assert(module); pa_assert(type == PA_NAMEREG_SINK || type == PA_NAMEREG_SOURCE); if (!(e = entry_new(c, name))) return -1; e->module = pa_xstrdup(module); e->argument = pa_xstrdup(argument); e->type = type; if (idx) *idx = e->index; return 0; }
Object* LookupTable::store(STATE, Object* key, Object* val) { unsigned int num_entries, num_bins, bin; Object* new_ent; Tuple* cur; Tuple* entry; key_to_sym(key); num_entries = entries_->to_native(); num_bins = bins_->to_native(); if(max_density_p(num_entries, num_bins)) { redistribute(state, num_bins <<= 1); } bin = find_bin(key_hash(key), num_bins); cur = entry = try_as<Tuple>(values_->at(state, bin)); while(entry) { if(entry->at(state, 0) == key) { entry->put(state, 1, val); return val; } cur = entry; entry = try_as<Tuple>(entry->at(state, 2)); } new_ent = entry_new(state, key, val); if(cur) { cur->put(state, 2, new_ent); } else { values_->put(state, bin, new_ent); } entries(state, Fixnum::from(num_entries + 1)); return val; }
void osm_upload(appdata_t *appdata, osm_t *osm, project_t *project) { printf("starting upload\n"); /* upload config and confirmation dialog */ /* count nodes */ osm_dirty_t dirty; memset(&dirty, 0, sizeof(dirty)); const node_t *node = osm->node; while(node) { object_counter(OSM_BASE(node), &dirty.nodes); node = node->next; } printf("nodes: new %2d, dirty %2d, deleted %2d\n", dirty.nodes.added, dirty.nodes.dirty, dirty.nodes.deleted); /* count ways */ const way_t *way = osm->way; while(way) { object_counter(OSM_BASE(way), &dirty.ways); way = way->next; } printf("ways: new %2d, dirty %2d, deleted %2d\n", dirty.ways.added, dirty.ways.dirty, dirty.ways.deleted); /* count relations */ const relation_t *relation = osm->relation; while(relation) { object_counter(OSM_BASE(relation), &dirty.relations); relation = relation->next; } printf("relations: new %2d, dirty %2d, deleted %2d\n", dirty.relations.added, dirty.relations.dirty, dirty.relations.deleted); GtkWidget *dialog = misc_dialog_new(MISC_DIALOG_MEDIUM, _("Upload to OSM"), GTK_WINDOW(appdata->window), GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT, GTK_STOCK_OK, GTK_RESPONSE_ACCEPT, NULL); GtkWidget *table = gtk_table_new(4, 5, TRUE); table_attach_label_c(table, _("Total"), 1, 2, 0, 1); table_attach_label_c(table, _("New"), 2, 3, 0, 1); table_attach_label_c(table, _("Modified"), 3, 4, 0, 1); table_attach_label_c(table, _("Deleted"), 4, 5, 0, 1); int row = 1; table_attach_label_l(table, _("Nodes:"), 0, 1, row, row + 1); table_insert_count(table, &dirty.nodes, row++); table_attach_label_l(table, _("Ways:"), 0, 1, row, row + 1); table_insert_count(table, &dirty.ways, row++); table_attach_label_l(table, _("Relations:"), 0, 1, row, row + 1); table_insert_count(table, &dirty.relations, row++); gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), table, FALSE, FALSE, 0); /* ------------------------------------------------------ */ gtk_box_pack_start(GTK_BOX(GTK_DIALOG(dialog)->vbox), gtk_hseparator_new(), FALSE, FALSE, 0); /* ------- add username and password entries ------------ */ table = gtk_table_new(2, 2, FALSE); table_attach_label_l(table, _("Username:"******"Password:"******"Please add a comment"), -1); /* disable ok button until user edited the comment */ gtk_dialog_set_response_sensitive(GTK_DIALOG(dialog), GTK_RESPONSE_ACCEPT, FALSE); g_signal_connect(G_OBJECT(buffer), "changed", G_CALLBACK(callback_buffer_modified), dialog); #ifndef FREMANTLE GtkWidget *view = gtk_text_view_new_with_buffer(buffer); #else GtkWidget *view = hildon_text_view_new(); hildon_text_view_set_buffer(HILDON_TEXT_VIEW(view), buffer); #endif gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(view), GTK_WRAP_WORD); gtk_text_view_set_editable(GTK_TEXT_VIEW(view), TRUE); gtk_text_view_set_left_margin(GTK_TEXT_VIEW(view), 2 ); gtk_text_view_set_right_margin(GTK_TEXT_VIEW(view), 2 ); g_object_set_data(G_OBJECT(view), "first_click", GINT_TO_POINTER(TRUE)); g_signal_connect(G_OBJECT(view), "focus-in-event", G_CALLBACK(cb_focus_in), buffer); gtk_container_add(GTK_CONTAINER(scrolled_win), view); gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(dialog)->vbox), scrolled_win); gtk_widget_show_all(dialog); if(GTK_RESPONSE_ACCEPT != gtk_dialog_run(GTK_DIALOG(dialog))) { printf("upload cancelled\n"); gtk_widget_destroy(dialog); return; } printf("clicked ok\n"); /* retrieve username and password */ g_free(appdata->settings->username); appdata->settings->username = g_strdup(gtk_entry_get_text(GTK_ENTRY(uentry))); g_free(appdata->settings->password); appdata->settings->password = g_strdup(gtk_entry_get_text(GTK_ENTRY(pentry))); /* osm upload itself also has a gui */ osm_upload_context_t *context = g_new0(osm_upload_context_t, 1); context->appdata = appdata; context->osm = osm; context->project = project; /* add proxy settings if required */ if(appdata->settings) context->proxy = appdata->settings->proxy; /* fetch comment from dialog */ GtkTextIter start, end; gtk_text_buffer_get_start_iter(buffer, &start); gtk_text_buffer_get_end_iter(buffer, &end); char *text = gtk_text_buffer_get_text(buffer, &start, &end, FALSE); context->comment = g_strdup(text); gtk_widget_destroy(dialog); project_save(GTK_WIDGET(appdata->window), project); context->dialog = misc_dialog_new(MISC_DIALOG_LARGE,_("Uploading"), GTK_WINDOW(appdata->window), GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, NULL); gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), GTK_RESPONSE_CLOSE, FALSE); /* ------- main ui element is this text view --------------- */ GtkWidget *scrolled_window = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); context->log.buffer = gtk_text_buffer_new(NULL); context->log.view = gtk_text_view_new_with_buffer(context->log.buffer); gtk_text_view_set_editable(GTK_TEXT_VIEW(context->log.view), FALSE); gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(context->log.view), FALSE); gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(context->log.view), GTK_WRAP_WORD); gtk_container_add(GTK_CONTAINER(scrolled_window), context->log.view); gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(scrolled_window), GTK_SHADOW_IN); gtk_box_pack_start_defaults(GTK_BOX(GTK_DIALOG(context->dialog)->vbox), scrolled_window); gtk_widget_show_all(context->dialog); /* server url should not end with a slash */ if(project->rserver && project->rserver[strlen(project->rserver)-1] == '/') { printf("removing trailing slash\n"); project->rserver[strlen(project->rserver)-1] = 0; } appendf(&context->log, NULL, _("Log generated by %s v%s using API 0.6\n"), PACKAGE, VERSION); appendf(&context->log, NULL, _("User comment: %s\n"), context->comment); /* check if server name contains string "0.5" and adjust it */ if(project->rserver && strstr(project->rserver, "0.5") != NULL) { strstr(project->rserver, "0.5")[2] = '6'; appendf(&context->log, NULL, _("Adjusting server name to v0.6\n")); } appendf(&context->log, NULL, _("Uploading to %s\n"), project->server); /* create a new changeset */ gchar *cred; if(osm_create_changeset(context, &cred)) { /* check for dirty entries */ appendf(&context->log, NULL, _("Uploading nodes:\n")); osm_upload_nodes(context, cred); appendf(&context->log, NULL, _("Uploading ways:\n")); osm_upload_ways(context, cred); appendf(&context->log, NULL, _("Uploading relations:\n")); osm_upload_relations(context, cred); appendf(&context->log, NULL, _("Deleting relations:\n")); osm_delete_relations(context, cred); appendf(&context->log, NULL, _("Deleting ways:\n")); osm_delete_ways(context, cred); appendf(&context->log, NULL, _("Deleting nodes:\n")); osm_delete_nodes(context, cred); /* close changeset */ osm_close_changeset(context, cred); } appendf(&context->log, NULL, _("Upload done.\n")); gboolean reload_map = FALSE; if(project->data_dirty) { appendf(&context->log, NULL, _("Server data has been modified.\n")); appendf(&context->log, NULL, _("Downloading updated osm data ...\n")); if(osm_download(context->dialog, appdata->settings, project)) { appendf(&context->log, NULL, _("Download successful!\n")); appendf(&context->log, NULL, _("The map will be reloaded.\n")); project->data_dirty = FALSE; reload_map = TRUE; } else appendf(&context->log, NULL, _("Download failed!\n")); project_save(context->dialog, project); if(reload_map) { /* this kind of rather brute force reload is useful as the moment */ /* after the upload is a nice moment to bring everything in sync again. */ /* we basically restart the entire map with fresh data from the server */ /* and the diff will hopefully be empty (if the upload was successful) */ appendf(&context->log, NULL, _("Reloading map ...\n")); if(!diff_is_clean(appdata->osm, FALSE)) { appendf(&context->log, COLOR_ERR, _("*** DIFF IS NOT CLEAN ***\n")); appendf(&context->log, COLOR_ERR, _("Something went wrong during upload,\n")); appendf(&context->log, COLOR_ERR, _("proceed with care!\n")); } /* redraw the entire map by destroying all map items and redrawing them */ appendf(&context->log, NULL, _("Cleaning up ...\n")); diff_save(appdata->project, appdata->osm); map_clear(appdata, MAP_LAYER_OBJECTS_ONLY); osm_free(appdata->osm); appendf(&context->log, NULL, _("Loading OSM ...\n")); appdata->osm = osm_parse(appdata->project->path, appdata->project->osm, &appdata->icon); appendf(&context->log, NULL, _("Applying diff ...\n")); diff_restore(appdata, appdata->project, appdata->osm); appendf(&context->log, NULL, _("Painting ...\n")); map_paint(appdata); appendf(&context->log, NULL, _("Done!\n")); } } /* tell the user that he can stop waiting ... */ appendf(&context->log, NULL, _("Process finished.\n")); gtk_dialog_set_response_sensitive(GTK_DIALOG(context->dialog), GTK_RESPONSE_CLOSE, TRUE); gtk_dialog_run(GTK_DIALOG(context->dialog)); gtk_widget_destroy(context->dialog); g_free(context->comment); g_free(context); }
static void dir_fill_cache_from_doc(Dir* d) { xmlNodePtr node; if (d->doc == NULL || d->doc->xmlRootNode == NULL || d->doc->xmlRootNode->xmlChildrenNode == NULL) { /* Empty document - just return. */ return; } node = d->doc->xmlRootNode->xmlChildrenNode; while (node != NULL) { if (node->type == XML_ELEMENT_NODE && (strcmp((xmlChar *)node->name, "entry") == 0)) { gchar* attr = my_xmlGetProp(node, "name"); if (attr != NULL) { if (g_hash_table_lookup(d->entry_cache, attr) != NULL) { gconf_log(GCL_WARNING, _("Duplicate entry `%s' in `%s', ignoring"), attr, d->xml_filename); } else { Entry* e; e = entry_new(attr); entry_set_node(e, node); entry_fill_from_node(e); safe_g_hash_table_insert(d->entry_cache, (gchar*)entry_get_name(e), e); } free(attr); } else { gconf_log(GCL_WARNING, _("Entry with no name in XML file `%s', ignoring"), d->xml_filename); } } else { if (node->type == XML_ELEMENT_NODE) gconf_log(GCL_WARNING, _("A toplevel node in XML file `%s' is <%s> rather than <entry>, ignoring"), d->xml_filename, node->name ? (char*) node->name : "unknown"); } node = node->next; } }
gboolean is_store_add_sensor(IsStore *self, IsSensor *sensor, GtkTreeIter *iter) { IsStorePrivate *priv; GSequence *entries; IsStoreEntry *entry = NULL; GSequenceIter *parent = NULL; gchar **names = NULL; int i; GtkTreePath *path; GtkTreeIter _iter; gboolean ret = FALSE; g_return_val_if_fail(IS_IS_STORE(self), FALSE); g_return_val_if_fail(IS_IS_SENSOR(sensor), FALSE); priv = self->priv; entry = find_entry(self, is_sensor_get_path(sensor)); if (entry) { is_warning("store", "sensor %s already exists in store, not adding duplicate", is_sensor_get_path(sensor)); goto out; } entries = priv->entries; names = g_strsplit(is_sensor_get_path(sensor), "/", 0); /* otherwise iterate through to create the entry */ for (i = 0; names[i] != NULL; i++) { GSequenceIter *seq_iter; gchar *name = names[i]; entry = NULL; for (seq_iter = g_sequence_get_begin_iter(entries); !g_sequence_iter_is_end(seq_iter); seq_iter = g_sequence_iter_next(seq_iter)) { entry = (IsStoreEntry *)g_sequence_get(seq_iter); if (g_strcmp0(entry->name, name) == 0) { entries = entry->entries; parent = seq_iter; break; } entry = NULL; } if (!entry) { /* create entry for this name component */ entry = entry_new(name); entry->iter = g_sequence_append(entries, entry); entry->parent = parent; entries = entry->entries; _iter.stamp = priv->stamp; _iter.user_data = entry->iter; path = gtk_tree_model_get_path(GTK_TREE_MODEL(self), &_iter); gtk_tree_model_row_inserted(GTK_TREE_MODEL(self), path, &_iter); gtk_tree_path_free(path); /* parent of the next entry we create will be this * entry */ parent = entry->iter; } } g_strfreev(names); g_assert(entry); g_assert(find_entry(self, is_sensor_get_path(sensor)) == entry); is_debug("store", "inserted sensor %s with label %s", is_sensor_get_path(sensor), is_sensor_get_label(sensor)); entry->sensor = g_object_ref(sensor); _iter.stamp = priv->stamp; _iter.user_data = entry->iter; path = gtk_tree_model_get_path(GTK_TREE_MODEL(self), &_iter); gtk_tree_model_row_changed(GTK_TREE_MODEL(self), path, &_iter); gtk_tree_path_free(path); /* return a copy of iter */ if (iter != NULL) { iter->stamp = priv->stamp; iter->user_data = entry->iter; } ret = TRUE; out: return ret; }
int main(int argc, char **argv) { block_t *l; entry_t *e; int8_t buffer[KEY_MAX]; sds key; int32_t count, cost, i; int32_t ok_c, err_c; if (argc != 2) return(-1); count = atoi(argv[1]); l = block_new(); printf("\nBlock add Test...\n"); ok_c = err_c = 0; cost = time(NULL); for (i = 0; i < count; i++) { e = entry_new(); snprintf(buffer,KEY_MAX,"%d",i); e->key = sdsnew(buffer); snprintf(buffer,KEY_MAX,"key = %d",i); e->value = sdsnew(buffer); if (0 == block_add(l,e)) ok_c++; else err_c++; } cost = time(NULL) - cost; printf("%d add ok and %d error\n",ok_c,err_c); printf("total cost : %d\n",cost); printf("\nBlock search Test...\n"); ok_c = err_c = 0; cost = time(NULL); for (i = 0; i < count; i++) { snprintf(buffer,KEY_MAX,"%d",i); key = sdsnew(buffer); if ((e = block_loup(l,key)) == NULL) err_c++; else { if (strstr(e->value,"0") != NULL) { printf("%s del ok\n",e->value); block_del(l,e);; } ok_c++; } sdsdel(key); } cost = time(NULL) - cost; printf("%d find ok and %d error\n",ok_c,err_c); printf("total cost : %d\n",cost); printf("\nBlock research Test...\n"); ok_c = err_c = 0; cost = time(NULL); for (i = 0; i < count; i++) { snprintf(buffer,KEY_MAX,"%d",i); key = sdsnew(buffer); if ((e = block_loup(l,key)) == NULL) err_c++; else { ok_c++; } sdsdel(key); } cost = time(NULL) - cost; printf("%d find ok and %d error\n",ok_c,err_c); printf("total cost : %d\n",cost); sleep(10); block_destroy(l); return(0); }
int main(int argc, char *argv[]) { FILE *fp; Result res; Entry *root; char *path, *locale; int opt; #ifdef SCR_WIDTH ui_scr_width = SCR_WIDTH; #else ui_scr_width = 0; #endif locale = ""; while ((opt = getopt(argc, argv, "hvl:w:b")) != -1) { switch (opt) { case 'b': use_term_colors = !use_term_colors; break; case 'w': ui_scr_width = atoi(optarg); if (ui_scr_width < 0) { fprintf(stderr, "WARN: Wrong width value, fixed-column is off\n"); fprintf(stderr, "Press enter to continue.\n"); fgetc(stdin); ui_scr_width = 0; } break; case 'l': locale = optarg; break; case 'v': version(); break; case 'h': default: usage(argv[0]); break; } } fp = NULL; if (setlocale(LC_ALL, locale) == NULL) { fprintf(stderr, "WARN: Couldn't change LC_ALL to '%s'\n", locale); fprintf(stderr, "Press enter to continue.\n"); fgetc(stdin); } if (optind < argc) { fp = fopen(argv[optind], "r"); if (fp == NULL) { perror("Can't open your file"); exit(1); } path = argv[optind]; } #ifdef DEFAULT_FILE else { fp = fopen(DEFAULT_FILE, "r"); path = DEFAULT_FILE; } #endif UI_File.path = NULL; if (fp) { res = data_load(fp); UI_File.loaded = true; UI_File.path = realpath(path, NULL); if (!UI_File.path) { perror("Couldn't resolve path"); exit(3); } fclose(fp); } else { res = entry_new(32); UI_File.loaded = false; } if (!res.success) { fwprintf(stderr, L"ERROR: %S.\n", res.msg); perror("Unix error"); exit(2); } ui_start(); root = (Entry *)res.data; if (!fp) root->length = 0; res = ui_set_root(root); if (!res.success) { fwprintf(stderr, L"ERROR: %S.\n", res.msg); perror("Unix error"); exit(3); } ui_refresh(); ui_mainloop(); ui_stop(); res = ui_get_root(); if (!res.success) { fwprintf(stderr, L"ERROR: %S.\n", res.msg); perror("Unix error"); exit(4); } data_unload((Entry *)res.data); free(UI_File.path); return 0; }