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