Esempio n. 1
0
void set_alt_gettext_mode (PRN *prn)
{
    gettext_mode = GETTEXT_DEFAULT;

    /* As of 2014-09-07, we'll handle RTF by (a) getting
       gettext to write UTF-8 (forcing it if necessary)
       then (b) using utf8_to_rtf() to convert to ASCII
       plus \uXXXX codes, as per the spec for RTF >= 1.5.
       (It would be nice if gettext were able to generate
       the latter directly, but it can't.)

       Note: this means that RTF should not be written to
       file directly: a bufferized PRN should be used
       first so that the buffer can be sent through
       utf8_to_rtf(); then it can be written to file.
    */

    if (prn != NULL && !native_utf8) {
	if (gretl_in_gui_mode()) {
	    if (printing_to_standard_stream(prn)) {
		gettext_mode = GETTEXT_FORCE_LOCALE;
	    }
	} else if (tex_format(prn) || rtf_format(prn)) {
	    /* CLI mode, writing TeX or RTF */
	    gettext_mode = GETTEXT_FORCE_UTF8;
	}
    }
}
Esempio n. 2
0
static int progress_bar_wanted (int opt)
{
    if (gretl_in_gui_mode()) {
	return (opt == GRAB_IDX || 
		opt == GRAB_DATA ||
		opt == GRAB_NBO_DATA ||
		opt == GRAB_FILE ||
		opt == GRAB_FUNC ||
		opt == GRAB_PDF ||
		opt == GRAB_PKG ||
		opt == GRAB_FOREIGN);
    }
    
    return 0;
}
Esempio n. 3
0
int retrieve_public_file (const char *uri, char *localname)
{
    int pl = proto_length(uri);
    int err = 0;

    if (pl == 0) {
	return E_DATA;
    } else if (*localname == '\0') {
	/* extract the filename from the uri */
	const char *s = strrchr(uri + pl, '/');

	if (s == NULL || *(s+1) == '\0') {
	    err = E_DATA;
	} else {
	    /* save to user's dotdir by default */
	    strcat(localname, gretl_dotdir());
	    strcat(localname, s + 1);
	}
    }

    if (!err) {
	urlinfo u;

	urlinfo_init(&u, NULL, SAVE_TO_FILE, localname);
	urlinfo_set_url(&u, uri);
	if (gretl_in_gui_mode()) {
	    urlinfo_set_show_progress(&u);
	}
	err = curl_get(&u);
	urlinfo_finalize(&u, NULL, &err);
    }

    if (err) {
	const char *s = gretl_errmsg_get();

	if (*s == '\0') {
	    /* no error message in place */
	    gretl_errmsg_sprintf("%s\ndownload failed", uri);
	}
    } else {
	err = check_downloaded_file(localname, uri);
    }

    return err;
}
Esempio n. 4
0
MODEL arma_x12_model (const int *list, const int *pqspec,
		      const DATASET *dset, int pdmax, 
		      gretlopt opt, PRN *prn)
{
    int verbose = (opt & OPT_V);
    const char *prog = gretl_x12_arima();
    const char *workdir = gretl_x12_arima_dir();
    char yname[VNAMELEN], path[MAXLEN];
    MODEL armod;
    arma_info ainfo_s, *ainfo;
    int missv = 0, misst = 0;
#ifdef WIN32
    char *cmd;
#endif
    int err = 0;

    if (dset->t2 < dset->n - 1) {
	/* FIXME this is temporary (OPT_F -> generate forecast) */
	opt |= OPT_F;
    }

    ainfo = &ainfo_s;
    arma_info_init(ainfo, opt | OPT_X, pqspec, dset);
    ainfo->prn = set_up_verbose_printer(opt, prn);
    gretl_model_init(&armod, dset); 

    ainfo->alist = gretl_list_copy(list);
    if (ainfo->alist == NULL) {
	err = E_ALLOC;
    }

    if (!err) {
	err = arma_check_list(ainfo, dset, opt);
    }

    if (err) {
	armod.errcode = err;
	goto bailout;
    }     

    /* calculate maximum lag */
    calc_max_lag(ainfo);

    x12a_maybe_allow_missvals(ainfo);

    /* adjust sample range if need be */
    armod.errcode = arma_adjust_sample(ainfo, dset, &missv, &misst);
    if (armod.errcode) {
	goto bailout;
    } else if (missv > 0) {
	set_arma_missvals(ainfo);
    }

    ainfo->y = (double *) dset->Z[ainfo->yno]; /* it's really const */
    strcpy(yname, dset->varname[ainfo->yno]);

    /* write out an .spc file */
    sprintf(path, "%s%c%s.spc", workdir, SLASH, yname);
    write_arma_spc_file(path, dset, ainfo, pdmax, opt);

    /* remove any files from an old run, in case of error */
    delete_old_files(path);

    /* run the program */
#ifdef WIN32
    cmd = g_strdup_printf("\"%s\" %s -r -p -q", prog, yname);
    err = win_run_sync(cmd, workdir);
    g_free(cmd);
#else
    err = tramo_x12a_spawn(workdir, prog, yname, "-r", "-p", "-q", "-n", NULL);
#endif

    if (!err) {
	sprintf(path, "%s%c%s", workdir, SLASH, yname); 
	populate_x12a_arma_model(&armod, path, dset, ainfo);
	if (verbose && !armod.errcode) {
	    print_iterations(path, ainfo->prn);
	}
	if (!armod.errcode) {
	    if (gretl_in_gui_mode()) {
		add_unique_output_file(&armod, path);
	    }
	    gretl_model_set_int(&armod, "arma_flags", (int) ainfo->flags);
	}	
    } else {
	armod.errcode = E_UNSPEC;
	gretl_errmsg_set(_("Failed to execute x12arima"));
    }

    if (armod.errcode && ainfo->prn != NULL) {
	sprintf(path, "%s%c%s.err", workdir, SLASH, yname);
	print_x12a_error_file(path, ainfo->prn);
    }

    if (ainfo->prn != NULL && ainfo->prn != prn) {
	iter_print_callback(0, ainfo->prn);
	close_down_verbose_printer(ainfo->prn);
    }

 bailout:

    arma_info_cleanup(ainfo);

    return armod;
}