1 S-Lang Library C Programmer's Guide, V1.4.0
2 John E. Davis, davis@space.mit.edu
3 Fri Apr 21 21:48:16 2000
4 ____________________________________________________________
75 2. Interpreter Interface
77 3. Embedding the Interpreter
79 4. Calling the Interpreter
81 5. Intrinsic Functions
83 5.1 Restrictions on Intrinsic Functions
84 5.2 Adding a New Intrinsic
85 5.3 More Complicated Intrinsics
87 6. Intrinsic Variables
89 7. Aggregate Data Objects
93 7.2.1 Interpreter Structures
94 7.2.2 Intrinsic Structures
95 7.2.2 Keyboard Interface
97 8. Initializing the Keyboard Interface
99 9. Resetting the Keyboard Interface
103 11. Setting the Interrupt Handler
105 12. Reading Keyboard Input with SLang[lowbar]getkey
107 13. Reading Keyboard Input with SLkp[lowbar]getkey
113 15. Screen Management
119 18. Handling Screen Resize Events
123 19.1 Positioning the cursor
124 19.2 Writing to the Display
125 19.3 Erasing the Display
126 19.4 Setting Character Attributes
127 19.5 Lines and Alternate Character Sets
128 19.6 Miscellaneous Functions
132 21. Hints for using SLsmg
135 21. Searching Functions
137 22. Regular Expressions
147 26. The GNU Public License
149 27. The Artistic License
153 ______________________________________________________________________
203 S-Lang is an interpreted language that was designed from the start to
204 be easily embedded into a program to provide it with a powerful
205 extension language. Examples of programs that use S-Lang as an
206 extension language include the jed text editor, the slrn newsreader,
207 and sldxe (unreleased), a numerical computation program. For this
208 reason, S-Lang does not exist as a separate application and many of
209 the examples in this document are presented in the context of one of
210 the above applications.
212 S-Lang is also a programmer's library that permits a programmer to
213 develop sophisticated platform-independent software. In addition to
214 providing the S-Lang extension language, the library provides
215 facilities for screen management, keymaps, low-level terminal I/O,
216 etc. However, this document is concerned only with the extension
217 language and does not address these other features of the S-Lang
218 library. For information about the other components of the library,
219 the reader is referred to the The S-Lang Library Reference.
222 1.1. A Brief History of S-Lang
226 I first began working on S-Lang sometime during the fall of 1992. At
227 that time I was writing a text editor (jed), which I wanted to endow
228 with a macro language. It occured to me that an application-
229 independent language that could be embedded into the editor would
230 prove more useful because I could envision embedding it into other
231 programs. As a result, S-Lang was born.
233 S-Lang was originally a stack language that supported a postscript-
234 like syntax. For that reason, I named it S-Lang, where the S was
235 supposed to emphasize its stack-based nature. About a year later, I
236 began to work on a preparser that would allow one to write using a
237 more traditional infix syntax making it easier to use for those
238 unfamiliar with stack based languages. Currently, the syntax of the
239 language resembles C, nevertheless some postscript-like features still
240 remain, e.g., the `%' character is still used as a comment delimiter.
244 1.2. Acknowledgements
248 Since I first released S-Lang, I have received a lot feedback about
249 the library and the language from many people. This has given me the
250 opportunity and pleasure to interact with several people to make the
251 library portable and easy to use. In particular, I would like to
252 thank the following individuals:
254 Luchesar Ionkov <lionkov@sf.cit.bg> for his comments and criticisms of
255 the syntax of the language. He was the person who made me realize
256 that the low-level byte-code engine should be totally type-
257 independent. He also improved the tokenizer and preparser and
258 impressed upon me that the language needed a grammar.
260 Mark Olesen <olesen@weber.me.queensu.ca> for his many patches to
261 various aspects of the library and his support on AIX. He also
262 contributed a lot to the pre-processing (SLprep) routines.
265 John Burnell <j.burnell@irl.cri.nz> for the OS/2 port of the video and
266 keyboard routines. He also made value suggestions regarding the
267 interpreter interface.
269 Darrel Hankerson <hankedr@mail.auburn.edu> for cleaning up and
270 unifying some of the code and the makefiles.
272 Dominik Wujastyk <ucgadkw@ucl.ac.uk> who was always willing to test
273 new releases of the library.
275 Michael Elkins <me@muddcs.cs.hmc.edu> for his work on the curses
278 Ulli Horlacher <framstag@belwue.de> and Oezguer Kesim <kesim@math.fu-
279 berlin.de> for the S-Lang newsgroup and mailing list.
281 Hunter Goatley, Andy Harper <Andy.Harper@kcl.ac.uk>, and Martin P.J.
282 Zinser <zinser@decus.decus.de> for their VMS support.
284 Dave Sims <sims@usa.acsys.com> and Chin Huang <cthuang@vex.net> for
285 Windows 95 and Windows NT support.
287 Lloyd Zusman <ljz@asfast.com> and Rich Roth <rich@on-the-net.com> for
288 creating and maintaining www.s-lang.org.
290 I am also grateful to many other people who send in bug-reports and
291 bug-fixes, for without such community involvement, S-Lang would not be
292 as well-tested and stable as it is. Finally, I would like to thank my
293 wife for her support and understanding while I spent long weekend
294 hours developing the library.
335 S-Lang is a C programmer's library that includes routines for the
336 rapid development of sophisticated, user friendly, multi-platform
337 applications. The S-Lang library includes the following:
340 o Low level tty input routines for reading single characters at a
343 o Keymap routines for defining keys and manipulating multiple
346 o A high-level keyprocessing interface (SLkp) for handling function
349 o High level screen management routines for manipulating both
350 monochrome and color terminals. These routines are very efficient.
353 o Low level terminal-independent routines for manipulating the
354 display of a terminal. (SLtt)
356 o Routines for reading single line input with line editing and recall
357 capabilities. (SLrline)
359 o Searching functions: both ordinary searches and regular expression
362 o An embedded stack-based language interpreter with a C-like syntax.
365 The library is currently available for OS/2, MSDOS, Unix, and VMS
366 systems. For the most part, the interface to library routines has
367 been implemented in such a way that it appears to be platform
368 independent from the point of view of the application. In addition,
369 care has been taken to ensure that the routines are ``independent'' of
370 one another as much as possible. For example, although the keymap
371 routines require keyboard input, they are not tied to S-Lang's
372 keyboard input routines--- one can use a different keyboard getkey
373 routine if one desires. This also means that linking to only part of
374 the S-Lang library does not pull the whole library into the
375 application. Thus, S-Lang applications tend to be relatively small in
376 comparison to programs that use libraries with similar capabilities.
397 3. Interpreter Interface
401 The S-Lang library provides an interpreter that when embedded into an
402 application, makes the application extensible. Examples of programs
403 that embed the interpreter include the jed editor and the slrn
406 Embedding the interpreter is easy. The hard part is to decide what
407 application specific built-in or intrinsic functions should be
408 provided by the application. The S-Lang library provides some pre-
409 defined intrinsic functions, such as string processing functions, and
410 simple file input-output routines. However, the basic philosophy
411 behind the interpreter is that it is not a standalone program and it
412 derives much of its power from the application that embeds it.
415 3.1. Embedding the Interpreter
419 Only one function needs to be called to embed the S-Lang interpreter
420 into an application: SLang_init_slang. This function initializes the
421 interpreter's data structures and adds some intrinsic functions:
424 if (-1 == SLang_init_slang ())
430 This function does not provide file input output intrinsic nor does it
431 provide mathematical functions. To make these as well as some posix
432 system calls available use
435 if ((-1 == SLang_init_slang ()) /* basic interpreter functions */
436 || (-1 == SLang_init_slmath ()) /* sin, cos, etc... */
437 || (-1 == SLang_init_stdio ()) /* stdio file I/O */
438 || (-1 == SLang_init_posix_dir ()) /* mkdir, stat, etc. */
439 || (-1 == SLang_init_posix_process ()) /* getpid, umask, etc. */
446 If you intend to enable all intrinsic functions, then it is simpler to
447 initialize the interpreter via
450 if (-1 == SLang_init_all ())
456 See the \slang-run-time-library for more information about the intrin-
463 3.2. Calling the Interpreter
467 There are several ways of calling the interpreter. The most common
468 method used by both jed and slrn is to use the SLang_load_file
469 function to interprete a file. For example, jed starts by loading a
473 if (-1 == SLang_load_file ("site.sl"))
482 The SLang_load_file function returns zero upon if successful, or -1
483 upon failure. The SLang_restart function resets the interpreter back
484 to its default state; however, it does not reset SLang_Error to zero.
485 It is up to the application to re-initialize the SLang_Error variable.
487 There are several other mechanisms for interacting with the
488 interpreter. For example, the SLang_load_string function loads a
489 string into the interpreter and interprets it:
492 if (-1 == SLang_load_string ("message (\"hello\");"))
501 Typically, an interactive application will load a file via
502 SLang_load_file and then go into a loop that consists of reading lines
503 of input and sending them to the interpreter, e.g.,
506 while (EOF != fgets (buf, sizeof (buf), stdin))
508 if (-1 == SLang_load_string (buf))
516 Both jed and slrn use another method of interacting with the
517 interpreter. They read key sequences from the keyboard and map those
518 key sequences to interpreter functions via the S-Lang keymap
523 3.3. Intrinsic Functions
527 An intrinsic function is simply a function that is written in C and is
528 made available to the interpreter as a built-in function. For this
529 reason, the words `intrinsic' and `built-in' are often used
532 Applications are expected to add application specific functions to the
533 interpreter. For example, jed adds nearly 300 editor-specific
534 intrinsic functions. The application designer should think carefully
535 about what intrinsic functions to add to the interpreter.
538 3.3.1. Restrictions on Intrinsic Functions
542 Intrinsic functions are required to follow a few rules to cooperate
543 with the interpreter.
545 Intrinsic function must take only pointer arguments. This is because
546 when the interpreter calls an intrinsic function, it passes value to
547 the function by reference and not by value. For example, intrinsic
548 with the declarations:
551 int intrinsic_0 (void);
552 int intrinsic_1 (char *s);
553 void intrinsic_2 (char *s, int *i);
554 void intrinsic_3 (int *i, double *d, double *e);
559 are all valid. However,
562 int invalid_1 (char *s, int len);
567 is not valid since the len parameter is not a pointer.
569 Intrinsic functions can only return void, int, double, or char *. A
578 is not permitted since it does not return one of these types. The
579 current implementation limits the number of arguments to 7.
581 Another restriction is that the intrinsic should regard all its
582 parameters as pointers to constant objects and make no attempt to
583 modify the value to which they point. For example,
586 void truncate (char *s)
594 is illegal since the function modifies the string s.
595 3.3.2. Adding a New Intrinsic
599 There are two mechanisms for adding an intrinsic function to the
600 interpreter: SLadd_intrinsic_function and SLadd_intrin_fun_table.
602 As an specific example, consider a function that will cause the
603 program to exit via the exit C library function. It is not possible
604 to make this function an intrinsic because it does not meet the
605 specifications for an intrinsic function that were described earlier.
606 However, one can call exit from a function that is suitable, e.g.,
609 void intrin_exit (int *code)
617 This function may be made available to the interpreter as as an
618 intrinsic via the SLadd_intrinsic_function routine:
621 if (-1 == SLadd_intrinsic_function ("exit", (FVOID_STAR) intrin_exit,
629 This statement basically tells the interpreter that intrin_exit is a
630 function that returns nothing and takes a single argument: a pointer
631 to an integer (SLANG_INT_TYPE). A user can call this function from
632 within the interpreter via
635 message ("Calling the exit function");
641 After printing a message, this will cause the intrin_exit function to
642 execute, which in turn calls exit.
644 The most convenient mechanism for adding new intrinsic functions is to
645 create a table of SLang_Intrin_Fun_Type objects and add the table via
646 the SLadd_intrin_fun_table function. The table will look like:
649 SLang_Intrin_Fun_Type My_Intrinsics [] =
652 MAKE_INTRINSIC_N(...),
653 MAKE_INTRINSIC_N(...),
656 MAKE_INTRINSIC_N(...),
661 Construction of the table entries may be facilitated using a set of
662 MAKE_INTRINSIC macros defined in slang.h. The main macro is called
663 MAKE_INTRINSIC_N and takes ?? arguments:
666 MAKE_INTRINSIC_N(name, funct-ptr, return-type, num-args,
667 arg-1-type, arg-2-type, ... arg-7-type)
672 Here name is the name of the intrinsic function that the interpreter
673 is to give to the function. func-ptr is a pointer to the intrinsic
674 function taking num-args and returning ret-type. The final 7 argu-
675 ments specifiy the argument types. For example, the intrin_exit
676 intrinsic described above may be added to the table using
679 MAKE_INTRINSIC_N("exit", intrin_exit, SLANG_VOID_TYPE, 1,
680 SLANG_INT_TYPE, 0,0,0,0,0,0)
685 While MAKE_INTRINSIC_N is the main macro for constructing table
686 entries, slang.h defines other macros that may prove useful. In
687 particular, an entry for the intrin_exit function may also be created
688 using any of the following forms:
691 MAKE_INTRINSIC_1("exit", intrin_exit, SLANG_VOID_TYPE, SLANG_INT_TYPE)
692 MAKE_INTRINSIC_I("exit", intrin_exit, SLANG_VOID_TYPE)
697 See slang.h for related macros. You are also encouraged to look at,
698 e.g., slang/src/slstd.c for a more extensive examples.
700 The table may be added via the SLadd_intrin_fun_table function, e.g.,
703 if (-1 == SLadd_intrin_fun_table (My_Intrinsics, NULL))
705 /* an error occurred */
711 Please note that there is no need to load a given table more than
712 once, and it is considered to be an error on the part of the applica-
713 tion it adds the same table multiple times. For performance reasons,
714 no checking is performed by the library to see if a table has already
719 3.3.3. More Complicated Intrinsics
722 The intrinsic functions described in the previous example were
723 functions that took a fixed number of arguments. In this section we
724 explore more complex intrinsics such as those that take a variable
727 Consider a function that takes two double precision numbers and
731 double intrin_min (double *a, double *b)
733 if (*a < *b) return *a;
740 This function may be added to a table of intrinsics using
743 MAKE_INTRINSIC_2("min", intrin_min, SLANG_DOUBLE_TYPE,
744 SLANG_DOUBLE_TYPE, SLANG_DOUBLE_TYPE)
749 It is useful to extend this function to take an arbitray number of
750 arguments and return the lesser. Consider the following variant:
753 double intrin_min_n (int *num_ptr)
756 unsigned int num = (unsigned int) *num_ptr;
758 if (-1 == SLang_pop_double (&min_value, NULL, NULL))
765 if (-1 == SLang_pop_double (&x, NULL, NULL))
767 if (x < min_value) min_value = x;
775 Here the number to compare is passed to the function and the actual
776 numbers are removed from the stack via the SLang_pop_double function.
777 A suitable table entry for it is
780 MAKE_INTRINSIC_I("min", intrin_min_n, SLANG_DOUBLE_TYPE)
785 This function would be used in an interpreter script via a statement
789 variable xmin = min (x0, x1, x2, x3, x4, 5);
793 which computes the smallest of 5 values.
795 The problem with this intrinsic function is that the user must
796 explicitly specify how many numbers to compare. It would be more
797 convenient to simply use
800 variable xmin = min (x0, x1, x2, x3, x4);
805 An intrinsic function can query the value of the variable
806 SLang_Num_Function_Args to obtain the necessary information:
809 double intrin_min (void)
813 unsigned int num = SLang_Num_Function_Args;
815 if (-1 == SLang_pop_double (&min_value, NULL, NULL))
822 if (-1 == SLang_pop_double (&x, NULL, NULL))
824 if (x < min_value) min_value = x;
832 This may be declared as an intrinsic using:
835 MAKE_INTRINSIC_0("min", intrin_min, SLANG_DOUBLE_TYPE)
844 3.4. Intrinsic Variables
848 It is possible to access an application's global variables from within
849 the interpreter. The current implementation supports the access of
850 variables of type int, char *, and double.
852 There are two methods of making an intrinsic variable available to the
853 interpreter. The most straight forward method is to use the function
854 SLadd_intrinsic_variable:
859 int SLadd_intrinsic_variable (char *name, VOID_STAR addr,
860 unsigned char data_type,
866 For example, suppose that I is an integer variable, e.g.,
874 One can make it known to the interpreter as I_Variable via a statement
878 if (-1 == SLadd_intrinsic_variable ("I_Variable", &I,
885 Similarly, if S is declared as
896 if (-1 == SLadd_intrinsic_variable ("S_Variable", &S,
897 SLANG_STRING_TYPE, 1))
903 makes S available as a read-only variable with the name S_Variable.
904 Note that if a pointer variable is made available to the interpreter,
905 its value is managed by the interpreter and not the application. For
906 this reason, it is recommended that such variables be declared as
909 It is important to note that if S were declared as an array of
918 then it would not be possible to make it directly available to the
919 interpreter. However, one could create a pointer to it, i.e.,
925 and make S_Ptr available as a read-only variable.
927 One should not make the mistake of trying to use the same address for
928 different variables as the following example illustrates:
931 int do_not_try_this (void)
933 static char *names[3] = {"larry", "curly", "moe"};
936 for (i = 0; i < 3; i++)
939 if (-1 == SLadd_intrinsic_variable (names[i], (VOID_STAR) &value,
949 Not only does this piece of code create intrinsic variables that use
950 the same address, it also uses the address of a local variable that
951 will go out of scope.
953 The most convenient method for adding many intrinsic variables to the
954 interpreter is to create an array of SLang_Intrin_Var_Type objects and
955 then add the array via SLadd_intrin_var_table. For example, the array
958 static SLang_Intrin_Var_Type Intrin_Vars [] =
960 MAKE_VARIABLE("I_Variable", &I, SLANG_INT_TYPE, 0),
961 MAKE_VARIABLE("S_Variable", &S_Ptr, SLANG_STRING_TYPE, 1),
971 if (-1 == SLadd_intrin_var_table (Intrin_Vars, NULL))
977 It should be rather obvious that the arguments to the MAKE_VARIABLE
978 macro correspond to the parameters of the SLadd_intrinsic_variable
984 3.5. Aggregate Data Objects
987 An aggregate data object is an object that can contain more than one
988 data value. The S-Lang interpreter supports several such objects:
989 arrays, structure, and associative arrays. In the following sections,
990 information about interacting with these objects is given.
994 An intrinsic function may interact with an array in several different
995 ways. For example, an intrinsic may create an array and return it.
996 The basic functions for manipulating arrays include:
1000 SLang_pop_array_of_type
1003 SLang_get_array_element
1004 SLang_set_array_element
1009 The use of these functions will be illustrated via a few simple exam-
1012 The first example shows how to create an return an array of strings to
1013 the interpreter. In particular, the names of the four seasons of the
1014 year will be returned:
1017 void months_of_the_year (void)
1019 static char *seasons[4] =
1021 "Spring", "Summer", "Autumn", "Winter"
1023 SLang_Array_Type *at;
1027 at = SLang_create_array (SLANG_STRING_TYPE, 0, NULL, &four, 1);
1031 /* Now set the elements of the array */
1032 for (i = 0; i < 4; i++)
1034 if (-1 == SLang_set_array_element (at, &i, &seasons[i]))
1036 SLang_free_array (at);
1041 (void) SLang_push_array (at, 0);
1042 SLang_free_array (at);
1048 This example illustrates several points. First of all, the SLang_cre-
1049 ate_array function was used to create a 1 dimensional array of 4
1050 strings. Since this function could fail, its return value was
1051 checked. Then the SLang_set_array_element function was used to set
1052 the elements of the newly created array. Note that the address con-
1053 taining the value of the array element was passed and not the value of
1054 the array element itself. That is,
1057 SLang_set_array_element (at, &i, seasons[i])
1062 was not used. The return value from this function was also checked
1063 because it too could also fail. Finally, the array was pushed onto
1064 the interpreter's stack and then it was freed. It is important to
1065 understand why it was freed. This is because arrays are reference-
1066 counted. When the array was created, it was returned with a reference
1067 count of 1. When it was pushed, the reference count was bumped up to
1068 2. Then since it was nolonger needed by the function,
1069 SLang_free_array was called to decrement the reference count back to
1070 1. For convenience, the second argument to SLang_push_array deter-
1071 mines whether or not it is to also free the array. So, instead of the
1075 (void) SLang_push_array (at, 0);
1076 SLang_free_array (at);
1081 it is preferable to combine them as
1084 (void) SLang_push_array (at, 1);
1089 The second example returns a diagonal array of a specified size to the
1090 stack. A diagonal array is a 2-d array with all elements zero except
1091 for those along the diagonal, which have a value of one:
1094 void make_diagonal_array (int n)
1096 SLang_Array_Type *at;
1100 dims[0] = dims[1] = n;
1101 at = SLang_create_array (SLANG_INT_TYPE, 0, NULL, dims, 2);
1106 for (i = 0; i < n; i++)
1108 dims[0] = dims[1] = i;
1109 if (-1 == SLang_set_array_element (at, dims, &one))
1111 SLang_free_array (at);
1116 (void) SLang_push_array (at, 1);
1122 In this example, only the diagonal elements of the array were set.
1123 This is bacause when the array was created, all its elements were set
1126 Now consider an example that acts upon an existing array. In
1127 particular, consider one that computes the trace of a 2-d matrix,
1128 i.e., the sum of the diagonal elements:
1131 double compute_trace (void)
1133 SLang_Array_Type *at;
1137 if (-1 == SLang_pop_array_of_type (&at, SLANG_DOUBLE_TYPE))
1140 /* We want a 2-d square matrix. If the matrix is 1-d and has only one
1141 element, then return that element. */
1143 if (((at->num_dims == 1) && (at->dims[0] == 1))
1144 || ((at->num_dims == 2) && (at->dims[0] == at->dims[1])))
1147 int n = at->dims[0];
1149 for (i = 0; i < n; i++)
1151 dims[0] = dims[1] = i;
1152 (void) SLang_get_array_element (at, &dims, &dtrace);
1156 else SLang_verror (SL_TYPE_MISMATCH, "Expecting a square matrix");
1158 SLang_free_array (at);
1165 In this example, SLang_pop_array_of_type was used to pop an array of
1166 doubles from the stack. This function will make implicit typecasts in
1167 order to return an array of the requested type.
1175 For the purposes of this section, we shall differentiate structures
1176 according to whether or not they correspond to an application defined
1177 C structure. Those that do are called intrinsic structures, and those
1178 do not are called S-Lang interpreter structures.
1181 3.5.2.1. Interpreter Structures
1184 The following simple example shows how to create and return a
1185 structure to the stack with a string an integer field:
1189 int push_struct_example (char *string_value, int int_value)
1191 char *field_names[2];
1192 unsigned char field_types[2];
1193 VOID_STAR field_values[2];
1195 field_names[0] = "string_field";
1196 field_types[0] = SLANG_STRING_TYPE;
1197 field_values[0] = &string_value;
1199 field_names[1] = "int_field";
1200 field_types[1] = SLANG_INT_TYPE;
1201 field_values[1] = &int_value;
1203 if (-1 == SLstruct_create_struct (2, field_names,
1204 field_types, field_values))
1212 Here, SLstruct_create_struct was used to push a structure with the
1213 specified field names and values onto the interpreter's stack.
1216 3.5.2.2. Intrinsic Structures
1219 Here we show how to make intrinsic structures available to the
1220 interpreter. The simplest interface is to structure pointers and not
1221 to the actual structures themselves. The latter would require the
1222 interpreter to be involved with the creation and destruction of the
1223 structures. Dealing with the pointers themselves is far simpler.
1225 As an example, consider an object such as
1228 typedef struct _Window_Type
1240 which defines a window object with a title, size (width, height), and
1241 location (row, col).
1243 We can make variables of type Window_Type available to the interpreter
1244 via a table as follows:
1255 static SLang_IStruct_Field_Type Window_Type_Field_Table [] =
1257 MAKE_ISTRUCT_FIELD(Window_Type, title, "title", SLANG_STRING_TYPE, 1),
1258 MAKE_ISTRUCT_FIELD(Window_Type, row, "row", SLANG_INT_TYPE, 0),
1259 MAKE_ISTRUCT_FIELD(Window_Type, col, "col", SLANG_INT_TYPE, 0),
1260 MAKE_ISTRUCT_FIELD(Window_Type, width, "width", SLANG_INT_TYPE, 0),
1261 MAKE_ISTRUCT_FIELD(Window_Type, height, "height", SLANG_INT_TYPE, 0),
1268 More precisely, this defines the layout of the Window_Type structure.
1269 Here, the title has been declared as a read-only field. Using
1272 MAKE_ISTRUCT_FIELD(Window_Type, title, "title", SLANG_STRING_TYPE, 0),
1277 would allow read-write access.
1279 Now suppose that My_Window is a pointer to a Window_Type object, i.e.,
1282 Window_Type *My_Window;
1287 We can make this variable available to the interpreter via the
1288 SLadd_istruct_table function:
1291 if (-1 == SLadd_istruct_table (Window_Type_Field_Table,
1292 (VOID_STAR) &My_Window,
1299 This creates a S-Lang interpreter variable called My_Win whose value
1300 corresponds to to the My_Win structure. This would permit one to
1301 access the fields of My_Window via S-Lang statements such as
1304 define set_width_and_height (w,h)
1313 It is extremely important to understand that the interface described
1314 in this section does not allow the interpreter to create new instances
1315 of Window_Type objects. The interface merely defines an association
1316 or correspondence between an intrinsic structure pointer and a S-Lang
1317 variable. For example, if the value of My_Window is NULL, then My_Win
1321 One should be careful in allowing read/write access to character
1322 string fields. If read/write access is allowed, then the application
1323 should always use the SLang_create_slstring and SLang_free_slstring
1324 functions to set the character string field of the structure.
1325 Finally, note that access to character array fields is not permitted
1326 via this interface. That is, a structure such as
1338 is not permitted since char name[32] is not a SLANG_STRING_TYPE
1387 4. Keyboard Interface
1393 S-Lang's keyboard interface has been designed to allow an application
1394 to read keyboard input from the user in a system-independent manner.
1395 The interface consists of a set of low routines for reading single
1396 character data as well as a higher level interface (SLkp) which
1397 utilize S-Lang's keymap facility for reading multi-character
1400 To initialize the interface, one must first call the function
1401 SLang_init_tty. Before exiting the program, the function
1402 SLang_reset_tty must be called to restore the keyboard interface to
1403 its original state. Once initialized, the low-level SLang_getkey
1404 function may be used to read simgle keyboard characters from the
1405 terminal. An application using the the higher-level SLkp interface
1406 will read charcters using the SLkp_getkey function.
1408 In addition to these basic functions, there are also functions to
1409 ``unget'' keyboard characters, flush the input, detect pending-input
1410 with a timeout, etc. These functions are defined below.
1414 4.1. Initializing the Keyboard Interface
1418 The function SLang_init_tty must be called to initialize the terminal
1419 for single character input. This puts the terminal in a mode usually
1420 referred to as ``raw'' mode.
1422 The prototype for the function is:
1425 int SLang_init_tty (int abort_char, int flow_ctrl, int opost);
1430 It takes three parameters that are used to specify how the terminal is
1431 to be initialized. %Although the S-Lang keyboard interface has been
1432 %designed to be as system independent as possible, there are semantic
1435 The first parameter, abort_char, is used to specify the interrupt
1436 character (SIGINT). Under MSDOS, this value corresponds to the scan
1437 code of the character that will be used to generate the interrupt.
1438 For example, under MSDOS, 34 should be used to make Ctrl-G generate an
1439 interrupt signal since 34 is the scan code for G. On other systems,
1440 the value of abort_char will simply be the ascii value of the control
1441 character that will be used to generate the interrupt signal, e.g., 7
1442 for Ctrl-G. If -1 is passed, the interrupt character will not be
1445 Pressing the interrupt character specified by the first argument will
1446 generate a signal (SIGINT) that may or not be caught by the
1447 application. It is up to the application to catch this signal. S-
1448 Lang provides the function Slang_set_abort_signal to make it easy to
1449 facilitate this task.
1451 The second parameter is used to specify whether or not flow control
1452 should be used. If this parameter is zero, flow control is enabled
1453 otherwise it is disabled. Disabling flow control is necessary to pass
1454 certain characters to the application (e.g., Ctrl-S and Ctrl-Q). For
1455 some systems such as MSDOS, this parameter is meaningless.
1457 The third parameter, opost, is used to turn output processing on or
1458 off. If opost is zero, output processing is not turned on otherwise,
1459 output processing is turned on.
1461 The SLang_init_tty function returns -1 upon failure. In addition,
1462 after it returns, the S-Lang global variable SLang_TT_Baud_Rate will
1463 be set to the baud rate of the terminal if this value can be
1469 if (-1 == SLang_init_tty (7, 0, 0)) /* For MSDOS, use 34 as scan code */
1471 fprintf (stderr, "Unable to initialize the terminal.\n");
1474 SLang_set_abort_signal (NULL);
1479 Here the terminal is initialized such that flow control and output
1480 processing are turned off. In addition, the character Ctrl-G (-- For
1481 MSDOS systems, use the scan code 34 instead of 7 for Ctrl-G--) has
1482 been specified to be the interrupt character. The function
1483 SLang_set_abort_signal is used to install the default S-Lang interrupt
1488 4.2. Resetting the Keyboard Interface
1492 The function SLang_reset_tty must be called to reset the terminal to
1493 the state it was in before the call to SLang_init_tty. The prototype
1494 for this function is:
1497 void SLang_reset_tty (void);
1502 Usually this function is only called before the program exits. How-
1503 ever, if the program is suspended it should also be called just before
1508 4.3. Initializing the SLkp Routines
1512 Extra initialization of the higher-level SLkp functions are required
1513 because they are layered on top of the lower level routines. Since
1514 the SLkp_getkey function is able to process function and arrow keys in
1515 a terminal independent manner, it is necessary to call the
1516 SLtt_get_terminfo function to get information about the escape
1517 character sequences that the terminal's function keys send. Once that
1518 information is available, the SLkp_init function can construct the
1519 proper keymaps to process the escape sequences.
1521 This part of the initialization process for an application using this
1522 interface will look something like:
1526 SLtt_get_terminfo ();
1527 if (-1 == SLkp_init ())
1529 SLang_doerror ("SLkp_init failed.");
1532 if (-1 == SLang_init_tty (-1, 0, 1))
1534 SLang_doerror ("SLang_init_tty failed.");
1541 It is important to check the return status of the SLkp_init function
1542 which can failed if it cannot allocate enough memory for the keymap.
1546 4.4. Setting the Interrupt Handler
1550 The function SLang_set_abort_signal may be used to associate an
1551 interrupt handler with the interrupt character that was previously
1552 specified by the SLang_init_tty function call. The prototype for this
1556 void SLang_set_abort_signal (void (*)(int));
1561 This function returns nothing and takes a single parameter which is a
1562 pointer to a function taking an integer value and returning void. If
1563 a NULL pointer is passed, the default S-Lang interrupt handler will be
1564 used. The S-Lang default interrupt handler under Unix looks like:
1567 static void default_sigint (int sig)
1569 SLsignal_intr (SIGINT, default_sigint);
1570 SLKeyBoard_Quit = 1;
1571 if (SLang_Ignore_User_Abort == 0) SLang_Error = USER_BREAK;
1577 It simply sets the global variable SLKeyBoard_Quit to one and if the
1578 variable SLang_Ignore_User_Abort is non-zero, SLang_Error is set to
1579 indicate a user break condition. (The function SLsignal_intr is simi-
1580 lar to the standard C signal function except that it will interrupt
1581 system calls. Some may not like this behavior and may wish to call
1582 this SLang_set_abort_signal with a different handler.)
1585 Although the function expressed above is specific to Unix, the
1586 analogous routines for other operating systems are equivalent in
1587 functionality even though the details of the implementation may vary
1588 drastically (e.g., under MSDOS, the hardware keyboard interrupt int 9h
1593 4.5. Reading Keyboard Input with SLang_getkey
1597 After initializing the keyboard via SLang_init_tty, the S-Lang
1598 function SLang_getkey may be used to read characters from the terminal
1599 interface. In addition, the function SLang_input_pending may be used
1600 to determine whether or not keyboard input is available to be read.
1602 These functions have prototypes:
1605 unsigned int SLang_getkey (void);
1606 int SLang_input_pending (int tsecs);
1611 The SLang_getkey function returns a single character from the termi-
1612 nal. Upon failure, it returns 0xFFFF. If the interrupt character
1613 specified by the SLang_init_tty function is pressed while this func-
1614 tion is called, the function will return the value of the interrupt
1615 character and set the S-Lang global variable SLKeyBoard_Quit to a non-
1616 zero value. In addition, if the default S-Lang interrupt handler has
1617 been specified by a NULL argument to the SLang_set_abort_signal func-
1618 tion, the global variable SLang_Error will be set to USER_BREAK unless
1619 the variable SLang_Ignore_User_Abort is non-zero.
1621 The SLang_getkey function waits until input is available to be read.
1622 The SLang_input_pending function may be used to determine whether or
1623 not input is ready. It takes a single parameter that indicates the
1624 amount of time to wait for input before returning with information
1625 regarding the availability of input. This parameter has units of one
1626 tenth (1/10) of a second, i.e., to wait one second, the value of the
1627 parameter should be 10. Passing a value of zero causes the function
1628 to return right away. SLang_input_pending returns a positive integer
1629 if input is available or zero if input is not available. It will
1630 return -1 if an error occurs.
1632 Here is a simple example that reads keys from the terminal until one
1633 presses Ctrl-G or until 5 seconds have gone by with no input:
1655 int abort_char = 7; /* For MSDOS, use 34 as scan code */
1658 if (-1 == SLang_init_tty (abort_char, 0, 1))
1660 fprintf (stderr, "Unable to initialize the terminal.\n");
1663 SLang_set_abort_signal (NULL);
1666 fputs ("\nPress any key. To quit, press Ctrl-G: ", stdout);
1668 if (SLang_input_pending (50) == 0) /* 50/10 seconds */
1670 fputs ("Waited too long! Bye\n", stdout);
1674 ch = SLang_getkey ();
1675 if (SLang_Error == USER_BREAK)
1677 fputs ("Ctrl-G pressed! Bye\n", stdout);
1680 putc ((int) ch, stdout);
1692 4.6. Reading Keyboard Input with SLkp_getkey
1696 Unlike the low-level function SLang_getkey, the SLkp_getkey function
1697 can read a multi-character sequence associated with function keys.
1698 The SLkp_getkey function uses SLang_getkey and S-Lang's keymap
1699 facility to process escape sequences. It returns a single integer
1700 which describes the key that was pressed:
1703 int SLkp_getkey (void);
1708 That is, the SLkp_getkey function simple provides a mapping between
1709 keys and integers. In this context the integers are called keysyms.
1711 For single character input such as generated by the a key on the
1712 keyboard, the function returns the character that was generated, e.g.,
1713 'a'. For single characters, SLkp_getkey will always return an keysym
1714 whose value ranges from 0 to 256. For keys that generate multiple
1715 character sequences, e.g., a function or arrow key, the function
1716 returns an keysym whose value is greater that 256. The actual values
1717 of these keysyms are represented as macros defined in the slang.h
1718 include file. For example, the up arrow key corresponds to the keysym
1719 whose value is SL_KEY_UP.
1721 Since it is possible for the user to enter a character sequence that
1722 does not correspond to any key. If this happens, the special keysym
1723 SL_KEY_ERR will be returned.
1725 Here is an example of how SLkp_getkey may be used by a file viewer:
1728 switch (SLkp_getkey ())
1752 Unlike its lower-level counterpart, SLang_getkey, there do not yet
1753 exist any functions in the library that are capable of ``ungetting''
1754 keysyms. In particular, the SLang_ungetkey function will not work.
1758 4.7. Buffering Input
1762 S-Lang has several functions pushing characters back onto the input
1763 stream to be read again later by SLang_getkey. It should be noted
1764 that none of the above functions are designed to push back keysyms
1765 read by the SLkp_getkey function. These functions are declared as
1769 void SLang_ungetkey (unsigned char ch);
1770 void SLang_ungetkey_string (unsigned char *buf, int buflen);
1771 void SLang_buffer_keystring (unsigned char *buf, int buflen);
1776 SLang_ungetkey is the most simple of the three functions. It takes a
1777 single character a pushes it back on to the input stream. The next
1778 call to SLang_getkey will return this character. This function may be
1779 used to peek at the character to be read by first reading it and then
1783 SLang_ungetkey_string has the same function as SLang_ungetkey except
1784 that it is able to push more than one character back onto the input
1785 stream. Since this function can push back null (ascii 0) characters,
1786 the number of characters to push is required as one of the parameters.
1788 The last of these three functions, SLang_buffer_keystring can handle
1789 more than one charater but unlike the other two, it places the
1790 characters at the end of the keyboard buffer instead of at the
1793 Note that the use of each of these three functions will cause
1794 SLang_input_pending to return right away with a non-zero value.
1796 Finally, the S-Lang keyboard interface includes the function
1797 SLang_flush_input with prototype
1800 void SLang_flush_input (void);
1805 It may be used to discard all input.
1807 Here is a simple example that looks to see what the next key to be
1808 read is if one is available:
1814 if (SLang_input_pending (0) == 0) return -1;
1815 ch = SLang_getkey ();
1816 SLang_ungetkey (ch);
1826 4.8. Global Variables
1829 Although the following S-Lang global variables have already been
1830 mentioned earlier, they are gathered together here for completeness.
1832 int SLang_Ignore_User_Abort; If non-zero, pressing the interrupt
1833 character will not result in SLang_Error being set to USER_BREAK.
1835 volatile int SLKeyBoard_Quit; This variable is set to a non-zero value
1836 when the interrupt character is pressed. If the interrupt character is
1837 pressed when SLang_getkey is called, the interrupt character will be
1838 returned from SLang_getkey.
1840 int SLang_TT_Baud_Rate; On systems which support it, this variable is
1841 set to the value of the terminal's baud rate after the call to
1849 5. Screen Management
1853 The S-Lang library provides two interfaces to terminal independent
1854 routines for manipulating the display on a terminal. The highest
1855 level interface, known as the SLsmg interface is discussed in this
1856 section. It provides high level screen management functions more
1857 manipulating the display in an optimal manner and is similar in spirit
1858 to the curses library. The lowest level interface, or the SLtt
1859 interface, is used by the SLsmg routines to actually perform the task
1860 of writing to the display. This interface is discussed in another
1861 section. Like the keyboard routines, the SLsmg routines are platform
1862 independent and work the same on MSDOS, OS/2, Unix, and VMS.
1864 The screen management, or SLsmg, routines are initialized by function
1865 SLsmg_init_smg. Once initialized, the application uses various SLsmg
1866 functions to write to a virtual display. This does not cause the
1867 physical terminal display to be updated immediately. The physical
1868 display is updated to look like the virtual display only after a call
1869 to the function SLsmg_refresh. Before exiting, the application using
1870 these routines is required to call SLsmg_reset_smg to reset the
1873 The following subsections explore S-Lang's screen management system in
1880 The function SLsmg_init_smg must be called before any other SLsmg
1881 function can be used. It has the simple prototype:
1884 int SLsmg_init_smg (void);
1889 It returns zero if successful or -1 if it cannot allocate space for
1890 the virtual display.
1892 For this routine to properly initialize the virtual display, the
1893 capabilities of the terminal must be known as well as the size of the
1894 physical display. For these reasons, the lower level SLtt routines
1895 come into play. In particular, before the first call to
1896 SLsmg_init_smg, the application is required to call the function
1897 SLtt_get_terminfo before calling SLsmg_init_smg.
1899 The SLtt_get_terminfo function sets the global variables
1900 SLtt_Screen_Rows and SLtt_Screen_Cols to the values appropriate for
1901 the terminal. It does this by calling the SLtt_get_screen_size
1902 function to query the terminal driver for the appropriate values for
1903 these variables. From this point on, it is up to the application to
1904 maintain the correct values for these variables by calling the
1905 SLtt_get_screen_size function whenever the display size changes, e.g.,
1906 in response to a SIGWINCH signal. Finally, if the application is going
1907 to read characters from the keyboard, it is also a good idea to
1908 initialize the keyboard routines at this point as well.
1911 5.2. Resetting SLsmg
1915 Before the program exits or suspends, the function SLsmg_reset_tty
1916 should be called to shutdown the display system. This function has
1920 void SLsmg_reset_smg (void);
1925 This will deallocate any memory allocated for the virtual screen and
1926 reset the terminal's display.
1928 Basically, a program that uses the SLsmg screen management functions
1929 and S-Lang's keyboard interface will look something like:
1935 SLtt_get_terminfo ();
1936 SLang_init_tty (-1, 0, 0);
1949 If this program is compiled and run, all it will do is clear the
1950 screen and position the cursor at the bottom of the display. In the
1951 following sections, other SLsmg functions will be introduced which may
1952 be used to make this simple program do much more.
1955 5.3. Handling Screen Resize Events
1957 The function SLsmg_reinit_smg is designed to be used in conjunction
1960 Under Unix-like operating systems, when the size of the display
1961 changes, the application will be sent a SIGWINCH signal. To properly
1962 handle this signal, the SLsmg routines must be reinitialized to use
1963 the new display size. This may be accomplished by calling
1964 SLtt_get_screen_size to get the new size, followed by SLsmg_reinit_smg
1965 to reinitialize the SLsmg interface to use the new size. Keep in mind
1966 that these routines should not be called from within the signal
1967 handler. The following code illustrates the main ideas involved in
1968 handling such events:
1981 static volatile int Screen_Size_Changed;
1982 static sigwinch_handler (int sig)
1984 Screen_Size_Changed = 1;
1985 SLsignal (SIGWINCH, sigwinch_handler);
1988 int main (int argc, char **argv)
1990 SLsignal (SIGWINCH, sigwinch_handler);
1994 /* Now enter main loop */
1997 if (Screen_Size_Changed)
1999 SLtt_get_screen_size ();
2000 SLsmg_reinit_smg ();
2014 5.4. SLsmg Functions
2018 In the previous sections, functions for initializing and shutting down
2019 the SLsmg routines were discussed. In this section, the rest of the
2020 SLsmg functions are presented. These functions act only on the
2021 virtual display. The physical display is updated when the
2022 SLsmg_refresh function is called and not until that time. This
2023 function has the simple prototype:
2026 void SLsmg_refresh (void);
2032 5.4.1. Positioning the cursor
2035 The SLsmg_gotorc function is used to position the cursor at a given
2036 row and column. The prototype for this function is:
2039 void SLsmg_gotorc (int row, int col);
2044 The origin of the screen is at the top left corner and is given the
2045 coordinate (0, 0), i.e., the top row of the screen corresponds to row
2046 = 0 and the first column corresponds to col = 0. The last row of the
2047 screen is given by row = SLtt_Screen_Rows - 1.
2049 It is possible to change the origin of the coordinate system by using
2050 the function SLsmg_set_screen_start with prototype:
2053 void SLsmg_set_screen_start (int *r, int *c);
2058 This function takes pointers to the new values of the first row and
2059 first column. It returns the previous values by modifying the values
2060 of the integers at the addresses specified by the parameter list. A
2061 NULL pointer may be passed to indicate that the origin is to be set to
2062 its initial value of 0. For example,
2066 SLsmg_set_screen_start (&r, NULL);
2071 sets the origin to (10, 0) and after the function returns, the vari-
2072 able r will have the value of the previous row origin.
2075 5.4.2. Writing to the Display
2078 SLsmg has several routines for outputting text to the virtual display.
2079 The following points should be understood:
2081 o The text is output at the position of the cursor of the virtual
2082 display and the cursor is advanced to the position that corresponds
2083 to the end of the text.
2086 o Text does not wrap at the boundary of the display--- it is
2087 trucated. This behavior seems to be more useful in practice since
2088 most programs that would use screen management tend to be line
2092 o Control characters are displayed in a two character sequence
2093 representation with ^ as the first character. That is, Ctrl-X is
2097 o The newline character does not cause the cursor to advance to the
2098 next row. Instead, when a newline character is encountered when
2099 outputting text, the output routine will return. That is,
2100 outputting a string containing a newline character will only
2101 display the contents of the string up to the newline character.
2104 Although the some of the above items might appear to be too
2105 restrictive, in practice this is not seem to be the case. In fact,
2106 the design of the output routines was influenced by their actual use
2107 and modified to simplify the code of the application utilizing them.
2109 void SLsmg_write_char (char ch); Write a single character to the
2113 void SLsmg_write_nchars (char *str, int len); Write len characters
2114 pointed to by str to the virtual display.
2116 void SLsmg_write_string (char *str); Write the null terminated string
2117 given by pointer str to the virtual display. This function is a
2118 wrapper around SLsmg_write_nchars.
2120 void SLsmg_write_nstring (char *str, int n); Write the null terminated
2121 string given by pointer str to the virtual display. At most, only n
2122 characters are written. If the length of the string is less than n,
2123 then the string will be padded with blanks. This function is a
2124 wrapper around SLsmg_write_nchars.
2126 void SLsmg_printf (char *fmt, ...); This function is similar to printf
2127 except that it writes to the SLsmg virtual display.
2129 void SLsmg_vprintf (char *, va_list); Like SLsmg_printf but uses a
2130 variable argument list.
2133 5.4.3. Erasing the Display
2136 The following functions may be used to fill portions of the display
2137 with blank characters. The attributes of blank character are the
2138 current attributes. (See below for a discussion of character
2141 void SLsmg_erase_eol (void); Erase line from current position to the
2144 void SLsmg_erase_eos (void); Erase from the current position to the
2147 void SLsmg_cls (void); Clear the entire virtual display.
2150 5.4.4. Setting Character Attributes
2153 Character attributes define the visual characteristics the character
2154 possesses when it is displayed. Visual characteristics include the
2155 foreground and background colors as well as other attributes such as
2156 blinking, bold, and so on. Since SLsmg takes a different approach to
2157 this problem than other screen management libraries an explanation of
2158 this approach is given here. This approach has been motivated by
2159 experience with programs that require some sort of screen management.
2161 Most programs that use SLsmg are composed of specific textual objects
2162 or objects made up of line drawing characters. For example, consider
2163 an application with a menu bar with drop down menus. The menus might
2164 be enclosed by some sort of frame or perhaps a shadow. The basic idea
2165 is to associate an integer to each of the objects (e.g., menu bar,
2166 shadow, current menu item, etc.) and create a mapping from the integer
2167 to the set of attributes. In the terminology of SLsmg, the integer is
2168 simply called an object.
2170 For example, the menu bar might be associated with the object 1, the
2171 drop down menu could be object 2, the shadow could be object 3, and so
2174 The range of values for the object integer is restricted from 0 up to
2175 and including 255 on all systems except MSDOS where the maximum
2176 allowed integer is 15 (-- This difference is due to memory constraints
2177 imposed by MSDOS. This restriction might be removed in a future
2178 version of the library.--) . The object numbered zero should not be
2179 regarding as an object at all. Rather it should be regarded as all
2180 other objects that have not explicitly been given an object number.
2181 SLsmg, or more precisely SLtt, refers to the attributes of this
2182 special object as the default or normal attributes.
2184 The SLsmg routines know nothing about the mapping of the color to the
2185 attributes associated with the color. The actual mapping takes place
2186 at a lower level in the SLtt routines. Hence, to map an object to the
2187 actual set of attributes requires a call to any of the following SLtt
2191 void SLtt_set_color (int obj, char *name, char *fg, char *bg);
2192 void SLtt_set_color_object (int obj, SLtt_Char_Type attr);
2193 void SLtt_set_mono (int obj, char *, SLtt_Char_Type attr);
2198 Only the first of these routines will be discussed briefly here. The
2199 latter two functions allow more fine control over the object to
2200 attribute mapping (such as assigning a ``blink'' attribute to the
2201 object). For a more full explanation on all of these routines see the
2202 section about the SLtt interface.
2204 The SLtt_set_color function takes four parameters. The first
2205 parameter, obj, is simply the integer of the object for which
2206 attributes are to be assigned. The second parameter is currently
2207 unused by these routines. The third and forth parameters, fg and bg,
2208 are the names of the foreground and background color to be used
2209 associated with the object. The strings that one can use for the
2210 third and fourth parameters can be any one of the 16 colors:
2215 "green" "brightgreen"
2218 "magenta" "brightmagenta"
2225 The value of the foreground parameter fg can be anyone of these six-
2226 teen colors. However, on most terminals, the background color will
2227 can only be one of the colors listed in the first column (-- This is
2228 also true on the Linux console. However, it need not be the case and
2229 hopefully the designers of Linux will someday remove this restric-
2232 Of course not all terminals are color terminals. If the S-Lang global
2233 variable SLtt_Use_Ansi_Colors is non-zero, the terminal is assumed to
2234 be a color terminal. The SLtt_get_terminfo will try to determine
2235 whether or not the terminal supports colors and set this variable
2236 accordingly. It does this by looking for the capability in the
2237 terminfo/termcap database. Unfortunately many Unix databases lack
2238 this information and so the SLtt_get_terminfo routine will check
2239 whether or not the environment variable COLORTERM exists. If it
2240 exists, the terminal will be assumed to support ANSI colors and
2241 SLtt_Use_Ansi_Colors will be set to one. Nevertheless, the
2242 application should provide some other mechanism to set this variable,
2243 e.g., via a command line parameter.
2245 When the SLtt_Use_Ansi_Colors variable is zero, all objects with
2246 numbers greater than one will be displayed in inverse video (-- This
2247 behavior can be modified by using the SLtt_set_mono function call.--)
2250 With this background, the SLsmg functions for setting the character
2251 attributes can now be defined. These functions simply set the object
2252 attributes that are to be assigned to subsequent characters written to
2253 the virtual display. For this reason, the new attribute is called the
2256 void SLsmg_set_color (int obj); Set the current attribute to those of
2259 void SLsmg_normal_video (void); This function is equivalent to
2260 SLsmg_set_color (0).
2262 void SLsmg_reverse_video (void); This function is equivalent to
2263 SLsmg_set_color (1). On monochrome terminals, it is equivalent to
2264 setting the subsequent character attributes to inverse video.
2266 Unfortunately there does not seem to be a standard way for the
2267 application or, in particular, the library to determine which color
2268 will be used by the terminal for the default background. Such
2269 information would be useful in initializing the foreground and
2270 background colors associated with the default color object (0). FOr
2271 this reason, it is up to the application to provide some means for the
2272 user to indicate what these colors are for the particular terminal
2273 setup. To facilitate this, the SLtt_get_terminfo function checks for
2274 the existence of the COLORFGBG environment variable. If this variable
2275 exists, its value will be used to initialize the colors associated
2276 with the default color object. Specifically, the value is assumed to
2277 consist of a foreground color name and a background color name
2278 separated by a semicolon. For example, if the value of COLORTERM is
2279 lightgray;blue, the default color object will be initialized to
2280 represent a lightgray foreground upon a blue background.
2283 5.4.5. Lines and Alternate Character Sets
2285 The S-Lang screen management library also includes routines for
2286 turning on and turning off alternate character sets. This is
2287 especially useful for drawing horizontal and vertical lines.
2289 void SLsmg_set_char_set (int flag); If flag is non-zero, subsequent
2290 write functions will use characters from the alternate character set.
2291 If flag is zero, the default, or, ordinary character set will be used.
2293 void SLsmg_draw_hline (int len); Draw a horizontal line from the
2294 current position to the column that is len characters to the right.
2296 void SLsmg_draw_vline (int len); Draw a horizontal line from the
2297 current position to the row that is len rows below.
2299 void SLsmg_draw_box (int r, int c, int dr, int dc); Draw a box whose
2300 upper right corner is at row r and column c. The box spans dr rows
2301 and dc columns. The current position will be left at row r and column
2305 5.4.6. Miscellaneous Functions
2308 void SLsmg_touch_lines (int r, int n); Mark screen rows numbered r, r
2309 + 1, ... r + (n - 1) as modified. When SLsmg_refresh is called, these
2310 rows will be completely redrawn.
2311 unsigned short SLsmg_char_at(void); Returns the character and its
2312 attributes object number at the current cursor position. The
2313 character itself occupies the lower byte and the object attributes
2314 number forms the upper byte. The object returned by this function
2315 call should not be written back out via any of the functions that
2316 write characters or character strings.
2325 The following S-Lang global variables are used by the SLsmg interface.
2326 Some of these have been previously discussed.
2328 int SLtt_Screen_Rows; int SLtt_Screen_Cols; The number of rows and
2329 columns of the physical display. If either of these numbers changes,
2330 the functions SLsmg_reset_smg and SLsmg_init_smg should be called
2331 again so that the SLsmg routines can re-adjust to the new size.
2333 int SLsmg_Tab_Width; Set this variable to the tab width that will be
2334 used when expanding tab characters. The default is 8.
2336 int SLsmg_Display_Eight_Bit This variable determines how characters
2337 with the high bit set are to be output. Specifically, a character
2338 with the high bit set with a value greater than or equal to this value
2339 is output as is; otherwise, it will be output in a 7-bit
2340 representation. The default value for this variable is 128 for MSDOS
2341 and 160 for other systems (ISO-Latin).
2343 int SLtt_Use_Ansi_Colors; If this value is non-zero, the terminal is
2344 assumed to support ANSI colors otherwise it is assumed to be
2345 monochrome. The default is 0.
2347 int SLtt_Term_Cannot_Scroll; If this value is zero, the SLsmg will
2348 attempt to scroll the physical display to optimize the update. If it
2349 is non-zero, the screen management routines will not perform this
2350 optimization. For some applications, this variable should be set to
2351 zero. The default value is set by the SLtt_get_terminfo function.
2355 5.6. Hints for using SLsmg
2358 This section discusses some general design issues that one must face
2359 when writing an application that requires some sort of screen
2381 Almost all non-trivial programs must worry about signals. This is
2382 especially true for programs that use the S-Lang terminal input/output
2383 and screen management routines. Unfortunately, there is no fixed way
2384 to handle signals; otherwise, the Unix kernel would take care of all
2385 issues regarding signals and the application programmer would never
2386 have to worry about them. For this reason, none of the routines in
2387 the S-Lang library catch signals; however, some of the routines block
2388 the delivery of signals during crucial moments. It is up to the
2389 application programmer to install handlers for the various signals of
2392 For the interpreter, the most important signal to worry about is
2393 SIGINT. This signal is usually generated when the user presses Ctrl-C
2394 at the keyboard. The interpreter checks the value of the SLang_Error
2395 variable to determine whether or not it should abort the interpreting
2396 process and return control back to the application. This means that
2397 if SIGINT is to be used to abort the interpreter, a signal handler for
2398 SIGINT should be installed. The handler should set the value of
2399 SLang_Error to SL_USER_BREAK.
2401 Applications that use the tty getkey routines or the screen management
2402 routines must worry about about signals such as:
2408 SIGTTOU background write
2409 SIGTTIN background read
2410 SIGWINCH window resize
2415 It is important that handlers be established for these signals while
2416 the either the SLsmg routines or the getkey routines are initialized.
2417 The SLang_init_tty, SLang_reset_tty, SLsmg_init_smg, and
2418 SLsmg_reset_smg functions block these signals from occuring while they
2421 Since a signal can be delivered at any time, it is important for the
2422 signal handler to call only functions that can be called from a signal
2423 handler. This usually means that such function must be re-entrant. In
2424 particular, the SLsmg routines are not re-entrant; hence, they should
2425 not be called when a signal is being processed unless the application
2426 can ensure that the signal was not delivered while an SLsmg function
2427 was called. This statement applies to many other functions such as
2428 malloc, or, more generally, any function that calls malloc. The
2429 upshot is that the signal handler should not attempt to do too much
2430 except set a global variable for the application to look at while not
2431 in a signal handler.
2433 The S-Lang library provides two functions for blocking and unblocking
2437 int SLsig_block_signals (void);
2438 int SLsig_unblock_signals (void);
2443 It should be noted that for every call to SLsig_block_signals, a cor-
2444 responding call should be made to SLsig_unblock_signals, e.g.,
2447 void update_screen ()
2449 SLsig_block_signals ();
2451 /* Call SLsmg functions */
2454 SLsig_unblock_signals ();
2460 See demo/pager.c for examples.
2509 7. Searching Functions
2513 The S-Lang library incorporates two types of searches: Regular
2514 expression pattern matching and ordinary searching.
2517 7.1. Regular Expressions
2521 !!! No documentation available yet !!!
2525 7.2. Simple Searches
2528 The routines for ordinary searching are defined in the slsearch.c
2529 file. To use these routines, simply include "slang.h" in your program
2530 and simply call the appropriate routines.
2532 The searches can go in either a forward or backward direction and can
2533 either be case or case insensitive. The region that is searched may
2534 contain null characters (ASCII 0) however, the search string cannot in
2535 the current implementation. In addition the length of the string to
2536 be found is currently limited to 256 characters.
2538 Before searching, the function SLsearch_init must first be called to
2539 `preprocess' the search string.
2546 The function SLsearch_init must be called before a search can take
2547 place. Its prototype is:
2550 int SLsearch_init (char *key, int dir, int case_sens, SLsearch_Type *st);
2555 Here key is the string to be searched for. dir specifies the direc-
2556 tion of the search: a value greater than zero is used for searching
2557 forward and a value less than zero is used for searching backward.
2558 The parameter case_sens specifies whether the search is case sensitive
2559 or not. A non-zero value indicates that case is important. st is a
2560 pointer to a structure of type SLsearch_Type defined in "slang.h".
2561 This structure is initialized by this routine and must be passed to
2562 SLsearch when the search is actually performed.
2564 This routine returns the length of the string to be searched for.
2575 Prototype: unsigned char *SLsearch (unsigned char *pmin,
2576 unsigned char *pmax,
2582 This function performs the search defined by a previous call to
2583 SLsearch_init over a region specified by the pointers pmin and pmax.
2585 It returns a pointer to the start of the match if successful or it
2586 will return NULL if a match was not found.
2643 The S-Lang library is distributed under two copyrights: the GNU Genral
2644 Public License, and the Artistic License. Any program that uses the
2645 interpreter must adhere to rules of one of these licenses.
2648 H.1. The GNU Public License
2652 GNU GENERAL PUBLIC LICENSE
2653 Version 2, June 1991
2655 Copyright (C) 1989, 1991 Free Software Foundation, Inc.
2656 675 Mass Ave, Cambridge, MA 02139, USA
2657 Everyone is permitted to copy and distribute verbatim copies
2658 of this license document, but changing it is not allowed.
2665 The licenses for most software are designed to take away your freedom
2666 to share and change it. By contrast, the GNU General Public License
2667 is intended to guarantee your freedom to share and change free soft-
2668 ware--to make sure the software is free for all its users. This Gen-
2669 eral Public License applies to most of the Free Software Foundation's
2670 software and to any other program whose authors commit to using it.
2671 (Some other Free Software Foundation software is covered by the GNU
2672 Library General Public License instead.) You can apply it to your
2675 When we speak of free software, we are referring to freedom, not
2676 price. Our General Public Licenses are designed to make sure that you
2677 have the freedom to distribute copies of free software (and charge for
2678 this service if you wish), that you receive source code or can get it
2679 if you want it, that you can change the software or use pieces of it
2680 in new free programs; and that you know you can do these things.
2682 To protect your rights, we need to make restrictions that forbid
2683 anyone to deny you these rights or to ask you to surrender the rights.
2684 These restrictions translate to certain responsibilities for you if
2685 you distribute copies of the software, or if you modify it.
2687 For example, if you distribute copies of such a program, whether
2688 gratis or for a fee, you must give the recipients all the rights that
2689 you have. You must make sure that they, too, receive or can get the
2690 source code. And you must show them these terms so they know their
2693 We protect your rights with two steps: (1) copyright the software, and
2694 (2) offer you this license which gives you legal permission to copy,
2695 distribute and/or modify the software.
2697 Also, for each author's protection and ours, we want to make certain
2698 that everyone understands that there is no warranty for this free
2699 software. If the software is modified by someone else and passed on,
2700 we want its recipients to know that what they have is not the
2701 original, so that any problems introduced by others will not reflect
2702 on the original authors' reputations.
2704 Finally, any free program is threatened constantly by software
2705 patents. We wish to avoid the danger that redistributors of a free
2706 program will individually obtain patent licenses, in effect making the
2707 program proprietary. To prevent this, we have made it clear that any
2708 patent must be licensed for everyone's free use or not licensed at
2711 The precise terms and conditions for copying, distribution and
2712 modification follow.
2715 GNU GENERAL PUBLIC LICENSE
2716 TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
2721 0. This License applies to any program or other work which contains a
2722 notice placed by the copyright holder saying it may be distributed
2723 under the terms of this General Public License. The "Program", below,
2724 refers to any such program or work, and a "work based on the Program"
2725 means either the Program or any derivative work under copyright law:
2726 that is to say, a work containing the Program or a portion of it,
2727 either verbatim or with modifications and/or translated into another
2728 language. (Hereinafter, translation is included without limitation in
2729 the term "modification".) Each licensee is addressed as "you".
2731 Activities other than copying, distribution and modification are not
2732 covered by this License; they are outside its scope. The act of
2733 running the Program is not restricted, and the output from the Program
2734 is covered only if its contents constitute a work based on the Program
2735 (independent of having been made by running the Program). Whether
2736 that is true depends on what the Program does.
2738 1. You may copy and distribute verbatim copies of the Program's source
2739 code as you receive it, in any medium, provided that you conspicuously
2740 and appropriately publish on each copy an appropriate copyright notice
2741 and disclaimer of warranty; keep intact all the notices that refer to
2742 this License and to the absence of any warranty; and give any other
2743 recipients of the Program a copy of this License along with the
2746 You may charge a fee for the physical act of transferring a copy, and
2747 you may at your option offer warranty protection in exchange for a
2750 2. You may modify your copy or copies of the Program or any portion of
2751 it, thus forming a work based on the Program, and copy and distribute
2752 such modifications or work under the terms of Section 1 above,
2753 provided that you also meet all of these conditions:
2773 a) You must cause the modified files to carry prominent notices
2774 stating that you changed the files and the date of any change.
2776 b) You must cause any work that you distribute or publish, that in
2777 whole or in part contains or is derived from the Program or any
2778 part thereof, to be licensed as a whole at no charge to all third
2779 parties under the terms of this License.
2781 c) If the modified program normally reads commands interactively
2782 when run, you must cause it, when started running for such
2783 interactive use in the most ordinary way, to print or display an
2784 announcement including an appropriate copyright notice and a
2785 notice that there is no warranty (or else, saying that you provide
2786 a warranty) and that users may redistribute the program under
2787 these conditions, and telling the user how to view a copy of this
2788 License. (Exception: if the Program itself is interactive but
2789 does not normally print such an announcement, your work based on
2790 the Program is not required to print an announcement.)
2795 These requirements apply to the modified work as a whole. If identi-
2796 fiable sections of that work are not derived from the Program, and can
2797 be reasonably considered independent and separate works in themselves,
2798 then this License, and its terms, do not apply to those sections when
2799 you distribute them as separate works. But when you distribute the
2800 same sections as part of a whole which is a work based on the Program,
2801 the distribution of the whole must be on the terms of this License,
2802 whose permissions for other licensees extend to the entire whole, and
2803 thus to each and every part regardless of who wrote it.
2805 Thus, it is not the intent of this section to claim rights or contest
2806 your rights to work written entirely by you; rather, the intent is to
2807 exercise the right to control the distribution of derivative or
2808 collective works based on the Program.
2810 In addition, mere aggregation of another work not based on the Program
2811 with the Program (or with a work based on the Program) on a volume of
2812 a storage or distribution medium does not bring the other work under
2813 the scope of this License.
2815 3. You may copy and distribute the Program (or a work based on it,
2816 under Section 2) in object code or executable form under the terms of
2817 Sections 1 and 2 above provided that you also do one of the following:
2820 a) Accompany it with the complete corresponding machine-readable
2821 source code, which must be distributed under the terms of Sections
2822 1 and 2 above on a medium customarily used for software interchange; or,
2824 b) Accompany it with a written offer, valid for at least three
2825 years, to give any third party, for a charge no more than your
2826 cost of physically performing source distribution, a complete
2827 machine-readable copy of the corresponding source code, to be
2828 distributed under the terms of Sections 1 and 2 above on a medium
2829 customarily used for software interchange; or,
2831 c) Accompany it with the information you received as to the offer
2832 to distribute corresponding source code. (This alternative is
2833 allowed only for noncommercial distribution and only if you
2834 received the program in object code or executable form with such
2835 an offer, in accord with Subsection b above.)
2839 The source code for a work means the preferred form of the work for
2840 making modifications to it. For an executable work, complete source
2841 code means all the source code for all modules it contains, plus any
2842 associated interface definition files, plus the scripts used to con-
2843 trol compilation and installation of the executable. However, as a
2844 special exception, the source code distributed need not include any-
2845 thing that is normally distributed (in either source or binary form)
2846 with the major components (compiler, kernel, and so on) of the operat-
2847 ing system on which the executable runs, unless that component itself
2848 accompanies the executable.
2850 If distribution of executable or object code is made by offering
2851 access to copy from a designated place, then offering equivalent
2852 access to copy the source code from the same place counts as
2853 distribution of the source code, even though third parties are not
2854 compelled to copy the source along with the object code.
2856 4. You may not copy, modify, sublicense, or distribute the Program
2857 except as expressly provided under this License. Any attempt
2858 otherwise to copy, modify, sublicense or distribute the Program is
2859 void, and will automatically terminate your rights under this License.
2860 However, parties who have received copies, or rights, from you under
2861 this License will not have their licenses terminated so long as such
2862 parties remain in full compliance.
2864 5. You are not required to accept this License, since you have not
2865 signed it. However, nothing else grants you permission to modify or
2866 distribute the Program or its derivative works. These actions are
2867 prohibited by law if you do not accept this License. Therefore, by
2868 modifying or distributing the Program (or any work based on the
2869 Program), you indicate your acceptance of this License to do so, and
2870 all its terms and conditions for copying, distributing or modifying
2871 the Program or works based on it.
2873 6. Each time you redistribute the Program (or any work based on the
2874 Program), the recipient automatically receives a license from the
2875 original licensor to copy, distribute or modify the Program subject to
2876 these terms and conditions. You may not impose any further
2877 restrictions on the recipients' exercise of the rights granted herein.
2878 You are not responsible for enforcing compliance by third parties to
2881 7. If, as a consequence of a court judgment or allegation of patent
2882 infringement or for any other reason (not limited to patent issues),
2883 conditions are imposed on you (whether by court order, agreement or
2884 otherwise) that contradict the conditions of this License, they do not
2885 excuse you from the conditions of this License. If you cannot
2886 distribute so as to satisfy simultaneously your obligations under this
2887 License and any other pertinent obligations, then as a consequence you
2888 may not distribute the Program at all. For example, if a patent
2889 license would not permit royalty-free redistribution of the Program by
2890 all those who receive copies directly or indirectly through you, then
2891 the only way you could satisfy both it and this License would be to
2892 refrain entirely from distribution of the Program.
2894 If any portion of this section is held invalid or unenforceable under
2895 any particular circumstance, the balance of the section is intended to
2896 apply and the section as a whole is intended to apply in other
2899 It is not the purpose of this section to induce you to infringe any
2900 patents or other property right claims or to contest validity of any
2901 such claims; this section has the sole purpose of protecting the
2902 integrity of the free software distribution system, which is
2903 implemented by public license practices. Many people have made
2904 generous contributions to the wide range of software distributed
2905 through that system in reliance on consistent application of that
2906 system; it is up to the author/donor to decide if he or she is willing
2907 to distribute software through any other system and a licensee cannot
2910 This section is intended to make thoroughly clear what is believed to
2911 be a consequence of the rest of this License.
2913 8. If the distribution and/or use of the Program is restricted in
2914 certain countries either by patents or by copyrighted interfaces, the
2915 original copyright holder who places the Program under this License
2916 may add an explicit geographical distribution limitation excluding
2917 those countries, so that distribution is permitted only in or among
2918 countries not thus excluded. In such case, this License incorporates
2919 the limitation as if written in the body of this License.
2921 9. The Free Software Foundation may publish revised and/or new
2922 versions of the General Public License from time to time. Such new
2923 versions will be similar in spirit to the present version, but may
2924 differ in detail to address new problems or concerns.
2926 Each version is given a distinguishing version number. If the Program
2927 specifies a version number of this License which applies to it and
2928 "any later version", you have the option of following the terms and
2929 conditions either of that version or of any later version published by
2930 the Free Software Foundation. If the Program does not specify a
2931 version number of this License, you may choose any version ever
2932 published by the Free Software Foundation.
2934 10. If you wish to incorporate parts of the Program into other free
2935 programs whose distribution conditions are different, write to the
2936 author to ask for permission. For software which is copyrighted by
2937 the Free Software Foundation, write to the Free Software Foundation;
2938 we sometimes make exceptions for this. Our decision will be guided by
2939 the two goals of preserving the free status of all derivatives of our
2940 free software and of promoting the sharing and reuse of software
2946 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY
2947 FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN
2948 OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES
2949 PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED
2950 OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
2951 MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS
2952 TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE
2953 PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING,
2954 REPAIR OR CORRECTION.
2956 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
2957 WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR
2958 REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES,
2959 INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING
2960 OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED
2961 TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY
2962 YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER
2963 PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE
2964 POSSIBILITY OF SUCH DAMAGES.
2966 END OF TERMS AND CONDITIONS
2971 Appendix: How to Apply These Terms to Your New Programs
2973 If you develop a new program, and you want it to be of the greatest
2974 possible use to the public, the best way to achieve this is to make it
2975 free software which everyone can redistribute and change under these
2978 To do so, attach the following notices to the program. It is safest
2979 to attach them to the start of each source file to most effectively
2980 convey the exclusion of warranty; and each file should have at least
2981 the "copyright" line and a pointer to where the full notice is found.
2984 <one line to give the program's name and a brief idea of what it does.>
2985 Copyright (C) 19yy <name of author>
2987 This program is free software; you can redistribute it and/or modify
2988 it under the terms of the GNU General Public License as published by
2989 the Free Software Foundation; either version 2 of the License, or
2990 (at your option) any later version.
2992 This program is distributed in the hope that it will be useful,
2993 but WITHOUT ANY WARRANTY; without even the implied warranty of
2994 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2995 GNU General Public License for more details.
2997 You should have received a copy of the GNU General Public License
2998 along with this program; if not, write to the Free Software
2999 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
3004 Also add information on how to contact you by electronic and paper
3007 If the program is interactive, make it output a short notice like this
3008 when it starts in an interactive mode:
3011 Gnomovision version 69, Copyright (C) 19yy name of author
3012 Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
3013 This is free software, and you are welcome to redistribute it
3014 under certain conditions; type `show c' for details.
3019 The hypothetical commands `show w' and `show c' should show the appro-
3020 priate parts of the General Public License. Of course, the commands
3021 you use may be called something other than `show w' and `show c'; they
3022 could even be mouse-clicks or menu items--whatever suits your program.
3024 You should also get your employer (if you work as a programmer) or
3025 your school, if any, to sign a "copyright disclaimer" for the program,
3026 if necessary. Here is a sample; alter the names:
3029 Yoyodyne, Inc., hereby disclaims all copyright interest in the program
3030 `Gnomovision' (which makes passes at compilers) written by James Hacker.
3032 <signature of Ty Coon>, 1 April 1989
3033 Ty Coon, President of Vice
3037 This General Public License does not permit incorporating your program
3038 into proprietary programs. If your program is a subroutine library,
3039 you may consider it more useful to permit linking proprietary applica-
3040 tions with the library. If this is what you want to do, use the GNU
3041 Library General Public License instead of this License.
3044 H.2. The Artistic License
3048 The "Artistic License"
3055 The intent of this document is to state the conditions under which a
3056 Package may be copied, such that the Copyright Holder maintains some
3057 semblance of artistic control over the development of the package,
3058 while giving the users of the package the right to use and distribute
3059 the Package in a more-or-less customary fashion, plus the right to
3060 make reasonable modifications.
3065 "Package" refers to the collection of files distributed by the
3066 Copyright Holder, and derivatives of that collection of files
3067 created through textual modification.
3069 "Standard Version" refers to such a Package if it has not been
3070 modified, or has been modified in accordance with the wishes
3071 of the Copyright Holder as specified below.
3073 "Copyright Holder" is whoever is named in the copyright or
3074 copyrights for the package.
3076 "You" is you, if you're thinking about copying or distributing
3079 "Reasonable copying fee" is whatever you can justify on the
3080 basis of media cost, duplication charges, time of people involved,
3081 and so on. (You will not be required to justify it to the
3082 Copyright Holder, but only to the computing community at large
3083 as a market that must bear the fee.)
3085 "Freely Available" means that no fee is charged for the item
3086 itself, though there may be fees involved in handling the item.
3087 It also means that recipients of the item may redistribute it
3088 under the same conditions they received it.
3093 1. You may make and give away verbatim copies of the source form of
3094 the Standard Version of this Package without restriction, provided
3095 that you duplicate all of the original copyright notices and associ-
3098 2. You may apply bug fixes, portability fixes and other modifications
3099 derived from the Public Domain or from the Copyright Holder. A
3100 Package modified in such a way shall still be considered the Standard
3103 3. You may otherwise modify your copy of this Package in any way,
3104 provided that you insert a prominent notice in each changed file
3105 stating how and when you changed that file, and provided that you do
3106 at least ONE of the following:
3109 a) place your modifications in the Public Domain or otherwise make them
3110 Freely Available, such as by posting said modifications to Usenet or
3111 an equivalent medium, or placing the modifications on a major archive
3112 site such as uunet.uu.net, or by allowing the Copyright Holder to include
3113 your modifications in the Standard Version of the Package.
3115 b) use the modified Package only within your corporation or organization.
3117 c) rename any non-standard executables so the names do not conflict
3118 with standard executables, which must also be provided, and provide
3119 a separate manual page for each non-standard executable that clearly
3120 documents how it differs from the Standard Version.
3122 d) make other distribution arrangements with the Copyright Holder.
3127 4. You may distribute the programs of this Package in object code or
3128 executable form, provided that you do at least ONE of the following:
3131 a) distribute a Standard Version of the executables and library files,
3132 together with instructions (in the manual page or equivalent) on where
3133 to get the Standard Version.
3135 b) accompany the distribution with the machine-readable source of
3136 the Package with your modifications.
3138 c) give non-standard executables non-standard names, and clearly
3139 document the differences in manual pages (or equivalent), together
3140 with instructions on where to get the Standard Version.
3142 d) make other distribution arrangements with the Copyright Holder.
3147 5. You may charge a reasonable copying fee for any distribution of
3148 this Package. You may charge any fee you choose for support of this
3149 Package. You may not charge a fee for this Package itself. However,
3150 you may distribute this Package in aggregate with other (possibly com-
3151 mercial) programs as part of a larger (possibly commercial) software
3152 distribution provided that you do not advertise this Package as a
3153 product of your own. You may embed this Package's interpreter within
3154 an executable of yours (by linking); this shall be construed as a mere
3155 form of aggregation, provided that the complete Standard Version of
3156 the interpreter is so embedded.
3158 6. The scripts and library files supplied as input to or produced as
3159 output from the programs of this Package do not automatically fall
3160 under the copyright of this Package, but belong to whomever generated
3161 them, and may be sold commercially, and may be aggregated with this
3162 Package. If such scripts or library files are aggregated with this
3163 Package via the so-called "undump" or "unexec" methods of producing a
3164 binary executable image, then distribution of such an image shall
3165 neither be construed as a distribution of this Package nor shall it
3166 fall under the restrictions of Paragraphs 3 and 4, provided that you
3167 do not represent such an executable image as a Standard Version of
3169 7. C subroutines (or comparably compiled subroutines in other
3170 languages) supplied by you and linked into this Package in order to
3171 emulate subroutines and variables of the language defined by this
3172 Package shall not be considered part of this Package, but are the
3173 equivalent of input as in Paragraph 6, provided these subroutines do
3174 not change the language in any way that would cause it to fail the
3175 regression tests for the language.
3177 8. Aggregation of this Package with a commercial distribution is
3178 always permitted provided that the use of this Package is embedded;
3179 that is, when no overt attempt is made to make this Package's
3180 interfaces visible to the end user of the commercial distribution.
3181 Such use shall not be construed as a distribution of this Package.
3183 9. The name of the Copyright Holder may not be used to endorse or
3184 promote products derived from this software without specific prior
3187 10. THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
3188 IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
3189 WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
3238 1. Preface . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
3239 1.1. A Brief History of S-Lang . . . . . . . . . . . . . . . . . . 4
3240 1.2. Acknowledgements . . . . . . . . . . . . . . . . . . . . . . 4
3241 2. Introduction . . . . . . . . . . . . . . . . . . . . . . . . . 6
3242 3. Interpreter Interface . . . . . . . . . . . . . . . . . . . . . 7
3243 3.1. Embedding the Interpreter . . . . . . . . . . . . . . . . . . 7
3244 3.2. Calling the Interpreter . . . . . . . . . . . . . . . . . . . 8
3245 3.3. Intrinsic Functions . . . . . . . . . . . . . . . . . . . . . 8
3246 3.3.1. Restrictions on Intrinsic Functions . . . . . . . . . . . . 9
3247 3.3.2. Adding a New Intrinsic . . . . . . . . . . . . . . . . . . 10
3248 3.3.3. More Complicated Intrinsics . . . . . . . . . . . . . . . . 11
3249 3.4. Intrinsic Variables . . . . . . . . . . . . . . . . . . . . . 13
3250 3.5. Aggregate Data Objects . . . . . . . . . . . . . . . . . . . 15
3251 3.5.1. Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3252 3.5.2. Structures . . . . . . . . . . . . . . . . . . . . . . . . 18
3253 3.5.2.1. Interpreter Structures . . . . . . . . . . . . . . . . . 18
3254 3.5.2.2. Intrinsic Structures . . . . . . . . . . . . . . . . . . 19
3255 4. Keyboard Interface . . . . . . . . . . . . . . . . . . . . . . 22
3256 4.1. Initializing the Keyboard Interface . . . . . . . . . . . . . 22
3257 4.2. Resetting the Keyboard Interface . . . . . . . . . . . . . . 23
3258 4.3. Initializing the SLkp Routines . . . . . . . . . . . . . . . 23
3259 4.4. Setting the Interrupt Handler . . . . . . . . . . . . . . . . 24
3260 4.5. Reading Keyboard Input with SLang_getkey . . . . . . . . . . 25
3261 4.6. Reading Keyboard Input with SLkp_getkey . . . . . . . . . . . 26
3262 4.7. Buffering Input . . . . . . . . . . . . . . . . . . . . . . . 27
3263 4.8. Global Variables . . . . . . . . . . . . . . . . . . . . . . 28
3264 5. Screen Management . . . . . . . . . . . . . . . . . . . . . . . 29
3265 5.1. Initialization . . . . . . . . . . . . . . . . . . . . . . . 29
3266 5.2. Resetting SLsmg . . . . . . . . . . . . . . . . . . . . . . . 29
3267 5.3. Handling Screen Resize Events . . . . . . . . . . . . . . . . 30
3268 5.4. SLsmg Functions . . . . . . . . . . . . . . . . . . . . . . . 31
3269 5.4.1. Positioning the cursor . . . . . . . . . . . . . . . . . . 31
3270 5.4.2. Writing to the Display . . . . . . . . . . . . . . . . . . 32
3271 5.4.3. Erasing the Display . . . . . . . . . . . . . . . . . . . . 33
3272 5.4.4. Setting Character Attributes . . . . . . . . . . . . . . . 33
3273 5.4.5. Lines and Alternate Character Sets . . . . . . . . . . . . 35
3274 5.4.6. Miscellaneous Functions . . . . . . . . . . . . . . . . . . 35
3275 5.5. Variables . . . . . . . . . . . . . . . . . . . . . . . . . . 36
3276 5.6. Hints for using SLsmg . . . . . . . . . . . . . . . . . . . . 36
3277 6. Signal Functions . . . . . . . . . . . . . . . . . . . . . . . 37
3278 7. Searching Functions . . . . . . . . . . . . . . . . . . . . . . 39
3279 7.1. Regular Expressions . . . . . . . . . . . . . . . . . . . . . 39
3280 7.2. Simple Searches . . . . . . . . . . . . . . . . . . . . . . . 39
3281 7.3. Initialization . . . . . . . . . . . . . . . . . . . . . . . 39
3282 7.4. SLsearch . . . . . . . . . . . . . . . . . . . . . . . . . . 39
3283 H. Copyright . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
3284 H.1. The GNU Public License . . . . . . . . . . . . . . . . . . . 41
3285 H.2. The Artistic License . . . . . . . . . . . . . . . . . . . . 47