The R Project SVN R

Rev

Rev 36478 | Rev 36512 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 r 1
/*
1058 maechler 2
 *  R : A Computer Language for Statistical Data Analysis
2 r 3
 *  Copyright (C) 1995, 1996  Robert Gentleman and Ross Ihaka
32696 ripley 4
 *  Copyright (C) 1998--2005  The R Development Core Team.
2 r 5
 *
6
 *  This program is free software; you can redistribute it and/or modify
7
 *  it under the terms of the GNU General Public License as published by
8
 *  the Free Software Foundation; either version 2 of the License, or
9
 *  (at your option) any later version.
10
 *
11
 *  This program is distributed in the hope that it will be useful,
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 *  GNU General Public License for more details.
15
 *
16
 *  You should have received a copy of the GNU General Public License
17
 *  along with this program; if not, write to the Free Software
5458 ripley 18
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
2 r 19
 */
20
 
21
#ifndef DEFN_H_
22
#define DEFN_H_
23
 
36498 ripley 24
#if defined(HAVE_GLIBC2)
25
/* The first three are the default, according to features.h */
26
# define _SVID_SOURCE 1
27
# define _BSD_SOURCE 1
28
# define _POSIX_SOURCE 1
29
/* add latest POSIX 1003.1 and C99 support */
30
# define _POSIX_C_SOURCE 200112L
31
# define _ISOC99_SOURCE 1
32
#endif
33
 
34
 
2 r 35
#define COUNTING
36
 
26145 luke 37
#define BYTECODE
25524 luke 38
#define NEW_CONDITION_HANDLING
39
 
10172 luke 40
/* To test the write barrier used by the generational collector,
41
   define TESTING_WRITE_BARRIER.  This makes the internal structure of
10865 ripley 42
   SEXPRECs visible only inside of files that explicitly define
10172 luke 43
   USE_RINTERNALS, and all uses of SEXPREC fields that do not go
10865 ripley 44
   through the appropriate functions or macros will become compilation
10172 luke 45
   errors.  Since this does impose a small but noticable performance
10865 ripley 46
   penalty, code that includes Defn.h (or code that explicitly defines
47
   USE_RINTERNALS) can access a SEXPREC's fields directly. */
10718 maechler 48
 
10172 luke 49
#ifndef TESTING_WRITE_BARRIER
50
# define USE_RINTERNALS
51
#endif
52
 
11497 hornik 53
#include <Rinternals.h>		/*-> Arith.h, Complex.h, Error.h, Memory.h
7731 ripley 54
				  PrtUtil.h, Utils.h */
10973 hornik 55
#include "Internal.h"		/* do_FOO */
10889 maechler 56
 
7731 ripley 57
#include "Errormsg.h"
2 r 58
 
10851 hornik 59
/* SunOS 4 is famous for broken header files. */
60
#ifdef SunOS4
61
# ifndef NULL
62
#  define	NULL		0
63
# endif
64
#endif /* SunOS4 */
65
 
18653 ripley 66
#ifdef Win32
67
void R_ProcessEvents(void);
18833 hornik 68
#endif /* Win32 */
18653 ripley 69
 
70
#ifdef Win32
10851 hornik 71
# include <psignal.h>
7731 ripley 72
#else
10851 hornik 73
# include <signal.h>
74
# include <setjmp.h>
7731 ripley 75
#endif
10851 hornik 76
 
77
#ifdef Unix
78
# define OSTYPE      "unix"
79
# define FILESEP     "/"
80
#endif /* Unix */
10865 ripley 81
 
10851 hornik 82
#ifdef Win32
83
# define OSTYPE      "windows"
84
# define FILESEP     "/"
85
#endif /* Win32 */
7731 ripley 86
 
10973 hornik 87
#ifdef HAVE_F77_UNDERSCORE
88
# define F77_SYMBOL(x)	x ## _
12256 pd 89
# define F77_QSYMBOL(x)	#x "_"
10973 hornik 90
#else
91
# define F77_SYMBOL(x)	x
92
# define F77_QSYMBOL(x) #x
93
#endif
10851 hornik 94
 
1893 ihaka 95
/*  Heap and Pointer Protection Stack Sizes.  */
2 r 96
 
35334 ripley 97
/* These are for future protection: will need to be different on Win64 */
98
typedef unsigned long R_ulong_t;
99
typedef long R_long_t;
100
 
28358 ripley 101
/* NB: will need a 64-bit type, ULONG64 or size_t, for Win64 */
30767 ripley 102
#if defined HAVE_DECL_SIZE_MAX && HAVE_DECL_SIZE_MAX
103
# ifdef HAVE_INTTYPES_H
104
#  include <inttypes.h>
105
# endif
106
# ifdef HAVE_STDINT_H
107
#  include <stdint.h>
108
# endif
109
# ifdef HAVE_LIMITS_H
110
#  include <limits.h>
111
# endif
112
  typedef size_t R_size_t;
113
/* final precaution in case we don't have the right headers */
114
# ifdef SIZE_MAX
115
#  define R_SIZE_T_MAX SIZE_MAX
116
# else
117
#  define R_SIZE_T_MAX ULONG_MAX
118
# endif
119
#else
120
  typedef unsigned long R_size_t;
121
# define R_SIZE_T_MAX ULONG_MAX
122
#endif
20094 ripley 123
 
3609 pd 124
#define Mega 1048576. /* 1 Mega Byte := 2^20 (= 1048576) Bytes */
20104 ripley 125
#define Giga 1073741824. /* 1 Giga Byte := 2^30 Bytes */
1893 ihaka 126
 
3609 pd 127
/*	R_PPSSIZE  The pointer protection stack size  */
4076 maechler 128
/*	R_NSIZE	   The number of cons cells	 */
129
/*	R_VSIZE	   The vector heap size in bytes */
9035 ripley 130
/*  These values are defaults and can be overridden in config.h
7809 ripley 131
    The maxima and minima are in ../unix/sys-common.c */
3609 pd 132
 
2 r 133
#ifndef R_PPSSIZE
35580 maechler 134
#define	R_PPSSIZE	50000L
2 r 135
#endif
136
#ifndef R_NSIZE
7809 ripley 137
#define	R_NSIZE		350000L
2 r 138
#endif
139
#ifndef R_VSIZE
4562 pd 140
#define	R_VSIZE		6291456L
2 r 141
#endif
142
 
3244 ihaka 143
#include <math.h>
464 maechler 144
 
18791 ripley 145
/* declare substitutions */
18792 ripley 146
#if defined(HAVE_DECL_ACOSH) && !HAVE_DECL_ACOSH
18791 ripley 147
extern double acosh(double x);
148
#endif
18792 ripley 149
#if defined(HAVE_DECL_ASINH) && !HAVE_DECL_ASINH
18794 ripley 150
extern double asinh(double x);
18791 ripley 151
#endif
18792 ripley 152
#if defined(HAVE_DECL_ATANH) && !HAVE_DECL_ATANH
18794 ripley 153
extern double atanh(double x);
18791 ripley 154
#endif
18792 ripley 155
#if defined(HAVE_DECL_SNPRINTF) && !HAVE_DECL_SNPRINTF
18791 ripley 156
extern int snprintf (char *s, size_t n, const char *format, ...);
157
#endif
18792 ripley 158
#if defined(HAVE_DECL_STRDUP) && !HAVE_DECL_STRDUP
36478 ripley 159
#undef strdup
18791 ripley 160
extern char *strdup(const char *s1);
161
#endif
18792 ripley 162
#if defined(HAVE_DECL_STRNCASECMP) && !HAVE_DECL_STRNCASECMP
18791 ripley 163
extern int strncasecmp(const char *s1, const char *s2, size_t n);
164
#endif
18792 ripley 165
#if defined(HAVE_DECL_VSNPRINTF) && !HAVE_DECL_VSNPRINTF
18791 ripley 166
extern int vsnprintf (char *str, size_t count, const char *fmt, va_list arg);
167
#endif
168
 
5226 hornik 169
/* Getting the working directory */
170
#if defined(HAVE_GETCWD)
10851 hornik 171
# define R_GETCWD(x, y) getcwd(x, y)
5226 hornik 172
#elif defined(Win32)
10851 hornik 173
# define R_GETCWD(x, y) GetCurrentDirectory(y, x)
5226 hornik 174
#else
10851 hornik 175
# undef R_GETCWD
5226 hornik 176
#endif
177
 
178
/* Maximal length of an entire file name */
179
#if !defined(PATH_MAX)
10851 hornik 180
# if defined(HAVE_SYS_PARAM_H)
181
#  include <sys/param.h>
182
# endif
20896 duncan 183
# if !defined(PATH_MAX)
21039 murdoch 184
#  if defined(MAXPATHLEN)
20896 duncan 185
#    define PATH_MAX MAXPATHLEN
186
#  elif defined(Win32)
187
#    define PATH_MAX 260
21039 murdoch 188
#  else
18561 ripley 189
/* quite possibly unlimited, so we make this large, and test when used */
20896 duncan 190
#    define PATH_MAX 5000
191
#  endif
10851 hornik 192
# endif
5226 hornik 193
#endif
194
 
6098 pd 195
#ifdef HAVE_POSIX_SETJMP
25220 luke 196
# define SIGJMP_BUF sigjmp_buf
197
# define SIGSETJMP(x,s) sigsetjmp(x,s)
198
# define SIGLONGJMP(x,i) siglongjmp(x,i)
6098 pd 199
# define JMP_BUF sigjmp_buf
25226 luke 200
# define SETJMP(x) sigsetjmp(x,0)
6098 pd 201
# define LONGJMP(x,i) siglongjmp(x,i)
202
#else
25220 luke 203
# define SIGJMP_BUF jmp_buf
204
# define SIGSETJMP(x,s) setjmp(x)
205
# define SIGLONGJMP(x,i) longjmp(x,i)
6098 pd 206
# define JMP_BUF jmp_buf
207
# define SETJMP(x) setjmp(x)
208
# define LONGJMP(x,i) longjmp(x,i)
209
#endif
210
 
19066 hornik 211
/* Availability of timing: on Unix, we need times(2).
212
   On Windows and the Mac, we can do without.
213
*/
24069 ripley 214
#if (defined(HAVE_TIMES) || defined(Win32))
19066 hornik 215
# define _R_HAVE_TIMING_ 1
216
#endif
217
 
19500 hornik 218
#include <R_ext/Rdynload.h>
7850 ripley 219
 
5182 ripley 220
#define HSIZE	   4119	/* The size of the hash table for symbols */
4076 maechler 221
#define MAXELTSIZE 8192 /* The largest string size */
2467 maechler 222
#define MAXIDSIZE   256	/* Largest symbol size possible */
2 r 223
 
1893 ihaka 224
/* The type of the do_xxxx functions. */
225
/* These are the built-in R functions. */
2 r 226
typedef SEXP (*CCODE)();
227
 
10893 maechler 228
/* Information for Deparsing Expressions */
229
typedef enum {
230
    PP_ASSIGN   =  1,
231
    PP_ASSIGN2  =  2,
232
    PP_BINARY   =  3,
233
    PP_BINARY2  =  4,
234
    PP_BREAK    =  5,
235
    PP_CURLY    =  6,
236
    PP_FOR      =  7,
237
    PP_FUNCALL  =  8,
238
    PP_FUNCTION =  9,
239
    PP_IF 	= 10,
240
    PP_NEXT 	= 11,
241
    PP_PAREN    = 12,
242
    PP_RETURN   = 13,
243
    PP_SUBASS   = 14,
244
    PP_SUBSET   = 15,
245
    PP_WHILE 	= 16,
246
    PP_UNARY 	= 17,
247
    PP_DOLLAR 	= 18,
248
    PP_FOREIGN 	= 19,
249
    PP_REPEAT 	= 20
21039 murdoch 250
} PPkind;
251
 
252
typedef enum {
253
    PREC_FN	 = 0,
254
    PREC_LEFT    = 1,
255
    PREC_EQ	 = 2,
256
    PREC_RIGHT	 = 3,
257
    PREC_TILDE	 = 4,
258
    PREC_OR	 = 5,
259
    PREC_AND	 = 6,
260
    PREC_NOT	 = 7,
261
    PREC_COMPARE = 8,
262
    PREC_SUM	 = 9,
263
    PREC_PROD	 = 10,
264
    PREC_PERCENT = 11,
265
    PREC_COLON	 = 12,
266
    PREC_SIGN	 = 13,
267
    PREC_POWER	 = 14,
268
    PREC_DOLLAR  = 15,
269
    PREC_NS	 = 16,
270
    PREC_SUBSET	 = 17
271
} PPprec;
272
 
273
typedef struct {
274
	PPkind kind; 	 /* deparse kind */
275
	PPprec precedence; /* operator precedence */
276
	unsigned int rightassoc;  /* right associative? */
10893 maechler 277
} PPinfo;
1893 ihaka 278
 
279
/* The type definitions for the table of built-in functions. */
280
/* This table can be found in ../main/names.c */
2 r 281
typedef struct {
1893 ihaka 282
    char   *name;    /* print name */
283
    CCODE  cfun;     /* c-code address */
284
    int	   code;     /* offset within c-code */
285
    int	   eval;     /* evaluate args? */
286
    int	   arity;    /* function arity */
10893 maechler 287
    PPinfo gram;     /* pretty-print info */
2 r 288
} FUNTAB;
289
 
10172 luke 290
#ifdef USE_RINTERNALS
1893 ihaka 291
/* General Cons Cell Attributes */
2 r 292
#define ATTRIB(x)	((x)->attrib)
293
#define OBJECT(x)	((x)->sxpinfo.obj)
294
#define MARK(x)		((x)->sxpinfo.mark)
295
#define TYPEOF(x)	((x)->sxpinfo.type)
296
#define NAMED(x)	((x)->sxpinfo.named)
297
 
1893 ihaka 298
/* Primitive Access Macros */
2 r 299
#define PRIMOFFSET(x)	((x)->u.primsxp.offset)
300
#define PRIMFUN(x)	(R_FunTab[(x)->u.primsxp.offset].cfun)
301
#define PRIMNAME(x)	(R_FunTab[(x)->u.primsxp.offset].name)
302
#define PRIMVAL(x)	(R_FunTab[(x)->u.primsxp.offset].code)
303
#define PRIMARITY(x)	(R_FunTab[(x)->u.primsxp.offset].arity)
304
#define PPINFO(x)	(R_FunTab[(x)->u.primsxp.offset].gram)
305
#define PRIMPRINT(x)	(((R_FunTab[(x)->u.primsxp.offset].eval)/100)%10)
306
 
1893 ihaka 307
/* Promise Access Macros */
26020 luke 308
#define PRCODE(x)	((x)->u.promsxp.expr)
2 r 309
#define PRENV(x)	((x)->u.promsxp.env)
310
#define PRVALUE(x)	((x)->u.promsxp.value)
311
#define PRSEEN(x)	((x)->sxpinfo.gp)
10172 luke 312
#ifndef USE_WRITE_BARRIER
10851 hornik 313
# define SET_PRENV(x,v)	  (((x)->u.promsxp.env)=(v))
314
# define SET_PRVALUE(x,v) (((x)->u.promsxp.value)=(v))
10172 luke 315
#endif
316
#define SET_PRSEEN(x,v)	(((x)->sxpinfo.gp)=(v))
2 r 317
 
8456 rgentlem 318
/* Hashing Macros */
319
#define HASHASH(x)      ((x)->sxpinfo.gp)
10869 luke 320
#define HASHVALUE(x)    TRUELENGTH(x)
10172 luke 321
#define SET_HASHASH(x,v) (((x)->sxpinfo.gp)=(v))
10869 luke 322
#define SET_HASHVALUE(x,v) SET_TRUELENGTH(x, v)
2 r 323
 
1893 ihaka 324
/* Vector Heap Structure */
2 r 325
typedef struct {
326
	union {
327
		SEXP		backpointer;
328
		double		align;
329
	} u;
330
} VECREC, *VECP;
331
 
1893 ihaka 332
/* Vector Heap Macros */
2 r 333
#define BACKPOINTER(v)	((v).u.backpointer)
334
#define BYTE2VEC(n)	(((n)>0)?(((n)-1)/sizeof(VECREC)+1):0)
335
#define INT2VEC(n)	(((n)>0)?(((n)*sizeof(int)-1)/sizeof(VECREC)+1):0)
336
#define FLOAT2VEC(n)	(((n)>0)?(((n)*sizeof(double)-1)/sizeof(VECREC)+1):0)
6994 pd 337
#define COMPLEX2VEC(n)	(((n)>0)?(((n)*sizeof(Rcomplex)-1)/sizeof(VECREC)+1):0)
2 r 338
#define PTR2VEC(n)	(((n)>0)?(((n)*sizeof(SEXP)-1)/sizeof(VECREC)+1):0)
10172 luke 339
#else
340
typedef struct VECREC *VECP;
341
#define PRIMFUN(x)	(R_FunTab[PRIMOFFSET(x)].cfun)
342
#define PRIMNAME(x)	(R_FunTab[PRIMOFFSET(x)].name)
343
#define PRIMVAL(x)	(R_FunTab[PRIMOFFSET(x)].code)
344
#define PRIMARITY(x)	(R_FunTab[PRIMOFFSET(x)].arity)
345
#define PPINFO(x)	(R_FunTab[PRIMOFFSET(x)].gram)
346
#define PRIMPRINT(x)	(((R_FunTab[PRIMOFFSET(x)].eval)/100)%10)
347
#endif
2 r 348
 
26025 luke 349
#ifdef BYTECODE
350
# ifdef BC_INT_STACK
351
typedef union { void *p; int i; } IStackval;
352
# endif
353
#endif
354
 
1893 ihaka 355
/* Evaluation Context Structure */
2 r 356
typedef struct RCNTXT {
1893 ihaka 357
    struct RCNTXT *nextcontext;	/* The next context up the chain */
358
    int callflag;		/* The context "type" */
3090 ihaka 359
    JMP_BUF cjmpbuf;		/* C stack and register information */
1893 ihaka 360
    int cstacktop;		/* Top of the pointer protection stack */
8230 rgentlem 361
    int evaldepth;	        /* evaluation depth at inception */
1893 ihaka 362
    SEXP promargs;		/* Promises supplied to closure */
23463 luke 363
    SEXP callfun;		/* The closure called */
1893 ihaka 364
    SEXP sysparent;		/* environment the closure was called from */
365
    SEXP call;			/* The call that effected this context*/
366
    SEXP cloenv;		/* The environment */
367
    SEXP conexit;		/* Interpreted "on.exit" code */
14561 luke 368
    void (*cend)(void *);	/* C "on.exit" thunk */
369
    void *cenddata;		/* data for C "on.exit" thunk */
14480 luke 370
    char *vmax;		        /* top of R_alloc stack */
25200 luke 371
    int intsusp;                /* interrupts enables */
25523 luke 372
#ifdef NEW_CONDITION_HANDLING
373
    SEXP handlerstack;          /* condition handler stack */
374
    SEXP restartstack;          /* stack of available restarts */
375
#endif
26025 luke 376
#ifdef BYTECODE
377
    SEXP *nodestack;
378
# ifdef BC_INT_STACK
379
    IStackval *intstack;
380
# endif
381
#endif
2 r 382
} RCNTXT, *context;
383
 
6193 maechler 384
/* The Various Context Types.
6188 rgentlem 385
 
6193 maechler 386
 * In general the type is a bitwise OR of the values below.
387
 * Note that CTXT_LOOP is already the or of CTXT_NEXT and CTXT_BREAK.
388
 * Only functions should have the third bit turned on;
389
 * this allows us to move up the context stack easily
390
 * with either RETURN's or GENERIC's or RESTART's.
391
 * If you add a new context type for functions make sure
392
 *   CTXT_NEWTYPE & CTXT_FUNCTION > 0
393
 */
2 r 394
enum {
1893 ihaka 395
    CTXT_TOPLEVEL = 0,
2423 maechler 396
    CTXT_NEXT	  = 1,
397
    CTXT_BREAK	  = 2,
398
    CTXT_LOOP	  = 3,	/* break OR next target */
6188 rgentlem 399
    CTXT_FUNCTION = 4,
2423 maechler 400
    CTXT_CCODE	  = 8,
6188 rgentlem 401
    CTXT_RETURN	  = 12,
402
    CTXT_BROWSER  = 16,
403
    CTXT_GENERIC  = 20,
14631 luke 404
    CTXT_RESTART  = 32,
405
    CTXT_BUILTIN  = 64  /* used in profiling */
2 r 406
};
407
 
6188 rgentlem 408
/*
409
TOP   0 0 0 0 0 0  = 0
410
NEX   1 0 0 0 0 0  = 1
411
BRE   0 1 0 0 0 0  = 2
412
LOO   1 1 0 0 0 0  = 3
413
FUN   0 0 1 0 0 0  = 4
414
CCO   0 0 0 1 0 0  = 8
415
BRO   0 0 0 0 1 0  = 16
416
RET   0 0 1 1 0 0  = 12
417
GEN   0 0 1 0 1 0  = 20
14631 luke 418
RES   0 0 0 0 0 0 1 = 32
419
BUI   0 0 0 0 0 0 0 1 = 64
6188 rgentlem 420
*/
14631 luke 421
 
422
#define IS_RESTART_BIT_SET(flags) ((flags) & CTXT_RESTART)
423
#define SET_RESTART_BIT_ON(flags) (flags |= CTXT_RESTART)
424
#define SET_RESTART_BIT_OFF(flags) (flags &= ~CTXT_RESTART)
425
 
1893 ihaka 426
/* Miscellaneous Definitions */
2 r 427
#define streql(s, t)	(!strcmp((s), (t)))
428
 
1893 ihaka 429
/* Arithmetic and Relation Operators */
10718 maechler 430
typedef enum {
431
    PLUSOP = 1,
432
    MINUSOP,
433
    TIMESOP,
434
    DIVOP,
435
    POWOP,
436
    MODOP,
437
    IDIVOP
438
} ARITHOP_TYPE;
2 r 439
 
10718 maechler 440
typedef enum {
441
    EQOP = 1,
442
    NEOP,
443
    LTOP,
444
    LEOP,
445
    GEOP,
446
    GTOP
447
} RELOP_TYPE;
2 r 448
 
2467 maechler 449
/* File Handling */
6412 pd 450
/*
2467 maechler 451
#define R_EOF	65535
6412 pd 452
*/
453
#define R_EOF	-1
2432 maechler 454
 
2467 maechler 455
/* MAGIC Numbers for files */
456
#define R_MAGIC_BINARY 1975
457
#define R_MAGIC_ASCII  1976
458
#define R_MAGIC_XDR    1977
2 r 459
 
2467 maechler 460
#define R_MAGIC_BINARY_VERSION16 1971
461
#define R_MAGIC_ASCII_VERSION16	 1972
462
 
463
 
464
/*--- Global Variables ---------------------------------------------------- */
465
 
4622 maechler 466
/* Defined and initialized in names.c (not main.c) :*/
467
#ifndef __R_Names__
4709 maechler 468
extern
4622 maechler 469
#endif
470
FUNTAB	R_FunTab[];	    /* Built in functions */
471
 
472
 
15716 ripley 473
#include <R_ext/libextern.h>
474
 
4622 maechler 475
#ifdef __MAIN__
19066 hornik 476
# define INI_as(v) = v
4622 maechler 477
#else
19066 hornik 478
# define INI_as(v)
4622 maechler 479
#endif
480
 
6994 pd 481
/* extern int	errno; already have errno.h ! */
6262 pd 482
extern int	gc_inhibit_torture INI_as(1);
2467 maechler 483
 
25200 luke 484
LibExtern Rboolean R_interrupts_suspended INI_as(FALSE);
25212 luke 485
LibExtern int R_interrupts_pending INI_as(0);
25200 luke 486
 
3094 r 487
/* R Home Directory */
32258 ripley 488
LibExtern char*	R_Home;		    /* Root of the R tree */
3094 r 489
 
1893 ihaka 490
/* Memory Management */
20094 ripley 491
extern R_size_t	R_NSize		INI_as(R_NSIZE);/* Size of cons cell heap */
492
extern R_size_t	R_VSize		INI_as(R_VSIZE);/* Size of the vector heap */
1893 ihaka 493
extern SEXP	R_NHeap;	    /* Start of the cons cell heap */
494
extern SEXP	R_FreeSEXP;	    /* Cons cell free list */
20094 ripley 495
extern R_size_t	R_Collected;	    /* Number of free cons cells (after gc) */
15716 ripley 496
LibExtern SEXP	R_PreciousList;	    /* List of Persistent Objects */
497
LibExtern int	R_Is_Running;	    /* for Windows memory manager */
2 r 498
 
1893 ihaka 499
/* The Pointer Protection Stack */
4622 maechler 500
extern int	R_PPStackSize	INI_as(R_PPSSIZE); /* The stack size (elements) */
1893 ihaka 501
extern int	R_PPStackTop;	    /* The top of the stack */
502
extern SEXP*	R_PPStack;	    /* The pointer protection stack */
503
 
504
/* Evaluation Environment */
15716 ripley 505
LibExtern SEXP	R_CurrentExpr;	    /* Currently evaluating expression */
1893 ihaka 506
extern SEXP	R_ReturnedValue;    /* Slot for return-ing values */
507
extern SEXP*	R_SymbolTable;	    /* The symbol table */
17323 ripley 508
LibExtern RCNTXT R_Toplevel;	    /* Storage for the toplevel environment */
509
LibExtern RCNTXT* R_ToplevelContext;  /* The toplevel environment */
510
LibExtern RCNTXT* R_GlobalContext;    /* The global environment */
15716 ripley 511
LibExtern int	R_Visible;	    /* Value visibility flag */
512
LibExtern int	R_EvalDepth	INI_as(0);	/* Evaluation recursion depth */
4622 maechler 513
extern int	R_BrowseLevel	INI_as(0);	/* how deep the browser is */
1893 ihaka 514
 
33670 maechler 515
extern int	R_Expressions	INI_as(5000);	/* options(expressions) */
11139 maechler 516
extern Rboolean	R_KeepSource	INI_as(FALSE);	/* options(keep.source) */
19680 luke 517
extern int	R_UseNamespaceDispatch INI_as(TRUE);
20106 ripley 518
extern int	R_WarnLength	INI_as(1000);	/* Error/warning max length */
35899 ripley 519
extern unsigned long	R_CStackLimit	INI_as(-1);	/* C stack limit */
520
extern unsigned long	R_CStackStart	INI_as(-1);	/* Initial stack address */
35898 ripley 521
extern int	R_CStackDir	INI_as(1);	/* C stack direction */
8552 maechler 522
 
1893 ihaka 523
/* File Input/Output */
15716 ripley 524
LibExtern Rboolean R_Interactive	INI_as(TRUE);	/* TRUE during interactive use*/
10718 maechler 525
extern Rboolean	R_Quiet		INI_as(FALSE);	/* Be as quiet as possible */
526
extern Rboolean	R_Slave		INI_as(FALSE);	/* Run as a slave process */
527
extern Rboolean	R_Verbose	INI_as(FALSE);	/* Be verbose */
1893 ihaka 528
/* extern int	R_Console; */	    /* Console active flag */
4622 maechler 529
/* IoBuffer R_ConsoleIob; : --> ./IOStuff.h */
530
extern FILE*	R_Consolefile	INI_as(NULL);	/* Console output file */
531
extern FILE*	R_Outputfile	INI_as(NULL);	/* Output file */
13852 ripley 532
extern int	R_ErrorCon	INI_as(2);	/* Error connection */
32258 ripley 533
LibExtern char*	R_TempDir	INI_as(NULL);	/* Name of per-session dir */
32564 ripley 534
extern char	R_StdinEnc[31]  INI_as("");	/* Encoding assumed for stdin */
1893 ihaka 535
 
536
/* Objects Used In Parsing  */
537
extern SEXP	R_CommentSxp;	    /* Comments accumulate here */
538
extern SEXP	R_ParseText;	    /* Text to be parsed */
539
extern int	R_ParseCnt;	    /* Count of lines of text to be parsed */
4622 maechler 540
extern int	R_ParseError	INI_as(0); /* Line where parse error occured */
35498 murdoch 541
#define PARSE_CONTEXT_SIZE 256	    /* Recent parse context kept in a circular buffer */
542
extern char	R_ParseContext[PARSE_CONTEXT_SIZE] INI_as("");
543
extern int	R_ParseContextLast INI_as(0); /* last character in context buffer */
1893 ihaka 544
 
545
/* Image Dump/Restore */
4622 maechler 546
extern int	R_DirtyImage	INI_as(0);	/* Current image dirty */
1893 ihaka 547
 
4913 hornik 548
/* History */
15716 ripley 549
LibExtern char*	R_HistoryFile;	/* Name of the history file */
550
LibExtern int	R_HistorySize;	/* Size of the history file */
551
LibExtern int	R_RestoreHistory;	/* restore the history file? */
33483 ripley 552
extern void 	R_setupHistory();
4913 hornik 553
 
4165 rgentlem 554
/* Warnings/Errors */
4622 maechler 555
extern int	R_CollectWarnings INI_as(0);	/* the number of warnings */
556
extern SEXP	R_Warnings;	    /* the warnings and their calls */
9336 maechler 557
extern int	R_ShowErrorMessages INI_as(1);	/* show error messages? */
25523 luke 558
#ifdef NEW_CONDITION_HANDLING
559
extern SEXP	R_HandlerStack;	/* Condition handler stack */
560
extern SEXP	R_RestartStack;	/* Stack of available restarts */
561
#endif
2 r 562
 
32720 ripley 563
LibExtern Rboolean utf8locale  INI_as(FALSE);  /* is this a UTF-8 locale? */
564
LibExtern Rboolean mbcslocale  INI_as(FALSE);  /* is this a MBCS locale? */
28024 ripley 565
 
34294 ripley 566
extern char OutDec	INI_as('.');  /* decimal point used for output */
567
 
29603 iacus 568
/* Initialization of the R environment when it is embedded */
569
extern int Rf_initEmbeddedR(int argc, char **argv);
28024 ripley 570
 
8925 ripley 571
/* GUI type */
572
 
573
extern char*	R_GUIType	INI_as("unknown");
574
 
26025 luke 575
#ifdef BYTECODE
576
#define R_BCNODESTACKSIZE 10000
577
extern SEXP *R_BCNodeStackBase, *R_BCNodeStackTop, *R_BCNodeStackEnd;
578
# ifdef BC_INT_STACK
579
#define R_BCINTSTACKSIZE 10000
580
extern IStackval *R_BCIntStackBase, *R_BCIntStackTop, *R_BCIntStackEnd;
581
# endif
582
#endif
583
 
16707 jmc 584
/* Pointer  type and utilities for dispatch in the methods package */
20088 jmc 585
typedef SEXP (*R_stdGen_ptr_t)(SEXP, SEXP, SEXP); /* typedef */
15938 jmc 586
R_stdGen_ptr_t R_get_standardGeneric_ptr(); /* get method */
26082 jmc 587
R_stdGen_ptr_t R_set_standardGeneric_ptr(R_stdGen_ptr_t, SEXP); /* set method */
26089 luke 588
extern SEXP R_MethodsNamespace;
16707 jmc 589
SEXP R_deferred_default_method();
590
SEXP R_set_prim_method(SEXP fname, SEXP op, SEXP code_vec, SEXP fundef, SEXP mlist);
591
SEXP do_set_prim_method(SEXP op, char *code_string, SEXP fundef, SEXP mlist);
17000 jmc 592
void R_set_quick_method_check(R_stdGen_ptr_t);
20088 jmc 593
SEXP R_primitive_methods(SEXP op);
15908 ripley 594
 
17000 jmc 595
/* slot management (in attrib.c) */
596
SEXP R_do_slot(SEXP obj, SEXP name);
18558 jmc 597
SEXP R_do_slot_assign(SEXP obj, SEXP name, SEXP value);
17000 jmc 598
 
22668 ripley 599
/* smallest decimal exponent, needed in format.c, set in Init_R_Machine */
600
extern int R_dec_min_exponent		INI_as(-308);
601
 
4622 maechler 602
#ifdef __MAIN__
19066 hornik 603
# undef extern
604
# undef LibExtern
4622 maechler 605
#endif
606
#undef INI_as
607
 
608
 
2467 maechler 609
/*--- FUNCTIONS ------------------------------------------------------ */
2 r 610
 
19066 hornik 611
# define begincontext		Rf_begincontext
612
# define checkArity		Rf_checkArity
613
# define CheckFormals		Rf_CheckFormals
614
# define CleanEd		Rf_CleanEd
615
# define DataFrameClass		Rf_DataFrameClass
616
# define ddfindVar		Rf_ddfindVar
617
# define deparse1		Rf_deparse1
618
# define deparse1line		Rf_deparse1line
619
# define DispatchGroup		Rf_DispatchGroup
620
# define DispatchOrEval		Rf_DispatchOrEval
621
# define dynamicfindVar		Rf_dynamicfindVar
29902 ripley 622
# define EncodeRaw              Rf_EncodeRaw
623
# define EncodeString           Rf_EncodeString
19066 hornik 624
# define endcontext		Rf_endcontext
625
# define errorcall		Rf_errorcall
626
# define ErrorMessage		Rf_ErrorMessage
627
# define factorsConform		Rf_factorsConform
628
# define FetchMethod		Rf_FetchMethod
629
# define findcontext		Rf_findcontext
630
# define findVar1		Rf_findVar1
631
# define FrameClassFix		Rf_FrameClassFix
632
# define framedepth		Rf_framedepth
633
# define frameSubscript		Rf_frameSubscript
634
# define get1index		Rf_get1index
635
# define getVar			Rf_getVar
636
# define getVarInFrame		Rf_getVarInFrame
637
# define hashpjw		Rf_hashpjw
638
# define InheritsClass		Rf_InheritsClass
639
# define InitArithmetic		Rf_InitArithmetic
640
# define InitColors		Rf_InitColors
641
# define InitConnections	Rf_InitConnections
642
# define InitEd			Rf_InitEd
643
# define InitFunctionHashing	Rf_InitFunctionHashing
35450 murdoch 644
# define InitBaseEnv		Rf_InitBaseEnv
19066 hornik 645
# define InitGlobalEnv		Rf_InitGlobalEnv
646
# define InitMemory		Rf_InitMemory
647
# define InitNames		Rf_InitNames
648
# define InitOptions		Rf_InitOptions
20669 ripley 649
# define InitTempDir		Rf_InitTempDir
19066 hornik 650
# define initStack		Rf_initStack
651
# define internalTypeCheck	Rf_internalTypeCheck
652
# define isValidName		Rf_isValidName
653
# define jump_to_toplevel	Rf_jump_to_toplevel
654
# define levelsgets		Rf_levelsgets
655
# define mainloop		Rf_mainloop
31101 iacus 656
# define ParseBrowser	Rf_ParseBrowser
19066 hornik 657
# define mat2indsub		Rf_mat2indsub
32530 ripley 658
# define Mbrtowc		Rf_mbrtowc
19066 hornik 659
# define mkCLOSXP		Rf_mkCLOSXP
660
# define mkComplex              Rf_mkComplex
661
# define mkFalse		Rf_mkFalse
662
# define mkFloat		Rf_mkFloat
663
# define mkNA			Rf_mkNA
664
# define mkPROMISE		Rf_mkPROMISE
665
# define mkQUOTE		Rf_mkQUOTE
666
# define mkSYMSXP		Rf_mkSYMSXP
667
# define mkTrue			Rf_mkTrue
668
# define NewEnvironment		Rf_NewEnvironment
669
# define OneIndex		Rf_OneIndex
670
# define onintr			Rf_onintr
671
# define onsigusr1              Rf_onsigusr1
672
# define onsigusr2              Rf_onsigusr2
673
# define parse			Rf_parse
674
# define PrintGreeting		Rf_PrintGreeting
675
# define PrintVersion		Rf_PrintVersion
676
# define PrintWarnings		Rf_PrintWarnings
677
# define promiseArgs		Rf_promiseArgs
678
# define RemoveClass		Rf_RemoveClass
679
# define setVarInFrame		Rf_setVarInFrame
680
# define sortVector		Rf_sortVector
681
# define ssort			Rf_ssort
682
# define str2type		Rf_str2type
683
# define StrToInternal		Rf_StrToInternal
684
# define substituteList		Rf_substituteList
685
# define tsConform		Rf_tsConform
686
# define tspgets		Rf_tspgets
687
# define type2str		Rf_type2str
688
# define type2symbol		Rf_type2symbol
689
# define unbindVar		Rf_unbindVar
690
# define usemethod		Rf_usemethod
691
# define warningcall		Rf_warningcall
692
# define WarningMessage		Rf_WarningMessage
693
# define yyerror		Rf_yyerror
694
# define yyinit			Rf_yyinit
695
# define yylex			Rf_yylex
696
# define yyparse		Rf_yyparse
697
# define yyprompt		Rf_yyprompt
698
# define yywrap			Rf_yywrap
7754 ripley 699
 
1893 ihaka 700
/* Platform Dependent Gui Hooks */
2 r 701
 
702
#define	R_CONSOLE	1
703
#define	R_FILE		2
704
#define R_TEXT		3
705
 
3921 pd 706
int	R_ReadConsole(char*, unsigned char*, int, int);
290 ihaka 707
void	R_WriteConsole(char*, int);
708
void	R_ResetConsole(void);
709
void	R_FlushConsole(void);
710
void	R_ClearerrConsole(void);
711
void	R_Busy(int);
11139 maechler 712
int	R_ShowFiles(int, char **, char **, char *, Rboolean, char *);
29051 murdoch 713
int     R_EditFiles(int, char **, char **, char *);
3656 ihaka 714
int	R_ChooseFile(int, char*, int);
11139 maechler 715
char*	R_Date(void);
3558 r 716
char*	R_HomeDir(void);
11139 maechler 717
Rboolean R_FileExists(char*);
718
Rboolean R_HiddenFile(char*);
24522 luke 719
double	R_FileMtime(char*);
2 r 720
 
16300 luke 721
/* environment cell access */
722
typedef struct R_varloc_st *R_varloc_t;
723
R_varloc_t R_findVarLocInFrame(SEXP, SEXP);
724
SEXP R_GetVarLocValue(R_varloc_t);
725
SEXP R_GetVarLocSymbol(R_varloc_t);
25088 luke 726
Rboolean R_GetVarLocMISSING(R_varloc_t);
16300 luke 727
void R_SetVarLocValue(R_varloc_t, SEXP);
728
 
30225 murdoch 729
/* deparse option bits */
730
 
731
#define KEEPINTEGER 		1
732
#define QUOTEEXPRESSIONS 	2
733
#define SHOWATTRIBUTES 		4
734
#define USESOURCE 		8
735
#define WARNINCOMPLETE 		16
30901 ripley 736
#define DELAYPROMISES 		32
30225 murdoch 737
/* common combinations of the above */
738
#define SIMPLEDEPARSE		0
739
#define FORSOURCING		31
740
 
2810 maechler 741
/* Other Internally Used Functions */
742
 
22926 ripley 743
SEXP Rf_append(SEXP, SEXP); /* apparently unused now */
23463 luke 744
void begincontext(RCNTXT*, int, SEXP, SEXP, SEXP, SEXP, SEXP);
2 r 745
void checkArity(SEXP, SEXP);
746
void CheckFormals(SEXP);
5182 ripley 747
void CleanEd(void);
2 r 748
void DataFrameClass(SEXP);
1916 rgentlem 749
SEXP ddfindVar(SEXP, SEXP);
30225 murdoch 750
SEXP deparse1(SEXP,Rboolean,int);
10718 maechler 751
SEXP deparse1line(SEXP,Rboolean);
16707 jmc 752
int DispatchOrEval(SEXP, SEXP, char*, SEXP, SEXP, SEXP*, int, int);
2 r 753
int DispatchGroup(char*, SEXP,SEXP,SEXP,SEXP,SEXP*);
754
SEXP duplicated(SEXP);
755
SEXP dynamicfindVar(SEXP, RCNTXT*);
756
void endcontext(RCNTXT*);
29578 rgentlem 757
int envlength(SEXP);
2 r 758
int factorsConform(SEXP, SEXP);
7758 ripley 759
SEXP FetchMethod(char *, char *, SEXP);
1258 ihaka 760
void findcontext(int, SEXP, SEXP);
2 r 761
SEXP findVar1(SEXP, SEXP, SEXPTYPE, int);
762
void FrameClassFix(SEXP);
763
int framedepth(RCNTXT*);
764
SEXP frameSubscript(int, SEXP, SEXP);
22883 ripley 765
int get1index(SEXP, SEXP, int, Rboolean, int);
2 r 766
SEXP getVar(SEXP, SEXP);
767
SEXP getVarInFrame(SEXP, SEXP);
768
int hashpjw(char*);
13606 maechler 769
Rboolean InheritsClass(SEXP, char*);
2 r 770
void InitArithmetic(void);
771
void InitColors(void);
11656 ripley 772
void InitConnections(void);
2 r 773
void InitEd(void);
774
void InitFunctionHashing(void);
35450 murdoch 775
void InitBaseEnv(void);
2 r 776
void InitGlobalEnv(void);
21102 jmc 777
Rboolean R_current_trace_state();
17000 jmc 778
Rboolean R_has_methods(SEXP);
2 r 779
void R_InitialData(void);
16764 jmc 780
SEXP R_possible_dispatch(SEXP, SEXP, SEXP, SEXP);
2 r 781
void InitMemory(void);
782
void InitNames(void);
783
void InitOptions(void);
20278 ripley 784
void Init_R_Variables(SEXP);
20669 ripley 785
void InitTempDir(void);
2 r 786
void initStack(void);
25523 luke 787
#ifdef NEW_CONDITION_HANDLING
788
void R_InsertRestartHandlers(RCNTXT *, Rboolean);
789
#endif
2 r 790
void internalTypeCheck(SEXP, SEXP, SEXPTYPE);
23073 ripley 791
Rboolean isMethodsDispatchOn(void);
4622 maechler 792
int isValidName(char *);
25520 luke 793
void R_JumpToContext(RCNTXT *, int, SEXP);
2 r 794
void jump_to_toplevel(void);
795
SEXP levelsgets(SEXP, SEXP);
796
void mainloop(void);
797
SEXP mat2indsub(SEXP, SEXP);
798
SEXP match(SEXP, SEXP, int);
799
SEXP mkCLOSXP(SEXP, SEXP, SEXP);
7758 ripley 800
SEXP mkComplex(char *s);
5124 ihaka 801
/* SEXP mkEnv(SEXP, SEXP, SEXP); */
7758 ripley 802
SEXP mkFalse(void);
803
SEXP mkFloat(char *s);
804
SEXP mkNA(void);
2 r 805
SEXP mkPRIMSXP (int, int);
806
SEXP mkPROMISE(SEXP, SEXP);
807
SEXP mkQUOTE(SEXP);
808
SEXP mkSYMSXP(SEXP, SEXP);
7758 ripley 809
SEXP mkTrue(void);
5124 ihaka 810
SEXP NewEnvironment(SEXP, SEXP, SEXP);
2 r 811
void onintr();
8422 tlumley 812
void onsigusr1();
813
void onsigusr2();
22883 ripley 814
int OneIndex(SEXP, SEXP, int, int, SEXP*, int);
2 r 815
SEXP parse(FILE*, int);
816
void PrintGreeting(void);
5194 ripley 817
void PrintVersion(char *);
4165 rgentlem 818
void PrintWarnings(void);
15427 hornik 819
void process_site_Renviron();
820
void process_system_Renviron();
821
void process_user_Renviron();
2 r 822
SEXP promiseArgs(SEXP, SEXP);
11656 ripley 823
void Rcons_vprintf(const char *, va_list);
7758 ripley 824
void RemoveClass(SEXP, char *);
32148 ripley 825
SEXP R_data_class(SEXP , Rboolean);
826
SEXP R_data_class2(SEXP);
5245 ripley 827
SEXP R_LoadFromFile(FILE*, int);
16242 luke 828
SEXP R_NewHashedEnv(SEXP);
8456 rgentlem 829
extern int R_Newhashpjw(char*);
2467 maechler 830
FILE* R_OpenLibraryFile(char *);
24522 luke 831
char *R_LibraryFileName(char *, char *, size_t);
2 r 832
void R_RestoreGlobalEnv(void);
16803 luke 833
void R_RestoreGlobalEnvFromFile(const char *, Rboolean);
2 r 834
void R_SaveGlobalEnv(void);
16803 luke 835
void R_SaveGlobalEnvToFile(const char *);
11116 ripley 836
void R_SaveToFile(SEXP, FILE*, int);
25087 luke 837
void R_SaveToFileV(SEXP, FILE*, int, int);
15753 jmc 838
SEXP R_set_class(SEXP, SEXP, SEXP);
4229 rgentlem 839
int R_SetOptionWarn(int);
3382 ihaka 840
int R_SetOptionWidth(int);
2467 maechler 841
void R_Suicide(char*);
2 r 842
SEXP setVarInFrame(SEXP, SEXP, SEXP);
18860 ripley 843
void sortVector(SEXP, Rboolean);
2 r 844
void ssort(SEXP*,int);
845
SEXPTYPE str2type(char*);
846
int StrToInternal(char*);
2810 maechler 847
SEXP substituteList(SEXP, SEXP);
571 ihaka 848
SEXP R_syscall(int,RCNTXT*);
849
int R_sysparent(int,RCNTXT*);
850
SEXP R_sysframe(int,RCNTXT*);
851
SEXP R_sysfunction(int,RCNTXT*);
11139 maechler 852
Rboolean tsConform(SEXP,SEXP);
2 r 853
SEXP tspgets(SEXP, SEXP);
854
SEXP type2str(SEXPTYPE);
15459 jmc 855
SEXP type2symbol(SEXPTYPE);
2 r 856
void unbindVar(SEXP, SEXP);
10172 luke 857
#ifdef ALLOW_OLD_SAVE
2 r 858
void unmarkPhase(void);
10172 luke 859
#endif
16335 luke 860
SEXP R_LookupMethod(SEXP, SEXP, SEXP, SEXP);
861
int usemethod(char*, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP, SEXP*);
24734 ripley 862
 
11139 maechler 863
/* ../main/errors.c : */
13997 duncan 864
void errorcall(SEXP, const char*, ...);
865
void warningcall(SEXP, const char*,...);
11139 maechler 866
void ErrorMessage(SEXP, int, ...);
867
void WarningMessage(SEXP, R_WARNING, ...);
25420 luke 868
SEXP R_GetTraceback(int);
11139 maechler 869
 
20094 ripley 870
R_size_t R_GetMaxVSize(void);
871
void R_SetMaxVSize(R_size_t);
872
R_size_t R_GetMaxNSize(void);
873
void R_SetMaxNSize(R_size_t);
874
R_size_t R_Decode2Long(char *p, int *ierr);
35334 ripley 875
void R_SetPPSize(R_size_t);
2467 maechler 876
 
14477 luke 877
void R_run_onexits(RCNTXT *);
14479 luke 878
void R_restore_globals(RCNTXT *);
11139 maechler 879
 
14477 luke 880
 
2467 maechler 881
/* gram.y & gram.c : */
2432 maechler 882
void yyerror(char *);
2 r 883
void yyinit(void);
2432 maechler 884
int yylex();
2 r 885
int yyparse(void);
886
void yyprompt(char *format, ...);
887
int yywrap(void);
888
 
29510 ripley 889
/* ../../main/printutils.c : */
32245 ripley 890
typedef enum {
891
    Rprt_adj_left = 0,
892
    Rprt_adj_right = 1,
35281 ripley 893
    Rprt_adj_centre = 2,
894
    Rprt_adj_none = 3
32245 ripley 895
} Rprt_adj;
896
 
29510 ripley 897
int	Rstrlen(SEXP, int);
29902 ripley 898
char *EncodeRaw(Rbyte);
32245 ripley 899
char *EncodeString(SEXP, int, int, Rprt_adj);
29510 ripley 900
 
35103 ripley 901
/* main/sort.c */
35580 maechler 902
void orderVector1(int *indx, int n, SEXP key, Rboolean nalast,
35103 ripley 903
		  Rboolean decreasing);
32564 ripley 904
 
35103 ripley 905
 
35175 ripley 906
#ifdef SUPPORT_MBCS /* implies we have this header */
32530 ripley 907
#include <wchar.h>
908
#endif
909
 
35826 ripley 910
/* main/util.c */
911
void UNIMPLEMENTED_TYPE(char *s, SEXP x);
912
void UNIMPLEMENTED_TYPEt(char *s, SEXPTYPE t);
913
Rboolean utf8strIsASCII(char *str);
35948 ripley 914
#ifdef SUPPORT_MBCS
35776 ripley 915
typedef unsigned short ucs2_t;
916
size_t mbcsToUcs2(char *in, ucs2_t *out);
917
size_t ucs2ToMbcs(ucs2_t *in, char *out);
35826 ripley 918
size_t mbcsMblen(char *in);
919
size_t ucs2Mblen(ucs2_t *in);
32625 ripley 920
int utf8clen(char c);
32639 ripley 921
#define mbs_init(x) memset(x, 0, sizeof(mbstate_t))
32530 ripley 922
size_t Mbrtowc(wchar_t *wc, const char *s, size_t n, mbstate_t *ps);
32624 ripley 923
void mbcsToLatin1(char *in, char *out);
32725 ripley 924
Rboolean mbcsValid(char *str);
32696 ripley 925
char *Rf_strchr(const char *s, int c);
926
char *Rf_strrchr(const char *s, int c);
927
#else
928
#define Rf_strchr(s, c) strchr(s, c)
929
#define Rf_strrchr(s, c) strrchr(s, c)
32530 ripley 930
#endif
32696 ripley 931
#ifdef Win32
932
void R_fixslash(char *s);
933
void R_fixbackslash(char *s);
32771 ripley 934
#endif
935
#if defined(Win32) && defined(SUPPORT_UTF8)
32720 ripley 936
#define mbrtowc(a,b,c,d) Rmbrtowc(a,b)
937
#define wcrtomb(a,b,c) Rwcrtomb(a,b)
938
#define mbstowcs(a,b,c) Rmbstowcs(a,b,c)
939
#define wcstombs(a,b,c) Rwcstombs(a,b,c)
940
size_t Rmbrtowc(wchar_t *wc, const char *s);
941
size_t Rwcrtomb(char *s, const wchar_t wc);
942
size_t Rmbstowcs(wchar_t *wc, const char *s, size_t n);
943
size_t Rwcstombs(char *s, const wchar_t *wc, size_t n);
32696 ripley 944
#endif
31887 ripley 945
 
35824 ripley 946
/* From localecharset.c */
947
extern char * locale2charset(const char *);
948
 
32787 ripley 949
/* used in relop.c and sort.c */
950
#if defined(Win32) && defined(SUPPORT_UTF8)
951
#define STRCOLL Rstrcoll
952
#else
953
 
954
#ifdef HAVE_STRCOLL
955
#define STRCOLL strcoll
956
#else
957
#define STRCOLL strcmp
958
#endif
959
 
960
#endif
961
 
32832 ripley 962
/* Localization */
32787 ripley 963
 
32832 ripley 964
#ifdef ENABLE_NLS
965
#include <libintl.h>
32878 ripley 966
#ifdef Win32
967
#define _(String) libintl_gettext (String)
968
#undef gettext /* needed for graphapp */
969
#else
32832 ripley 970
#define _(String) gettext (String)
32878 ripley 971
#endif
32832 ripley 972
#define gettext_noop(String) String
973
#define N_(String) gettext_noop (String)
35365 ripley 974
#define P_(StringS, StringP, N) ngettext (StringS, StringP, N)
32878 ripley 975
#else /* not NLS */
32832 ripley 976
#define _(String) (String)
977
#define N_(String) String
35648 ripley 978
#define P_(String, StringP, N) (N > 1 ? StringP: String)
32832 ripley 979
#endif
32787 ripley 980
 
32832 ripley 981
 
8684 luke 982
/* Macros for suspending interrupts */
25200 luke 983
#define BEGIN_SUSPEND_INTERRUPTS do { \
984
    Rboolean __oldsusp__ = R_interrupts_suspended; \
985
    R_interrupts_suspended = TRUE;
986
#define END_SUSPEND_INTERRUPTS R_interrupts_suspended = __oldsusp__; \
25497 luke 987
    if (R_interrupts_pending && ! R_interrupts_suspended) \
25200 luke 988
        onintr(); \
989
} while(0)
8684 luke 990
 
32158 ripley 991
/* structure for caching machine accuracy values */
992
typedef struct {
993
    int ibeta, it, irnd, ngrd, machep, negep, iexp, minexp, maxexp;
994
    double eps, epsneg, xmin, xmax;
995
} AccuracyInfo;
996
 
33670 maechler 997
extern AccuracyInfo R_AccuracyInfo;
32158 ripley 998
 
34599 ripley 999
/* FreeBSD defines alloca in stdlib.h, _and_ does not allow a definition
1000
   as here.  (Since it uses GCC, it should use the first clause.) */
1001
#ifdef __GNUC__
34600 ripley 1002
# undef alloca
34599 ripley 1003
# define alloca(x) __builtin_alloca((x))
1004
#else
1005
# ifdef HAVE_ALLOCA_H
1006
#  include <alloca.h>
1007
# endif
1008
# if !HAVE_DECL_ALLOCA  && !defined(__FreeBSD__)
1009
extern char *alloca(size_t);
1010
# endif
1011
#endif
1012
 
11116 ripley 1013
#endif /* DEFN_H_ */
2467 maechler 1014
/*
1015
 *- Local Variables:
1016
 *- page-delimiter: "^/\\*---"
1017
 *- End:
1018
 */