The R Project SVN R

Rev

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

Rev 63181 Rev 63235
Line 314... Line 314...
314
#endif
314
#endif
315
 
315
 
316
# define BUFSIZE 10000
316
# define BUFSIZE 10000
317
int dummy_vfprintf(Rconnection con, const char *format, va_list ap)
317
int dummy_vfprintf(Rconnection con, const char *format, va_list ap)
318
{
318
{
-
 
319
    R_CheckStack2(BUFSIZE); // prudence
319
    char buf[BUFSIZE], *b = buf;
320
    char buf[BUFSIZE], *b = buf;
320
    int res;
321
    int res;
321
    const void *vmax = vmaxget();
322
    const void *vmax = NULL; /* -Wall*/
322
    int usedRalloc = FALSE, usedVasprintf = FALSE;
323
    int usedVasprintf = FALSE;
323
    va_list aq;
324
    va_list aq;
324
 
325
 
325
    va_copy(aq, ap);
326
    va_copy(aq, ap);
326
    res = vsnprintf(buf, BUFSIZE, format, aq);
327
    res = vsnprintf(buf, BUFSIZE, format, aq);
327
    va_end(aq);
328
    va_end(aq);
Line 334... Line 335...
334
	    warning(_("printing of extremely long output is truncated"));
335
	    warning(_("printing of extremely long output is truncated"));
335
	} else usedVasprintf = TRUE;
336
	} else usedVasprintf = TRUE;
336
    }
337
    }
337
#else
338
#else
338
    if(res >= BUFSIZE) { /* res is the desired output length */
339
    if(res >= BUFSIZE) { /* res is the desired output length */
339
	usedRalloc = TRUE;
340
	vmax = vmaxget();
340
	/* apparently some implementations count short,
341
	/* apparently some implementations count short,
341
	   <http://unixpapa.com/incnote/stdio.html>
342
	   <http://unixpapa.com/incnote/stdio.html>
342
	   so add some margin here */
343
	   so add some margin here */
343
	b = R_alloc(res + 101, sizeof(char));
344
	b = R_alloc(res + 101, sizeof(char));
344
	vsnprintf(b, res+100, format, ap);
345
	vsnprintf(b, res + 100, format, ap);
345
    } else if(res < 0) { /* just a failure indication */
346
    } else if(res < 0) { /* just a failure indication */
346
	usedRalloc = TRUE;
347
	vmax = vmaxget();
347
	b = R_alloc(10*BUFSIZE, sizeof(char));
348
	b = R_alloc(10*BUFSIZE, sizeof(char));
348
	res = vsnprintf(b, 10*BUFSIZE, format, ap);
349
	res = vsnprintf(b, 10*BUFSIZE, format, ap);
349
	if (res < 0) {
350
	if (res < 0) {
350
	    b[10*BUFSIZE - 1] = '\0';
351
	    b[10*BUFSIZE - 1] = '\0';
351
	    warning(_("printing of extremely long output is truncated"));
352
	    warning(_("printing of extremely long output is truncated"));
Line 376... Line 377...
376
	    con->write(outbuf, 1, strlen(outbuf), con);
377
	    con->write(outbuf, 1, strlen(outbuf), con);
377
	} while(again && inb > 0);  /* it seems some iconv signal -1 on
378
	} while(again && inb > 0);  /* it seems some iconv signal -1 on
378
				       zero-length input */
379
				       zero-length input */
379
    } else
380
    } else
380
	con->write(b, 1, res, con);
381
	con->write(b, 1, res, con);
381
    if(usedRalloc) vmaxset(vmax);
382
    if(vmax) vmaxset(vmax);
382
    if(usedVasprintf) free(b);
383
    if(usedVasprintf) free(b);
383
    return res;
384
    return res;
384
}
385
}
385
 
386
 
386
int dummy_fgetc(Rconnection con)
387
int dummy_fgetc(Rconnection con)
Line 2644... Line 2645...
2644
 
2645
 
2645
static int text_vfprintf(Rconnection con, const char *format, va_list ap)
2646
static int text_vfprintf(Rconnection con, const char *format, va_list ap)
2646
{
2647
{
2647
    Routtextconn this = con->private;
2648
    Routtextconn this = con->private;
2648
    char buf[BUFSIZE], *b = buf, *p, *q;
2649
    char buf[BUFSIZE], *b = buf, *p, *q;
2649
    const void *vmax = vmaxget();
2650
    const void *vmax = NULL;
2650
    int res = 0, usedRalloc = FALSE, buffree,
2651
    int res = 0, buffree,
2651
	already = (int) strlen(this->lastline); // we do not allow longer lines
2652
	already = (int) strlen(this->lastline); // we do not allow longer lines
2652
    SEXP tmp;
2653
    SEXP tmp;
2653
 
2654
 
2654
    va_list aq;
2655
    va_list aq;
2655
    va_copy(aq, ap);
2656
    va_copy(aq, ap);
Line 2665... Line 2666...
2665
	buffree = BUFSIZE - already; // checked < BUFSIZE above
2666
	buffree = BUFSIZE - already; // checked < BUFSIZE above
2666
	res = vsnprintf(p, buffree, format, aq);
2667
	res = vsnprintf(p, buffree, format, aq);
2667
    }
2668
    }
2668
    va_end(aq);
2669
    va_end(aq);
2669
    if(res >= buffree) { /* res is the desired output length */
2670
    if(res >= buffree) { /* res is the desired output length */
2670
	usedRalloc = TRUE;
2671
	vmax = vmaxget();
2671
	b = R_alloc(res + already + 1, sizeof(char));
2672
	b = R_alloc(res + already + 1, sizeof(char));
2672
	strcpy(b, this->lastline);
2673
	strcpy(b, this->lastline);
2673
	p = b + already;
2674
	p = b + already;
2674
	vsprintf(p, format, ap);
2675
	vsprintf(p, format, ap);
2675
    } else if(res < 0) { /* just a failure indication */
2676
    } else if(res < 0) { /* just a failure indication */
2676
#define NBUFSIZE (already + 100*BUFSIZE)
2677
#define NBUFSIZE (already + 100*BUFSIZE)
2677
	usedRalloc = TRUE;
2678
	vmax = vmaxget();
2678
	b = R_alloc(NBUFSIZE, sizeof(char));
2679
	b = R_alloc(NBUFSIZE, sizeof(char));
2679
	strncpy(b, this->lastline, NBUFSIZE);
2680
	strncpy(b, this->lastline, NBUFSIZE);
2680
	*(b + NBUFSIZE - 1) = '\0';
2681
	*(b + NBUFSIZE - 1) = '\0';
2681
	p = b + already;
2682
	p = b + already;
2682
	res = vsnprintf(p, NBUFSIZE - already, format, ap);
2683
	res = vsnprintf(p, NBUFSIZE - already, format, ap);
Line 2725... Line 2726...
2725
	    strcpy(this->lastline, p);
2726
	    strcpy(this->lastline, p);
2726
	    con->incomplete = strlen(this->lastline) > 0;
2727
	    con->incomplete = strlen(this->lastline) > 0;
2727
	    break;
2728
	    break;
2728
	}
2729
	}
2729
    }
2730
    }
2730
    if(usedRalloc) vmaxset(vmax);
2731
    if(vmax) vmaxset(vmax);
2731
    return res;
2732
    return res;
2732
}
2733
}
2733
 
2734
 
2734
static void outtext_init(Rconnection con, SEXP stext, const char *mode, int idx)
2735
static void outtext_init(Rconnection con, SEXP stext, const char *mode, int idx)
2735
{
2736
{
Line 5255... Line 5256...
5255
}
5256
}
5256
#else
5257
#else
5257
#define uiSwap(x) (x)
5258
#define uiSwap(x) (x)
5258
#endif
5259
#endif
5259
 
5260
 
-
 
5261
/* These are all hidden and used only in serialize.c, 
-
 
5262
   so managing R_alloc stack is prudence. */
5260
attribute_hidden
5263
attribute_hidden
5261
SEXP R_compress1(SEXP in)
5264
SEXP R_compress1(SEXP in)
5262
{
5265
{
5263
    const void *vmax = vmaxget();
5266
    const void *vmax = vmaxget();
5264
    unsigned int inlen;
5267
    unsigned int inlen;