3 /* -*- mode: C; mode: fold; -*- */
4 /* Copyright (c) 1992, 1995 John E. Davis
7 * You may distribute under the terms of either the GNU General Public
8 * License or the Perl Artistic License.
10 #define SLANG_VERSION 9938
11 /*{{{ System Dependent Macros and Typedefs */
13 #if defined(__WATCOMC__) && !defined(__QNX__)
26 #endif /* __watcomc__ */
36 # define REAL_UNIX_SYSTEM
40 /* Set of the various defines for pc systems. This includes OS/2 */
54 # ifdef REAL_UNIX_SYSTEM
55 # undef REAL_UNIX_SYSTEM
59 #if defined(__EMX__) && defined(OS2)
65 # define NEEDS_LOCAL_DIRENT_H
75 /* ---------------------------- Generic Macros ----------------------------- */
77 /* __SC__ is defined for Symantec C++
78 DOS386 is defined for -mx memory model, 32 bit DOS extender. */
84 #if defined(msdos) && !defined(DOS386) & !defined(__WIN32__) && !defined(__GO32__)
88 typedef void *VOID_STAR
;
92 # if defined (__cplusplus) || defined(__STDC__)
93 typedef void *VOID_STAR
;
96 typedef unsigned char *VOID_STAR
;
97 # define VOID unsigned char
102 typedef int (*FVOID_STAR
)(void);
104 # define FVOID_STAR VOID_STAR
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))
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
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))
124 # define SLREALLOC realloc
126 # define SLCALLOC calloc
130 #ifdef SL_MALLOC_DEBUG
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);
159 #ifndef FLOAT64_TYPEDEFED
160 # define FLOAT64_TYPEDEFED
161 typedef double float64
;
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
178 typedef struct SLang_Name_Type
181 int n
; /* number of times referenced */
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
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
;
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
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
221 int top_level
; /* 1 if at top level of parsing */
224 #if defined(ultrix) && !defined(__GNUC__)
225 # ifndef NO_PROTOTYPES
226 # define NO_PROTOTYPES
230 #ifndef NO_PROTOTYPES
233 # define _PROTO(x) ()
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
;
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 */
268 extern SLang_Class_Type
*SLang_Registered_Types
[256];
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 */
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 *);
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
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
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
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 *,
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:
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
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 *,
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 *);
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
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
527 /*{{{ SLang getkey interface Functions */
529 #ifdef REAL_UNIX_SYSTEM
530 extern int SLang_TT_Baud_Rate
;
531 extern int SLang_TT_Read_FD
;
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);
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
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
;
582 /* If this function returns -1, ^Y will be added to input buffer. */
583 extern int (*SLtty_VMS_Ctrl_Y_Hook
) (void);
587 /*{{{ SLang Keymap routines */
589 typedef struct SLKeymap_Function_Type
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 */
614 struct SLang_Key_Type
*next
; /* */
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 */
627 /* This is arbitrary but I have got to start somewhere */
629 #define SLANG_MAX_KEYMAPS 10
631 #define SLANG_MAX_KEYMAPS 30
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. */
647 extern int SLkm_define_key (char *, FVOID_STAR
, SLKeyMap_List_Type
*);
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
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 */
671 #ifdef SLKEYMAP_OBSOLETE
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
;
686 /*{{{ SLang Readline Interface */
688 typedef struct SLang_Read_Line_Type
690 struct SLang_Read_Line_Type
*prev
, *next
;
692 int buf_len
; /* number of chars in the buffer */
693 int num
; /* num and misc are application specific*/
695 } SLang_Read_Line_Type
;
697 /* Maximum size of display */
698 #define SLRL_DISPLAY_BUFFER_SIZE 256
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 */
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
;
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
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
;
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
;
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, ?? */
783 extern int SLtt_Try_Termcap
;
789 extern int SLtt_Msdos_Cheap_Video
;
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 **);
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
);
847 /*{{{ SLang Preprocessor Interface */
854 char preprocess_char
;
857 #define SLPREP_BLANK_LINES_OK 1
858 #define SLPREP_COMMENT_LINES_OK 2
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);
873 /*{{{ SLsmg Screen Management Functions */
876 extern void SLsmg_fill_region (int, int, int, int, unsigned char);
878 extern void SLsmg_set_char_set (int);
879 extern int SLsmg_Scroll_Hash_Border
;
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
;
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
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'
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
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);
1010 /*{{{ SLang Scroll Interface */
1012 typedef struct _SLscroll_Type
1014 struct _SLscroll_Type
*next
;
1015 struct _SLscroll_Type
*prev
;
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
*);
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
*);
1052 extern int SLsig_block_signals (void);
1053 extern int SLsig_unblock_signals (void);
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 */
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.
1074 # define FLOAT_TYPE 3
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.
1089 /* This is not ready yet. */
1090 # define SLANG_NOOP 9
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
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))
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}
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}
1170 #define SLANG_END_TABLE MAKE_INTRINSIC("", 0, 0, 0)
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)])
1190 /*{{{ Regular Expression Interface */
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
1208 int offset
; /* offset to be added to beg_matches */
1211 extern unsigned char *SLang_regexp_match(unsigned char *,
1214 extern int SLang_regexp_compile (SLRegexp_Type
*);
1215 extern char *SLregexp_quote_string (char *, char *, unsigned int);
1220 /*{{{ SLang Command Interface */
1222 #define SLCMD_MAX_ARGS 10
1223 struct _SLcmd_Cmd_Type
; /* Pre-declaration is needed below */
1226 struct _SLcmd_Cmd_Type
*table
;
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
*);
1239 char arg_type
[SLCMD_MAX_ARGS
];
1242 extern int SLcmd_execute_string (char *, SLcmd_Cmd_Table_Type
*);
1246 /*{{{ SLang Search Interface */
1250 int cs
; /* case sensitive */
1251 unsigned char key
[256];
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
1285 #endif /* _DAVIS_SLANG_H_ */