/** * cellregion_extent: * @cr: #GnmCellRegion * @extent: #GnmRange * * Find the min and max col/row with cell content **/ static void cellregion_extent (GnmCellRegion const *cr, GnmRange *extent) { if (NULL != cr->cell_content) { range_init (extent, -1, -1, -1, -1); g_hash_table_foreach (cr->cell_content, (GHFunc)cb_cellregion_extent, extent); } else range_init (extent, 0, 0, 0, 0); }
/* * Finish the current sequence due to disconnect. * See mdc_import_event() */ void seq_client_flush(struct lu_client_seq *seq) { wait_queue_t link; LASSERT(seq != NULL); init_waitqueue_entry_current(&link); mutex_lock(&seq->lcs_mutex); while (seq->lcs_update) { add_wait_queue(&seq->lcs_waitq, &link); set_current_state(TASK_UNINTERRUPTIBLE); mutex_unlock(&seq->lcs_mutex); waitq_wait(&link, TASK_UNINTERRUPTIBLE); mutex_lock(&seq->lcs_mutex); remove_wait_queue(&seq->lcs_waitq, &link); set_current_state(TASK_RUNNING); } fid_zero(&seq->lcs_fid); /** * this id shld not be used for seq range allocation. * set to -1 for dgb check. */ seq->lcs_space.lsr_index = -1; range_init(&seq->lcs_space); mutex_unlock(&seq->lcs_mutex); }
static range_t *range_new() { range_t *range = (range_t*)malloc(sizeof(*range)); range_init(range); range->ref++; return range; }
/* * Finish the current sequence due to disconnect. * See mdc_import_event() */ void seq_client_flush(struct lu_client_seq *seq) { cfs_waitlink_t link; LASSERT(seq != NULL); cfs_waitlink_init(&link); mutex_lock(&seq->lcs_mutex); while (seq->lcs_update) { cfs_waitq_add(&seq->lcs_waitq, &link); cfs_set_current_state(CFS_TASK_UNINT); mutex_unlock(&seq->lcs_mutex); cfs_waitq_wait(&link, CFS_TASK_UNINT); mutex_lock(&seq->lcs_mutex); cfs_waitq_del(&seq->lcs_waitq, &link); cfs_set_current_state(CFS_TASK_RUNNING); } fid_zero(&seq->lcs_fid); /** * this id shld not be used for seq range allocation. * set to -1 for dgb check. */ seq->lcs_space.lsr_index = -1; range_init(&seq->lcs_space); mutex_unlock(&seq->lcs_mutex); }
// creates and returns a range *object by parsing a string // with format "%f:%f:%f" range_t *range_init_from_string(const char *st) { // create a gstring from st GString *gst = g_string_new(st); // split the gstring GPtrArray *tokens = g_string_split(gst, ':'); assert(tokens->len == 3); // parse the values GString *s = g_ptr_array_index(tokens, 0); double start = atof(s->str); g_string_free(s, TRUE); s = g_ptr_array_index(tokens, 1); double stop = atof(s->str); g_string_free(s, TRUE); s = g_ptr_array_index(tokens, 2); double step = atof(s->str); g_string_free(s, TRUE); // free the pointer array (strings have been freed) g_ptr_array_free(tokens, TRUE); // free the gstring g_string_free(gst, TRUE); return range_init(start, stop, step); }
void find_load_segments(ElfObj *eo, Range *seg_offset_range, Range *seg_vaddr_range) { // this should cover everything mapped by the original two phdrs. int load_phdr_count; ElfWS_Phdr **load_phdrs = elfobj_get_phdrs(eo, PT_LOAD, &load_phdr_count); range_init(seg_offset_range); range_init(seg_vaddr_range); int pi; for (pi=0; pi<load_phdr_count; pi++) { ElfWS_Phdr *ph = load_phdrs[pi]; range_grow(seg_offset_range, ph->p_offset, ph->p_filesz); range_grow(seg_vaddr_range, ph->p_vaddr, ph->p_memsz); } free(load_phdrs); }
VALUE rb_range_new(VALUE beg, VALUE end, int exclude_end) { VALUE range = rb_obj_alloc(rb_cRange); range_init(range, beg, end, exclude_end); return range; }
void find_allocated_sections(ElfObj *eo, Range *offset_range, int *first_unallocated_section_idx) { range_init(offset_range); int si; for (si=0; si<eo->ehdr->e_shnum; si++) { ElfWS_Shdr *sh = &eo->shdr[si]; if (file_alloced_bits(sh)) { range_grow(offset_range, sh->sh_offset, sh->sh_size); } } #if DEBUG printf("sec_offset_range.start %08x\n", offset_range->start); printf("sec_offset_range.end %08x\n", offset_range->end); #endif int last_allocated_section_idx = 0; for (si=0; si<eo->ehdr->e_shnum; si++) { ElfWS_Shdr *sh = &eo->shdr[si]; if (sh->sh_type==SHT_NOBITS) { // nothing to move around; doesn't matter where these end up. continue; } bool in_alloc_region = ((sh->sh_offset >= offset_range->start) && (sh->sh_offset+sh->sh_size <= offset_range->end)); bool is_allocated = file_alloced_bits(sh); if (in_alloc_region != is_allocated) { assert(false); } if (is_allocated) { last_allocated_section_idx = si; } } // Now slurp in section 0: // the Ehdr, Phdr, and the mystery garbage stuck before section 1. // We don't want to move that. offset_range->start = 0; int bss_idx = elfobj_find_section_index_by_name(eo, ".bss"); if (bss_idx == last_allocated_section_idx+1) { // don't shift .bss. It'll confuse something. last_allocated_section_idx = bss_idx; } if (first_unallocated_section_idx != NULL) { *first_unallocated_section_idx = last_allocated_section_idx+1; } }
range elf_section_headers(void* elf) { range r; range_init(&r, (char*)elf + ELF_GET(elf, elf, ehdr, e_shoff), ELF_GET(elf, elf, ehdr, e_shnum), ELF_GET(elf, elf, ehdr, e_shentsize)); return r; }
range elf_program_headers(void* elf) { range r; range_init(&r, (char*)elf + ELF_GET(elf, elf, ehdr, e_phoff), ELF_GET(elf, elf, ehdr, e_phnum), ELF_GET(elf, elf, ehdr, e_phentsize)); return r; }
static VALUE range_initialize(int argc, VALUE *argv, VALUE range) { VALUE beg, end, flags; rb_scan_args(argc, argv, "21", &beg, &end, &flags); range_modify(range); range_init(range, beg, end, RBOOL(RTEST(flags))); return Qnil; }
mrb_value mrb_range_initialize(mrb_state *mrb, mrb_value range) { mrb_value beg, end; mrb_value flags; mrb_get_args(mrb, "ooo", &beg, &end, &flags); /* Ranges are immutable, so that they should be initialized only once. */ range_init(mrb, range, beg, end, mrb_test(flags)); return range; }
static VALUE range_initialize(VALUE range, SEL sel ,int argc, VALUE *argv) { VALUE beg, end, flags; rb_scan_args(argc, argv, "21", &beg, &end, &flags); /* Ranges are immutable, so that they should be initialized only once. */ if (RANGE_EXCL(range) != Qnil) { rb_name_error(rb_intern("initialize"), "`initialize' called twice"); } range_init(range, beg, end, RTEST(flags)); return Qnil; }
mrb_value mrb_range_initialize(mrb_state *mrb, mrb_value range) { mrb_value beg, end; mrb_bool exclusive; int n; n = mrb_get_args(mrb, "oo|b", &beg, &end, &exclusive); if (n != 3) { exclusive = FALSE; } /* Ranges are immutable, so that they should be initialized only once. */ range_init(mrb, range, beg, end, exclusive); return range; }
int main(int argc, char **argv) { char data[] = "We have been up all night, my friends and I, beneath mosque lamps whose brass cupolas are bright as our souls, because like them they were illuminated by the internal glow of electric hearts. And trampling underfoot our native sloth on opulent Persian carpets, we have been discussing right up to the limits of logic and scrawling the paper with demented writing. Our hearts were filled with an immense pride at feeling ourselves standing quite alone, like lighthouses or like the sentinels in an outpost, facing the army of enemy stars encamped in their celestial bivouacs. Alone with the engineers in the infernal stokeholes of great ships, alone with the black spirits which rage in the belly of rogue locomotives, alone with the drunkards beating their wings against the walls. Then we were suddenly distracted by the rumbling of huge double decker trams that went leaping by, streaked with light like the villages celebrating their festivals, which the Po in flood suddenly knocks down and uproots, and, in the rapids and eddies of a deluge, drags down to the sea. Then the silence increased. As we listened to the last faint prayer of the old canal and the crumbling of the bones of the moribund palaces with their green growth of beard, suddenly the hungry automobiles roared beneath our windows."; Ngram *n2 = malloc(sizeof(Ngram)); ngram_init(n2, (unsigned char *) data, strlen(data), 2); Ngram *n3 = malloc(sizeof(Ngram)); ngram_init(n3, (unsigned char *) data, strlen(data), 3); Plugin *plugins[] = {(Plugin *)n2, (Plugin *)n3, NULL}; Range *range = malloc(sizeof(Range)); range_init(range, (unsigned char *) data, strlen(data), plugins); range->plugin.set_width((Plugin *)range, strlen(data)); print(n2); print(n3); return 0; }
/* 15.2.14.4.15(x) */ static mrb_value range_initialize_copy(mrb_state *mrb, mrb_value copy) { mrb_value src; struct RRange *r; mrb_get_args(mrb, "o", &src); if (mrb_obj_equal(mrb, copy, src)) return copy; if (!mrb_obj_is_instance_of(mrb, src, mrb_obj_class(mrb, copy))) { mrb_raise(mrb, E_TYPE_ERROR, "wrong argument class"); } r = mrb_range_ptr(src); range_init(mrb, copy, r->edges->beg, r->edges->end, r->excl); return copy; }
bool update_medoids(int concurrency, int K, leveldb::DB* db, leveldb::DB* work_db, std::vector<GDELTMini>& val_centroids, std::vector<std::string>& key_centroids, const vuad& distances, const vuai& cluster_sizes) { std::vector<KV> thread_best(concurrency); std::vector<double> thread_best_dist(concurrency); bool changed = false; for (int cluster = 0; cluster < K; ++cluster) { double min_dist = distances[cluster]->load(); auto current_key = get_centroid_prefix(cluster, K); auto next_key = get_centroid_prefix(cluster + 1, K); for (auto& d : thread_best_dist) d = min_dist; auto parvec_i = range_uniform(current_key, next_key, concurrency, work_db, cluster_sizes[cluster]->load()); auto parvec_j = range_init(current_key, next_key, concurrency, work_db); parallel_ifor(concurrency, update_medoids_serial, std::ref(parvec_i), std::ref(parvec_j), std::ref(thread_best), std::ref(thread_best_dist), db); auto min = std::distance(thread_best_dist.begin(), std::min_element(thread_best_dist.begin(), thread_best_dist.end())); if (thread_best_dist[min] < min_dist) { key_centroids[cluster] = thread_best[min].first; val_centroids[cluster] = thread_best[min].second; } if (true || (cluster + 1) % (K / 100) == 0) { std::cout << " Cluster update " << (cluster + 1.0) * 100.0 / K << "% done" << std::endl; } } return changed; }
/** * gnm_ft_new: * * Create a new 'empty' GnmFT * * Return value: the new GnmFT **/ static GnmFT * gnm_ft_new (void) { GnmFT *ft; ft = g_new0 (GnmFT, 1); ft->filename = NULL; ft->author = g_strdup (go_get_real_name ()); ft->name = g_strdup (N_("Name")); ft->description = g_strdup (""); ft->category = NULL; ft->members = NULL; ft->number = TRUE; ft->border = TRUE; ft->font = TRUE; ft->patterns = TRUE; ft->alignment = TRUE; ft->edges.left = TRUE; ft->edges.right = TRUE; ft->edges.top = TRUE; ft->edges.bottom = TRUE; ft->table = g_hash_table_new_full ((GHashFunc)gnm_cellpos_hash, (GEqualFunc)gnm_cellpos_equal, (GDestroyNotify)g_free, (GDestroyNotify)gnm_style_unref); ft->invalidate_hash = TRUE; range_init (&ft->dimension, 0,0,0,0); return ft; }
static void cb_dialog_ok_clicked (SortFlowState *state) { GnmSortData *data, *data_copy; GnmSortClause *array, *this_array_item; int item = 0; GtkTreeIter iter; gboolean descending, case_sensitive, sort_by_value, move_format; gint number; gint base; char const *text; array = g_new (GnmSortClause, state->sort_items); this_array_item = array; base = (state->is_cols ? state->sel->v_range.cell.a.col : state->sel->v_range.cell.a.row); while (gtk_tree_model_iter_nth_child (GTK_TREE_MODEL (state->model), &iter, NULL, item)) { gtk_tree_model_get (GTK_TREE_MODEL (state->model), &iter, ITEM_DESCENDING,&descending, ITEM_CASE_SENSITIVE, &case_sensitive, ITEM_SORT_BY_VALUE, &sort_by_value, ITEM_MOVE_FORMAT, &move_format, ITEM_NUMBER, &number, -1); item++; this_array_item->offset = number - base; this_array_item->asc = !!descending; this_array_item->cs = case_sensitive; this_array_item->val = sort_by_value; this_array_item++; } data = g_new (GnmSortData, 1); data->sheet = state->sel->v_range.cell.a.sheet; data->range = g_new (GnmRange, 1); data->range = range_init (data->range, state->sel->v_range.cell.a.col + ((state->header && !state->is_cols) ? 1 : 0), state->sel->v_range.cell.a.row + ((state->header && state->is_cols) ? 1 : 0), state->sel->v_range.cell.b.col, state->sel->v_range.cell.b.row); data->num_clause = state->sort_items; data->clauses = array; data->top = state->is_cols; data->retain_formats = gtk_toggle_button_get_active ( GTK_TOGGLE_BUTTON (state->retain_format_check)); data->locale = go_locale_sel_get_locale (state->locale_selector); data_copy = gnm_sort_data_copy (data); text = gnm_expr_entry_get_text (state->range_entry); gnm_sheet_add_sort_setup (data->sheet, g_strdup((text != NULL && text[0] != '\0') ? text : "Other"), data_copy); cmd_sort (WORKBOOK_CONTROL (state->wbcg), data); gtk_widget_destroy (state->dialog); return; }
static int seq_client_rpc(struct lu_client_seq *seq, struct lu_seq_range *output, __u32 opc, const char *opcname) { struct obd_export *exp = seq->lcs_exp; struct ptlrpc_request *req; struct lu_seq_range *out, *in; __u32 *op; unsigned int debug_mask; int rc; ENTRY; LASSERT(exp != NULL && !IS_ERR(exp)); req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_SEQ_QUERY, LUSTRE_MDS_VERSION, SEQ_QUERY); if (req == NULL) RETURN(-ENOMEM); /* Init operation code */ op = req_capsule_client_get(&req->rq_pill, &RMF_SEQ_OPC); *op = opc; /* Zero out input range, this is not recovery yet. */ in = req_capsule_client_get(&req->rq_pill, &RMF_SEQ_RANGE); range_init(in); ptlrpc_request_set_replen(req); in->lsr_index = seq->lcs_space.lsr_index; if (seq->lcs_type == LUSTRE_SEQ_METADATA) fld_range_set_mdt(in); else fld_range_set_ost(in); if (opc == SEQ_ALLOC_SUPER) { req->rq_request_portal = SEQ_CONTROLLER_PORTAL; req->rq_reply_portal = MDC_REPLY_PORTAL; /* During allocating super sequence for data object, * the current thread might hold the export of MDT0(MDT0 * precreating objects on this OST), and it will send the * request to MDT0 here, so we can not keep resending the * request here, otherwise if MDT0 is failed(umounted), * it can not release the export of MDT0 */ if (seq->lcs_type == LUSTRE_SEQ_DATA) req->rq_no_delay = req->rq_no_resend = 1; debug_mask = D_CONSOLE; } else { if (seq->lcs_type == LUSTRE_SEQ_METADATA) { req->rq_reply_portal = MDC_REPLY_PORTAL; req->rq_request_portal = SEQ_METADATA_PORTAL; } else { req->rq_reply_portal = OSC_REPLY_PORTAL; req->rq_request_portal = SEQ_DATA_PORTAL; } debug_mask = D_INFO; } ptlrpc_at_set_req_timeout(req); if (opc != SEQ_ALLOC_SUPER && seq->lcs_type == LUSTRE_SEQ_METADATA) mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); rc = ptlrpc_queue_wait(req); if (opc != SEQ_ALLOC_SUPER && seq->lcs_type == LUSTRE_SEQ_METADATA) mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); if (rc) GOTO(out_req, rc); out = req_capsule_server_get(&req->rq_pill, &RMF_SEQ_RANGE); *output = *out; if (!range_is_sane(output)) { CERROR("%s: Invalid range received from server: " DRANGE"\n", seq->lcs_name, PRANGE(output)); GOTO(out_req, rc = -EINVAL); } if (range_is_exhausted(output)) { CERROR("%s: Range received from server is exhausted: " DRANGE"]\n", seq->lcs_name, PRANGE(output)); GOTO(out_req, rc = -EINVAL); } CDEBUG_LIMIT(debug_mask, "%s: Allocated %s-sequence "DRANGE"]\n", seq->lcs_name, opcname, PRANGE(output)); EXIT; out_req: ptlrpc_req_finished(req); return rc; }
G_MODULE_EXPORT void paradox_file_open (GOFileOpener const *fo, GOIOContext *io_context, WorkbookView *wb_view, GsfInput *input) { Workbook *wb; pxdoc_t *pxdoc; pxhead_t *pxh; pxfield_t *pxf; char *data; char *name; Sheet *sheet; GnmCell *cell; GnmValue *val = NULL; GOErrorInfo *open_error = NULL; guint row, i, j, offset; #ifdef PX_MEMORY_DEBUGGING PX_mp_init (); #endif #ifdef PX_MEMORY_DEBUGGING pxdoc = PX_new2 (gn_errorhandler, PX_mp_malloc, PX_mp_realloc, PX_mp_free); #else pxdoc = PX_new2 (gn_errorhandler, gn_malloc, gn_realloc, gn_free); #endif if (PX_open_gsf (pxdoc, input) < 0) { go_io_error_info_set (io_context, go_error_info_new_str_with_details ( _("Error while opening Paradox file."), open_error)); return; } pxh = pxdoc->px_head; PX_set_targetencoding (pxdoc, "UTF-8"); wb = wb_view_get_workbook (wb_view); name = workbook_sheet_get_free_name (wb, pxh->px_tablename, FALSE, TRUE); sheet = sheet_new (wb, name, 256, 65536); g_free (name); workbook_sheet_attach (wb, sheet); pxf = pxh->px_fields; for (i = 0 ; i < (guint) pxh->px_numfields; i++) { char str[30], *str2; char ctypes[26] = {'?', 'A', 'D', 'S', 'I', '$', 'N', '?', '?', 'L', '?', '?', 'M', 'B', 'F', 'O', 'G', '?', '?', '?', 'T', '@', '+', '#', 'Y', }; cell = sheet_cell_fetch (sheet, i, 0); if (pxf->px_ftype == pxfBCD) snprintf (str, 30, "%s,%c,%d", pxf->px_fname, ctypes[(int)pxf->px_ftype], pxf->px_fdc); else snprintf (str, 30, "%s,%c,%d", pxf->px_fname, ctypes[(int)pxf->px_ftype], pxf->px_flen); #if PXLIB_MAJOR_VERSION == 0 && (PXLIB_MINOR_VERION < 3 || (PXLIB_MAJOR_VERSION == 3 && PXLIB_MICRO_VERSION == 0)) /* Convert the field names to utf-8. This is actually in pxlib * responsibility, but hasn't been implemented yet. For the mean time * we *misuse* PX_get_data_alpha() */ PX_get_data_alpha (pxdoc, str, strlen (str), &str2); gnm_cell_set_text (cell, str2); pxdoc->free (pxdoc, str2); #else gnm_cell_set_text (cell, str); #endif pxf++; } { GnmRange r; GnmStyle *bold = gnm_style_new (); gnm_style_set_font_bold (bold, TRUE); sheet_style_apply_range (sheet, range_init (&r, 0, 0, pxh->px_numfields-1, 0), bold); } if ((data = (char *) pxdoc->malloc (pxdoc, pxh->px_recordsize, _("Could not allocate memory for record."))) == NULL) { go_io_error_info_set (io_context, go_error_info_new_str_with_details ( _("Error while opening Paradox file."), open_error)); return; } row = 1; for (j = 0; j < (guint)pxh->px_numrecords; j++) { pxdatablockinfo_t pxdbinfo; int isdeleted = 0; if (NULL != PX_get_record2 (pxdoc, j, data, &isdeleted, &pxdbinfo)) { offset = 0; pxf = pxh->px_fields; for (i = 0; i < (guint) pxh->px_numfields ; i++) { cell = sheet_cell_fetch (sheet, i, row); val = NULL; switch (pxf->px_ftype) { case pxfAlpha: { char *value; if (0 < PX_get_data_alpha (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_string_nocopy (value); /* value_set_fmt (val, field->fmt); */ } break; } case pxfShort: { short int value; if (0 < PX_get_data_short (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_int (value); } break; } case pxfAutoInc: case pxfLong: { long value; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_int (value); } break; } case pxfCurrency: case pxfNumber: { double value; if (0 < PX_get_data_double (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_float (value); if (pxf->px_ftype == pxfCurrency) value_set_fmt (val, go_format_default_money ()); } break; } case pxfTimestamp: { double value; if (0 < PX_get_data_double (pxdoc, &data[offset], pxf->px_flen, &value)) { value = value / 86400000.0; /* 693594 = number of days up to 31.12.1899 */ value -= 693594; val = value_new_float (value); value_set_fmt (val, go_format_default_date_time ()); } break; } case pxfLogical: { char value; if (0 < PX_get_data_byte (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_bool (value ? TRUE : FALSE); } break; } case pxfDate: { long value; int year, month, day; GDate *date; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { PX_SdnToGregorian (value+1721425, &year, &month, &day); date = g_date_new_dmy (day, month, year); val = value_new_int (go_date_g_to_serial (date, NULL)); value_set_fmt (val, go_format_default_date ()); g_date_free (date); } break; } case pxfTime: { long value; if (0 < PX_get_data_long (pxdoc, &data[offset], pxf->px_flen, &value)) { val = value_new_float (value/86400000.0); value_set_fmt (val, go_format_default_time ()); } break; } case pxfBCD: { char *value; if (0 < PX_get_data_bcd (pxdoc, &data[offset], pxf->px_fdc, &value)) { val = value_new_string_nocopy (value); } break; } case pxfMemoBLOb: { char *value; int size, mod_nr; if (0 < PX_get_data_blob (pxdoc, &data[offset], pxf->px_flen, &mod_nr, &size, &value)) { val = value_new_string_nocopy (value); } break; } default: val = value_new_string_nocopy ( g_strdup_printf (_("Field type %d is not supported."), pxf->px_ftype)); } if (val) gnm_cell_set_value (cell, val); offset += pxf->px_flen; pxf++; } if (pxh->px_filetype == pxfFileTypPrimIndex) { short int value; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } offset += 2; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } offset += 2; cell = sheet_cell_fetch (sheet, i++, row); if (0 < PX_get_data_short (pxdoc, &data[offset], 2, &value)) { val = value_new_int (value); gnm_cell_set_value (cell, val); } cell = sheet_cell_fetch (sheet, i++, row); val = value_new_int (pxdbinfo.number); gnm_cell_set_value (cell, val); } } row++; } pxdoc->free (pxdoc, data); PX_close (pxdoc); PX_delete (pxdoc); sheet_flag_recompute_spans (sheet); }
static int seq_client_rpc(struct lu_client_seq *seq, struct lu_seq_range *output, __u32 opc, const char *opcname) { struct obd_export *exp = seq->lcs_exp; struct ptlrpc_request *req; struct lu_seq_range *out, *in; __u32 *op; int rc; ENTRY; req = ptlrpc_request_alloc_pack(class_exp2cliimp(exp), &RQF_SEQ_QUERY, LUSTRE_MDS_VERSION, SEQ_QUERY); if (req == NULL) RETURN(-ENOMEM); /* Init operation code */ op = req_capsule_client_get(&req->rq_pill, &RMF_SEQ_OPC); *op = opc; /* Zero out input range, this is not recovery yet. */ in = req_capsule_client_get(&req->rq_pill, &RMF_SEQ_RANGE); range_init(in); ptlrpc_request_set_replen(req); if (seq->lcs_type == LUSTRE_SEQ_METADATA) { req->rq_request_portal = SEQ_METADATA_PORTAL; in->lsr_flags = LU_SEQ_RANGE_MDT; } else { LASSERTF(seq->lcs_type == LUSTRE_SEQ_DATA, "unknown lcs_type %u\n", seq->lcs_type); req->rq_request_portal = SEQ_DATA_PORTAL; in->lsr_flags = LU_SEQ_RANGE_OST; } if (opc == SEQ_ALLOC_SUPER) { /* Update index field of *in, it is required for * FLD update on super sequence allocator node. */ in->lsr_index = seq->lcs_space.lsr_index; req->rq_request_portal = SEQ_CONTROLLER_PORTAL; } else { LASSERTF(opc == SEQ_ALLOC_META, "unknown opcode %u\n, opc", opc); } ptlrpc_at_set_req_timeout(req); mdc_get_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); rc = ptlrpc_queue_wait(req); mdc_put_rpc_lock(exp->exp_obd->u.cli.cl_rpc_lock, NULL); if (rc) GOTO(out_req, rc); out = req_capsule_server_get(&req->rq_pill, &RMF_SEQ_RANGE); *output = *out; if (!range_is_sane(output)) { CERROR("%s: Invalid range received from server: " DRANGE"\n", seq->lcs_name, PRANGE(output)); GOTO(out_req, rc = -EINVAL); } if (range_is_exhausted(output)) { CERROR("%s: Range received from server is exhausted: " DRANGE"]\n", seq->lcs_name, PRANGE(output)); GOTO(out_req, rc = -EINVAL); } CDEBUG(D_INFO, "%s: Allocated %s-sequence "DRANGE"]\n", seq->lcs_name, opcname, PRANGE(output)); EXIT; out_req: ptlrpc_req_finished(req); return rc; }
static gboolean item_grid_draw_region (GocItem const *item, cairo_t *cr, double x_0, double y_0, double x_1, double y_1) { GocCanvas *canvas = item->canvas; double scale = canvas->pixels_per_unit; gint64 x0 = x_0 * scale, y0 = y_0 * scale, x1 = x_1 * scale, y1 = y_1 * scale; gint width = x1 - x0; gint height = y1 - y0; GnmPane *pane = GNM_PANE (canvas); Sheet const *sheet = scg_sheet (pane->simple.scg); WBCGtk *wbcg = scg_wbcg (pane->simple.scg); GnmCell const * const edit_cell = wbcg->editing_cell; GnmItemGrid *ig = GNM_ITEM_GRID (item); ColRowInfo const *ri = NULL, *next_ri = NULL; int const dir = sheet->text_is_rtl ? -1 : 1; SheetView const *sv = scg_view (ig->scg); WorkbookView *wbv = sv_wbv (sv); gboolean show_function_cell_markers = wbv->show_function_cell_markers; gboolean show_extension_markers = wbv->show_extension_markers; /* we use the selected background color from an entry for selected cells */ GtkWidget *entry = gtk_entry_new (); GtkStyleContext *ctxt = gtk_widget_get_style_context (entry); /* To ensure that far and near borders get drawn we pretend to draw +-2 * pixels around the target area which would include the surrounding * borders if necessary */ /* TODO : there is an opportunity to speed up the redraw loop by only * painting the borders of the edges and not the content. * However, that feels like more hassle that it is worth. Look into this someday. */ int x; gint64 y, start_x, offset; int col, row, n, start_col, end_col; int start_row = gnm_pane_find_row (pane, y0-2, &y); int end_row = gnm_pane_find_row (pane, y1+2, NULL); gint64 const start_y = y - canvas->scroll_y1 * scale; GnmStyleRow sr, next_sr; GnmStyle const **styles; GnmBorder const **borders, **prev_vert; GnmBorder const *none = sheet->hide_grid ? NULL : gnm_style_border_none (); GnmRange view; GSList *merged_active, *merged_active_seen, *merged_used, *merged_unused, *ptr, **lag; int *colwidths = NULL; gboolean const draw_selection = ig->scg->selected_objects == NULL && wbcg->new_object == NULL; start_col = gnm_pane_find_col (pane, x0-2, &start_x); end_col = gnm_pane_find_col (pane, x1+2, NULL); g_return_val_if_fail (start_col <= end_col, TRUE); #if 0 g_printerr ("%s:", cell_coord_name (start_col, start_row)); g_printerr ("%s <= %ld vs ???", cell_coord_name(end_col, end_row), (long)y); g_printerr (" [%s]\n", cell_coord_name (ig->bound.end.col, ig->bound.end.row)); #endif /* clip to bounds */ if (end_col > ig->bound.end.col) end_col = ig->bound.end.col; if (end_row > ig->bound.end.row) end_row = ig->bound.end.row; /* Skip any hidden cols/rows at the start */ for (; start_col <= end_col ; ++start_col) { ri = sheet_col_get_info (sheet, start_col); if (ri->visible) break; } for (; start_row <= end_row ; ++start_row) { ri = sheet_row_get_info (sheet, start_row); if (ri->visible) break; } /* if everything is hidden no need to draw */ if (end_col < ig->bound.start.col || start_col > ig->bound.end.col || end_row < ig->bound.start.row || start_row > ig->bound.end.row) return TRUE; /* Respan all rows that need it. */ for (row = start_row; row <= end_row; row++) { ColRowInfo const *ri = sheet_row_get_info (sheet, row); if (ri->visible && ri->needs_respan) row_calc_spans ((ColRowInfo *)ri, row, sheet); } sheet_style_update_grid_color (sheet); /* Fill entire region with default background (even past far edge) */ cairo_save (cr); if (canvas->direction == GOC_DIRECTION_LTR) gtk_render_background (goc_item_get_style_context (item), cr, x0 - canvas->scroll_x1 * scale, y0 - canvas->scroll_y1 * scale, width, height); else gtk_render_background (goc_item_get_style_context (item), cr, canvas->width - x0 + canvas->scroll_x1 * scale - width, y0 - canvas->scroll_y1 * scale, width, height); cairo_restore (cr); /* Get ordered list of merged regions */ merged_active = merged_active_seen = merged_used = NULL; merged_unused = gnm_sheet_merge_get_overlap (sheet, range_init (&view, start_col, start_row, end_col, end_row)); /* * allocate a single blob of memory for all 8 arrays of pointers. * - 6 arrays of n GnmBorder const * * - 2 arrays of n GnmStyle const * * * then alias the arrays for easy access so that array [col] is valid * for all elements start_col-1 .. end_col+1 inclusive. * Note that this means that in some cases array [-1] is legal. */ n = end_col - start_col + 3; /* 1 before, 1 after, 1 fencepost */ style_row_init (&prev_vert, &sr, &next_sr, start_col, end_col, g_alloca (n * 8 * sizeof (gpointer)), sheet->hide_grid); /* load up the styles for the first row */ next_sr.row = sr.row = row = start_row; sheet_style_get_row (sheet, &sr); /* Collect the column widths */ colwidths = g_alloca (n * sizeof (int)); colwidths -= start_col; for (col = start_col; col <= end_col; col++) { ColRowInfo const *ci = sheet_col_get_info (sheet, col); colwidths[col] = ci->visible ? ci->size_pixels : -1; } goc_canvas_c2w (canvas, start_x / scale, 0, &x, NULL); start_x = x; for (y = start_y; row <= end_row; row = sr.row = next_sr.row, ri = next_ri) { /* Restore the set of ranges seen, but still active. * Reinverting list to maintain the original order */ g_return_val_if_fail (merged_active == NULL, TRUE); #if DEBUG_SELECTION_PAINT g_printerr ("row = %d (startcol = %d)\n", row, start_col); #endif while (merged_active_seen != NULL) { GSList *tmp = merged_active_seen->next; merged_active_seen->next = merged_active; merged_active = merged_active_seen; merged_active_seen = tmp; MERGE_DEBUG (merged_active->data, " : seen -> active\n"); } /* find the next visible row */ while (1) { ++next_sr.row; if (next_sr.row <= end_row) { next_ri = sheet_row_get_info (sheet, next_sr.row); if (next_ri->visible) { sheet_style_get_row (sheet, &next_sr); break; } } else { for (col = start_col ; col <= end_col; ++col) next_sr.vertical [col] = next_sr.bottom [col] = none; break; } } /* look for merges that start on this row, on the first painted row * also check for merges that start above. */ view.start.row = row; lag = &merged_unused; for (ptr = merged_unused; ptr != NULL; ) { GnmRange * const r = ptr->data; if (r->start.row <= row) { GSList *tmp = ptr; ptr = *lag = tmp->next; if (r->end.row < row) { tmp->next = merged_used; merged_used = tmp; MERGE_DEBUG (r, " : unused -> used\n"); } else { ColRowInfo const *ci = sheet_col_get_info (sheet, r->start.col); g_slist_free_1 (tmp); merged_active = g_slist_insert_sorted (merged_active, r, (GCompareFunc)merged_col_cmp); MERGE_DEBUG (r, " : unused -> active\n"); if (ci->visible) item_grid_draw_merged_range (cr, ig, start_x, y, &view, r, draw_selection, ctxt); } } else { lag = &(ptr->next); ptr = ptr->next; } } for (col = start_col, x = start_x; col <= end_col ; col++) { GnmStyle const *style; CellSpanInfo const *span; ColRowInfo const *ci = sheet_col_get_info (sheet, col); #if DEBUG_SELECTION_PAINT g_printerr ("col [%d] = %d\n", col, x); #endif if (!ci->visible) { if (merged_active != NULL) { GnmRange const *r = merged_active->data; if (r->end.col == col) { ptr = merged_active; merged_active = merged_active->next; if (r->end.row <= row) { ptr->next = merged_used; merged_used = ptr; MERGE_DEBUG (r, " : active2 -> used\n"); } else { ptr->next = merged_active_seen; merged_active_seen = ptr; MERGE_DEBUG (r, " : active2 -> seen\n"); } } } continue; } /* Skip any merged regions */ if (merged_active != NULL) { GnmRange const *r = merged_active->data; if (r->start.col <= col) { gboolean clear_top, clear_bottom = FALSE; int i, first = r->start.col; int last = r->end.col; ptr = merged_active; merged_active = merged_active->next; if (r->end.row <= row) { ptr->next = merged_used; merged_used = ptr; MERGE_DEBUG (r, " : active -> used\n"); /* in case something managed the bottom of a merge */ if (r->end.row < row) goto plain_draw; } else { ptr->next = merged_active_seen; merged_active_seen = ptr; MERGE_DEBUG (r, " : active -> seen\n"); if (next_sr.row <= r->end.row) clear_bottom = TRUE; } x += dir * scg_colrow_distance_get ( pane->simple.scg, TRUE, col, last+1); col = last; if (first < start_col) { first = start_col; sr.vertical [first] = NULL; } if (last > end_col) { last = end_col; sr.vertical [last+1] = NULL; } clear_top = (r->start.row != row); /* Clear the borders */ for (i = first ; i <= last ; i++) { if (clear_top) sr.top [i] = NULL; if (clear_bottom) sr.bottom [i] = NULL; if (i > first) sr.vertical [i] = NULL; } continue; } } plain_draw : /* a quick hack to deal with 142267 */ if (dir < 0) x -= ci->size_pixels; style = sr.styles [col]; item_grid_draw_background (cr, ig, style, col, row, x, y, ci->size_pixels, ri->size_pixels, draw_selection, ctxt); /* Is this part of a span? * 1) There are cells allocated in the row * (indicated by ri->spans != NULL) * 2) Look in the rows hash table to see if * there is a span descriptor. */ if (NULL == ri->spans || NULL == (span = row_span_get (ri, col))) { /* If it is being edited pretend it is empty to * avoid problems with long cells' * contents extending past the edge of the edit * box. Ignore blanks too. */ GnmCell const *cell = sheet_cell_get (sheet, col, row); if (!gnm_cell_is_empty (cell) && cell != edit_cell) { if (show_function_cell_markers) draw_function_marker (ig, cell, cr, x, y, ci->size_pixels, ri->size_pixels, dir); cell_draw (cell, cr, x, y, ci->size_pixels, ri->size_pixels, -1, show_extension_markers); } /* Only draw spaning cells after all the backgrounds * that we are going to draw have been drawn. No need * to draw the edit cell, or blanks. */ } else if (edit_cell != span->cell && (col == span->right || col == end_col)) { GnmCell const *cell = span->cell; int const start_span_col = span->left; int const end_span_col = span->right; int real_x = x; ColRowInfo const *cell_col = sheet_col_get_info (sheet, cell->pos.col); int center_offset = cell_col->size_pixels/2; int tmp_width = ci->size_pixels; if (col != cell->pos.col) style = sheet_style_get (sheet, cell->pos.col, row); /* x, y are relative to this cell origin, but the cell * might be using columns to the left (if it is set to right * justify or center justify) compute the pixel difference */ if (dir > 0 && start_span_col != cell->pos.col) center_offset += scg_colrow_distance_get ( pane->simple.scg, TRUE, start_span_col, cell->pos.col); else if (dir < 0 && end_span_col != cell->pos.col) center_offset += scg_colrow_distance_get ( pane->simple.scg, TRUE, cell->pos.col, end_span_col); if (start_span_col != col) { offset = scg_colrow_distance_get ( pane->simple.scg, TRUE, start_span_col, col); tmp_width += offset; if (dir > 0) real_x -= offset; sr.vertical [col] = NULL; } if (end_span_col != col) { offset = scg_colrow_distance_get ( pane->simple.scg, TRUE, col+1, end_span_col + 1); tmp_width += offset; if (dir < 0) real_x -= offset; } if (show_function_cell_markers) draw_function_marker (ig, cell, cr, real_x, y, tmp_width, ri->size_pixels, dir); cell_draw (cell, cr, real_x, y, tmp_width, ri->size_pixels, center_offset, show_extension_markers); } else if (col != span->left) sr.vertical [col] = NULL; if (dir > 0) x += ci->size_pixels; } gnm_style_borders_row_draw (prev_vert, &sr, cr, start_x, y, y+ri->size_pixels, colwidths, TRUE, dir); /* In case there were hidden merges that trailed off the end */ while (merged_active != NULL) { GnmRange const *r = merged_active->data; ptr = merged_active; merged_active = merged_active->next; if (r->end.row <= row) { ptr->next = merged_used; merged_used = ptr; MERGE_DEBUG (r, " : active3 -> used\n"); } else { ptr->next = merged_active_seen; merged_active_seen = ptr; MERGE_DEBUG (r, " : active3 -> seen\n"); } } /* roll the pointers */ borders = prev_vert; prev_vert = sr.vertical; sr.vertical = next_sr.vertical; next_sr.vertical = borders; borders = sr.top; sr.top = sr.bottom; sr.bottom = next_sr.top = next_sr.bottom; next_sr.bottom = borders; styles = sr.styles; sr.styles = next_sr.styles; next_sr.styles = styles; y += ri->size_pixels; } if (ig->bound.start.row > 0 && start_y < 1) ig_cairo_draw_bound (ig, cr, start_x, 1, x, 1); if (ig->bound.start.col > 0) { if (canvas->direction == GOC_DIRECTION_RTL && start_x >= goc_canvas_get_width (canvas)) { x = goc_canvas_get_width (canvas); ig_cairo_draw_bound (ig, cr, x, start_y, x, y); } else if (canvas->direction == GOC_DIRECTION_LTR && start_x < 1) ig_cairo_draw_bound (ig, cr, 1, start_y, 1, y); } g_object_ref_sink (entry); g_object_unref (entry); g_slist_free (merged_used); /* merges with bottom in view */ g_slist_free (merged_active_seen); /* merges with bottom the view */ g_slist_free (merged_unused); /* merges in hidden rows */ g_return_val_if_fail (merged_active == NULL, TRUE); return TRUE; }
int main(){ pwm_init(); MSS_GPIO_init(); range_init(); MSS_GPIO_config(MSS_GPIO_31, MSS_GPIO_OUTPUT_MODE); UART_init(&g_uart, COREUARTAPB0_BASE_ADDR, 162, (DATA_8_BITS | NO_PARITY)); uint8_t buff[BUFFER_SIZE]; int offset = 0; size_t received; int joyx, joyy, cx, cy, start, fire; int startDown = 0; int mode = 0; // 0 for manual, 1 for automatic uint8_t tx[100]; int txSize; firing = 0; curr_angle = 0; MSS_GPIO_set_output(MSS_GPIO_31, 0); /*while(1) { wheel2(255); //wheel4(255); //wheel2(-255); //wheel3(255); //wheel4(-255); }*/ while (1) { while (!(received = UART_get_rx(&g_uart, buff+offset, sizeof(buff)-offset))); offset += received; //printf("Received: %d\n\r", received); if (buff[offset-1] == '\0') { // message fully received //printf("%s\n\r", buff); if (6 != sscanf(buff, "%d %d %d %d %d %d", &joyx, &joyy, &cx, &cy, &fire, &start)) { bzero(buff, BUFFER_SIZE); continue; } offset = 0; if (start && !startDown) { mode = !mode; startDown = 1; } if (!start && startDown) startDown = 0; joyx = joyx * .65; joyy = joyy * .65; if (joyx < 0) joyx -= 150; else if (joyx > 0) joyx += 150; if (joyy < 0) joyy -= 150; else if (joyy > 0) joyy += 150; printf("JoyX: %3d, JoyY: %3d, CX: %3d, CY: %3d, Fire: %d, Start: %d\n\r", joyx, joyy, cx, cy, fire, start); wheel1(joyy); wheel2(joyx); wheel3(joyy); wheel4(joyx); moveTurret(cy); if (fire && !firing) { start_gun(); } if (firing && fire_counter <= FIRE_TIME) fire_counter++; if (!fire && firing && fire_counter >= FIRE_TIME) stop_gun(); } else continue; txSize = sprintf(tx, "%d %d", mode, get_range()) + 1; UART_send(&g_uart, tx, txSize); } /*while(1){ set_gun_angle(0); wheel1(-255); }*/ return 0; }
static void html_read_row (htmlNodePtr cur, htmlDocPtr doc, GnmHtmlTableCtxt *tc) { htmlNodePtr ptr; int col = -1; for (ptr = cur->children; ptr != NULL ; ptr = ptr->next) { if (xmlStrEqual (ptr->name, CC2XML ("td")) || xmlStrEqual (ptr->name, CC2XML ("th"))) { GString *buf; xmlBufferPtr a_buf; xmlAttrPtr props; int colspan = 1; int rowspan = 1; GnmCellPos pos; GnmStyle *mstyle; GSList *hrefs = NULL; GnmHLink *lnk = NULL; /* Check whether we need to skip merges from above */ pos.row = tc->row; pos.col = col + 1; while (gnm_sheet_merge_contains_pos (tc->sheet, &pos)) { col++; pos.col++; } /* Do we span across multiple rows or cols? */ props = ptr->properties; while (props) { if (xmlStrEqual (props->name, CC2XML ("colspan")) && props->children) colspan = atoi (CXML2C (props->children->content)); if (xmlStrEqual (props->name, CC2XML ("rowspan")) && props->children) rowspan = atoi (CXML2C (props->children->content)); props = props->next; } if (colspan < 1) colspan = 1; if (rowspan < 1) rowspan = 1; /* Let's figure out the content of the cell */ buf = g_string_new (NULL); a_buf = xmlBufferCreate (); mstyle = gnm_style_new_default (); if (xmlStrEqual (ptr->name, CC2XML ("th"))) gnm_style_set_font_bold (mstyle, TRUE); html_read_content (ptr, buf, mstyle, a_buf, &hrefs, TRUE, doc, tc); if (g_slist_length (hrefs) >= 1 && buf->len > 0) { /* One hyperlink, and text to make it * visible */ char *url; xmlBufferPtr h_buf = xmlBufferCreate (); hrefs = g_slist_reverse (hrefs); htmlNodeDump ( h_buf, doc, (htmlNodePtr)hrefs->data); url = g_strndup ( CXML2C (h_buf->content), h_buf->use); if (strncmp (url, "mailto:", strlen ("mailto:")) == 0) lnk = gnm_hlink_new ( gnm_hlink_email_get_type (), tc->sheet); else lnk = gnm_hlink_new ( gnm_hlink_url_get_type (), tc->sheet); gnm_hlink_set_target (lnk, url); gnm_style_set_hlink (mstyle, lnk); gnm_style_set_font_uline (mstyle, UNDERLINE_SINGLE); gnm_style_set_font_color (mstyle, gnm_color_new_go (GO_COLOR_BLUE)); g_free (url); xmlBufferFree (h_buf); } if (g_slist_length (hrefs) > 1 || buf->len <= 0) { /* Multiple links, * or no text to give hyperlink style, * so put them in a comment */ GSList *l; for (l = hrefs; l != NULL; l = l->next) { htmlNodeDump (a_buf, doc, (htmlNodePtr)l->data); xmlBufferAdd (a_buf, CC2XML ("\n"), -1); } } g_slist_free (hrefs); if (buf->len > 0) { GnmCell *cell = sheet_cell_fetch (tc->sheet, col + 1, tc->row); sheet_style_set_pos (tc->sheet, col + 1, tc->row, mstyle); gnm_cell_set_text (cell, buf->str); } else gnm_style_unref (mstyle); if (a_buf->use > 0) { char *name; name = g_strndup (CXML2C (a_buf->content), a_buf->use); cell_set_comment (tc->sheet, &pos, NULL, name, NULL); g_free (name); } g_string_free (buf, TRUE); xmlBufferFree (a_buf); /* If necessary create the merge */ if (colspan > 1 || rowspan > 1) { GnmRange range; GnmRange *r = ⦥ range_init (r, col + 1, tc->row, col + colspan, tc->row + rowspan - 1); gnm_sheet_merge_add (tc->sheet, r, FALSE, NULL); } col += colspan; } } }
int seq_server_init(struct lu_server_seq *seq, struct dt_device *dev, const char *prefix, enum lu_mgr_type type, struct seq_server_site *ss, const struct lu_env *env) { int rc, is_srv = (type == LUSTRE_SEQ_SERVER); ENTRY; LASSERT(dev != NULL); LASSERT(prefix != NULL); LASSERT(ss != NULL); LASSERT(ss->ss_lu != NULL); seq->lss_cli = NULL; seq->lss_type = type; seq->lss_site = ss; range_init(&seq->lss_space); range_init(&seq->lss_lowater_set); range_init(&seq->lss_hiwater_set); seq->lss_set_width = LUSTRE_SEQ_BATCH_WIDTH; mutex_init(&seq->lss_mutex); seq->lss_width = is_srv ? LUSTRE_SEQ_META_WIDTH : LUSTRE_SEQ_SUPER_WIDTH; snprintf(seq->lss_name, sizeof(seq->lss_name), "%s-%s", (is_srv ? "srv" : "ctl"), prefix); rc = seq_store_init(seq, env, dev); if (rc) GOTO(out, rc); /* Request backing store for saved sequence info. */ rc = seq_store_read(seq, env); if (rc == -ENODATA) { /* Nothing is read, init by default value. */ seq->lss_space = is_srv ? LUSTRE_SEQ_ZERO_RANGE: LUSTRE_SEQ_SPACE_RANGE; LASSERT(ss != NULL); seq->lss_space.lsr_index = ss->ss_node_id; LCONSOLE_INFO("%s: No data found " "on store. Initialize space\n", seq->lss_name); rc = seq_store_update(env, seq, NULL, 0); if (rc) { CERROR("%s: Can't write space data, " "rc %d\n", seq->lss_name, rc); } } else if (rc) { CERROR("%s: Can't read space data, rc %d\n", seq->lss_name, rc); GOTO(out, rc); } if (is_srv) { LASSERT(range_is_sane(&seq->lss_space)); } else { LASSERT(!range_is_zero(&seq->lss_space) && range_is_sane(&seq->lss_space)); } rc = seq_server_proc_init(seq); if (rc) GOTO(out, rc); EXIT; out: if (rc) seq_server_fini(seq, env); return rc; }
static GODataCache * build_cache(void) { Workbook *wb; Sheet *sheet; GODataCache *cache; GnmRange *range; int row, col, numRows = 60, numCols = 5; wb = workbook_new(); sheet = workbook_sheet_add (wb, -1, 1024, 1024); for (row = 0; row < numRows; row++) { for (col = 0; col < numCols; col++) { GnmCell * tempCell = sheet_cell_create(sheet, col, row); GnmValue * tempVal; if (col == 0) { if (row%4 == 0) { tempVal = value_new_string_nocopy((char *)"A"); } else if (row%4 == 1) { tempVal = value_new_string_nocopy((char *)"B"); } else if (row%4 == 2) { tempVal = value_new_string_nocopy((char *)"C"); } else { tempVal = value_new_string_nocopy((char *)"D"); } } else if (col == 1) { tempVal = value_new_int(row); } else if (col == 2) { if (row%5 == 0) { tempVal = value_new_float(14.4); } else if (row%5 == 1) { tempVal = value_new_float(18.8); } else if (row%5 == 2) { tempVal = value_new_float(7.6); } else if (row%5 == 3) { tempVal = value_new_float(3.3); } else { tempVal = value_new_float(11.6); } } else if (col == 3) { tempVal = value_new_int(row % 10); } else if (col == 4) { if (row == 0) { GnmEvalPos *pos = g_new(GnmEvalPos, 1); pos = eval_pos_init(pos, sheet, col, row); tempVal = value_new_error_DIV0(pos); } else if (row == 1) { GnmEvalPos *pos = g_new(GnmEvalPos, 1); pos = eval_pos_init(pos, sheet, col, row); tempVal = value_new_error_NA(pos); } else if (row == 2) { GnmEvalPos *pos = g_new(GnmEvalPos, 1); pos = eval_pos_init(pos, sheet, col, row); tempVal = value_new_error_REF(pos); } else if (row == 3) { tempVal = value_new_bool(TRUE); } else if (row == 4) { tempVal = value_new_bool(FALSE); } else if (row == 5) { tempVal = value_new_empty(); } else { if (row%5 == 1) { tempVal = value_new_string_nocopy((char *)"a"); } else if (row%5 == 2) { tempVal = value_new_string_nocopy((char *)"b"); } else if (row%5 == 3) { tempVal = value_new_string_nocopy((char *)"c"); } else if (row%5 == 4) { tempVal = value_new_string_nocopy((char *)"d"); } else { tempVal = value_new_string_nocopy((char *)"e"); } } } sheet_cell_set_value(tempCell, tempVal); } } cache = g_object_new(GO_DATA_CACHE_TYPE, NULL); range = g_new(GnmRange, 1); range = range_init(range, 0, 0, numCols - 1, numRows - 1); go_data_cache_build_cache(cache, sheet, range); g_object_unref (wb); return cache; }