The R Project SVN R

Rev

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

Rev 41928 Rev 41944
Line 252... Line 252...
252
static void reset_inWarning(void *data)
252
static void reset_inWarning(void *data)
253
{
253
{
254
    inWarning = 0;
254
    inWarning = 0;
255
}
255
}
256
 
256
 
-
 
257
#ifdef SUPPORT_MBCS
-
 
258
#include <R_ext/rlocale.h>
-
 
259
 
-
 
260
static int wd(const char * buf)
-
 
261
{
-
 
262
    int nc = mbstowcs(NULL, buf, 0), nw;
-
 
263
    if(nc >= 0 || nc < 200) {
-
 
264
	wchar_t wc[200];
-
 
265
	mbstowcs(wc, buf, nc + 1);
-
 
266
	nw = Ri18n_wcswidth(wc, 2147483647);
-
 
267
	return (nw < 1) ? nc : nw;
-
 
268
    }
-
 
269
    return nc;
-
 
270
}
-
 
271
#endif
-
 
272
 
257
static void vwarningcall_dflt(SEXP call, const char *format, va_list ap)
273
static void vwarningcall_dflt(SEXP call, const char *format, va_list ap)
258
{
274
{
259
    int w;
275
    int w;
260
    SEXP names, s;
276
    SEXP names, s;
261
    const char *dcall;
277
    const char *dcall;
Line 311... Line 327...
311
	    strcat(buf, " [... truncated]");
327
	    strcat(buf, " [... truncated]");
312
	if(dcall[0] == '\0')
328
	if(dcall[0] == '\0')
313
	    REprintf(_("Warning: %s\n"), buf);
329
	    REprintf(_("Warning: %s\n"), buf);
314
#ifdef SUPPORT_MBCS
330
#ifdef SUPPORT_MBCS
315
	else if(mbcslocale &&
331
	else if(mbcslocale &&
316
		18+mbstowcs(NULL, dcall, 0)+mbstowcs(NULL, buf, 0) <= LONGWARN)
332
		18 + wd(dcall) + wd(buf) <= LONGWARN)
317
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
333
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
318
#endif
334
#endif
319
	else if(18+strlen(dcall)+strlen(buf) <= LONGWARN)
335
	else if(18+strlen(dcall)+strlen(buf) <= LONGWARN)
320
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
336
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
321
	else
337
	else
322
	    REprintf(_("Warning in %s :\n  %s\n"), dcall, buf);
338
	    REprintf(_("Warning in %s :\n  %s\n"), dcall, buf);
323
	if(R_ShowCalls && call != R_NilValue) {
339
	if(R_ShowWarnCalls && call != R_NilValue) {
324
	    tr = R_ConciseTraceback(call, 0);
340
	    tr = R_ConciseTraceback(call, 0);
325
	    if (strlen(tr)) REprintf("Calls: %s\n", tr);
341
	    if (strlen(tr)) REprintf("Calls: %s\n", tr);
326
	}
342
	}
327
    }
343
    }
328
    else if(w == 0) {	/* collect them */
344
    else if(w == 0) {	/* collect them */
Line 333... Line 349...
333
	    return;
349
	    return;
334
	SET_VECTOR_ELT(R_Warnings, R_CollectWarnings, call);
350
	SET_VECTOR_ELT(R_Warnings, R_CollectWarnings, call);
335
	Rvsnprintf(buf, min(BUFSIZE, R_WarnLength+1), format, ap);
351
	Rvsnprintf(buf, min(BUFSIZE, R_WarnLength+1), format, ap);
336
	if(R_WarnLength < BUFSIZE - 20 && strlen(buf) == R_WarnLength)
352
	if(R_WarnLength < BUFSIZE - 20 && strlen(buf) == R_WarnLength)
337
	    strcat(buf, " [... truncated]");
353
	    strcat(buf, " [... truncated]");
338
	if(R_ShowCalls && call != R_NilValue) {
354
	if(R_ShowWarnCalls && call != R_NilValue) {
339
	    tr =  R_ConciseTraceback(call, 0); nc = strlen(tr);
355
	    tr =  R_ConciseTraceback(call, 0); nc = strlen(tr);
340
	    if (nc && nc + strlen(buf) + 8 < BUFSIZE) {
356
	    if (nc && nc + strlen(buf) + 8 < BUFSIZE) {
341
		strcat(buf, "\nCalls: "); 
357
		strcat(buf, "\nCalls: "); 
342
		strcat(buf, tr);
358
		strcat(buf, tr);
343
	    }
359
	    }
Line 427... Line 443...
427
	    if (mbcslocale) {
443
	    if (mbcslocale) {
428
		int msgline1;
444
		int msgline1;
429
		char *p = strchr(msg, '\n');
445
		char *p = strchr(msg, '\n');
430
		if (p) {
446
		if (p) {
431
		    *p = '\0';
447
		    *p = '\0';
432
		    msgline1 = mbstowcs(NULL, msg, 0);
448
		    msgline1 = wd(msg);
433
		    *p = '\n';
449
		    *p = '\n';
434
		} else msgline1 = mbstowcs(NULL, msg, 0);
450
		} else msgline1 = wd(msg);
435
		if (6+mbstowcs(NULL, dcall, 0) + msgline1
-
 
436
		    > LONGWARN) sep = "\n  ";
451
		if (6 + wd(dcall) + msgline1 > LONGWARN) sep = "\n  ";
437
	    } else
452
	    } else
438
#endif
453
#endif
439
	    {
454
	    {
440
		int msgline1 = strlen(msg);
455
		int msgline1 = strlen(msg);
441
		char *p = strchr(msg, '\n');
456
		char *p = strchr(msg, '\n');
Line 458... Line 473...
458
		if (mbcslocale) {
473
		if (mbcslocale) {
459
		    int msgline1;
474
		    int msgline1;
460
		    char *p = strchr(msg, '\n');
475
		    char *p = strchr(msg, '\n');
461
		    if (p) {
476
		    if (p) {
462
			*p = '\0';
477
			*p = '\0';
463
			msgline1 = mbstowcs(NULL, msg, 0);
478
			msgline1 = wd(msg);
464
			*p = '\n';
479
			*p = '\n';
465
		    } else msgline1 = mbstowcs(NULL, msg, 0);
480
		    } else msgline1 = wd(msg);
466
		    if (10+mbstowcs(NULL, dcall, 0) + msgline1
-
 
467
			> LONGWARN) sep = "\n  ";
481
		    if (10 + wd(dcall) + msgline1 > LONGWARN) sep = "\n  ";
468
		} else
482
		} else
469
#endif
483
#endif
470
		{
484
		{
471
		    int msgline1 = strlen(msg);
485
		    int msgline1 = strlen(msg);
472
		    char *p = strchr(msg, '\n');
486
		    char *p = strchr(msg, '\n');
Line 562... Line 576...
562
	    if (mbcslocale) {
576
	    if (mbcslocale) {
563
		int msgline1;
577
		int msgline1;
564
		char *p = strchr(tmp, '\n');
578
		char *p = strchr(tmp, '\n');
565
		if (p) {
579
		if (p) {
566
		    *p = '\0';
580
		    *p = '\0';
567
		    msgline1 = mbstowcs(NULL, tmp, 0);
581
		    msgline1 = wd(tmp);
568
		    *p = '\n';
582
		    *p = '\n';
569
		} else msgline1 = mbstowcs(NULL, tmp, 0);
583
		} else msgline1 = wd(tmp);
570
		if (14+mbstowcs(NULL, dcall, 0) + mbstowcs(NULL, tmp, 0)
-
 
571
		    > LONGWARN) strcat(errbuf, tail);
584
		if (14 + wd(dcall) + wd(tmp) > LONGWARN) strcat(errbuf, tail);
572
	    } else
585
	    } else
573
#endif
586
#endif
574
	    {
587
	    {
575
		int msgline1 = strlen(tmp);
588
		int msgline1 = strlen(tmp);
576
		char *p = strchr(tmp, '\n');
589
		char *p = strchr(tmp, '\n');
Line 591... Line 604...
591
    }
604
    }
592
    
605
    
593
    p = errbuf + strlen(errbuf) - 1;
606
    p = errbuf + strlen(errbuf) - 1;
594
    if(*p != '\n') strcat(errbuf, "\n");
607
    if(*p != '\n') strcat(errbuf, "\n");
595
 
608
 
596
    if(R_ShowCalls && call != R_NilValue) {  /* assume we want to avoid deparse */
609
    if(R_ShowErrorCalls && call != R_NilValue) {  /* assume we want to avoid deparse */
597
	tr = R_ConciseTraceback(call, 0); nc = strlen(tr);
610
	tr = R_ConciseTraceback(call, 0); nc = strlen(tr);
598
	if (nc && nc + strlen(errbuf) + 8 < BUFSIZE) {
611
	if (nc && nc + strlen(errbuf) + 8 < BUFSIZE) {
599
	    strcat(errbuf, "Calls: ");
612
	    strcat(errbuf, "Calls: ");
600
	    strcat(errbuf, tr);
613
	    strcat(errbuf, tr);
601
	    strcat(errbuf, "\n");
614
	    strcat(errbuf, "\n");
Line 1258... Line 1271...
1258
	    }
1271
	    }
1259
	}
1272
	}
1260
    UNPROTECT(1);
1273
    UNPROTECT(1);
1261
    return s;
1274
    return s;
1262
}
1275
}
1263
 
1276
\
1264
static char * R_ConciseTraceback(SEXP call, int skip)
1277
static char * R_ConciseTraceback(SEXP call, int skip)
1265
{
1278
{
1266
    static char buf[260];
1279
    static char buf[560];
1267
    RCNTXT *c;
1280
    RCNTXT *c;
1268
    int nl, ncalls = 0;
1281
    int nl, ncalls = 0;
1269
    Rboolean too_many = FALSE;
1282
    Rboolean too_many = FALSE;
1270
    const char *top = "" /* -Wall */;
1283
    const char *top = "" /* -Wall */;
1271
 
1284
 
Line 1287... Line 1300...
1287
		    buf[0] =  '\0'; ncalls = 0; too_many = FALSE;
1300
		    buf[0] =  '\0'; ncalls = 0; too_many = FALSE;
1288
		} else {
1301
		} else {
1289
		    ncalls++;
1302
		    ncalls++;
1290
		    if(too_many) {
1303
		    if(too_many) {
1291
			top = this;
1304
			top = this;
1292
		    } else if(strlen(buf) > 200) {
1305
		    } else if(strlen(buf) > R_NShowCalls) {
1293
			memmove(buf+4, buf, strlen(buf)+1);
1306
			memmove(buf+4, buf, strlen(buf)+1);
1294
			memcpy(buf, "... ", 4);
1307
			memcpy(buf, "... ", 4);
1295
			too_many = TRUE;
1308
			too_many = TRUE;
1296
			top = this;
1309
			top = this;
1297
		    } else if(strlen(buf)) {
1310
		    } else if(strlen(buf)) {