slang.h 40 KB

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