The R Project SVN R

Rev

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

Rev 48811 Rev 49591
Line 277... Line 277...
277
static void reset_inWarning(void *data)
277
static void reset_inWarning(void *data)
278
{
278
{
279
    inWarning = 0;
279
    inWarning = 0;
280
}
280
}
281
 
281
 
282
#ifdef SUPPORT_MBCS
-
 
283
#include <R_ext/rlocale.h>
282
#include <R_ext/rlocale.h>
284
 
283
 
285
static int wd(const char * buf)
284
static int wd(const char * buf)
286
{
285
{
287
    int nc = mbstowcs(NULL, buf, 0), nw;
286
    int nc = mbstowcs(NULL, buf, 0), nw;
Line 291... Line 290...
291
	nw = Ri18n_wcswidth(wc, 2147483647);
290
	nw = Ri18n_wcswidth(wc, 2147483647);
292
	return (nw < 1) ? nc : nw;
291
	return (nw < 1) ? nc : nw;
293
    }
292
    }
294
    return nc;
293
    return nc;
295
}
294
}
296
#endif
-
 
297
 
295
 
298
static void vwarningcall_dflt(SEXP call, const char *format, va_list ap)
296
static void vwarningcall_dflt(SEXP call, const char *format, va_list ap)
299
{
297
{
300
    int w;
298
    int w;
301
    SEXP names, s;
299
    SEXP names, s;
Line 350... Line 348...
350
	Rvsnprintf(buf, min(BUFSIZE, R_WarnLength+1), format, ap);
348
	Rvsnprintf(buf, min(BUFSIZE, R_WarnLength+1), format, ap);
351
	if(R_WarnLength < BUFSIZE - 20 && strlen(buf) == R_WarnLength)
349
	if(R_WarnLength < BUFSIZE - 20 && strlen(buf) == R_WarnLength)
352
	    strcat(buf, " [... truncated]");
350
	    strcat(buf, " [... truncated]");
353
	if(dcall[0] == '\0')
351
	if(dcall[0] == '\0')
354
	    REprintf(_("Warning: %s\n"), buf);
352
	    REprintf(_("Warning: %s\n"), buf);
355
#ifdef SUPPORT_MBCS
-
 
356
	else if(mbcslocale &&
353
	else if(mbcslocale &&
357
		18 + wd(dcall) + wd(buf) <= LONGWARN)
354
		18 + wd(dcall) + wd(buf) <= LONGWARN)
358
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
355
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
359
#endif
-
 
360
	else if(18+strlen(dcall)+strlen(buf) <= LONGWARN)
356
	else if(18+strlen(dcall)+strlen(buf) <= LONGWARN)
361
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
357
	    REprintf(_("Warning in %s : %s\n"), dcall, buf);
362
	else
358
	else
363
	    REprintf(_("Warning in %s :\n  %s\n"), dcall, buf);
359
	    REprintf(_("Warning in %s :\n  %s\n"), dcall, buf);
364
	if(R_ShowWarnCalls && call != R_NilValue) {
360
	if(R_ShowWarnCalls && call != R_NilValue) {
Line 461... Line 457...
461
	if( VECTOR_ELT(R_Warnings, 0) == R_NilValue )
457
	if( VECTOR_ELT(R_Warnings, 0) == R_NilValue )
462
	   REprintf("%s \n", CHAR(STRING_ELT(names, 0)));
458
	   REprintf("%s \n", CHAR(STRING_ELT(names, 0)));
463
	else {
459
	else {
464
	    const char *dcall, *sep = " ", *msg = CHAR(STRING_ELT(names, 0));
460
	    const char *dcall, *sep = " ", *msg = CHAR(STRING_ELT(names, 0));
465
	    dcall = CHAR(STRING_ELT(deparse1s(VECTOR_ELT(R_Warnings, 0)), 0));
461
	    dcall = CHAR(STRING_ELT(deparse1s(VECTOR_ELT(R_Warnings, 0)), 0));
466
#ifdef SUPPORT_MBCS
-
 
467
	    if (mbcslocale) {
462
	    if (mbcslocale) {
468
		int msgline1;
463
		int msgline1;
469
		char *p = strchr(msg, '\n');
464
		char *p = strchr(msg, '\n');
470
		if (p) {
465
		if (p) {
471
		    *p = '\0';
466
		    *p = '\0';
472
		    msgline1 = wd(msg);
467
		    msgline1 = wd(msg);
473
		    *p = '\n';
468
		    *p = '\n';
474
		} else msgline1 = wd(msg);
469
		} else msgline1 = wd(msg);
475
		if (6 + wd(dcall) + msgline1 > LONGWARN) sep = "\n  ";
470
		if (6 + wd(dcall) + msgline1 > LONGWARN) sep = "\n  ";
476
	    } else
471
	    } else {
477
#endif
-
 
478
	    {
-
 
479
		int msgline1 = strlen(msg);
472
		int msgline1 = strlen(msg);
480
		char *p = strchr(msg, '\n');
473
		char *p = strchr(msg, '\n');
481
		if (p) msgline1 = (int)(p - msg);
474
		if (p) msgline1 = (int)(p - msg);
482
		if (6+strlen(dcall) + msgline1 > LONGWARN) sep = "\n  ";
475
		if (6+strlen(dcall) + msgline1 > LONGWARN) sep = "\n  ";
483
	    }
476
	    }
Line 490... Line 483...
490
	    if( VECTOR_ELT(R_Warnings, i) == R_NilValue )
483
	    if( VECTOR_ELT(R_Warnings, i) == R_NilValue )
491
		REprintf("%d: %s \n", i+1, CHAR(STRING_ELT(names, i)));
484
		REprintf("%d: %s \n", i+1, CHAR(STRING_ELT(names, i)));
492
	    else {
485
	    else {
493
		const char *dcall, *sep = " ", *msg = CHAR(STRING_ELT(names, i));
486
		const char *dcall, *sep = " ", *msg = CHAR(STRING_ELT(names, i));
494
		dcall = CHAR(STRING_ELT(deparse1s(VECTOR_ELT(R_Warnings, i)), 0));
487
		dcall = CHAR(STRING_ELT(deparse1s(VECTOR_ELT(R_Warnings, i)), 0));
495
#ifdef SUPPORT_MBCS
-
 
496
		if (mbcslocale) {
488
		if (mbcslocale) {
497
		    int msgline1;
489
		    int msgline1;
498
		    char *p = strchr(msg, '\n');
490
		    char *p = strchr(msg, '\n');
499
		    if (p) {
491
		    if (p) {
500
			*p = '\0';
492
			*p = '\0';
501
			msgline1 = wd(msg);
493
			msgline1 = wd(msg);
502
			*p = '\n';
494
			*p = '\n';
503
		    } else msgline1 = wd(msg);
495
		    } else msgline1 = wd(msg);
504
		    if (10 + wd(dcall) + msgline1 > LONGWARN) sep = "\n  ";
496
		    if (10 + wd(dcall) + msgline1 > LONGWARN) sep = "\n  ";
505
		} else
497
		} else {
506
#endif
-
 
507
		{
-
 
508
		    int msgline1 = strlen(msg);
498
		    int msgline1 = strlen(msg);
509
		    char *p = strchr(msg, '\n');
499
		    char *p = strchr(msg, '\n');
510
		    if (p) msgline1 = (int)(p - msg);
500
		    if (p) msgline1 = (int)(p - msg);
511
		    if (10+strlen(dcall) + msgline1 > LONGWARN) sep = "\n  ";
501
		    if (10+strlen(dcall) + msgline1 > LONGWARN) sep = "\n  ";
512
		}
502
		}
Line 593... Line 583...
593
 
583
 
594
	Rvsnprintf(tmp, min(BUFSIZE, R_WarnLength) - strlen(head), format, ap);
584
	Rvsnprintf(tmp, min(BUFSIZE, R_WarnLength) - strlen(head), format, ap);
595
	dcall = CHAR(STRING_ELT(deparse1s(call), 0));
585
	dcall = CHAR(STRING_ELT(deparse1s(call), 0));
596
	if (len + strlen(dcall) + strlen(tmp) < BUFSIZE) {
586
	if (len + strlen(dcall) + strlen(tmp) < BUFSIZE) {
597
	    sprintf(errbuf, "%s%s%s", head, dcall, mid);
587
	    sprintf(errbuf, "%s%s%s", head, dcall, mid);
598
#ifdef SUPPORT_MBCS
-
 
599
	    if (mbcslocale) {
588
	    if (mbcslocale) {
600
		int msgline1;
589
		int msgline1;
601
		char *p = strchr(tmp, '\n');
590
		char *p = strchr(tmp, '\n');
602
		if (p) {
591
		if (p) {
603
		    *p = '\0';
592
		    *p = '\0';
604
		    msgline1 = wd(tmp);
593
		    msgline1 = wd(tmp);
605
		    *p = '\n';
594
		    *p = '\n';
606
		} else msgline1 = wd(tmp);
595
		} else msgline1 = wd(tmp);
607
		if (14 + wd(dcall) + wd(tmp) > LONGWARN) strcat(errbuf, tail);
596
		if (14 + wd(dcall) + wd(tmp) > LONGWARN) strcat(errbuf, tail);
608
	    } else
597
	    } else {
609
#endif
-
 
610
	    {
-
 
611
		int msgline1 = strlen(tmp);
598
		int msgline1 = strlen(tmp);
612
		char *p = strchr(tmp, '\n');
599
		char *p = strchr(tmp, '\n');
613
		if (p) msgline1 = (int)(p - tmp);
600
		if (p) msgline1 = (int)(p - tmp);
614
		if (14 + strlen(dcall) + msgline1 > LONGWARN)
601
		if (14 + strlen(dcall) + msgline1 > LONGWARN)
615
		    strcat(errbuf, tail);
602
		    strcat(errbuf, tail);