1 #ifndef DAVIS_SLANG_H_
2 #define DAVIS_SLANG_H_
3 /* -*- mode: C; mode: fold; -*- */
4 /*
5 Copyright (C) 2004-2017,2018 John E. Davis
6 
7 This file is part of the S-Lang Library.
8 
9 The S-Lang Library is free software; you can redistribute it and/or
10 modify it under the terms of the GNU General Public License as
11 published by the Free Software Foundation; either version 2 of the
12 License, or (at your option) any later version.
13 
14 The S-Lang Library is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this library; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
22 USA.
23 */
24 
25 #define SLANG_VERSION 20302
26 #define SLANG_VERSION_STRING "2.3.2"
27 /* #ifdef __DATE__ */
28 /* # define SLANG_VERSION_STRING SLANG_VERSION_STRING0 " " __DATE__ */
29 /* #else */
30 /* # define SLANG_VERSION_STRING SLANG_VERSION_STRING0 */
31 /* #endif */
32 /*{{{ System Dependent Macros and Typedefs */
33 
34 #if defined(__WATCOMC__) && defined(DOS)
35 # ifndef __MSDOS__
36 #  define __MSDOS__
37 # endif
38 # ifndef  DOS386
39 #  define  DOS386
40 # endif
41 # ifndef IBMPC_SYSTEM
42 #  define IBMPC_SYSTEM
43 # endif
44 #endif /* __watcomc__ */
45 
46 #if defined(unix) || defined(__unix)
47 # ifndef __unix__
48 #  define __unix__ 1
49 # endif
50 #endif
51 
52 #if defined(__APPLE__)
53 # ifndef __unix__
54 #  define __unix__ 1		       /* cough */
55 # endif
56 #endif
57 
58 #if !defined(__GO32__)
59 # ifdef __unix__
60 #  define REAL_UNIX_SYSTEM
61 # endif
62 #endif
63 
64 /* Set of the various defines for pc systems.  This includes OS/2 */
65 #ifdef __GO32__
66 # ifndef __DJGPP__
67 #  define __DJGPP__ 1
68 # endif
69 # ifndef IBMPC_SYSTEM
70 #   define IBMPC_SYSTEM
71 # endif
72 #endif
73 
74 #ifdef __BORLANDC__
75 # ifndef IBMPC_SYSTEM
76 #  define IBMPC_SYSTEM
77 # endif
78 #endif
79 
80 #ifdef __MSDOS__
81 # ifndef IBMPC_SYSTEM
82 #   define IBMPC_SYSTEM
83 # endif
84 #endif
85 
86 #if defined(OS2) || defined(__os2__)
87 # ifndef IBMPC_SYSTEM
88 #   define IBMPC_SYSTEM
89 # endif
90 # ifndef __os2__
91 #  define __os2__
92 # endif
93 #endif
94 
95 #if defined(__NT__) || defined(__MINGW32__) /* || defined(__CYGWIN32__) */
96 # ifndef IBMPC_SYSTEM
97 #  define IBMPC_SYSTEM
98 # endif
99 #endif
100 
101 #if defined(WIN32) || defined(__WIN32__)
102 # ifndef IBMPC_SYSTEM
103 #  define IBMPC_SYSTEM
104 # endif
105 # ifndef __WIN32__
106 #  define __WIN32__
107 # endif
108 #endif
109 
110 #if defined(IBMPC_SYSTEM) || defined(VMS)
111 # ifdef REAL_UNIX_SYSTEM
112 #  undef REAL_UNIX_SYSTEM
113 # endif
114 #endif
115 
116 #ifdef __cplusplus
117 extern "C" {
118 #endif
119 #if 0
120 }
121 #endif
122 
123 #include <stdio.h>
124 #include <stdarg.h>
125 #if defined(__STDC__) || defined(__BORLANDC__) || defined(__cplusplus)
126 # include <stddef.h>		       /* for offsetof */
127 #endif
128 
129 #ifdef SIZEOF_SHORT
130 # define SLANG_SIZEOF_SHORT SIZEOF_SHORT
131 #endif
132 #ifdef SIZEOF_INT
133 # define SLANG_SIZEOF_INT SIZEOF_INT
134 #endif
135 #ifdef SIZEOF_FLOAT
136 # define SLANG_SIZEOF_FLOAT SIZEOF_FLOAT
137 #endif
138 #ifdef SIZEOF_DOUBLE
139 # define SLANG_SIZEOF_DOUBLE SIZEOF_DOUBLE
140 #endif
141 
142 #if !defined(SIZEOF_SHORT) || !defined(SIZEOF_INT) || !defined(SIZEOF_LONG) || !defined(SIZEOF_FLOAT) || !defined(SIZEOF_DOUBLE)
143 # include <limits.h>
144 # if !defined(SIZEOF_SHORT) && defined(SHRT_MAX)
145 #  if SHRT_MAX == 32767
146 #   define SLANG_SIZEOF_SHORT 2
147 #  else
148 #   if SHRT_MAX == 2147483647L
149 #    define SLANG_SIZEOF_SHORT 4
150 #   endif
151 #  endif
152 # endif
153 # if !defined(SIZEOF_INT) && defined(INT_MAX)
154 #  if INT_MAX == 32767
155 #   define SLANG_SIZEOF_INT 2
156 #  else
157 #   if INT_MAX == 2147483647L
158 #    define SLANG_SIZEOF_INT 4
159 #   endif
160 #  endif
161 # endif
162 # if !defined(SIZEOF_LONG) && defined(LONG_MAX)
163 #  if LONG_MAX == 32767
164 #   define SLANG_SIZEOF_LONG 2
165 #  else
166 #   if LONG_MAX == 2147483647L
167 #    define SLANG_SIZEOF_LONG 4
168 #   else
169 #    define SLANG_SIZEOF_LONG 8
170 #   endif
171 #  endif
172 # endif
173 #endif
174 
175 #ifndef SLANG_SIZEOF_SHORT
176 # define SLANG_SIZEOF_SHORT 2
177 #endif
178 #ifndef SLANG_SIZEOF_INT
179 # define SLANG_SIZEOF_INT 4
180 #endif
181 #ifndef SLANG_SIZEOF_LONG
182 # define SLANG_SIZEOF_LONG 4
183 #endif
184 #ifndef SLANG_SIZEOF_FLOAT
185 # define SLANG_SIZEOF_FLOAT 4
186 #endif
187 #ifndef SLANG_SIZEOF_DOUBLE
188 # define SLANG_SIZEOF_DOUBLE 8
189 #endif
190 
191 /* ---------------------------- Generic Macros ----------------------------- */
192 
193 /*  __SC__ is defined for Symantec C++
194    DOS386 is defined for -mx memory model, 32 bit DOS extender. */
195 
196 #if defined(__SC__) && !defined(DOS386)
197 # include <dos.h>
198 #endif
199 
200 #if defined(__BORLANDC__)
201 # include <alloc.h>
202 #endif
203 
204 #ifdef __GNUC__
205 # define SLATTRIBUTE_(x) __attribute__ (x)
206 #else
207 # define SLATTRIBUTE_(x)
208 #endif
209 #define SLATTRIBUTE_PRINTF(a,b) SLATTRIBUTE_((format(printf,a,b)))
210 
211 #if defined (__cplusplus) || defined(__STDC__) || defined(IBMPC_SYSTEM)
212 typedef void *VOID_STAR;
213 #define SLCONST const
214 #else
215 typedef unsigned char *VOID_STAR;
216 #define SLCONST
217 #endif
218 
219 #ifdef ENABLE_SLFUTURE_CONST
220 # define SLFUTURE_CONST SLCONST
221 #else
222 # define SLFUTURE_CONST
223 #endif
224 
225 #ifdef ENABLE_SLFUTURE_VOID
226 # define SLFUTURE_VOID void
227 #else
228 # define SLFUTURE_VOID char
229 #endif
230 
231 typedef int (*FVOID_STAR)(void);
232 
233 #if defined(__MSDOS__) && defined(__BORLANDC__)
234 # define SLFREE(buf)  farfree((void far *)(buf))
235 # define SLMALLOC(x) farmalloc((unsigned long) (x))
236 # define SLREALLOC(buf, n) farrealloc((void far *) (buf), (unsigned long) (n))
237 # define SLCALLOC(n, m) farcalloc((unsigned long) (n), (unsigned long) (m))
238 #else
239 # if defined(VMS) && !defined(__DECC)
240 #  define SLFREE VAXC$FREE_OPT
241 #  define SLMALLOC VAXC$MALLOC_OPT
242 #  define SLREALLOC VAXC$REALLOC_OPT
243 #  define SLCALLOC VAXC$CALLOC_OPT
244 # else
245 #  define SLFREE(x) free((char *)(x))
246 #  define SLMALLOC malloc
247 #  define SLREALLOC realloc
248 #  define SLCALLOC calloc
249 # endif
250 #endif
251 
252 #if (defined(__WIN32__) || defined(__CYGWIN32__)) && defined(SLANG_DLL) && SLANG_DLL
253 # define SL_EXPORT __declspec(dllexport)
254 # define SL_IMPORT __declspec(dllimport)
255 #else
256 # define SL_EXPORT
257 # define SL_IMPORT
258 #endif
259 #ifdef SLANG_SOURCE_
260 # define SL_EXTERN extern SL_EXPORT
261 #else
262 # define SL_EXTERN extern SL_IMPORT
263 #endif
264 
265 SL_EXTERN SLFUTURE_VOID *SLdebug_malloc (unsigned long);
266 SL_EXTERN SLFUTURE_VOID *SLdebug_calloc (unsigned long, unsigned long);
267 SL_EXTERN SLFUTURE_VOID *SLdebug_realloc (SLFUTURE_VOID *, unsigned long);
268 SL_EXTERN void SLdebug_free (SLFUTURE_VOID *);
269 SL_EXTERN void SLmalloc_dump_statistics (void);
270 SL_EXTERN char *SLstrcpy(register char *, register char *);
271 SL_EXTERN int SLstrcmp(register char *, register char *);
272 SL_EXTERN char *SLstrncpy(char *, register char *, register  int);
273 
274 SL_EXTERN void SLmemset (char *, char, int);
275 SL_EXTERN char *SLmemchr (register char *, register char, register int);
276 SL_EXTERN char *SLmemcpy (char *, char *, int);
277 SL_EXTERN int SLmemcmp (char *, char *, int);
278 
279 /*}}}*/
280 
281 typedef unsigned int SLstrlen_Type;    /* Eventually this will become size_t */
282 #define SLANG_STRLEN_TYPE SLANG_UINT_TYPE
283 typedef int SLindex_Type;
284 typedef unsigned int SLuindex_Type;
285 #define SLANG_ARRAY_INDEX_TYPE SLANG_INT_TYPE
286 
287 /* SLstrings */
288 typedef char SLstr_Type;
289 SL_EXTERN int SLang_pop_strlen_type (SLstrlen_Type *);
290 SL_EXTERN int SLang_push_strlen_type (SLstrlen_Type);
291 
292 /* An SLstr_Type object must be treated as a constant and may only be freed
293  * by the SLang_free_slstring function and nothing else.
294  */
295 SL_EXTERN SLstr_Type *SLang_create_nslstring (SLFUTURE_CONST char *, SLstrlen_Type);
296 SL_EXTERN SLstr_Type *SLang_create_slstring (SLFUTURE_CONST char *);
297 SL_EXTERN void SLang_free_slstring (SLCONST SLstr_Type *);    /* handles NULL */
298 SL_EXTERN int SLang_pop_slstring (SLstr_Type **);   /* free with SLang_free_slstring */
299 SL_EXTERN SLstr_Type *SLang_concat_slstrings (SLstr_Type *a, SLstr_Type *b);
300 typedef unsigned long SLstr_Hash_Type;
301 SL_EXTERN SLstr_Hash_Type SLcompute_string_hash (SLCONST SLstr_Type *);
302 
303 
304 /* SL_EXTERN void SLstring_dump_stats (void);  // is not (yet?) defined by S-Lang library */
305 
306 /*{{{ UTF-8 and Wide Char support */
307 
308 #if SLANG_SIZEOF_INT == 4
309 typedef unsigned int SLwchar_Type;
310 # define SLANG_WCHAR_TYPE SLANG_UINT_TYPE
311 # define SLang_push_wchar SLang_push_uint
312 # define SLang_pop_wchar SLang_pop_uint
313 #else
314 typedef unsigned long SLwchar_Type;
315 # define SLANG_WCHAR_TYPE SLANG_ULONG_TYPE
316 # define SLang_push_wchar SLang_push_ulong
317 # define SLang_pop_wchar SLang_pop_ulong
318 #endif
319 typedef unsigned char SLuchar_Type;
320 
321 /* Maximum multi-byte len for a unicode wchar */
322 #define SLUTF8_MAX_MBLEN	6
323 
324 /* If argument is 1, force UTF-8 mode on.  If argument is 0, force mode off.
325  * If -1, determine mode from the locale.
326  * Returns 1 if enabled, 0 if not.
327  */
328 SL_EXTERN int SLutf8_enable (int);
329 SL_EXTERN int SLutf8_is_utf8_mode (void);
330 SL_EXTERN int SLtt_utf8_enable (int);
331 SL_EXTERN int SLtt_is_utf8_mode (void);
332 SL_EXTERN int SLsmg_utf8_enable (int);
333 SL_EXTERN int SLsmg_is_utf8_mode (void);
334 SL_EXTERN int SLinterp_utf8_enable (int);
335 SL_EXTERN int SLinterp_is_utf8_mode (void);
336 
337 SL_EXTERN SLwchar_Type SLwchar_toupper (SLwchar_Type);
338 SL_EXTERN SLwchar_Type SLwchar_tolower (SLwchar_Type);
339 
340 SL_EXTERN int SLwchar_wcwidth (SLwchar_Type);
341 SL_EXTERN int SLwchar_isalnum (SLwchar_Type);
342 SL_EXTERN int SLwchar_isalpha (SLwchar_Type);
343 SL_EXTERN int SLwchar_isblank (SLwchar_Type);
344 SL_EXTERN int SLwchar_iscntrl (SLwchar_Type);
345 SL_EXTERN int SLwchar_isdigit (SLwchar_Type);
346 SL_EXTERN int SLwchar_isgraph (SLwchar_Type);
347 SL_EXTERN int SLwchar_islower (SLwchar_Type);
348 SL_EXTERN int SLwchar_isprint (SLwchar_Type);
349 SL_EXTERN int SLwchar_ispunct (SLwchar_Type);
350 SL_EXTERN int SLwchar_isspace (SLwchar_Type);
351 SL_EXTERN int SLwchar_isupper (SLwchar_Type);
352 SL_EXTERN int SLwchar_isxdigit (SLwchar_Type);
353 
354 #define SLWCWIDTH_SINGLE_WIDTH	0x0001 /* all double width characters given as single width */
355 #define SLWCWIDTH_CJK_LEGACY	0x0002 /* Ambiguous characters given width of 2 */
356 SL_EXTERN int SLwchar_set_wcwidth_flags (int flags);
357 
358 /* The skip_char functions also skip over malformed strings counting each byte
359  * in the malformed sequence.
360  */
361 SL_EXTERN SLuchar_Type *SLutf8_skip_char (SLuchar_Type *u, SLuchar_Type *umax);
362 SL_EXTERN SLuchar_Type *SLutf8_bskip_char (SLuchar_Type *umin, SLuchar_Type *u);
363 SL_EXTERN SLuchar_Type *SLutf8_skip_chars (SLuchar_Type *u, SLuchar_Type *umax,
364 					SLstrlen_Type num, SLstrlen_Type *dnum,
365 					int ignore_combining );
366 SL_EXTERN SLuchar_Type *SLutf8_bskip_chars (SLuchar_Type *umin, SLuchar_Type *u,
367 					  SLstrlen_Type num, SLstrlen_Type *dnum,
368 					 int ignore_combining);
369 
370 /* The SLutf8_strup/lo functions return slstrings -- free with SLang_free_slstring */
371 SL_EXTERN SLuchar_Type *SLutf8_strup (SLuchar_Type *u, SLuchar_Type *umax);
372 SL_EXTERN SLuchar_Type *SLutf8_strlo (SLuchar_Type *u, SLuchar_Type *umax);
373 
374 SL_EXTERN SLstr_Type *SLutf8_subst_wchar (SLuchar_Type *u, SLuchar_Type *umax,
375 				       SLwchar_Type wch, SLstrlen_Type pos,
376 				       int ignore_combining);
377 
378 SL_EXTERN SLstrlen_Type SLutf8_strlen (SLuchar_Type *s, int ignore_combining);
379 SL_EXTERN SLuchar_Type *SLutf8_decode (SLuchar_Type *u, SLuchar_Type *umax,
380 				     SLwchar_Type *w, SLstrlen_Type *nconsumedp);
381 SL_EXTERN SLuchar_Type *SLutf8_encode (SLwchar_Type w, SLuchar_Type *u, SLstrlen_Type ulen);
382 
383 SL_EXTERN int SLutf8_compare (SLuchar_Type *a, SLuchar_Type *amax,
384 			      SLuchar_Type *b, SLuchar_Type *bmax,
385 			      SLstrlen_Type nchars, int case_sensitive);
386 
387 /* In these functions, buf is assumed to contain at least SLUTF8_MAX_MBLEN+1
388  * bytes
389  */
390 SL_EXTERN SLuchar_Type *SLutf8_extract_utf8_char (SLuchar_Type *u, SLuchar_Type *umax, SLuchar_Type *buf);
391 SL_EXTERN SLuchar_Type *SLutf8_encode_null_terminate (SLwchar_Type w, SLuchar_Type *buf);
392 
393 typedef struct SLwchar_Lut_Type SLwchar_Lut_Type;
394 SL_EXTERN SLwchar_Lut_Type *SLwchar_create_lut (unsigned int num_entries);
395 SL_EXTERN int SLwchar_add_range_to_lut (SLwchar_Lut_Type *r, SLwchar_Type a, SLwchar_Type b);
396 SL_EXTERN SLuchar_Type *SLwchar_skip_range (SLwchar_Lut_Type *r, SLuchar_Type *p,
397 					 SLuchar_Type *pmax, int ignore_combining,
398 					 int invert);
399 SL_EXTERN SLwchar_Lut_Type *SLwchar_strtolut (SLuchar_Type *u,
400 					   int allow_range, int allow_charclass);
401 SL_EXTERN void SLwchar_free_lut (SLwchar_Lut_Type *r);
402 SL_EXTERN SLuchar_Type *SLwchar_bskip_range (SLwchar_Lut_Type *r, SLuchar_Type *pmin,
403 					  SLuchar_Type *p,
404 					  int ignore_combining,
405 					  int invert);
406 SL_EXTERN int SLwchar_in_lut (SLwchar_Lut_Type *r, SLwchar_Type wch);
407 
408 typedef struct SLwchar_Map_Type SLwchar_Map_Type;
409 SL_EXTERN void SLwchar_free_char_map (SLwchar_Map_Type *map);
410 SL_EXTERN SLwchar_Map_Type *SLwchar_allocate_char_map (SLuchar_Type *from, SLuchar_Type *to);
411 SL_EXTERN int SLwchar_apply_char_map (SLwchar_Map_Type *map, SLwchar_Type *input, SLwchar_Type *output, unsigned int num);
412 
413 /* This function returns a malloced string */
414 SLuchar_Type *SLuchar_apply_char_map (SLwchar_Map_Type *map, SLuchar_Type *str);
415 
416 /*}}}*/
417 
418 /*{{{ Interpreter Typedefs */
419 
420 typedef unsigned int SLtype;
421 #define SLANG_SLTYPE_INT_TYPE SLANG_UINT_TYPE
422 
423 typedef struct _pSLang_Name_Type
424 {
425    SLFUTURE_CONST char *name;
426    struct _pSLang_Name_Type *next;
427    unsigned char name_type;
428    /* These values here map directly to byte codes.  See _slang.h.
429     */
430 #define SLANG_LVARIABLE		0x01
431 #define SLANG_GVARIABLE 	0x02
432 #define SLANG_IVARIABLE 	0x03           /* intrinsic variables */
433    /* Note!!! For Macro MAKE_VARIABLE below to work, SLANG_IVARIABLE Must
434     be 1 less than SLANG_RVARIABLE!!! */
435 #define SLANG_RVARIABLE		0x04	       /* read only variable */
436 #define SLANG_INTRINSIC 	0x05
437 #define SLANG_FUNCTION  	0x06
438 #define SLANG_MATH_UNARY  	0x07
439 #define SLANG_APP_UNARY  	0x08
440 #define SLANG_ARITH_UNARY	0x09   /* private */
441 #define SLANG_ARITH_BINARY	0x0A
442 #define SLANG_ICONSTANT		0x0B
443 #define SLANG_DCONSTANT		0x0C
444 #define SLANG_FCONSTANT		0x0D
445 #define SLANG_LLCONSTANT	0x0E
446 #define SLANG_PVARIABLE		0x0F   /* private */
447 #define SLANG_PFUNCTION		0x10   /* private */
448 #define SLANG_HCONSTANT		0x11
449 #define SLANG_LCONSTANT		0x12
450    /* Rest of fields depend on name type */
451 }
452 SLang_Name_Type;
453 
454 typedef struct
455 {
456    SLFUTURE_CONST char *name;
457    struct _pSLang_Name_Type *next;      /* this is for the hash table */
458    char name_type;
459 
460    FVOID_STAR i_fun;		       /* address of object */
461 
462    /* Do not change this without modifying slang.c:execute_intrinsic_fun */
463 #define SLANG_MAX_INTRIN_ARGS	7
464    SLtype arg_types [SLANG_MAX_INTRIN_ARGS];
465    unsigned char num_args;
466    SLtype return_type;
467 }
468 SLang_Intrin_Fun_Type;
469 
470 typedef struct
471 {
472    SLFUTURE_CONST char *name;
473    SLang_Name_Type *next;
474    char name_type;
475 
476    VOID_STAR addr;
477    SLtype type;
478 }
479 SLang_Intrin_Var_Type;
480 
481 typedef struct
482 {
483    SLFUTURE_CONST char *name;
484    SLang_Name_Type *next;
485    char name_type;
486 
487    int unary_op;
488 }
489 SLang_App_Unary_Type;
490 
491 typedef struct
492 {
493    SLFUTURE_CONST char *name;
494    SLang_Name_Type *next;
495    char name_type;
496 
497    int unary_op;
498 }
499 SLang_Math_Unary_Type;
500 
501 typedef struct
502 {
503    SLFUTURE_CONST char *name;
504    SLang_Name_Type *next;
505    char name_type;
506 
507    SLtype data_type;
508    short value;
509 }
510 SLang_HConstant_Type;
511 
512 typedef struct
513 {
514    SLFUTURE_CONST char *name;
515    SLang_Name_Type *next;
516    char name_type;
517 
518    SLtype data_type;
519    int value;
520 }
521 SLang_IConstant_Type;
522 
523 typedef struct
524 {
525    SLFUTURE_CONST char *name;
526    SLang_Name_Type *next;
527    char name_type;
528 
529    SLtype data_type;
530    long value;
531 }
532 SLang_LConstant_Type;
533 
534 #ifdef HAVE_LONG_LONG
535 typedef struct
536 {
537    SLFUTURE_CONST char *name;
538    SLang_Name_Type *next;
539    char name_type;
540 
541    long long ll;
542 }
543 SLang_LLConstant_Type;
544 #endif
545 
546 typedef struct
547 {
548    SLFUTURE_CONST char *name;
549    SLang_Name_Type *next;
550    char name_type;
551    double d;
552 }
553 SLang_DConstant_Type;
554 
555 typedef struct
556 {
557    SLFUTURE_CONST char *name;
558    SLang_Name_Type *next;
559    char name_type;
560    float f;
561 }
562 SLang_FConstant_Type;
563 
564 typedef struct
565 {
566    SLFUTURE_CONST char *field_name;		       /* gets replaced by slstring at run-time */
567    unsigned int offset;
568    SLtype type;
569    unsigned char read_only;
570 }
571 SLang_IStruct_Field_Type;
572 
573 typedef SLCONST struct _pSLang_CStruct_Field_Type   /* a g++ bug?? yuk*/
574 {
575    SLFUTURE_CONST char *field_name;
576    unsigned int offset;
577    SLtype type;
578    unsigned char read_only;
579 }
580 SLang_CStruct_Field_Type;
581 
582 SL_EXTERN int SLadd_intrin_fun_table (SLang_Intrin_Fun_Type *, SLFUTURE_CONST char *);
583 SL_EXTERN int SLadd_intrin_var_table (SLang_Intrin_Var_Type *, SLFUTURE_CONST char *);
584 SL_EXTERN int SLadd_app_unary_table (SLang_App_Unary_Type *, SLFUTURE_CONST char *);
585 SL_EXTERN int SLadd_math_unary_table (SLang_Math_Unary_Type *, SLFUTURE_CONST char *);
586 SL_EXTERN int SLadd_iconstant_table (SLang_IConstant_Type *, SLFUTURE_CONST char *);
587 SL_EXTERN int SLadd_lconstant_table (SLang_LConstant_Type *, SLFUTURE_CONST char *pp);
588 SL_EXTERN int SLadd_dconstant_table (SLang_DConstant_Type *, SLFUTURE_CONST char *);
589 SL_EXTERN int SLadd_fconstant_table (SLang_FConstant_Type *, SLFUTURE_CONST char *);
590 #ifdef HAVE_LONG_LONG
591 SL_EXTERN int SLadd_llconstant_table (SLang_LLConstant_Type *, SLFUTURE_CONST char *);
592 #endif
593 SL_EXTERN int SLadd_istruct_table (SLang_IStruct_Field_Type *, VOID_STAR, SLFUTURE_CONST char *);
594 
595 typedef struct _pSLang_NameSpace_Type SLang_NameSpace_Type;
596 
597 SL_EXTERN int SLns_add_intrin_fun_table (SLang_NameSpace_Type *, SLang_Intrin_Fun_Type *, SLFUTURE_CONST char *);
598 SL_EXTERN int SLns_add_intrin_var_table (SLang_NameSpace_Type *, SLang_Intrin_Var_Type *, SLFUTURE_CONST char *);
599 SL_EXTERN int SLns_add_app_unary_table (SLang_NameSpace_Type *, SLang_App_Unary_Type *, SLFUTURE_CONST char *);
600 SL_EXTERN int SLns_add_math_unary_table (SLang_NameSpace_Type *, SLang_Math_Unary_Type *, SLFUTURE_CONST char *);
601 SL_EXTERN int SLns_add_hconstant_table (SLang_NameSpace_Type *, SLang_HConstant_Type *, SLFUTURE_CONST char *);
602 SL_EXTERN int SLns_add_iconstant_table (SLang_NameSpace_Type *, SLang_IConstant_Type *, SLFUTURE_CONST char *);
603 SL_EXTERN int SLns_add_lconstant_table (SLang_NameSpace_Type *, SLang_LConstant_Type *, SLFUTURE_CONST char *);
604 /* SL_EXTERN int SLns_add_fconstant_table (SLang_NameSpace_Type *, SLang_FConstant_Type *, SLFUTURE_CONST char *);  // is not (yet?) defined by S-Lang library */
605 SL_EXTERN int SLns_add_dconstant_table (SLang_NameSpace_Type *, SLang_DConstant_Type *, SLFUTURE_CONST char *);
606 #ifdef HAVE_LONG_LONG
607 /* SL_EXTERN int SLns_add_llconstant_table (SLang_NameSpace_Type *, SLang_LLConstant_Type *, SLFUTURE_CONST char *);  // is not (yet?) defined by S-Lang library */
608 #endif
609 SL_EXTERN int SLns_add_istruct_table (SLang_NameSpace_Type *, SLang_IStruct_Field_Type *, VOID_STAR, SLFUTURE_CONST char *);
610 
611 SL_EXTERN int SLns_add_hconstant (SLang_NameSpace_Type *, SLFUTURE_CONST char *, SLtype, short);
612 SL_EXTERN int SLns_add_iconstant (SLang_NameSpace_Type *, SLFUTURE_CONST char *, SLtype, int);
613 SL_EXTERN int SLns_add_lconstant (SLang_NameSpace_Type *, SLFUTURE_CONST char *, SLtype, long);
614 SL_EXTERN int SLns_add_fconstant (SLang_NameSpace_Type *, SLFUTURE_CONST char *, float);
615 SL_EXTERN int SLns_add_dconstant (SLang_NameSpace_Type *, SLFUTURE_CONST char *, double);
616 #ifdef HAVE_LONG_LONG
617 SL_EXTERN int SLns_add_llconstant (SLang_NameSpace_Type *, SLFUTURE_CONST char *, long long);
618 #endif
619 SL_EXTERN SLang_NameSpace_Type *SLns_create_namespace (SLFUTURE_CONST char *);
620 SL_EXTERN void SLns_delete_namespace (SLang_NameSpace_Type *);
621 
622 SL_EXTERN int SLns_load_file (SLFUTURE_CONST char *, SLFUTURE_CONST char *);
623 SL_EXTERN int SLns_load_string (SLFUTURE_CONST char *, SLFUTURE_CONST char *);
624 SL_EXTERN int (*SLns_Load_File_Hook) (SLFUTURE_CONST char *, SLFUTURE_CONST char *);
625 
626 #define SLANG_LOAD_FILE_VERBOSE		0x1
627 #define SLANG_LOAD_MODULE_VERBOSE	0x2
628 SL_EXTERN int SLang_load_file_verbose (int);
629 /* Bitmapped value that controls loading messages */
630 
631 typedef struct SLang_Load_Type
632 {
633    int type;
634 
635    VOID_STAR client_data;
636    /* Pointer to data that client needs for loading */
637 
638    int auto_declare_globals;
639    /* if non-zero, undefined global variables are declared as static */
640 
641    char *(*read)(struct SLang_Load_Type *);
642    /* function to call to read next line from obj. */
643 
644    unsigned int line_num;
645    /* Number of lines read, used for error reporting */
646 
647    int parse_level;
648    /* 0 if at top level of parsing */
649 
650    SLFUTURE_CONST char *name;
651    /* Name of this object, e.g., filename.  This name should be unique because
652     * it alone determines the name space for static objects associated with
653     * the compilable unit.
654     */
655 
656    SLFUTURE_CONST char *namespace_name;
657    unsigned long reserved[3];
658    /* For future expansion */
659 } SLang_Load_Type;
660 
661 SL_EXTERN SLang_Load_Type *SLallocate_load_type (SLFUTURE_CONST char *);
662 SL_EXTERN void SLdeallocate_load_type (SLang_Load_Type *);
663 SL_EXTERN SLang_Load_Type *SLns_allocate_load_type (SLFUTURE_CONST char *, SLFUTURE_CONST char *);
664 
665 /* Returns SLang_Error upon failure */
666 SL_EXTERN int SLang_load_object (SLang_Load_Type *);
667 SL_EXTERN int (*SLang_Load_File_Hook)(SLFUTURE_CONST char *);
668 SL_EXTERN int (*SLang_Auto_Declare_Var_Hook) (SLFUTURE_CONST char *);
669 
670 SL_EXTERN int SLang_generate_debug_info (int);
671 
672 #if defined(ultrix) && !defined(__GNUC__)
673 # ifndef NO_PROTOTYPES
674 #  define NO_PROTOTYPES
675 # endif
676 #endif
677 
678 #ifndef NO_PROTOTYPES
679 # define _PROTO(x) x
680 #else
681 # define _PROTO(x) ()
682 #endif
683 
684 SL_EXTERN int SLang_pop_array_index (SLindex_Type *);
685 SL_EXTERN int SLang_push_array_index (SLindex_Type);
686 
687 typedef struct _pSLang_Struct_Type SLang_Struct_Type;
688 SL_EXTERN void SLang_free_struct (SLang_Struct_Type *);
689 SL_EXTERN int SLang_push_struct (SLang_Struct_Type *);
690 SL_EXTERN int SLang_pop_struct (SLang_Struct_Type **);
691 
692 SL_EXTERN SLang_Struct_Type *SLang_create_struct (SLFUTURE_CONST char **field_names, unsigned int nfields);
693 /* Push the specified field value onto the stack */
694 SL_EXTERN int SLang_push_struct_field (SLang_Struct_Type *s, char *name);
695 /* Pop the value from the stack into the specified field */
696 SL_EXTERN int SLang_pop_struct_field (SLang_Struct_Type *s, char *name);
697 /* Set the first n fields of the struct from the stack.  If n < 0, pop all fields. */
698 SL_EXTERN int SLang_pop_struct_fields (SLang_Struct_Type *s, int n);
699 
700 
701 typedef struct _pSLang_Assoc_Array_Type SLang_Assoc_Array_Type;
702 
703 SL_EXTERN SLang_Assoc_Array_Type *SLang_create_assoc (SLtype type, int has_default);
704 /* If has_default is non-zero, take the default value from the stack */
705 SL_EXTERN void SLang_free_assoc (SLang_Assoc_Array_Type *);
706 SL_EXTERN int SLang_push_assoc (SLang_Assoc_Array_Type *, int free_flag);
707 SL_EXTERN int SLang_pop_assoc (SLang_Assoc_Array_Type **);
708 SL_EXTERN int SLang_assoc_get (SLang_Assoc_Array_Type *, SLstr_Type *, SLtype *);
709 /* SLang_assoc_get leaves the object on the stack */
710 SL_EXTERN int SLang_assoc_put (SLang_Assoc_Array_Type *, SLstr_Type *);
711 /* SLang_assoc_put takes the object from the stack */
712 
713 SL_EXTERN int SLang_assoc_key_exists (SLang_Assoc_Array_Type *, SLstr_Type *);
714 
715 typedef struct _pSLang_List_Type SLang_List_Type;
716 SL_EXTERN SLang_List_Type *SLang_create_list (int);
717 SL_EXTERN int SLang_list_append (SLang_List_Type *, int);
718 SL_EXTERN int SLang_list_insert (SLang_List_Type *, int);
719 SL_EXTERN int SLang_push_list (SLang_List_Type *, int free_list);
720 SL_EXTERN int SLang_pop_list (SLang_List_Type **);
721 SL_EXTERN void SLang_free_list (SLang_List_Type *);
722 
723 typedef struct _pSLang_Foreach_Context_Type SLang_Foreach_Context_Type;
724 
725 typedef struct _pSLang_Class_Type SLang_Class_Type;
726 
727 /* These are the low-level functions for building push/pop methods.  They
728  * know nothing about memory management.  For SLANG_CLASS_TYPE_MMT, use the
729  * MMT push/pop functions instead.
730  */
731 SL_EXTERN int SLclass_push_double_obj (SLtype, double);
732 SL_EXTERN int SLclass_push_float_obj (SLtype, float);
733 SL_EXTERN int SLclass_push_long_obj (SLtype, long);
734 SL_EXTERN int SLclass_push_int_obj (SLtype, int);
735 SL_EXTERN int SLclass_push_short_obj (SLtype, short);
736 SL_EXTERN int SLclass_push_char_obj (SLtype, char);
737 SL_EXTERN int SLclass_push_ptr_obj (SLtype, VOID_STAR);
738 SL_EXTERN int SLclass_pop_double_obj (SLtype, double *);
739 SL_EXTERN int SLclass_pop_float_obj (SLtype, float *);
740 SL_EXTERN int SLclass_pop_long_obj (SLtype, long *);
741 SL_EXTERN int SLclass_pop_int_obj (SLtype, int *);
742 SL_EXTERN int SLclass_pop_short_obj (SLtype, short *);
743 SL_EXTERN int SLclass_pop_char_obj (SLtype, char *);
744 SL_EXTERN int SLclass_pop_ptr_obj (SLtype, VOID_STAR *);
745 
746 #ifdef HAVE_LONG_LONG
747 SL_EXTERN int SLang_pop_long_long (long long *);
748 SL_EXTERN int SLang_push_long_long (long long);
749 SL_EXTERN int SLang_pop_ulong_long (unsigned long long *);
750 SL_EXTERN int SLang_push_ulong_long (unsigned long long);
751 /* SL_EXTERN int SLclass_pop_llong_obj (SLtype, long long *);  // is not (yet?) defined by S-Lang library */
752 SL_EXTERN int SLclass_push_llong_obj (SLtype, long long);
753 #endif
754 
755 SL_EXTERN SLang_Class_Type *SLclass_allocate_class (SLFUTURE_CONST char *);
756 SL_EXTERN int SLclass_get_class_id (SLang_Class_Type *cl);
757 SL_EXTERN int SLclass_create_synonym (SLFUTURE_CONST char *, SLtype);
758 SL_EXTERN int SLclass_is_class_defined (SLtype);
759 SL_EXTERN int SLclass_dup_object (SLtype type, VOID_STAR from, VOID_STAR to);
760 
761 typedef int SLclass_Type;
762 #define SLANG_CLASS_TYPE_MMT		0
763 #define SLANG_CLASS_TYPE_SCALAR		1
764 #define SLANG_CLASS_TYPE_VECTOR		2
765 #define SLANG_CLASS_TYPE_PTR		3
766 SL_EXTERN int SLclass_register_class (SLang_Class_Type *, SLtype, unsigned int, SLclass_Type);
767 
768 SL_EXTERN int SLclass_set_string_function (SLang_Class_Type *, char *(*)(SLtype, VOID_STAR));
769 SL_EXTERN int SLclass_set_destroy_function (SLang_Class_Type *, void (*)(SLtype, VOID_STAR));
770 SL_EXTERN int SLclass_set_push_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
771 SL_EXTERN int SLclass_set_apush_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
772 SL_EXTERN int SLclass_set_pop_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
773 
774 SL_EXTERN int SLclass_set_aget_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
775 SL_EXTERN int SLclass_set_aput_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
776 SL_EXTERN int SLclass_set_anew_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
777 
778 SL_EXTERN int SLclass_set_sget_function (SLang_Class_Type *, int (*)(SLtype, SLFUTURE_CONST char *));
779 SL_EXTERN int SLclass_set_sput_function (SLang_Class_Type *, int (*)(SLtype, SLFUTURE_CONST char *));
780 
781 SL_EXTERN int SLclass_set_acopy_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR, VOID_STAR));
782 SL_EXTERN int SLclass_set_deref_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
783 SL_EXTERN int SLclass_set_eqs_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR, SLtype, VOID_STAR));
784 
785 SL_EXTERN int SLclass_set_length_function (SLang_Class_Type *, int(*)(SLtype, VOID_STAR, SLuindex_Type *));
786 
787 SL_EXTERN int SLclass_set_is_container (SLang_Class_Type *, int);
788 SL_EXTERN int SLclass_set_foreach_functions (
789   SLang_Class_Type *,
790   SLang_Foreach_Context_Type *(*)(SLtype, unsigned int),   /* open method */
791   int (*)(SLtype, SLang_Foreach_Context_Type *),   /* foreach method */
792   void (*)(SLtype, SLang_Foreach_Context_Type *));/* close method */
793 
794 /* When an array is created, this callback function is called to initialize the data
795  * at the specified address.
796  */
797 SL_EXTERN int SLclass_set_aelem_init_function (SLang_Class_Type *cl, int (*f)(SLtype, VOID_STAR));
798 
799 /* Typecast object on the stack to type p1.  p2 and p3 should be set to 1 */
800 SL_EXTERN int SLclass_typecast (SLtype, int, int);
801 
802 #define SLMATH_SIN	1
803 #define SLMATH_COS	2
804 #define SLMATH_TAN	3
805 #define SLMATH_ATAN	4
806 #define SLMATH_ASIN	5
807 #define SLMATH_ACOS	6
808 #define SLMATH_EXP	7
809 #define SLMATH_LOG	8
810 #define SLMATH_SQRT	9
811 #define SLMATH_LOG10	10
812 #define SLMATH_REAL	11
813 #define SLMATH_IMAG	12
814 #define SLMATH_SINH	13
815 #define SLMATH_COSH	14
816 #define SLMATH_TANH	15
817 #define SLMATH_ATANH	16
818 #define SLMATH_ASINH	17
819 #define SLMATH_ACOSH	18
820 #define SLMATH_TODOUBLE	19
821 #define SLMATH_CONJ	20
822 #define SLMATH_ISINF	21
823 #define SLMATH_ISNAN	22
824 #define SLMATH_FLOOR	23
825 #define SLMATH_CEIL	24
826 #define SLMATH_ROUND	25
827 #define SLMATH_EXPM1	26
828 #define SLMATH_LOG1P	27
829 
830 SL_EXTERN int SLclass_add_unary_op (SLtype,
831 				 int (*) (int,
832 					  SLtype, VOID_STAR, SLuindex_Type,
833 					  VOID_STAR),
834 				 int (*) (int, SLtype, SLtype *));
835 
836 SL_EXTERN int
837 SLclass_add_app_unary_op (SLtype,
838 			  int (*) (int,
839 				   SLtype, VOID_STAR, SLuindex_Type,
840 				   VOID_STAR),
841 			  int (*) (int, SLtype, SLtype *));
842 
843 SL_EXTERN int
844 SLclass_add_binary_op (SLtype, SLtype,
845 		       int (*) (int,
846 				SLtype, VOID_STAR, SLuindex_Type,
847 				SLtype, VOID_STAR, SLuindex_Type,
848 				VOID_STAR),
849 		       int (*) (int, SLtype, SLtype, SLtype *));
850 
851 SL_EXTERN int
852 SLclass_add_math_op (SLtype,
853 		     int (*)(int,
854 			     SLtype, VOID_STAR, SLuindex_Type,
855 			     VOID_STAR),
856 		     int (*)(int, SLtype, SLtype *));
857 
858 SL_EXTERN int
859 SLclass_add_typecast (SLtype /* from */, SLtype /* to */,
860 		      int (*)_PROTO((SLtype, VOID_STAR, SLuindex_Type,
861 				     SLtype, VOID_STAR)),
862 		      int	       /* allow implicit typecasts */
863 		      );
864 
865 SL_EXTERN SLFUTURE_CONST char *SLclass_get_datatype_name (SLtype);
866 
867 SL_EXTERN double SLcomplex_abs (double *);
868 SL_EXTERN double *SLcomplex_times (double *, double *, double *);
869 SL_EXTERN double *SLcomplex_divide (double *, double *, double *);
870 SL_EXTERN double *SLcomplex_sin (double *, double *);
871 SL_EXTERN double *SLcomplex_cos (double *, double *);
872 SL_EXTERN double *SLcomplex_tan (double *, double *);
873 SL_EXTERN double *SLcomplex_asin (double *, double *);
874 SL_EXTERN double *SLcomplex_acos (double *, double *);
875 SL_EXTERN double *SLcomplex_atan (double *, double *);
876 SL_EXTERN double *SLcomplex_exp (double *, double *);
877 SL_EXTERN double *SLcomplex_log (double *, double *);
878 SL_EXTERN double *SLcomplex_log10 (double *, double *);
879 SL_EXTERN double *SLcomplex_sqrt (double *, double *);
880 SL_EXTERN double *SLcomplex_sinh (double *, double *);
881 SL_EXTERN double *SLcomplex_cosh (double *, double *);
882 SL_EXTERN double *SLcomplex_tanh (double *, double *);
883 SL_EXTERN double *SLcomplex_pow (double *, double *, double *);
884 SL_EXTERN double SLmath_hypot (double x, double y);
885 
886 /* Not implemented yet */
887 SL_EXTERN double *SLcomplex_asinh (double *, double *);
888 SL_EXTERN double *SLcomplex_acosh (double *, double *);
889 SL_EXTERN double *SLcomplex_atanh (double *, double *);
890 
891 #ifdef SLANG_SOURCE_
892 typedef struct _pSLang_MMT_Type SLang_MMT_Type;
893 #else
894 typedef int SLang_MMT_Type;
895 #endif
896 
897 SL_EXTERN void SLang_free_mmt (SLang_MMT_Type *);
898 SL_EXTERN VOID_STAR SLang_object_from_mmt (SLang_MMT_Type *);
899 SL_EXTERN SLang_MMT_Type *SLang_create_mmt (SLtype, VOID_STAR);
900 SL_EXTERN int SLang_push_mmt (SLang_MMT_Type *);
901 SL_EXTERN SLang_MMT_Type *SLang_pop_mmt (SLtype);
902 SL_EXTERN void SLang_inc_mmt (SLang_MMT_Type *);
903 
904 /* Maximum number of dimensions of an array. */
905 #define SLARRAY_MAX_DIMS		7
906 typedef struct _pSLang_Array_Type
907 {
908    SLtype data_type;
909    unsigned int sizeof_type;
910    VOID_STAR data;
911    SLuindex_Type num_elements;
912    unsigned int num_dims;
913    SLindex_Type dims [SLARRAY_MAX_DIMS];
914    VOID_STAR (*index_fun)_PROTO((struct _pSLang_Array_Type *, SLindex_Type *));
915    /* This function is designed to allow a type to store an array in
916     * any manner it chooses.  This function returns the address of the data
917     * value at the specified index location.
918     */
919    unsigned int flags;
920 #define SLARR_DATA_VALUE_IS_READ_ONLY		0x0001
921 #define SLARR_DATA_VALUE_IS_POINTER		0x0002
922 #define SLARR_DATA_VALUE_IS_RANGE		0x0004
923 #define SLARR_DATA_VALUE_IS_INTRINSIC		0x0008
924 #define SLARR_DERIVED_FROM_SCALAR		0x0100
925    SLang_Class_Type *cl;
926    unsigned int num_refs;
927    void (*free_fun)_PROTO((struct _pSLang_Array_Type *));
928    VOID_STAR client_data;
929 }
930 SLang_Array_Type;
931 
932 SL_EXTERN int _pSLarray_convert_to_array (VOID_STAR cd,
933 				       int (*get_type)(VOID_STAR, SLuindex_Type, SLtype *),
934 				       int (*push)(VOID_STAR, SLuindex_Type),
935 				       SLuindex_Type num_objects, SLtype type);
936 
937 SL_EXTERN int SLang_pop_array_of_type (SLang_Array_Type **atp, SLtype type);
938 SL_EXTERN int SLang_pop_array (SLang_Array_Type **atp, int convert_scalar);
939 SL_EXTERN int SLang_push_array (SLang_Array_Type *at, int do_free);
940 SL_EXTERN void SLang_free_array (SLang_Array_Type *at);
941 SL_EXTERN SLang_Array_Type *SLang_create_array (SLtype, int, VOID_STAR, SLindex_Type *, unsigned int);
942 SL_EXTERN SLang_Array_Type *SLang_create_array1 (SLtype, int, VOID_STAR, SLindex_Type *, unsigned int, int);
943 SL_EXTERN SLang_Array_Type *SLang_duplicate_array (SLang_Array_Type *);
944 SL_EXTERN int SLang_get_array_element (SLang_Array_Type *, SLindex_Type *, VOID_STAR);
945 SL_EXTERN int SLang_set_array_element (SLang_Array_Type *, SLindex_Type *, VOID_STAR);
946 
947 typedef int SLarray_Contract_Fun_Type (VOID_STAR xp, unsigned int increment, unsigned int num, VOID_STAR yp);
948 typedef struct
949 {
950    SLtype from_type;		       /* if array is this type */
951    SLtype typecast_to_type;	       /* typecast it to this */
952    SLtype result_type;		       /* to produce this */
953    SLarray_Contract_Fun_Type *f;       /* via this function */
954 }
955 SLarray_Contract_Type;
956 SL_EXTERN int SLarray_contract_array (SLCONST SLarray_Contract_Type *);
957 
958 typedef int SLarray_Map_Fun_Type (SLtype xtype, VOID_STAR xp,
959 				  unsigned int increment, unsigned int num,
960 				  SLtype ytype, VOID_STAR yp, VOID_STAR clientdata);
961 typedef struct
962 {
963    SLtype from_type;		       /* if array is this type */
964    SLtype typecast_to_type;	       /* typecast it to this */
965    SLtype result_type;		       /* to produce this */
966    SLarray_Map_Fun_Type *f;	       /* via this function */
967 }
968 SLarray_Map_Type;
969 
970 SL_EXTERN int SLarray_map_array_1 (SLCONST SLarray_Map_Type *,
971 				int *use_this_dim,
972 				VOID_STAR clientdata);
973 SL_EXTERN int SLarray_map_array (SLCONST SLarray_Map_Type *);
974 
975 /*}}}*/
976 
977 /*{{{ Interpreter Function Prototypes */
978 
979 SL_EXTERN int SLerr_throw (int err, SLFUTURE_CONST char *msg, SLtype obj_type, VOID_STAR objptr);
980 SL_EXTERN void SLang_verror (int, SLFUTURE_CONST char *, ...) SLATTRIBUTE_PRINTF(2,3);
981 SL_EXTERN void SLang_verror_va (int errcode, SLFUTURE_CONST char *fmt, va_list va);
982 SL_EXTERN int SLang_get_error (void);
983 SL_EXTERN int SLang_set_error (int);
984 SL_EXTERN SLFUTURE_CONST char *SLerr_strerror (int errcode);
985 SL_EXTERN int SLerr_new_exception (int baseclass, SLFUTURE_CONST char *name, SLFUTURE_CONST char *descript);
986 SL_EXTERN int SLerr_exception_eqs (int, int);
987 
988 SL_EXTERN int SL_Any_Error;
989 SL_EXTERN int SL_OS_Error;
990 SL_EXTERN int   SL_Malloc_Error;
991 SL_EXTERN int   SL_IO_Error;
992 SL_EXTERN int     SL_Write_Error;
993 SL_EXTERN int     SL_Read_Error;
994 SL_EXTERN int     SL_Open_Error;
995 SL_EXTERN int SL_RunTime_Error;
996 SL_EXTERN int   SL_InvalidParm_Error;
997 SL_EXTERN int   SL_TypeMismatch_Error;
998 SL_EXTERN int   SL_UserBreak_Error;
999 SL_EXTERN int   SL_Stack_Error;
1000 SL_EXTERN int     SL_StackOverflow_Error;
1001 SL_EXTERN int     SL_StackUnderflow_Error;
1002 SL_EXTERN int   SL_ReadOnly_Error;
1003 SL_EXTERN int   SL_VariableUninitialized_Error;
1004 SL_EXTERN int   SL_NumArgs_Error;
1005 SL_EXTERN int   SL_Index_Error;
1006 SL_EXTERN int SL_Parse_Error;
1007 SL_EXTERN int   SL_Syntax_Error;
1008 SL_EXTERN int   SL_DuplicateDefinition_Error;
1009 SL_EXTERN int   SL_UndefinedName_Error;
1010 SL_EXTERN int SL_Usage_Error;
1011 SL_EXTERN int SL_Application_Error;
1012 SL_EXTERN int SL_Internal_Error;
1013 SL_EXTERN int SL_NotImplemented_Error;
1014 SL_EXTERN int SL_LimitExceeded_Error;
1015 SL_EXTERN int SL_Forbidden_Error;
1016 SL_EXTERN int SL_Math_Error;
1017 SL_EXTERN int   SL_DivideByZero_Error;
1018 SL_EXTERN int   SL_ArithOverflow_Error;
1019 SL_EXTERN int   SL_ArithUnderflow_Error;
1020 SL_EXTERN int   SL_Domain_Error;
1021 SL_EXTERN int SL_Data_Error;
1022 SL_EXTERN int SL_Unicode_Error;
1023 SL_EXTERN int   SL_InvalidUTF8_Error;
1024 SL_EXTERN int SL_Namespace_Error;
1025 SL_EXTERN int SL_Unknown_Error;
1026 SL_EXTERN int SL_Import_Error;
1027 
1028 /* Non zero if error occurs.  Must be reset to zero to continue. */
1029 
1030 /* Compatibility */
1031 #define USER_BREAK			SL_UserBreak_Error
1032 #define INTRINSIC_ERROR			SL_RunTime_Error
1033 #define SL_OBJ_NOPEN			SL_Open_Error
1034 
1035 #define SL_UNKNOWN_ERROR	SL_Unknown_Error
1036 #define SL_APPLICATION_ERROR	SL_Application_Error
1037 #define SL_INTERNAL_ERROR	SL_Internal_Error
1038 #define SL_INTRINSIC_ERROR	SL_RunTime_Error
1039 #define SL_NOT_IMPLEMENTED	SL_NotImplemented_Error
1040 #define SL_BUILTIN_LIMIT_EXCEEDED	SL_LimitExceeded_Error
1041 #define SL_MALLOC_ERROR		SL_Malloc_Error
1042 #define SL_USER_BREAK		SL_UserBreak_Error
1043 #define SL_IO_WRITE_ERROR	SL_Write_Error
1044 #define SL_IO_READ_ERROR	SL_Read_Error
1045 #define SL_IO_OPEN_ERROR	SL_Open_Error
1046 #define SL_SYNTAX_ERROR		SL_Syntax_Error
1047 #define SL_STACK_OVERFLOW	SL_StackOverflow_Error
1048 #define SL_STACK_UNDERFLOW	SL_StackUnderflow_Error
1049 #define SL_TYPE_MISMATCH	SL_TypeMismatch_Error
1050 #define SL_READONLY_ERROR	SL_ReadOnly_Error
1051 #define SL_VARIABLE_UNINITIALIZED	SL_VariableUninitialized_Error
1052 #define SL_DUPLICATE_DEFINITION		SL_DuplicateDefinition_Error
1053 #define SL_INVALID_PARM			SL_InvalidParm_Error
1054 #define SL_UNDEFINED_NAME		SL_UndefinedName_Error
1055 #define SL_NUM_ARGS_ERROR		SL_NumArgs_Error
1056 #define SL_INDEX_ERROR			SL_Index_Error
1057 #define SL_DIVIDE_ERROR			SL_DivideByZero_Error
1058 #define SL_MATH_ERROR			SL_Math_Error
1059 #define SL_ARITH_OVERFLOW_ERROR		SL_ArithOverflow_Error
1060 #define SL_ARITH_UNDERFLOW_ERROR	SL_ArithUnderflow_Error
1061 #define SL_USAGE_ERROR			SL_Usage_Error
1062 #define SL_INVALID_DATA_ERROR		SL_Data_Error
1063 #define SL_UNICODE_ERROR		SL_Unicode_Error
1064 #define SL_INVALID_UTF8			SL_InvalidUTF8_Error
1065 
1066   SL_EXTERN int SLang_Traceback;
1067 #define SL_TB_NONE		0x0
1068 #define SL_TB_FULL		0x1    /* full traceback */
1069 #define SL_TB_OMIT_LOCALS	0x2    /* full, but omit local vars */
1070 #define SL_TB_PARTIAL		0x4    /* show just on line of traceback */
1071 
1072   /* If non-zero, dump an S-Lang traceback upon error.  Available as
1073      _traceback in S-Lang. */
1074 
1075   SL_EXTERN char *SLang_User_Prompt;
1076   /* Prompt to use when reading from stdin */
1077   SL_EXTERN int SLang_Version;
1078   SL_EXTERN SLFUTURE_CONST char *SLang_Version_String;
1079 SL_EXTERN SLFUTURE_CONST char *SLang_Doc_Dir;
1080 
1081 SL_EXTERN void (*SLang_VMessage_Hook) (SLFUTURE_CONST char *, va_list);
1082 SL_EXTERN void SLang_vmessage (SLFUTURE_CONST char *, ...) SLATTRIBUTE_PRINTF(1,2);
1083 
1084   SL_EXTERN void (*SLang_Error_Hook)(SLFUTURE_CONST char *);
1085   /* Pointer to application dependent error messaging routine.  By default,
1086      messages are displayed on stderr. */
1087 
1088   SL_EXTERN void (*SLang_Exit_Error_Hook)(SLFUTURE_CONST char *, va_list);
1089 SL_EXTERN void SLang_exit_error (SLFUTURE_CONST char *, ...) SLATTRIBUTE_((format (printf, 1, 2), noreturn));
1090   SL_EXTERN void (*SLang_Dump_Routine)(SLFUTURE_CONST char *);
1091   /* Called if S-Lang traceback is enabled as well as other debugging
1092      routines (e.g., trace).  By default, these messages go to stderr. */
1093 
1094   SL_EXTERN void (*SLang_Interrupt)(void);
1095   /* function to call whenever inner interpreter is entered.  This is
1096      a good place to set SLang_Error to USER_BREAK. */
1097 
1098   SL_EXTERN void (*SLang_User_Clear_Error)(void);
1099   /* function that gets called when '_clear_error' is called. */
1100 
1101   /* If non null, these call C functions before and after a slang function. */
1102   SL_EXTERN void (*SLang_Enter_Function)(SLFUTURE_CONST char *);
1103 SL_EXTERN void (*SLang_Exit_Function)(SLFUTURE_CONST char *);
1104 
1105 SL_EXTERN int SLang_Num_Function_Args;
1106 
1107 /* This function should be called when a system call is interrupted.  It
1108  * runs a set of hooks.  If any of the hooks returns -1, then the system call
1109  * should not be restarted.
1110  */
1111 SL_EXTERN int SLang_handle_interrupt (void);
1112 SL_EXTERN int SLang_add_interrupt_hook (int (*)(VOID_STAR), VOID_STAR);
1113 SL_EXTERN void SLang_remove_interrupt_hook (int (*)(VOID_STAR), VOID_STAR);
1114 
1115 /* Functions: */
1116 
1117 SL_EXTERN int SLang_init_all (void);
1118 /* Initializes interpreter and all modules */
1119 
1120 SL_EXTERN int SLang_init_slang (void);
1121 /* This function is mandatory and must be called by all applications that
1122  * use the interpreter
1123  */
1124 SL_EXTERN int SLang_init_posix_process (void);   /* process specific intrinsics */
1125 SL_EXTERN int SLang_init_stdio (void);    /* fgets, etc. stdio functions  */
1126 SL_EXTERN int SLang_init_posix_dir (void);
1127 SL_EXTERN int SLang_init_ospath (void);
1128 
1129 SL_EXTERN int SLang_init_slmath (void);
1130 /* called if math functions sin, cos, etc... are needed. */
1131 
1132 /* These functions are obsolete.  Use init_stdio, posix_process, etc. */
1133 SL_EXTERN int SLang_init_slfile (void);
1134 SL_EXTERN int SLang_init_slunix (void);
1135 
1136 SL_EXTERN int SLang_init_slassoc (void);
1137 /* Assoc Arrays (Hashes) */
1138 
1139 SL_EXTERN int SLang_init_array (void);
1140 /* Additional arrays functions: transpose, etc... */
1141 
1142 SL_EXTERN int SLang_init_array_extra (void);
1143 /* Additional arrays functions, if any */
1144 
1145 SL_EXTERN int SLang_init_signal (void);
1146 /* signal handling within the interpreter */
1147 
1148 /* Dynamic linking facility */
1149 SL_EXTERN int SLang_init_import (void);
1150 
1151    SL_EXTERN int SLang_load_file (SLFUTURE_CONST char *);
1152    /* Load a file of S-Lang code for interpreting.  If the parameter is
1153     * NULL, input comes from stdin. */
1154 
1155    SL_EXTERN void SLang_restart(int);
1156    /* should be called if an error occurs.  If the passed integer is
1157     * non-zero, items are popped off the stack; otherwise, the stack is
1158     * left intact.  Any time the stack is believed to be trashed, this routine
1159     * should be called with a non-zero argument (e.g., if setjmp/longjmp is
1160     * called). */
1161 
1162    SL_EXTERN int SLang_byte_compile_file(SLFUTURE_CONST char *, int);
1163    /* takes a file of S-Lang code and ``byte-compiles'' it for faster
1164     * loading.  The new filename is equivalent to the old except that a `c' is
1165     * appended to the name.  (e.g., init.sl --> init.slc).  The second
1166     * specified the method; currently, it is not used.
1167     */
1168 
1169    SL_EXTERN int SLang_autoload(SLFUTURE_CONST char *, SLFUTURE_CONST char *);
1170    /* Automatically load S-Lang function p1 from file p2.  This function
1171       is also available via S-Lang */
1172 
1173    SL_EXTERN int SLang_load_string(SLFUTURE_CONST char *);
1174    /* Like SLang_load_file except input is from a null terminated string. */
1175 
1176 SL_EXTERN int SLstack_depth(void);
1177 
1178 SL_EXTERN int SLdo_pop(void);
1179 SL_EXTERN int SLdo_pop_n(unsigned int);
1180 
1181 SL_EXTERN int SLang_push_char (char);
1182 SL_EXTERN int SLang_push_uchar (unsigned char);
1183 SL_EXTERN int SLang_pop_char (char *);
1184 SL_EXTERN int SLang_pop_uchar (unsigned char *);
1185 
1186 #define SLang_push_integer SLang_push_int
1187 #define SLang_push_uinteger SLang_push_uint
1188 #define SLang_pop_integer SLang_pop_int
1189 #define SLang_pop_uinteger SLang_pop_uint
1190 SL_EXTERN int SLang_push_int(int);
1191 SL_EXTERN int SLang_push_uint(unsigned int);
1192 SL_EXTERN int SLang_pop_int(int *);
1193 SL_EXTERN int SLang_pop_uint(unsigned int *);
1194 
1195 SL_EXTERN int SLang_pop_short(short *);
1196 SL_EXTERN int SLang_pop_ushort(unsigned short *);
1197 SL_EXTERN int SLang_push_short(short);
1198 SL_EXTERN int SLang_push_ushort(unsigned short);
1199 
1200 SL_EXTERN int SLang_pop_long(long *);
1201 SL_EXTERN int SLang_pop_ulong(unsigned long *);
1202 SL_EXTERN int SLang_push_long(long);
1203 SL_EXTERN int SLang_push_ulong(unsigned long);
1204 
1205 SL_EXTERN int SLang_pop_float(float *);
1206 SL_EXTERN int SLang_push_float(float);
1207 
1208 SL_EXTERN int SLang_pop_double(double *);
1209 SL_EXTERN int SLang_push_double(double);
1210 
1211 SL_EXTERN int SLang_push_complex (double, double);
1212 SL_EXTERN int SLang_pop_complex (double *, double *);
1213 
1214 SL_EXTERN int SLang_push_datatype (SLtype);
1215 SL_EXTERN int SLang_pop_datatype (SLtype *);
1216 
1217 SL_EXTERN int SLang_push_malloced_string(char *);
1218 /* The normal SLang_push_string pushes an slstring.  This one converts
1219  * a normally malloced string to an slstring, and then frees the
1220  * malloced string.  So, do NOT use the malloced string after calling
1221  * this routine because it will be freed!  The routine returns -1 upon
1222  * error, but the string will be freed.
1223  */
1224 
1225 SL_EXTERN int SLang_push_string(SLFUTURE_CONST char *);
1226 SL_EXTERN int SLpop_string (char **);  /* malloced -- free with SLfree */
1227 
1228 SL_EXTERN int SLang_push_null (void);
1229 SL_EXTERN int SLang_pop_null (void);
1230 
1231 SL_EXTERN int SLang_push_value (SLtype type, VOID_STAR);
1232 SL_EXTERN int SLang_pop_value (SLtype type, VOID_STAR);
1233 SL_EXTERN void SLang_free_value (SLtype type, VOID_STAR);
1234 
1235 typedef struct _pSLang_Object_Type SLang_Any_Type;
1236 SL_EXTERN int SLang_pop_anytype (SLang_Any_Type **);
1237 SL_EXTERN int SLang_push_anytype (SLang_Any_Type *);
1238 SL_EXTERN void SLang_free_anytype (SLang_Any_Type *);
1239 
1240 #ifdef SLANG_SOURCE_
1241 typedef struct _pSLang_Ref_Type SLang_Ref_Type;
1242 #else
1243 typedef int SLang_Ref_Type;
1244 #endif
1245 
1246 SL_EXTERN int SLang_pop_ref (SLang_Ref_Type **);
1247 SL_EXTERN void SLang_free_ref (SLang_Ref_Type *);
1248 SL_EXTERN int SLang_assign_to_ref (SLang_Ref_Type *, SLtype, VOID_STAR);
1249 SL_EXTERN int SLang_assign_nametype_to_ref (SLang_Ref_Type *, SLang_Name_Type *);
1250 SL_EXTERN SLang_Name_Type *SLang_pop_function (void);
1251 SL_EXTERN int SLang_push_function (SLang_Name_Type *);
1252 SL_EXTERN SLang_Name_Type *SLang_get_fun_from_ref (SLang_Ref_Type *);
1253 SL_EXTERN void SLang_free_function (SLang_Name_Type *f);
1254 SL_EXTERN SLang_Name_Type *SLang_copy_function (SLang_Name_Type *);
1255 
1256 /* C structure interface */
1257 SL_EXTERN int SLang_push_cstruct (VOID_STAR, SLang_CStruct_Field_Type *);
1258 SL_EXTERN int SLang_pop_cstruct (VOID_STAR, SLang_CStruct_Field_Type *);
1259 SL_EXTERN void SLang_free_cstruct (VOID_STAR, SLang_CStruct_Field_Type *);
1260 SL_EXTERN int SLang_assign_cstruct_to_ref (SLang_Ref_Type *, VOID_STAR, SLang_CStruct_Field_Type *);
1261 
1262    SL_EXTERN int SLang_is_defined(SLFUTURE_CONST char *);
1263    /* Return non-zero is p1 is defined otherwise returns 0. */
1264 
1265    SL_EXTERN int SLang_run_hooks(SLFUTURE_CONST char *, unsigned int, ...);
1266    /* calls S-Lang function p1 pushing p2 strings in the variable argument
1267     * list onto the stack first.
1268     * Returns -1 upon error, 1 if hooks exists and it ran,
1269     * or 0 if hook does not exist.  Thus it returns non-zero is hook was called.
1270     */
1271 
1272 /* These functions return 1 if the indicated function exists and the function
1273  * runs without error.  If the function does not exist, the function returns
1274  * 0.  Otherwise -1 is returned with SLang_Error set appropriately.
1275  */
1276 SL_EXTERN int SLexecute_function (SLang_Name_Type *);
1277 SL_EXTERN int SLang_execute_function(SLFUTURE_CONST char *);
1278 
1279 SL_EXTERN int SLang_end_arg_list (void);
1280 SL_EXTERN int SLang_start_arg_list (void);
1281 
1282 SL_EXTERN int SLang_add_intrinsic_array (SLFUTURE_CONST char *,   /* name */
1283 				      SLtype,   /* type */
1284 				      int,   /* readonly */
1285 				      VOID_STAR,   /* data */
1286 				      unsigned int, ...);   /* num dims */
1287 
1288 SL_EXTERN int SLextract_list_element (SLFUTURE_CONST char *, unsigned int, char,
1289 				   char *, unsigned int);
1290 
1291 /* If utf8_encode is >1, then byte values > 127 will be utf8-encoded.
1292  * If the string is already in utf8 form, and utf8 is desired, then use with
1293  * utf8_encode set to 0.  A value of -1 implies use the value appropriate for
1294  * the current state of the interpreter.
1295  */
1296 SL_EXTERN int SLexpand_escaped_string (char *dest, char *src, char *src_max,
1297 				       int utf8_encode);
1298 
1299 SL_EXTERN SLang_Name_Type *SLang_get_function (SLFUTURE_CONST char *);
1300 SL_EXTERN void SLang_release_function (SLang_Name_Type *);
1301 
1302 SL_EXTERN int SLreverse_stack (int);
1303 SL_EXTERN int SLroll_stack (int);
1304 /* If argument p is positive, the top p objects on the stack are rolled
1305  * up.  If negative, the stack is rolled down.
1306  */
1307 
1308 /* exchange two items on the stack.  The top item is given by 0 */
1309 SL_EXTERN int SLstack_exch (unsigned int, unsigned int);
1310 
1311 SL_EXTERN int SLdup_n (int n);
1312 /* Duplicate top n elements of stack */
1313 
1314 SL_EXTERN int SLang_peek_at_stack1 (void);
1315 SL_EXTERN int SLang_peek_at_stack (void);
1316 SL_EXTERN int SLang_peek_at_stack_n (unsigned int n);
1317 SL_EXTERN int SLang_peek_at_stack1_n (unsigned int n);
1318 
1319 /* Returns type of next object on stack-- -1 upon stack underflow. */
1320 SL_EXTERN void SLmake_lut (unsigned char *, unsigned char *, unsigned char);
1321 
1322    SL_EXTERN int SLang_guess_type (SLFUTURE_CONST char *);
1323 
1324 SL_EXTERN int SLstruct_create_struct (unsigned int,
1325 				   SLFUTURE_CONST char **,
1326 				   SLtype *,
1327 				   VOID_STAR *);
1328 
1329 /*}}}*/
1330 
1331 /*{{{ Misc Functions */
1332 
1333 /* This is an interface to atexit */
1334 SL_EXTERN int SLang_add_cleanup_function (void (*)(void));
1335 
1336 SL_EXTERN char *SLmake_string (SLFUTURE_CONST char *);
1337 SL_EXTERN char *SLmake_nstring (SLFUTURE_CONST char *, SLstrlen_Type);
1338 /* Returns a null terminated string made from the first n characters of the
1339  * string.
1340  */
1341 
1342 /* Binary strings */
1343 /* The binary string is an opaque type.  Use the SLbstring_get_pointer function
1344  * to get a pointer and length.
1345  */
1346 typedef struct _pSLang_BString_Type SLang_BString_Type;
1347 SL_EXTERN unsigned char *SLbstring_get_pointer (SLang_BString_Type *, SLstrlen_Type *);
1348 
1349 SL_EXTERN SLang_BString_Type *SLbstring_dup (SLang_BString_Type *);
1350 SL_EXTERN SLang_BString_Type *SLbstring_create (unsigned char *, SLstrlen_Type);
1351 
1352 /* The create_malloced function uses the first argument which is assumed
1353  * to be a pointer to a len + 1 malloced string.  The extra byte is for
1354  * \0 termination.
1355  */
1356 SL_EXTERN SLang_BString_Type *SLbstring_create_malloced (unsigned char *s, SLstrlen_Type len, int free_on_error);
1357 
1358 /* Create a bstring from an slstring */
1359 SL_EXTERN SLang_BString_Type *SLbstring_create_slstring (SLFUTURE_CONST char *);
1360 
1361 SL_EXTERN void SLbstring_free (SLang_BString_Type *);
1362 SL_EXTERN int SLang_pop_bstring (SLang_BString_Type **);
1363 SL_EXTERN int SLang_push_bstring (SLang_BString_Type *);
1364 
1365 SL_EXTERN SLFUTURE_VOID *SLmalloc (SLstrlen_Type);
1366 SL_EXTERN SLFUTURE_VOID *SLcalloc (SLstrlen_Type, SLstrlen_Type);
1367 SL_EXTERN void SLfree(SLFUTURE_VOID *);	       /* This function handles NULL */
1368 SL_EXTERN SLFUTURE_VOID *SLrealloc (SLFUTURE_VOID *, SLstrlen_Type);
1369 
1370 SL_EXTERN char *SLcurrent_time_string (void);
1371 
1372 SL_EXTERN int SLatoi(unsigned char *);
1373 SL_EXTERN long SLatol (unsigned char *);
1374 SL_EXTERN unsigned long SLatoul (unsigned char *);
1375 
1376 #ifdef HAVE_LONG_LONG
1377 SL_EXTERN long long SLatoll (unsigned char *s);
1378 SL_EXTERN unsigned long long SLatoull (unsigned char *s);
1379 #endif
1380 SL_EXTERN int SLang_pop_fileptr (SLang_MMT_Type **, FILE **);
1381 SL_EXTERN SLFUTURE_CONST char *SLang_get_name_from_fileptr (SLang_MMT_Type *);
1382 
1383 SL_EXTERN int SLang_get_fileptr (SLang_MMT_Type *, FILE **);
1384 /* This function may be used to obtain the FILE* object associated with an MMT.
1385  * It returns 0 if no-errors were encountered, and -1 otherwise.
1386  * If FILE* object has been closed, this function will return 0 and set the FILE*
1387  * parameter to NULL.
1388  */
1389 
1390 typedef struct _pSLFile_FD_Type SLFile_FD_Type;
1391 SL_EXTERN SLFile_FD_Type *SLfile_create_fd (SLFUTURE_CONST char *, int);
1392 SL_EXTERN void SLfile_free_fd (SLFile_FD_Type *);
1393 SL_EXTERN int SLfile_push_fd (SLFile_FD_Type *);
1394 SL_EXTERN int SLfile_pop_fd (SLFile_FD_Type **);
1395 SL_EXTERN int SLfile_get_fd (SLFile_FD_Type *, int *);
1396 SL_EXTERN SLFile_FD_Type *SLfile_dup_fd (SLFile_FD_Type *f0);
1397 SL_EXTERN int SLang_init_posix_io (void);
1398 
1399 /* These routines allow an application to attach an object to a file-descriptor
1400  * as well a provide read/write/close/etc methods.  To allow the coexistence of
1401  * different types of objects, a clientdata-id must be used.
1402  */
1403 SL_EXTERN int SLfile_set_getfd_method (SLFile_FD_Type *f, int (*func)(VOID_STAR, int *));
1404 SL_EXTERN int SLfile_set_close_method (SLFile_FD_Type *f, int (*func)(VOID_STAR));
1405 SL_EXTERN int SLfile_set_read_method (SLFile_FD_Type *f, int (*func)(VOID_STAR, char*, unsigned int));
1406 SL_EXTERN int SLfile_set_write_method (SLFile_FD_Type *f, int (*func)(VOID_STAR, char*, unsigned int));
1407 SL_EXTERN int SLfile_set_dup_method (SLFile_FD_Type *f, SLFile_FD_Type *(*func)(VOID_STAR));
1408 SL_EXTERN int SLfile_create_clientdata_id (int *id);
1409 SL_EXTERN int SLfile_set_clientdata (SLFile_FD_Type *f, void (*free_func)(VOID_STAR), VOID_STAR cd, int id);
1410 SL_EXTERN int SLfile_get_clientdata (SLFile_FD_Type *f, int id, VOID_STAR *cdp);
1411 
1412 typedef double (*SLang_To_Double_Fun_Type)(VOID_STAR);
1413 SL_EXTERN SLang_To_Double_Fun_Type SLarith_get_to_double_fun (SLtype, unsigned int *);
1414 
1415 SL_EXTERN int SLang_set_argc_argv (int, char **);
1416 
1417 /*}}}*/
1418 
1419 /*{{{ Qualifier Functions */
1420 
1421 SL_EXTERN int SLang_qualifier_exists (SLCONST char *name);
1422 SL_EXTERN int SLang_get_int_qualifier (SLCONST char *name, int *val, int defval);
1423 SL_EXTERN int SLang_get_long_qualifier (SLCONST char *name, long *val, long defval);
1424 SL_EXTERN int SLang_get_double_qualifier (SLCONST char *name, double *val, double defval);
1425 SL_EXTERN int SLang_get_string_qualifier (SLCONST char *name, char **val, SLFUTURE_CONST char *defval);
1426 
1427 /*}}}*/
1428 
1429 /*{{{ SLang getkey interface Functions */
1430 
1431 #ifdef REAL_UNIX_SYSTEM
1432 SL_EXTERN int SLang_TT_Baud_Rate;
1433 SL_EXTERN int SLang_TT_Read_FD;
1434 #else
1435 # if defined(__WIN32__)
1436 /* I do not want to include windows.h just to get the typedef for HANDLE.
1437  * Make this conditional upon the inclusion of windows.h.
1438  */
1439 #  ifdef _WINDOWS_
1440 SL_EXTERN HANDLE SLw32_Hstdin;
1441 #  endif
1442 # endif
1443 #endif
1444 
1445 SL_EXTERN int SLang_init_tty (int, int, int);
1446 /* Initializes the tty for single character input.  If the first parameter *p1
1447  * is in the range 0-255, it will be used for the abort character;
1448  * otherwise, (unix only) if it is -1, the abort character will be the one
1449  * used by the terminal.  If the second parameter p2 is non-zero, flow
1450  * control is enabled.  If the last parmeter p3 is zero, output processing
1451  * is NOT turned on.  A value of zero is required for the screen management
1452  * routines. Returns 0 upon success. In addition, if SLang_TT_Baud_Rate ==
1453  * 0 when this function is called, SLang will attempt to determine the
1454  * terminals baud rate.  As far as the SLang library is concerned, if
1455  * SLang_TT_Baud_Rate is less than or equal to zero, the baud rate is
1456  * effectively infinite.
1457  */
1458 
1459 SL_EXTERN void SLang_reset_tty (void);
1460 /* Resets tty to what it was prior to a call to SLang_init_tty */
1461 #ifdef REAL_UNIX_SYSTEM
1462 SL_EXTERN void SLtty_set_suspend_state (int);
1463    /* If non-zero argument, terminal driver will be told to react to the
1464     * suspend character.  If 0, it will not.
1465     */
1466 SL_EXTERN int (*SLang_getkey_intr_hook) (void);
1467 #endif
1468 
1469 #define SLANG_GETKEY_ERROR 0xFFFF
1470 SL_EXTERN unsigned int SLang_getkey (void);
1471 /* reads a single key from the tty.  If the read fails,  0xFFFF is returned. */
1472 
1473 #ifdef IBMPC_SYSTEM
1474 SL_EXTERN int SLgetkey_map_to_ansi (int);
1475 #endif
1476 
1477 SL_EXTERN int SLang_ungetkey_string (unsigned char *, unsigned int);
1478 SL_EXTERN int SLang_buffer_keystring (unsigned char *, unsigned int);
1479 SL_EXTERN int SLang_ungetkey (unsigned char);
1480 SL_EXTERN void SLang_flush_input (void);
1481 SL_EXTERN int SLang_input_pending (int);
1482 SL_EXTERN int SLang_Abort_Char;
1483 /* The value of the character (0-255) used to trigger SIGINT */
1484 SL_EXTERN int SLang_Ignore_User_Abort;
1485 /* If non-zero, pressing the abort character will not result in USER_BREAK
1486  * SLang_Error. */
1487 
1488 SL_EXTERN int SLang_set_abort_signal (void (*)(int));
1489 /* If SIGINT is generated, the function p1 will be called.  If p1 is NULL
1490  * the SLang_default signal handler is called.  This sets SLang_Error to
1491  * USER_BREAK.  I suspect most users will simply want to pass NULL.
1492  */
1493 SL_EXTERN unsigned int SLang_Input_Buffer_Len;
1494 
1495 SL_EXTERN volatile int SLKeyBoard_Quit;
1496 
1497 #ifdef VMS
1498 /* If this function returns -1, ^Y will be added to input buffer. */
1499 SL_EXTERN int (*SLtty_VMS_Ctrl_Y_Hook) (void);
1500 #endif
1501 /*}}}*/
1502 
1503 /*{{{ SLang Keymap routines */
1504 
1505 typedef struct SLKeymap_Function_Type
1506 {
1507    SLFUTURE_CONST char *name;
1508    int (*f)(void);
1509 }
1510 SLKeymap_Function_Type;
1511 
1512 #define SLANG_MAX_KEYMAP_KEY_SEQ	14
1513 typedef struct SLang_Key_Type
1514 {
1515    struct SLang_Key_Type *next;
1516    union
1517      {
1518 	char *s;
1519 	FVOID_STAR f;
1520 	unsigned int keysym;
1521 	SLang_Name_Type *slang_fun;
1522      }
1523      f;
1524    unsigned char type;	       /* type of function */
1525 #define SLKEY_F_INTERPRET	0x01
1526 #define SLKEY_F_INTRINSIC	0x02
1527 #define SLKEY_F_KEYSYM		0x03
1528 #define SLKEY_F_SLANG		0x04
1529    unsigned char str[SLANG_MAX_KEYMAP_KEY_SEQ + 1];/* key sequence */
1530 }
1531 SLang_Key_Type;
1532 
1533 int SLkm_set_free_method (int, void (*)(int, VOID_STAR));
1534 
1535 typedef struct _pSLkeymap_Type
1536 {
1537    SLFUTURE_CONST char *name;			       /* hashed string */
1538    SLang_Key_Type *keymap;
1539    SLKeymap_Function_Type *functions;  /* intrinsic functions */
1540    struct _pSLkeymap_Type *next;
1541 } SLkeymap_Type;
1542 
1543 SL_EXTERN SLkeymap_Type *SLKeyMap_List_Root;   /* linked list of keymaps */
1544 
1545 /* backward compat */
1546 typedef SLkeymap_Type SLKeyMap_List_Type;
1547 
1548 SL_EXTERN char *SLang_process_keystring(SLFUTURE_CONST char *);
1549 
1550 SL_EXTERN int SLkm_define_key (SLFUTURE_CONST char *, FVOID_STAR, SLkeymap_Type *);
1551 
1552 SL_EXTERN int SLang_define_key(SLFUTURE_CONST char *, SLFUTURE_CONST char *, SLkeymap_Type *);
1553 /* Like define_key1 except that p2 is a string that is to be associated with
1554  * a function in the functions field of p3.
1555  */
1556 
1557 SL_EXTERN int SLkm_define_keysym (SLFUTURE_CONST char *, unsigned int, SLkeymap_Type *);
1558 SL_EXTERN int SLkm_define_slkey (SLFUTURE_CONST char *keysequence, SLang_Name_Type *func, SLkeymap_Type *);
1559 SL_EXTERN void SLang_undefine_key(SLFUTURE_CONST char *, SLkeymap_Type *);
1560 
1561 SL_EXTERN SLkeymap_Type *SLang_create_keymap(SLFUTURE_CONST char *, SLkeymap_Type *);
1562 /* create and returns a pointer to a new keymap named p1 created by copying
1563  * keymap p2.  If p2 is NULL, it is up to the calling routine to initialize
1564  * the keymap.
1565  */
1566 
1567 SL_EXTERN char *SLang_make_keystring(unsigned char *);
1568 
1569 SL_EXTERN SLang_Key_Type *SLang_do_key(SLkeymap_Type *, int (*)(void));
1570 /* read a key using keymap p1 with getkey function p2 */
1571 
1572 SL_EXTERN FVOID_STAR SLang_find_key_function(SLFUTURE_CONST char *, SLkeymap_Type *);
1573 
1574 SL_EXTERN SLkeymap_Type *SLang_find_keymap(SLFUTURE_CONST char *);
1575 
1576 SL_EXTERN int SLang_Last_Key_Char;
1577 /* Despite the name of this variable, its value is the last BYTE of a key-sequence */
1578 
1579 SL_EXTERN int SLang_Key_TimeOut_Flag;
1580 
1581 /*}}}*/
1582 
1583 /*{{{ SLang Readline Interface */
1584 
1585 typedef struct _pSLrline_Type SLrline_Type;
1586 SL_EXTERN SLrline_Type *SLrline_open (unsigned int width, unsigned int flags);
1587 SL_EXTERN SLrline_Type *SLrline_open2 (SLFUTURE_CONST char *, unsigned int width, unsigned int flags);
1588 #define SL_RLINE_NO_ECHO	0x0001
1589 #define SL_RLINE_USE_ANSI	0x0002
1590 #define SL_RLINE_BLINK_MATCH	0x0004
1591 #define SL_RLINE_UTF8_MODE	0x0008
1592 #define SL_RLINE_USE_MULTILINE  0x0010
1593 
1594 SL_EXTERN void SLrline_close (SLrline_Type *);
1595 
1596 /* This returns a malloced string */
1597 SL_EXTERN char *SLrline_read_line (SLrline_Type *, SLFUTURE_CONST char *prompt, unsigned int *lenp);
1598 
1599 SL_EXTERN int SLrline_bol (SLrline_Type *);
1600 SL_EXTERN int SLrline_eol (SLrline_Type *);
1601 SL_EXTERN int SLrline_del (SLrline_Type *, unsigned int len);
1602 SL_EXTERN int SLrline_ins (SLrline_Type *, SLFUTURE_CONST char *s, unsigned int len);
1603 SL_EXTERN int SLrline_move (SLrline_Type *, int);
1604 
1605 SL_EXTERN int SLrline_set_echo (SLrline_Type *, int);
1606 SL_EXTERN int SLrline_set_tab (SLrline_Type *, unsigned int tabwidth);
1607 SL_EXTERN int SLrline_set_point (SLrline_Type *, unsigned int);
1608 SL_EXTERN int SLrline_set_line (SLrline_Type *, SLFUTURE_CONST char *);
1609 SL_EXTERN int SLrline_set_hscroll (SLrline_Type *, unsigned int);
1610 SL_EXTERN int SLrline_set_display_width (SLrline_Type *, unsigned int);
1611 
1612 SL_EXTERN int SLrline_get_echo (SLrline_Type *, int *);
1613 SL_EXTERN int SLrline_get_tab (SLrline_Type *, unsigned int *);
1614 SL_EXTERN int SLrline_get_point (SLrline_Type *, unsigned int *);
1615 SL_EXTERN char *SLrline_get_line (SLrline_Type *);
1616 SL_EXTERN int SLrline_get_hscroll (SLrline_Type *, unsigned int *);
1617 SL_EXTERN int SLrline_get_display_width (SLrline_Type *, unsigned int *);
1618 
1619 SL_EXTERN int SLrline_set_update_hook (SLrline_Type *,
1620 				    void (*)(SLrline_Type *rli,
1621 					     SLFUTURE_CONST char *prompt,
1622 					     SLFUTURE_CONST char *buf, unsigned int len,
1623 					     unsigned int point, VOID_STAR client_data),
1624 				    VOID_STAR client_data);
1625 /* free update_hook client_data */
1626 SL_EXTERN void SLrline_set_free_update_cb (SLrline_Type *, void (*)(SLrline_Type *, VOID_STAR));
1627 
1628 /* These functions are passed a pointer to the update_hook client_data */
1629 SL_EXTERN void SLrline_set_update_clear_cb(SLrline_Type *, void (*)(SLrline_Type *, VOID_STAR));
1630 SL_EXTERN void SLrline_set_update_preread_cb (SLrline_Type *, void (*)(SLrline_Type *, VOID_STAR));
1631 SL_EXTERN void SLrline_set_update_postread_cb (SLrline_Type *, void (*)(SLrline_Type *, VOID_STAR));
1632 SL_EXTERN void SLrline_set_update_width_cb (SLrline_Type *, void (*)(SLrline_Type *, int, VOID_STAR));
1633 SL_EXTERN int SLrline_get_update_client_data (SLrline_Type *, VOID_STAR *);
1634 
1635 SL_EXTERN SLkeymap_Type *SLrline_get_keymap (SLrline_Type *);
1636 
1637 SL_EXTERN void SLrline_redraw (SLrline_Type *);
1638 SL_EXTERN int SLrline_save_line (SLrline_Type *);
1639 SL_EXTERN int SLrline_add_to_history (SLrline_Type *, SLFUTURE_CONST char *);
1640 
1641 /* Interpreter interface */
1642 SL_EXTERN int SLrline_init (SLFUTURE_CONST char *appname, SLFUTURE_CONST char *user_initfile, SLFUTURE_CONST char *sys_initfile);
1643 
1644 /* Compatibility */
1645 typedef SLrline_Type SLang_RLine_Info_Type;
1646 
1647 /*}}}*/
1648 
1649 /*{{{ Low Level Screen Output Interface */
1650 
1651 SL_EXTERN unsigned long SLtt_Num_Chars_Output;
1652 SL_EXTERN int SLtt_Baud_Rate;
1653 
1654 typedef unsigned long SLtt_Char_Type;
1655 
1656 #define SLTT_BOLD_MASK	0x01000000UL
1657 #define SLTT_BLINK_MASK	0x02000000UL
1658 #define SLTT_ULINE_MASK	0x04000000UL
1659 #define SLTT_REV_MASK	0x08000000UL
1660 #define SLTT_ALTC_MASK  0x10000000UL
1661 #define SLTT_ITALIC_MASK  0x20000000UL
1662 
1663 SL_EXTERN int SLtt_Screen_Rows;
1664 SL_EXTERN int SLtt_Screen_Cols;
1665 SL_EXTERN int SLtt_Term_Cannot_Insert;
1666 SL_EXTERN int SLtt_Term_Cannot_Scroll;
1667 SL_EXTERN int SLtt_Use_Ansi_Colors;
1668 SL_EXTERN int SLtt_Ignore_Beep;
1669 #if defined(REAL_UNIX_SYSTEM)
1670 SL_EXTERN int SLtt_Force_Keypad_Init;
1671 SL_EXTERN int SLang_TT_Write_FD;
1672 #endif
1673 
1674 #ifndef IBMPC_SYSTEM
1675 SL_EXTERN char *SLtt_Graphics_Char_Pairs;
1676 #endif
1677 
1678 #ifndef __GO32__
1679 #if defined(VMS) || defined(REAL_UNIX_SYSTEM)
1680 SL_EXTERN int SLtt_Blink_Mode;
1681 SL_EXTERN int SLtt_Use_Blink_For_ACS;
1682 SL_EXTERN int SLtt_Newline_Ok;
1683 SL_EXTERN int SLtt_Has_Alt_Charset;
1684 SL_EXTERN int SLtt_Has_Status_Line;       /* if 0, NO.  If > 0, YES, IF -1, ?? */
1685 # ifndef VMS
1686 SL_EXTERN int SLtt_Try_Termcap;
1687 # endif
1688 #endif
1689 #endif
1690 
1691 #if defined(IBMPC_SYSTEM)
1692 SL_EXTERN int SLtt_Msdos_Cheap_Video;
1693 #endif
1694 
1695 typedef unsigned short SLsmg_Color_Type;
1696 #define SLSMG_MAX_COLORS	0x7FFE /* keep one for BCE */
1697 #define SLSMG_COLOR_MASK	0x7FFF
1698 #define SLSMG_ACS_MASK		0x8000
1699 
1700 #define SLSMG_MAX_CHARS_PER_CELL 5
1701 typedef struct
1702 {
1703    unsigned int nchars;
1704    SLwchar_Type wchars[SLSMG_MAX_CHARS_PER_CELL];
1705    SLsmg_Color_Type color;
1706 }
1707 SLsmg_Char_Type;
1708 
1709 #define SLSMG_EXTRACT_COLOR(x) ((x).color)
1710 #define SLSMG_EXTRACT_CHAR(x) ((x).wchars[0])
1711 
1712 SL_EXTERN int SLtt_flush_output (void);
1713 SL_EXTERN void SLtt_set_scroll_region(int, int);
1714 SL_EXTERN void SLtt_reset_scroll_region(void);
1715 SL_EXTERN void SLtt_reverse_video (int);
1716 SL_EXTERN void SLtt_bold_video (void);
1717 SL_EXTERN void SLtt_begin_insert(void);
1718 SL_EXTERN void SLtt_end_insert(void);
1719 SL_EXTERN void SLtt_del_eol(void);
1720 SL_EXTERN void SLtt_goto_rc (int, int);
1721 SL_EXTERN void SLtt_delete_nlines(int);
1722 SL_EXTERN void SLtt_delete_char(void);
1723 SL_EXTERN void SLtt_erase_line(void);
1724 SL_EXTERN void SLtt_normal_video(void);
1725 SL_EXTERN void SLtt_cls(void);
1726 SL_EXTERN void SLtt_beep(void);
1727 SL_EXTERN void SLtt_reverse_index(int);
1728 SL_EXTERN void SLtt_smart_puts(SLsmg_Char_Type *, SLsmg_Char_Type *, int, int);
1729 SL_EXTERN void SLtt_write_string (SLFUTURE_CONST char *);
1730 SL_EXTERN void SLtt_putchar(char);
1731 SL_EXTERN int SLtt_init_video (void);
1732 SL_EXTERN int SLtt_reset_video (void);
1733 SL_EXTERN void SLtt_get_terminfo(void);
1734 SL_EXTERN void SLtt_get_screen_size (void);
1735 SL_EXTERN int SLtt_set_cursor_visibility (int);
1736 
1737 SL_EXTERN int SLtt_set_mouse_mode (int, int);
1738 
1739 #if defined(VMS) || defined(REAL_UNIX_SYSTEM)
1740 SL_EXTERN int SLtt_initialize (SLFUTURE_CONST char *);
1741 SL_EXTERN void SLtt_enable_cursor_keys(void);
1742 SL_EXTERN void SLtt_set_term_vtxxx(int *);
1743 SL_EXTERN void SLtt_wide_width(void);
1744 SL_EXTERN void SLtt_narrow_width(void);
1745 SL_EXTERN void SLtt_set_alt_char_set (int);
1746 SL_EXTERN int SLtt_write_to_status_line (SLFUTURE_CONST char *, int);
1747 SL_EXTERN void SLtt_disable_status_line (void);
1748 # ifdef REAL_UNIX_SYSTEM
1749 /* These are termcap/terminfo routines that assume SLtt_initialize has
1750  * been called.
1751  */
1752 SL_EXTERN char *SLtt_tgetstr (SLFUTURE_CONST char *);
1753 SL_EXTERN int SLtt_tgetnum (SLFUTURE_CONST char *);
1754 SL_EXTERN int SLtt_tgetflag (SLFUTURE_CONST char *);
1755 SL_EXTERN int SLtt_tgetent(char *name);
1756 SL_EXTERN char *SLtt_tgoto(char *cap, int col, int row);
1757 SL_EXTERN int SLtt_tputs(char *str, int affcnt, int (*putcfun)(int));
1758 
1759 /* The following are terminfo-only routines -- these prototypes will change
1760  * in V2.x.
1761  */
1762 SL_EXTERN char *SLtt_tigetent (SLFUTURE_CONST char *);
1763 SL_EXTERN char *SLtt_tigetstr (SLFUTURE_CONST char *, char **);
1764 SL_EXTERN int SLtt_tigetnum (SLFUTURE_CONST char *, char **);
1765 # endif
1766 #endif
1767 
1768 SL_EXTERN SLtt_Char_Type SLtt_get_color_object (int);
1769 SL_EXTERN int SLtt_set_color_object (int, SLtt_Char_Type);
1770 SL_EXTERN int SLtt_set_color (int, SLFUTURE_CONST char *, SLFUTURE_CONST char *, SLFUTURE_CONST char *);
1771 SL_EXTERN int SLtt_set_mono (int, SLFUTURE_CONST char *, SLtt_Char_Type);
1772 SL_EXTERN int SLtt_add_color_attribute (int, SLtt_Char_Type);
1773 SL_EXTERN int SLtt_set_color_fgbg (int, SLtt_Char_Type, SLtt_Char_Type);
1774 
1775 /*}}}*/
1776 
1777 /*{{{ SLang Preprocessor Interface */
1778 
1779 /* #define SLPreprocess_Type SLprep_Type; */
1780 typedef struct _pSLprep_Type SLprep_Type;
1781 
1782 SL_EXTERN SLprep_Type *SLprep_new (void);
1783 SL_EXTERN void SLprep_delete (SLprep_Type *);
1784 SL_EXTERN int SLprep_line_ok (SLFUTURE_CONST char *, SLprep_Type *);
1785 SL_EXTERN int SLprep_set_flags (SLprep_Type *, unsigned int flags);
1786 #define SLPREP_BLANK_LINES_OK	0x1
1787 #define SLPREP_COMMENT_LINES_OK	0x2
1788 
1789 SL_EXTERN int SLprep_set_comment (SLprep_Type *, SLFUTURE_CONST char *, SLFUTURE_CONST char *);
1790 SL_EXTERN int SLprep_set_prefix (SLprep_Type *, SLFUTURE_CONST char *);
1791 SL_EXTERN int SLprep_set_exists_hook (SLprep_Type *,
1792 				   int (*)(SLprep_Type *, SLFUTURE_CONST char *));
1793 SL_EXTERN int SLprep_set_eval_hook (SLprep_Type *,
1794 				 int (*)(SLprep_Type *, SLFUTURE_CONST char *));
1795 
1796 SL_EXTERN int SLdefine_for_ifdef (SLFUTURE_CONST char *);
1797    /* Adds a string to the SLang #ifdef preparsing defines. SLang already
1798       defines MSDOS, UNIX, and VMS on the appropriate system. */
1799 
1800 /*}}}*/
1801 
1802 /*{{{ SLsmg Screen Management Functions */
1803 
1804 SL_EXTERN void SLsmg_fill_region (int, int, unsigned int, unsigned int,
1805 			       SLwchar_Type);
1806 SL_EXTERN void SLsmg_set_char_set (int);
1807 #ifndef IBMPC_SYSTEM
1808 SL_EXTERN int SLsmg_Scroll_Hash_Border;
1809 #endif
1810 SL_EXTERN int SLsmg_suspend_smg (void);
1811 SL_EXTERN int SLsmg_resume_smg (void);
1812 SL_EXTERN void SLsmg_erase_eol (void);
1813 SL_EXTERN void SLsmg_gotorc (int, int);
1814 SL_EXTERN void SLsmg_erase_eos (void);
1815 SL_EXTERN void SLsmg_reverse_video (void);
1816 SL_EXTERN void SLsmg_set_color (SLsmg_Color_Type);
1817 SL_EXTERN void SLsmg_normal_video (void);
1818 SL_EXTERN void SLsmg_printf (SLFUTURE_CONST char *, ...) SLATTRIBUTE_PRINTF(1,2);
1819 /* SL_EXTERN void SLsmg_printf (SLFUTURE_CONST char *, ...) SLATTRIBUTE_PRINTF(1,2); */
1820 SL_EXTERN void SLsmg_vprintf (SLFUTURE_CONST char *, va_list);
1821 SL_EXTERN void SLsmg_write_string (SLFUTURE_CONST char *);
1822 SL_EXTERN void SLsmg_write_nstring (SLFUTURE_CONST char *, unsigned int);
1823 SL_EXTERN void SLsmg_write_chars (SLuchar_Type *u, SLuchar_Type *umax);
1824 SL_EXTERN void SLsmg_write_nchars (SLFUTURE_CONST char *str, unsigned int len);
1825 SL_EXTERN void SLsmg_write_char (SLwchar_Type ch);
1826 SL_EXTERN void SLsmg_write_wrapped_string (SLuchar_Type *, int, int, unsigned int, unsigned int, int);
1827 SL_EXTERN void SLsmg_cls (void);
1828 SL_EXTERN void SLsmg_refresh (void);
1829 SL_EXTERN void SLsmg_touch_lines (int, unsigned int);
1830 SL_EXTERN void SLsmg_touch_screen (void);
1831 SL_EXTERN int SLsmg_init_smg (void);
1832 SL_EXTERN int SLsmg_reinit_smg (void);
1833 SL_EXTERN void SLsmg_reset_smg (void);
1834 SL_EXTERN int SLsmg_char_at (SLsmg_Char_Type *);
1835 SL_EXTERN void SLsmg_set_screen_start (int *, int *);
1836 SL_EXTERN void SLsmg_draw_hline (unsigned int);
1837 SL_EXTERN void SLsmg_draw_vline (int);
1838 SL_EXTERN void SLsmg_draw_object (int, int, SLwchar_Type);
1839 SL_EXTERN void SLsmg_draw_box (int, int, unsigned int, unsigned int);
1840 SL_EXTERN int SLsmg_get_column(void);
1841 SL_EXTERN int SLsmg_get_row(void);
1842 SL_EXTERN void SLsmg_forward (int);
1843 SL_EXTERN void SLsmg_write_color_chars (SLsmg_Char_Type *, unsigned int);
1844 SL_EXTERN unsigned int SLsmg_read_raw (SLsmg_Char_Type *, unsigned int);
1845 SL_EXTERN unsigned int SLsmg_write_raw (SLsmg_Char_Type *, unsigned int);
1846 SL_EXTERN void SLsmg_set_color_in_region (int, int, int, unsigned int, unsigned int);
1847 
1848 SL_EXTERN unsigned int SLsmg_strwidth (SLuchar_Type *u, SLuchar_Type *max);
1849 SL_EXTERN unsigned int SLsmg_strbytes (SLuchar_Type *u, SLuchar_Type *max, unsigned int width);
1850 SL_EXTERN int SLsmg_embedded_escape_mode (int on_or_off);
1851 SL_EXTERN int SLsmg_Display_Eight_Bit;
1852 SL_EXTERN int SLsmg_Tab_Width;
1853 
1854 #define SLSMG_NEWLINE_IGNORED	0      /* default */
1855 #define SLSMG_NEWLINE_MOVES	1      /* moves to next line, column 0 */
1856 #define SLSMG_NEWLINE_SCROLLS	2      /* moves but scrolls at bottom of screen */
1857 #define SLSMG_NEWLINE_PRINTABLE	3      /* prints as ^J */
1858 SL_EXTERN int SLsmg_Newline_Behavior;
1859 
1860 SL_EXTERN int SLsmg_Backspace_Moves;
1861 
1862 #ifdef IBMPC_SYSTEM
1863 # define SLSMG_HLINE_CHAR	0xC4
1864 # define SLSMG_VLINE_CHAR	0xB3
1865 # define SLSMG_ULCORN_CHAR	0xDA
1866 # define SLSMG_URCORN_CHAR	0xBF
1867 # define SLSMG_LLCORN_CHAR	0xC0
1868 # define SLSMG_LRCORN_CHAR	0xD9
1869 # define SLSMG_RTEE_CHAR	0xB4
1870 # define SLSMG_LTEE_CHAR	0xC3
1871 # define SLSMG_UTEE_CHAR	0xC2
1872 # define SLSMG_DTEE_CHAR	0xC1
1873 # define SLSMG_PLUS_CHAR	0xC5
1874 /* There are several to choose from: 0xB0, 0xB1, and 0xB2 */
1875 # define SLSMG_CKBRD_CHAR	0xB0
1876 # define SLSMG_DIAMOND_CHAR	0x04
1877 # define SLSMG_DEGREE_CHAR	0xF8
1878 # define SLSMG_PLMINUS_CHAR	0xF1
1879 # define SLSMG_BULLET_CHAR	0xF9
1880 # define SLSMG_LARROW_CHAR	0x1B
1881 # define SLSMG_RARROW_CHAR	0x1A
1882 # define SLSMG_DARROW_CHAR	0x19
1883 # define SLSMG_UARROW_CHAR	0x18
1884 # define SLSMG_BOARD_CHAR	0xB2
1885 # define SLSMG_BLOCK_CHAR	0xDB
1886 #else
1887 # if defined(AMIGA)
1888 #  define SLSMG_HLINE_CHAR	((unsigned char)'-')
1889 #  define SLSMG_VLINE_CHAR	((unsigned char)'|')
1890 #  define SLSMG_ULCORN_CHAR	((unsigned char)'+')
1891 #  define SLSMG_URCORN_CHAR	((unsigned char)'+')
1892 #  define SLSMG_LLCORN_CHAR	((unsigned char)'+')
1893 #  define SLSMG_LRCORN_CHAR	((unsigned char)'+')
1894 #  define SLSMG_CKBRD_CHAR	((unsigned char)'#')
1895 #  define SLSMG_RTEE_CHAR	((unsigned char)'+')
1896 #  define SLSMG_LTEE_CHAR	((unsigned char)'+')
1897 #  define SLSMG_UTEE_CHAR	((unsigned char)'+')
1898 #  define SLSMG_DTEE_CHAR	((unsigned char)'+')
1899 #  define SLSMG_PLUS_CHAR	((unsigned char)'+')
1900 #  define SLSMG_DIAMOND_CHAR	((unsigned char)'+')
1901 #  define SLSMG_DEGREE_CHAR	((unsigned char)'\\')
1902 #  define SLSMG_PLMINUS_CHAR	((unsigned char)'#')
1903 #  define SLSMG_BULLET_CHAR	((unsigned char)'o')
1904 #  define SLSMG_LARROW_CHAR	((unsigned char)'<')
1905 #  define SLSMG_RARROW_CHAR	((unsigned char)'>')
1906 #  define SLSMG_DARROW_CHAR	((unsigned char)'v')
1907 #  define SLSMG_UARROW_CHAR	((unsigned char)'^')
1908 #  define SLSMG_BOARD_CHAR	((unsigned char)'#')
1909 #  define SLSMG_BLOCK_CHAR	((unsigned char)'#')
1910 # else
1911 #  define SLSMG_HLINE_CHAR	((unsigned char)'q')
1912 #  define SLSMG_VLINE_CHAR	((unsigned char)'x')
1913 #  define SLSMG_ULCORN_CHAR	((unsigned char)'l')
1914 #  define SLSMG_URCORN_CHAR	((unsigned char)'k')
1915 #  define SLSMG_LLCORN_CHAR	((unsigned char)'m')
1916 #  define SLSMG_LRCORN_CHAR	((unsigned char)'j')
1917 #  define SLSMG_CKBRD_CHAR	((unsigned char)'a')
1918 #  define SLSMG_RTEE_CHAR	((unsigned char)'u')
1919 #  define SLSMG_LTEE_CHAR	((unsigned char)'t')
1920 #  define SLSMG_UTEE_CHAR	((unsigned char)'w')
1921 #  define SLSMG_DTEE_CHAR	((unsigned char)'v')
1922 #  define SLSMG_PLUS_CHAR	((unsigned char)'n')
1923 #  define SLSMG_DIAMOND_CHAR	((unsigned char)'`')
1924 #  define SLSMG_DEGREE_CHAR	((unsigned char)'f')
1925 #  define SLSMG_PLMINUS_CHAR	((unsigned char)'g')
1926 #  define SLSMG_BULLET_CHAR	((unsigned char)'~')
1927 #  define SLSMG_LARROW_CHAR	((unsigned char)',')
1928 #  define SLSMG_RARROW_CHAR	((unsigned char)'+')
1929 #  define SLSMG_DARROW_CHAR	((unsigned char)'.')
1930 #  define SLSMG_UARROW_CHAR	((unsigned char)'-')
1931 #  define SLSMG_BOARD_CHAR	((unsigned char)'h')
1932 #  define SLSMG_BLOCK_CHAR	((unsigned char)'0')
1933 # endif				       /* AMIGA */
1934 #endif				       /* IBMPC_SYSTEM */
1935 
1936 #ifndef IBMPC_SYSTEM
1937 # define SLSMG_COLOR_BLACK		0x000000
1938 # define SLSMG_COLOR_RED		0x000001
1939 # define SLSMG_COLOR_GREEN		0x000002
1940 # define SLSMG_COLOR_BROWN		0x000003
1941 # define SLSMG_COLOR_BLUE		0x000004
1942 # define SLSMG_COLOR_MAGENTA		0x000005
1943 # define SLSMG_COLOR_CYAN		0x000006
1944 # define SLSMG_COLOR_LGRAY		0x000007
1945 # define SLSMG_COLOR_GRAY		0x000008
1946 # define SLSMG_COLOR_BRIGHT_RED		0x000009
1947 # define SLSMG_COLOR_BRIGHT_GREEN	0x00000A
1948 # define SLSMG_COLOR_BRIGHT_BROWN	0x00000B
1949 # define SLSMG_COLOR_BRIGHT_BLUE	0x00000C
1950 # define SLSMG_COLOR_BRIGHT_MAGENTA	0x00000D
1951 # define SLSMG_COLOR_BRIGHT_CYAN	0x00000E
1952 # define SLSMG_COLOR_BRIGHT_WHITE	0x00000F
1953 #endif
1954 
1955 typedef struct
1956 {
1957    void (*tt_normal_video)(void);
1958    void (*tt_set_scroll_region)(int, int);
1959    void (*tt_goto_rc)(int, int);
1960    void (*tt_reverse_index)(int);
1961    void (*tt_reset_scroll_region)(void);
1962    void (*tt_delete_nlines)(int);
1963    void (*tt_cls) (void);
1964    void (*tt_del_eol) (void);
1965    void (*tt_smart_puts) (SLsmg_Char_Type *, SLsmg_Char_Type *, int, int);
1966    int (*tt_flush_output) (void);
1967    int (*tt_reset_video) (void);
1968    int (*tt_init_video) (void);
1969 
1970    int *tt_screen_rows;
1971    int *tt_screen_cols;
1972 
1973    int *tt_term_cannot_scroll;
1974 #if 0
1975    int *tt_use_blink_for_acs;
1976 #endif
1977    int *tt_has_alt_charset;
1978    char **tt_graphic_char_pairs;
1979    int *unicode_ok;
1980 
1981    long reserved[4];
1982 }
1983 SLsmg_Term_Type;
1984 SL_EXTERN void SLsmg_set_terminal_info (SLsmg_Term_Type *);
1985 
1986 /*}}}*/
1987 
1988 /*{{{ SLang Keypad Interface */
1989 
1990 #define SL_KEY_ERR		0xFFFF
1991 
1992 #define SL_KEY_UP		0x101
1993 #define SL_KEY_DOWN		0x102
1994 #define SL_KEY_LEFT		0x103
1995 #define SL_KEY_RIGHT		0x104
1996 #define SL_KEY_PPAGE		0x105
1997 #define SL_KEY_NPAGE		0x106
1998 #define SL_KEY_HOME		0x107
1999 #define SL_KEY_END		0x108
2000 #define SL_KEY_A1		0x109
2001 #define SL_KEY_A3		0x10A
2002 #define SL_KEY_B2		0x10B
2003 #define SL_KEY_C1		0x10C
2004 #define SL_KEY_C3		0x10D
2005 #define SL_KEY_REDO		0x10E
2006 #define SL_KEY_UNDO		0x10F
2007 #define SL_KEY_BACKSPACE	0x110
2008 #define SL_KEY_ENTER		0x111
2009 #define SL_KEY_IC		0x112
2010 #define SL_KEY_DELETE		0x113
2011 
2012 #define SL_KEY_F0		0x200
2013 #define SL_KEY_F(X)		(SL_KEY_F0 + X)
2014 
2015 /* I do not intend to use keysymps > 0x1000.  Applications can use those. */
2016 /* Returns 0 upon success or -1 upon error. */
2017 SL_EXTERN int SLkp_define_keysym (SLFUTURE_CONST char *, unsigned int);
2018 
2019 /* This function must be called AFTER SLtt_get_terminfo and not before. */
2020 SL_EXTERN int SLkp_init (void);
2021 
2022 /* By default, SLang_getkey is used as the low-level function.  This hook
2023  * allows you to specify something else.
2024  */
2025 SL_EXTERN void SLkp_set_getkey_function (int (*)(void));
2026 
2027 /* This function uses SLang_getkey and assumes that what ever initialization
2028  * is required for SLang_getkey has been performed.  If you do not want
2029  * SLang_getkey to be used, then specify another function via
2030  * SLkp_set_getkey_function.
2031  */
2032 SL_EXTERN int SLkp_getkey (void);
2033 
2034 /*}}}*/
2035 
2036 /*{{{ SLang Scroll Interface */
2037 
2038 typedef struct _pSLscroll_Type
2039 {
2040    struct _pSLscroll_Type *next;
2041    struct _pSLscroll_Type *prev;
2042    unsigned int flags;
2043 }
2044 SLscroll_Type;
2045 
2046 typedef struct
2047 {
2048    unsigned int flags;
2049    SLscroll_Type *top_window_line;   /* list element at top of window */
2050    SLscroll_Type *bot_window_line;   /* list element at bottom of window */
2051    SLscroll_Type *current_line;    /* current list element */
2052    SLscroll_Type *lines;	       /* first list element */
2053    unsigned int nrows;		       /* number of rows in window */
2054    unsigned int hidden_mask;	       /* applied to flags in SLscroll_Type */
2055    unsigned int line_num;	       /* current line number (visible) */
2056    unsigned int num_lines;	       /* total number of lines (visible) */
2057    unsigned int window_row;	       /* row of current_line in window */
2058    unsigned int border;		       /* number of rows that form scroll border */
2059    int cannot_scroll;		       /* should window scroll or recenter */
2060 }
2061 SLscroll_Window_Type;
2062 
2063 SL_EXTERN int SLscroll_find_top (SLscroll_Window_Type *);
2064 SL_EXTERN int SLscroll_find_line_num (SLscroll_Window_Type *);
2065 SL_EXTERN unsigned int SLscroll_next_n (SLscroll_Window_Type *, unsigned int);
2066 SL_EXTERN unsigned int SLscroll_prev_n (SLscroll_Window_Type *, unsigned int);
2067 SL_EXTERN int SLscroll_pageup (SLscroll_Window_Type *);
2068 SL_EXTERN int SLscroll_pagedown (SLscroll_Window_Type *);
2069 
2070 /*}}}*/
2071 
2072 /*{{{ Signal Routines */
2073 
2074 typedef void SLSig_Fun_Type (int);
2075 SL_EXTERN SLSig_Fun_Type *SLsignal (int, SLSig_Fun_Type *);
2076 SL_EXTERN SLSig_Fun_Type *SLsignal_intr (int, SLSig_Fun_Type *);
2077 SL_EXTERN int SLsig_block_signals (void);
2078 SL_EXTERN int SLsig_unblock_signals (void);
2079 SL_EXTERN int SLsystem (SLFUTURE_CONST char *);
2080 SL_EXTERN int SLsystem_intr (SLFUTURE_CONST char *);
2081 
2082 /* Make a signal off-limits to the interpreter */
2083 SL_EXTERN int SLsig_forbid_signal (int);
2084 
2085 SL_EXTERN SLFUTURE_CONST char *SLerrno_strerror (int);
2086 SL_EXTERN int SLerrno_set_errno (int);
2087 
2088 /*}}}*/
2089 
2090 /* Functions for dealing with the FPU */
2091 SL_EXTERN void SLfpu_clear_except_bits (void);
2092 SL_EXTERN unsigned int SLfpu_test_except_bits (unsigned int bits);
2093 #define SL_FE_DIVBYZERO		0x01
2094 #define SL_FE_INVALID		0x02
2095 #define SL_FE_OVERFLOW		0x04
2096 #define SL_FE_UNDERFLOW		0x08
2097 #define SL_FE_INEXACT		0x10
2098 #define SL_FE_ALLEXCEPT		0x1F
2099 
2100 SL_EXTERN SLtype SLang_get_int_type (int nbits);
2101 /* if nbits is negative it gets the signed int type, else unsigned int type */
2102 SL_EXTERN int SLang_get_int_size (SLtype);
2103 /* Opposite of SLang_get_int_type */
2104 
2105 /*{{{ Interpreter Macro Definitions */
2106 
2107 /* The definitions here are for objects that may be on the run-time stack.
2108  * They are actually sub_types of literal and data main_types.  The actual
2109  * numbers are historical.
2110  */
2111 #define SLANG_UNDEFINED_TYPE	0x00   /* MUST be 0 */
2112 #define SLANG_VOID_TYPE		0x01   /* also matches ANY type */
2113 #define SLANG_NULL_TYPE		(0x02)
2114 #define SLANG_ANY_TYPE		(0x03)
2115 #define SLANG_DATATYPE_TYPE	(0x04)
2116 /* SLANG_REF_TYPE refers to an object on the stack that is a pointer (reference)
2117  * to some other object.
2118  */
2119 #define SLANG_REF_TYPE		(0x05)
2120 #define SLANG_STRING_TYPE	(0x06)
2121 #define SLANG_BSTRING_TYPE	(0x07)
2122 #define SLANG_FILE_PTR_TYPE	(0x08)
2123 #define SLANG_FILE_FD_TYPE	(0x09)
2124 #define SLANG_MD5_TYPE		(0x0A)
2125 #define SLANG_INTP_TYPE		(0x0F)
2126 
2127 /* Integer types */
2128 /* The integer and floating point types are arranged in order of arithmetic
2129  * precedence.
2130  */
2131 #define SLANG_CHAR_TYPE		(0x10)
2132 #define SLANG_UCHAR_TYPE	(0x11)
2133 #define SLANG_SHORT_TYPE	(0x12)
2134 #define SLANG_USHORT_TYPE	(0x13)
2135 #define SLANG_INT_TYPE 		(0x14)
2136 #define SLANG_UINT_TYPE		(0x15)
2137 #define SLANG_LONG_TYPE		(0x16)
2138 #define SLANG_ULONG_TYPE	(0x17)
2139 #define SLANG_LLONG_TYPE	(0x18)
2140 #define SLANG_ULLONG_TYPE	(0x19)
2141 /* floating point types */
2142 #define SLANG_FLOAT_TYPE	(0x1A)
2143 #define SLANG_DOUBLE_TYPE	(0x1B)
2144 #define SLANG_LDOUBLE_TYPE	(0x1C)
2145 
2146 #define SLANG_COMPLEX_TYPE	(0x20)
2147 
2148 /* An object of SLANG_INTP_TYPE should never really occur on the stack.  Rather,
2149  * the integer to which it refers will be there instead.  It is defined here
2150  * because it is a valid type for MAKE_VARIABLE.
2151  */
2152 
2153 /* Container types */
2154 #define SLANG_ISTRUCT_TYPE 	(0x2A)
2155 #define SLANG_STRUCT_TYPE	(0x2B)
2156 #define SLANG_ASSOC_TYPE	(0x2C)
2157 #define SLANG_ARRAY_TYPE	(0x2D)
2158 #define SLANG_LIST_TYPE		(0x2E)
2159 
2160 #define SLANG_MIN_UNUSED_TYPE	(0x30)
2161 
2162 /* Compatibility */
2163 #ifdef FLOAT_TYPE
2164 # undef FLOAT_TYPE
2165 #endif
2166 #define VOID_TYPE SLANG_VOID_TYPE
2167 #define INT_TYPE SLANG_INT_TYPE
2168 #define INTP_TYPE SLANG_INTP_TYPE
2169 #define FLOAT_TYPE SLANG_DOUBLE_TYPE
2170 #define ARRAY_TYPE SLANG_ARRAY_TYPE
2171 #define CHAR_TYPE SLANG_CHAR_TYPE
2172 #define STRING_TYPE SLANG_STRING_TYPE
2173 
2174 /* I am reserving values greater than or equal to 128 for user applications.
2175  * The first 127 are reserved for S-Lang.
2176  */
2177 
2178 /* Binary and Unary Subtypes */
2179 /* Since the application can define new types and can overload the binary
2180  * and unary operators, these definitions must be present in this file.
2181  * The current implementation assumes both unary and binary are distinct.
2182  */
2183 #define SLANG_BINARY_OP_MIN	0x01
2184 #define SLANG_PLUS		0x01
2185 #define SLANG_MINUS		0x02
2186 #define SLANG_TIMES		0x03
2187 #define SLANG_DIVIDE		0x04
2188 #define SLANG_EQ		0x05
2189 #define SLANG_NE		0x06
2190 #define SLANG_GT		0x07
2191 #define SLANG_GE		0x08
2192 #define SLANG_LT		0x09
2193 #define SLANG_LE		0x0A
2194 #define SLANG_POW		0x0B
2195 #define SLANG_OR		0x0C
2196 #define SLANG_AND		0x0D
2197 #define SLANG_BAND		0x0E
2198 #define SLANG_BOR		0x0F
2199 #define SLANG_BXOR		0x10
2200 #define SLANG_SHL		0x11
2201 #define SLANG_SHR		0x12
2202 #define SLANG_MOD		0x13
2203 #define SLANG_BINARY_OP_MAX	0x13
2204 
2205 /* UNARY subtypes  (may be overloaded) */
2206 #define SLANG_UNARY_OP_MIN	0x20
2207 
2208 #define SLANG_PLUSPLUS		0x20
2209 #define SLANG_MINUSMINUS	0x21
2210 #define SLANG_CHS		0x22
2211 #define SLANG_NOT		0x23
2212 #define SLANG_BNOT		0x24
2213 /* These are implemented as unary function calls */
2214 #define SLANG_ABS		0x25
2215 #define SLANG_SIGN		0x26
2216 #define SLANG_SQR		0x27
2217 #define SLANG_MUL2		0x28
2218 #define SLANG_ISPOS		0x29
2219 #define SLANG_ISNEG		0x2A
2220 #define SLANG_ISNONNEG		0x2B
2221 
2222 #define SLANG_UNARY_OP_MAX	0x2B
2223 
2224 /* SL_EXTERN SLFUTURE_CONST char *SLang_Error_Message; */
2225 
2226 SL_EXTERN int SLadd_intrinsic_variable (SLFUTURE_CONST char *, VOID_STAR, SLtype, int);
2227 SL_EXTERN int SLadd_intrinsic_function (SLFUTURE_CONST char *, FVOID_STAR, SLtype, unsigned int,...);
2228 
2229 SL_EXTERN int SLns_add_intrinsic_variable (SLang_NameSpace_Type *, SLFUTURE_CONST char *, VOID_STAR, SLtype, int);
2230 SL_EXTERN int SLns_add_intrinsic_function (SLang_NameSpace_Type *, SLFUTURE_CONST char *, FVOID_STAR, SLtype, unsigned int,...);
2231 
2232 /* These functions are used to patch intrinsic tables that make use of
2233  * dynamically allocated types whose type id is determined at
2234  * run-time.  The second version is useful for the most common case of a
2235  * single mapping.
2236  */
2237 SL_EXTERN int SLclass_patch_intrin_fun_table (SLang_Intrin_Fun_Type *table,
2238 					 SLtype *from_types, SLtype *to_types, unsigned int num);
2239 SL_EXTERN int SLclass_patch_intrin_fun_table1 (SLang_Intrin_Fun_Type *table,
2240 					  SLtype from_type, SLtype to_type);
2241 
2242 #define MAKE_INTRINSIC_N(n,f,out,in,a1,a2,a3,a4,a5,a6,a7) \
2243     {(n), NULL, SLANG_INTRINSIC, (FVOID_STAR) (f), \
2244       {a1,a2,a3,a4,a5,a6,a7}, (in), (out)}
2245 
2246 #define MAKE_INTRINSIC_7(n,f,out,a1,a2,a3,a4,a5,a6,a7) \
2247     MAKE_INTRINSIC_N(n,f,out,7,a1,a2,a3,a4,a5,a6,a7)
2248 #define MAKE_INTRINSIC_6(n,f,out,a1,a2,a3,a4,a5,a6) \
2249     MAKE_INTRINSIC_N(n,f,out,6,a1,a2,a3,a4,a5,a6,0)
2250 #define MAKE_INTRINSIC_5(n,f,out,a1,a2,a3,a4,a5) \
2251     MAKE_INTRINSIC_N(n,f,out,5,a1,a2,a3,a4,a5,0,0)
2252 #define MAKE_INTRINSIC_4(n,f,out,a1,a2,a3,a4) \
2253     MAKE_INTRINSIC_N(n,f,out,4,a1,a2,a3,a4,0,0,0)
2254 #define MAKE_INTRINSIC_3(n,f,out,a1,a2,a3) \
2255     MAKE_INTRINSIC_N(n,f,out,3,a1,a2,a3,0,0,0,0)
2256 #define MAKE_INTRINSIC_2(n,f,out,a1,a2) \
2257     MAKE_INTRINSIC_N(n,f,out,2,a1,a2,0,0,0,0,0)
2258 #define MAKE_INTRINSIC_1(n,f,out,a1) \
2259     MAKE_INTRINSIC_N(n,f,out,1,a1,0,0,0,0,0,0)
2260 #define MAKE_INTRINSIC_0(n,f,out) \
2261     MAKE_INTRINSIC_N(n,f,out,0,0,0,0,0,0,0,0)
2262 
2263 #define MAKE_INTRINSIC_S(n,f,r) \
2264    MAKE_INTRINSIC_1(n,f,r,SLANG_STRING_TYPE)
2265 #define MAKE_INTRINSIC_I(n,f,r) \
2266    MAKE_INTRINSIC_1(n,f,r,SLANG_INT_TYPE)
2267 
2268 #define MAKE_INTRINSIC_SS(n,f,r) \
2269    MAKE_INTRINSIC_2(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE)
2270 #define MAKE_INTRINSIC_SI(n,f,r) \
2271    MAKE_INTRINSIC_2(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE)
2272 #define MAKE_INTRINSIC_IS(n,f,r) \
2273    MAKE_INTRINSIC_2(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE)
2274 #define MAKE_INTRINSIC_II(n,f,r) \
2275    MAKE_INTRINSIC_2(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE)
2276 
2277 #define MAKE_INTRINSIC_SSS(n,f,r) \
2278    MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE,SLANG_STRING_TYPE)
2279 #define MAKE_INTRINSIC_SSI(n,f,r) \
2280    MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE,SLANG_INT_TYPE)
2281 #define MAKE_INTRINSIC_SIS(n,f,r) \
2282    MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE,SLANG_STRING_TYPE)
2283 #define MAKE_INTRINSIC_SII(n,f,r) \
2284    MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE,SLANG_INT_TYPE)
2285 #define MAKE_INTRINSIC_ISS(n,f,r) \
2286    MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE,SLANG_STRING_TYPE)
2287 #define MAKE_INTRINSIC_ISI(n,f,r) \
2288    MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE,SLANG_INT_TYPE)
2289 #define MAKE_INTRINSIC_IIS(n,f,r) \
2290    MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE,SLANG_STRING_TYPE)
2291 #define MAKE_INTRINSIC_III(n,f,r) \
2292    MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE,SLANG_INT_TYPE)
2293 
2294 #define MAKE_INTRINSIC(n, f, out, in) \
2295     MAKE_INTRINSIC_N(n,f,out,in,0,0,0,0,0,0,0)
2296 
2297 #define MAKE_VARIABLE(n, v, t, r)     \
2298     {n, NULL, SLANG_IVARIABLE + (r), (VOID_STAR)(v), (t)}
2299 
2300 #define MAKE_APP_UNARY(n,op) \
2301     {(n), NULL, SLANG_APP_UNARY, (op)}
2302 
2303 #define MAKE_ARITH_UNARY(n,op) \
2304     {(n), NULL, SLANG_ARITH_UNARY, (op)}
2305 
2306 #define MAKE_ARITH_BINARY(n,op) \
2307     {(n), NULL, SLANG_ARITH_BINARY, (op)}
2308 
2309 #define MAKE_MATH_UNARY(n,op) \
2310     {(n), NULL, SLANG_MATH_UNARY, (op)}
2311 
2312 #define MAKE_HCONSTANT_T(n,val,T) \
2313     {(n),NULL, SLANG_HCONSTANT, T, (short)(val)}
2314 #define MAKE_HCONSTANT(n,val) MAKE_HCONSTANT_T(n,val,SLANG_SHORT_TYPE)
2315 
2316 #define MAKE_ICONSTANT_T(n,val,T) \
2317     {(n),NULL, SLANG_ICONSTANT, T, (int)(val)}
2318 #define MAKE_ICONSTANT(n,val) MAKE_ICONSTANT_T(n,val,SLANG_INT_TYPE)
2319 
2320 #define MAKE_LCONSTANT_T(n,val,T) \
2321     {(n),NULL, SLANG_LCONSTANT, T, (long)(val)}
2322 #define MAKE_LCONSTANT(n,val) MAKE_LCONSTANT_T(n,val,SLANG_LONG_TYPE)
2323 
2324 #ifdef HAVE_LONG_LONG
2325 # define MAKE_LLCONSTANT_T(n,val,T) \
2326     {(n),NULL, T, (long long)(val)}
2327 # define MAKE_LLCONSTANT(n,val) MAKE_LLCONSTANT_T(n,val,SLANG_LLONG_TYPE)
2328 #endif
2329 
2330 #define MAKE_FCONSTANT(n,val) \
2331     {(n),NULL, SLANG_FCONSTANT, (val)}
2332 
2333 #define MAKE_DCONSTANT(n,val) \
2334     {(n),NULL, SLANG_DCONSTANT, (val)}
2335 
2336 #ifndef offsetof
2337 # define offsetof(T,F) ((unsigned int)((char *)&((T *)0L)->F - (char *)0L))
2338 #endif
2339 
2340 #define MAKE_ISTRUCT_FIELD(s,f,n,t,r) {(n), offsetof(s,f), (t), (r)}
2341 #define MAKE_CSTRUCT_FIELD(s,f,n,t,r) {(n), offsetof(s,f), (t), (r)}
2342 
2343 #define MAKE_CSTRUCT_INT_FIELD(s,f,n,r) {(n), offsetof(s,f),\
2344    (sizeof(((s*)0L)->f)==sizeof(int))?(SLANG_INT_TYPE): \
2345    (sizeof(((s*)0L)->f)==sizeof(short))?(SLANG_SHORT_TYPE): \
2346    (sizeof(((s*)0L)->f)==sizeof(char))?(SLANG_CHAR_TYPE): \
2347    (sizeof(((s*)0L)->f)==sizeof(long))?(SLANG_LONG_TYPE): \
2348    SLANG_LLONG_TYPE, (r)\
2349 }
2350 #define MAKE_CSTRUCT_UINT_FIELD(s,f,n,r) {(n), offsetof(s,f),\
2351    (sizeof(((s*)0L)->f)==sizeof(int))?(SLANG_UINT_TYPE): \
2352    (sizeof(((s*)0L)->f)==sizeof(short))?(SLANG_USHORT_TYPE): \
2353    (sizeof(((s*)0L)->f)==sizeof(char))?(SLANG_UCHAR_TYPE): \
2354    (sizeof(((s*)0L)->f)==sizeof(long))?(SLANG_ULONG_TYPE): \
2355    SLANG_ULLONG_TYPE, (r)\
2356 }
2357 
2358 #define MAKE_CSTRUCT_FLOAT_FIELD(s,f,n,r) {(n), offsetof(s,f),\
2359    (sizeof(((s*)0L)->f)==sizeof(float))?(SLANG_FLOAT_TYPE): \
2360    SLANG_DOUBLE_TYPE, (r)\
2361 }
2362 
2363 #define SLANG_END_TABLE {NULL}
2364 #define SLANG_END_INTRIN_FUN_TABLE MAKE_INTRINSIC_0(NULL,NULL,0)
2365 #define SLANG_END_FCONST_TABLE MAKE_DCONSTANT(NULL,0)
2366 #define SLANG_END_DCONST_TABLE MAKE_DCONSTANT(NULL,0)
2367 #define SLANG_END_MATH_UNARY_TABLE MAKE_MATH_UNARY(NULL,0)
2368 #define SLANG_END_ARITH_UNARY_TABLE MAKE_ARITH_UNARY(NULL,0)
2369 #define SLANG_END_ARITH_BINARY_TABLE MAKE_ARITH_BINARY(NULL,0)
2370 #define SLANG_END_APP_UNARY_TABLE MAKE_APP_UNARY(NULL,0)
2371 #define SLANG_END_INTRIN_VAR_TABLE MAKE_VARIABLE(NULL,NULL,0,0)
2372 #define SLANG_END_ICONST_TABLE MAKE_ICONSTANT(NULL,0)
2373 #define SLANG_END_LCONST_TABLE MAKE_LCONSTANT(NULL,0)
2374 #define SLANG_END_LLCONST_TABLE MAKE_LLCONSTANT(NULL,0)
2375 #define SLANG_END_ISTRUCT_TABLE {NULL, 0, 0, 0}
2376 #define SLANG_END_CSTRUCT_TABLE {NULL, 0, 0, 0}
2377 
2378 /*}}}*/
2379 
2380 /*{{{ Upper/Lowercase Functions */
2381 
2382 SL_EXTERN void SLang_define_case(int *, int *);
2383 SL_EXTERN void SLang_init_case_tables (void);
2384 
2385 SL_EXTERN unsigned char _pSLChg_UCase_Lut[256];
2386 SL_EXTERN unsigned char _pSLChg_LCase_Lut[256];
2387 #define UPPER_CASE(x) (_pSLChg_UCase_Lut[(unsigned char) (x)])
2388 #define LOWER_CASE(x) (_pSLChg_LCase_Lut[(unsigned char) (x)])
2389 #define CHANGE_CASE(x) (((x) == _pSLChg_LCase_Lut[(unsigned char) (x)]) ?\
2390 			_pSLChg_UCase_Lut[(unsigned char) (x)] : _pSLChg_LCase_Lut[(unsigned char) (x)])
2391 
2392 /*}}}*/
2393 
2394 /*{{{ Regular Expression Interface */
2395 typedef struct _pSLRegexp_Type SLRegexp_Type;
2396 SL_EXTERN SLRegexp_Type *SLregexp_compile (SLFUTURE_CONST char *pattern, unsigned int flags);
2397 #define SLREGEXP_CASELESS	0x01
2398 #define SLREGEXP_UTF8		0x10
2399 
2400 SL_EXTERN void SLregexp_free (SLRegexp_Type *);
2401 SL_EXTERN char *SLregexp_match (SLRegexp_Type *compiled_regexp, SLFUTURE_CONST char *str, SLstrlen_Type len);
2402 SL_EXTERN int SLregexp_nth_match (SLRegexp_Type *, unsigned int nth, SLstrlen_Type *ofsp, SLstrlen_Type *lenp);
2403 
2404 SL_EXTERN int SLregexp_get_hints (SLRegexp_Type *, unsigned int *flagsp);
2405 #define SLREGEXP_HINT_BOL		0x01   /* pattern must match bol */
2406 #define SLREGEXP_HINT_OSEARCH		0x02   /* ordinary search will do */
2407 
2408 SL_EXTERN char *SLregexp_quote_string (SLFUTURE_CONST char *pattern, char *buf, unsigned int buflen);
2409 
2410 /*}}}*/
2411 
2412 /*{{{ SLang Command Interface */
2413 
2414 struct _pSLcmd_Cmd_Type; /* Pre-declaration is needed below */
2415 typedef struct
2416 {
2417    struct _pSLcmd_Cmd_Type *table;
2418    int argc;
2419    /* Version 2.0 needs to use a union!! */
2420    SLFUTURE_CONST char **string_args;
2421    int *int_args;
2422    double *double_args;
2423    SLtype *arg_type;
2424    unsigned long reserved[4];
2425 } SLcmd_Cmd_Table_Type;
2426 
2427 typedef struct _pSLcmd_Cmd_Type
2428 {
2429    int (*cmdfun)(int, SLcmd_Cmd_Table_Type *);
2430    SLFUTURE_CONST char *cmd;
2431    SLFUTURE_CONST char *arg_type;
2432 } SLcmd_Cmd_Type;
2433 
2434 SL_EXTERN int SLcmd_execute_string (SLFUTURE_CONST char *, SLcmd_Cmd_Table_Type *);
2435 
2436 /*}}}*/
2437 
2438 /*{{{ SLang Search Interface */
2439 
2440 typedef struct _pSLsearch_Type SLsearch_Type;
2441 SL_EXTERN SLsearch_Type *SLsearch_new (SLuchar_Type *u, int search_flags);
2442 #define SLSEARCH_CASELESS	0x1
2443 #define SLSEARCH_UTF8		0x2
2444 
2445 SL_EXTERN void SLsearch_delete (SLsearch_Type *);
2446 
2447 SL_EXTERN SLuchar_Type *SLsearch_forward (SLsearch_Type *st,
2448                                         SLuchar_Type *pmin, SLuchar_Type *pmax);
2449 SL_EXTERN SLuchar_Type *SLsearch_backward (SLsearch_Type *st,
2450                                          SLuchar_Type *pmin, SLuchar_Type *pstart, SLuchar_Type *pmax);
2451 SL_EXTERN SLstrlen_Type SLsearch_match_len (SLsearch_Type *);
2452 
2453 /*}}}*/
2454 
2455 /*{{{ SLang Pathname Interface */
2456 
2457 /* These function return pointers to the original space */
2458 SL_EXTERN char *SLpath_basename (SLFUTURE_CONST char *);
2459 SL_EXTERN char *SLpath_extname (SLFUTURE_CONST char *);
2460 
2461 SL_EXTERN int SLpath_is_absolute_path (SLFUTURE_CONST char *);
2462 
2463 /* Get and set the character delimiter for search paths */
2464 SL_EXTERN int SLpath_get_delimiter (void);
2465 SL_EXTERN int SLpath_set_delimiter (int);
2466 
2467 /* search path for loading .sl files */
2468 SL_EXTERN int SLpath_set_load_path (SLFUTURE_CONST char *);
2469 /* search path for loading .sl files --- returns slstring */
2470 SL_EXTERN char *SLpath_get_load_path (void);
2471 
2472 /* These return malloced strings--- NOT slstrings */
2473 SL_EXTERN char *SLpath_dircat (SLFUTURE_CONST char *, SLFUTURE_CONST char *);
2474 SL_EXTERN char *SLpath_find_file_in_path (SLFUTURE_CONST char *, SLFUTURE_CONST char *);
2475 SL_EXTERN char *SLpath_dirname (SLFUTURE_CONST char *);
2476 SL_EXTERN int SLpath_file_exists (SLFUTURE_CONST char *);
2477 SL_EXTERN char *SLpath_pathname_sans_extname (SLFUTURE_CONST char *);
2478 SL_EXTERN char *SLpath_getcwd (void);  /* return NULL on error, sets errno */
2479 
2480 /*}}}*/
2481 
2482 SL_EXTERN int SLang_set_module_load_path (SLFUTURE_CONST char *);
2483 
2484 #ifdef __cplusplus
2485 # define SLANG_MODULE(name) \
2486    extern SL_EXPORT "C" int init_##name##_module_ns (char *); \
2487    extern SL_EXPORT "C" void deinit_##name##_module (void); \
2488    extern SL_EXPORT "C" int SLmodule_##name##_api_version; \
2489    SL_EXPORT int SLmodule_##name##_api_version = SLANG_VERSION
2490 #else
2491 # define SLANG_MODULE(name) \
2492    extern SL_EXPORT int init_##name##_module_ns (char *); \
2493    extern SL_EXPORT void deinit_##name##_module (void); \
2494    SL_EXPORT int SLmodule_##name##_api_version = SLANG_VERSION
2495 #endif
2496 
2497 SL_EXTERN int SLvsnprintf (char *, unsigned int, SLFUTURE_CONST char *, va_list);
2498 SL_EXTERN int SLsnprintf (char *, unsigned int, SLFUTURE_CONST char *, ...) SLATTRIBUTE_PRINTF(3,4);
2499 
2500 #if 0
2501 {
2502 #endif
2503 #ifdef __cplusplus
2504 }
2505 #endif
2506 
2507 #endif  /* DAVIS_SLANG_H_ */
2508