1
1

Update to S-Lang 1.4.5. Move include files to "include"

directory to avoid the need to rename slang.h.
* Makefile.am: Adjust file list.  Add "-Iinclude" to the
compiler flags.
* include/jdmacros.h: Rewrite to use glib.
* slmisc.c: Trim to include only needed functions.
Этот коммит содержится в:
Pavel Roskin 2002-10-07 04:41:03 +00:00
родитель 540ffe0db3
Коммит b0b73df498
25 изменённых файлов: 8529 добавлений и 5244 удалений

Просмотреть файл

@ -1,3 +1,12 @@
2002-10-07 Pavel Roskin <proski@gnu.org>
Update to S-Lang 1.4.5. Move include files to "include"
directory to avoid the need to rename slang.h.
* Makefile.am: Adjust file list. Add "-Iinclude" to the
compiler flags.
* include/jdmacros.h: Rewrite to use glib.
* slmisc.c: Trim to include only needed functions.
2002-09-18 Andrew V. Samoilov <sav@bcs.zp.ua>
* slerr.c (SLang_doerror): Use error parameter. Eliminate

Просмотреть файл

@ -1,4 +1,4 @@
AM_CFLAGS = $(GLIB_CFLAGS)
AM_CFLAGS = $(GLIB_CFLAGS) -Iinclude
if INCLUDED_SLANG
noinst_LIBRARIES = libmcslang.a
@ -6,9 +6,24 @@ else
noinst_LIBRARIES =
endif
libmcslang_a_SOURCES = sldisply.c slerr.c slsmg.c slutty.c slgetkey.c \
slmemcpy.c slmemset.c sltermin.c sltoken.c slsignal.c \
slang-mc.h _slang.h sl-feat.h jdmacros.h
SLANG_INCLUDES = \
include/_slang.h \
include/jdmacros.h \
include/sl-feat.h \
include/slang.h \
include/slinclud.h \
include/sllimits.h
libmcslang_a_SOURCES = \
sldisply.c \
slerr.c \
slgetkey.c \
slmisc.c \
slsignal.c \
slsmg.c \
sltermin.c \
slutty.c \
$(SLANG_INCLUDES)
EXTRASRC = slvideo.c slw32tty.c
EXTRADOCS = ChangeLog README

Просмотреть файл

@ -1,327 +0,0 @@
/* header file for S-Lang internal structures that users do not (should not)
need. Use slang.h for that purpose. */
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "config.h"
#include <string.h>
#include <glib.h>
#include "slang-mc.h"
#include "jdmacros.h"
#ifdef VMS
# define SLANG_SYSTEM_NAME "_VMS"
#else
# if defined (__GO32__) || defined (__EMX__) || \
defined (msdos) || defined (__os2__)
# define SLANG_SYSTEM_NAME "_IBMPC"
# else
# define SLANG_SYSTEM_NAME "_UNIX"
# endif
#endif /* VMS */
#ifdef msdos
#define SLANG_MAX_SYMBOLS 500
#else
#define SLANG_MAX_SYMBOLS 2500
#endif
/* maximum number of global symbols--- slang builtin, functions, global vars */
/* These quantities are main_types for byte-compiled code. They are used
* by the inner_interp routine. The ones commented out with a // are
* actually defined in slang.h because they are also used as the main_type in
* the name table.
*/
/* // #define SLANG_LVARIABLE 0x01 */
#define SLANG_LOGICAL 0x02
#define SLANG_BINARY 0x03
/* // #define SLANG_INTRINSIC 0x06 */
/* // #define SLANG_FUNCTION 0x07 */
#define SLANG_LITERAL 0x08 /* constant objects */
#define SLANG_BLOCK 0x09
#define SLANG_EQS 0x0A
#define SLANG_UNARY 0x0B
#define SLANG_LUNARY 0x0C
/* // #define SLANG_GVARIABLE 0x0D */
/* // #define SLANG_IVARIABLE 0x0E */ /* intrinsic variables */
/* // #define SLANG_RVARIABLE 0x0F */ /* read only variable */
/* These 3 MUST be in this order too ! */
#define SLANG_RETURN 0x10
#define SLANG_BREAK 0x11
#define SLANG_CONTINUE 0x12
#define SLANG_EXCH 0x13
#define SLANG_LABEL 0x14
#define SLANG_LOBJPTR 0x15
#define SLANG_GOBJPTR 0x16
#define SLANG_X_ERROR 0x17
/* These must be in this order */
#define SLANG_X_USER0 0x18
#define SLANG_X_USER1 0x19
#define SLANG_X_USER2 0x1A
#define SLANG_X_USER3 0x1B
#define SLANG_X_USER4 0x1C
#ifdef SLANG_NOOP
# define SLANG_NOOP_DIRECTIVE 0x2F
#endif
/* If SLANG_DATA occurs as the main_type for an object in the interpreter's
* byte-code, it currently refers to a STRING.
*/
/* // #define SLANG_DATA 0x30 */ /* real objects which may be destroyed */
/* Subtypes */
#define ERROR_BLOCK 0x01
/* gets executed if block encounters error other than stack related */
#define EXIT_BLOCK 0x02
#define USER_BLOCK0 0x03
#define USER_BLOCK1 0x04
#define USER_BLOCK2 0x05
#define USER_BLOCK3 0x06
#define USER_BLOCK4 0x07
/* The user blocks MUST be in the above order */
/* directive subtypes */
#define SLANG_LOOP_MASK 0x80
#define SLANG_LOOP 0x81
#define SLANG_WHILE 0x82
#define SLANG_FOR 0x83
#define SLANG_FOREVER 0x84
#define SLANG_CFOR 0x85
#define SLANG_DOWHILE 0x86
#define SLANG_IF_MASK 0x40
#define SLANG_IF 0x41
#define SLANG_IFNOT 0x42
#define SLANG_ELSE 0x43
/* local, global variable assignments
* The order here is important. See interp_variable_eqs to see how this
* is exploited. */
#define SLANG_EQS_MASK 0x20
/* local variables */
/* Keep these in this order!! */
#define SLANG_LEQS 0x21
#define SLANG_LPEQS 0x22
#define SLANG_LMEQS 0x23
#define SLANG_LPP 0x24
#define SLANG_LMM 0x25
/* globals */
/* Keep this on this order!! */
#define SLANG_GEQS 0x26
#define SLANG_GPEQS 0x27
#define SLANG_GMEQS 0x28
#define SLANG_GPP 0x29
#define SLANG_GMM 0x2A
/* intrinsic variables */
#define SLANG_IEQS 0x2B
#define SLANG_IPEQS 0x2C
#define SLANG_IMEQS 0x2D
#define SLANG_IPP 0x2E
#define SLANG_IMM 0x2F
#define SLANG_ELSE_MASK 0x10
#define SLANG_ANDELSE 0x11
#define SLANG_ORELSE 0x12
#define SLANG_SWITCH 0x13
/* LOGICAL SUBTYPES (operate on integers) */
#define SLANG_MOD 16
#define SLANG_OR 17
#define SLANG_AND 18
#define SLANG_BAND 19
#define SLANG_BOR 20
#define SLANG_BXOR 21
#define SLANG_SHL 22
#define SLANG_SHR 23
/* LUnary Subtypes */
#define SLANG_NOT 24
#define SLANG_BNOT 25
typedef struct SLBlock_Type
{
unsigned char main_type;
unsigned char sub_type;
union
{
struct SLBlock_Type *blk;
int i_blk;
SLang_Name_Type *n_blk;
char *s_blk;
#ifdef FLOAT_TYPE
float64 *f_blk; /*literal float is a pointer */
#endif
long l_blk;
}
b;
}
SLBlock_Type;
typedef struct
{
unsigned char main_type; /* block, intrinsic... */
unsigned char sub_type; /* SLANG_WHILE, SLANG_DATA, ... */
union
{
long l_val;
char *s_val;
int i_val;
SLuser_Object_Type *uobj;
SLang_Name_Type *n_val;
#ifdef FLOAT_TYPE
float64 f_val;
#endif
} v;
} SLang_Object_Type;
extern void SLang_free_object (SLang_Object_Type *);
extern int SLang_pop_non_object (SLang_Object_Type *);
extern void _SLdo_error (char *, ...);
extern void SLcompile(char *);
extern void (*SLcompile_ptr)(char *);
typedef struct
{
char *name; int type;
} SLang_Name2_Type;
extern void SLstupid_hash(void);
typedef struct SLName_Table
{
struct SLName_Table *next; /* next table */
SLang_Name_Type *table; /* pointer to table */
int n; /* entries in this table */
char name[32]; /* name of table */
int ofs[256]; /* offsets into table */
} SLName_Table;
extern SLName_Table *SLName_Table_Root;
#ifdef MSWINDOWS
extern SLang_Name_Type *SLang_Name_Table;
#else
extern SLang_Name_Type SLang_Name_Table[SLANG_MAX_SYMBOLS];
#endif
extern SLang_Name2_Type SL_Binary_Ops [];
extern SLang_Object_Type *SLStack_Pointer;
extern char *SLbyte_compile_name(char *);
extern int SLang_pop(SLang_Object_Type *);
extern char *SLexpand_escaped_char(char *, char *);
extern void SLexpand_escaped_string (char *, char *, char *);
extern SLang_Object_Type *_SLreverse_stack (int);
extern SLang_Name_Type *SLang_locate_name(char *);
/* returns a pointer to a MALLOCED string */
extern char *SLstringize_object (SLang_Object_Type *);
/* array types */
typedef struct SLArray_Type
{
unsigned char type; /* int, float, etc... */
int dim; /* # of dims (max 3) */
int x, y, z; /* actual dims */
union
{
unsigned char *c_ptr;
unsigned char **s_ptr;
int *i_ptr;
#ifdef FLOAT_TYPE
float64 *f_ptr;
#endif
SLuser_Object_Type **u_ptr;
}
buf;
unsigned char flags; /* readonly, etc... If this is non-zero,
* the buf pointer will NOT be freed.
* See SLarray_free_array.
*/
} SLArray_Type;
/* Callback to delete array */
extern void SLarray_free_array (long *);
/* maximum size of run time stack */
#ifdef msdos
#define SLANG_MAX_STACK_LEN 500
#else
#define SLANG_MAX_STACK_LEN 2500
#endif
#ifdef MSWINDOWS
extern SLang_Object_Type *SLRun_Stack;
#else
extern SLang_Object_Type SLRun_Stack[SLANG_MAX_STACK_LEN];
#endif
extern SLang_Object_Type *SLStack_Pointer;
extern int SLang_Trace;
extern int SLstack_depth(void);
extern void SLang_trace_fun(char *);
extern void SLexecute_function(SLang_Name_Type *);
extern char *SLmake_string (char *);
extern int _SLeqs_name(char *, SLang_Name2_Type *);
extern void SLang_push(SLang_Object_Type *);
extern void SLang_push_float(float64);
extern void SLadd_variable(char *);
extern void SLang_clear_error(void);
extern void SLarray_info (void);
extern int SLPreprocess_Only; /* preprocess instead of
* bytecompiling
*/
extern void SLdo_pop (void);
extern unsigned int SLsys_getkey (void);
extern int SLsys_input_pending (int);
#ifdef REAL_UNIX_SYSTEM
extern int SLtt_tigetflag (char *, char **);
extern int SLtt_tigetnum (char *, char **);
extern char *SLtt_tigetstr (char *, char **);
extern char *SLtt_tigetent (char *);
#endif
#ifdef msdos
#define MAX_INPUT_BUFFER_LEN 40
#else
#define MAX_INPUT_BUFFER_LEN 1024
#endif
extern unsigned char SLang_Input_Buffer [MAX_INPUT_BUFFER_LEN];
extern unsigned int SLang_Input_Buffer_Len;
extern int SLregister_types (void);
#ifndef pc_system
extern char *SLtt_Graphics_Char_Pairs;
#endif /* NOT pc_system */
extern void _SLerrno_set_return_status (void);
extern char *_SLerrno_strerror (void);
extern int _SLerrno_Return_Status;

743
slang/include/_slang.h Обычный файл
Просмотреть файл

@ -0,0 +1,743 @@
#ifndef _PRIVATE_SLANG_H_
#define _PRIVATE_SLANG_H_
/* header file for S-Lang internal structures that users do not (should not)
need. Use slang.h for that purpose. */
/* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
/* #include "config.h" */
#include "jdmacros.h"
#include "sllimits.h"
#ifdef VMS
# define SLANG_SYSTEM_NAME "_VMS"
#else
# if defined (IBMPC_SYSTEM)
# define SLANG_SYSTEM_NAME "_IBMPC"
# else
# define SLANG_SYSTEM_NAME "_UNIX"
# endif
#endif /* VMS */
/* These quantities are main_types for byte-compiled code. They are used
* by the inner_interp routine. The _BC_ means byte-code.
*/
#define _SLANG_BC_LVARIABLE SLANG_LVARIABLE /* 0x01 */
#define _SLANG_BC_GVARIABLE SLANG_GVARIABLE /* 0x02 */
#define _SLANG_BC_IVARIABLE SLANG_IVARIABLE /* 0x03 */
#define _SLANG_BC_RVARIABLE SLANG_RVARIABLE /* 0x04 */
#define _SLANG_BC_INTRINSIC SLANG_INTRINSIC /* 0x05 */
#define _SLANG_BC_FUNCTION SLANG_FUNCTION /* 0x06 */
#define _SLANG_BC_MATH_UNARY SLANG_MATH_UNARY /* 0x07 */
#define _SLANG_BC_APP_UNARY SLANG_APP_UNARY /* 0x08 */
#define _SLANG_BC_ICONST SLANG_ICONSTANT /* 0x09 */
#define _SLANG_BC_DCONST SLANG_DCONSTANT /* 0x0A */
#define _SLANG_BC_PVARIABLE SLANG_PVARIABLE /* 0x0B */
#define _SLANG_BC_PFUNCTION SLANG_PFUNCTION /* 0x0C */
#define _SLANG_BC_BINARY 0x10
#define _SLANG_BC_LITERAL 0x11 /* constant objects */
#define _SLANG_BC_LITERAL_INT 0x12
#define _SLANG_BC_LITERAL_STR 0x13
#define _SLANG_BC_BLOCK 0x14
/* These 3 MUST be in this order too ! */
#define _SLANG_BC_RETURN 0x15
#define _SLANG_BC_BREAK 0x16
#define _SLANG_BC_CONTINUE 0x17
#define _SLANG_BC_EXCH 0x18
#define _SLANG_BC_LABEL 0x19
#define _SLANG_BC_LOBJPTR 0x1A
#define _SLANG_BC_GOBJPTR 0x1B
#define _SLANG_BC_X_ERROR 0x1C
/* These must be in this order */
#define _SLANG_BC_X_USER0 0x1D
#define _SLANG_BC_X_USER1 0x1E
#define _SLANG_BC_X_USER2 0x1F
#define _SLANG_BC_X_USER3 0x20
#define _SLANG_BC_X_USER4 0x21
#define _SLANG_BC_CALL_DIRECT 0x24
#define _SLANG_BC_CALL_DIRECT_FRAME 0x25
#define _SLANG_BC_UNARY 0x26
#define _SLANG_BC_UNARY_FUNC 0x27
#define _SLANG_BC_DEREF_ASSIGN 0x30
#define _SLANG_BC_SET_LOCAL_LVALUE 0x31
#define _SLANG_BC_SET_GLOBAL_LVALUE 0x32
#define _SLANG_BC_SET_INTRIN_LVALUE 0x33
#define _SLANG_BC_SET_STRUCT_LVALUE 0x34
#define _SLANG_BC_FIELD 0x35
#define _SLANG_BC_SET_ARRAY_LVALUE 0x36
#define _SLANG_BC_LINE_NUM 0x40
#define _SLANG_BC_TMP 0x50
#define _SLANG_BC_LVARIABLE_AGET 0x60
#define _SLANG_BC_LVARIABLE_APUT 0x61
#define _SLANG_BC_INTEGER_PLUS 0x62
#define _SLANG_BC_INTEGER_MINUS 0x63
#define _SLANG_BC_ARG_LVARIABLE 0x64
#define _SLANG_BC_EARG_LVARIABLE 0x65
#define _SLANG_BC_CALL_DIRECT_INTRINSIC 0x80
#define _SLANG_BC_INTRINSIC_CALL_DIRECT 0x81
#define _SLANG_BC_CALL_DIRECT_LSTR 0x82
#define _SLANG_BC_CALL_DIRECT_SLFUN 0x83
#define _SLANG_BC_CALL_DIRECT_INTRSTOP 0x84
#define _SLANG_BC_INTRINSIC_STOP 0x85
#define _SLANG_BC_CALL_DIRECT_EARG_LVAR 0x86
#define _SLANG_BC_CALL_DIRECT_LINT 0x87
#define _SLANG_BC_CALL_DIRECT_LVAR 0x88
/* Byte-Code Sub Types (_BCST_) */
/* These are sub_types of _SLANG_BC_BLOCK */
#define _SLANG_BCST_ERROR_BLOCK 0x01
#define _SLANG_BCST_EXIT_BLOCK 0x02
#define _SLANG_BCST_USER_BLOCK0 0x03
#define _SLANG_BCST_USER_BLOCK1 0x04
#define _SLANG_BCST_USER_BLOCK2 0x05
#define _SLANG_BCST_USER_BLOCK3 0x06
#define _SLANG_BCST_USER_BLOCK4 0x07
/* The user blocks MUST be in the above order */
#define _SLANG_BCST_LOOP 0x10
#define _SLANG_BCST_WHILE 0x11
#define _SLANG_BCST_FOR 0x12
#define _SLANG_BCST_FOREVER 0x13
#define _SLANG_BCST_CFOR 0x14
#define _SLANG_BCST_DOWHILE 0x15
#define _SLANG_BCST_FOREACH 0x16
#define _SLANG_BCST_IF 0x20
#define _SLANG_BCST_IFNOT 0x21
#define _SLANG_BCST_ELSE 0x22
#define _SLANG_BCST_ANDELSE 0x23
#define _SLANG_BCST_ORELSE 0x24
#define _SLANG_BCST_SWITCH 0x25
#define _SLANG_BCST_NOTELSE 0x26
/* assignment (_SLANG_BC_SET_*_LVALUE) subtypes. The order MUST correspond
* to the assignment token order with the ASSIGN_TOKEN as the first!
*/
#define _SLANG_BCST_ASSIGN 0x01
#define _SLANG_BCST_PLUSEQS 0x02
#define _SLANG_BCST_MINUSEQS 0x03
#define _SLANG_BCST_TIMESEQS 0x04
#define _SLANG_BCST_DIVEQS 0x05
#define _SLANG_BCST_BOREQS 0x06
#define _SLANG_BCST_BANDEQS 0x07
#define _SLANG_BCST_PLUSPLUS 0x08
#define _SLANG_BCST_POST_PLUSPLUS 0x09
#define _SLANG_BCST_MINUSMINUS 0x0A
#define _SLANG_BCST_POST_MINUSMINUS 0x0B
/* These use SLANG_PLUS, SLANG_MINUS, SLANG_PLUSPLUS, etc... */
typedef union
{
#if SLANG_HAS_FLOAT
double double_val;
float float_val;
#endif
long long_val;
unsigned long ulong_val;
VOID_STAR ptr_val;
char *s_val;
int int_val;
unsigned int uint_val;
SLang_MMT_Type *ref;
SLang_Name_Type *n_val;
struct _SLang_Struct_Type *struct_val;
struct _SLang_Array_Type *array_val;
short short_val;
unsigned short ushort_val;
char char_val;
unsigned char uchar_val;
}
_SL_Object_Union_Type;
typedef struct _SLang_Object_Type
{
SLtype data_type; /* SLANG_INT_TYPE, ... */
_SL_Object_Union_Type v;
}
SLang_Object_Type;
struct _SLang_MMT_Type
{
SLtype data_type; /* int, string, etc... */
VOID_STAR user_data; /* address of user structure */
unsigned int count; /* number of references */
};
extern int _SLang_pop_object_of_type (SLtype, SLang_Object_Type *, int);
typedef struct
{
char *name; /* slstring */
SLang_Object_Type obj;
}
_SLstruct_Field_Type;
typedef struct _SLang_Struct_Type
{
_SLstruct_Field_Type *fields;
unsigned int nfields; /* number used */
unsigned int num_refs;
}
_SLang_Struct_Type;
extern void _SLstruct_delete_struct (_SLang_Struct_Type *);
extern int _SLang_push_struct (_SLang_Struct_Type *);
extern int _SLang_pop_struct (_SLang_Struct_Type **);
extern int _SLstruct_init (void);
/* extern int _SLstruct_get_field (char *); */
extern int _SLstruct_define_struct (void);
extern int _SLstruct_define_typedef (void);
struct _SLang_Ref_Type
{
int is_global;
union
{
SLang_Name_Type *nt;
SLang_Object_Type *local_obj;
}
v;
};
extern int _SLang_dereference_ref (SLang_Ref_Type *);
extern int _SLang_deref_assign (SLang_Ref_Type *);
extern int _SLang_push_ref (int, VOID_STAR);
extern int _SL_increment_frame_pointer (void);
extern int _SL_decrement_frame_pointer (void);
extern int SLang_pop(SLang_Object_Type *);
extern void SLang_free_object (SLang_Object_Type *);
extern int _SLanytype_typecast (SLtype, VOID_STAR, unsigned int,
SLtype, VOID_STAR);
extern void _SLstring_intrinsic (void);
/* These functions are used to create slstrings of a fixed length. Be
* very careful how they are used. In particular, if len bytes are allocated,
* then the string must be len characters long, no more and no less.
*/
extern char *_SLallocate_slstring (unsigned int);
extern char *_SLcreate_via_alloced_slstring (char *, unsigned int);
extern void _SLunallocate_slstring (char *, unsigned int);
extern int _SLpush_alloced_slstring (char *, unsigned int);
typedef struct
{
char **buf;
unsigned int max_num;
unsigned int num;
unsigned int delta_num;
}
_SLString_List_Type;
extern int _SLstring_list_append (_SLString_List_Type *, char *);
extern int _SLstring_list_init (_SLString_List_Type *, unsigned int, unsigned int);
extern void _SLstring_list_delete (_SLString_List_Type *);
extern int _SLstring_list_push (_SLString_List_Type *);
/* This function assumes that s is an slstring. */
extern char *_SLstring_dup_slstring (char *);
extern int _SLang_dup_and_push_slstring (char *);
extern int _SLang_init_import (void);
/* This function checks to see if the referenced object is initialized */
extern int _SLang_is_ref_initialized (SLang_Ref_Type *);
extern int _SLcheck_identifier_syntax (char *);
extern int _SLang_uninitialize_ref (SLang_Ref_Type *);
extern int _SLpush_slang_obj (SLang_Object_Type *);
extern char *_SLexpand_escaped_char(char *, char *);
extern void _SLexpand_escaped_string (char *, char *, char *);
/* returns a pointer to an SLstring string-- use SLang_free_slstring */
extern char *_SLstringize_object (SLang_Object_Type *);
extern int _SLdump_objects (char *, SLang_Object_Type *, unsigned int, int);
extern SLang_Object_Type *_SLRun_Stack;
extern SLang_Object_Type *_SLStack_Pointer;
struct _SLang_NameSpace_Type
{
struct _SLang_NameSpace_Type *next;
char *name; /* this is the load_type name */
char *namespace_name; /* this name is assigned by implements */
unsigned int table_size;
SLang_Name_Type **table;
};
extern SLang_NameSpace_Type *_SLns_allocate_namespace (char *, unsigned int);
extern SLang_NameSpace_Type *_SLns_find_namespace (char *);
extern int _SLns_set_namespace_name (SLang_NameSpace_Type *, char *);
extern SLang_Array_Type *_SLnspace_apropos (SLang_NameSpace_Type *, char *, unsigned int);
extern void _SLang_use_namespace_intrinsic (char *name);
extern char *_SLang_cur_namespace_intrinsic (void);
extern SLang_Array_Type *_SLang_apropos (char *, char *, unsigned int);
extern void _SLang_implements_intrinsic (char *);
extern int _SLang_Trace;
extern int _SLstack_depth(void);
extern char *_SLang_Current_Function_Name;
extern int _SLang_trace_fun(char *);
extern int _SLang_Compile_Line_Num_Info;
extern char *_SLstring_dup_hashed_string (char *, unsigned long);
extern unsigned long _SLcompute_string_hash (char *);
extern char *_SLstring_make_hashed_string (char *, unsigned int, unsigned long *);
extern void _SLfree_hashed_string (char *, unsigned int, unsigned long);
unsigned long _SLstring_hash (unsigned char *, unsigned char *);
extern int _SLinit_slcomplex (void);
extern int _SLang_init_slstrops (void);
extern int _SLstrops_do_sprintf_n (int);
extern int _SLang_sscanf (void);
extern double _SLang_atof (char *);
extern int _SLang_init_bstring (void);
extern int _SLang_init_sltime (void);
extern void _SLpack (void);
extern void _SLunpack (char *, SLang_BString_Type *);
extern void _SLpack_pad_format (char *);
extern unsigned int _SLpack_compute_size (char *);
extern int _SLusleep (unsigned long);
/* frees upon error. NULL __NOT__ ok. */
extern int _SLang_push_slstring (char *);
extern SLtype _SLarith_promote_type (SLtype);
extern int _SLarith_get_precedence (SLtype);
extern int _SLarith_typecast (SLtype, VOID_STAR, unsigned int,
SLtype, VOID_STAR);
extern int SLang_push(SLang_Object_Type *);
extern int SLadd_global_variable (char *);
extern void _SLang_clear_error (void);
extern int _SLdo_pop (void);
extern unsigned int _SLsys_getkey (void);
extern int _SLsys_input_pending (int);
#ifdef IBMPC_SYSTEM
extern unsigned int _SLpc_convert_scancode (unsigned int, unsigned int, int);
#define _SLTT_KEY_SHIFT 1
#define _SLTT_KEY_CTRL 2
#define _SLTT_KEY_ALT 4
#endif
typedef struct _SLterminfo_Type SLterminfo_Type;
extern SLterminfo_Type *_SLtt_tigetent (char *);
extern char *_SLtt_tigetstr (SLterminfo_Type *, char *);
extern int _SLtt_tigetnum (SLterminfo_Type *, char *);
extern int _SLtt_tigetflag (SLterminfo_Type *, char *);
#if SLTT_HAS_NON_BCE_SUPPORT
extern int _SLtt_get_bce_color_offset (void);
#endif
extern void (*_SLtt_color_changed_hook)(void);
extern unsigned char SLang_Input_Buffer [SL_MAX_INPUT_BUFFER_LEN];
extern int _SLregister_types (void);
extern SLang_Class_Type *_SLclass_get_class (SLtype);
extern VOID_STAR _SLclass_get_ptr_to_value (SLang_Class_Type *, SLang_Object_Type *);
extern void _SLclass_type_mismatch_error (SLtype, SLtype);
extern int _SLclass_init (void);
extern int _SLclass_copy_class (SLtype, SLtype);
extern SLtype _SLclass_Class_Type [256];
extern int (*_SLclass_get_typecast (SLtype, SLtype, int))
(SLtype, VOID_STAR, unsigned int,
SLtype, VOID_STAR);
extern int (*_SLclass_get_binary_fun (int, SLang_Class_Type *, SLang_Class_Type *, SLang_Class_Type **, int))
(int,
SLtype, VOID_STAR, unsigned int,
SLtype, VOID_STAR, unsigned int,
VOID_STAR);
extern int (*_SLclass_get_unary_fun (int, SLang_Class_Type *, SLang_Class_Type **, int))
(int, SLtype, VOID_STAR, unsigned int, VOID_STAR);
extern int _SLarith_register_types (void);
extern SLtype _SLarith_Arith_Types [];
extern SLtype _SLarith_Is_Arith_Type [256];
extern int _SLarith_bin_op (SLang_Object_Type *, SLang_Object_Type *, int);
extern int _SLarray_add_bin_op (SLtype);
extern int _SLang_call_funptr (SLang_Name_Type *);
extern void _SLset_double_format (char *);
extern SLang_Name_Type *_SLlocate_global_name (char *);
extern SLang_Name_Type *_SLlocate_name (char *);
extern char *_SLdefines[];
#define SL_ERRNO_NOT_IMPLEMENTED 0x7FFF
extern int _SLerrno_errno;
extern int _SLerrno_init (void);
extern int _SLstdio_fdopen (char *, int, char *);
extern void _SLstruct_pop_args (int *);
extern void _SLstruct_push_args (SLang_Array_Type *);
extern int _SLarray_aput (void);
extern int _SLarray_aget (void);
extern int _SLarray_inline_implicit_array (void);
extern int _SLarray_inline_array (void);
extern int _SLarray_wildcard_array (void);
extern int
_SLarray_typecast (SLtype, VOID_STAR, unsigned int,
SLtype, VOID_STAR, int);
extern int _SLarray_aput_transfer_elem (SLang_Array_Type *, int *,
VOID_STAR, unsigned int, int);
extern int _SLarray_aget_transfer_elem (SLang_Array_Type *, int *,
VOID_STAR, unsigned int, int);
extern void _SLarray_free_array_elements (SLang_Class_Type *, VOID_STAR, unsigned int);
extern SLang_Foreach_Context_Type *
_SLarray_cl_foreach_open (SLtype, unsigned int);
extern void _SLarray_cl_foreach_close (SLtype, SLang_Foreach_Context_Type *);
extern int _SLarray_cl_foreach (SLtype, SLang_Foreach_Context_Type *);
extern int _SLarray_matrix_multiply (void);
extern void (*_SLang_Matrix_Multiply)(void);
extern int _SLarray_init_slarray (void);
extern SLang_Array_Type *
SLang_create_array1 (SLtype, int, VOID_STAR, int *, unsigned int, int);
extern int _SLcompile_push_context (SLang_Load_Type *);
extern int _SLcompile_pop_context (void);
extern int _SLang_Auto_Declare_Globals;
typedef struct
{
union
{
long long_val;
char *s_val; /* Used for IDENT_TOKEN, FLOAT, etc... */
SLang_BString_Type *b_val;
} v;
int free_sval_flag;
unsigned int num_refs;
unsigned long hash;
#if _SLANG_HAS_DEBUG_CODE
int line_number;
#endif
SLtype type;
}
_SLang_Token_Type;
extern void _SLcompile (_SLang_Token_Type *);
extern void (*_SLcompile_ptr)(_SLang_Token_Type *);
/* *** TOKENS *** */
/* Note that that tokens corresponding to ^J, ^M, and ^Z should not be used.
* This is because a file that contains any of these characters will
* have an OS dependent interpretation, e.g., ^Z is EOF on MSDOS.
*/
/* Special tokens */
#define ILLEGAL_TOKEN 0x00 /* no token has this value */
#define EOF_TOKEN 0x01
#define RPN_TOKEN 0x02
#define NL_TOKEN 0x03
#define NOP_TOKEN 0x05
#define FARG_TOKEN 0x06
#define TMP_TOKEN 0x07
#define RESERVED1_TOKEN 0x0A /* \n */
#define RESERVED2_TOKEN 0x0D /* \r */
/* Literal tokens */
#define CHAR_TOKEN 0x10
#define UCHAR_TOKEN 0x11
#define SHORT_TOKEN 0x12
#define USHORT_TOKEN 0x13
#define INT_TOKEN 0x14
#define UINT_TOKEN 0x15
#define LONG_TOKEN 0x16
#define ULONG_TOKEN 0x17
#define IS_INTEGER_TOKEN(x) ((x >= CHAR_TOKEN) && (x <= ULONG_TOKEN))
#define FLOAT_TOKEN 0x18
#define DOUBLE_TOKEN 0x19
#define RESERVED3_TOKEN 0x1A /* ^Z */
#define COMPLEX_TOKEN 0x1B
#define STRING_TOKEN 0x1C
#define BSTRING_TOKEN 0x1D
#define _BSTRING_TOKEN 0x1E /* byte-compiled BSTRING */
#define ESC_STRING_TOKEN 0x1F
/* Tokens that can be LVALUES */
#define IDENT_TOKEN 0x20
#define ARRAY_TOKEN 0x21
#define DOT_TOKEN 0x22
#define METHOD_TOKEN 0x24
#define IS_LVALUE_TOKEN (((t) <= METHOD_TOKEN) && ((t) >= IDENT_TOKEN))
/* do not use these values */
#define RESERVED4_TOKEN 0x23 /* # */
#define RESERVED5_TOKEN 0x25 /* % */
/* Flags for struct fields */
#define STATIC_TOKEN 0x26
#define READONLY_TOKEN 0x27
#define PRIVATE_TOKEN 0x28
#define PUBLIC_TOKEN 0x29
/* Punctuation tokens */
#define OBRACKET_TOKEN 0x2a
#define CBRACKET_TOKEN 0x2b
#define OPAREN_TOKEN 0x2c
#define CPAREN_TOKEN 0x2d
#define OBRACE_TOKEN 0x2e
#define CBRACE_TOKEN 0x2f
#define COMMA_TOKEN 0x31
#define SEMICOLON_TOKEN 0x32
#define COLON_TOKEN 0x33
#define NAMESPACE_TOKEN 0x34
/* Operators */
#define POW_TOKEN 0x38
/* The order here must match the order in the Binop_Level table in slparse.c */
#define FIRST_BINARY_OP 0x39
#define ADD_TOKEN 0x39
#define SUB_TOKEN 0x3a
#define TIMES_TOKEN 0x3b
#define DIV_TOKEN 0x3c
#define LT_TOKEN 0x3d
#define LE_TOKEN 0x3e
#define GT_TOKEN 0x3f
#define GE_TOKEN 0x40
#define EQ_TOKEN 0x41
#define NE_TOKEN 0x42
#define AND_TOKEN 0x43
#define OR_TOKEN 0x44
#define MOD_TOKEN 0x45
#define BAND_TOKEN 0x46
#define SHL_TOKEN 0x47
#define SHR_TOKEN 0x48
#define BXOR_TOKEN 0x49
#define BOR_TOKEN 0x4a
#define POUND_TOKEN 0x4b /* matrix multiplication */
#define LAST_BINARY_OP 0x4b
#define IS_BINARY_OP(t) ((t >= FIRST_BINARY_OP) && (t <= LAST_BINARY_OP))
/* unary tokens -- but not all of them (see grammar) */
#define DEREF_TOKEN 0x4d
#define NOT_TOKEN 0x4e
#define BNOT_TOKEN 0x4f
#define IS_INTERNAL_FUNC(t) ((t >= 0x50) && (t <= 0x56))
#define POP_TOKEN 0x50
#define CHS_TOKEN 0x51
#define SIGN_TOKEN 0x52
#define ABS_TOKEN 0x53
#define SQR_TOKEN 0x54
#define MUL2_TOKEN 0x55
#define EXCH_TOKEN 0x56
/* Assignment tokens. Note: these must appear with sequential values.
* The order here must match the specific lvalue assignments below.
* These tokens are used by rpn routines in slang.c. slparse.c maps them
* onto the specific lvalue tokens while parsing infix.
* Also the assignment _SLANG_BCST_ assumes this order
*/
#define ASSIGN_TOKEN 0x57
#define PLUSEQS_TOKEN 0x58
#define MINUSEQS_TOKEN 0x59
#define TIMESEQS_TOKEN 0x5A
#define DIVEQS_TOKEN 0x5B
#define BOREQS_TOKEN 0x5C
#define BANDEQS_TOKEN 0x5D
#define PLUSPLUS_TOKEN 0x5E
#define POST_PLUSPLUS_TOKEN 0x5F
#define MINUSMINUS_TOKEN 0x60
#define POST_MINUSMINUS_TOKEN 0x61
/* Directives */
#define FIRST_DIRECTIVE_TOKEN 0x62
#define IFNOT_TOKEN 0x62
#define IF_TOKEN 0x63
#define ELSE_TOKEN 0x64
#define FOREVER_TOKEN 0x65
#define WHILE_TOKEN 0x66
#define FOR_TOKEN 0x67
#define _FOR_TOKEN 0x68
#define LOOP_TOKEN 0x69
#define SWITCH_TOKEN 0x6A
#define DOWHILE_TOKEN 0x6B
#define ANDELSE_TOKEN 0x6C
#define ORELSE_TOKEN 0x6D
#define ERRBLK_TOKEN 0x6E
#define EXITBLK_TOKEN 0x6F
/* These must be sequential */
#define USRBLK0_TOKEN 0x70
#define USRBLK1_TOKEN 0x71
#define USRBLK2_TOKEN 0x72
#define USRBLK3_TOKEN 0x73
#define USRBLK4_TOKEN 0x74
#define CONT_TOKEN 0x75
#define BREAK_TOKEN 0x76
#define RETURN_TOKEN 0x77
#define CASE_TOKEN 0x78
#define DEFINE_TOKEN 0x79
#define DO_TOKEN 0x7a
#define VARIABLE_TOKEN 0x7b
#define GVARIABLE_TOKEN 0x7c
#define _REF_TOKEN 0x7d
#define PUSH_TOKEN 0x7e
#define STRUCT_TOKEN 0x7f
#define TYPEDEF_TOKEN 0x80
#define NOTELSE_TOKEN 0x81
#define DEFINE_STATIC_TOKEN 0x82
#define FOREACH_TOKEN 0x83
#define USING_TOKEN 0x84
#define DEFINE_PRIVATE_TOKEN 0x85
#define DEFINE_PUBLIC_TOKEN 0x86
/* Note: the order here must match the order of the generic assignment tokens.
* Also, the first token of each group must be the ?_ASSIGN_TOKEN.
* slparse.c exploits this order, as well as slang.h.
*/
#define FIRST_ASSIGN_TOKEN 0x90
#define _STRUCT_ASSIGN_TOKEN 0x90
#define _STRUCT_PLUSEQS_TOKEN 0x91
#define _STRUCT_MINUSEQS_TOKEN 0x92
#define _STRUCT_TIMESEQS_TOKEN 0x93
#define _STRUCT_DIVEQS_TOKEN 0x94
#define _STRUCT_BOREQS_TOKEN 0x95
#define _STRUCT_BANDEQS_TOKEN 0x96
#define _STRUCT_PLUSPLUS_TOKEN 0x97
#define _STRUCT_POST_PLUSPLUS_TOKEN 0x98
#define _STRUCT_MINUSMINUS_TOKEN 0x99
#define _STRUCT_POST_MINUSMINUS_TOKEN 0x9A
#define _ARRAY_ASSIGN_TOKEN 0xA0
#define _ARRAY_PLUSEQS_TOKEN 0xA1
#define _ARRAY_MINUSEQS_TOKEN 0xA2
#define _ARRAY_TIMESEQS_TOKEN 0xA3
#define _ARRAY_DIVEQS_TOKEN 0xA4
#define _ARRAY_BOREQS_TOKEN 0xA5
#define _ARRAY_BANDEQS_TOKEN 0xA6
#define _ARRAY_PLUSPLUS_TOKEN 0xA7
#define _ARRAY_POST_PLUSPLUS_TOKEN 0xA8
#define _ARRAY_MINUSMINUS_TOKEN 0xA9
#define _ARRAY_POST_MINUSMINUS_TOKEN 0xAA
#define _SCALAR_ASSIGN_TOKEN 0xB0
#define _SCALAR_PLUSEQS_TOKEN 0xB1
#define _SCALAR_MINUSEQS_TOKEN 0xB2
#define _SCALAR_TIMESEQS_TOKEN 0xB3
#define _SCALAR_DIVEQS_TOKEN 0xB4
#define _SCALAR_BOREQS_TOKEN 0xB5
#define _SCALAR_BANDEQS_TOKEN 0xB6
#define _SCALAR_PLUSPLUS_TOKEN 0xB7
#define _SCALAR_POST_PLUSPLUS_TOKEN 0xB8
#define _SCALAR_MINUSMINUS_TOKEN 0xB9
#define _SCALAR_POST_MINUSMINUS_TOKEN 0xBA
#define _DEREF_ASSIGN_TOKEN 0xC0
#define _DEREF_PLUSEQS_TOKEN 0xC1
#define _DEREF_MINUSEQS_TOKEN 0xC2
#define _DEREF_TIMESEQS_TOKEN 0xC3
#define _DEREF_DIVEQS_TOKEN 0xC4
#define _DEREF_BOREQS_TOKEN 0xC5
#define _DEREF_BANDEQS_TOKEN 0xC6
#define _DEREF_PLUSPLUS_TOKEN 0xC7
#define _DEREF_POST_PLUSPLUS_TOKEN 0xC8
#define _DEREF_MINUSMINUS_TOKEN 0xC9
#define _DEREF_POST_MINUSMINUS_TOKEN 0xCA
#define LAST_ASSIGN_TOKEN 0xCA
#define IS_ASSIGN_TOKEN(t) (((t)>=FIRST_ASSIGN_TOKEN)&&((t)<=LAST_ASSIGN_TOKEN))
#define _INLINE_ARRAY_TOKEN 0xE0
#define _INLINE_IMPLICIT_ARRAY_TOKEN 0xE1
#define _NULL_TOKEN 0xE2
#define _INLINE_WILDCARD_ARRAY_TOKEN 0xE3
#define LINE_NUM_TOKEN 0xFC
#define ARG_TOKEN 0xFD
#define EARG_TOKEN 0xFE
#define NO_OP_LITERAL 0xFF
typedef struct
{
/* sltoken.c */
/* SLang_eval_object */
SLang_Load_Type *llt;
SLPreprocess_Type *this_slpp;
/* prep_get_char() */
char *input_line;
char cchar;
/* get_token() */
int want_nl_token;
/* slparse.c */
_SLang_Token_Type ctok;
int block_depth;
int assignment_expression;
/* slang.c : SLcompile() */
_SLang_Token_Type save_token;
_SLang_Token_Type next_token;
void (*slcompile_ptr)(_SLang_Token_Type *);
}
_SLEval_Context;
extern int _SLget_token (_SLang_Token_Type *);
extern void _SLparse_error (char *, _SLang_Token_Type *, int);
extern void _SLparse_start (SLang_Load_Type *);
extern int _SLget_rpn_token (_SLang_Token_Type *);
extern void _SLcompile_byte_compiled (void);
extern int (*_SLprep_eval_hook) (char *);
#ifndef _SLvsnprintf
#ifdef HAVE_VSNPRINTF
#define _SLvsnprintf vsnprintf
#else
extern int _SLvsnprintf (char *, unsigned int, char *, va_list);
#endif
#endif
#ifdef HAVE_SNPRINTF
# define _SLsnprintf snprintf
#else
extern int _SLsnprintf (char *, unsigned int, char *, ...);
#endif
#undef _INLINE_
#if defined(__GNUC__) && _SLANG_USE_INLINE_CODE
# define _INLINE_ __inline__
#else
# define _INLINE_
#endif
#endif /* _PRIVATE_SLANG_H_ */

20
slang/include/jdmacros.h Обычный файл
Просмотреть файл

@ -0,0 +1,20 @@
/* Fully rewritten to use glib */
#ifndef _JD_MACROS_H_
#define _JD_MACROS_H_
#include <glib.h>
#ifndef SLMEMSET
#define SLMEMSET memset
#endif
#ifndef SLMEMCPY
#define SLMEMCPY memcpy
#endif
#define SLfree(x) g_free(x)
#define SLmalloc(x) g_malloc(x)
#define _SLvsnprintf g_vsnprintf
#endif /* _JD_MACROS_H_ */

61
slang/include/sl-feat.h Обычный файл
Просмотреть файл

@ -0,0 +1,61 @@
/* Setting this to 1 enables automatic support for associative arrays.
* If this is set to 0, an application must explicitly enable associative
* array support via SLang_init_slassoc.
*/
#define SLANG_HAS_ASSOC_ARRAYS 1
#define SLANG_HAS_COMPLEX 1
#define SLANG_HAS_FLOAT 1
/* This is the old space-speed trade off. To reduce memory usage and code
* size, set this to zero.
*/
/*#define _SLANG_OPTIMIZE_FOR_SPEED 2 */
#define _SLANG_OPTIMIZE_FOR_SPEED 2
#define _SLANG_USE_INLINE_CODE 1
/* This is experimental. It adds extra information for tracking down
* errors.
*/
#define _SLANG_HAS_DEBUG_CODE 1
/* Allow optimizations based upon the __tmp operator. */
#define _SLANG_USE_TMP_OPTIMIZATION 1
/* Setting this to one will map 8 bit vtxxx terminals to 7 bit. Terminals
* such as the vt320 can be set up to output the two-character escape sequence
* encoded as 'ESC [' as single character. Setting this variable to 1 will
* insert code to map such characters to the 7 bit equivalent.
* This affects just input characters in the range 128-160 on non PC
* systems.
*/
#if defined(VMS) || defined(AMIGA)
# define _SLANG_MAP_VTXXX_8BIT 1
#else
# define _SLANG_MAP_VTXXX_8BIT 0
#endif
/* Add support for color terminals that cannot do background color erases
* Such terminals are poorly designed and are slowly disappearing but they
* are still quite common. For example, screen is one of them!
*
* This is experimental. In particular, it is not known to work if
* KANJI suupport is enabled.
*/
#if !defined(IBMPC_SYSTEM)
# define SLTT_HAS_NON_BCE_SUPPORT 1
#else
# define SLTT_HAS_NON_BCE_SUPPORT 0
#endif
/* If you want slang to assume that an xterm always has the background color
* erase feature, then set this to 1. Otherwise, it will check the terminfo
* database. This may or may not be a good idea since most good color xterms
* support bce but many terminfo systems do not support it.
*/
#define SLTT_XTERM_ALWAYS_BCE 0
/* Set this to 1 to enable Kanji support. See above comment. */
#define SLANG_HAS_KANJI_SUPPORT 0

1947
slang/include/slang.h Обычный файл

Разница между файлами не показана из-за своего большого размера Загрузить разницу

30
slang/include/slinclud.h Обычный файл
Просмотреть файл

@ -0,0 +1,30 @@
#ifndef _SLANG_INCLUDE_H_
#define _SLANG_INCLUDE_H_
#include "config.h"
#include "sl-feat.h"
#include <stdio.h>
#include <string.h>
#if defined(__QNX__) && defined(__WATCOMC__)
# include <unix.h>
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#ifdef HAVE_MALLOC_H
# include <malloc.h>
#endif
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
#endif /* _SLANG_INCLUDE_H_ */

64
slang/include/sllimits.h Обычный файл
Просмотреть файл

@ -0,0 +1,64 @@
/* Copyright (c) 1998, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
/* sllimits.h */
/* slstring.c: Size of the hash table used for strings (prime numbers) */
#ifdef __MSDOS_16BIT__
# define SLSTRING_HASH_TABLE_SIZE 601
# define SLASSOC_HASH_TABLE_SIZE 601
#else
# define SLSTRING_HASH_TABLE_SIZE 2909
# define SLASSOC_HASH_TABLE_SIZE 2909
#endif
/* slang.c: maximum size of run time stack */
#ifdef __MSDOS_16BIT__
# define SLANG_MAX_STACK_LEN 500
#else
# define SLANG_MAX_STACK_LEN 2500
#endif
/* slang.c: This sets the size on the depth of function calls */
#ifdef __MSDOS_16BIT__
# define SLANG_MAX_RECURSIVE_DEPTH 50
#else
# define SLANG_MAX_RECURSIVE_DEPTH 250
#endif
/* slang.c: Size of the stack used for local variables */
#ifdef __MSDOS_16BIT__
# define SLANG_MAX_LOCAL_STACK 200
#else
# define SLANG_MAX_LOCAL_STACK 1024
#endif
/* slang.c: The size of the hash table used for local and global objects.
* These should be prime numbers.
*/
#define SLGLOBALS_HASH_TABLE_SIZE 2909
#define SLLOCALS_HASH_TABLE_SIZE 73
#define SLSTATIC_HASH_TABLE_SIZE 73
/* Size of the keyboard buffer use by the ungetkey routines */
#ifdef __MSDOS_16BIT__
# define SL_MAX_INPUT_BUFFER_LEN 40
#else
# define SL_MAX_INPUT_BUFFER_LEN 1024
#endif
/* Maximum number of nested switch statements */
#define SLANG_MAX_NESTED_SWITCH 10
/* Size of the block stack (used in byte-compiling) */
#define SLANG_MAX_BLOCK_STACK_LEN 50
/* slfile.c: Max number of open file pointers */
#ifdef __MSDOS_16BIT__
# define SL_MAX_FILES 32
#else
# define SL_MAX_FILES 256
#endif

Просмотреть файл

@ -1,76 +0,0 @@
#ifndef _JD_MACROS_H_
#define _JD_MACROS_H_
/* This file defines some macros that I use with programs that link to
* the slang library.
*/
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#if !defined(STDC_HEADERS) && defined(HAVE_MALLOC_H)
# include <malloc.h>
#endif
#ifdef HAVE_MEMORY_H
# include <memory.h>
#endif
#ifndef SLMEMSET
# ifdef HAVE_MEMSET
# define SLMEMSET memset
# else
# define SLMEMSET SLmemset
# endif
#endif
#ifndef SLMEMCHR
# ifdef HAVE_MEMCHR
# define SLMEMCHR memchr
# else
# define SLMEMCHR SLmemchr
# endif
#endif
#ifndef SLMEMCPY
# ifdef HAVE_MEMCPY
# define SLMEMCPY memcpy
# else
# define SLMEMCPY SLmemcpy
# endif
#endif
/* Note: HAVE_MEMCMP requires an unsigned memory comparison!!! */
#ifndef SLMEMCMP
# ifdef HAVE_MEMCMP
# define SLMEMCMP memcmp
# else
# define SLMEMCMP SLmemcmp
# endif
#endif
#if SLANG_VERSION < 9934
# define SLmemcmp jed_memcmp
# define SLmemcpy jed_memcpy
# define SLmemset jed_memset
# define SLmemchr jed_memchr
#endif
#ifndef SLFREE
# define SLFREE free
#endif
#ifndef SLMALLOC
# define SLMALLOC malloc
#endif
#ifndef SLCALLOC
# define SLCALLOC calloc
#endif
#ifndef SLREALLOC
# define SLREALLOC realloc
#endif
#endif /* _JD_MACROS_H_ */

Просмотреть файл

@ -1,2 +0,0 @@
/* Set this to 1 to enable Kanji support */
#define SLANG_HAS_KANJI_SUPPORT 0

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,48 +1,181 @@
/* error handling common to all routines. */
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
/* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "slinclud.h"
#include "config.h"
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include "slang.h"
#include "_slang.h"
void (*SLang_Error_Routine)(char *);
void (*SLang_Exit_Error_Hook)(char *);
void (*SLang_VMessage_Hook) (char *, va_list);
void (*SLang_Error_Hook)(char *);
void (*SLang_Exit_Error_Hook)(char *, va_list);
volatile int SLang_Error = 0;
char *SLang_Error_Message;
volatile int SLKeyBoard_Quit = 0;
static char *get_error_string (void)
{
char *str;
if (!SLang_Error) SLang_Error = SL_UNKNOWN_ERROR;
if (SLang_Error_Message != NULL) str = SLang_Error_Message;
else switch(SLang_Error)
{
case SL_NOT_IMPLEMENTED: str = "Not Implemented"; break;
case SL_APPLICATION_ERROR: str = "Application Error"; break;
case SL_VARIABLE_UNINITIALIZED: str = "Variable Uninitialized"; break;
case SL_MALLOC_ERROR : str = "Malloc Error"; break;
case SL_INTERNAL_ERROR: str = "Internal Error"; break;
case SL_STACK_OVERFLOW: str = "Stack Overflow"; break;
case SL_STACK_UNDERFLOW: str = "Stack Underflow"; break;
case SL_INTRINSIC_ERROR: str = "Intrinsic Error"; break;
case SL_USER_BREAK: str = "User Break"; break;
case SL_UNDEFINED_NAME: str = "Undefined Name"; break;
case SL_SYNTAX_ERROR: str = "Syntax Error"; break;
case SL_DUPLICATE_DEFINITION: str = "Duplicate Definition"; break;
case SL_TYPE_MISMATCH: str = "Type Mismatch"; break;
case SL_READONLY_ERROR: str = "Variable is read-only"; break;
case SL_DIVIDE_ERROR: str = "Divide by zero"; break;
case SL_OBJ_NOPEN: str = "Object not opened"; break;
case SL_OBJ_UNKNOWN: str = "Object unknown"; break;
case SL_INVALID_PARM: str = "Invalid Parameter"; break;
case SL_TYPE_UNDEFINED_OP_ERROR:
str = "Operation not defined for datatype"; break;
case SL_USER_ERROR:
str = "User Error"; break;
case SL_USAGE_ERROR:
str = "Illegal usage of function";
break;
case SL_FLOATING_EXCEPTION:
str = "Floating Point Exception";
break;
case SL_UNKNOWN_ERROR:
default: str = "Unknown Error Code";
}
SLang_Error_Message = NULL;
return str;
}
void SLang_doerror (char *error)
{
if (SLang_Error_Routine == NULL)
char *str = NULL;
char *err;
char *malloced_err_buf;
char err_buf [1024];
malloced_err_buf = NULL;
if (((SLang_Error == SL_USER_ERROR)
|| (SLang_Error == SL_USAGE_ERROR))
&& (error != NULL) && (*error != 0))
err = error;
else
{
fprintf (stderr, "S-Lang Error: %s\r\n", error);
char *sle = "S-Lang Error: ";
unsigned int len;
char *fmt;
str = get_error_string ();
fmt = "%s%s%s";
if ((error == NULL) || (*error == 0))
error = "";
else if (SLang_Error == SL_UNKNOWN_ERROR)
/* Do not display an unknown error message if error is non-NULL */
str = "";
else
fmt = "%s%s: %s";
len = strlen (sle) + strlen (str) + strlen(error) + 1;
err = err_buf;
if (len >= sizeof (err_buf))
{
if (NULL == (malloced_err_buf = SLmalloc (len)))
err = NULL;
else
err = malloced_err_buf;
}
if (err != NULL) sprintf (err, fmt, sle, str, error);
else err = "Out of memory";
}
if (SLang_Error_Hook == NULL)
{
fputs (err, stderr);
fputs("\r\n", stderr);
fflush (stderr);
}
else
(*SLang_Error_Routine)(error);
(*SLang_Error_Hook)(err);
SLfree (malloced_err_buf);
}
void SLang_exit_error (char *s)
void SLang_verror (int err_code, char *fmt, ...)
{
va_list ap;
char err [1024];
if (err_code == 0) err_code = SL_INTRINSIC_ERROR;
if (SLang_Error == 0) SLang_Error = err_code;
if (fmt != NULL)
{
va_start(ap, fmt);
(void) _SLvsnprintf (err, sizeof (err), fmt, ap);
fmt = err;
va_end(ap);
}
SLang_doerror (fmt);
}
void SLang_exit_error (char *fmt, ...)
{
va_list ap;
va_start (ap, fmt);
if (SLang_Exit_Error_Hook != NULL)
{
(*SLang_Exit_Error_Hook) (s);
(*SLang_Exit_Error_Hook) (fmt, ap);
exit (1);
}
if (s != NULL) fprintf (stderr, "%s\n", s);
exit (-1);
if (fmt != NULL)
{
vfprintf (stderr, fmt, ap);
fputs ("\r\n", stderr);
fflush (stderr);
}
va_end (ap);
exit (1);
}
void SLang_vmessage (char *fmt, ...)
{
va_list ap;
if (fmt == NULL)
return;
va_start (ap, fmt);
if (SLang_VMessage_Hook != NULL)
(*SLang_VMessage_Hook) (fmt, ap);
else
{
vfprintf (stdout, fmt, ap);
fputs ("\r\n", stdout);
}
va_end (ap);
}

Просмотреть файл

@ -1,17 +1,17 @@
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
/* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "config.h"
#include "slinclud.h"
#include <stdio.h>
#include "slang.h"
#include "_slang.h"
unsigned int SLang_Input_Buffer_Len = 0;
unsigned char SLang_Input_Buffer [MAX_INPUT_BUFFER_LEN];
unsigned char SLang_Input_Buffer [SL_MAX_INPUT_BUFFER_LEN];
int SLang_Abort_Char = 7;
int SLang_Ignore_User_Abort = 0;
@ -19,13 +19,7 @@ int SLang_Ignore_User_Abort = 0;
/* This has the effect of mapping all characters in the range 128-169 to
* ESC [ something
*/
#ifndef __GO32__
# if defined(__unix__) || defined(vms)
# define DEC_8BIT_HACK 64
# endif
#endif
#ifdef NATIVE_WIN32 /* see the replacement in src/slint.c */
unsigned int SLang_getkey (void)
{
unsigned int imax;
@ -40,29 +34,31 @@ unsigned int SLang_getkey (void)
SLMEMCPY ((char *) SLang_Input_Buffer,
(char *) (SLang_Input_Buffer + 1), imax);
}
else if (0xFFFF == (ch = SLsys_getkey ())) return ch;
else if (SLANG_GETKEY_ERROR == (ch = _SLsys_getkey ())) return ch;
#ifdef DEC_8BIT_HACK
#if _SLANG_MAP_VTXXX_8BIT
# if !defined(IBMPC_SYSTEM)
if (ch & 0x80)
{
unsigned char i;
i = (unsigned char) (ch & 0x7F);
if (i < ' ')
{
i += DEC_8BIT_HACK;
i += 64;
SLang_ungetkey (i);
ch = 27;
}
}
# endif
#endif
return(ch);
}
#endif /* NATIVE_WIN32 */
void SLang_ungetkey_string (unsigned char *s, unsigned int n)
int SLang_ungetkey_string (unsigned char *s, unsigned int n)
{
register unsigned char *bmax, *b, *b1;
if (SLang_Input_Buffer_Len + n + 3 > MAX_INPUT_BUFFER_LEN) return;
if (SLang_Input_Buffer_Len + n + 3 > SL_MAX_INPUT_BUFFER_LEN)
return -1;
b = SLang_Input_Buffer;
bmax = (b - 1) + SLang_Input_Buffer_Len;
@ -71,31 +67,32 @@ void SLang_ungetkey_string (unsigned char *s, unsigned int n)
bmax = b + n;
while (b < bmax) *b++ = *s++;
SLang_Input_Buffer_Len += n;
return 0;
}
void SLang_buffer_keystring (unsigned char *s, unsigned int n)
int SLang_buffer_keystring (unsigned char *s, unsigned int n)
{
if (n + SLang_Input_Buffer_Len + 3 > MAX_INPUT_BUFFER_LEN) return;
if (n + SLang_Input_Buffer_Len + 3 > SL_MAX_INPUT_BUFFER_LEN) return -1;
SLMEMCPY ((char *) SLang_Input_Buffer + SLang_Input_Buffer_Len,
(char *) s, n);
SLang_Input_Buffer_Len += n;
return 0;
}
void SLang_ungetkey (unsigned char ch)
int SLang_ungetkey (unsigned char ch)
{
SLang_ungetkey_string(&ch, 1);
return SLang_ungetkey_string(&ch, 1);
}
#ifdef NATIVE_WIN32 /* see the replacement in src/slint.c */
int SLang_input_pending (int tsecs)
{
int n;
unsigned char c;
if (SLang_Input_Buffer_Len) return (int) SLang_Input_Buffer_Len;
n = SLsys_input_pending (tsecs);
n = _SLsys_input_pending (tsecs);
if (n <= 0) return 0;
@ -104,7 +101,6 @@ int SLang_input_pending (int tsecs)
return n;
}
#endif /* NATIVE_WIN32 */
void SLang_flush_input (void)
{
@ -112,13 +108,199 @@ void SLang_flush_input (void)
SLang_Input_Buffer_Len = 0;
SLKeyBoard_Quit = 0;
while (SLsys_input_pending (0) > 0)
while (_SLsys_input_pending (0) > 0)
{
(void) SLsys_getkey ();
/* Set this to 0 because SLsys_getkey may stuff keyboard buffer if
(void) _SLsys_getkey ();
/* Set this to 0 because _SLsys_getkey may stuff keyboard buffer if
* key sends key sequence (OS/2, DOS, maybe VMS).
*/
SLang_Input_Buffer_Len = 0;
}
SLKeyBoard_Quit = quit;
}
#ifdef IBMPC_SYSTEM
static int Map_To_ANSI;
int SLgetkey_map_to_ansi (int enable)
{
Map_To_ANSI = enable;
return 0;
}
static int convert_scancode (unsigned int scan,
unsigned int shift,
int getkey,
unsigned int *ret_key)
{
unsigned char buf[16];
unsigned char *b;
unsigned char end;
int is_arrow;
shift &= (_SLTT_KEY_ALT|_SLTT_KEY_SHIFT|_SLTT_KEY_CTRL);
b = buf;
if (_SLTT_KEY_ALT == shift)
{
shift = 0;
*b++ = 27;
}
*b++ = 27;
*b++ = '[';
is_arrow = 0;
end = '~';
if (shift)
{
if (shift == _SLTT_KEY_CTRL)
end = '^';
else if (shift == _SLTT_KEY_SHIFT)
end = '$';
else shift = 0;
}
/* These mappings correspond to what rxvt produces under Linux */
switch (scan & 0xFF)
{
default:
return -1;
case 0x47: /* home */
*b++ = '1';
break;
case 0x48: /* up */
end = 'A';
is_arrow = 1;
break;
case 0x49: /* PgUp */
*b++ = '5';
break;
case 0x4B: /* Left */
end = 'D';
is_arrow = 1;
break;
case 0x4D: /* Right */
end = 'C';
is_arrow = 1;
break;
case 0x4F: /* End */
*b++ = '4';
break;
case 0x50: /* Down */
end = 'B';
is_arrow = 1;
break;
case 0x51: /* PgDn */
*b++ = '6';
break;
case 0x52: /* Insert */
*b++ = '2';
break;
case 0x53: /* Delete */
*b++ = '3';
break;
case ';': /* F1 */
*b++ = '1';
*b++ = '1';
break;
case '<': /* F2 */
*b++ = '1';
*b++ = '2';
break;
case '=': /* F3 */
*b++ = '1';
*b++ = '3';
break;
case '>': /* F4 */
*b++ = '1';
*b++ = '4';
break;
case '?': /* F5 */
*b++ = '1';
*b++ = '5';
break;
case '@': /* F6 */
*b++ = '1';
*b++ = '7';
break;
case 'A': /* F7 */
*b++ = '1';
*b++ = '8';
break;
case 'B': /* F8 */
*b++ = '1';
*b++ = '9';
break;
case 'C': /* F9 */
*b++ = '2';
*b++ = '0';
break;
case 'D': /* F10 */
*b++ = '2';
*b++ = '1';
break;
case 0x57: /* F11 */
*b++ = '2';
*b++ = '3';
break;
case 0x58: /* F12 */
*b++ = '2';
*b++ = '4';
break;
}
if (is_arrow && shift)
{
if (shift == _SLTT_KEY_CTRL)
end &= 0x1F;
else
end |= 0x20;
}
*b++ = end;
if (getkey)
{
(void) SLang_buffer_keystring (buf + 1, (unsigned int) (b - (buf + 1)));
*ret_key = buf[0];
return 0;
}
(void) SLang_buffer_keystring (buf, (unsigned int) (b - buf));
return 0;
}
unsigned int _SLpc_convert_scancode (unsigned int scan,
unsigned int shift,
int getkey)
{
unsigned char buf[16];
if (Map_To_ANSI)
{
if (0 == convert_scancode (scan, shift, getkey, &scan))
return scan;
}
if (getkey)
{
buf[0] = scan & 0xFF;
SLang_buffer_keystring (buf, 1);
return (scan >> 8) & 0xFF;
}
buf[0] = (scan >> 8) & 0xFF;
buf[1] = scan & 0xFF;
(void) SLang_buffer_keystring (buf, 2);
return 0;
}
#endif

Просмотреть файл

@ -1,50 +0,0 @@
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
/* These routines are fast memcpy, memset routines. When available, I
use system rouines. For msdos, I use inline assembly. */
/* The current versions only work in the forward direction only!! */
#include "config.h"
#include <stdio.h>
#include "_slang.h"
char *SLmemcpy(char *s1, char *s2, int n)
{
#if defined(msdos) && !defined(__WIN32__) && !defined(__GO32__)
asm mov ax, ds
asm mov bx, si
asm mov dx, di
asm mov cx, n
asm les di, s1
asm lds si, s2
asm cld
asm rep movsb
asm mov ds, ax
asm mov si, bx
asm mov di, dx
return(s1);
#else
register char *smax, *s = s1;
int n2;
n2 = n % 4;
smax = s + (n - 4);
while (s <= smax)
{
*s = *s2; *(s + 1) = *(s2 + 1); *(s + 2) = *(s2 + 2); *(s + 3) = *(s2 + 3);
s += 4;
s2 += 4;
}
while (n2--) *s++ = *s2++;
return(s1);
#endif
}

Просмотреть файл

@ -1,42 +0,0 @@
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
/* These routines are fast memcpy, memset routines. When available, I
use system rouines. For msdos, I use inline assembly. */
/* The current versions only work in the forward direction only!! */
#include "config.h"
#include <stdio.h>
#include "_slang.h"
void SLmemset(char *p, char space, int n)
{
#if defined(msdos) && !defined(__WIN32__) && !defined(__GO32__)
asm mov al, space
asm mov dx, di
asm mov cx, n
asm les di, p
asm cld
asm rep stosb
asm mov di, dx
#else
register char *pmax;
pmax = p + (n - 4);
n = n % 4;
while (p <= pmax)
{
*p++ = space; *p++ = space; *p++ = space; *p++= space;
}
while (n--) *p++ = space;
#endif
}

78
slang/slmisc.c Обычный файл
Просмотреть файл

@ -0,0 +1,78 @@
/* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* Trimmed down for use in GNU Midnight Commander.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "slinclud.h"
#include "slang.h"
#include "_slang.h"
/* p and ch may point to the same buffer */
char *_SLexpand_escaped_char(char *p, char *ch)
{
int i = 0;
int max = 0, num, base = 0;
char ch1;
ch1 = *p++;
switch (ch1)
{
default: num = ch1; break;
case 'n': num = '\n'; break;
case 't': num = '\t'; break;
case 'v': num = '\v'; break;
case 'b': num = '\b'; break;
case 'r': num = '\r'; break;
case 'f': num = '\f'; break;
case 'E': case 'e': num = 27; break;
case 'a': num = 7;
break;
/* octal */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
max = '7';
base = 8; i = 2; num = ch1 - '0';
break;
case 'd': /* decimal -- S-Lang extension */
base = 10;
i = 3;
max = '9';
num = 0;
break;
case 'x': /* hex */
base = 16;
max = '9';
i = 2;
num = 0;
break;
}
while (i--)
{
ch1 = *p;
if ((ch1 <= max) && (ch1 >= '0'))
{
num = base * num + (ch1 - '0');
}
else if (base == 16)
{
ch1 |= 0x20;
if ((ch1 < 'a') || ((ch1 > 'f'))) break;
num = base * num + 10 + (ch1 - 'a');
}
else break;
p++;
}
*ch = (char) num;
return p;
}

Просмотреть файл

@ -1,24 +1,36 @@
#include "config.h"
/* Copyright (c) 1998, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "slinclud.h"
#include <stdio.h>
#include <signal.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#ifdef HAVE_SYS_WAIT_H
# include <sys/wait.h>
#endif
#include <errno.h>
#include "slang.h"
#include "_slang.h"
/* Do not trust these environments */
#if defined(__CYGWIN32__) || defined(__MINGW32__) || defined(AMIGA)
# ifdef SLANG_POSIX_SIGNALS
# undef SLANG_POSIX_SIGNALS
# endif
#endif
/* This function will cause system calls to be restarted after signal if possible */
SLSig_Fun_Type *SLsignal (int sig, SLSig_Fun_Type *f)
{
#ifdef SLANG_POSIX_SIGNALS
#if defined(SLANG_POSIX_SIGNALS)
struct sigaction old_sa, new_sa;
# ifdef SIGALRM
@ -70,7 +82,6 @@ SLSig_Fun_Type *SLsignal_intr (int sig, SLSig_Fun_Type *f)
#endif
}
/* We are primarily interested in blocking signals that would cause the
* application to reset the tty. These include suspend signals and
* possibly interrupt signals.
@ -110,6 +121,9 @@ int SLsig_block_signals (void)
# ifdef SIGTTOU
sigaddset (&new_mask, SIGTTOU);
# endif
# ifdef SIGWINCH
sigaddset (&new_mask, SIGWINCH);
# endif
(void) sigprocmask (SIG_BLOCK, &new_mask, &Old_Signal_Mask);
return 0;
@ -136,3 +150,187 @@ int SLsig_unblock_signals (void)
return -1;
#endif
}
#ifdef MSWINDOWS
int SLsystem (char *cmd)
{
SLang_verror (SL_NOT_IMPLEMENTED, "system not implemented");
return -1;
}
#else
int SLsystem (char *cmd)
{
#ifdef SLANG_POSIX_SIGNALS
pid_t pid;
int status;
struct sigaction ignore;
# ifdef SIGINT
struct sigaction save_intr;
# endif
# ifdef SIGQUIT
struct sigaction save_quit;
# endif
# ifdef SIGCHLD
sigset_t child_mask, save_mask;
# endif
if (cmd == NULL) return 1;
ignore.sa_handler = SIG_IGN;
sigemptyset (&ignore.sa_mask);
ignore.sa_flags = 0;
# ifdef SIGINT
if (-1 == sigaction (SIGINT, &ignore, &save_intr))
return -1;
# endif
# ifdef SIGQUIT
if (-1 == sigaction (SIGQUIT, &ignore, &save_quit))
{
(void) sigaction (SIGINT, &save_intr, NULL);
return -1;
}
# endif
# ifdef SIGCHLD
sigemptyset (&child_mask);
sigaddset (&child_mask, SIGCHLD);
if (-1 == sigprocmask (SIG_BLOCK, &child_mask, &save_mask))
{
# ifdef SIGINT
(void) sigaction (SIGINT, &save_intr, NULL);
# endif
# ifdef SIGQUIT
(void) sigaction (SIGQUIT, &save_quit, NULL);
# endif
return -1;
}
# endif
pid = fork();
if (pid == -1)
status = -1;
else if (pid == 0)
{
/* Child */
# ifdef SIGINT
(void) sigaction (SIGINT, &save_intr, NULL);
# endif
# ifdef SIGQUIT
(void) sigaction (SIGQUIT, &save_quit, NULL);
# endif
# ifdef SIGCHLD
(void) sigprocmask (SIG_SETMASK, &save_mask, NULL);
# endif
execl ("/bin/sh", "sh", "-c", cmd, NULL);
_exit (127);
}
else
{
/* parent */
while (-1 == waitpid (pid, &status, 0))
{
# ifdef EINTR
if (errno == EINTR)
continue;
# endif
# ifdef ERESTARTSYS
if (errno == ERESTARTSYS)
continue;
# endif
status = -1;
break;
}
}
# ifdef SIGINT
if (-1 == sigaction (SIGINT, &save_intr, NULL))
status = -1;
# endif
# ifdef SIGQUIT
if (-1 == sigaction (SIGQUIT, &save_quit, NULL))
status = -1;
# endif
# ifdef SIGCHLD
if (-1 == sigprocmask (SIG_SETMASK, &save_mask, NULL))
status = -1;
# endif
return status;
#else /* No POSIX Signals */
# ifdef SIGINT
void (*sint)(int);
# endif
# ifdef SIGQUIT
void (*squit)(int);
# endif
int status;
# ifdef SIGQUIT
squit = SLsignal (SIGQUIT, SIG_IGN);
# endif
# ifdef SIGINT
sint = SLsignal (SIGINT, SIG_IGN);
# endif
status = system (cmd);
# ifdef SIGINT
SLsignal (SIGINT, sint);
# endif
# ifdef SIGQUIT
SLsignal (SIGQUIT, squit);
# endif
return status;
#endif /* POSIX_SIGNALS */
}
#endif
#if 0
#include <windows.h>
static int msw_system (char *cmd)
{
STARTUPINFO startup_info;
PROCESS_INFORMATION process_info;
int status;
if (cmd == NULL) return -1;
memset ((char *) &startup_info, 0, sizeof (STARTUPINFO));
startup_info.cb = sizeof(STARTUPINFO);
startup_info.dwFlags = STARTF_USESHOWWINDOW;
startup_info.wShowWindow = SW_SHOWDEFAULT;
if (FALSE == CreateProcess (NULL,
cmd,
NULL,
NULL,
FALSE,
NORMAL_PRIORITY_CLASS|CREATE_NEW_CONSOLE,
NULL,
NULL,
&startup_info,
&process_info))
{
SLang_verror (0, "%s: CreateProcess failed.", cmd);
return -1;
}
status = -1;
if (0xFFFFFFFFUL != WaitForSingleObject (process_info.hProcess, INFINITE))
{
DWORD exit_code;
if (TRUE == GetExitCodeProcess (process_info.hProcess, &exit_code))
status = (int) exit_code;
}
CloseHandle (process_info.hThread);
CloseHandle (process_info.hProcess);
return status;
}
#endif

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,354 +0,0 @@
/*--------------------------------*-C-*---------------------------------*
* File: sltoken.c
*
* Descript: ---
*
* Requires: ---
*
* Public: SLexpand_escaped_char ();
* SLexpand_escaped_string ();
* SLang_extract_token ();
* SLang_guess_type ();
* SLatoi ();
*
* Private: ---
*
* Notes: ---
*
* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
\*----------------------------------------------------------------------*/
#include "config.h"
#include <stdio.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <string.h>
#include "_slang.h"
/* There are non-zeros at positions "\t %()*,/:;[]{}" */
static const unsigned char special_chars[256] =
{
/* 0 */ 0,0,0,0,0,0,0,0, 0,'\t',0,0,0,0,0,0,
/* 16 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 32 */ ' ',0,0,0,0,'%',0,0, '(',')','*',0,',',0,0,'/',
/* 48 */ 0,0,0,0,0,0,0,0, 0,0,':',';',0,0,0,0,
/* 64 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 80 */ 0,0,0,0,0,0,0,0, 0,0,0,'[',0,']',0,0,
/* 96 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 112 */ 0,0,0,0,0,0,0,0, 0,0,0,'{',0,'}',0,0,
/* 8-bit characters */
/* 128 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 144 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 160 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 176 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 192 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 208 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 224 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,
/* 240 */ 0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0
};
char *SLexpand_escaped_char(char *p, char *ch)
{
int i = 0;
int max = 0, num, base = 0;
char ch1;
ch1 = *p++;
switch (ch1)
{
default: num = ch1; break;
case 'n': num = '\n'; break;
case 't': num = '\t'; break;
case 'v': num = '\v'; break;
case 'b': num = '\b'; break;
case 'r': num = '\r'; break;
case 'f': num = '\f'; break;
case 'E': case 'e': num = 27; break;
case 'a': num = 7;
break;
/* octal */
case '0': case '1': case '2': case '3':
case '4': case '5': case '6': case '7':
max = '7';
base = 8; i = 2; num = ch1 - '0';
break;
case 'd': /* decimal -- S-Lang extension */
base = 10;
i = 3;
max = '9';
num = 0;
break;
case 'x': /* hex */
base = 16;
max = '9';
i = 2;
num = 0;
break;
}
while (i--)
{
ch1 = *p;
if ((ch1 <= max) && (ch1 >= '0'))
{
num = base * num + (ch1 - '0');
}
else if (base == 16)
{
ch1 |= 0x20;
if ((ch1 < 'a') || ((ch1 > 'f'))) break;
num = base * num + 10 + (ch1 - 'a');
}
else break;
p++;
}
*ch = (char) num;
return p;
}
void SLexpand_escaped_string (register char *s, register char *t,
register char *tmax)
{
char ch;
while (t < tmax)
{
ch = *t++;
if (ch == '\\')
{
t = SLexpand_escaped_char (t, &ch);
}
*s++ = ch;
}
*s = 0;
}
int SLang_extract_token (char **linep, char *word_parm, int byte_comp)
{
register char ch, *line, *word = word_parm;
int string;
char ch1;
char *word_max;
word_max = word + 250;
line = *linep;
/* skip white space */
while (((ch = *line) == ' ')
|| (ch == '\t')) line++;
if ((!ch) || (ch == '\n'))
{
*linep = line;
return(0);
}
*word++ = ch;
line++;
/* Look for -something and rule out --something and -= something */
if ((ch == '-') &&
(*line != '-') && (*line != '=') && ((*line > '9') || (*line < '0')))
{
*word = 0;
*linep = line;
return 1;
}
if (ch == '"') string = 1; else string = 0;
if (ch == '\'')
{
if ((ch = *line++) != 0)
{
if (ch == '\\')
{
line = SLexpand_escaped_char(line, &ch1);
ch = ch1;
}
if (*line++ == '\'')
{
--word;
sprintf(word, "%d", (int) ((unsigned char) ch));
word += strlen (word); ch = '\'';
}
else SLang_Error = SYNTAX_ERROR;
}
else SLang_Error = SYNTAX_ERROR;
}
else if (!special_chars[(unsigned char) ch])
{
while (ch = *line++,
(ch > '"') ||
((ch != '\n') && (ch != 0) && (ch != '"')))
{
if (string)
{
if (ch == '\\')
{
ch = *line++;
if ((ch == 0) || (ch == '\n')) break;
if (byte_comp) *word++ = '\\';
else
{
line = SLexpand_escaped_char(line - 1, &ch1);
ch = ch1;
}
}
}
else if (special_chars[(unsigned char) ch])
{
line--;
break;
}
*word++ = ch;
if (word > word_max)
{
SLang_doerror ("Token to large.");
break;
}
}
}
if ((!ch) || (ch == '\n')) line--;
if ((ch == '"') && string) *word++ = '"'; else if (string) SLang_Error = SYNTAX_ERROR;
*word = 0;
*linep = line;
/* massage variable-- and ++ into --variable, etc... */
if (((int) (word - word_parm) > 2)
&& (ch = *(word - 1), (ch == '+') || (ch == '-'))
&& (ch == *(word - 2)))
{
word--;
while (word >= word_parm + 2)
{
*word = *(word - 2);
word--;
}
*word-- = ch;
*word-- = ch;
}
return(1);
}
int SLang_guess_type (char *t)
{
char *p;
register char ch;
if (*t == '-') t++;
p = t;
#ifdef FLOAT_TYPE
if (*p != '.')
{
#endif
while ((*p >= '0') && (*p <= '9')) p++;
if (t == p) return(STRING_TYPE);
if ((*p == 'x') && (p == t + 1)) /* 0x?? */
{
p++;
while (ch = *p,
((ch >= '0') && (ch <= '9'))
|| (((ch | 0x20) >= 'a') && ((ch | 0x20) <= 'f'))) p++;
}
if (*p == 0) return(INT_TYPE);
#ifndef FLOAT_TYPE
return(STRING_TYPE);
#else
}
/* now down to float case */
if (*p == '.')
{
p++;
while ((*p >= '0') && (*p <= '9')) p++;
}
if (*p == 0) return(FLOAT_TYPE);
if ((*p != 'e') && (*p != 'E')) return(STRING_TYPE);
p++;
if ((*p == '-') || (*p == '+')) p++;
while ((*p >= '0') && (*p <= '9')) p++;
if (*p != 0) return(STRING_TYPE); else return(FLOAT_TYPE);
#endif
}
int SLatoi (unsigned char *s)
{
register unsigned char ch;
register unsigned int value;
register int base;
if (*s != '0') return atoi((char *) s);
/* look for 'x' which indicates hex */
s++;
if ((*s | 0x20) == 'x')
{
base = 16;
s++;
if (*s == 0)
{
SLang_Error = SYNTAX_ERROR;
return -1;
}
}
else base = 8;
value = 0;
while ((ch = *s++) != 0)
{
char ch1 = ch | 0x20;
switch (ch1)
{
default:
SLang_Error = SYNTAX_ERROR;
break;
case '8':
case '9':
if (base != 16) SLang_Error = SYNTAX_ERROR;
/* drop */
case '0':
case '1':
case '2':
case '3':
case '4':
case '5':
case '6':
case '7':
ch1 -= '0';
break;
case 'a':
case 'b':
case 'c':
case 'd':
case 'e':
case 'f':
if (base != 16) SLang_Error = SYNTAX_ERROR;
ch1 = (ch1 - 'a') + 10;
break;
}
value = value * base + ch1;
}
return (int) value;
}

Просмотреть файл

@ -1,15 +1,13 @@
/* slutty.c --- Unix Low level terminal (tty) functions for S-Lang */
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
/* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "slinclud.h"
#include "config.h"
#include <stdio.h>
#include <signal.h>
/* sequent support thanks to Kenneth Lorber <keni@oasys.dt.navy.mil> */
/* SYSV (SYSV ISC R3.2 v3.0) provided by iain.lea@erlm.siemens.de */
@ -18,14 +16,6 @@
# define _ALL_SOURCE /* so NBBY is defined in <sys/types.h> */
#endif
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
#include <sys/time.h>
#include <sys/types.h>
@ -39,7 +29,6 @@
# endif
#endif
#ifdef __BEOS__
/* Prototype for select */
# include <net/socket.h>
@ -66,13 +55,12 @@
# include <fcntl.h>
#endif
#include "slang.h"
#include "_slang.h"
int SLang_TT_Read_FD = -1;
int SLang_TT_Baud_Rate;
#ifdef HAVE_TERMIOS_H
# if !defined(HAVE_TCGETATTR) || !defined(HAVE_TCSETATTR)
# undef HAVE_TERMIOS_H
@ -103,39 +91,103 @@ typedef struct termios TTY_Termio_Type;
static TTY_Termio_Type Old_TTY;
#ifdef HAVE_TERMIOS_H
static const struct
typedef struct
{
speed_t key;
int value;
} Baud_Rates[] =
unsigned int key;
unsigned int value;
} Baud_Rate_Type;
static Baud_Rate_Type Baud_Rates [] =
{
{B0, 0},
{B50, 50},
{B75, 75},
{B110, 110},
{B134, 134},
{B150, 150},
{B200, 200},
{B300, 300},
{B600, 600},
{B1200, 1200},
{B1800, 1800},
{B2400, 2400},
{B4800, 4800},
{B9600, 9600},
{B19200, 19200},
{B38400, 38400}
#ifdef B0
{B0, 0},
#endif
#ifdef B50
{B50, 50},
#endif
#ifdef B75
{B75, 75},
#endif
#ifdef B110
{B110, 110},
#endif
#ifdef B134
{B134, 134},
#endif
#ifdef B150
{B150, 150},
#endif
#ifdef B200
{B200, 200},
#endif
#ifdef B300
{B300, 300},
#endif
#ifdef B600
{B600, 600},
#endif
#ifdef B1200
{B1200, 1200},
#endif
#ifdef B1800
{B1800, 1800},
#endif
#ifdef B2400
{B2400, 2400},
#endif
#ifdef B4800
{B4800, 4800},
#endif
#ifdef B9600
{B9600, 9600},
#endif
#ifdef B19200
{B19200, 19200},
#endif
#ifdef B38400
{B38400, 38400},
#endif
#ifdef B57600
, {B57600, 57600}
{B57600, 57600},
#endif
#ifdef B115200
, {B115200, 115200}
{B115200, 115200},
#endif
#ifdef B230400
, {B230400, 230400}
{B230400, 230400},
#endif
{0, 0}
};
static void
set_baud_rate (TTY_Termio_Type *tty)
{
#ifdef HAVE_CFGETOSPEED
unsigned int speed;
Baud_Rate_Type *b, *bmax;
if (SLang_TT_Baud_Rate)
return; /* already set */
speed = (unsigned int) cfgetospeed (tty);
b = Baud_Rates;
bmax = b + (sizeof (Baud_Rates)/sizeof(Baud_Rates[0]));
while (b < bmax)
{
if (b->key == speed)
{
SLang_TT_Baud_Rate = b->value;
return;
}
b++;
}
#else
(void) tty;
#endif
}
#endif /* HAVE_TERMIOS_H */
#ifdef HAVE_TERMIOS_H
# define GET_TERMIOS(fd, x) tcgetattr(fd, x)
@ -170,17 +222,6 @@ static int TTY_Open = 0;
# endif
#endif
static int
speed_t2baud_rate (speed_t s)
{
int i;
for (i = 0; i < sizeof (Baud_Rates)/sizeof (Baud_Rates[0]); i++)
if (Baud_Rates[i].key == s)
return (Baud_Rates[i].value);
return 0;
}
int SLang_init_tty (int abort_char, int no_flow_control, int opost)
{
TTY_Termio_Type newtty;
@ -198,30 +239,19 @@ int SLang_init_tty (int abort_char, int no_flow_control, int opost)
if ((SLang_TT_Read_FD == -1)
|| (1 != isatty (SLang_TT_Read_FD)))
{
#if 0
#ifdef O_RDWR
# ifndef __BEOS__ /* I have been told that BEOS will HANG if passed /dev/tty */
# if !defined(__BEOS__) && !defined(__APPLE__)
/* I have been told that BEOS will HANG if passed /dev/tty */
if ((SLang_TT_Read_FD = open("/dev/tty", O_RDWR)) >= 0)
{
TTY_Open = 1;
}
# endif
#endif
#endif /* 0 */
if (TTY_Open == 0)
{
#if 0
/* In the Midnight Commander we bind stderr sometimes to a pipe. If we
use stderr for terminal input and call SLang_getkey while stderr is
bound to a pipe MC will hang completly in SLsys_input_pending.
NOTE: There's an independent fix for this problem in src/slint.c for
the case that the Midnight Commander is linked against a shared slang
library compiled from different sources.
*/
SLang_TT_Read_FD = fileno (stderr);
if (1 != isatty (SLang_TT_Read_FD))
#endif
{
SLang_TT_Read_FD = fileno (stdin);
if (1 != isatty (SLang_TT_Read_FD))
@ -257,6 +287,8 @@ int SLang_init_tty (int abort_char, int no_flow_control, int opost)
}
#ifndef HAVE_TERMIOS_H
(void) opost;
(void) no_flow_control;
newtty.s.sg_flags &= ~(ECHO);
newtty.s.sg_flags &= ~(CRMOD);
/* if (Flow_Control == 0) newtty.s.sg_flags &= ~IXON; */
@ -272,35 +304,30 @@ int SLang_init_tty (int abort_char, int no_flow_control, int opost)
/* get baud rate */
/* [not only QNX related !?!]
* ECHO(0x08) is a c_lflag bit, it means here PARMRK(0x08) in c_iflag!!!
*/
/*newtty.c_iflag &= ~(ECHO | INLCR | ICRNL);*/
newtty.c_iflag &= ~(INLCR | ICRNL);
newtty.c_iflag &= ~(ECHO | INLCR | ICRNL);
#ifdef ISTRIP
/* newtty.c_iflag &= ~ISTRIP; */
#endif
if (opost == 0) newtty.c_oflag &= ~OPOST;
if (SLang_TT_Baud_Rate == 0)
{
/* Note: if this generates an compiler error, simply remove
the statement */
#ifdef HAVE_CFGETOSPEED
SLang_TT_Baud_Rate = cfgetospeed (&newtty);
#endif
SLang_TT_Baud_Rate = speed_t2baud_rate (SLang_TT_Baud_Rate);
}
set_baud_rate (&newtty);
if (no_flow_control) newtty.c_iflag &= ~IXON; else newtty.c_iflag |= IXON;
newtty.c_cc[VEOF] = 1;
newtty.c_cc[VMIN] = 1;
newtty.c_cc[VTIME] = 0;
newtty.c_cc[VEOF] = 1;
newtty.c_lflag = ISIG | NOFLSH;
if (abort_char == -1) SLang_Abort_Char = newtty.c_cc[VINTR];
newtty.c_cc[VINTR] = SLang_Abort_Char; /* ^G */
newtty.c_cc[VQUIT] = NULL_VALUE;
newtty.c_cc[VSUSP] = NULL_VALUE; /* to ignore ^Z */
#ifdef VDSUSP
newtty.c_cc[VDSUSP] = NULL_VALUE; /* to ignore ^Y */
#endif
#ifdef VLNEXT
newtty.c_cc[VLNEXT] = NULL_VALUE; /* to ignore ^V ? */
#endif
#ifdef VSWTCH
newtty.c_cc[VSWTCH] = NULL_VALUE; /* to ignore who knows what */
#endif
@ -337,11 +364,32 @@ void SLtty_set_suspend_state (int mode)
;
#ifndef HAVE_TERMIOS_H
if (mode == 0) newtty.lt.t_suspc = 255;
else newtty.lt.t_suspc = Old_TTY.lt.t_suspc;
/* I do not know if all systems define the t_dsuspc field */
if (mode == 0)
{
newtty.lt.t_suspc = 255;
newtty.lt.t_dsuspc = 255;
}
else
{
newtty.lt.t_suspc = Old_TTY.lt.t_suspc;
newtty.lt.t_dsuspc = Old_TTY.lt.t_dsuspc;
}
#else
if (mode == 0) newtty.c_cc[VSUSP] = NULL_VALUE;
else newtty.c_cc[VSUSP] = Old_TTY.c_cc[VSUSP];
if (mode == 0)
{
newtty.c_cc[VSUSP] = NULL_VALUE;
#ifdef VDSUSP
newtty.c_cc[VDSUSP] = NULL_VALUE;
#endif
}
else
{
newtty.c_cc[VSUSP] = Old_TTY.c_cc[VSUSP];
#ifdef VDSUSP
newtty.c_cc[VDSUSP] = Old_TTY.c_cc[VDSUSP];
#endif
}
#endif
while ((-1 == SET_TERMIOS (SLang_TT_Read_FD, &newtty))
@ -384,19 +432,25 @@ static void default_sigint (int sig)
sig = errno; /* use parameter */
SLKeyBoard_Quit = 1;
if (SLang_Ignore_User_Abort == 0) SLang_Error = USER_BREAK;
if (SLang_Ignore_User_Abort == 0) SLang_Error = SL_USER_BREAK;
SLsignal_intr (SIGINT, default_sigint);
errno = sig;
}
void SLang_set_abort_signal (void (*hand)(int))
int SLang_set_abort_signal (void (*hand)(int))
{
int save_errno = errno;
SLSig_Fun_Type *f;
if (hand == NULL) hand = default_sigint;
SLsignal_intr (SIGINT, hand);
f = SLsignal_intr (SIGINT, hand);
errno = save_errno;
if (f == (SLSig_Fun_Type *) SIG_ERR)
return -1;
return 0;
}
#ifndef FD_SET
@ -408,15 +462,19 @@ typedef int fd_set;
static fd_set Read_FD_Set;
/* HACK: If > 0, use 1/10 seconds. If < 0, use 1/1000 seconds */
int SLsys_input_pending(int tsecs)
int _SLsys_input_pending(int tsecs)
{
struct timeval wait;
long usecs, secs;
if (TTY_Inited == 0) return -1;
if ((TTY_Inited == 0)
|| (SLang_TT_Read_FD < 0))
{
errno = EBADF;
return -1;
}
if (tsecs >= 0)
{
@ -439,7 +497,6 @@ int SLsys_input_pending(int tsecs)
return select(SLang_TT_Read_FD + 1, &Read_FD_Set, NULL, NULL, &wait);
}
int (*SLang_getkey_intr_hook) (void);
static int handle_interrupt (void)
@ -458,10 +515,9 @@ static int handle_interrupt (void)
return 0;
}
unsigned int SLsys_getkey (void)
unsigned int _SLsys_getkey (void)
{
unsigned char c;
unsigned int i;
if (TTY_Inited == 0)
{
@ -477,7 +533,7 @@ unsigned int SLsys_getkey (void)
if (SLKeyBoard_Quit)
return SLang_Abort_Char;
if (0 == (ret = SLsys_input_pending (100)))
if (0 == (ret = _SLsys_input_pending (100)))
continue;
if (ret != -1)
@ -497,8 +553,19 @@ unsigned int SLsys_getkey (void)
break; /* let read handle it */
}
while (-1 == (i = read(SLang_TT_Read_FD, (char *) &c, 1)))
while (1)
{
int status = read(SLang_TT_Read_FD, (char *) &c, 1);
if (status > 0)
break;
if (status == 0)
{
/* We are at the end of a file. Let application handle it. */
return SLANG_GETKEY_ERROR;
}
if (errno == EINTR)
{
if (-1 == handle_interrupt ())
@ -526,15 +593,12 @@ unsigned int SLsys_getkey (void)
#ifdef EIO
if (errno == EIO)
{
SLang_exit_error ("SLsys_getkey: EIO error.");
SLang_exit_error ("_SLsys_getkey: EIO error.");
}
#endif
return SLANG_GETKEY_ERROR;
}
if (i == 0)
return SLANG_GETKEY_ERROR;
return((unsigned int) c);
}

Разница между файлами не показана из-за своего большого размера Загрузить разницу

Просмотреть файл

@ -1,16 +1,16 @@
/* Copyright (c) 1992, 1995 John E. Davis
* All rights reserved.
/* Copyright (c) 1992, 1999, 2001, 2002 John E. Davis
* This file is part of the S-Lang library.
*
* You may distribute under the terms of either the GNU General Public
* License or the Perl Artistic License.
*/
#include "config.h"
#include <stdio.h>
#include "slinclud.h"
#include <windows.h>
#include <winbase.h>
#include "slang.h"
#include "_slang.h"
#ifdef __cplusplus
@ -19,7 +19,7 @@
# define _DOTS_ void
#endif
static int Process_Mouse_Events;
/*----------------------------------------------------------------------*\
* Function: static void set_ctrl_break (int state);
@ -30,7 +30,6 @@ static void set_ctrl_break (int state)
{
}
/*----------------------------------------------------------------------*\
* Function: int SLang_init_tty (int abort_char, int no_flow_control,
* int opost);
@ -40,77 +39,40 @@ static void set_ctrl_break (int state)
* NO_FLOW_CONTROL and OPOST are only for compatiblity and are ignored.
\*----------------------------------------------------------------------*/
HANDLE hStdout, hStdin;
CONSOLE_SCREEN_BUFFER_INFO csbiInfo;
HANDLE _SLw32_Hstdin = INVALID_HANDLE_VALUE;
int SLang_init_tty (int abort_char, int no_flow_control, int opost)
{
SMALL_RECT windowRect;
COORD newPosition;
long flags;
(void) opost;
(void) no_flow_control;
#ifndef SLANG_SAVES_CONSOLE
/* first off, create a new console so the old one can be restored on exit */
HANDLE console = CreateConsoleScreenBuffer(GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ |FILE_SHARE_WRITE,
0,
CONSOLE_TEXTMODE_BUFFER,
0);
if (SetConsoleActiveScreenBuffer(console) == FALSE) {
return -1;
}
#endif
if (_SLw32_Hstdin != INVALID_HANDLE_VALUE)
return 0;
/* start things off at the origin */
newPosition.X = 0;
newPosition.Y = 0;
/* still read in characters from stdin, but output to the new console */
/* this way, on program exit, the original screen is restored */
hStdin = GetStdHandle(STD_INPUT_HANDLE);
/* hStdin = console; */
#ifndef SLANG_SAVES_CONSOLE
hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
#if 1
/* stdin may have been redirected. So try this */
_SLw32_Hstdin = CreateFile ("CONIN$", GENERIC_READ|GENERIC_WRITE,
FILE_SHARE_READ|FILE_SHARE_WRITE, NULL,
OPEN_EXISTING, 0, NULL);
if (_SLw32_Hstdin == INVALID_HANDLE_VALUE)
return -1;
#else
hStdout = console;
if (INVALID_HANDLE_VALUE == (_SLw32_Hstdin = GetStdHandle(STD_INPUT_HANDLE)))
return -1;
#endif
if (hStdin == INVALID_HANDLE_VALUE || hStdout == INVALID_HANDLE_VALUE) {
return -1; /* failure */
}
if (FALSE == SetConsoleMode(_SLw32_Hstdin, ENABLE_WINDOW_INPUT|ENABLE_MOUSE_INPUT))
{
_SLw32_Hstdin = INVALID_HANDLE_VALUE;
return -1;
}
if (!GetConsoleScreenBufferInfo(hStdout, &csbiInfo)) {
return -1; /* failure */
} // if
if (abort_char > 0)
SLang_Abort_Char = abort_char;
windowRect.Left = 0;
windowRect.Top = 0;
windowRect.Right = csbiInfo.dwSize.X - 1;
windowRect.Bottom = csbiInfo.dwSize.Y - 1;
if (!SetConsoleWindowInfo(hStdout, TRUE, &windowRect)) {
return -1;
}
if (SetConsoleMode(hStdin, 0) == FALSE) {
return -1; /* failure */
}
if (SetConsoleMode(hStdout, 0) == FALSE) {
return -1; /* failure */
}
if (GetConsoleMode(hStdin, &flags)) {
if (flags & ENABLE_PROCESSED_INPUT) {
return -1;
}
}
(void) SetConsoleCursorPosition(hStdout, newPosition);
/* success */
return 0;
} /* SLang_init_tty */
return 0;
}
/* SLang_init_tty */
/*----------------------------------------------------------------------*\
* Function: void SLang_reset_tty (void);
@ -119,70 +81,224 @@ int SLang_init_tty (int abort_char, int no_flow_control, int opost)
\*----------------------------------------------------------------------*/
void SLang_reset_tty (void)
{
_SLw32_Hstdin = INVALID_HANDLE_VALUE;
set_ctrl_break (1);
}
/*----------------------------------------------------------------------*\
* Function: int SLsys_input_pending (int tsecs);
*
* sleep for *tsecs tenths of a sec waiting for input
\*----------------------------------------------------------------------*/
int SLsys_input_pending (int tsecs)
static int process_mouse_event (MOUSE_EVENT_RECORD *m)
{
INPUT_RECORD record;
long one = 1;
long bytesRead;
char buf [8];
while (1)
if (Process_Mouse_Events == 0)
return -1;
if (m->dwEventFlags)
return -1; /* double click or movement event */
/* A button was either pressed or released. Now make sure that
* the shift keys were not also pressed.
*/
if (m->dwControlKeyState
& (LEFT_ALT_PRESSED|RIGHT_ALT_PRESSED
|LEFT_CTRL_PRESSED|RIGHT_CTRL_PRESSED
|SHIFT_PRESSED))
return -1;
/* We have a simple press or release. Encode it as an escape sequence
* and buffer the result. The encoding is:
* 'ESC [ M b x y'
* where b represents the button state, and x,y represent the coordinates.
* The ESC is handled by the calling routine.
*/
if (m->dwButtonState & 1) buf[3] = ' ';
else if (m->dwButtonState & 2) buf[3] = ' ' + 2;
else if (m->dwButtonState & 4) buf[3] = ' ' + 1;
else return -1;
buf[0] = 27;
buf[1] = '[';
buf[2] = 'M';
buf[4] = 1 + ' ' + m->dwMousePosition.X;
buf[5] = 1 + ' ' + m->dwMousePosition.Y;
return SLang_buffer_keystring ((unsigned char *)buf, 6);
}
static int process_key_event (KEY_EVENT_RECORD *key)
{
unsigned int key_state = 0;
unsigned int scan;
char c1;
DWORD d = key->dwControlKeyState;
unsigned char buf[4];
if (!key->bKeyDown) return 0;
if (d & (LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
key_state |= _SLTT_KEY_ALT;
if (d & (LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
key_state |= _SLTT_KEY_CTRL;
if (d & SHIFT_PRESSED)
key_state |= _SLTT_KEY_SHIFT;
scan = key->wVirtualScanCode;
switch (scan)
{
if (PeekConsoleInput(hStdin, &record, 1, &bytesRead))
{
if (bytesRead == 1)
{
if ((record.EventType == KEY_EVENT)
&& record.Event.KeyEvent.bKeyDown)
{
/* ok, there is a keypress here */
return 1;
}
else
{
/* something else is here, so read it and try again */
(void) ReadConsoleInput(hStdin, &record, 1, &bytesRead);
}
}
else
{
/* no Pending events */
return 0;
}
}
case 0x00E: /* backspace */
return SLang_buffer_keystring ((unsigned char *)"\x7F", 1);
case 0x003: /* 2 key */
if (key_state & _SLTT_KEY_ALT)
break;
/* Drop */
case 0x039: /* space */
if (key_state & _SLTT_KEY_CTRL)
return SLang_buffer_keystring ((unsigned char *)"\x00\x03", 2);
break;
case 0x007: /* 6 key */
if (_SLTT_KEY_CTRL == (key_state & (_SLTT_KEY_ALT|_SLTT_KEY_CTRL)))
return SLang_buffer_keystring ((unsigned char *)"\x1E", 1); /* Ctrl-^ */
break;
case 0x00C: /* -/_ key */
if (_SLTT_KEY_CTRL == (key_state & (_SLTT_KEY_ALT|_SLTT_KEY_CTRL)))
return SLang_buffer_keystring ((unsigned char *)"\x1F", 1);
break;
case 0x00F: /* TAB */
if (_SLTT_KEY_SHIFT == key_state)
return SLang_buffer_keystring ((unsigned char *)"\x00\x09", 2);
break;
case 0xE02F: /* KEYPAD SLASH */
case 0x037: /* KEYPAD STAR */
case 0x04A: /* KEYPAD MINUS */
case 0x04E: /* KEYPAD PLUS */
if (d & NUMLOCK_ON)
break;
case 0x047: /* KEYPAD HOME */
case 0x048: /* KEYPAD UP */
case 0x049: /* KEYPAD PGUP */
case 0x04B: /* KEYPAD LEFT */
case 0x04C: /* KEYPAD 5 */
case 0x04D: /* KEYPAD RIGHT */
case 0x04F: /* KEYPAD END */
case 0x050: /* KEYPAD DOWN */
case 0x051: /* KEYPAD PGDN */
case 0x052: /* KEYPAD INSERT */
case 0x053: /* KEYPAD DEL */
if (d & ENHANCED_KEY)
scan |= 0xE000;
else
{
/* function failed */
return 0;
if (d & NUMLOCK_ON)
break;
}
}
#if 0
/* no delays yet */
/* use Sleep */
/*
int count = tsecs * 5;
(void) _SLpc_convert_scancode (scan, key_state, 0);
return 0;
if (keyWaiting()) return 1;
while (count > 0)
{
delay (20); 20 ms or 1/50 sec
if (keyWaiting()) break;
count--;
case 0x3b: /* F1 */
case 0x3c:
case 0x3d:
case 0x3e:
case 0x3f:
case 0x40:
case 0x41:
case 0x42:
case 0x43:
case 0x44:
case 0x57:
case 0x58: /* F12 */
(void) _SLpc_convert_scancode (scan, key_state, 0);
}
c1 = key->uChar.AsciiChar;
if (c1 != 0)
{
if (_SLTT_KEY_ALT == (key_state & (_SLTT_KEY_ALT|_SLTT_KEY_CTRL)))
{
buf[0] = 27;
buf[1] = c1;
return SLang_buffer_keystring (buf, 2);
}
if (c1 == SLang_Abort_Char)
{
if (SLang_Ignore_User_Abort == 0) SLang_Error = USER_BREAK;
SLKeyBoard_Quit = 1;
}
buf[0] = c1;
return SLang_buffer_keystring (buf, 1);
}
return 0;
}
static void process_console_records(void)
{
INPUT_RECORD record;
DWORD bytesRead;
DWORD n = 0;
if (FALSE == GetNumberOfConsoleInputEvents(_SLw32_Hstdin, &n))
return;
while (n > 0)
{
ReadConsoleInput(_SLw32_Hstdin, &record, 1, &bytesRead);
switch (record.EventType)
{
case KEY_EVENT:
(void) process_key_event(&record.Event.KeyEvent);
break;
case MOUSE_EVENT:
process_mouse_event(&record.Event.MouseEvent);
break;
case WINDOW_BUFFER_SIZE_EVENT:
/* process_resize_records(&record.Event.WindowBufferSizeEvent); */
break;
}
n--;
}
return (count);
*/
#endif
}
/*----------------------------------------------------------------------*\
* Function: unsigned int SLsys_getkey (void);
* Function: int _SLsys_input_pending (int tsecs);
*
* sleep for *tsecs tenths of a sec waiting for input
\*----------------------------------------------------------------------*/
int _SLsys_input_pending (int tsecs)
{
long ms;
if (_SLw32_Hstdin == INVALID_HANDLE_VALUE)
return -1;
if (tsecs < 0) ms = -tsecs; /* specifies 1/1000 */
else ms = tsecs * 100L; /* convert 1/10 to 1/1000 secs */
process_console_records ();
while ((ms > 0)
&& (SLang_Input_Buffer_Len == 0))
{
long t;
t = GetTickCount ();
(void) WaitForSingleObject (_SLw32_Hstdin, ms);
process_console_records ();
ms -= GetTickCount () - t;
}
return SLang_Input_Buffer_Len;
}
/*----------------------------------------------------------------------*\
* Function: unsigned int _SLsys_getkey (void);
*
* wait for and get the next available keystroke.
* Also re-maps some useful keystrokes.
@ -191,33 +307,48 @@ int SLsys_input_pending (int tsecs)
* Ctrl-Space => ^@ (^@^3 - a pc NUL char)
* extended keys are prefixed by a null character
\*----------------------------------------------------------------------*/
unsigned int SLsys_getkey (void)
unsigned int _SLsys_getkey (void)
{
unsigned int scan, ch, shift;
long key, bytesRead;
INPUT_RECORD record;
/* Check the input buffer because _SLsys_input_pending may have been
* called prior to this to stuff the input buffer.
*/
if (SLang_Input_Buffer_Len)
return SLang_getkey ();
while (1) {
if (!ReadConsoleInput(hStdin, &record, 1, &bytesRead)) {
return 0;
}
if (record.EventType == KEY_EVENT && record.Event.KeyEvent.bKeyDown) {
#ifndef __MINGW32__
return record.Event.KeyEvent.uChar.AsciiChar;
#else
return record.Event.KeyEvent.AsciiChar;
#endif
}
}
/* ReadFile(hStdin, &key, 1, &bytesRead, NULL); */
if (_SLw32_Hstdin == INVALID_HANDLE_VALUE)
return SLANG_GETKEY_ERROR;
/* return key; */
while (1)
{
int status;
if (SLKeyBoard_Quit)
return SLang_Abort_Char;
status = _SLsys_input_pending (600);
if (status == -1)
return SLANG_GETKEY_ERROR;
if (status > 0)
return SLang_getkey ();
}
}
/*----------------------------------------------------------------------*\
* Function: void SLang_set_abort_signal (void (*handler)(int));
* Function: int SLang_set_abort_signal (void (*handler)(int));
\*----------------------------------------------------------------------*/
void SLang_set_abort_signal (void (*handler)(int))
int SLang_set_abort_signal (void (*handler)(int))
{
if (_SLw32_Hstdin == INVALID_HANDLE_VALUE)
return -1;
return 0;
}
int SLtt_set_mouse_mode (int mode, int force)
{
(void) force;
Process_Mouse_Events = mode;
return 0;
}