my homework was late :-)
[midnight-commander.git] / slang / slang-mc.h
blob8ee722f045c607688eeda42f095a88b02dd435b2
1 #ifndef DAVIS_SLANG_H_
2 #define DAVIS_SLANG_H_
3 /* -*- mode: C; mode: fold; -*- */
4 /* Copyright (c) 1992, 1995 John E. Davis
5 * All rights reserved.
6 *
7 * You may distribute under the terms of either the GNU General Public
8 * License or the Perl Artistic License.
9 */
10 #define SLANG_VERSION 9938
11 /*{{{ System Dependent Macros and Typedefs */
13 #if defined(__WATCOMC__) && !defined(__QNX__)
14 # ifndef msdos
15 # define msdos
16 # endif
17 # ifndef DOS386
18 # define DOS386
19 # endif
20 # ifndef FLOAT_TYPE
21 # define FLOAT_TYPE
22 # endif
23 # ifndef pc_system
24 # define pc_system
25 # endif
26 #endif /* __watcomc__ */
28 #ifdef unix
29 # ifndef __unix__
30 # define __unix__ 1
31 # endif
32 #endif
34 #ifndef __GO32__
35 # ifdef __unix__
36 # define REAL_UNIX_SYSTEM
37 # endif
38 #endif
40 /* Set of the various defines for pc systems. This includes OS/2 */
41 #ifdef __MSDOS__
42 # ifndef msdos
43 # define msdos
44 # endif
45 # ifndef pc_system
46 # define pc_system
47 # endif
48 #endif
50 #ifdef __GO32__
51 # ifndef pc_system
52 # define pc_system
53 # endif
54 # ifdef REAL_UNIX_SYSTEM
55 # undef REAL_UNIX_SYSTEM
56 # endif
57 #endif
59 #if defined(__EMX__) && defined(OS2)
60 # ifndef pc_system
61 # define pc_system
62 # endif
63 # ifndef __os2__
64 # define __os2__
65 # define NEEDS_LOCAL_DIRENT_H
66 # endif
67 #endif
69 #ifdef __cplusplus
70 extern "C" {
71 #endif
72 #if 0
74 #endif
75 /* ---------------------------- Generic Macros ----------------------------- */
77 /* __SC__ is defined for Symantec C++
78 DOS386 is defined for -mx memory model, 32 bit DOS extender. */
80 #ifdef VOID
81 # undef VOID
82 #endif
84 #if defined(msdos) && !defined(DOS386) & !defined(__WIN32__) && !defined(__GO32__)
85 # ifdef __SC__
86 # include <dos.h>
87 # endif
88 typedef void *VOID_STAR;
89 # define VOID void
90 # include <alloc.h>
91 #else
92 # if defined (__cplusplus) || defined(__STDC__)
93 typedef void *VOID_STAR;
94 # define VOID void
95 # else
96 typedef unsigned char *VOID_STAR;
97 # define VOID unsigned char
98 # endif
99 #endif
101 #if 1
102 typedef int (*FVOID_STAR)(void);
103 #else
104 # define FVOID_STAR VOID_STAR
105 #endif
107 #if defined(msdos) && !defined(DOS386) && !defined(__GO32__) && !defined(__WIN32__)
108 # define SLFREE(buf) farfree((void far *)(buf))
109 # define SLMALLOC(x) farmalloc((unsigned long) (x))
110 # define SLREALLOC(buf, n) farrealloc((void far *) (buf), (unsigned long) (n))
111 # define SLCALLOC(n, m) farcalloc((unsigned long) (n), (unsigned long) (m))
112 #else
113 # if defined(VMS) && !defined(__DECC)
114 # define SLFREE VAXC$FREE_OPT
115 # define SLMALLOC VAXC$MALLOC_OPT
116 # define SLREALLOC VAXC$REALLOC_OPT
117 # define SLCALLOC VAXC$CALLOC_OPT
118 # else
119 # define SLFREE(x) free((char *)(x))
120 # define SLMALLOC malloc
121 # if defined(__cplusplus) && !defined(__BEOS__)
122 # define SLREALLOC(p,n) realloc((malloc_t) (p), (n))
123 # else
124 # define SLREALLOC realloc
125 # endif
126 # define SLCALLOC calloc
127 # endif
128 #endif
130 #ifdef SL_MALLOC_DEBUG
131 # undef SLMALLOC
132 # undef SLCALLOC
133 # undef SLREALLOC
134 # undef SLFREE
135 # define SLMALLOC(x) SLdebug_malloc((unsigned long) (x))
136 # define SLFREE(x) SLdebug_free((unsigned char *)(x))
137 # define SLCALLOC(n, m) SLdebug_calloc((unsigned long) (n), (unsigned long)(m))
138 # define SLREALLOC(p, x) SLdebug_realloc((unsigned char *)(p), (unsigned long)(x))
139 #endif /* SL_MALLOC_DEBUG */
141 extern unsigned char *SLdebug_malloc (unsigned long);
142 extern unsigned char *SLdebug_calloc (unsigned long, unsigned long);
143 extern unsigned char *SLdebug_realloc (unsigned char *, unsigned long);
144 extern void SLdebug_free (unsigned char *);
145 extern void SLmalloc_dump_statistics (void);
146 extern char *SLstrcpy(register char *, register char *);
147 extern int SLstrcmp(register char *, register char *);
148 extern char *SLstrncpy(char *, register char *, register int);
150 extern void SLmemset (char *, char, int);
151 extern char *SLmemchr (register char *, register char, register int);
152 extern char *SLmemcpy (char *, char *, int);
153 extern int SLmemcmp (char *, char *, int);
155 #ifdef float64
156 # undef float64
157 #endif
159 #ifndef FLOAT64_TYPEDEFED
160 # define FLOAT64_TYPEDEFED
161 typedef double float64;
162 #endif
165 /*}}}*/
167 /*{{{ Interpreter Typedefs */
169 #define SLANG_MAX_NAME_LEN 30
170 /* maximum length of an identifier */
171 /* first char in identifiers is the hash */
173 /* Note that long is used for addresses instead of void *. The reason for
174 * this is that I have a gut feeling that sizeof (long) > sizeof(void *)
175 * on some machines. This is certainly the case for MSDOS where addresses
176 * can be 16 bit.
178 typedef struct SLang_Name_Type
180 #ifdef SLANG_STATS
181 int n; /* number of times referenced */
182 #endif
183 char name[SLANG_MAX_NAME_LEN + 2]; /* [0] is hash */
185 unsigned char sub_type;
187 /* Values for main_type may be as follows. The particlular values are
188 * for compatability.
190 #define SLANG_LVARIABLE 0x01
191 #define SLANG_INTRINSIC 0x06
192 #define SLANG_FUNCTION 0x07
193 #define SLANG_GVARIABLE 0x0D
194 #define SLANG_IVARIABLE 0x0E /* intrinsic variables */
195 /* Note!!! For Macro MAKE_VARIABLE below to work, SLANG_IVARIABLE Must
196 be 1 less than SLANG_RVARIABLE!!! */
197 #define SLANG_RVARIABLE 0x0F /* read only variable */
198 unsigned char main_type;
199 long addr;
201 SLang_Name_Type;
204 typedef struct SLang_Load_Type
206 long name; /* file name, string address, ... */
207 long handle; /* FILE *, string address, etc... */
209 char *ptr; /* input pointer to next line in object
210 * to be read.
212 /* Things below here are used by S-Lang. */
213 int type; /* 'F' = file, 'S' = String, etc.. */
214 char *buf; /* buffer for file, etc... */
215 char *(*read)(struct SLang_Load_Type *); /* function to call to read obj */
216 int n; /* line number, etc... */
217 char token[256]; /* token to be parsed */
218 int ofs; /* offset from buf where last read
219 * took place
221 int top_level; /* 1 if at top level of parsing */
222 } SLang_Load_Type;
224 #if defined(ultrix) && !defined(__GNUC__)
225 # ifndef NO_PROTOTYPES
226 # define NO_PROTOTYPES
227 # endif
228 #endif
230 #ifndef NO_PROTOTYPES
231 # define _PROTO(x) x
232 #else
233 # define _PROTO(x) ()
234 #endif
236 typedef struct SL_OOBinary_Type
238 unsigned char sub_type; /* partner type for binary op */
240 /* The function take the binary op as first argument, the operand types
241 * form the second and third parameters and the last two parameters are
242 * pointers to the objects themselves. It is up to the function to push
243 * the result on the stack. It must return 1 if it handled the operation
244 * return zero if the operation is not defined.
246 int (*binary_function)_PROTO((int, unsigned char, unsigned char,
247 VOID_STAR, VOID_STAR));
249 struct SL_OOBinary_Type *next;
251 SL_OOBinary_Type;
253 typedef struct
255 /* Methods */
256 void (*destroy)_PROTO((VOID_STAR));
257 /* called to delete/free the object */
258 char *(*string)_PROTO((VOID_STAR));
259 /* returns a string representation of the object */
260 int (*unary_function)_PROTO((int, unsigned char, VOID_STAR));
261 /* unary operation function */
262 SL_OOBinary_Type *binary_ops;
264 int (*copy_function)_PROTO((unsigned char, VOID_STAR));
265 /* This function is called do make a copy of the object */
266 } SLang_Class_Type;
268 extern SLang_Class_Type *SLang_Registered_Types[256];
270 typedef struct
272 unsigned char main_type; /* SLANG_RVARIABLE, etc.. */
273 unsigned char sub_type; /* int, string, etc... */
274 long *obj; /* address of user structure */
276 /* Everything below is considered private */
277 unsigned int count; /* number of references */
279 SLuser_Object_Type;
282 /*}}}*/
283 /*{{{ Interpreter Function Prototypes */
285 extern volatile int SLang_Error;
286 /* Non zero if error occurs. Must be reset to zero to continue. */
288 extern int SLang_Traceback;
289 /* If non-zero, dump an S-Lang traceback upon error. Available as
290 _traceback in S-Lang. */
292 extern char *SLang_User_Prompt;
293 /* Prompt to use when reading from stdin */
294 extern int SLang_Version;
296 extern void (*SLang_Error_Routine)(char *);
297 /* Pointer to application dependent error messaging routine. By default,
298 messages are displayed on stderr. */
300 extern void (*SLang_Exit_Error_Hook)(char *);
301 extern void SLang_exit_error (char *);
302 extern void (*SLang_Dump_Routine)(char *);
303 /* Called if S-Lang traceback is enabled as well as other debugging
304 routines (e.g., trace). By default, these messages go to stderr. */
306 extern void (*SLang_Interrupt)(void);
307 /* function to call whenever inner interpreter is entered. This is
308 a good place to set SLang_Error to USER_BREAK. */
310 extern void (*SLang_User_Clear_Error)(void);
311 /* function that gets called when '_clear_error' is called. */
312 extern int (*SLang_User_Open_Slang_Object)(SLang_Load_Type *);
313 extern int (*SLang_User_Close_Slang_Object)(SLang_Load_Type *);
314 /* user defined loading routines. */
317 /* If non null, these call C functions before and after a slang function. */
318 extern void (*SLang_Enter_Function)(char *);
319 extern void (*SLang_Exit_Function)(char *);
322 /* Functions: */
324 extern int init_SLang(void);
325 /* This function is mandatory and must be called by all applications */
326 extern int init_SLfiles(void);
327 /* called if fputs, fgets, etc are need in S-Lang */
328 extern int init_SLmath(void);
329 /* called if math functions sin, cos, etc... are needed. */
331 extern int init_SLunix(void);
332 /* unix system functions chmod, stat, etc... */
334 extern int init_SLmatrix(void);
336 extern int SLang_add_table(SLang_Name_Type *, char *);
337 /* add application dependent function table p1 to S-Lang. A name p2 less
338 * than 32 characters must also be supplied.
339 * Returns 0 upon failure or 1 upon success. */
341 extern int SLang_add_global_variable (char *);
342 extern int SLang_load_object(SLang_Load_Type *);
343 extern int SLang_load_file(char *);
344 /* Load a file of S-Lang code for interpreting. If the parameter is
345 NULL, input comes from stdin. */
347 extern void SLang_restart(int);
348 /* should be called if an error occurs. If the passed integer is
349 * non-zero, items are popped off the stack; otherwise, the stack is
350 * left intact. Any time the stack is believed to be trashed, this routine
351 * should be called with a non-zero argument (e.g., if setjmp/longjmp is
352 * called). */
354 extern void SLang_byte_compile_file(char *, int *);
355 /* takes a file of S-Lang code and ``byte-compiles'' it for faster
356 * loading. The new filename is equivalent to the old except that a `c' is
357 * appended to the name. (e.g., init.sl --> init.slc). If the second
358 * parameter is non-zero, preprocess the file only.
361 extern void SLang_autoload(char *, char *);
362 /* Automatically load S-Lang function p1 from file p2. This function
363 is also available via S-Lang */
365 extern char *SLang_load_string(char *);
366 /* Like SLang_load_file except input is from a null terminated string. */
368 extern void SLang_do_pop(void);
369 /* pops item off stack and frees any memory associated with it */
371 extern int SLang_pop_integer(int *);
372 /* pops integer *p0 from the stack. Returns 0 upon success and non-zero
373 * if the stack is empty or a type mismatch occurs, setting SLang_Error.
376 extern int SLpop_string (char **);
377 extern int SLang_pop_string(char **, int *);
378 /* pops string *p0 from stack. If *p1 is non-zero, the string must be
379 * freed after its use. DO NOT FREE p0 if *p1 IS ZERO! Returns 0 upon
380 * success */
382 extern int SLang_pop_float(float64 *, int *, int *);
383 /* Pops float *p1 from stack. If *p3 is non-zero, *p1 was derived
384 from the integer *p2. Returns zero upon success. */
386 extern SLuser_Object_Type *SLang_pop_user_object (unsigned char);
387 extern void SLang_free_user_object (SLuser_Object_Type *);
388 extern void SLang_free_intrinsic_user_object (SLuser_Object_Type *);
389 /* This is like SLang_free_user_object but is meant to free those
390 * that have been declared as intrinsic variables by the application.
391 * Normally an application would never need to call this.
394 extern void SLang_push_user_object (SLuser_Object_Type *);
395 extern SLuser_Object_Type *SLang_create_user_object (unsigned char);
397 extern int SLang_add_unary_op (unsigned char, FVOID_STAR);
398 extern int SLang_add_binary_op (unsigned char, unsigned char, FVOID_STAR);
399 extern int SLang_register_class (unsigned char, FVOID_STAR, FVOID_STAR);
400 extern int SLang_add_copy_operation (unsigned char, FVOID_STAR);
402 extern long *SLang_pop_pointer(unsigned char *, unsigned char *, int *);
403 /* Returns a pointer to object of type *p1,*p2 on top of stack.
404 If *p3 is non-zero, the Object must be freed after use. */
407 extern void SLang_push_float(float64);
408 /* Push Float onto stack */
410 extern void SLang_push_string(char *);
411 /* Push string p1 onto stack */
413 extern void SLang_push_integer(int);
414 /* push integer p1 on stack */
416 extern void SLang_push_malloced_string(char *);
417 /* The normal SLang_push_string mallocs space for the string. This one
418 does not. DO NOT FREE IT IF YOU USE THIS ROUTINE */
420 extern int SLang_is_defined(char *);
421 /* Return non-zero is p1 is defined otherwise returns 0. */
423 extern int SLang_run_hooks(char *, char *, char *);
424 /* calls S-Lang function p1 pushing strings p2 and p3 onto the stack
425 * first. If either string is NULL, it is not pushed. If p1 is not
426 * defined, 0 is returned. */
428 extern int SLang_execute_function(char *);
429 /* Call S-Lang function p1. Returns 0 if the function is not defined
430 * and 1 if it is.
433 extern char *SLang_find_name(char *);
434 /* Return a pointer to p1 in table if it is defined. Returns NULL
435 * otherwise. This is useful when one wants to avoid redundant strings.
438 extern char *SLang_rpn_interpret(char *);
439 /* Interpret string as reverse polish notation */
441 extern void SLang_doerror(char *);
442 /* set SLang_Error and display p1 as error message */
444 extern SLuser_Object_Type *SLang_add_array(char *, long *,
445 int, int, int, int,
446 unsigned char, unsigned char);
447 /* This function has not been tested thoroughly yet. Its purpose is to
448 * allow a S-Lang procedure to access a C array. For example, suppose that
449 * you have an array of 100 ints defined as:
451 * int c_array[100];
453 * By calling something like:
455 * SLang_add_array ("array_name", (long *) c_array, 1, 100, 0, 0,
456 * 'i', SLANG_IVARIABLE);
458 * the array can be accessed by the name 'array_name'. This function
459 * returns -1 upon failure. The 3rd argument specifies the dimension
460 * of the array, the 4th, and 5th arguments specify how many elements
461 * there are in the x,y, and z directions. The last argument must
462 * be one of:
464 * SLANG_IVARIABLE: indicates array is writable
465 * SLANG_RVARIABLE: indicates array is read only
467 * Returns NULL upon failure.
471 extern int SLang_free_array_handle (int);
472 /* This routine may be called by application to free array handle created by
473 * the application. Returns 0 upon success, -1 if the handle is invalid and
474 * -2 if the handle is not associated with a C array.
477 extern char *SLang_extract_list_element(char *, int *, int*);
478 extern void SLexpand_escaped_string (register char *, register char *,
479 register char *);
481 extern SLang_Name_Type *SLang_get_function (char *);
482 /* The parameter is the name of a user defined S-Lang function. This
483 * routine returns NULL if the function does not exist or it returns the
484 * a pointer to it in an internal S-Lang table. This pointer can be used
485 * by 'SLexecute_function' to call the function directly from C.
488 extern void SLexecute_function(SLang_Name_Type *);
489 /* This function allows an application to call a S-Lang function from within
490 * the C program. The parameter must be non-NULL and must have been
491 * previously obtained by a call to 'SLang_get_function'.
493 extern void SLroll_stack (int *);
494 /* If argument *p is positive, the top |*p| objects on the stack are rolled
495 * up. If negative, the stack is rolled down.
498 extern void SLmake_lut (unsigned char *, unsigned char *, unsigned char);
500 extern int SLang_guess_type (char *);
503 /*}}}*/
505 /*{{{ Misc Functions */
507 extern char *SLmake_string (char *);
508 extern char *SLmake_nstring (char *, unsigned int);
509 /* Returns a null terminated string made from the first n characters of the
510 * string.
513 extern char *SLcurrent_time_string (void);
515 extern int SLatoi(unsigned char *);
517 extern int SLang_extract_token(char **, char *, int);
518 /* returns 0 upon failure and non-zero upon success. The first parameter
519 * is a pointer to the input stream which this function will bump along.
520 * The second parameter is the buffer where the token is placed. The third
521 * parameter is used internally by the S-Lang library and should be 0 for
522 * user applications.
525 /*}}}*/
527 /*{{{ SLang getkey interface Functions */
529 #ifdef REAL_UNIX_SYSTEM
530 extern int SLang_TT_Baud_Rate;
531 extern int SLang_TT_Read_FD;
532 #endif
534 extern int SLang_init_tty (int, int, int);
535 /* Initializes the tty for single character input. If the first parameter *p1
536 * is in the range 0-255, it will be used for the abort character;
537 * otherwise, (unix only) if it is -1, the abort character will be the one
538 * used by the terminal. If the second parameter p2 is non-zero, flow
539 * control is enabled. If the last parmeter p3 is zero, output processing
540 * is NOT turned on. A value of zero is required for the screen management
541 * routines. Returns 0 upon success. In addition, if SLang_TT_Baud_Rate ==
542 * 0 when this function is called, SLang will attempt to determine the
543 * terminals baud rate. As far as the SLang library is concerned, if
544 * SLang_TT_Baud_Rate is less than or equal to zero, the baud rate is
545 * effectively infinite.
548 extern void SLang_reset_tty (void);
549 /* Resets tty to what it was prior to a call to SLang_init_tty */
550 #ifdef REAL_UNIX_SYSTEM
551 extern void SLtty_set_suspend_state (int);
552 /* If non-zero argument, terminal driver will be told to react to the
553 * suspend character. If 0, it will not.
555 extern int (*SLang_getkey_intr_hook) (void);
556 #endif
558 #define SLANG_GETKEY_ERROR 0xFFFF
559 extern unsigned int SLang_getkey (void);
560 /* reads a single key from the tty. If the read fails, 0xFFFF is returned. */
562 extern void SLang_ungetkey_string (unsigned char *, unsigned int);
563 extern void SLang_buffer_keystring (unsigned char *, unsigned int);
564 extern void SLang_ungetkey (unsigned char);
565 extern void SLang_flush_input (void);
566 extern int SLang_input_pending (int);
567 extern int SLang_Abort_Char;
568 /* The value of the character (0-255) used to trigger SIGINT */
569 extern int SLang_Ignore_User_Abort;
570 /* If non-zero, pressing the abort character will not result in USER_BREAK
571 * SLang_Error. */
573 extern void SLang_set_abort_signal (void (*)(int));
574 /* If SIGINT is generated, the function p1 will be called. If p1 is NULL
575 * the SLang_default signal handler is called. This sets SLang_Error to
576 * USER_BREAK. I suspect most users will simply want to pass NULL.
579 extern volatile int SLKeyBoard_Quit;
581 #ifdef VMS
582 /* If this function returns -1, ^Y will be added to input buffer. */
583 extern int (*SLtty_VMS_Ctrl_Y_Hook) (void);
584 #endif
585 /*}}}*/
587 /*{{{ SLang Keymap routines */
589 typedef struct SLKeymap_Function_Type
591 char *name;
592 int (*f)(void);
594 SLKeymap_Function_Type;
596 typedef struct SLang_Key_Type
598 unsigned char str[13]; /* key sequence */
599 #define SLKEY_F_INTERPRET 0x01
600 #define SLKEY_F_INTRINSIC 0x02
601 #define SLKEY_F_KEYSYM 0x03
602 unsigned char type; /* type of function */
603 #ifdef SLKEYMAP_OBSOLETE
604 VOID_STAR f; /* function to invoke */
605 #else
606 union
608 char *s;
609 FVOID_STAR f;
610 unsigned int keysym;
613 #endif
614 struct SLang_Key_Type *next; /* */
616 SLang_Key_Type;
618 #define MAX_KEYMAP_NAME_LEN 8
619 typedef struct SLKeyMap_List_Type
621 char name[MAX_KEYMAP_NAME_LEN + 1];
622 SLang_Key_Type *keymap;
623 SLKeymap_Function_Type *functions; /* intrinsic functions */
625 SLKeyMap_List_Type;
627 /* This is arbitrary but I have got to start somewhere */
628 #ifdef msdos
629 #define SLANG_MAX_KEYMAPS 10
630 #else
631 #define SLANG_MAX_KEYMAPS 30
632 #endif
634 extern SLKeyMap_List_Type SLKeyMap_List[SLANG_MAX_KEYMAPS]; /* these better be inited to 0! */
637 extern char *SLang_process_keystring(char *);
639 #ifdef SLKEYMAP_OBSOLETE
640 extern int SLang_define_key1(char *, VOID_STAR, unsigned int, SLKeyMap_List_Type *);
641 /* define key p1 in keymap p4 to invoke function p2. If type p3 is given by
642 * SLKEY_F_INTRINSIC, p2 is an intrinsic function, else it is a string to be
643 * passed to the interpreter for evaluation. The return value is important.
644 * It returns 0 upon success, -1 upon malloc error, and -2 if the key is
645 * inconsistent. SLang_Error is set upon error. */
646 #else
647 extern int SLkm_define_key (char *, FVOID_STAR, SLKeyMap_List_Type *);
648 #endif
650 extern int SLang_define_key(char *, char *, SLKeyMap_List_Type *);
651 /* Like define_key1 except that p2 is a string that is to be associated with
652 * a function in the functions field of p3. This routine calls define_key1.
655 extern int SLkm_define_keysym (char *, unsigned int, SLKeyMap_List_Type *);
657 extern void SLang_undefine_key(char *, SLKeyMap_List_Type *);
659 extern SLKeyMap_List_Type *SLang_create_keymap(char *, SLKeyMap_List_Type *);
660 /* create and returns a pointer to a new keymap named p1 created by copying
661 * keymap p2. If p2 is NULL, it is up to the calling routine to initialize
662 * the keymap.
665 extern char *SLang_make_keystring(unsigned char *);
667 extern SLang_Key_Type *SLang_do_key(SLKeyMap_List_Type *, int (*)(void));
668 /* read a key using keymap p1 with getkey function p2 */
670 extern
671 #ifdef SLKEYMAP_OBSOLETE
672 VOID_STAR
673 #else
674 FVOID_STAR
675 #endif
676 SLang_find_key_function(char *, SLKeyMap_List_Type *);
678 extern SLKeyMap_List_Type *SLang_find_keymap(char *);
680 extern int SLang_Last_Key_Char;
681 extern int SLang_Key_TimeOut_Flag;
684 /*}}}*/
686 /*{{{ SLang Readline Interface */
688 typedef struct SLang_Read_Line_Type
690 struct SLang_Read_Line_Type *prev, *next;
691 unsigned char *buf;
692 int buf_len; /* number of chars in the buffer */
693 int num; /* num and misc are application specific*/
694 int misc;
695 } SLang_Read_Line_Type;
697 /* Maximum size of display */
698 #define SLRL_DISPLAY_BUFFER_SIZE 256
700 typedef struct
702 SLang_Read_Line_Type *root, *tail, *last;
703 unsigned char *buf; /* edit buffer */
704 int buf_len; /* sizeof buffer */
705 int point; /* current editing point */
706 int tab; /* tab width */
707 int len; /* current line size */
709 /* display variables */
710 int edit_width; /* length of display field */
711 int curs_pos; /* current column */
712 int start_column; /* column offset of display */
713 int dhscroll; /* amount to use for horiz scroll */
714 char *prompt;
716 FVOID_STAR last_fun; /* last function executed by rl */
718 /* These two contain an image of what is on the display */
719 unsigned char upd_buf1[SLRL_DISPLAY_BUFFER_SIZE];
720 unsigned char upd_buf2[SLRL_DISPLAY_BUFFER_SIZE];
721 unsigned char *old_upd, *new_upd; /* pointers to previous two buffers */
722 int new_upd_len, old_upd_len; /* length of output buffers */
724 SLKeyMap_List_Type *keymap;
726 /* tty variables */
727 unsigned int flags; /* */
728 #define SL_RLINE_NO_ECHO 1
729 #define SL_RLINE_USE_ANSI 2
730 unsigned int (*getkey)(void); /* getkey function -- required */
731 void (*tt_goto_column)(int);
732 void (*tt_insert)(char);
733 void (*update_hook)(unsigned char *, int, int);
734 /* The update hook is called with a pointer to a buffer p1 that contains
735 * an image of what the update hook is suppoed to produce. The length
736 * of the buffer is p2 and after the update, the cursor is to be placed
737 * in column p3.
739 } SLang_RLine_Info_Type;
741 extern int SLang_RL_EOF_Char;
743 extern SLang_Read_Line_Type * SLang_rline_save_line (SLang_RLine_Info_Type *);
744 extern int SLang_init_readline (SLang_RLine_Info_Type *);
745 extern int SLang_read_line (SLang_RLine_Info_Type *);
746 extern int SLang_rline_insert (char *);
747 extern void SLrline_redraw (SLang_RLine_Info_Type *);
748 extern int SLang_Rline_Quit;
750 /*}}}*/
752 /*{{{ Low Level Screen Output Interface */
754 extern unsigned long SLtt_Num_Chars_Output;
755 extern int SLtt_Baud_Rate;
757 typedef unsigned long SLtt_Char_Type;
759 #define SLTT_BOLD_MASK 0x01000000
760 #define SLTT_BLINK_MASK 0x02000000
761 #define SLTT_ULINE_MASK 0x04000000
762 #define SLTT_REV_MASK 0x08000000
763 #define SLTT_ALTC_MASK 0x10000000
765 extern int SLtt_Screen_Rows;
766 extern int SLtt_Screen_Cols;
767 extern int SLtt_Term_Cannot_Insert;
768 extern int SLtt_Term_Cannot_Scroll;
769 extern int SLtt_Use_Ansi_Colors;
770 extern int SLtt_Ignore_Beep;
771 #if defined(REAL_UNIX_SYSTEM)
772 extern int SLtt_Force_Keypad_Init;
773 #endif
775 #ifndef __GO32__
776 #if defined(VMS) || defined(REAL_UNIX_SYSTEM)
777 extern int SLtt_Blink_Mode;
778 extern int SLtt_Use_Blink_For_ACS;
779 extern int SLtt_Newline_Ok;
780 extern int SLtt_Has_Alt_Charset;
781 extern int SLtt_Has_Status_Line; /* if 0, NO. If > 0, YES, IF -1, ?? */
782 # ifndef VMS
783 extern int SLtt_Try_Termcap;
784 # endif
785 #endif
786 #endif
788 #ifdef msdos
789 extern int SLtt_Msdos_Cheap_Video;
790 #endif
793 extern int SLtt_flush_output (void);
794 extern void SLtt_set_scroll_region(int, int);
795 extern void SLtt_reset_scroll_region(void);
796 extern void SLtt_reverse_video (int);
797 extern void SLtt_bold_video (void);
798 extern void SLtt_begin_insert(void);
799 extern void SLtt_end_insert(void);
800 extern void SLtt_del_eol(void);
801 extern void SLtt_goto_rc (int, int);
802 extern void SLtt_delete_nlines(int);
803 extern void SLtt_delete_char(void);
804 extern void SLtt_erase_line(void);
805 extern void SLtt_normal_video(void);
806 extern void SLtt_cls(void);
807 extern void SLtt_beep(void);
808 extern void SLtt_reverse_index(int);
809 extern void SLtt_smart_puts(unsigned short *, unsigned short *, int, int);
810 extern void SLtt_write_string (char *);
811 extern void SLtt_putchar(char);
812 extern void SLtt_init_video (void);
813 extern void SLtt_reset_video (void);
814 extern void SLtt_get_terminfo(void);
815 extern void SLtt_get_screen_size (void);
816 extern int SLtt_set_cursor_visibility (int);
818 #if defined(VMS) || defined(REAL_UNIX_SYSTEM)
819 extern void SLtt_enable_cursor_keys(void);
820 extern void SLtt_set_term_vtxxx(int *);
821 extern void SLtt_set_color_esc (int, char *);
822 extern void SLtt_wide_width(void);
823 extern void SLtt_narrow_width(void);
824 extern int SLtt_set_mouse_mode (int, int);
825 extern void SLtt_set_alt_char_set (int);
826 extern int SLtt_write_to_status_line (char *, int);
827 extern void SLtt_disable_status_line (void);
828 # ifdef REAL_UNIX_SYSTEM
829 extern char *SLtt_tgetstr (char *);
830 extern int SLtt_tgetnum (char *);
831 extern int SLtt_tgetflag (char *);
832 extern char *SLtt_tigetent (char *);
833 extern char *SLtt_tigetstr (char *, char **);
834 extern int SLtt_tigetnum (char *, char **);
835 # endif
836 #endif
838 extern SLtt_Char_Type SLtt_get_color_object (int);
839 extern void SLtt_set_color_object (int, SLtt_Char_Type);
840 extern void SLtt_set_color (int, char *, char *, char *);
841 extern void SLtt_set_mono (int, char *, SLtt_Char_Type);
842 extern void SLtt_add_color_attribute (int, SLtt_Char_Type);
843 extern void SLtt_set_color_fgbg (int, SLtt_Char_Type, SLtt_Char_Type);
845 /*}}}*/
847 /*{{{ SLang Preprocessor Interface */
849 typedef struct
851 int this_level;
852 int exec_level;
853 int prev_exec_level;
854 char preprocess_char;
855 char comment_char;
856 unsigned char flags;
857 #define SLPREP_BLANK_LINES_OK 1
858 #define SLPREP_COMMENT_LINES_OK 2
860 SLPreprocess_Type;
862 extern int SLprep_open_prep (SLPreprocess_Type *);
863 extern void SLprep_close_prep (SLPreprocess_Type *);
864 extern int SLprep_line_ok (char *, SLPreprocess_Type *);
865 extern int SLdefine_for_ifdef (char *);
866 /* Adds a string to the SLang #ifdef preparsing defines. SLang already
867 defines MSDOS, UNIX, and VMS on the appropriate system. */
868 extern int (*SLprep_exists_hook) (char *, char);
871 /*}}}*/
873 /*{{{ SLsmg Screen Management Functions */
875 #include <stdarg.h>
876 extern void SLsmg_fill_region (int, int, int, int, unsigned char);
877 #ifndef pc_system
878 extern void SLsmg_set_char_set (int);
879 extern int SLsmg_Scroll_Hash_Border;
880 #endif
881 extern void SLsmg_suspend_smg (void);
882 extern void SLsmg_resume_smg (void);
883 extern void SLsmg_erase_eol (void);
884 extern void SLsmg_gotorc (int, int);
885 extern void SLsmg_erase_eos (void);
886 extern void SLsmg_reverse_video (void);
887 extern void SLsmg_set_color (int);
888 extern void SLsmg_normal_video (void);
889 extern void SLsmg_printf (char *, ...);
890 extern void SLsmg_vprintf (char *, va_list);
891 extern void SLsmg_write_string (char *);
892 extern void SLsmg_write_nstring (char *, int);
893 extern void SLsmg_write_char (char);
894 extern void SLsmg_write_nchars (char *, int);
895 extern void SLsmg_write_wrapped_string (char *, int, int, int, int, int);
896 extern void SLsmg_cls (void);
897 extern void SLsmg_refresh (void);
898 extern void SLsmg_touch_lines (int, int);
899 extern int SLsmg_init_smg (void);
900 extern void SLsmg_reset_smg (void);
901 extern unsigned short SLsmg_char_at(void);
902 extern void SLsmg_set_screen_start (int *, int *);
903 extern void SLsmg_draw_hline (int);
904 extern void SLsmg_draw_vline (int);
905 extern void SLsmg_draw_object (int, int, unsigned char);
906 extern void SLsmg_draw_box (int, int, int, int);
907 extern int SLsmg_get_column(void);
908 extern int SLsmg_get_row(void);
909 extern void SLsmg_forward (int);
910 extern void SLsmg_write_color_chars (unsigned short *, unsigned int);
911 extern unsigned int SLsmg_read_raw (unsigned short *, unsigned int);
912 extern unsigned int SLsmg_write_raw (unsigned short *, unsigned int);
914 extern int SLsmg_Display_Eight_Bit;
915 extern int SLsmg_Tab_Width;
916 extern int SLsmg_Newline_Moves;
917 extern int SLsmg_Backspace_Moves;
919 #ifdef pc_system
920 # define SLSMG_HLINE_CHAR 0xC4
921 # define SLSMG_VLINE_CHAR 0xB3
922 # define SLSMG_ULCORN_CHAR 0xDA
923 # define SLSMG_URCORN_CHAR 0xBF
924 # define SLSMG_LLCORN_CHAR 0xC0
925 # define SLSMG_LRCORN_CHAR 0xD9
926 # define SLSMG_RTEE_CHAR 0xB4
927 # define SLSMG_LTEE_CHAR 0xC3
928 # define SLSMG_UTEE_CHAR 0xC2
929 # define SLSMG_DTEE_CHAR 0xC1
930 # define SLSMG_PLUS_CHAR 0xC5
931 /* There are several to choose from: 0xB0, 0xB1, and 0xB2 */
932 # define SLSMG_CKBRD_CHAR 0xB0
933 #else
934 # define SLSMG_HLINE_CHAR 'q'
935 # define SLSMG_VLINE_CHAR 'x'
936 # define SLSMG_ULCORN_CHAR 'l'
937 # define SLSMG_URCORN_CHAR 'k'
938 # define SLSMG_LLCORN_CHAR 'm'
939 # define SLSMG_LRCORN_CHAR 'j'
940 # define SLSMG_CKBRD_CHAR 'a'
941 # define SLSMG_RTEE_CHAR 'u'
942 # define SLSMG_LTEE_CHAR 't'
943 # define SLSMG_UTEE_CHAR 'w'
944 # define SLSMG_DTEE_CHAR 'v'
945 # define SLSMG_PLUS_CHAR 'n'
946 #endif
948 #ifndef pc_system
949 # define SLSMG_COLOR_BLACK 0x000000
950 # define SLSMG_COLOR_RED 0x000001
951 # define SLSMG_COLOR_GREEN 0x000002
952 # define SLSMG_COLOR_BROWN 0x000003
953 # define SLSMG_COLOR_BLUE 0x000004
954 # define SLSMG_COLOR_MAGENTA 0x000005
955 # define SLSMG_COLOR_CYAN 0x000006
956 # define SLSMG_COLOR_LGRAY 0x000007
957 # define SLSMG_COLOR_GRAY 0x000008
958 # define SLSMG_COLOR_BRIGHT_RED 0x000009
959 # define SLSMG_COLOR_BRIGHT_GREEN 0x00000A
960 # define SLSMG_COLOR_BRIGHT_BROWN 0x00000B
961 # define SLSMG_COLOR_BRIGHT_BLUE 0x00000C
962 # define SLSMG_COLOR_BRIGHT_CYAN 0x00000D
963 # define SLSMG_COLOR_BRIGHT_MAGENTA 0x00000E
964 # define SLSMG_COLOR_BRIGHT_WHITE 0x00000F
965 #endif
967 /*}}}*/
969 /*{{{ SLang Keypad Interface */
971 #define SL_KEY_ERR 0xFFFF
973 #define SL_KEY_UP 0x101
974 #define SL_KEY_DOWN 0x102
975 #define SL_KEY_LEFT 0x103
976 #define SL_KEY_RIGHT 0x104
977 #define SL_KEY_PPAGE 0x105
978 #define SL_KEY_NPAGE 0x106
979 #define SL_KEY_HOME 0x107
980 #define SL_KEY_END 0x108
981 #define SL_KEY_A1 0x109
982 #define SL_KEY_A3 0x10A
983 #define SL_KEY_B2 0x10B
984 #define SL_KEY_C1 0x10C
985 #define SL_KEY_C3 0x10D
986 #define SL_KEY_REDO 0x10E
987 #define SL_KEY_UNDO 0x10F
988 #define SL_KEY_BACKSPACE 0x110
989 #define SL_KEY_ENTER 0x111
990 #define SL_KEY_IC 0x112
991 #define SL_KEY_DELETE 0x113
993 #define SL_KEY_F0 0x200
994 #define SL_KEY_F(X) (SL_KEY_F0 + X)
996 /* I do not intend to use keysymps > 0x1000. Applications can use those. */
997 /* Returns 0 upon success or -1 upon error. */
998 int SLkp_define_keysym (char *, unsigned int);
1000 /* This function must be called AFTER SLtt_get_terminfo and not before. */
1001 extern int SLkp_init (void);
1003 /* This function uses SLang_getkey and assumes that what ever initialization
1004 * is required for SLang_getkey has been performed.
1006 extern int SLkp_getkey (void);
1008 /*}}}*/
1010 /*{{{ SLang Scroll Interface */
1012 typedef struct _SLscroll_Type
1014 struct _SLscroll_Type *next;
1015 struct _SLscroll_Type *prev;
1016 unsigned int flags;
1018 SLscroll_Type;
1020 typedef struct
1022 unsigned int flags;
1023 SLscroll_Type *top_window_line; /* list element at top of window */
1024 SLscroll_Type *bot_window_line; /* list element at bottom of window */
1025 SLscroll_Type *current_line; /* current list element */
1026 SLscroll_Type *lines; /* first list element */
1027 unsigned int nrows; /* number of rows in window */
1028 unsigned int hidden_mask; /* applied to flags in SLscroll_Type */
1029 unsigned int line_num; /* current line number (visible) */
1030 unsigned int num_lines; /* total number of lines (visible) */
1031 unsigned int window_row; /* row of current_line in window */
1032 unsigned int border; /* number of rows that form scroll border */
1033 int cannot_scroll; /* should window scroll or recenter */
1035 SLscroll_Window_Type;
1037 extern int SLscroll_find_top (SLscroll_Window_Type *);
1038 extern int SLscroll_find_line_num (SLscroll_Window_Type *);
1039 extern unsigned int SLscroll_next_n (SLscroll_Window_Type *, unsigned int);
1040 extern unsigned int SLscroll_prev_n (SLscroll_Window_Type *, unsigned int);
1041 extern int SLscroll_pageup (SLscroll_Window_Type *);
1042 extern int SLscroll_pagedown (SLscroll_Window_Type *);
1044 /*}}}*/
1046 /*{{{ Signal Routines */
1048 typedef void SLSig_Fun_Type (int);
1049 extern SLSig_Fun_Type *SLsignal (int, SLSig_Fun_Type *);
1050 extern SLSig_Fun_Type *SLsignal_intr (int, SLSig_Fun_Type *);
1051 #ifndef pc_system
1052 extern int SLsig_block_signals (void);
1053 extern int SLsig_unblock_signals (void);
1054 #endif
1055 /*}}}*/
1057 /*{{{ Interpreter Macro Definitions */
1059 /* This value is a main_type just like the other main_types defined
1060 * near the definition of SLang_Name_Type. Applications should avoid using
1061 * this so if you do not understands its role, do not use it.
1063 #define SLANG_DATA 0x30 /* real objects which may be destroyed */
1065 /* Subtypes */
1067 /* The definitions here are for objects that may be on the run-time stack.
1068 * They are actually sub_types of literal and data main_types.
1070 #define VOID_TYPE 1
1071 #define INT_TYPE 2
1072 #ifdef FLOAT_TYPE
1073 # undef FLOAT_TYPE
1074 # define FLOAT_TYPE 3
1075 #endif
1076 #define CHAR_TYPE 4
1077 #define INTP_TYPE 5
1078 /* An object of INTP_TYPE should never really occur on the stack. Rather,
1079 * the integer to which it refers will be there instead. It is defined here
1080 * because it is a valid type for MAKE_VARIABLE.
1083 #define SLANG_OBJ_TYPE 6
1084 /* SLANG_OBJ_TYPE refers to an object on the stack that is a pointer to
1085 * some other object.
1088 #if 0
1089 /* This is not ready yet. */
1090 # define SLANG_NOOP 9
1091 #endif
1093 /* Everything above string should correspond to a pointer in the object
1094 * structure. See do_binary (slang.c) for exploitation of this fact.
1096 #define STRING_TYPE 10
1097 /* Array type MUST be the smallest number for SLuser_Object_Type structs */
1098 #define ARRAY_TYPE 20
1099 /* I am reserving values greater than or equal to user applications. The
1100 * first 99 are used for S-Lang.
1104 /* Binary and Unary Subtypes */
1105 /* Since the application can define new types and can overload the binary
1106 * and unary operators, these definitions must be present in this file.
1108 #define SLANG_PLUS 1
1109 #define SLANG_MINUS 2
1110 #define SLANG_TIMES 3
1111 #define SLANG_DIVIDE 4
1112 #define SLANG_EQ 5
1113 #define SLANG_NE 6
1114 #define SLANG_GT 7
1115 #define SLANG_GE 8
1116 #define SLANG_LT 9
1117 #define SLANG_LE 10
1119 /* UNARY subtypes (may be overloaded) */
1120 #define SLANG_ABS 11
1121 #define SLANG_SIGN 12
1122 #define SLANG_SQR 13
1123 #define SLANG_MUL2 14
1124 #define SLANG_CHS 15
1126 /* error codes, severe errors are less than 0 */
1127 #define SL_INVALID_PARM -6
1128 #define SL_MALLOC_ERROR -5
1129 #define INTERNAL_ERROR -4
1130 #define UNKNOWN_ERROR -3
1131 #define STACK_OVERFLOW -1
1132 #define STACK_UNDERFLOW -2
1133 #define INTRINSIC_ERROR 1
1134 /* Intrinsic error is an error generated by intrinsic functions */
1135 #define USER_BREAK 2
1136 #define UNDEFINED_NAME 3
1137 #define SYNTAX_ERROR 4
1138 #define DUPLICATE_DEFINITION 5
1139 #define TYPE_MISMATCH 6
1140 #define READONLY_ERROR 7
1141 #define DIVIDE_ERROR 8
1142 /* object could not be opened */
1143 #define SL_OBJ_NOPEN 9
1144 /* unknown object */
1145 #define SL_OBJ_UNKNOWN 10
1147 extern char *SLang_Error_Message;
1149 extern void SLadd_name(char *, long, unsigned char, unsigned char);
1150 extern void SLadd_at_handler (long *, char *);
1152 #define SLANG_MAKE_ARGS(out, in) ((unsigned char)(out) | ((unsigned short) (in) << 4))
1154 #ifdef SLANG_STATS
1156 #define MAKE_INTRINSIC(n, f, out, in) \
1157 {0, n, (out | (in << 4)), SLANG_INTRINSIC, (long) f}
1159 #define MAKE_VARIABLE(n, v, t, r) \
1160 {0, n, t, (SLANG_IVARIABLE + r), (long) v}
1162 #else
1163 #define MAKE_INTRINSIC(n, f, out, in) \
1164 {n, (out | (in << 4)), SLANG_INTRINSIC, (long) f}
1166 #define MAKE_VARIABLE(n, v, t, r) \
1167 {n, t, (SLANG_IVARIABLE + r), (long) v}
1168 #endif
1170 #define SLANG_END_TABLE MAKE_INTRINSIC("", 0, 0, 0)
1173 /*}}}*/
1175 /*{{{ Upper/Lowercase Functions */
1177 extern void SLang_define_case(int *, int *);
1178 extern void SLang_init_case_tables (void);
1180 extern unsigned char Chg_UCase_Lut[256];
1181 extern unsigned char Chg_LCase_Lut[256];
1182 #define UPPER_CASE(x) (Chg_UCase_Lut[(unsigned char) (x)])
1183 #define LOWER_CASE(x) (Chg_LCase_Lut[(unsigned char) (x)])
1184 #define CHANGE_CASE(x) (((x) == Chg_LCase_Lut[(unsigned char) (x)]) ?\
1185 Chg_UCase_Lut[(unsigned char) (x)] : Chg_LCase_Lut[(unsigned char) (x)])
1188 /*}}}*/
1190 /*{{{ Regular Expression Interface */
1192 typedef struct
1194 unsigned char *pat; /* regular expression pattern */
1195 unsigned char *buf; /* buffer for compiled regexp */
1196 unsigned int buf_len; /* length of buffer */
1197 int case_sensitive; /* 1 if match is case sensitive */
1198 int must_match; /* 1 if line must contain substring */
1199 int must_match_bol; /* true if it must match beginning of line */
1200 unsigned char must_match_str[16]; /* 15 char null term substring */
1201 int osearch; /* 1 if ordinary search suffices */
1202 unsigned int min_length; /* minimum length the match must be */
1203 int beg_matches[10]; /* offset of start of \( */
1204 unsigned int end_matches[10]; /* length of nth submatch
1205 * Note that the entire match corresponds
1206 * to \0
1208 int offset; /* offset to be added to beg_matches */
1209 } SLRegexp_Type;
1211 extern unsigned char *SLang_regexp_match(unsigned char *,
1212 unsigned int,
1213 SLRegexp_Type *);
1214 extern int SLang_regexp_compile (SLRegexp_Type *);
1215 extern char *SLregexp_quote_string (char *, char *, unsigned int);
1218 /*}}}*/
1220 /*{{{ SLang Command Interface */
1222 #define SLCMD_MAX_ARGS 10
1223 struct _SLcmd_Cmd_Type; /* Pre-declaration is needed below */
1224 typedef struct
1226 struct _SLcmd_Cmd_Type *table;
1227 int argc;
1228 char *string_args[SLCMD_MAX_ARGS];
1229 int int_args[SLCMD_MAX_ARGS];
1230 float64 float_args[SLCMD_MAX_ARGS];
1231 unsigned char arg_type[SLCMD_MAX_ARGS];
1232 } SLcmd_Cmd_Table_Type;
1235 typedef struct _SLcmd_Cmd_Type
1237 int (*cmdfun)(int, SLcmd_Cmd_Table_Type *);
1238 char cmd[32];
1239 char arg_type[SLCMD_MAX_ARGS];
1240 } SLcmd_Cmd_Type;
1242 extern int SLcmd_execute_string (char *, SLcmd_Cmd_Table_Type *);
1244 /*}}}*/
1246 /*{{{ SLang Search Interface */
1248 typedef struct
1250 int cs; /* case sensitive */
1251 unsigned char key[256];
1252 int ind[256];
1253 int key_len;
1254 int dir;
1255 } SLsearch_Type;
1257 extern int SLsearch_init (char *, int, int, SLsearch_Type *);
1258 /* This routine must first be called before any search can take place.
1259 * The second parameter specifies the direction of the search: greater than
1260 * zero for a forwrd search and less than zero for a backward search. The
1261 * third parameter specifies whether the search is case sensitive or not.
1262 * The last parameter is a pointer to a structure that is filled by this
1263 * function and it is this structure that must be passed to SLsearch.
1266 unsigned char *SLsearch (unsigned char *, unsigned char *, SLsearch_Type *);
1267 /* To use this routine, you must first call 'SLsearch_init'. Then the first
1268 * two parameters p1 and p2 serve to define the region over which the search
1269 * is to take place. The third parameter is the structure that was previously
1270 * initialized by SLsearch_init.
1272 * The routine returns a pointer to the match if found otherwise it returns
1273 * NULL.
1276 /*}}}*/
1278 #if 0
1280 #endif
1281 #ifdef __cplusplus
1283 #endif
1285 #endif /* _DAVIS_SLANG_H_ */