コード例 #1
0
ファイル: editor.c プロジェクト: cyy0523xc/r-source
static void editor_save_file(editor c, const char *name, int enc)
{
    textbox t = getdata(c);
    FILE *f;
    char buf[MAX_PATH+30];
    const char *sname;

    if (name == NULL)
	return;
    else {
	if(enc == CE_UTF8) {
	    wchar_t wname[MAX_PATH+1];
	    Rf_utf8towcs(wname, name, MAX_PATH+1);
	    sname = reEnc(name, CE_UTF8, CE_NATIVE, 3);
	    f = R_wfopen(wname, L"w");
	} else {
	    sname = name;
	    f = R_fopen(sname, "w");
	}
	if (f == NULL) {
	    snprintf(buf, MAX_PATH+30, G_("Could not save file '%s'"), sname);
	    askok(buf);
	    return;
	}
	fprintf(f, "%s", gettext(t));
	fclose(f);
    }
}
コード例 #2
0
ファイル: vfonts.c プロジェクト: FatManCoding/r-source
attribute_hidden
void R_GE_VText(double x, double y, const char * const s, cetype_t enc,
		double x_justify, double y_justify, double rotation,
		const pGEcontext gc, pGEDevDesc dd)
{
    if(!initialized) vfonts_Init();
    if(initialized > 0) {
	const void *vmax = vmaxget();
	const char *str = reEnc(s, enc, CE_LATIN1, 2 /* '.' */);
	(*routines.GEVText)(x, y, str, x_justify, y_justify, rotation, gc, dd);
	vmaxset(vmax);
    } else
	error(_("Hershey fonts cannot be loaded"));
}
コード例 #3
0
ファイル: vfonts.c プロジェクト: FatManCoding/r-source
attribute_hidden
double R_GE_VStrWidth(const char *s, cetype_t enc, const pGEcontext gc, pGEDevDesc dd)
{
    double res;
    if(!initialized) vfonts_Init();
    if(initialized > 0) {
	const void *vmax = vmaxget();
	const char *str = reEnc(s, enc, CE_LATIN1, 2 /* '.' */);
	res = (*routines.GEVStrWidth)(str, gc, dd);
	vmaxset(vmax);
	return res;
    } else {
	error(_("Hershey fonts cannot be loaded"));
	return 0.0; /* -Wall */
    }
}
コード例 #4
0
ファイル: editor.c プロジェクト: cyy0523xc/r-source
static void editor_load_file(editor c, const char *name, int enc)
{
    textbox t = getdata(c);
    EditorData p = getdata(t);
    FILE *f;
    char *buffer = NULL, tmp[MAX_PATH+50];
    const char *sname;
    long num = 1, bufsize;

    if(enc == CE_UTF8) {
	wchar_t wname[MAX_PATH+1];
	Rf_utf8towcs(wname, name, MAX_PATH+1);
	f = R_wfopen(wname, L"r");
	sname = reEnc(name, CE_UTF8, CE_NATIVE, 3);
    } else {
	f = R_fopen(name, "r");
	sname = name;
    }
    if (f == NULL) {
	snprintf(tmp, MAX_PATH+50, 
		 G_("unable to open file %s for reading"), sname);
	R_ShowMessage(tmp);
	return;
    }
    p->file = 1;
    strncpy(p->filename, name, MAX_PATH+1);
    bufsize = 0;
    while (num > 0) {
	buffer = realloc(buffer, bufsize + 3000 + 1);
	num = fread(buffer + bufsize, 1, 3000 - 1, f);
	if (num >= 0) {
	    bufsize += num;
	    buffer[bufsize] = '\0';
	}
	else {
	    snprintf(tmp, MAX_PATH+50, 
		     G_("Could not read from file '%s'"), sname);
	    askok(tmp);
	}
    }
    setlimittext(t, 2 * strlen(buffer));
    settext(t, buffer);
    gsetmodified(t, 0);
    free(buffer);
    fclose(f);
}
コード例 #5
0
ファイル: stubs.c プロジェクト: Bgods/r-source
// formerly in src/main/platform.c
SEXP fileedit(SEXP call, SEXP op, SEXP args, SEXP rho)
{
    SEXP fn, ti, ed;
    const char **f, **title, *editor;
    int i, n;
    const void *vmax = vmaxget();

    args = CDR(args);
    fn = CAR(args); args = CDR(args);
    ti = CAR(args); args = CDR(args);
    ed = CAR(args);

    n = length(fn);
    if (!isString(ed) || length(ed) != 1)
	error(_("invalid '%s' specification"), "editor");
    if (n > 0) {
	if (!isString(fn))
	    error(_("invalid '%s' specification"), "filename");
	f = (const char**) R_alloc(n, sizeof(char*));
	title = (const char**) R_alloc(n, sizeof(char*));
	/* FIXME convert to UTF-8 on Windows */
	for (i = 0; i < n; i++) {
	    SEXP el = STRING_ELT(fn, 0);
	    if (!isNull(el))
#ifdef Win32
		f[i] = acopy_string(reEnc(CHAR(el), getCharCE(el), CE_UTF8, 1));
#else
		f[i] = acopy_string(translateChar(el));
#endif
	    else
		f[i] = "";
	    if (!isNull(STRING_ELT(ti, i)))
		title[i] = acopy_string(translateChar(STRING_ELT(ti, i)));
	    else
		title[i] = "";
	}
    }
コード例 #6
0
ファイル: editor.c プロジェクト: cyy0523xc/r-source
static void editoropen(const char *default_name)
{
    wchar_t *wname;
    char name[4*MAX_PATH];
    const char* title;

    int i; textbox t; EditorData p;
    setuserfilterW(L"R files (*.R)\0*.R\0S files (*.q, *.ssc, *.S)\0*.q;*.ssc;*.S\0All files (*.*)\0*.*\0\0");
    wname = askfilenameW(G_("Open script"), default_name); /* returns NULL if open dialog cancelled */
    if (wname) {
	wcstoutf8(name, wname, MAX_PATH);
	/* check if file is already open in an editor. If so, close and open again */
	for (i = 0; i < neditors; ++i) {
	    t = getdata(REditors[i]);
	    p = getdata(t);
	    if (!strcmp (name, p->filename)) {
		editorclose(REditors[i]);
		break;
	    }
	}
	title = reEnc(name, CE_UTF8, CE_NATIVE, 3);
	Rgui_Edit(name, CE_UTF8, title, 0);
    } else show(RConsole);
}
コード例 #7
0
ファイル: editor.c プロジェクト: cyy0523xc/r-source
static void editorsaveas(editor c)
{
    textbox t = getdata(c);
    EditorData p = getdata(t);
    wchar_t *wname;

    setuserfilterW(L"R files (*.R)\0*.R\0S files (*.q, *.ssc, *.S)\0*.q;*.ssc;*.S\0All files (*.*)\0*.*\0\0");
    wname = askfilesaveW(G_("Save script as"), "");
    if (wname) {
	char name[4*MAX_PATH+1];
	const char *tname;
	wcstoutf8(name, wname, MAX_PATH);
	/* now check if it has an extension */
	char *q = strchr(name, '.');
	if(!q) strncat(name, ".R", 4*MAX_PATH);
	tname = reEnc(name, CE_UTF8, CE_NATIVE, 3);
	editor_save_file(c, name, CE_UTF8);
	p->file = 1;
	strncpy(p->filename, tname, MAX_PATH+1);
	gsetmodified(t, 0);
	editor_set_title(c, tname);
    }
    show(c);
}