| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  | /*
 | 
					
						
							| 
									
										
										
										
											2007-02-11 08:30:18 +00:00
										 |  |  |  * $Id: lsp.h,v 1.38 2007-02-11 08:30:18 bacon Exp $ | 
					
						
							| 
									
										
										
										
											2007-02-03 10:52:36 +00:00
										 |  |  |  * | 
					
						
							|  |  |  |  * {License} | 
					
						
							| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | #ifndef _ASE_LSP_LSP_H_
 | 
					
						
							|  |  |  | #define _ASE_LSP_LSP_H_
 | 
					
						
							| 
									
										
										
										
											2005-09-17 17:50:45 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-25 13:42:31 +00:00
										 |  |  | #include <ase/types.h>
 | 
					
						
							|  |  |  | #include <ase/macros.h>
 | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | typedef struct ase_lsp_t ase_lsp_t; | 
					
						
							|  |  |  | typedef struct ase_lsp_obj_t ase_lsp_obj_t; | 
					
						
							| 
									
										
										
										
											2007-02-01 08:52:10 +00:00
										 |  |  | typedef struct ase_lsp_prmfns_t ase_lsp_prmfns_t; | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | typedef ase_ssize_t (*ase_lsp_io_t) ( | 
					
						
							|  |  |  | 	int cmd, void* arg, ase_char_t* data, ase_size_t count); | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-01 08:52:10 +00:00
										 |  |  | typedef void* (*ase_lsp_malloc_t)  (ase_size_t n, void* custom_data);  | 
					
						
							|  |  |  | typedef void* (*ase_lsp_realloc_t) (void* ptr, ase_size_t n, void* custom_data); | 
					
						
							|  |  |  | typedef void  (*ase_lsp_free_t)    (void* ptr, void* custom_data);  | 
					
						
							|  |  |  | typedef void* (*ase_lsp_memcpy_t)  (void* dst, const void* src, ase_size_t n); | 
					
						
							|  |  |  | typedef void* (*ase_lsp_memset_t)  (void* dst, int val, ase_size_t n); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef ase_bool_t (*ase_lsp_isctype_t) (ase_cint_t c); | 
					
						
							|  |  |  | typedef ase_cint_t (*ase_lsp_toctype_t) (ase_cint_t c); | 
					
						
							|  |  |  | typedef ase_real_t (*ase_lsp_pow_t) (ase_real_t x, ase_real_t y); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | typedef int (*ase_lsp_sprintf_t) ( | 
					
						
							|  |  |  | 	ase_char_t* buf, ase_size_t size, const ase_char_t* fmt, ...); | 
					
						
							|  |  |  | typedef void (*ase_lsp_aprintf_t) (const ase_char_t* fmt, ...);  | 
					
						
							|  |  |  | typedef void (*ase_lsp_dprintf_t) (const ase_char_t* fmt, ...);  | 
					
						
							|  |  |  | typedef void (*ase_lsp_abort_t) (void* custom_data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | struct ase_lsp_prmfns_t | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | { | 
					
						
							|  |  |  | 	/* memory */ | 
					
						
							| 
									
										
										
										
											2007-02-01 08:52:10 +00:00
										 |  |  | 	ase_lsp_malloc_t  malloc; | 
					
						
							|  |  |  | 	ase_lsp_realloc_t realloc; | 
					
						
							|  |  |  | 	ase_lsp_free_t    free; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	ase_lsp_memcpy_t  memcpy; | 
					
						
							|  |  |  | 	ase_lsp_memset_t  memset; | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* character class */ | 
					
						
							| 
									
										
										
										
											2007-02-01 08:52:10 +00:00
										 |  |  | 	ase_lsp_isctype_t is_upper; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_lower; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_alpha; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_digit; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_xdigit; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_alnum; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_space; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_print; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_graph; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_cntrl; | 
					
						
							|  |  |  | 	ase_lsp_isctype_t is_punct; | 
					
						
							|  |  |  | 	ase_lsp_toctype_t to_upper; | 
					
						
							|  |  |  | 	ase_lsp_toctype_t to_lower; | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	/* utilities */ | 
					
						
							| 
									
										
										
										
											2007-02-01 08:52:10 +00:00
										 |  |  | 	ase_lsp_sprintf_t sprintf; | 
					
						
							|  |  |  | 	ase_lsp_aprintf_t aprintf; | 
					
						
							|  |  |  | 	ase_lsp_dprintf_t dprintf; | 
					
						
							|  |  |  | 	ase_lsp_abort_t abort; | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	void* custom_data; | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | /* io function commands */ | 
					
						
							|  |  |  | enum  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | 	ASE_LSP_IO_OPEN   = 0, | 
					
						
							|  |  |  | 	ASE_LSP_IO_CLOSE  = 1, | 
					
						
							|  |  |  | 	ASE_LSP_IO_READ   = 2, | 
					
						
							|  |  |  | 	ASE_LSP_IO_WRITE  = 3 | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | /* option code */ | 
					
						
							|  |  |  | enum | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | 	ASE_LSP_UNDEFSYMBOL = (1 << 0) | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | }; | 
					
						
							| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-23 14:42:38 +00:00
										 |  |  | /* error code */ | 
					
						
							| 
									
										
										
										
											2005-09-18 08:10:50 +00:00
										 |  |  | enum  | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | 	ASE_LSP_ENOERR, | 
					
						
							|  |  |  | 	ASE_LSP_ENOMEM, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-03 10:52:36 +00:00
										 |  |  | 	ASE_LSP_EEXIT, | 
					
						
							|  |  |  | 	ASE_LSP_EEND, | 
					
						
							| 
									
										
										
										
											2007-02-10 13:52:41 +00:00
										 |  |  | 	ASE_LSP_EENDSTR, | 
					
						
							| 
									
										
										
										
											2007-02-11 07:36:55 +00:00
										 |  |  | 	ASE_LSP_ENOINP, | 
					
						
							|  |  |  | 	ASE_LSP_EINPUT, | 
					
						
							|  |  |  | 	ASE_LSP_ENOOUTP, | 
					
						
							|  |  |  | 	ASE_LSP_EOUTPUT, | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-03 10:52:36 +00:00
										 |  |  | 	ASE_LSP_ESYNTAX, | 
					
						
							| 
									
										
										
										
											2007-02-11 07:36:55 +00:00
										 |  |  | 	ASE_LSP_ERPAREN, | 
					
						
							| 
									
										
										
										
											2006-10-30 03:34:41 +00:00
										 |  |  | 	ASE_LSP_EARGBAD, | 
					
						
							|  |  |  | 	ASE_LSP_EARGFEW, | 
					
						
							|  |  |  | 	ASE_LSP_EARGMANY, | 
					
						
							| 
									
										
										
										
											2007-02-11 07:36:55 +00:00
										 |  |  | 	ASE_LSP_EUNDEFFN, | 
					
						
							|  |  |  | 	ASE_LSP_EBADFN, | 
					
						
							| 
									
										
										
										
											2007-02-10 13:52:41 +00:00
										 |  |  | 	ASE_LSP_EDUPFML, | 
					
						
							| 
									
										
										
										
											2007-02-03 10:52:36 +00:00
										 |  |  | 	ASE_LSP_EBADSYM, | 
					
						
							| 
									
										
										
										
											2007-02-11 07:36:55 +00:00
										 |  |  | 	ASE_LSP_EUNDEFSYM, | 
					
						
							| 
									
										
										
										
											2007-02-03 10:52:36 +00:00
										 |  |  | 	ASE_LSP_EEMPBDY, | 
					
						
							| 
									
										
										
										
											2006-10-30 11:26:57 +00:00
										 |  |  | 	ASE_LSP_EVALBAD, | 
					
						
							| 
									
										
										
										
											2007-02-03 10:52:36 +00:00
										 |  |  | 	ASE_LSP_EDIVBY0 | 
					
						
							| 
									
										
										
										
											2005-09-18 10:18:35 +00:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | typedef ase_lsp_obj_t* (*ase_lsp_prim_t) (ase_lsp_t* lsp, ase_lsp_obj_t* obj); | 
					
						
							| 
									
										
										
										
											2005-09-19 03:05:37 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-30 14:31:37 +00:00
										 |  |  | /* assertion statement */ | 
					
						
							| 
									
										
										
										
											2006-10-26 09:31:28 +00:00
										 |  |  | #ifdef NDEBUG
 | 
					
						
							|  |  |  | 	#define ASE_LSP_ASSERT(lsp,expr) ((void)0)
 | 
					
						
							| 
									
										
										
										
											2006-10-30 14:31:37 +00:00
										 |  |  | 	#define ASE_LSP_ASSERTX(lsp,expr,desc) ((void)0)
 | 
					
						
							| 
									
										
										
										
											2006-10-26 09:31:28 +00:00
										 |  |  | #else
 | 
					
						
							|  |  |  | 	#define ASE_LSP_ASSERT(lsp,expr) (void)((expr) || \
 | 
					
						
							| 
									
										
										
										
											2006-10-30 14:31:37 +00:00
										 |  |  | 		(ase_lsp_assertfail (lsp, ASE_T(#expr), ASE_NULL, ASE_T(__FILE__), __LINE__), 0)) | 
					
						
							|  |  |  | 	#define ASE_LSP_ASSERTX(lsp,expr,desc) (void)((expr) || \
 | 
					
						
							|  |  |  | 		(ase_lsp_assertfail (lsp, ASE_T(#expr), ASE_T(desc), ASE_T(__FILE__), __LINE__), 0)) | 
					
						
							| 
									
										
										
										
											2006-10-26 09:31:28 +00:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | extern "C" { | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | ase_lsp_t* ase_lsp_open ( | 
					
						
							| 
									
										
										
										
											2007-02-01 08:52:10 +00:00
										 |  |  | 	const ase_lsp_prmfns_t* prmfns, | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | 	ase_size_t mem_ubound, ase_size_t mem_ubound_inc); | 
					
						
							| 
									
										
										
										
											2005-09-18 10:18:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | void ase_lsp_close (ase_lsp_t* lsp); | 
					
						
							| 
									
										
										
										
											2005-09-17 17:42:21 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-11 07:36:55 +00:00
										 |  |  | void ase_lsp_geterror ( | 
					
						
							|  |  |  | 	ase_lsp_t* lsp, int* errnum, const ase_char_t** errmsg); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | void ase_lsp_seterror ( | 
					
						
							|  |  |  | 	ase_lsp_t* lsp, int errnum,  | 
					
						
							|  |  |  | 	const ase_char_t** errarg, ase_size_t argcnt); | 
					
						
							| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-11 08:30:18 +00:00
										 |  |  | int ase_lsp_attinput (ase_lsp_t* lsp, ase_lsp_io_t input, void* arg); | 
					
						
							|  |  |  | int ase_lsp_detinput (ase_lsp_t* lsp); | 
					
						
							| 
									
										
										
										
											2005-09-18 10:18:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-02-11 08:30:18 +00:00
										 |  |  | int ase_lsp_attoutput (ase_lsp_t* lsp, ase_lsp_io_t output, void* arg); | 
					
						
							|  |  |  | int ase_lsp_detoutput (ase_lsp_t* lsp); | 
					
						
							| 
									
										
										
										
											2005-09-18 10:18:35 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-24 04:22:40 +00:00
										 |  |  | ase_lsp_obj_t* ase_lsp_read (ase_lsp_t* lsp); | 
					
						
							|  |  |  | ase_lsp_obj_t* ase_lsp_eval (ase_lsp_t* lsp, ase_lsp_obj_t* obj); | 
					
						
							|  |  |  | int ase_lsp_print (ase_lsp_t* lsp, const ase_lsp_obj_t* obj); | 
					
						
							| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-29 13:00:39 +00:00
										 |  |  | int ase_lsp_addprim ( | 
					
						
							|  |  |  | 	ase_lsp_t* lsp, const ase_char_t* name, ase_size_t name_len,  | 
					
						
							|  |  |  | 	ase_lsp_prim_t prim, ase_size_t min_args, ase_size_t max_args); | 
					
						
							|  |  |  | int ase_lsp_removeprim (ase_lsp_t* lsp, const ase_char_t* name); | 
					
						
							| 
									
										
										
										
											2005-09-18 14:05:16 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-25 13:42:31 +00:00
										 |  |  | /* string functions exported by lsp.h */ | 
					
						
							|  |  |  | ase_char_t* ase_lsp_strdup (ase_lsp_t* lsp, const ase_char_t* str); | 
					
						
							|  |  |  | ase_char_t* ase_lsp_strxdup ( | 
					
						
							|  |  |  | 	ase_lsp_t* lsp, const ase_char_t* str, ase_size_t len); | 
					
						
							|  |  |  | ase_char_t* ase_lsp_strxdup2 ( | 
					
						
							|  |  |  | 	ase_lsp_t* lsp, | 
					
						
							|  |  |  | 	const ase_char_t* str1, ase_size_t len1, | 
					
						
							|  |  |  | 	const ase_char_t* str2, ase_size_t len2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ase_size_t ase_lsp_strlen (const ase_char_t* str); | 
					
						
							|  |  |  | ase_size_t ase_lsp_strcpy (ase_char_t* buf, const ase_char_t* str); | 
					
						
							|  |  |  | ase_size_t ase_lsp_strncpy (ase_char_t* buf, const ase_char_t* str, ase_size_t len); | 
					
						
							|  |  |  | int ase_lsp_strcmp (const ase_char_t* s1, const ase_char_t* s2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ase_lsp_strxncmp ( | 
					
						
							|  |  |  | 	const ase_char_t* s1, ase_size_t len1,  | 
					
						
							|  |  |  | 	const ase_char_t* s2, ase_size_t len2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | int ase_lsp_strxncasecmp ( | 
					
						
							|  |  |  | 	ase_lsp_t* lsp, | 
					
						
							|  |  |  | 	const ase_char_t* s1, ase_size_t len1,  | 
					
						
							|  |  |  | 	const ase_char_t* s2, ase_size_t len2); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | ase_char_t* ase_lsp_strxnstr ( | 
					
						
							|  |  |  | 	const ase_char_t* str, ase_size_t strsz,  | 
					
						
							|  |  |  | 	const ase_char_t* sub, ase_size_t subsz); | 
					
						
							| 
									
										
										
										
											2006-10-23 10:57:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-26 09:31:28 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | /* abort function for assertion. use ASE_LSP_ASSERT instead */ | 
					
						
							|  |  |  | int ase_lsp_assertfail (ase_lsp_t* lsp, | 
					
						
							| 
									
										
										
										
											2006-10-30 14:31:37 +00:00
										 |  |  | 	const ase_char_t* expr, const ase_char_t* desc, | 
					
						
							|  |  |  | 	const ase_char_t* file, int line); | 
					
						
							| 
									
										
										
										
											2006-10-26 09:31:28 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2006-10-23 10:57:59 +00:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2005-02-04 15:39:11 +00:00
										 |  |  | #ifdef __cplusplus
 | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif
 |