slang.h 62 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947
  1. #ifndef DAVIS_SLANG_H_
  2. #define DAVIS_SLANG_H_
  3. /* -*- mode: C; mode: fold; -*- */
  4. /* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
  5. * This file is part of the S-Lang library.
  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 10405
  11. #define SLANG_VERSION_STRING "1.4.5"
  12. /*{{{ System Dependent Macros and Typedefs */
  13. #if defined(__WATCOMC__) && defined(DOS)
  14. # ifndef __MSDOS__
  15. # define __MSDOS__
  16. # endif
  17. # ifndef DOS386
  18. # define DOS386
  19. # endif
  20. # ifndef IBMPC_SYSTEM
  21. # define IBMPC_SYSTEM
  22. # endif
  23. #endif /* __watcomc__ */
  24. #if defined(unix) || defined(__unix) || defined (_AIX)
  25. # ifndef __unix__
  26. # define __unix__ 1
  27. # endif
  28. #endif
  29. #if !defined(__GO32__)
  30. # ifdef __unix__
  31. # define REAL_UNIX_SYSTEM
  32. # endif
  33. #endif
  34. /* Set of the various defines for pc systems. This includes OS/2 */
  35. #ifdef __GO32__
  36. # ifndef __DJGPP__
  37. # define __DJGPP__ 1
  38. # endif
  39. # ifndef IBMPC_SYSTEM
  40. # define IBMPC_SYSTEM
  41. # endif
  42. #endif
  43. #ifdef __BORLANDC__
  44. # ifndef IBMPC_SYSTEM
  45. # define IBMPC_SYSTEM
  46. # endif
  47. #endif
  48. #ifdef __MSDOS__
  49. # ifndef IBMPC_SYSTEM
  50. # define IBMPC_SYSTEM
  51. # endif
  52. #endif
  53. #if defined(OS2) || defined(__os2__)
  54. # ifndef IBMPC_SYSTEM
  55. # define IBMPC_SYSTEM
  56. # endif
  57. # ifndef __os2__
  58. # define __os2__
  59. # endif
  60. #endif
  61. #if defined(__NT__) || defined(__MINGW32__) /* || defined(__CYGWIN32__) */
  62. # ifndef IBMPC_SYSTEM
  63. # define IBMPC_SYSTEM
  64. # endif
  65. #endif
  66. #if defined(IBMPC_SYSTEM) || defined(VMS)
  67. # ifdef REAL_UNIX_SYSTEM
  68. # undef REAL_UNIX_SYSTEM
  69. # endif
  70. #endif
  71. #ifdef __cplusplus
  72. extern "C" {
  73. #endif
  74. #if 0
  75. }
  76. #endif
  77. #include <stdio.h>
  78. #include <stdarg.h>
  79. #if defined(__STDC__) || defined(__BORLANDC__) || defined(__cplusplus)
  80. # include <stddef.h> /* for offsetof */
  81. #endif
  82. /* ---------------------------- Generic Macros ----------------------------- */
  83. /* __SC__ is defined for Symantec C++
  84. DOS386 is defined for -mx memory model, 32 bit DOS extender. */
  85. #if defined(__SC__) && !defined(DOS386)
  86. # include <dos.h>
  87. #endif
  88. #if defined(__BORLANDC__)
  89. # include <alloc.h>
  90. #endif
  91. #if defined (__cplusplus) || defined(__STDC__) || defined(IBMPC_SYSTEM)
  92. typedef void *VOID_STAR;
  93. #else
  94. typedef unsigned char *VOID_STAR;
  95. #endif
  96. typedef int (*FVOID_STAR)(void);
  97. #if defined(__MSDOS__) && defined(__BORLANDC__)
  98. # define SLFREE(buf) farfree((void far *)(buf))
  99. # define SLMALLOC(x) farmalloc((unsigned long) (x))
  100. # define SLREALLOC(buf, n) farrealloc((void far *) (buf), (unsigned long) (n))
  101. # define SLCALLOC(n, m) farcalloc((unsigned long) (n), (unsigned long) (m))
  102. #else
  103. # if defined(VMS) && !defined(__DECC)
  104. # define SLFREE VAXC$FREE_OPT
  105. # define SLMALLOC VAXC$MALLOC_OPT
  106. # define SLREALLOC VAXC$REALLOC_OPT
  107. # define SLCALLOC VAXC$CALLOC_OPT
  108. # else
  109. # define SLFREE(x) free((char *)(x))
  110. # define SLMALLOC malloc
  111. # define SLREALLOC realloc
  112. # define SLCALLOC calloc
  113. # endif
  114. #endif
  115. extern char *SLdebug_malloc (unsigned long);
  116. extern char *SLdebug_calloc (unsigned long, unsigned long);
  117. extern char *SLdebug_realloc (char *, unsigned long);
  118. extern void SLdebug_free (char *);
  119. extern void SLmalloc_dump_statistics (void);
  120. extern char *SLstrcpy(register char *, register char *);
  121. extern int SLstrcmp(register char *, register char *);
  122. extern char *SLstrncpy(char *, register char *, register int);
  123. extern void SLmemset (char *, char, int);
  124. extern char *SLmemchr (register char *, register char, register int);
  125. extern char *SLmemcpy (char *, char *, int);
  126. extern int SLmemcmp (char *, char *, int);
  127. /*}}}*/
  128. /*{{{ Interpreter Typedefs */
  129. typedef unsigned char SLtype; /* This will be unsigned int in V2 */
  130. typedef struct _SLang_Name_Type
  131. {
  132. char *name;
  133. struct _SLang_Name_Type *next;
  134. char name_type;
  135. /* These values must be less than 0x10 because they map directly
  136. * to byte codes. See _slang.h.
  137. */
  138. #define SLANG_LVARIABLE 0x01
  139. #define SLANG_GVARIABLE 0x02
  140. #define SLANG_IVARIABLE 0x03 /* intrinsic variables */
  141. /* Note!!! For Macro MAKE_VARIABLE below to work, SLANG_IVARIABLE Must
  142. be 1 less than SLANG_RVARIABLE!!! */
  143. #define SLANG_RVARIABLE 0x04 /* read only variable */
  144. #define SLANG_INTRINSIC 0x05
  145. #define SLANG_FUNCTION 0x06
  146. #define SLANG_MATH_UNARY 0x07
  147. #define SLANG_APP_UNARY 0x08
  148. #define SLANG_ICONSTANT 0x09
  149. #define SLANG_DCONSTANT 0x0A
  150. #define SLANG_PVARIABLE 0x0B /* private */
  151. #define SLANG_PFUNCTION 0x0C /* private */
  152. /* Rest of fields depend on name type */
  153. }
  154. SLang_Name_Type;
  155. typedef struct
  156. {
  157. char *name;
  158. struct _SLang_Name_Type *next; /* this is for the hash table */
  159. char name_type;
  160. FVOID_STAR i_fun; /* address of object */
  161. /* Do not change this without modifying slang.c:execute_intrinsic_fun */
  162. #define SLANG_MAX_INTRIN_ARGS 7
  163. SLtype arg_types [SLANG_MAX_INTRIN_ARGS];
  164. unsigned char num_args;
  165. SLtype return_type;
  166. }
  167. SLang_Intrin_Fun_Type;
  168. typedef struct
  169. {
  170. char *name;
  171. SLang_Name_Type *next;
  172. char name_type;
  173. VOID_STAR addr;
  174. SLtype type;
  175. }
  176. SLang_Intrin_Var_Type;
  177. typedef struct
  178. {
  179. char *name;
  180. SLang_Name_Type *next;
  181. char name_type;
  182. int unary_op;
  183. }
  184. SLang_App_Unary_Type;
  185. typedef struct
  186. {
  187. char *name;
  188. SLang_Name_Type *next;
  189. char name_type;
  190. int unary_op;
  191. }
  192. SLang_Math_Unary_Type;
  193. typedef struct
  194. {
  195. char *name;
  196. SLang_Name_Type *next;
  197. char name_type;
  198. int i;
  199. }
  200. SLang_IConstant_Type;
  201. typedef struct
  202. {
  203. char *name;
  204. SLang_Name_Type *next;
  205. char name_type;
  206. double d;
  207. }
  208. SLang_DConstant_Type;
  209. typedef struct
  210. {
  211. char *field_name;
  212. unsigned int offset;
  213. SLtype type;
  214. unsigned char read_only;
  215. }
  216. SLang_IStruct_Field_Type;
  217. extern int SLadd_intrin_fun_table (SLang_Intrin_Fun_Type *, char *);
  218. extern int SLadd_intrin_var_table (SLang_Intrin_Var_Type *, char *);
  219. extern int SLadd_app_unary_table (SLang_App_Unary_Type *, char *);
  220. extern int SLadd_math_unary_table (SLang_Math_Unary_Type *, char *);
  221. extern int SLadd_iconstant_table (SLang_IConstant_Type *, char *);
  222. extern int SLadd_dconstant_table (SLang_DConstant_Type *, char *);
  223. extern int SLadd_istruct_table (SLang_IStruct_Field_Type *, VOID_STAR, char *);
  224. typedef struct _SLang_NameSpace_Type SLang_NameSpace_Type;
  225. extern int SLns_add_intrin_fun_table (SLang_NameSpace_Type *, SLang_Intrin_Fun_Type *, char *);
  226. extern int SLns_add_intrin_var_table (SLang_NameSpace_Type *, SLang_Intrin_Var_Type *, char *);
  227. extern int SLns_add_app_unary_table (SLang_NameSpace_Type *, SLang_App_Unary_Type *, char *);
  228. extern int SLns_add_math_unary_table (SLang_NameSpace_Type *, SLang_Math_Unary_Type *, char *);
  229. extern int SLns_add_iconstant_table (SLang_NameSpace_Type *, SLang_IConstant_Type *, char *);
  230. extern int SLns_add_dconstant_table (SLang_NameSpace_Type *, SLang_DConstant_Type *, char *);
  231. extern int SLns_add_istruct_table (SLang_NameSpace_Type *, SLang_IStruct_Field_Type *, VOID_STAR, char *);
  232. extern SLang_NameSpace_Type *SLns_create_namespace (char *);
  233. extern void SLns_delete_namespace (SLang_NameSpace_Type *);
  234. typedef struct SLang_Load_Type
  235. {
  236. int type;
  237. VOID_STAR client_data;
  238. /* Pointer to data that client needs for loading */
  239. int auto_declare_globals;
  240. /* if non-zero, undefined global variables are declared as static */
  241. char *(*read)(struct SLang_Load_Type *);
  242. /* function to call to read next line from obj. */
  243. unsigned int line_num;
  244. /* Number of lines read, used for error reporting */
  245. int parse_level;
  246. /* 0 if at top level of parsing */
  247. char *name;
  248. /* Name of this object, e.g., filename. This name should be unique because
  249. * it alone determines the name space for static objects associated with
  250. * the compilable unit.
  251. */
  252. unsigned long reserved[4];
  253. /* For future expansion */
  254. } SLang_Load_Type;
  255. extern SLang_Load_Type *SLallocate_load_type (char *);
  256. extern void SLdeallocate_load_type (SLang_Load_Type *);
  257. /* Returns SLang_Error upon failure */
  258. extern int SLang_load_object (SLang_Load_Type *);
  259. extern int (*SLang_Load_File_Hook)(char *);
  260. extern int (*SLang_Auto_Declare_Var_Hook) (char *);
  261. extern int SLang_generate_debug_info (int);
  262. #if defined(ultrix) && !defined(__GNUC__)
  263. # ifndef NO_PROTOTYPES
  264. # define NO_PROTOTYPES
  265. # endif
  266. #endif
  267. #ifndef NO_PROTOTYPES
  268. # define _PROTO(x) x
  269. #else
  270. # define _PROTO(x) ()
  271. #endif
  272. typedef struct SL_OOBinary_Type
  273. {
  274. SLtype data_type; /* partner type for binary op */
  275. int (*binary_function)_PROTO((int,
  276. SLtype, VOID_STAR, unsigned int,
  277. SLtype, VOID_STAR, unsigned int,
  278. VOID_STAR));
  279. int (*binary_result) _PROTO((int, SLtype, SLtype, SLtype *));
  280. struct SL_OOBinary_Type *next;
  281. }
  282. SL_OOBinary_Type;
  283. typedef struct _SL_Typecast_Type
  284. {
  285. SLtype data_type; /* to_type */
  286. int allow_implicit;
  287. int (*typecast)_PROTO((SLtype, VOID_STAR, unsigned int,
  288. SLtype, VOID_STAR));
  289. struct _SL_Typecast_Type *next;
  290. }
  291. SL_Typecast_Type;
  292. typedef struct _SLang_Struct_Type SLang_Struct_Type;
  293. typedef struct _SLang_Foreach_Context_Type SLang_Foreach_Context_Type;
  294. #if 0
  295. #if defined(SL_APP_WANTS_FOREACH)
  296. typedef struct _SLang_Foreach_Context_Type SLang_Foreach_Context_Type;
  297. /* It is up to the application to define struct _SLang_Foreach_Context_Type */
  298. #else
  299. typedef int SLang_Foreach_Context_Type;
  300. #endif
  301. #endif
  302. typedef struct
  303. {
  304. unsigned char cl_class_type;
  305. #define SLANG_CLASS_TYPE_MMT 0
  306. #define SLANG_CLASS_TYPE_SCALAR 1
  307. #define SLANG_CLASS_TYPE_VECTOR 2
  308. #define SLANG_CLASS_TYPE_PTR 3
  309. unsigned int cl_data_type; /* SLANG_INTEGER_TYPE, etc... */
  310. char *cl_name; /* slstring type */
  311. unsigned int cl_sizeof_type;
  312. VOID_STAR cl_transfer_buf; /* cl_sizeof_type bytes*/
  313. /* Methods */
  314. /* Most of the method functions are prototyped:
  315. * int method (SLtype type, VOID_STAR addr);
  316. * Here, @type@ represents the type of object that the method is asked
  317. * to deal with. The second parameter @addr@ will contain the ADDRESS of
  318. * the object. For example, if type is SLANG_INT_TYPE, then @addr@ will
  319. * actually be int *. Similary, if type is SLANG_STRING_TYPE,
  320. * then @addr@ will contain the address of the string, i.e., char **.
  321. */
  322. void (*cl_destroy)_PROTO((SLtype, VOID_STAR));
  323. /* Prototype: void destroy(unsigned type, VOID_STAR val)
  324. * Called to delete/free the object */
  325. char *(*cl_string)_PROTO((SLtype, VOID_STAR));
  326. /* Prototype: char *to_string (SLtype t, VOID_STAR p);
  327. * Here p is a pointer to the object for which a string representation
  328. * is to be returned. The returned pointer is to be a MALLOCED string.
  329. */
  330. /* Prototype: void push(SLtype type, VOID_STAR v);
  331. * Push a copy of the object of type @type@ at address @v@ onto the
  332. * stack.
  333. */
  334. int (*cl_push)_PROTO((SLtype, VOID_STAR));
  335. /* Prototype: int pop(SLtype type, VOID_STAR v);
  336. * Pops value from stack and assign it to object, whose address is @v@.
  337. */
  338. int (*cl_pop)_PROTO((SLtype, VOID_STAR));
  339. int (*cl_unary_op_result_type)_PROTO((int, SLtype, SLtype *));
  340. int (*cl_unary_op)_PROTO((int, SLtype, VOID_STAR, unsigned int, VOID_STAR));
  341. int (*cl_app_unary_op_result_type)_PROTO((int, SLtype, SLtype *));
  342. int (*cl_app_unary_op)_PROTO((int, SLtype, VOID_STAR, unsigned int, VOID_STAR));
  343. /* If this function is non-NULL, it will be called for sin, cos, etc... */
  344. #define SLMATH_SIN 1
  345. #define SLMATH_COS 2
  346. #define SLMATH_TAN 3
  347. #define SLMATH_ATAN 4
  348. #define SLMATH_ASIN 5
  349. #define SLMATH_ACOS 6
  350. #define SLMATH_EXP 7
  351. #define SLMATH_LOG 8
  352. #define SLMATH_SQRT 9
  353. #define SLMATH_LOG10 10
  354. #define SLMATH_REAL 11
  355. #define SLMATH_IMAG 12
  356. #define SLMATH_SINH 13
  357. #define SLMATH_COSH 14
  358. #define SLMATH_TANH 15
  359. #define SLMATH_ATANH 16
  360. #define SLMATH_ASINH 17
  361. #define SLMATH_ACOSH 18
  362. #define SLMATH_TODOUBLE 19
  363. #define SLMATH_CONJ 20
  364. int (*cl_math_op)_PROTO((int, SLtype, VOID_STAR, unsigned int, VOID_STAR));
  365. int (*cl_math_op_result_type)_PROTO((int, SLtype, SLtype *));
  366. SL_OOBinary_Type *cl_binary_ops;
  367. SL_Typecast_Type *cl_typecast_funs;
  368. void (*cl_byte_code_destroy)_PROTO((SLtype, VOID_STAR));
  369. void (*cl_user_destroy_fun)_PROTO((SLtype, VOID_STAR));
  370. int (*cl_init_array_object)_PROTO((SLtype, VOID_STAR));
  371. int (*cl_datatype_deref)_PROTO((SLtype));
  372. SLang_Struct_Type *cl_struct_def;
  373. int (*cl_dereference) _PROTO((SLtype, VOID_STAR));
  374. int (*cl_acopy) (SLtype, VOID_STAR, VOID_STAR);
  375. int (*cl_apop) _PROTO((SLtype, VOID_STAR));
  376. int (*cl_apush) _PROTO((SLtype, VOID_STAR));
  377. int (*cl_push_literal) _PROTO((SLtype, VOID_STAR));
  378. void (*cl_adestroy)_PROTO((SLtype, VOID_STAR));
  379. int (*cl_push_intrinsic)_PROTO((SLtype, VOID_STAR));
  380. int (*cl_void_typecast)_PROTO((SLtype, VOID_STAR, unsigned int, SLtype, VOID_STAR));
  381. int (*cl_anytype_typecast)_PROTO((SLtype, VOID_STAR, unsigned int, SLtype, VOID_STAR));
  382. /* Array access functions */
  383. int (*cl_aput) (SLtype, unsigned int);
  384. int (*cl_aget) (SLtype, unsigned int);
  385. int (*cl_anew) (SLtype, unsigned int);
  386. /* length method */
  387. int (*cl_length) (SLtype, VOID_STAR, unsigned int *);
  388. /* foreach */
  389. SLang_Foreach_Context_Type *(*cl_foreach_open) (SLtype, unsigned int);
  390. void (*cl_foreach_close) (SLtype, SLang_Foreach_Context_Type *);
  391. int (*cl_foreach) (SLtype, SLang_Foreach_Context_Type *);
  392. /* Structure access: get and put (assign to) fields */
  393. int (*cl_sput) (SLtype, char *);
  394. int (*cl_sget) (SLtype, char *);
  395. /* File I/O */
  396. int (*cl_fread) (SLtype, FILE *, VOID_STAR, unsigned int, unsigned int *);
  397. int (*cl_fwrite) (SLtype, FILE *, VOID_STAR, unsigned int, unsigned int *);
  398. int (*cl_fdread) (SLtype, int, VOID_STAR, unsigned int, unsigned int *);
  399. int (*cl_fdwrite) (SLtype, int, VOID_STAR, unsigned int, unsigned int *);
  400. int (*cl_to_bool) (SLtype, int *);
  401. int (*cl_cmp)(SLtype, VOID_STAR, VOID_STAR, int *);
  402. } SLang_Class_Type;
  403. /* These are the low-level functions for building push/pop methods. They
  404. * know nothing about memory management. For SLANG_CLASS_TYPE_MMT, use the
  405. * MMT push/pop functions instead.
  406. */
  407. extern int SLclass_push_double_obj (SLtype, double);
  408. extern int SLclass_push_float_obj (SLtype, float);
  409. extern int SLclass_push_long_obj (SLtype, long);
  410. extern int SLclass_push_int_obj (SLtype, int);
  411. extern int SLclass_push_short_obj (SLtype, short);
  412. extern int SLclass_push_char_obj (SLtype, char);
  413. extern int SLclass_push_ptr_obj (SLtype, VOID_STAR);
  414. extern int SLclass_pop_double_obj (SLtype, double *);
  415. extern int SLclass_pop_float_obj (SLtype, float *);
  416. extern int SLclass_pop_long_obj (SLtype, long *);
  417. extern int SLclass_pop_int_obj (SLtype, int *);
  418. extern int SLclass_pop_short_obj (SLtype, short *);
  419. extern int SLclass_pop_char_obj (SLtype, char *);
  420. extern int SLclass_pop_ptr_obj (SLtype, VOID_STAR *);
  421. extern SLang_Class_Type *SLclass_allocate_class (char *);
  422. extern int SLclass_get_class_id (SLang_Class_Type *cl);
  423. extern int SLclass_create_synonym (char *, SLtype);
  424. extern int SLclass_is_class_defined (SLtype);
  425. extern int SLclass_dup_object (SLtype type, VOID_STAR from, VOID_STAR to);
  426. extern int SLclass_register_class (SLang_Class_Type *, SLtype, unsigned int, SLtype);
  427. extern int SLclass_set_string_function (SLang_Class_Type *, char *(*)(SLtype, VOID_STAR));
  428. extern int SLclass_set_destroy_function (SLang_Class_Type *, void (*)(SLtype, VOID_STAR));
  429. extern int SLclass_set_push_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
  430. extern int SLclass_set_pop_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR));
  431. extern int SLclass_set_aget_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
  432. extern int SLclass_set_aput_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
  433. extern int SLclass_set_anew_function (SLang_Class_Type *, int (*)(SLtype, unsigned int));
  434. extern int SLclass_set_sget_function (SLang_Class_Type *, int (*)(SLtype, char *));
  435. extern int SLclass_set_sput_function (SLang_Class_Type *, int (*)(SLtype, char *));
  436. extern int SLclass_set_acopy_function (SLang_Class_Type *, int (*)(SLtype, VOID_STAR, VOID_STAR));
  437. /* Typecast object on the stack to type p1. p2 and p3 should be set to 1 */
  438. extern int SLclass_typecast (SLtype, int, int);
  439. extern int SLclass_add_unary_op (SLtype,
  440. int (*) (int,
  441. SLtype, VOID_STAR, unsigned int,
  442. VOID_STAR),
  443. int (*) (int, SLtype, SLtype *));
  444. extern int
  445. SLclass_add_app_unary_op (SLtype,
  446. int (*) (int,
  447. SLtype, VOID_STAR, unsigned int,
  448. VOID_STAR),
  449. int (*) (int, SLtype, SLtype *));
  450. extern int
  451. SLclass_add_binary_op (SLtype, SLtype,
  452. int (*) (int,
  453. SLtype, VOID_STAR, unsigned int,
  454. SLtype, VOID_STAR, unsigned int,
  455. VOID_STAR),
  456. int (*) (int, SLtype, SLtype, SLtype *));
  457. extern int
  458. SLclass_add_math_op (SLtype,
  459. int (*)(int,
  460. SLtype, VOID_STAR, unsigned int,
  461. VOID_STAR),
  462. int (*)(int, SLtype, SLtype *));
  463. extern int
  464. SLclass_add_typecast (SLtype /* from */, SLtype /* to */,
  465. int (*)_PROTO((SLtype, VOID_STAR, unsigned int,
  466. SLtype, VOID_STAR)),
  467. int /* allow implicit typecasts */
  468. );
  469. extern char *SLclass_get_datatype_name (SLtype);
  470. extern double SLcomplex_abs (double *);
  471. extern double *SLcomplex_times (double *, double *, double *);
  472. extern double *SLcomplex_divide (double *, double *, double *);
  473. extern double *SLcomplex_sin (double *, double *);
  474. extern double *SLcomplex_cos (double *, double *);
  475. extern double *SLcomplex_tan (double *, double *);
  476. extern double *SLcomplex_asin (double *, double *);
  477. extern double *SLcomplex_acos (double *, double *);
  478. extern double *SLcomplex_atan (double *, double *);
  479. extern double *SLcomplex_exp (double *, double *);
  480. extern double *SLcomplex_log (double *, double *);
  481. extern double *SLcomplex_log10 (double *, double *);
  482. extern double *SLcomplex_sqrt (double *, double *);
  483. extern double *SLcomplex_sinh (double *, double *);
  484. extern double *SLcomplex_cosh (double *, double *);
  485. extern double *SLcomplex_tanh (double *, double *);
  486. extern double *SLcomplex_pow (double *, double *, double *);
  487. extern double SLmath_hypot (double x, double y);
  488. /* Not implemented yet */
  489. extern double *SLcomplex_asinh (double *, double *);
  490. extern double *SLcomplex_acosh (double *, double *);
  491. extern double *SLcomplex_atanh (double *, double *);
  492. #ifdef _SLANG_SOURCE_
  493. typedef struct _SLang_MMT_Type SLang_MMT_Type;
  494. #else
  495. typedef int SLang_MMT_Type;
  496. #endif
  497. extern void SLang_free_mmt (SLang_MMT_Type *);
  498. extern VOID_STAR SLang_object_from_mmt (SLang_MMT_Type *);
  499. extern SLang_MMT_Type *SLang_create_mmt (SLtype, VOID_STAR);
  500. extern int SLang_push_mmt (SLang_MMT_Type *);
  501. extern SLang_MMT_Type *SLang_pop_mmt (SLtype);
  502. extern void SLang_inc_mmt (SLang_MMT_Type *);
  503. /* Maximum number of dimensions of an array. */
  504. #define SLARRAY_MAX_DIMS 7
  505. typedef struct _SLang_Array_Type
  506. {
  507. SLtype data_type;
  508. unsigned int sizeof_type;
  509. VOID_STAR data;
  510. unsigned int num_elements;
  511. unsigned int num_dims;
  512. int dims [SLARRAY_MAX_DIMS];
  513. VOID_STAR (*index_fun)_PROTO((struct _SLang_Array_Type *, int *));
  514. /* This function is designed to allow a type to store an array in
  515. * any manner it chooses. This function returns the address of the data
  516. * value at the specified index location.
  517. */
  518. unsigned int flags;
  519. #define SLARR_DATA_VALUE_IS_READ_ONLY 1
  520. #define SLARR_DATA_VALUE_IS_POINTER 2
  521. #define SLARR_DATA_VALUE_IS_RANGE 4
  522. #define SLARR_DATA_VALUE_IS_INTRINSIC 8
  523. SLang_Class_Type *cl;
  524. unsigned int num_refs;
  525. void (*free_fun)_PROTO((struct _SLang_Array_Type *));
  526. VOID_STAR client_data;
  527. }
  528. SLang_Array_Type;
  529. extern int SLang_pop_array_of_type (SLang_Array_Type **, SLtype);
  530. extern int SLang_pop_array (SLang_Array_Type **, int);
  531. extern int SLang_push_array (SLang_Array_Type *, int);
  532. extern void SLang_free_array (SLang_Array_Type *);
  533. extern SLang_Array_Type *SLang_create_array (SLtype, int, VOID_STAR, int *, unsigned int);
  534. extern SLang_Array_Type *SLang_duplicate_array (SLang_Array_Type *);
  535. extern int SLang_get_array_element (SLang_Array_Type *, int *, VOID_STAR);
  536. extern int SLang_set_array_element (SLang_Array_Type *, int *, VOID_STAR);
  537. /*}}}*/
  538. /*{{{ Interpreter Function Prototypes */
  539. extern volatile int SLang_Error;
  540. /* Non zero if error occurs. Must be reset to zero to continue. */
  541. /* error codes, severe errors are less than 0 */
  542. #define SL_APPLICATION_ERROR -2
  543. #define SL_VARIABLE_UNINITIALIZED -3
  544. #define SL_INTERNAL_ERROR -5
  545. #define SL_STACK_OVERFLOW -6
  546. #define SL_STACK_UNDERFLOW -7
  547. #define SL_UNDEFINED_NAME -8
  548. #define SL_SYNTAX_ERROR -9
  549. #define SL_DUPLICATE_DEFINITION -10
  550. #define SL_TYPE_MISMATCH -11
  551. #define SL_OBJ_UNKNOWN -13
  552. #define SL_UNKNOWN_ERROR -14
  553. #define SL_TYPE_UNDEFINED_OP_ERROR -16
  554. #define SL_INTRINSIC_ERROR 1
  555. /* Intrinsic error is an error generated by intrinsic functions */
  556. #define SL_USER_BREAK 2
  557. #define SL_DIVIDE_ERROR 3
  558. #define SL_OBJ_NOPEN 4
  559. #define SL_USER_ERROR 5
  560. #define SL_USAGE_ERROR 6
  561. #define SL_READONLY_ERROR 7
  562. #define SL_INVALID_PARM 8
  563. #define SL_NOT_IMPLEMENTED 9
  564. #define SL_MALLOC_ERROR 10
  565. #define SL_OVERFLOW 11
  566. #define SL_FLOATING_EXCEPTION 12
  567. /* Compatibility */
  568. #define USER_BREAK SL_USER_BREAK
  569. #define INTRINSIC_ERROR SL_INTRINSIC_ERROR
  570. extern int SLang_Traceback;
  571. /* If non-zero, dump an S-Lang traceback upon error. Available as
  572. _traceback in S-Lang. */
  573. extern char *SLang_User_Prompt;
  574. /* Prompt to use when reading from stdin */
  575. extern int SLang_Version;
  576. extern char *SLang_Version_String;
  577. extern char *SLang_Doc_Dir;
  578. extern void (*SLang_VMessage_Hook) (char *, va_list);
  579. extern void SLang_vmessage (char *, ...);
  580. extern void (*SLang_Error_Hook)(char *);
  581. /* Pointer to application dependent error messaging routine. By default,
  582. messages are displayed on stderr. */
  583. extern void (*SLang_Exit_Error_Hook)(char *, va_list);
  584. extern void SLang_exit_error (char *, ...);
  585. extern void (*SLang_Dump_Routine)(char *);
  586. /* Called if S-Lang traceback is enabled as well as other debugging
  587. routines (e.g., trace). By default, these messages go to stderr. */
  588. extern void (*SLang_Interrupt)(void);
  589. /* function to call whenever inner interpreter is entered. This is
  590. a good place to set SLang_Error to USER_BREAK. */
  591. extern void (*SLang_User_Clear_Error)(void);
  592. /* function that gets called when '_clear_error' is called. */
  593. /* If non null, these call C functions before and after a slang function. */
  594. extern void (*SLang_Enter_Function)(char *);
  595. extern void (*SLang_Exit_Function)(char *);
  596. extern int SLang_Num_Function_Args;
  597. /* Functions: */
  598. extern int SLang_init_all (void);
  599. /* Initializes interpreter and all modules */
  600. extern int SLang_init_slang (void);
  601. /* This function is mandatory and must be called by all applications that
  602. * use the interpreter
  603. */
  604. extern int SLang_init_posix_process (void); /* process specific intrinsics */
  605. extern int SLang_init_stdio (void); /* fgets, etc. stdio functions */
  606. extern int SLang_init_posix_dir (void);
  607. extern int SLang_init_ospath (void);
  608. extern int SLang_init_slmath (void);
  609. /* called if math functions sin, cos, etc... are needed. */
  610. extern int SLang_init_slfile (void);
  611. extern int SLang_init_slunix (void);
  612. /* These functions are obsolte. Use init_stdio, posix_process, etc. */
  613. extern int SLang_init_slassoc (void);
  614. /* Assoc Arrays (Hashes) */
  615. extern int SLang_init_array (void);
  616. /* Additional arrays functions: transpose, etc... */
  617. /* Dynamic linking facility */
  618. extern int SLang_init_import (void);
  619. extern int SLang_load_file (char *);
  620. /* Load a file of S-Lang code for interpreting. If the parameter is
  621. * NULL, input comes from stdin. */
  622. extern void SLang_restart(int);
  623. /* should be called if an error occurs. If the passed integer is
  624. * non-zero, items are popped off the stack; otherwise, the stack is
  625. * left intact. Any time the stack is believed to be trashed, this routine
  626. * should be called with a non-zero argument (e.g., if setjmp/longjmp is
  627. * called). */
  628. extern int SLang_byte_compile_file(char *, int);
  629. /* takes a file of S-Lang code and ``byte-compiles'' it for faster
  630. * loading. The new filename is equivalent to the old except that a `c' is
  631. * appended to the name. (e.g., init.sl --> init.slc). The second
  632. * specified the method; currently, it is not used.
  633. */
  634. extern int SLang_autoload(char *, char *);
  635. /* Automatically load S-Lang function p1 from file p2. This function
  636. is also available via S-Lang */
  637. extern int SLang_load_string(char *);
  638. /* Like SLang_load_file except input is from a null terminated string. */
  639. extern int SLdo_pop(void);
  640. /* pops item off stack and frees any memory associated with it */
  641. extern int SLdo_pop_n(unsigned int);
  642. /* pops n items off stack and frees any memory associated with them */
  643. extern int SLang_pop_datatype (SLtype *);
  644. extern int SLang_push_datatype (SLtype);
  645. extern int SLang_pop_integer(int *);
  646. extern int SLang_pop_uinteger(unsigned int *);
  647. /* pops integer *p0 from the stack. Returns 0 upon success and non-zero
  648. * if the stack is empty or a type mismatch occurs, setting SLang_Error.
  649. */
  650. extern int SLang_pop_char (char *);
  651. extern int SLang_pop_uchar (SLtype *);
  652. extern int SLang_pop_short(short *);
  653. extern int SLang_pop_ushort(unsigned short *);
  654. extern int SLang_pop_long(long *);
  655. extern int SLang_pop_ulong(unsigned long *);
  656. extern int SLang_pop_float(float *);
  657. extern int SLang_pop_double(double *, int *, int *);
  658. /* Pops double *p1 from stack. If *p3 is non-zero, *p1 was derived
  659. from the integer *p2. Returns zero upon success. */
  660. extern int SLang_pop_complex (double *, double *);
  661. extern int SLpop_string (char **);
  662. extern int SLang_pop_string(char **, int *);
  663. /* pops string *p0 from stack. If *p1 is non-zero, the string must be
  664. * freed after its use. DO NOT FREE p0 if *p1 IS ZERO! Returns 0 upon
  665. * success */
  666. extern int SLang_push_complex (double, double);
  667. extern int SLang_push_char (char);
  668. extern int SLang_push_uchar (SLtype);
  669. extern int SLang_push_integer(int);
  670. extern int SLang_push_uinteger(unsigned int);
  671. /* push integer p1 on stack */
  672. extern int SLang_push_short(short);
  673. extern int SLang_push_ushort(unsigned short);
  674. extern int SLang_push_long(long);
  675. extern int SLang_push_ulong(unsigned long);
  676. extern int SLang_push_float(float);
  677. extern int SLang_push_double(double);
  678. /* Push double onto stack */
  679. extern int SLang_push_string(char *);
  680. /* Push string p1 onto stack */
  681. extern int SLang_push_malloced_string(char *);
  682. /* The normal SLang_push_string pushes an slstring. This one converts
  683. * a normally malloced string to an slstring, and then frees the
  684. * malloced string. So, do NOT use the malloced string after calling
  685. * this routine because it will be freed! The routine returns -1 upon
  686. * error, but the string will be freed.
  687. */
  688. extern int SLang_push_null (void);
  689. extern int SLang_pop_null (void);
  690. extern int SLang_push_value (SLtype type, VOID_STAR);
  691. extern int SLang_pop_value (SLtype type, VOID_STAR);
  692. extern void SLang_free_value (SLtype type, VOID_STAR);
  693. typedef struct _SLang_Object_Type SLang_Any_Type;
  694. extern int SLang_pop_anytype (SLang_Any_Type **);
  695. extern int SLang_push_anytype (SLang_Any_Type *);
  696. extern void SLang_free_anytype (SLang_Any_Type *);
  697. #ifdef _SLANG_SOURCE_
  698. typedef struct _SLang_Ref_Type SLang_Ref_Type;
  699. #else
  700. typedef int SLang_Ref_Type;
  701. #endif
  702. extern int SLang_pop_ref (SLang_Ref_Type **);
  703. extern void SLang_free_ref (SLang_Ref_Type *);
  704. extern int SLang_assign_to_ref (SLang_Ref_Type *, SLtype, VOID_STAR);
  705. extern SLang_Name_Type *SLang_pop_function (void);
  706. extern SLang_Name_Type *SLang_get_fun_from_ref (SLang_Ref_Type *);
  707. extern void SLang_free_function (SLang_Name_Type *f);
  708. extern int SLang_is_defined(char *);
  709. /* Return non-zero is p1 is defined otherwise returns 0. */
  710. extern int SLang_run_hooks(char *, unsigned int, ...);
  711. /* calls S-Lang function p1 pushing p2 strings in the variable argument
  712. * list onto the stack first.
  713. * Returns -1 upon error, 1 if hooks exists and it ran,
  714. * or 0 if hook does not exist. Thus it returns non-zero is hook was called.
  715. */
  716. /* These functions return 1 if the indicated function exists and the function
  717. * runs without error. If the function does not exist, the function returns
  718. * 0. Otherwise -1 is returned with SLang_Error set appropriately.
  719. */
  720. extern int SLexecute_function (SLang_Name_Type *);
  721. extern int SLang_execute_function(char *);
  722. extern int SLang_end_arg_list (void);
  723. extern int SLang_start_arg_list (void);
  724. extern void SLang_verror (int, char *, ...);
  725. extern void SLang_doerror(char *);
  726. /* set SLang_Error and display p1 as error message */
  727. extern int SLang_add_intrinsic_array (char *, /* name */
  728. SLtype, /* type */
  729. int, /* readonly */
  730. VOID_STAR, /* data */
  731. unsigned int, ...); /* num dims */
  732. extern int SLextract_list_element (char *, unsigned int, char,
  733. char *, unsigned int);
  734. extern void SLexpand_escaped_string (register char *, register char *,
  735. register char *);
  736. extern SLang_Name_Type *SLang_get_function (char *);
  737. extern void SLang_release_function (SLang_Name_Type *);
  738. extern int SLreverse_stack (int);
  739. extern int SLroll_stack (int);
  740. /* If argument p is positive, the top p objects on the stack are rolled
  741. * up. If negative, the stack is rolled down.
  742. */
  743. extern int SLdup_n (int n);
  744. /* Duplicate top n elements of stack */
  745. extern int SLang_peek_at_stack1 (void);
  746. extern int SLang_peek_at_stack (void);
  747. /* Returns type of next object on stack-- -1 upon stack underflow. */
  748. extern void SLmake_lut (unsigned char *, unsigned char *, unsigned char);
  749. extern int SLang_guess_type (char *);
  750. extern int SLstruct_create_struct (unsigned int,
  751. char **,
  752. SLtype *,
  753. VOID_STAR *);
  754. /*}}}*/
  755. /*{{{ Misc Functions */
  756. /* This is an interface to atexit */
  757. extern int SLang_add_cleanup_function (void (*)(void));
  758. extern char *SLmake_string (char *);
  759. extern char *SLmake_nstring (char *, unsigned int);
  760. /* Returns a null terminated string made from the first n characters of the
  761. * string.
  762. */
  763. /* The string created by this routine must be freed by SLang_free_slstring
  764. * and nothing else!! Also these strings must not be modified. Use
  765. * SLmake_string if you intend to modify them!!
  766. */
  767. extern char *SLang_create_nslstring (char *, unsigned int);
  768. extern char *SLang_create_slstring (char *);
  769. extern void SLang_free_slstring (char *); /* handles NULL */
  770. extern int SLang_pop_slstring (char **); /* free with SLang_free_slstring */
  771. extern char *SLang_concat_slstrings (char *a, char *b);
  772. extern char *SLang_create_static_slstring (char *); /* adds a string that will not get deleted */
  773. extern void SLstring_dump_stats (void);
  774. /* Binary strings */
  775. /* The binary string is an opaque type. Use the SLbstring_get_pointer function
  776. * to get a pointer and length.
  777. */
  778. typedef struct _SLang_BString_Type SLang_BString_Type;
  779. extern unsigned char *SLbstring_get_pointer (SLang_BString_Type *, unsigned int *);
  780. extern SLang_BString_Type *SLbstring_dup (SLang_BString_Type *);
  781. extern SLang_BString_Type *SLbstring_create (unsigned char *, unsigned int);
  782. /* The create_malloced function used the first argument which is assumed
  783. * to be a pointer to a len + 1 malloced string. The extra byte is for
  784. * \0 termination.
  785. */
  786. extern SLang_BString_Type *SLbstring_create_malloced (unsigned char *, unsigned int, int);
  787. /* Create a bstring from an slstring */
  788. extern SLang_BString_Type *SLbstring_create_slstring (char *);
  789. extern void SLbstring_free (SLang_BString_Type *);
  790. extern int SLang_pop_bstring (SLang_BString_Type **);
  791. extern int SLang_push_bstring (SLang_BString_Type *);
  792. extern char *SLmalloc (unsigned int);
  793. extern char *SLcalloc (unsigned int, unsigned int);
  794. extern void SLfree(char *); /* This function handles NULL */
  795. extern char *SLrealloc (char *, unsigned int);
  796. extern char *SLcurrent_time_string (void);
  797. extern int SLatoi(unsigned char *);
  798. extern long SLatol (unsigned char *);
  799. extern unsigned long SLatoul (unsigned char *);
  800. extern int SLang_pop_fileptr (SLang_MMT_Type **, FILE **);
  801. extern char *SLang_get_name_from_fileptr (SLang_MMT_Type *);
  802. typedef struct _SLFile_FD_Type SLFile_FD_Type;
  803. extern SLFile_FD_Type *SLfile_create_fd (char *, int);
  804. extern void SLfile_free_fd (SLFile_FD_Type *);
  805. extern int SLfile_push_fd (SLFile_FD_Type *);
  806. extern int SLfile_pop_fd (SLFile_FD_Type **);
  807. extern int SLfile_get_fd (SLFile_FD_Type *, int *);
  808. extern SLFile_FD_Type *SLfile_dup_fd (SLFile_FD_Type *f0);
  809. extern int SLang_init_posix_io (void);
  810. typedef double (*SLang_To_Double_Fun_Type)(VOID_STAR);
  811. extern SLang_To_Double_Fun_Type SLarith_get_to_double_fun (SLtype, unsigned int *);
  812. extern int SLang_set_argc_argv (int, char **);
  813. /*}}}*/
  814. /*{{{ SLang getkey interface Functions */
  815. #ifdef REAL_UNIX_SYSTEM
  816. extern int SLang_TT_Baud_Rate;
  817. extern int SLang_TT_Read_FD;
  818. #endif
  819. extern int SLang_init_tty (int, int, int);
  820. /* Initializes the tty for single character input. If the first parameter *p1
  821. * is in the range 0-255, it will be used for the abort character;
  822. * otherwise, (unix only) if it is -1, the abort character will be the one
  823. * used by the terminal. If the second parameter p2 is non-zero, flow
  824. * control is enabled. If the last parmeter p3 is zero, output processing
  825. * is NOT turned on. A value of zero is required for the screen management
  826. * routines. Returns 0 upon success. In addition, if SLang_TT_Baud_Rate ==
  827. * 0 when this function is called, SLang will attempt to determine the
  828. * terminals baud rate. As far as the SLang library is concerned, if
  829. * SLang_TT_Baud_Rate is less than or equal to zero, the baud rate is
  830. * effectively infinite.
  831. */
  832. extern void SLang_reset_tty (void);
  833. /* Resets tty to what it was prior to a call to SLang_init_tty */
  834. #ifdef REAL_UNIX_SYSTEM
  835. extern void SLtty_set_suspend_state (int);
  836. /* If non-zero argument, terminal driver will be told to react to the
  837. * suspend character. If 0, it will not.
  838. */
  839. extern int (*SLang_getkey_intr_hook) (void);
  840. #endif
  841. #define SLANG_GETKEY_ERROR 0xFFFF
  842. extern unsigned int SLang_getkey (void);
  843. /* reads a single key from the tty. If the read fails, 0xFFFF is returned. */
  844. #ifdef IBMPC_SYSTEM
  845. extern int SLgetkey_map_to_ansi (int);
  846. #endif
  847. extern int SLang_ungetkey_string (unsigned char *, unsigned int);
  848. extern int SLang_buffer_keystring (unsigned char *, unsigned int);
  849. extern int SLang_ungetkey (unsigned char);
  850. extern void SLang_flush_input (void);
  851. extern int SLang_input_pending (int);
  852. extern int SLang_Abort_Char;
  853. /* The value of the character (0-255) used to trigger SIGINT */
  854. extern int SLang_Ignore_User_Abort;
  855. /* If non-zero, pressing the abort character will not result in USER_BREAK
  856. * SLang_Error. */
  857. extern int SLang_set_abort_signal (void (*)(int));
  858. /* If SIGINT is generated, the function p1 will be called. If p1 is NULL
  859. * the SLang_default signal handler is called. This sets SLang_Error to
  860. * USER_BREAK. I suspect most users will simply want to pass NULL.
  861. */
  862. extern unsigned int SLang_Input_Buffer_Len;
  863. extern volatile int SLKeyBoard_Quit;
  864. #ifdef VMS
  865. /* If this function returns -1, ^Y will be added to input buffer. */
  866. extern int (*SLtty_VMS_Ctrl_Y_Hook) (void);
  867. #endif
  868. /*}}}*/
  869. /*{{{ SLang Keymap routines */
  870. typedef struct SLKeymap_Function_Type
  871. {
  872. char *name;
  873. int (*f)(void);
  874. }
  875. SLKeymap_Function_Type;
  876. #define SLANG_MAX_KEYMAP_KEY_SEQ 14
  877. typedef struct SLang_Key_Type
  878. {
  879. struct SLang_Key_Type *next;
  880. union
  881. {
  882. char *s;
  883. FVOID_STAR f;
  884. unsigned int keysym;
  885. }
  886. f;
  887. unsigned char type; /* type of function */
  888. #define SLKEY_F_INTERPRET 0x01
  889. #define SLKEY_F_INTRINSIC 0x02
  890. #define SLKEY_F_KEYSYM 0x03
  891. unsigned char str[SLANG_MAX_KEYMAP_KEY_SEQ + 1];/* key sequence */
  892. }
  893. SLang_Key_Type;
  894. typedef struct SLKeyMap_List_Type
  895. {
  896. char *name; /* hashed string */
  897. SLang_Key_Type *keymap;
  898. SLKeymap_Function_Type *functions; /* intrinsic functions */
  899. }
  900. SLKeyMap_List_Type;
  901. /* This is arbitrary but I have got to start somewhere */
  902. #define SLANG_MAX_KEYMAPS 30
  903. extern SLKeyMap_List_Type SLKeyMap_List[SLANG_MAX_KEYMAPS];
  904. extern char *SLang_process_keystring(char *);
  905. extern int SLkm_define_key (char *, FVOID_STAR, SLKeyMap_List_Type *);
  906. extern int SLang_define_key(char *, char *, SLKeyMap_List_Type *);
  907. /* Like define_key1 except that p2 is a string that is to be associated with
  908. * a function in the functions field of p3.
  909. */
  910. extern int SLkm_define_keysym (char *, unsigned int, SLKeyMap_List_Type *);
  911. extern void SLang_undefine_key(char *, SLKeyMap_List_Type *);
  912. extern SLKeyMap_List_Type *SLang_create_keymap(char *, SLKeyMap_List_Type *);
  913. /* create and returns a pointer to a new keymap named p1 created by copying
  914. * keymap p2. If p2 is NULL, it is up to the calling routine to initialize
  915. * the keymap.
  916. */
  917. extern char *SLang_make_keystring(unsigned char *);
  918. extern SLang_Key_Type *SLang_do_key(SLKeyMap_List_Type *, int (*)(void));
  919. /* read a key using keymap p1 with getkey function p2 */
  920. extern
  921. FVOID_STAR
  922. SLang_find_key_function(char *, SLKeyMap_List_Type *);
  923. extern SLKeyMap_List_Type *SLang_find_keymap(char *);
  924. extern int SLang_Last_Key_Char;
  925. extern int SLang_Key_TimeOut_Flag;
  926. /*}}}*/
  927. /*{{{ SLang Readline Interface */
  928. typedef struct SLang_Read_Line_Type
  929. {
  930. struct SLang_Read_Line_Type *prev, *next;
  931. unsigned char *buf;
  932. int buf_len; /* number of chars in the buffer */
  933. int num; /* num and misc are application specific*/
  934. int misc;
  935. } SLang_Read_Line_Type;
  936. /* Maximum size of display */
  937. #define SLRL_DISPLAY_BUFFER_SIZE 256
  938. typedef struct
  939. {
  940. SLang_Read_Line_Type *root, *tail, *last;
  941. unsigned char *buf; /* edit buffer */
  942. int buf_len; /* sizeof buffer */
  943. int point; /* current editing point */
  944. int tab; /* tab width */
  945. int len; /* current line size */
  946. /* display variables */
  947. int edit_width; /* length of display field */
  948. int curs_pos; /* current column */
  949. int start_column; /* column offset of display */
  950. int dhscroll; /* amount to use for horiz scroll */
  951. char *prompt;
  952. FVOID_STAR last_fun; /* last function executed by rl */
  953. /* These two contain an image of what is on the display */
  954. unsigned char upd_buf1[SLRL_DISPLAY_BUFFER_SIZE];
  955. unsigned char upd_buf2[SLRL_DISPLAY_BUFFER_SIZE];
  956. unsigned char *old_upd, *new_upd; /* pointers to previous two buffers */
  957. int new_upd_len, old_upd_len; /* length of output buffers */
  958. SLKeyMap_List_Type *keymap;
  959. /* tty variables */
  960. unsigned int flags; /* */
  961. #define SL_RLINE_NO_ECHO 1
  962. #define SL_RLINE_USE_ANSI 2
  963. #define SL_RLINE_BLINK_MATCH 4
  964. unsigned int (*getkey)(void); /* getkey function -- required */
  965. void (*tt_goto_column)(int);
  966. void (*tt_insert)(char);
  967. void (*update_hook)(unsigned char *, int, int);
  968. /* The update hook is called with a pointer to a buffer p1 that contains
  969. * an image of what the update hook is suppoed to produce. The length
  970. * of the buffer is p2 and after the update, the cursor is to be placed
  971. * in column p3.
  972. */
  973. /* This function is only called when blinking matches */
  974. int (*input_pending)(int);
  975. unsigned long reserved[4];
  976. } SLang_RLine_Info_Type;
  977. extern int SLang_RL_EOF_Char;
  978. extern SLang_Read_Line_Type * SLang_rline_save_line (SLang_RLine_Info_Type *);
  979. extern int SLang_init_readline (SLang_RLine_Info_Type *);
  980. extern int SLang_read_line (SLang_RLine_Info_Type *);
  981. extern int SLang_rline_insert (char *);
  982. extern void SLrline_redraw (SLang_RLine_Info_Type *);
  983. extern int SLang_Rline_Quit;
  984. /*}}}*/
  985. /*{{{ Low Level Screen Output Interface */
  986. extern unsigned long SLtt_Num_Chars_Output;
  987. extern int SLtt_Baud_Rate;
  988. typedef unsigned long SLtt_Char_Type;
  989. #define SLTT_BOLD_MASK 0x01000000UL
  990. #define SLTT_BLINK_MASK 0x02000000UL
  991. #define SLTT_ULINE_MASK 0x04000000UL
  992. #define SLTT_REV_MASK 0x08000000UL
  993. #define SLTT_ALTC_MASK 0x10000000UL
  994. extern int SLtt_Screen_Rows;
  995. extern int SLtt_Screen_Cols;
  996. extern int SLtt_Term_Cannot_Insert;
  997. extern int SLtt_Term_Cannot_Scroll;
  998. extern int SLtt_Use_Ansi_Colors;
  999. extern int SLtt_Ignore_Beep;
  1000. #if defined(REAL_UNIX_SYSTEM)
  1001. extern int SLtt_Force_Keypad_Init;
  1002. extern int SLang_TT_Write_FD;
  1003. #endif
  1004. #ifndef IBMPC_SYSTEM
  1005. extern char *SLtt_Graphics_Char_Pairs;
  1006. #endif
  1007. #ifndef __GO32__
  1008. #if defined(VMS) || defined(REAL_UNIX_SYSTEM)
  1009. extern int SLtt_Blink_Mode;
  1010. extern int SLtt_Use_Blink_For_ACS;
  1011. extern int SLtt_Newline_Ok;
  1012. extern int SLtt_Has_Alt_Charset;
  1013. extern int SLtt_Has_Status_Line; /* if 0, NO. If > 0, YES, IF -1, ?? */
  1014. # ifndef VMS
  1015. extern int SLtt_Try_Termcap;
  1016. # endif
  1017. #endif
  1018. #endif
  1019. #if defined(IBMPC_SYSTEM)
  1020. extern int SLtt_Msdos_Cheap_Video;
  1021. #endif
  1022. typedef unsigned short SLsmg_Char_Type;
  1023. #define SLSMG_EXTRACT_CHAR(x) ((x) & 0xFF)
  1024. #define SLSMG_EXTRACT_COLOR(x) (((x)>>8)&0xFF)
  1025. #define SLSMG_BUILD_CHAR(ch,color) (((SLsmg_Char_Type)(unsigned char)(ch))|((color)<<8))
  1026. extern int SLtt_flush_output (void);
  1027. extern void SLtt_set_scroll_region(int, int);
  1028. extern void SLtt_reset_scroll_region(void);
  1029. extern void SLtt_reverse_video (int);
  1030. extern void SLtt_bold_video (void);
  1031. extern void SLtt_begin_insert(void);
  1032. extern void SLtt_end_insert(void);
  1033. extern void SLtt_del_eol(void);
  1034. extern void SLtt_goto_rc (int, int);
  1035. extern void SLtt_delete_nlines(int);
  1036. extern void SLtt_delete_char(void);
  1037. extern void SLtt_erase_line(void);
  1038. extern void SLtt_normal_video(void);
  1039. extern void SLtt_cls(void);
  1040. extern void SLtt_beep(void);
  1041. extern void SLtt_reverse_index(int);
  1042. extern void SLtt_smart_puts(SLsmg_Char_Type *, SLsmg_Char_Type *, int, int);
  1043. extern void SLtt_write_string (char *);
  1044. extern void SLtt_putchar(char);
  1045. extern int SLtt_init_video (void);
  1046. extern int SLtt_reset_video (void);
  1047. extern void SLtt_get_terminfo(void);
  1048. extern void SLtt_get_screen_size (void);
  1049. extern int SLtt_set_cursor_visibility (int);
  1050. extern int SLtt_set_mouse_mode (int, int);
  1051. #if defined(VMS) || defined(REAL_UNIX_SYSTEM)
  1052. extern int SLtt_initialize (char *);
  1053. extern void SLtt_enable_cursor_keys(void);
  1054. extern void SLtt_set_term_vtxxx(int *);
  1055. extern void SLtt_set_color_esc (int, char *);
  1056. extern void SLtt_wide_width(void);
  1057. extern void SLtt_narrow_width(void);
  1058. extern void SLtt_set_alt_char_set (int);
  1059. extern int SLtt_write_to_status_line (char *, int);
  1060. extern void SLtt_disable_status_line (void);
  1061. # ifdef REAL_UNIX_SYSTEM
  1062. /* These are termcap/terminfo routines that assume SLtt_initialize has
  1063. * been called.
  1064. */
  1065. extern char *SLtt_tgetstr (char *);
  1066. extern int SLtt_tgetnum (char *);
  1067. extern int SLtt_tgetflag (char *);
  1068. /* The following are terminfo-only routines -- these prototypes will change
  1069. * in V2.x.
  1070. */
  1071. extern char *SLtt_tigetent (char *);
  1072. extern char *SLtt_tigetstr (char *, char **);
  1073. extern int SLtt_tigetnum (char *, char **);
  1074. # endif
  1075. #endif
  1076. extern SLtt_Char_Type SLtt_get_color_object (int);
  1077. extern void SLtt_set_color_object (int, SLtt_Char_Type);
  1078. extern void SLtt_set_color (int, char *, char *, char *);
  1079. extern void SLtt_set_mono (int, char *, SLtt_Char_Type);
  1080. extern void SLtt_add_color_attribute (int, SLtt_Char_Type);
  1081. extern void SLtt_set_color_fgbg (int, SLtt_Char_Type, SLtt_Char_Type);
  1082. /*}}}*/
  1083. /*{{{ SLang Preprocessor Interface */
  1084. typedef struct
  1085. {
  1086. int this_level;
  1087. int exec_level;
  1088. int prev_exec_level;
  1089. char preprocess_char;
  1090. char comment_char;
  1091. unsigned char flags;
  1092. #define SLPREP_BLANK_LINES_OK 1
  1093. #define SLPREP_COMMENT_LINES_OK 2
  1094. }
  1095. SLPreprocess_Type;
  1096. extern int SLprep_open_prep (SLPreprocess_Type *);
  1097. extern void SLprep_close_prep (SLPreprocess_Type *);
  1098. extern int SLprep_line_ok (char *, SLPreprocess_Type *);
  1099. extern int SLdefine_for_ifdef (char *);
  1100. /* Adds a string to the SLang #ifdef preparsing defines. SLang already
  1101. defines MSDOS, UNIX, and VMS on the appropriate system. */
  1102. extern int (*SLprep_exists_hook) (char *, char);
  1103. /*}}}*/
  1104. /*{{{ SLsmg Screen Management Functions */
  1105. extern void SLsmg_fill_region (int, int, unsigned int, unsigned int, unsigned char);
  1106. extern void SLsmg_set_char_set (int);
  1107. #ifndef IBMPC_SYSTEM
  1108. extern int SLsmg_Scroll_Hash_Border;
  1109. #endif
  1110. extern int SLsmg_suspend_smg (void);
  1111. extern int SLsmg_resume_smg (void);
  1112. extern void SLsmg_erase_eol (void);
  1113. extern void SLsmg_gotorc (int, int);
  1114. extern void SLsmg_erase_eos (void);
  1115. extern void SLsmg_reverse_video (void);
  1116. extern void SLsmg_set_color (int);
  1117. extern void SLsmg_normal_video (void);
  1118. extern void SLsmg_printf (char *, ...);
  1119. extern void SLsmg_vprintf (char *, va_list);
  1120. extern void SLsmg_write_string (char *);
  1121. extern void SLsmg_write_nstring (char *, unsigned int);
  1122. extern void SLsmg_write_char (char);
  1123. extern void SLsmg_write_nchars (char *, unsigned int);
  1124. extern void SLsmg_write_wrapped_string (char *, int, int, unsigned int, unsigned int, int);
  1125. extern void SLsmg_cls (void);
  1126. extern void SLsmg_refresh (void);
  1127. extern void SLsmg_touch_lines (int, unsigned int);
  1128. extern void SLsmg_touch_screen (void);
  1129. extern int SLsmg_init_smg (void);
  1130. extern int SLsmg_reinit_smg (void);
  1131. extern void SLsmg_reset_smg (void);
  1132. extern SLsmg_Char_Type SLsmg_char_at(void);
  1133. extern void SLsmg_set_screen_start (int *, int *);
  1134. extern void SLsmg_draw_hline (unsigned int);
  1135. extern void SLsmg_draw_vline (int);
  1136. extern void SLsmg_draw_object (int, int, unsigned char);
  1137. extern void SLsmg_draw_box (int, int, unsigned int, unsigned int);
  1138. extern int SLsmg_get_column(void);
  1139. extern int SLsmg_get_row(void);
  1140. extern void SLsmg_forward (int);
  1141. extern void SLsmg_write_color_chars (SLsmg_Char_Type *, unsigned int);
  1142. extern unsigned int SLsmg_read_raw (SLsmg_Char_Type *, unsigned int);
  1143. extern unsigned int SLsmg_write_raw (SLsmg_Char_Type *, unsigned int);
  1144. extern void SLsmg_set_color_in_region (int, int, int, unsigned int, unsigned int);
  1145. extern int SLsmg_Display_Eight_Bit;
  1146. extern int SLsmg_Tab_Width;
  1147. #define SLSMG_NEWLINE_IGNORED 0 /* default */
  1148. #define SLSMG_NEWLINE_MOVES 1 /* moves to next line, column 0 */
  1149. #define SLSMG_NEWLINE_SCROLLS 2 /* moves but scrolls at bottom of screen */
  1150. #define SLSMG_NEWLINE_PRINTABLE 3 /* prints as ^J */
  1151. extern int SLsmg_Newline_Behavior;
  1152. extern int SLsmg_Backspace_Moves;
  1153. #ifdef IBMPC_SYSTEM
  1154. # define SLSMG_HLINE_CHAR 0xC4
  1155. # define SLSMG_VLINE_CHAR 0xB3
  1156. # define SLSMG_ULCORN_CHAR 0xDA
  1157. # define SLSMG_URCORN_CHAR 0xBF
  1158. # define SLSMG_LLCORN_CHAR 0xC0
  1159. # define SLSMG_LRCORN_CHAR 0xD9
  1160. # define SLSMG_RTEE_CHAR 0xB4
  1161. # define SLSMG_LTEE_CHAR 0xC3
  1162. # define SLSMG_UTEE_CHAR 0xC2
  1163. # define SLSMG_DTEE_CHAR 0xC1
  1164. # define SLSMG_PLUS_CHAR 0xC5
  1165. /* There are several to choose from: 0xB0, 0xB1, and 0xB2 */
  1166. # define SLSMG_CKBRD_CHAR 0xB0
  1167. # define SLSMG_DIAMOND_CHAR 0x04
  1168. # define SLSMG_DEGREE_CHAR 0xF8
  1169. # define SLSMG_PLMINUS_CHAR 0xF1
  1170. # define SLSMG_BULLET_CHAR 0xF9
  1171. # define SLSMG_LARROW_CHAR 0x1B
  1172. # define SLSMG_RARROW_CHAR 0x1A
  1173. # define SLSMG_DARROW_CHAR 0x19
  1174. # define SLSMG_UARROW_CHAR 0x18
  1175. # define SLSMG_BOARD_CHAR 0xB2
  1176. # define SLSMG_BLOCK_CHAR 0xDB
  1177. #else
  1178. # if defined(AMIGA)
  1179. # define SLSMG_HLINE_CHAR '-'
  1180. # define SLSMG_VLINE_CHAR '|'
  1181. # define SLSMG_ULCORN_CHAR '+'
  1182. # define SLSMG_URCORN_CHAR '+'
  1183. # define SLSMG_LLCORN_CHAR '+'
  1184. # define SLSMG_LRCORN_CHAR '+'
  1185. # define SLSMG_CKBRD_CHAR '#'
  1186. # define SLSMG_RTEE_CHAR '+'
  1187. # define SLSMG_LTEE_CHAR '+'
  1188. # define SLSMG_UTEE_CHAR '+'
  1189. # define SLSMG_DTEE_CHAR '+'
  1190. # define SLSMG_PLUS_CHAR '+'
  1191. # define SLSMG_DIAMOND_CHAR '+'
  1192. # define SLSMG_DEGREE_CHAR '\\'
  1193. # define SLSMG_PLMINUS_CHAR '#'
  1194. # define SLSMG_BULLET_CHAR 'o'
  1195. # define SLSMG_LARROW_CHAR '<'
  1196. # define SLSMG_RARROW_CHAR '>'
  1197. # define SLSMG_DARROW_CHAR 'v'
  1198. # define SLSMG_UARROW_CHAR '^'
  1199. # define SLSMG_BOARD_CHAR '#'
  1200. # define SLSMG_BLOCK_CHAR '#'
  1201. # else
  1202. # define SLSMG_HLINE_CHAR 'q'
  1203. # define SLSMG_VLINE_CHAR 'x'
  1204. # define SLSMG_ULCORN_CHAR 'l'
  1205. # define SLSMG_URCORN_CHAR 'k'
  1206. # define SLSMG_LLCORN_CHAR 'm'
  1207. # define SLSMG_LRCORN_CHAR 'j'
  1208. # define SLSMG_CKBRD_CHAR 'a'
  1209. # define SLSMG_RTEE_CHAR 'u'
  1210. # define SLSMG_LTEE_CHAR 't'
  1211. # define SLSMG_UTEE_CHAR 'w'
  1212. # define SLSMG_DTEE_CHAR 'v'
  1213. # define SLSMG_PLUS_CHAR 'n'
  1214. # define SLSMG_DIAMOND_CHAR '`'
  1215. # define SLSMG_DEGREE_CHAR 'f'
  1216. # define SLSMG_PLMINUS_CHAR 'g'
  1217. # define SLSMG_BULLET_CHAR '~'
  1218. # define SLSMG_LARROW_CHAR ','
  1219. # define SLSMG_RARROW_CHAR '+'
  1220. # define SLSMG_DARROW_CHAR '.'
  1221. # define SLSMG_UARROW_CHAR '-'
  1222. # define SLSMG_BOARD_CHAR 'h'
  1223. # define SLSMG_BLOCK_CHAR '0'
  1224. # endif /* AMIGA */
  1225. #endif /* IBMPC_SYSTEM */
  1226. #ifndef IBMPC_SYSTEM
  1227. # define SLSMG_COLOR_BLACK 0x000000
  1228. # define SLSMG_COLOR_RED 0x000001
  1229. # define SLSMG_COLOR_GREEN 0x000002
  1230. # define SLSMG_COLOR_BROWN 0x000003
  1231. # define SLSMG_COLOR_BLUE 0x000004
  1232. # define SLSMG_COLOR_MAGENTA 0x000005
  1233. # define SLSMG_COLOR_CYAN 0x000006
  1234. # define SLSMG_COLOR_LGRAY 0x000007
  1235. # define SLSMG_COLOR_GRAY 0x000008
  1236. # define SLSMG_COLOR_BRIGHT_RED 0x000009
  1237. # define SLSMG_COLOR_BRIGHT_GREEN 0x00000A
  1238. # define SLSMG_COLOR_BRIGHT_BROWN 0x00000B
  1239. # define SLSMG_COLOR_BRIGHT_BLUE 0x00000C
  1240. # define SLSMG_COLOR_BRIGHT_CYAN 0x00000D
  1241. # define SLSMG_COLOR_BRIGHT_MAGENTA 0x00000E
  1242. # define SLSMG_COLOR_BRIGHT_WHITE 0x00000F
  1243. #endif
  1244. typedef struct
  1245. {
  1246. void (*tt_normal_video)(void);
  1247. void (*tt_set_scroll_region)(int, int);
  1248. void (*tt_goto_rc)(int, int);
  1249. void (*tt_reverse_index)(int);
  1250. void (*tt_reset_scroll_region)(void);
  1251. void (*tt_delete_nlines)(int);
  1252. void (*tt_cls) (void);
  1253. void (*tt_del_eol) (void);
  1254. void (*tt_smart_puts) (SLsmg_Char_Type *, SLsmg_Char_Type *, int, int);
  1255. int (*tt_flush_output) (void);
  1256. int (*tt_reset_video) (void);
  1257. int (*tt_init_video) (void);
  1258. int *tt_screen_rows;
  1259. int *tt_screen_cols;
  1260. int *tt_term_cannot_scroll;
  1261. int *tt_has_alt_charset;
  1262. int *tt_use_blink_for_acs;
  1263. char **tt_graphic_char_pairs;
  1264. long reserved[4];
  1265. }
  1266. SLsmg_Term_Type;
  1267. extern void SLsmg_set_terminal_info (SLsmg_Term_Type *);
  1268. /*}}}*/
  1269. /*{{{ SLang Keypad Interface */
  1270. #define SL_KEY_ERR 0xFFFF
  1271. #define SL_KEY_UP 0x101
  1272. #define SL_KEY_DOWN 0x102
  1273. #define SL_KEY_LEFT 0x103
  1274. #define SL_KEY_RIGHT 0x104
  1275. #define SL_KEY_PPAGE 0x105
  1276. #define SL_KEY_NPAGE 0x106
  1277. #define SL_KEY_HOME 0x107
  1278. #define SL_KEY_END 0x108
  1279. #define SL_KEY_A1 0x109
  1280. #define SL_KEY_A3 0x10A
  1281. #define SL_KEY_B2 0x10B
  1282. #define SL_KEY_C1 0x10C
  1283. #define SL_KEY_C3 0x10D
  1284. #define SL_KEY_REDO 0x10E
  1285. #define SL_KEY_UNDO 0x10F
  1286. #define SL_KEY_BACKSPACE 0x110
  1287. #define SL_KEY_ENTER 0x111
  1288. #define SL_KEY_IC 0x112
  1289. #define SL_KEY_DELETE 0x113
  1290. #define SL_KEY_F0 0x200
  1291. #define SL_KEY_F(X) (SL_KEY_F0 + X)
  1292. /* I do not intend to use keysymps > 0x1000. Applications can use those. */
  1293. /* Returns 0 upon success or -1 upon error. */
  1294. extern int SLkp_define_keysym (char *, unsigned int);
  1295. /* This function must be called AFTER SLtt_get_terminfo and not before. */
  1296. extern int SLkp_init (void);
  1297. /* By default, SLang_getkey is used as the low-level function. This hook
  1298. * allows you to specify something else.
  1299. */
  1300. extern void SLkp_set_getkey_function (int (*)(void));
  1301. /* This function uses SLang_getkey and assumes that what ever initialization
  1302. * is required for SLang_getkey has been performed. If you do not want
  1303. * SLang_getkey to be used, then specify another function via
  1304. * SLkp_set_getkey_function.
  1305. */
  1306. extern int SLkp_getkey (void);
  1307. /*}}}*/
  1308. /*{{{ SLang Scroll Interface */
  1309. typedef struct _SLscroll_Type
  1310. {
  1311. struct _SLscroll_Type *next;
  1312. struct _SLscroll_Type *prev;
  1313. unsigned int flags;
  1314. }
  1315. SLscroll_Type;
  1316. typedef struct
  1317. {
  1318. unsigned int flags;
  1319. SLscroll_Type *top_window_line; /* list element at top of window */
  1320. SLscroll_Type *bot_window_line; /* list element at bottom of window */
  1321. SLscroll_Type *current_line; /* current list element */
  1322. SLscroll_Type *lines; /* first list element */
  1323. unsigned int nrows; /* number of rows in window */
  1324. unsigned int hidden_mask; /* applied to flags in SLscroll_Type */
  1325. unsigned int line_num; /* current line number (visible) */
  1326. unsigned int num_lines; /* total number of lines (visible) */
  1327. unsigned int window_row; /* row of current_line in window */
  1328. unsigned int border; /* number of rows that form scroll border */
  1329. int cannot_scroll; /* should window scroll or recenter */
  1330. }
  1331. SLscroll_Window_Type;
  1332. extern int SLscroll_find_top (SLscroll_Window_Type *);
  1333. extern int SLscroll_find_line_num (SLscroll_Window_Type *);
  1334. extern unsigned int SLscroll_next_n (SLscroll_Window_Type *, unsigned int);
  1335. extern unsigned int SLscroll_prev_n (SLscroll_Window_Type *, unsigned int);
  1336. extern int SLscroll_pageup (SLscroll_Window_Type *);
  1337. extern int SLscroll_pagedown (SLscroll_Window_Type *);
  1338. /*}}}*/
  1339. /*{{{ Signal Routines */
  1340. typedef void SLSig_Fun_Type (int);
  1341. extern SLSig_Fun_Type *SLsignal (int, SLSig_Fun_Type *);
  1342. extern SLSig_Fun_Type *SLsignal_intr (int, SLSig_Fun_Type *);
  1343. extern int SLsig_block_signals (void);
  1344. extern int SLsig_unblock_signals (void);
  1345. extern int SLsystem (char *);
  1346. extern char *SLerrno_strerror (int);
  1347. extern int SLerrno_set_errno (int);
  1348. /*}}}*/
  1349. /*{{{ Interpreter Macro Definitions */
  1350. /* The definitions here are for objects that may be on the run-time stack.
  1351. * They are actually sub_types of literal and data main_types. The actual
  1352. * numbers are historical.
  1353. */
  1354. #define SLANG_UNDEFINED_TYPE 0x00 /* MUST be 0 */
  1355. #define SLANG_VOID_TYPE 0x01 /* also matches ANY type */
  1356. #define SLANG_INT_TYPE 0x02
  1357. #define SLANG_DOUBLE_TYPE 0x03
  1358. #define SLANG_CHAR_TYPE 0x04
  1359. #define SLANG_INTP_TYPE 0x05
  1360. /* An object of SLANG_INTP_TYPE should never really occur on the stack. Rather,
  1361. * the integer to which it refers will be there instead. It is defined here
  1362. * because it is a valid type for MAKE_VARIABLE.
  1363. */
  1364. #define SLANG_REF_TYPE 0x06
  1365. /* SLANG_REF_TYPE refers to an object on the stack that is a pointer (reference)
  1366. * to some other object.
  1367. */
  1368. #define SLANG_COMPLEX_TYPE 0x07
  1369. #define SLANG_NULL_TYPE 0x08
  1370. #define SLANG_UCHAR_TYPE 0x09
  1371. #define SLANG_SHORT_TYPE 0x0A
  1372. #define SLANG_USHORT_TYPE 0x0B
  1373. #define SLANG_UINT_TYPE 0x0C
  1374. #define SLANG_LONG_TYPE 0x0D
  1375. #define SLANG_ULONG_TYPE 0x0E
  1376. #define SLANG_STRING_TYPE 0x0F
  1377. #define SLANG_FLOAT_TYPE 0x10
  1378. #define SLANG_STRUCT_TYPE 0x11
  1379. #define SLANG_ISTRUCT_TYPE 0x12
  1380. #define SLANG_ARRAY_TYPE 0x20
  1381. #define SLANG_DATATYPE_TYPE 0x21
  1382. #define SLANG_FILE_PTR_TYPE 0x22
  1383. #define SLANG_ASSOC_TYPE 0x23
  1384. #define SLANG_ANY_TYPE 0x24
  1385. #define SLANG_BSTRING_TYPE 0x25
  1386. #define SLANG_FILE_FD_TYPE 0x26
  1387. /* Compatibility */
  1388. #ifdef FLOAT_TYPE
  1389. # undef FLOAT_TYPE
  1390. #endif
  1391. #define VOID_TYPE SLANG_VOID_TYPE
  1392. #define INT_TYPE SLANG_INT_TYPE
  1393. #define INTP_TYPE SLANG_INTP_TYPE
  1394. #define FLOAT_TYPE SLANG_DOUBLE_TYPE
  1395. #define ARRAY_TYPE SLANG_ARRAY_TYPE
  1396. #define CHAR_TYPE SLANG_CHAR_TYPE
  1397. #define STRING_TYPE SLANG_STRING_TYPE
  1398. /* I am reserving values greater than or equal to 128 for user applications.
  1399. * The first 127 are reserved for S-Lang.
  1400. */
  1401. /* Binary and Unary Subtypes */
  1402. /* Since the application can define new types and can overload the binary
  1403. * and unary operators, these definitions must be present in this file.
  1404. * The current implementation assumes both unary and binary are distinct.
  1405. */
  1406. #define SLANG_PLUS 0x01
  1407. #define SLANG_MINUS 0x02
  1408. #define SLANG_TIMES 0x03
  1409. #define SLANG_DIVIDE 0x04
  1410. #define SLANG_EQ 0x05
  1411. #define SLANG_NE 0x06
  1412. #define SLANG_GT 0x07
  1413. #define SLANG_GE 0x08
  1414. #define SLANG_LT 0x09
  1415. #define SLANG_LE 0x0A
  1416. #define SLANG_POW 0x0B
  1417. #define SLANG_OR 0x0C
  1418. #define SLANG_AND 0x0D
  1419. #define SLANG_BAND 0x0E
  1420. #define SLANG_BOR 0x0F
  1421. #define SLANG_BXOR 0x10
  1422. #define SLANG_SHL 0x11
  1423. #define SLANG_SHR 0x12
  1424. #define SLANG_MOD 0x13
  1425. /* UNARY subtypes (may be overloaded) */
  1426. #define SLANG_PLUSPLUS 0x20
  1427. #define SLANG_MINUSMINUS 0x21
  1428. #define SLANG_ABS 0x22
  1429. #define SLANG_SIGN 0x23
  1430. #define SLANG_SQR 0x24
  1431. #define SLANG_MUL2 0x25
  1432. #define SLANG_CHS 0x26
  1433. #define SLANG_NOT 0x27
  1434. #define SLANG_BNOT 0x28
  1435. extern char *SLang_Error_Message;
  1436. int SLadd_intrinsic_variable (char *, VOID_STAR, unsigned char, int);
  1437. int SLadd_intrinsic_function (char *, FVOID_STAR, unsigned char, unsigned int,...);
  1438. int SLns_add_intrinsic_variable (SLang_NameSpace_Type *, char *, VOID_STAR, unsigned char, int);
  1439. int SLns_add_intrinsic_function (SLang_NameSpace_Type *, char *, FVOID_STAR, unsigned char, unsigned int,...);
  1440. #define MAKE_INTRINSIC_N(n,f,out,in,a1,a2,a3,a4,a5,a6,a7) \
  1441. {(n), NULL, SLANG_INTRINSIC, (FVOID_STAR) (f), \
  1442. {a1,a2,a3,a4,a5,a6,a7}, (in), (out)}
  1443. #define MAKE_INTRINSIC_7(n,f,out,a1,a2,a3,a4,a5,a6,a7) \
  1444. MAKE_INTRINSIC_N(n,f,out,7,a1,a2,a3,a4,a5,a6,a7)
  1445. #define MAKE_INTRINSIC_6(n,f,out,a1,a2,a3,a4,a5,a6) \
  1446. MAKE_INTRINSIC_N(n,f,out,6,a1,a2,a3,a4,a5,a6,0)
  1447. #define MAKE_INTRINSIC_5(n,f,out,a1,a2,a3,a4,a5) \
  1448. MAKE_INTRINSIC_N(n,f,out,5,a1,a2,a3,a4,a5,0,0)
  1449. #define MAKE_INTRINSIC_4(n,f,out,a1,a2,a3,a4) \
  1450. MAKE_INTRINSIC_N(n,f,out,4,a1,a2,a3,a4,0,0,0)
  1451. #define MAKE_INTRINSIC_3(n,f,out,a1,a2,a3) \
  1452. MAKE_INTRINSIC_N(n,f,out,3,a1,a2,a3,0,0,0,0)
  1453. #define MAKE_INTRINSIC_2(n,f,out,a1,a2) \
  1454. MAKE_INTRINSIC_N(n,f,out,2,a1,a2,0,0,0,0,0)
  1455. #define MAKE_INTRINSIC_1(n,f,out,a1) \
  1456. MAKE_INTRINSIC_N(n,f,out,1,a1,0,0,0,0,0,0)
  1457. #define MAKE_INTRINSIC_0(n,f,out) \
  1458. MAKE_INTRINSIC_N(n,f,out,0,0,0,0,0,0,0,0)
  1459. #define MAKE_INTRINSIC_S(n,f,r) \
  1460. MAKE_INTRINSIC_1(n,f,r,SLANG_STRING_TYPE)
  1461. #define MAKE_INTRINSIC_I(n,f,r) \
  1462. MAKE_INTRINSIC_1(n,f,r,SLANG_INT_TYPE)
  1463. #define MAKE_INTRINSIC_SS(n,f,r) \
  1464. MAKE_INTRINSIC_2(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE)
  1465. #define MAKE_INTRINSIC_SI(n,f,r) \
  1466. MAKE_INTRINSIC_2(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE)
  1467. #define MAKE_INTRINSIC_IS(n,f,r) \
  1468. MAKE_INTRINSIC_2(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE)
  1469. #define MAKE_INTRINSIC_II(n,f,r) \
  1470. MAKE_INTRINSIC_2(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE)
  1471. #define MAKE_INTRINSIC_SSS(n,f,r) \
  1472. MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE,SLANG_STRING_TYPE)
  1473. #define MAKE_INTRINSIC_SSI(n,f,r) \
  1474. MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_STRING_TYPE,SLANG_INT_TYPE)
  1475. #define MAKE_INTRINSIC_SIS(n,f,r) \
  1476. MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE,SLANG_STRING_TYPE)
  1477. #define MAKE_INTRINSIC_SII(n,f,r) \
  1478. MAKE_INTRINSIC_3(n,f,r,SLANG_STRING_TYPE,SLANG_INT_TYPE,SLANG_INT_TYPE)
  1479. #define MAKE_INTRINSIC_ISS(n,f,r) \
  1480. MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE,SLANG_STRING_TYPE)
  1481. #define MAKE_INTRINSIC_ISI(n,f,r) \
  1482. MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_STRING_TYPE,SLANG_INT_TYPE)
  1483. #define MAKE_INTRINSIC_IIS(n,f,r) \
  1484. MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE,SLANG_STRING_TYPE)
  1485. #define MAKE_INTRINSIC_III(n,f,r) \
  1486. MAKE_INTRINSIC_3(n,f,r,SLANG_INT_TYPE,SLANG_INT_TYPE,SLANG_INT_TYPE)
  1487. #define MAKE_INTRINSIC(n, f, out, in) \
  1488. MAKE_INTRINSIC_N(n,f,out,in,0,0,0,0,0,0,0)
  1489. #define MAKE_VARIABLE(n, v, t, r) \
  1490. {n, NULL, SLANG_IVARIABLE + (r), (VOID_STAR)(v), (t)}
  1491. #define MAKE_APP_UNARY(n,op) \
  1492. {(n), NULL, SLANG_APP_UNARY, (op)}
  1493. #define MAKE_MATH_UNARY(n,op) \
  1494. {(n), NULL, SLANG_MATH_UNARY, (op)}
  1495. #define MAKE_ICONSTANT(n,val) \
  1496. {(n),NULL, SLANG_ICONSTANT, (val)}
  1497. #define MAKE_DCONSTANT(n,val) \
  1498. {(n),NULL, SLANG_DCONSTANT, (val)}
  1499. #ifndef offsetof
  1500. # define offsetof(T,F) ((unsigned int)((char *)&((T *)0L)->F - (char *)0L))
  1501. #endif
  1502. #define MAKE_ISTRUCT_FIELD(s,f,n,t,r) {(n), offsetof(s,f), (t), (r)}
  1503. #define SLANG_END_TABLE {NULL}
  1504. #define SLANG_END_INTRIN_FUN_TABLE MAKE_INTRINSIC_0(NULL,NULL,0)
  1505. #define SLANG_END_DCONST_TABLE MAKE_DCONSTANT(NULL,0)
  1506. #define SLANG_END_MATH_UNARY_TABLE MAKE_MATH_UNARY(NULL,0)
  1507. #define SLANG_END_INTRIN_VAR_TABLE MAKE_VARIABLE(NULL,NULL,0,0)
  1508. #define SLANG_END_ICONST_TABLE MAKE_ICONSTANT(NULL,0)
  1509. #define SLANG_END_ISTRUCT_TABLE {NULL, 0, 0, 0}
  1510. /*}}}*/
  1511. /*{{{ Upper/Lowercase Functions */
  1512. extern void SLang_define_case(int *, int *);
  1513. extern void SLang_init_case_tables (void);
  1514. extern unsigned char _SLChg_UCase_Lut[256];
  1515. extern unsigned char _SLChg_LCase_Lut[256];
  1516. #define UPPER_CASE(x) (_SLChg_UCase_Lut[(unsigned char) (x)])
  1517. #define LOWER_CASE(x) (_SLChg_LCase_Lut[(unsigned char) (x)])
  1518. #define CHANGE_CASE(x) (((x) == _SLChg_LCase_Lut[(unsigned char) (x)]) ?\
  1519. _SLChg_UCase_Lut[(unsigned char) (x)] : _SLChg_LCase_Lut[(unsigned char) (x)])
  1520. /*}}}*/
  1521. /*{{{ Regular Expression Interface */
  1522. typedef struct
  1523. {
  1524. /* These must be set by calling routine. */
  1525. unsigned char *pat; /* regular expression pattern */
  1526. unsigned char *buf; /* buffer for compiled regexp */
  1527. unsigned int buf_len; /* length of buffer */
  1528. int case_sensitive; /* 1 if match is case sensitive */
  1529. /* The rest are set by SLang_regexp_compile */
  1530. int must_match; /* 1 if line must contain substring */
  1531. int must_match_bol; /* true if it must match beginning of line */
  1532. unsigned char must_match_str[16]; /* 15 char null term substring */
  1533. int osearch; /* 1 if ordinary search suffices */
  1534. unsigned int min_length; /* minimum length the match must be */
  1535. int beg_matches[10]; /* offset of start of \( */
  1536. unsigned int end_matches[10]; /* length of nth submatch
  1537. * Note that the entire match corresponds
  1538. * to \0
  1539. */
  1540. int offset; /* offset to be added to beg_matches */
  1541. int reserved[10];
  1542. } SLRegexp_Type;
  1543. extern unsigned char *SLang_regexp_match(unsigned char *,
  1544. unsigned int,
  1545. SLRegexp_Type *);
  1546. /* Returns 0 upon success. If failure, the offset into the
  1547. * pattern is returned (start = 1).
  1548. */
  1549. extern int SLang_regexp_compile (SLRegexp_Type *);
  1550. extern char *SLregexp_quote_string (char *, char *, unsigned int);
  1551. /*}}}*/
  1552. /*{{{ SLang Command Interface */
  1553. struct _SLcmd_Cmd_Type; /* Pre-declaration is needed below */
  1554. typedef struct
  1555. {
  1556. struct _SLcmd_Cmd_Type *table;
  1557. int argc;
  1558. /* Version 2.0 needs to use a union!! */
  1559. char **string_args;
  1560. int *int_args;
  1561. double *double_args;
  1562. unsigned char *arg_type;
  1563. unsigned long reserved[4];
  1564. } SLcmd_Cmd_Table_Type;
  1565. typedef struct _SLcmd_Cmd_Type
  1566. {
  1567. int (*cmdfun)(int, SLcmd_Cmd_Table_Type *);
  1568. char *cmd;
  1569. char *arg_type;
  1570. } SLcmd_Cmd_Type;
  1571. extern int SLcmd_execute_string (char *, SLcmd_Cmd_Table_Type *);
  1572. /*}}}*/
  1573. /*{{{ SLang Search Interface */
  1574. typedef struct
  1575. {
  1576. int cs; /* case sensitive */
  1577. unsigned char key[256];
  1578. int ind[256];
  1579. int key_len;
  1580. int dir;
  1581. } SLsearch_Type;
  1582. extern int SLsearch_init (char *, int, int, SLsearch_Type *);
  1583. /* This routine must first be called before any search can take place.
  1584. * The second parameter specifies the direction of the search: greater than
  1585. * zero for a forwrd search and less than zero for a backward search. The
  1586. * third parameter specifies whether the search is case sensitive or not.
  1587. * The last parameter is a pointer to a structure that is filled by this
  1588. * function and it is this structure that must be passed to SLsearch.
  1589. */
  1590. extern unsigned char *SLsearch (unsigned char *, unsigned char *, SLsearch_Type *);
  1591. /* To use this routine, you must first call 'SLsearch_init'. Then the first
  1592. * two parameters p1 and p2 serve to define the region over which the search
  1593. * is to take place. The third parameter is the structure that was previously
  1594. * initialized by SLsearch_init.
  1595. *
  1596. * The routine returns a pointer to the match if found otherwise it returns
  1597. * NULL.
  1598. */
  1599. /*}}}*/
  1600. /*{{{ SLang Pathname Interface */
  1601. /* These function return pointers to the original space */
  1602. extern char *SLpath_basename (char *);
  1603. extern char *SLpath_extname (char *);
  1604. extern int SLpath_is_absolute_path (char *);
  1605. /* These return malloced strings--- NOT slstrings */
  1606. extern char *SLpath_dircat (char *, char *);
  1607. extern char *SLpath_find_file_in_path (char *, char *);
  1608. extern char *SLpath_dirname (char *);
  1609. extern int SLpath_file_exists (char *);
  1610. extern char *SLpath_pathname_sans_extname (char *);
  1611. /*}}}*/
  1612. extern int SLang_set_module_load_path (char *);
  1613. #define SLANG_MODULE(name) \
  1614. extern int init_##name##_module_ns (char *); \
  1615. extern void deinit_##name##_module (void)
  1616. #if 0
  1617. {
  1618. #endif
  1619. #ifdef __cplusplus
  1620. }
  1621. #endif
  1622. #endif /* _DAVIS_SLANG_H_ */