The R Project SVN R

Rev

Rev 45017 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 45017 Rev 82565
Line 23... Line 23...
23
   WITHOUT ANY WARRANTY.
23
   WITHOUT ANY WARRANTY.
24
 
24
 
25
   See the file COPYLIB.TXT for details.
25
   See the file COPYLIB.TXT for details.
26
*/
26
*/
27
 
27
 
-
 
28
/* Copyright (C) 2022  The R Core Team
-
 
29
   
-
 
30
   avoid stack corruption on long lines  
-
 
31
*/
-
 
32
 
28
#include "internal.h"
33
#include "internal.h"
29
#include <stdarg.h>
34
#include <stdarg.h>
30
 
35
 
31
#define COMPRESS_WHITESPACE 0
36
#define COMPRESS_WHITESPACE 0
32
 
37
 
-
 
38
static size_t max_line_size(const char *s)
-
 
39
{
-
 
40
    size_t size = 0;
-
 
41
    size_t i;
-
 
42
 
-
 
43
    for(i = 0; s[i]; i++) {
-
 
44
	if (s[i] == '\t') size += 8;
-
 
45
	else size++;
-
 
46
    }
-
 
47
    return size + 1;
-
 
48
}
-
 
49
 
33
static const char *get_next_line(char *line, int width, const char *s)
50
static const char *get_next_line(char *line, int width, const char *s)
34
{
51
{
35
    const char *t; char  *k;
52
    const char *t; char  *k;
36
    int	word_width, line_width;
53
    int	word_width, line_width;
37
    int	sp, tab, nl;
54
    int	sp, tab, nl;
Line 96... Line 113...
96
}
113
}
97
 
114
 
98
int textheight(int width, const char *s)
115
int textheight(int width, const char *s)
99
{
116
{
100
    int y;
117
    int y;
101
    char line[256];
118
    size_t size;
102
    int height;
119
    int height;
-
 
120
    char *line;
103
 
121
 
-
 
122
    size = max_line_size(s);
-
 
123
    line = (char *)malloc(size * sizeof(char));
104
    height = getheight(current->fnt);
124
    height = getheight(current->fnt);
105
 
125
 
106
    for(y=0; s; y+=height)
126
    for(y=0; s; y+=height)
107
    {
127
    {
108
	s = get_next_line(line, width, s);
128
	s = get_next_line(line, width, s);
109
    }
129
    }
110
 
130
 
-
 
131
    free(line);
111
    return y;
132
    return y;
112
}
133
}
113
 
134
 
114
static const char *draw_text_left(char *line, rect r, int line_height,
135
static const char *draw_text_left(char *line, rect r, int line_height,
115
				  int underline, const char *s)
136
				  int underline, const char *s)
Line 281... Line 302...
281
    int nlines;
302
    int nlines;
282
    int line_height;
303
    int line_height;
283
    int u = 0;
304
    int u = 0;
284
    rect clip;
305
    rect clip;
285
    const char *remains;
306
    const char *remains;
286
    char line[256];
307
    char *line;
-
 
308
    size_t size;
-
 
309
 
287
 
310
 
288
    initapp(0,0);
311
    initapp(0,0);
289
    if (! s) return (char *) NULL;
312
    if (! s) return (char *) NULL;
-
 
313
    size = max_line_size(s);
-
 
314
    line = (char *)malloc(size * sizeof(char));
-
 
315
 
290
    if (! current->fnt)
316
    if (! current->fnt)
291
	current->fnt = SystemFont;
317
	current->fnt = SystemFont;
292
 
318
 
293
    clip = getcliprect();
319
    clip = getcliprect();
294
    setcliprect(r);
320
    setcliprect(r);
Line 324... Line 350...
324
	remains = draw_text_right(line, r, line_height, u, s);
350
	remains = draw_text_right(line, r, line_height, u, s);
325
    else
351
    else
326
	remains = draw_text_left(line, r, line_height, u, s);
352
	remains = draw_text_left(line, r, line_height, u, s);
327
 
353
 
328
    setcliprect(clip);
354
    setcliprect(clip);
-
 
355
    free(line);
329
    return remains;
356
    return remains;
330
}
357
}
331
 
358
 
332
int gprintf(const char *fmt, ...)
359
int gprintf(const char *fmt, ...)
333
{
360
{