slang-mc.h 40 KB

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