static void ainfo_data_to_model (arma_info *ainfo, MODEL *pmod) { pmod->ifc = ainfo->ifc; pmod->dfn = ainfo->nc - pmod->ifc; pmod->dfd = pmod->nobs - pmod->dfn; pmod->ncoeff = ainfo->nc; if (arma_has_seasonal(ainfo)) { gretl_model_set_int(pmod, "arma_P", ainfo->P); gretl_model_set_int(pmod, "arma_Q", ainfo->Q); gretl_model_set_int(pmod, "arma_pd", ainfo->pd); } if (ainfo->d > 0 || ainfo->D > 0) { gretl_model_set_int(pmod, "arima_d", ainfo->d); gretl_model_set_int(pmod, "arima_D", ainfo->D); } if (ainfo->nexo > 0) { gretl_model_set_int(pmod, "armax", 1); } if (ainfo->pmask != NULL) { gretl_model_set_string_as_data(pmod, "pmask", gretl_strdup(ainfo->pmask)); } if (ainfo->qmask != NULL) { gretl_model_set_string_as_data(pmod, "qmask", gretl_strdup(ainfo->qmask)); } }
static void wbook_init (wbook *book, const int *list, char *sheetname) { book->version = 0; book->nsheets = 0; book->col_offset = book->row_offset = 0; book->targname = NULL; book->sheetnames = NULL; book->byte_offsets = NULL; book->selected = 0; book->flags = 0; book->xf_list = NULL; book->get_min_offset = NULL; book->data = NULL; if (sheetname != NULL && *sheetname != '\0') { book->targname = gretl_strdup(sheetname); tailstrip(book->targname); } if (list != NULL && list[0] == 3) { if (book->targname == NULL && list[1] > 0) { book->selected = list[1] - 1; } book->col_offset = list[2]; book->row_offset = list[3]; } }
static int gretl_array_copy_content (gretl_array *Acpy, const gretl_array *A, int write_offset) { int i, j, err = 0; for (i=0; i<A->n && !err; i++) { if (A->data[i] != NULL) { j = i + write_offset; if (A->type == GRETL_TYPE_STRINGS) { Acpy->data[j] = gretl_strdup(A->data[i]); } else if (A->type == GRETL_TYPE_MATRICES) { Acpy->data[j] = gretl_matrix_copy(A->data[i]); } else if (A->type == GRETL_TYPE_BUNDLES) { Acpy->data[j] = gretl_bundle_copy(A->data[i], &err); } else { Acpy->data[j] = gretl_list_copy(A->data[i]); } if (Acpy->data[j] == NULL) { err = E_ALLOC; } } } return err; }
char *retrieve_remote_pkg_filename (const char *pkgname, int *err) { char *fname = NULL; char *buf = NULL; *err = retrieve_url(gretlhost, FUNC_FULLNAME, pkgname, NULL, NULL, 0, &buf); if (!*err) { if (buf == NULL) { *err = E_DATA; } else { if (strstr(buf, "not found")) { gretl_errmsg_set(buf); *err = E_DATA; } else { char tmp[64]; sscanf(buf, "%63s", tmp); fname = gretl_strdup(tmp); } free(buf); } } return fname; }
static char *win_special_path (int folder) { TCHAR dpath[MAX_PATH]; LPITEMIDLIST id_list; DWORD result; LPMALLOC allocator; char *ret = NULL; if (SHGetSpecialFolderLocation(NULL, folder | CSIDL_FLAG_CREATE, &id_list) != S_OK) { return NULL; } result = SHGetPathFromIDList(id_list, dpath); if (result) { ret = gretl_strdup(dpath); } if (SHGetMalloc(&allocator) == S_OK) { allocator->lpVtbl->Free(allocator, id_list); allocator->lpVtbl->Release(allocator); } return ret; }
void gretl_push_c_numeric_locale (void) { if (numeric_c_locale_depth == 0) { free(numeric_locale); numeric_locale = gretl_strdup(setlocale(LC_NUMERIC, NULL)); setlocale(LC_NUMERIC, "C"); } numeric_c_locale_depth++; }
char *gretl_getenv (const char *key, int *defined, int *err) { char *test = getenv(key); char *val = NULL; if (test == NULL) { *defined = 0; val = gretl_strdup(""); } else { *defined = 1; val = gretl_strdup(test); } if (val == NULL) { *err = E_ALLOC; } return val; }
static int wsheet_setup (wsheet *sheet, wbook *book, int n) { sheet->name = gretl_strdup(book->sheetnames[n]); if (sheet->name == NULL) { return 1; } sheet->ID = n; sheet->col_offset = book->col_offset; sheet->row_offset = book->row_offset; return 0; }
char *gretl_print_get_chunk_at (PRN *prn, int pos) { int maxpos = prn->blen; char *ret; if (prn == NULL || prn->buf == NULL || pos < 0 || pos > maxpos) { return NULL; } ret = gretl_strdup(prn->buf + pos); return ret; }
char *retrieve_date_string (int t, const DATASET *dset, int *err) { char *ret = NULL; if (t <= 0 || t > dset->n) { *err = E_DATA; } else if (dset->S != NULL) { ret = gretl_strdup(dset->S[t-1]); if (ret == NULL) { *err = E_ALLOC; } } else { char datestr[OBSLEN] = {0}; ntodate(datestr, t - 1, dset); ret = gretl_strdup(datestr); if (ret == NULL) { *err = E_ALLOC; } } return ret; }
char *gretl_print_get_chunk (PRN *prn) { int maxpos = prn->blen; char *ret; if (prn == NULL || prn->buf == NULL || prn->savepos < 0 || prn->savepos > maxpos) { return NULL; } ret = gretl_strdup(prn->buf + prn->savepos); prn->savepos = -1; return ret; }
char *gretl_backtick (const char *arg, int *err) { char *val = NULL; *err = shell_grab(arg, &val); if (!*err && val == NULL) { val = gretl_strdup(""); if (val == NULL) { *err = E_ALLOC; } } return val; }
static void look_up_string_variable (const char *s, parser *p) { char *val = get_string_by_name(s + 1); if (val != NULL) { p->idstr = gretl_strdup(s + 1); if (p->idstr == NULL) { p->err = E_ALLOC; } else { p->uval = val; p->sym = USTR; } } else { undefined_symbol_error(s, p); } }
static int wsheet_setup (wsheet *sheet, wbook *book, int n) { int err = 0; sheet->name = gretl_strdup(book->sheetnames[n]); if (sheet->name == NULL) { err = E_ALLOC; } else { sheet->ID = n; sheet->col_offset = book->col_offset; sheet->row_offset = book->row_offset; } return err; }
static int set_string (gretl_array *A, int i, char *s, int copy) { int err = 0; if (copy) { A->data[i] = gretl_strdup(s); if (A->data[i] == NULL) { err = E_ALLOC; } } else { A->data[i] = s; } return err; }
static void parse_number (parser *p) { char xstr[NUMLEN] = {0}; int gotcol = 0; int i = 0; while (ok_dbl_char(p, xstr, i - 1) && i < NUMLEN - 1) { xstr[i++] = p->ch; if (p->ch == ':') { gotcol = 1; } parser_getc(p); } while (p->ch >= '0' && p->ch <= '9') { /* flush excess numeric characters */ parser_getc(p); } #if LDEBUG fprintf(stderr, "parse_number: xstr = '%s'\n", xstr); #endif if (gotcol) { #if LDEBUG fprintf(stderr, " got colon: obs identifier?\n"); #endif if (p->dset == NULL || p->dset->n == 0) { p->err = E_NODATA; } else if (p->dset->pd == 1) { p->err = E_PDWRONG; } else if (dateton(xstr, p->dset) < 0) { p->err = E_DATA; } else { p->idstr = gretl_strdup(xstr); p->sym = STR; } } else { p->xval = dot_atof(xstr); p->sym = NUM; #if LDEBUG fprintf(stderr, " dot_atof gave %g\n", p->xval); #endif } }
static int add_file_to_list (const char *fname) { int n = nfiles; file_list = realloc(file_list, (n + 1) * sizeof *file_list); if (file_list == NULL) { return 1; } file_list[n] = gretl_strdup(fname); if (file_list[n] == NULL) { return 1; } nfiles++; return 0; }
int buf_to_clipboard (const char *buf) { int err = 0; if (buf == NULL || *buf == '\0') { return 0; } gretl_clipboard_free(); clipboard_buf = gretl_strdup(buf); if (clipboard_buf == NULL) { err = 1; } else { gretl_clipboard_set(GRETL_FORMAT_TXT, 0); } return err; }
int gretl_bundle_set_creator (gretl_bundle *bundle, const char *name) { int err = 0; if (bundle == NULL) { err = E_DATA; } else { free(bundle->creator); if (name == NULL) { bundle->creator = NULL; } else { bundle->creator = gretl_strdup(name); if (bundle->creator == NULL) { err = E_ALLOC; } } } return err; }
void *gretl_array_get_element (gretl_array *A, int i, GretlType *type, int *err) { void *ret = NULL; /* Note that the data returned here are not "deep copied", we just pass the pointer. It's up to geneval.c to decide if a copy has to be made, given that the pointer from here should not be modified. */ if (A == NULL || i < 0 || i >= A->n) { *err = E_DATA; } else { *type = gretl_type_get_singular(A->type); if (A->type == GRETL_TYPE_STRINGS) { if (A->data[i] == NULL) { A->data[i] = gretl_strdup(""); } } else if (A->type == GRETL_TYPE_MATRICES) { if (A->data[i] == NULL) { A->data[i] = gretl_null_matrix_new(); } } else if (A->type == GRETL_TYPE_BUNDLES) { if (A->data[i] == NULL) { A->data[i] = gretl_bundle_new(); } } else { if (A->data[i] == NULL) { A->data[i] = gretl_list_new(0); } } ret = A->data[i]; if (ret == NULL) { *err = E_ALLOC; } } return ret; }
int gretl_bundle_set_note (gretl_bundle *bundle, const char *key, const char *note) { int err = 0; if (bundle == NULL) { err = E_UNKVAR; } else { gpointer p = g_hash_table_lookup(bundle->ht, key); if (p == NULL) { err = E_DATA; } else { bundled_item *item = p; free(item->note); item->note = gretl_strdup(note); } } return err; }
static void look_up_dollar_word (const char *s, parser *p) { if ((p->idnum = dvar_lookup(s)) > 0) { p->sym = DVAR; } else if ((p->idnum = const_lookup(s)) > 0) { if (p->idnum == CONST_SYSINFO) { p->sym = BUNDLE; p->idstr = gretl_strdup("$sysinfo"); p->uval = get_sysinfo_bundle(&p->err); } else { p->sym = CON; } } else if ((p->idnum = mvar_lookup(s)) > 0) { p->sym = MVAR; } else { undefined_symbol_error(s, p); } #if LDEBUG fprintf(stderr, "look_up_dollar_word: '%s' -> %d\n", s, p->idnum); #endif }
void gretl_insert_builtin_string (const char *name, const char *s) { int i, n = sizeof built_ins / sizeof built_ins[0]; for (i=0; i<n; i++) { if (!strcmp(name, built_ins[i].name)) { free(built_ins[i].s); if (s == NULL) { built_ins[i].s = NULL; } else { int m = strlen(s); if (s[m-1] == SLASH) { /* drop trailing dir separator for paths */ built_ins[i].s = gretl_strndup(s, m - 1); } else { built_ins[i].s = gretl_strdup(s); } } return; } } }
int substitute_named_strings (char *line, int *subst) { char sname[VNAMELEN]; int len = strlen(line); char *sub, *tmp, *s = line; int bs = 0, in_format = 0; int freeit; int i, n, m, err = 0; if (*s == '#' || strchr(s, '@') == NULL) { return 0; } if (!strncmp(line, "printf", 6) || !strncmp(line, "sprintf", 7)) { s = strchr(s, '"'); if (s == NULL) { /* no format string */ return E_PARSE; } s++; in_format = 1; } i = s - line; while (*s && !err) { if (in_format) { if (*s == '"' && (bs % 2 == 0)) { /* reached end of (s)printf format string */ in_format = 0; } if (*s == '\\') { bs++; } else { bs = 0; } } if (*s == '@') { n = gretl_namechar_spn(s + 1); if (n > 0) { if (n >= VNAMELEN) { n = VNAMELEN - 1; } *sname = '\0'; strncat(sname, s + 1, n); freeit = 0; sub = maybe_get_subst(sname, &n, in_format, &freeit); if (sub != NULL) { m = strlen(sub); if (len + m + 2 >= MAXLINE) { too_long(); err = 1; break; } tmp = gretl_strdup(s + n + 1); if (tmp == NULL) { err = E_ALLOC; } else { strcpy(s, sub); strcpy(s + m, tmp); free(tmp); len += m - (n + 1); s += m - 1; i += m - 1; *subst = 1; } if (freeit) { free(sub); } } } } s++; i++; } return err; }
static void look_up_word (const char *s, parser *p) { int fsym, err = 0; fsym = p->sym = function_lookup_with_alias(s); if (p->sym == 0 || p->ch != '(') { p->idnum = const_lookup(s); if (p->idnum > 0) { p->sym = CON; } else { p->idnum = dummy_lookup(s); if (p->idnum > 0) { p->sym = DUM; } else { GretlType vtype = 0; char *bstr; if ((p->idnum = current_series_index(p->dset, s)) >= 0) { p->sym = UVEC; p->idstr = gretl_strdup(s); } else if (!strcmp(s, "time")) { p->sym = DUM; p->idnum = DUM_TREND; } else if ((p->uval = user_var_get_value_and_type(s, &vtype)) != NULL) { if (vtype == GRETL_TYPE_DOUBLE) { p->sym = UNUM; } else if (vtype == GRETL_TYPE_MATRIX) { p->sym = UMAT; } else if (vtype == GRETL_TYPE_BUNDLE) { p->sym = BUNDLE; } else if (vtype == GRETL_TYPE_STRING) { p->sym = USTR; } else if (vtype == GRETL_TYPE_LIST) { p->sym = ULIST; } else if (vtype == GRETL_TYPE_STRING) { p->sym = USTR; } p->idstr = gretl_strdup(s); } else if ((bstr = get_built_in_string_by_name(s))) { /* FIXME should use $-accessors? */ p->sym = STR; p->idstr = gretl_strdup(bstr); } else if (gretl_get_object_by_name(s)) { p->sym = UOBJ; p->idstr = gretl_strdup(s); } else if (get_user_function_by_name(s)) { p->sym = UFUN; p->idstr = gretl_strdup(s); } else if (p->targ == LIST && varname_match_any(p->dset, s)) { p->sym = WLIST; p->idstr = gretl_strdup(s); } else if (!strcmp(s, "t")) { /* if "t" has not been otherwise defined, treat it as an alias for "obs" */ p->sym = DVAR; p->idnum = R_INDEX; } else if (maybe_get_R_function(s)) { /* note: all "native" types take precedence over this */ p->sym = RFUN; p->idstr = gretl_strdup(s + 2); } else if (parsing_query) { p->sym = UNDEF; p->idstr = gretl_strdup(s); } else { err = E_UNKVAR; } } } } if (err) { if (fsym) { function_noargs_error(s, p); } else { undefined_symbol_error(s, p); } } }
int midas_forecast_setup (const MODEL *pmod, DATASET *dset, ForecastMethod method, char **pformula) { gretl_array *mA; midas_info *minfo = NULL; int *xlist = NULL; int *hflist = NULL; int nmidas = 0; int err = 0; mA = gretl_model_get_data(pmod, "midas_info"); xlist = gretl_model_get_data(pmod, "lfxlist"); if (mA == NULL || xlist == NULL) { err = E_DATA; } else { minfo = minfo_from_array(mA, &nmidas, &err); } if (!err) { /* reconstitute MIDAS lag-lists */ err = make_midas_laglists(minfo, nmidas, dset); } if (!err) { /* build and push list of all MIDAS terms */ hflist = make_midas_biglist(NULL, minfo, nmidas); if (hflist == NULL) { err = E_ALLOC; } else { /* note: remember_list() copies its argument */ err = remember_list(hflist, "HFLFC___", NULL); user_var_privatize_by_name("HFLFC___"); free(hflist); } } if (!err) { /* build and push vector of all MIDAS coeffs */ err = push_midas_coeff_array(pmod, xlist, minfo, nmidas); } if (!err) { /* build a string that can be passed to "genr" to calculate fitted values */ char tmp[64], line[MAXLEN]; double *b = pmod->coeff; int p, yno = pmod->list[1]; int i, xi, j = 0; *line = '\0'; gretl_push_c_numeric_locale(); for (i=1; i<=xlist[0]; i++) { xi = xlist[i]; if (xi == 0) { sprintf(tmp, "%+.15g", b[j++]); } else { /* allow for dynamic formula? */ p = (method == FC_STATIC)? 0 : standard_lag_of(xi, yno, dset); if (p > 0) { sprintf(tmp, "%+.15g*%s(-%d)", b[j++], dset->varname[yno], p); } else { sprintf(tmp, "%+.15g*%s", b[j++], dset->varname[xi]); } } strcat(line, tmp); } strcat(line, "+lincomb(HFLFC___,hfb___)"); gretl_pop_c_numeric_locale(); #if FC_DEBUG fprintf(stderr, "formula='%s'\n", line); #endif *pformula = gretl_strdup(line); } free(minfo); return err; }
static int finalize_midas_model (MODEL *pmod, const int *list, const char *param, const DATASET *dset, midas_info *minfo, int nmidas, int *xlist, int ldepvar, int hfslopes) { int type0, mixed = 0; int i, err = 0; gretl_model_set_string_as_data(pmod, "midas_spec", gretl_strdup(param)); if (pmod->ci == OLS) { /* @pmod is the result of OLS estimation */ int vi; gretl_model_allocate_param_names(pmod, pmod->ncoeff); for (i=0; i<pmod->ncoeff; i++) { vi = pmod->list[i+2]; gretl_model_set_param_name(pmod, i, dset->varname[vi]); } gretl_model_set_int(pmod, "umidas", 1); } else { /* @pmod is the result of NLS estimation */ free(pmod->depvar); pmod->depvar = gretl_strdup(dset->varname[list[1]]); free(pmod->list); pmod->list = gretl_list_copy(list); } pmod->ci = MIDASREG; /* record list of low-frequency regressors */ gretl_model_set_list_as_data(pmod, "lfxlist", xlist); if (ldepvar) { gretl_model_set_int(pmod, "dynamic", 1); } /* record the (common) type of MIDAS term? */ type0 = minfo[0].type; if (nmidas > 1) { for (i=1; i<nmidas; i++) { if (minfo[i].type != type0) { mixed = 1; break; } } } if (!mixed && type0 > 0) { gretl_model_set_int(pmod, "midas_type", type0); } if (nmidas == 1) { /* Record the "gross" MIDAS coefficients, to enable drawing of a plot? We'll do this only if we have a single MIDAS term, which is probably the most most common case. Otherwise it becomes too hard to get the plot right. */ int nx = list[0] - 1; const double *b = pmod->coeff + nx; add_midas_plot_matrix(pmod, &minfo[0], b); } if (!err) { err = model_add_minfo_array(pmod, minfo, nmidas); } return err; }
static int bundled_item_replace_data (bundled_item *item, GretlType type, void *ptr, int size, int copy) { int err = 0; if (ptr == item->data) { return 0; } if (item->type == GRETL_TYPE_DOUBLE) { double *dp = item->data; *dp = *(double *) ptr; } else if (item->type == GRETL_TYPE_STRING) { free(item->data); if (copy) { item->data = gretl_strdup((char *) ptr); } else { item->data = ptr; } } else if (item->type == GRETL_TYPE_MATRIX) { gretl_matrix_free(item->data); if (copy) { item->data = gretl_matrix_copy((gretl_matrix *) ptr); } else { item->data = ptr; } } else if (item->type == GRETL_TYPE_MATRIX_REF) { release_matrix_pointer((gretl_matrix **) &item->data); item->data = ptr; } else if (item->type == GRETL_TYPE_SERIES) { free(item->data); if (copy) { item->data = copyvec((const double *) ptr, size); } else { item->data = ptr; } item->size = size; } else if (item->type == GRETL_TYPE_BUNDLE) { gretl_bundle_destroy((gretl_bundle *) item->data); if (copy) { item->data = gretl_bundle_copy((gretl_bundle *) ptr, &err); } else { item->data = ptr; } } else if (item->type == GRETL_TYPE_ARRAY) { gretl_array_destroy((gretl_array*) item->data); if (copy) { item->data = gretl_array_copy((gretl_array *) ptr, &err); } else { item->data = ptr; } } else { return E_DATA; } if (!err && item->data == NULL) { err = E_ALLOC; } if (item->note != NULL) { free(item->note); item->note = NULL; } return err; }
static bundled_item *bundled_item_new (GretlType type, void *ptr, int size, int copy, const char *note, int *err) { bundled_item *item = malloc(sizeof *item); if (item == NULL) { *err = E_ALLOC; } else { item->type = type; item->size = 0; item->note = NULL; switch (item->type) { case GRETL_TYPE_DOUBLE: item->data = malloc(sizeof(double)); if (item->data != NULL) { double *dp = item->data; *dp = *(double *) ptr; } break; case GRETL_TYPE_STRING: if (copy) { item->data = gretl_strdup((char *) ptr); } else { item->data = ptr; } break; case GRETL_TYPE_MATRIX: if (copy) { item->data = gretl_matrix_copy((gretl_matrix *) ptr); } else { item->data = ptr; } break; case GRETL_TYPE_MATRIX_REF: item->data = ptr; break; case GRETL_TYPE_SERIES: if (copy) { item->data = copyvec((const double *) ptr, size); } else { item->data = ptr; } item->size = size; break; case GRETL_TYPE_BUNDLE: if (copy) { item->data = gretl_bundle_copy((gretl_bundle *) ptr, err); } else { item->data = ptr; } break; case GRETL_TYPE_ARRAY: if (copy) { item->data = gretl_array_copy((gretl_array *) ptr, err); } else { item->data = ptr; } break; default: *err = E_TYPES; break; } if (!*err && item->data == NULL) { free(item); item = NULL; *err = E_ALLOC; } if (item != NULL && note != NULL) { item->note = gretl_strdup(note); } } return item; }
static int xlsx_read_row (xmlNodePtr cur, xlsx_info *xinfo, PRN *prn) { PRN *myprn = NULL; xmlNodePtr val; char *tmp; int row = -1, col = -1; int pass, empty = 1; int err = 0; pass = xinfo->dset == NULL ? 1 : 2; #if XDEBUG myprn = prn; pprintf(myprn, "*** Reading row (pass %d)...\n", pass); #endif cur = cur->xmlChildrenNode; /* loop across cells in row */ while (cur != NULL && !err) { if (!xmlStrcmp(cur->name, (XUC) "c")) { /* we got a cell in the given row */ char *cref = NULL; char *formula = NULL; const char *strval = NULL; double xval = NADBL; int stringcell = 0; int gotv = 0, gotf = 0; pprintf(myprn, " cell"); cref = (char *) xmlGetProp(cur, (XUC) "r"); if (cref == NULL) { pprintf(myprn, ": couldn't find 'r' property\n"); err = E_DATA; break; } err = xlsx_cell_get_coordinates(cref, &row, &col); if (err) { pprintf(myprn, ": couldn't find coordinates\n", row, col); } else { pprintf(myprn, "(%d, %d)", row, col); } if (pass == 2 && row > xinfo->maxrow) { goto skipit; } tmp = (char *) xmlGetProp(cur, (XUC) "t"); if (tmp != NULL) { if (!strcmp(tmp, "s")) { /* string from string table */ stringcell = 1; } else if (!strcmp(tmp, "str")) { /* "inline" string literal? */ stringcell = 2; } free(tmp); } val = cur->xmlChildrenNode; /* find a value in the current row/cell */ while (val && !err && !gotv) { if (!xmlStrcmp(val->name, (XUC) "v")) { tmp = (char *) xmlNodeGetContent(val); if (tmp != NULL) { if (stringcell) { if (stringcell == 1) { strval = xlsx_string_value(tmp, xinfo, prn); } else { strval = gretl_strdup(tmp); } if (strval == NULL) { pputs(myprn, " value = ?\n"); err = E_DATA; } else { pprintf(myprn, " value = '%s'\n", strval); } } else { pprintf(myprn, " value = %s\n", tmp); if (*tmp != '\0' && check_atof(tmp) == 0) { xval = atof(tmp); } } free(tmp); gotv = 1; } } else if (!gotf && !xmlStrcmp(val->name, (XUC) "f")) { formula = (char *) xmlNodeGetContent(val); gotf = 1; } val = val->next; } if (gotf && formula == NULL) { gotf = 0; } if (!err && xinfo->dset == NULL) { /* on the first pass, check for obs column, varname status */ xlsx_check_top_left(xinfo, row, col, stringcell, strval, xval); } if (err) { pprintf(myprn, ": (%s) error", cref); } else if (!gotv) { pprintf(myprn, ": (%s) no data value", cref); if (gotf) { pprintf(myprn, "; formula = '%s'\n", formula); } else { pputc(myprn, '\n'); } } if (!err && xinfo->dset != NULL && col > xinfo->xoffset && row > xinfo->yoffset) { int i = xlsx_var_index(xinfo, col); int t = xlsx_obs_index(xinfo, row); /* here we're on the second pass, with a dataset allocated */ if (stringcell) { if (row == xinfo->namerow) { err = xlsx_set_varname(xinfo, i, strval, row, col, prn); } else if (col == xinfo->obscol) { err = xlsx_set_obs_string(xinfo, row, col, t, strval, prn); } else if (strval != NULL) { err = xlsx_handle_stringval(strval, row, col, prn); } if (stringcell == 2) { /* finished with copy of string literal */ free((char *) strval); } } else if (gotv) { err = xlsx_set_value(xinfo, i, t, xval); } else if (gotf) { xlsx_maybe_handle_formula(xinfo, formula, i, t); } } else if (stringcell == 2 && strval != NULL) { free((char *) strval); } if (gotv || gotf) { empty = 0; } skipit: free(cref); free(formula); } /* move onto next cell in row */ cur = cur->next; } /* end loop across cells in row */ if (!err) { if (empty) { pputs(myprn, " xlsx_read_row: empty row!\n"); } else if (pass == 1) { xlsx_set_dims(xinfo, row, col); } } if (err) { fprintf(stderr, "xlsx_read_row: returning %d\n", err); } return err; }