The R Project SVN R

Rev

Rev 83709 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 83709 Rev 88761
Line 1... Line 1...
1
/*
1
/*
2
 *  R : A Computer Language for Statistical Data Analysis
2
 *  R : A Computer Language for Statistical Data Analysis
3
 *  Copyright (C) 1999-2023  The R Core Team
3
 *  Copyright (C) 1999-2025  The R Core Team
4
 *
4
 *
5
 *  This program is free software; you can redistribute it and/or modify
5
 *  This program is free software; you can redistribute it and/or modify
6
 *  it under the terms of the GNU General Public License as published by
6
 *  it under the terms of the GNU General Public License as published by
7
 *  the Free Software Foundation; either version 2 of the License, or
7
 *  the Free Software Foundation; either version 2 of the License, or
8
 *  (at your option) any later version.
8
 *  (at your option) any later version.
Line 57... Line 57...
57
 
57
 
58
static EditorData neweditordata (int file)
58
static EditorData neweditordata (int file)
59
{
59
{
60
    EditorData p;
60
    EditorData p;
61
    p = (EditorData) malloc(sizeof(struct structEditorData));
61
    p = (EditorData) malloc(sizeof(struct structEditorData));
-
 
62
    if (!p)
-
 
63
	return NULL;
62
    p->file = file;
64
    p->file = file;
63
    p->filename = NULL;
65
    p->filename = NULL;
64
    p->title = (char *) malloc((EDITORMAXTITLE + 1)*sizeof(char));
66
    p->title = (char *) malloc((EDITORMAXTITLE + 1)*sizeof(char));
-
 
67
    if (!p->title) {
-
 
68
	free(p);
-
 
69
	return NULL;
-
 
70
    }
65
    p->title[EDITORMAXTITLE] = p->title[0] = '\0';
71
    p->title[EDITORMAXTITLE] = p->title[0] = '\0';
66
    return p;
72
    return p;
67
}
73
}
68
 
74
 
69
void deleditordata(EditorData p)
75
void deleditordata(EditorData p)
Line 148... Line 154...
148
    const char *sname;
154
    const char *sname;
149
    long num = 1, bufsize;
155
    long num = 1, bufsize;
150
 
156
 
151
    if(enc == CE_UTF8) {
157
    if(enc == CE_UTF8) {
152
	wchar_t *wname = utf8_to_wchar(name);
158
	wchar_t *wname = utf8_to_wchar(name);
-
 
159
	if (!wname) {
-
 
160
	    R_ShowMessage(G_("Not enough memory"));
-
 
161
	    return;
-
 
162
	}
153
	f = R_wfopen(wname, L"r");
163
	f = R_wfopen(wname, L"r");
154
	free(wname);
164
	free(wname);
155
	sname = utf8_to_native(name);
165
	sname = utf8_to_native(name);
-
 
166
	if (!sname) {
-
 
167
	    R_ShowMessage(G_("Not enough memory"));
-
 
168
	    return;
-
 
169
	}
156
    } else {
170
    } else {
157
	f = R_fopen(name, "r");
171
	f = R_fopen(name, "r");
158
	sname = name;
172
	sname = name;
159
    }
173
    }
160
    if (f == NULL) {
174
    if (f == NULL) {
Line 168... Line 182...
168
    p->file = 1;
182
    p->file = 1;
169
    if (p->filename)
183
    if (p->filename)
170
	free(p->filename);
184
	free(p->filename);
171
    if (enc == CE_UTF8) {
185
    if (enc == CE_UTF8) {
172
	p->filename = (char *) malloc(strlen(name) + 1);
186
	p->filename = (char *) malloc(strlen(name) + 1);
-
 
187
	if (!p->filename) {
-
 
188
	    free((char *)sname);
-
 
189
	    R_ShowMessage(G_("Not enough memory"));
-
 
190
	    return;
-
 
191
	}
173
	strcpy(p->filename, name);
192
	strcpy(p->filename, name);
174
    } else
193
    } else {
175
	p->filename = native_to_utf8(name);
194
	p->filename = native_to_utf8(name);
-
 
195
	if (!p->filename) {
-
 
196
	    R_ShowMessage(G_("Not enough memory"));
-
 
197
	    return;
-
 
198
	}
-
 
199
    }
176
 
200
 
177
    bufsize = 0;
201
    bufsize = 0;
178
    while (num > 0) {
202
    while (num > 0) {
179
	buffer = realloc(buffer, bufsize + 3000 + 1);
203
	buffer = realloc(buffer, bufsize + 3000 + 1);
-
 
204
	if (!buffer) {
-
 
205
	    if (enc == CE_UTF8)
-
 
206
		free((char *)sname);
-
 
207
	    R_ShowMessage(G_("Not enough memory"));
-
 
208
	    return;
-
 
209
	}
180
	num = fread(buffer + bufsize, 1, 3000 - 1, f);
210
	num = fread(buffer + bufsize, 1, 3000 - 1, f);
181
	if (num >= 0) {
211
	if (num >= 0) {
182
	    bufsize += num;
212
	    bufsize += num;
183
	    buffer[bufsize] = '\0';
213
	    buffer[bufsize] = '\0';
184
	}
214
	}
Line 246... Line 276...
246
	    if (tmp) {
276
	    if (tmp) {
247
		strcpy(tmp, name);
277
		strcpy(tmp, name);
248
		strcat(tmp, ".R");
278
		strcat(tmp, ".R");
249
		free(name);
279
		free(name);
250
		name = tmp;
280
		name = tmp;
-
 
281
	    } else {
-
 
282
		R_ShowMessage(G_("Not enough memory"));
-
 
283
		return;
251
	    }
284
	    }
252
	}
285
	}
253
	editor_save_file(c, name, CE_UTF8);
286
	editor_save_file(c, name, CE_UTF8);
254
	p->file = 1;
287
	p->file = 1;
255
	p->filename = name; /* keeps name */
288
	p->filename = name; /* keeps name */
256
	gsetmodified(t, 0);
289
	gsetmodified(t, 0);
257
	char *sname = utf8_to_native(name);
290
	char *sname = utf8_to_native(name);
-
 
291
	if (sname) {
258
	editor_set_title(c, sname);
292
	    editor_set_title(c, sname);
259
	free(sname);
293
	    free(sname);
-
 
294
	} else
-
 
295
	    R_ShowMessage(G_("Not enough memory"));
260
    }
296
    }
261
    show(c);
297
    show(c);
262
}
298
}
263
 
299
 
264
static void menueditorsaveas(control m)
300
static void menueditorsaveas(control m)
Line 325... Line 361...
325
	istartline = i;
361
	istartline = i;
326
	while (contents[i] != '\n' && contents[i] != '\0') {
362
	while (contents[i] != '\n' && contents[i] != '\0') {
327
	    ++i; ++j;
363
	    ++i; ++j;
328
	}
364
	}
329
	linebuf = realloc(linebuf, (j+1)*sizeof(char));
365
	linebuf = realloc(linebuf, (j+1)*sizeof(char));
-
 
366
	if (!linebuf) {
-
 
367
	    del(lpr);
-
 
368
	    R_ShowMessage(G_("Not enough memory"));
-
 
369
	    return;
-
 
370
	}
330
	strncpy(linebuf, &contents[istartline], j);
371
	strncpy(linebuf, &contents[istartline], j);
331
	linebuf[j] = '\0';
372
	linebuf[j] = '\0';
332
	gdrawstr(lpr, f, Black, pt(left, linep), linebuf);
373
	gdrawstr(lpr, f, Black, pt(left, linep), linebuf);
333
	linep += fh;
374
	linep += fh;
334
	++i;
375
	++i;
Line 537... Line 578...
537
{
578
{
538
    int length = getlinelength(t); /* return character num */
579
    int length = getlinelength(t); /* return character num */
539
    /* Extra space for null and word length in getcurrentline */
580
    /* Extra space for null and word length in getcurrentline */
540
    size_t alength = length * MB_CUR_MAX + 1 + sizeof(WORD);
581
    size_t alength = length * MB_CUR_MAX + 1 + sizeof(WORD);
541
    char *line = malloc(alength);
582
    char *line = malloc(alength);
-
 
583
    if (!line) {
-
 
584
	R_ShowMessage(G_("Not enough memory"));
-
 
585
	return;
-
 
586
    }
542
    memset(line, 0, alength);
587
    memset(line, 0, alength);
543
    getcurrentline(t, line, length);
588
    getcurrentline(t, line, length);
544
    consolecmd(RConsole, line);
589
    consolecmd(RConsole, line);
545
    free(line);
590
    free(line);
546
    scrollcaret(t, 1);
591
    scrollcaret(t, 1);
Line 715... Line 760...
715
    long flags;
760
    long flags;
716
    font editorfn = (consolefn ? consolefn : FixedFont);
761
    font editorfn = (consolefn ? consolefn : FixedFont);
717
    EditorData p = neweditordata(0);
762
    EditorData p = neweditordata(0);
718
    DWORD rand;
763
    DWORD rand;
719
 
764
 
-
 
765
    if (!p)
-
 
766
	return NULL;
720
    w = (pagercol + 1)*fontwidth(editorfn);
767
    w = (pagercol + 1)*fontwidth(editorfn);
721
    h = (pagerrow + 1)*fontheight(editorfn) + 1;
768
    h = (pagerrow + 1)*fontheight(editorfn) + 1;
722
#ifdef USE_MDI
769
#ifdef USE_MDI
723
    if(ismdi()) {
770
    if(ismdi()) {
724
	RECT *pR = RgetMDIsize();
771
	RECT *pR = RgetMDIsize();
Line 840... Line 887...
840
    MCHECK(m = newmenuitem("-", 0, NULL));
887
    MCHECK(m = newmenuitem("-", 0, NULL));
841
    MCHECK(newmenuitem(G_("GUI preferences..."), 0, menuconfig));
888
    MCHECK(newmenuitem(G_("GUI preferences..."), 0, menuconfig));
842
 
889
 
843
    /* Packages menu should go here */
890
    /* Packages menu should go here */
844
    p->pmenu = (PkgMenuItems) malloc(sizeof(struct structPkgMenuItems));
891
    p->pmenu = (PkgMenuItems) malloc(sizeof(struct structPkgMenuItems));
-
 
892
    if (!p->pmenu)
-
 
893
	return NULL;
845
    RguiPackageMenu(p->pmenu);
894
    RguiPackageMenu(p->pmenu);
846
 
895
 
847
#ifdef USE_MDI
896
#ifdef USE_MDI
848
    newmdimenu(); /* Create and fill the 'Window' menu */
897
    newmdimenu(); /* Create and fill the 'Window' menu */
849
#endif
898
#endif
850
 
899
 
851
    MCHECK(m = newmenu(G_("Help")));
900
    MCHECK(m = newmenu(G_("Help")));
852
    MCHECK(newmenuitem(G_("Editor"), 0, menueditorhelp));
901
    MCHECK(newmenuitem(G_("Editor"), 0, menueditorhelp));
853
    MCHECK(newmenuitem("-", 0, NULL));
902
    MCHECK(newmenuitem("-", 0, NULL));
854
    p->hmenu = (HelpMenuItems) malloc(sizeof(struct structHelpMenuItems));
903
    p->hmenu = (HelpMenuItems) malloc(sizeof(struct structHelpMenuItems));
-
 
904
    if (!p->hmenu)
-
 
905
	return NULL;
855
    RguiCommonHelp(m, p->hmenu);
906
    RguiCommonHelp(m, p->hmenu);
856
 
907
 
857
    settextfont(t, editorfn);
908
    settextfont(t, editorfn);
858
    setforeground(t, guiColors[editorfg]);    
909
    setforeground(t, guiColors[editorfg]);    
859
    setresize(c, editorresize);
910
    setresize(c, editorresize);