The R Project SVN R

Rev

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

Rev 34073 Rev 34099
Line 26... Line 26...
26
 *
26
 *
27
 *  See ./format.c	 for the  format_FOO_  functions used below.
27
 *  See ./format.c	 for the  format_FOO_  functions used below.
28
 */
28
 */
29
 
29
 
30
/* <UTF8> char here is handled as a whole, 
30
/* <UTF8> char here is handled as a whole, 
31
   but lengths are used as display widths */
31
   but lengths were used as display widths */
32
 
32
 
33
#ifdef HAVE_CONFIG_H
33
#ifdef HAVE_CONFIG_H
34
#include <config.h>
34
#include <config.h>
35
#endif
35
#endif
36
 
36
 
37
#include "Defn.h"
37
#include "Defn.h"
38
#include "Print.h"
38
#include "Print.h"
39
 
39
 
40
/* We need display width of a string */
40
/* We need display width of a string */
41
 
-
 
42
 
-
 
43
#ifdef SUPPORT_MBCS
-
 
44
 
-
 
45
#ifdef HAVE_ALLOCA_H
-
 
46
#include <alloca.h>
-
 
47
#endif
-
 
48
#if !HAVE_DECL_ALLOCA
-
 
49
extern char *alloca(size_t);
-
 
50
#endif
-
 
51
 
-
 
52
# include <wchar.h>
-
 
53
# include <wctype.h>
-
 
54
#if !HAVE_DECL_WCSWIDTH
-
 
55
extern int wcswidth(const wchar_t *s, size_t n);
41
int Rstrwid(char *str, int slen, int quote);  /* from printutils.c */
56
#endif
-
 
57
#endif
-
 
58
 
-
 
59
static int strwidth(const char *str)
42
#define strwidth(x) Rstrwid(x, strlen(x), 0)
60
{
-
 
61
#ifdef SUPPORT_MBCS
-
 
62
    if(mbcslocale) {
-
 
63
	int nc = mbstowcs(NULL, str, 0);
-
 
64
#ifdef HAVE_WCSWIDTH
-
 
65
	wchar_t *wc;
-
 
66
	if(nc == 0) return 0;
-
 
67
	wc = (wchar_t *) alloca((nc+1) * sizeof(wchar_t));
-
 
68
	if(!wc) error(_("allocation failure in strwidth"));
-
 
69
	mbstowcs(wc, str, nc + 1);
-
 
70
	return wcswidth(wc, 2147483647);
-
 
71
#else
-
 
72
	return nc;
-
 
73
#endif
-
 
74
    } else
-
 
75
#endif
-
 
76
	return strlen(str);
-
 
77
}
-
 
78
 
-
 
79
 
43
 
80
static void printLogicalMatrix(SEXP sx, int offset, int r, int c,
44
static void printLogicalMatrix(SEXP sx, int offset, int r, int c,
81
			       SEXP rl, SEXP cl, char *rn, char *cn)
45
			       SEXP rl, SEXP cl, char *rn, char *cn)
82
{
46
{
83
    SEXP sw;
47
    SEXP sw;