From 2b592580bf65040373b55ff2ccc3b59a0a231a18 Mon Sep 17 00:00:00 2001 From: nobu Date: Sun, 10 Jun 2007 03:06:15 +0000 Subject: * include/ruby: moved public headers. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12501 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- include/ruby.h | 1 + include/ruby/defines.h | 284 ++++++++++++++++ include/ruby/intern.h | 627 +++++++++++++++++++++++++++++++++++ include/ruby/io.h | 126 ++++++++ include/ruby/missing.h | 162 ++++++++++ include/ruby/node.h | 400 +++++++++++++++++++++++ include/ruby/oniguruma.h | 816 ++++++++++++++++++++++++++++++++++++++++++++++ include/ruby/re.h | 58 ++++ include/ruby/regex.h | 46 +++ include/ruby/ruby.h | 826 +++++++++++++++++++++++++++++++++++++++++++++++ include/ruby/signal.h | 93 ++++++ include/ruby/st.h | 79 +++++ include/ruby/util.h | 81 +++++ include/ruby/win32.h | 544 +++++++++++++++++++++++++++++++ include/rubyio.h | 1 + include/rubysig.h | 1 + 16 files changed, 4145 insertions(+) create mode 100644 include/ruby.h create mode 100644 include/ruby/defines.h create mode 100644 include/ruby/intern.h create mode 100644 include/ruby/io.h create mode 100644 include/ruby/missing.h create mode 100644 include/ruby/node.h create mode 100644 include/ruby/oniguruma.h create mode 100644 include/ruby/re.h create mode 100644 include/ruby/regex.h create mode 100644 include/ruby/ruby.h create mode 100644 include/ruby/signal.h create mode 100644 include/ruby/st.h create mode 100644 include/ruby/util.h create mode 100644 include/ruby/win32.h create mode 100644 include/rubyio.h create mode 100644 include/rubysig.h (limited to 'include') diff --git a/include/ruby.h b/include/ruby.h new file mode 100644 index 0000000000..b1fb46c897 --- /dev/null +++ b/include/ruby.h @@ -0,0 +1 @@ +#include diff --git a/include/ruby/defines.h b/include/ruby/defines.h new file mode 100644 index 0000000000..81f2ef45ed --- /dev/null +++ b/include/ruby/defines.h @@ -0,0 +1,284 @@ +/************************************************ + + defines.h - + + $Author$ + $Date$ + created at: Wed May 18 00:21:44 JST 1994 + +************************************************/ + +#ifndef RUBY_DEFINES_H +#define RUBY_DEFINES_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#define RUBY + +#include +#ifdef __cplusplus +# ifndef HAVE_PROTOTYPES +# define HAVE_PROTOTYPES 1 +# endif +# ifndef HAVE_STDARG_PROTOTYPES +# define HAVE_STDARG_PROTOTYPES 1 +# endif +#endif + +#undef _ +#ifdef HAVE_PROTOTYPES +# define _(args) args +#else +# define _(args) () +#endif + +#undef __ +#ifdef HAVE_STDARG_PROTOTYPES +# define __(args) args +#else +# define __(args) () +#endif + +#ifdef __cplusplus +#define ANYARGS ... +#else +#define ANYARGS +#endif + +#define xmalloc ruby_xmalloc +#define xmalloc2 ruby_xmalloc2 +#define xcalloc ruby_xcalloc +#define xrealloc ruby_xrealloc +#define xrealloc2 ruby_xrealloc2 +#define xfree ruby_xfree + +void *xmalloc(size_t); +void *xmalloc2(size_t,size_t); +void *xcalloc(size_t,size_t); +void *xrealloc(void*,size_t); +void *xrealloc2(void*,size_t,size_t); +void xfree(void*); + +#if SIZEOF_LONG_LONG > 0 +# define LONG_LONG long long +#elif SIZEOF___INT64 > 0 +# define HAVE_LONG_LONG 1 +# define LONG_LONG __int64 +# undef SIZEOF_LONG_LONG +# define SIZEOF_LONG_LONG SIZEOF___INT64 +#endif + +#if SIZEOF_INT*2 <= SIZEOF_LONG_LONG +# define BDIGIT unsigned int +# define SIZEOF_BDIGITS SIZEOF_INT +# define BDIGIT_DBL unsigned LONG_LONG +# define BDIGIT_DBL_SIGNED LONG_LONG +#elif SIZEOF_INT*2 <= SIZEOF_LONG +# define BDIGIT unsigned int +# define SIZEOF_BDIGITS SIZEOF_INT +# define BDIGIT_DBL unsigned long +# define BDIGIT_DBL_SIGNED long +#elif SIZEOF_SHORT*2 <= SIZEOF_LONG +# define BDIGIT unsigned short +# define SIZEOF_BDIGITS SIZEOF_SHORT +# define BDIGIT_DBL unsigned long +# define BDIGIT_DBL_SIGNED long +#else +# define BDIGIT unsigned short +# define SIZEOF_BDIGITS (SIZEOF_LONG/2) +# define BDIGIT_DBL unsigned long +# define BDIGIT_DBL_SIGNED long +#endif + +#ifdef __CYGWIN__ +#undef _WIN32 +#endif + +#if defined(MSDOS) || defined(_WIN32) || defined(__human68k__) || defined(__EMX__) +#define DOSISH 1 +#ifndef _WIN32_WCE +# define DOSISH_DRIVE_LETTER +#endif +#endif + +/* define RUBY_USE_EUC/SJIS for default kanji-code */ +#ifndef DEFAULT_KCODE +#if defined(DOSISH) || defined(__CYGWIN__) || defined(__MACOS__) || defined(OS2) +#define DEFAULT_KCODE KCODE_SJIS +#else +#define DEFAULT_KCODE KCODE_EUC +#endif +#endif + +#ifdef __NeXT__ +/* NextStep, OpenStep, Rhapsody */ +#ifndef S_IRUSR +#define S_IRUSR 0000400 /* read permission, owner */ +#endif +#ifndef S_IRGRP +#define S_IRGRP 0000040 /* read permission, group */ +#endif +#ifndef S_IROTH +#define S_IROTH 0000004 /* read permission, other */ +#endif +#ifndef S_IWUSR +#define S_IWUSR 0000200 /* write permission, owner */ +#endif +#ifndef S_IWGRP +#define S_IWGRP 0000020 /* write permission, group */ +#endif +#ifndef S_IWOTH +#define S_IWOTH 0000002 /* write permission, other */ +#endif +#ifndef S_IXUSR +#define S_IXUSR 0000100 /* execute/search permission, owner */ +#endif +#ifndef S_IXGRP +#define S_IXGRP 0000010 /* execute/search permission, group */ +#endif +#ifndef S_IXOTH +#define S_IXOTH 0000001 /* execute/search permission, other */ +#endif +#ifndef S_IRWXU +#define S_IRWXU 0000700 /* read, write, execute permissions, owner */ +#endif +#ifndef S_IRWXG +#define S_IRWXG 0000070 /* read, write, execute permissions, group */ +#endif +#ifndef S_IRWXO +#define S_IRWXO 0000007 /* read, write, execute permissions, other */ +#endif +#ifndef S_ISBLK +#define S_ISBLK(mode) (((mode) & (0170000)) == (0060000)) +#endif +#ifndef S_ISCHR +#define S_ISCHR(mode) (((mode) & (0170000)) == (0020000)) +#endif +#ifndef S_ISDIR +#define S_ISDIR(mode) (((mode) & (0170000)) == (0040000)) +#endif +#ifndef S_ISFIFO +#define S_ISFIFO(mode) (((mode) & (0170000)) == (0010000)) +#endif +#ifndef S_ISREG +#define S_ISREG(mode) (((mode) & (0170000)) == (0100000)) +#endif +/* Do not trust WORDS_BIGENDIAN from configure since -arch compiler flag may + result in a different endian. Instead trust __BIG_ENDIAN__ and + __LITTLE_ENDIAN__ which are set correctly by -arch. */ +#undef WORDS_BIGENDIAN +#ifdef __BIG_ENDIAN__ +#define WORDS_BIGENDIAN +#endif +#ifndef __APPLE__ +/* NextStep, OpenStep (but not Rhapsody) */ +#ifndef GETPGRP_VOID +#define GETPGRP_VOID 1 +#endif +#ifndef WNOHANG +#define WNOHANG 01 +#endif +#ifndef WUNTRACED +#define WUNTRACED 02 +#endif +#ifndef X_OK +#define X_OK 1 +#endif +#endif /* __APPLE__ */ +#endif /* NeXT */ + +#ifdef _WIN32 +#include "ruby/win32.h" +#endif + +#if defined(__VMS) +#include "vms/vms.h" +#endif + +#if defined(__BEOS__) +#include /* intern.h needs fd_set definition */ +#endif + +#ifdef RUBY_EXPORT +#undef RUBY_EXTERN +#endif + +#ifndef RUBY_EXTERN +#define RUBY_EXTERN extern +#endif + +#ifndef EXTERN +#define EXTERN RUBY_EXTERN /* deprecated */ +#endif + +#ifndef RUBY_MBCHAR_MAXSIZE +#define RUBY_MBCHAR_MAXSIZE INT_MAX + /* MB_CUR_MAX will not work well in C locale */ +#endif + +#if defined(sparc) || defined(__sparc__) +static inline void +flush_register_windows(void) +{ + asm +#ifdef __GNUC__ + volatile +#endif +# if defined(__sparc_v9__) || defined(__sparcv9) || defined(__arch64__) + ("flushw") +# elif defined(linux) || defined(__linux__) + ("ta 0x83") +# else /* Solaris, OpenBSD, NetBSD, etc. */ + ("ta 0x03") +# endif /* trap always to flush register windows if we are on a Sparc system */ + ; +} +# define FLUSH_REGISTER_WINDOWS flush_register_windows() +#elif defined(__ia64) +void *rb_ia64_bsp(void); +void rb_ia64_flushrs(void); +# define FLUSH_REGISTER_WINDOWS rb_ia64_flushrs() +#else +# define FLUSH_REGISTER_WINDOWS ((void)0) +#endif + +#if defined(DOSISH) +#define PATH_SEP ";" +#elif defined(riscos) +#define PATH_SEP "," +#else +#define PATH_SEP ":" +#endif +#define PATH_SEP_CHAR PATH_SEP[0] + +#if defined(__human68k__) +#define PATH_ENV "path" +#else +#define PATH_ENV "PATH" +#endif + +#if defined(DOSISH) && !defined(__human68k__) && !defined(__EMX__) +#define ENV_IGNORECASE +#endif + +#ifndef DLEXT_MAXLEN +#define DLEXT_MAXLEN 4 +#endif + +#ifndef RUBY_PLATFORM +#define RUBY_PLATFORM "unknown-unknown" +#endif + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_DEFINES_H */ diff --git a/include/ruby/intern.h b/include/ruby/intern.h new file mode 100644 index 0000000000..a74bd8ed23 --- /dev/null +++ b/include/ruby/intern.h @@ -0,0 +1,627 @@ +/********************************************************************** + + intern.h - + + $Author$ + $Date$ + created at: Thu Jun 10 14:22:17 JST 1993 + + Copyright (C) 1993-2003 Yukihiro Matsumoto + Copyright (C) 2000 Network Applied Communication Laboratory, Inc. + Copyright (C) 2000 Information-technology Promotion Agency, Japan + +**********************************************************************/ + +#ifndef RUBY_INTERN_H +#define RUBY_INTERN_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#ifdef HAVE_STDARG_PROTOTYPES +# include +#else +# include +#endif +#include + +/* + * Functions and variables that are used by more than one source file of + * the kernel. + */ + +#define ID_ALLOCATOR 1 + +/* array.c */ +void rb_mem_clear(register VALUE*, register long); +VALUE rb_assoc_new(VALUE, VALUE); +VALUE rb_check_array_type(VALUE); +VALUE rb_ary_new(void); +VALUE rb_ary_new2(long); +VALUE rb_ary_new3(long,...); +VALUE rb_ary_new4(long, const VALUE *); +void rb_ary_free(VALUE); +VALUE rb_values_new(long,...); +VALUE rb_values_new2(long, const VALUE *); +VALUE rb_values_from_ary(VALUE); +VALUE rb_ary_from_values(VALUE); +VALUE rb_ary_freeze(VALUE); +VALUE rb_ary_aref(int, VALUE*, VALUE); +void rb_ary_store(VALUE, long, VALUE); +VALUE rb_ary_dup(VALUE); +VALUE rb_ary_to_ary(VALUE); +VALUE rb_ary_to_s(VALUE); +VALUE rb_ary_push(VALUE, VALUE); +VALUE rb_ary_pop(VALUE); +VALUE rb_ary_shift(VALUE); +VALUE rb_ary_unshift(VALUE, VALUE); +VALUE rb_ary_entry(VALUE, long); +VALUE rb_ary_each(VALUE); +VALUE rb_ary_join(VALUE, VALUE); +VALUE rb_ary_print_on(VALUE, VALUE); +VALUE rb_ary_reverse(VALUE); +VALUE rb_ary_sort(VALUE); +VALUE rb_ary_sort_bang(VALUE); +VALUE rb_ary_delete(VALUE, VALUE); +VALUE rb_ary_delete_at(VALUE, long); +VALUE rb_ary_clear(VALUE); +VALUE rb_ary_plus(VALUE, VALUE); +VALUE rb_ary_concat(VALUE, VALUE); +VALUE rb_ary_assoc(VALUE, VALUE); +VALUE rb_ary_rassoc(VALUE, VALUE); +VALUE rb_ary_includes(VALUE, VALUE); +VALUE rb_ary_cmp(VALUE, VALUE); +VALUE rb_ary_replace(VALUE copy, VALUE orig); +VALUE rb_check_array_value(VALUE); +VALUE rb_get_values_at(VALUE, long, int, VALUE*, VALUE(*)(VALUE,long)); +/* bignum.c */ +VALUE rb_big_clone(VALUE); +void rb_big_2comp(VALUE); +VALUE rb_big_norm(VALUE); +VALUE rb_uint2big(VALUE); +VALUE rb_int2big(SIGNED_VALUE); +VALUE rb_uint2inum(VALUE); +VALUE rb_int2inum(SIGNED_VALUE); +VALUE rb_cstr_to_inum(const char*, int, int); +VALUE rb_str_to_inum(VALUE, int, int); +VALUE rb_cstr2inum(const char*, int); +VALUE rb_str2inum(VALUE, int); +VALUE rb_big2str(VALUE, int); +VALUE rb_big2str0(VALUE, int, int); +SIGNED_VALUE rb_big2long(VALUE); +#define rb_big2int(x) rb_big2long(x) +VALUE rb_big2ulong(VALUE); +#define rb_big2uint(x) rb_big2ulong(x) +#if HAVE_LONG_LONG +VALUE rb_ll2inum(LONG_LONG); +VALUE rb_ull2inum(unsigned LONG_LONG); +LONG_LONG rb_big2ll(VALUE); +unsigned LONG_LONG rb_big2ull(VALUE); +#endif /* HAVE_LONG_LONG */ +void rb_quad_pack(char*,VALUE); +VALUE rb_quad_unpack(const char*,int); +VALUE rb_dbl2big(double); +double rb_big2dbl(VALUE); +VALUE rb_big_cmp(VALUE, VALUE); +VALUE rb_big_eq(VALUE, VALUE); +VALUE rb_big_plus(VALUE, VALUE); +VALUE rb_big_minus(VALUE, VALUE); +VALUE rb_big_mul(VALUE, VALUE); +VALUE rb_big_div(VALUE, VALUE); +VALUE rb_big_modulo(VALUE, VALUE); +VALUE rb_big_divmod(VALUE, VALUE); +VALUE rb_big_pow(VALUE, VALUE); +VALUE rb_big_and(VALUE, VALUE); +VALUE rb_big_or(VALUE, VALUE); +VALUE rb_big_xor(VALUE, VALUE); +VALUE rb_big_lshift(VALUE, VALUE); +/* class.c */ +VALUE rb_class_boot(VALUE); +VALUE rb_class_new(VALUE); +VALUE rb_mod_init_copy(VALUE, VALUE); +VALUE rb_class_init_copy(VALUE, VALUE); +VALUE rb_singleton_class_clone(VALUE); +void rb_singleton_class_attached(VALUE,VALUE); +VALUE rb_make_metaclass(VALUE, VALUE); +void rb_check_inheritable(VALUE); +VALUE rb_class_inherited(VALUE, VALUE); +VALUE rb_define_class_id(ID, VALUE); +VALUE rb_module_new(void); +VALUE rb_define_module_id(ID); +VALUE rb_mod_included_modules(VALUE); +VALUE rb_mod_include_p(VALUE, VALUE); +VALUE rb_mod_ancestors(VALUE); +VALUE rb_class_instance_methods(int, VALUE*, VALUE); +VALUE rb_class_public_instance_methods(int, VALUE*, VALUE); +VALUE rb_class_protected_instance_methods(int, VALUE*, VALUE); +VALUE rb_class_private_instance_methods(int, VALUE*, VALUE); +VALUE rb_class_local_methods(VALUE); +VALUE rb_obj_singleton_methods(int, VALUE*, VALUE); +void rb_define_method_id(VALUE, ID, VALUE (*)(ANYARGS), int); +void rb_frozen_class_p(VALUE); +void rb_undef(VALUE, ID); +void rb_define_protected_method(VALUE, const char*, VALUE (*)(ANYARGS), int); +void rb_define_private_method(VALUE, const char*, VALUE (*)(ANYARGS), int); +void rb_define_singleton_method(VALUE, const char*, VALUE(*)(ANYARGS), int); +VALUE rb_singleton_class(VALUE); +/* compar.c */ +int rb_cmpint(VALUE, VALUE, VALUE); +NORETURN(void rb_cmperr(VALUE, VALUE)); +/* enum.c */ +/* enumerator.c */ +VALUE rb_enumeratorize(VALUE, VALUE, int, VALUE *); +#define RETURN_ENUMERATOR(obj, argc, argv) do { \ + if (!rb_block_given_p()) \ + return rb_enumeratorize(obj, ID2SYM(rb_frame_this_func()), \ + argc, argv); \ + } while (0) +/* error.c */ +RUBY_EXTERN int ruby_nerrs; +VALUE rb_exc_new(VALUE, const char*, long); +VALUE rb_exc_new2(VALUE, const char*); +VALUE rb_exc_new3(VALUE, VALUE); +PRINTF_ARGS(NORETURN(void rb_loaderror(const char*, ...)), 1, 2); +PRINTF_ARGS(NORETURN(void rb_name_error(ID, const char*, ...)), 2, 3); +NORETURN(void rb_invalid_str(const char*, const char*)); +PRINTF_ARGS(void rb_compile_error(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_compile_error_append(const char*, ...), 1, 2); +NORETURN(void rb_load_fail(const char*)); +NORETURN(void rb_error_frozen(const char*)); +void rb_check_frozen(VALUE); +/* eval.c */ +#if defined(NFDBITS) && defined(HAVE_RB_FD_INIT) +typedef struct { + int maxfd; + fd_set *fdset; +} rb_fdset_t; + +void rb_fd_init(volatile rb_fdset_t *); +void rb_fd_term(rb_fdset_t *); +void rb_fd_zero(rb_fdset_t *); +void rb_fd_set(int, rb_fdset_t *); +void rb_fd_clr(int, rb_fdset_t *); +int rb_fd_isset(int, const rb_fdset_t *); +void rb_fd_copy(rb_fdset_t *, const fd_set *, int); +int rb_fd_select(int, rb_fdset_t *, rb_fdset_t *, rb_fdset_t *, struct timeval *); + +#define rb_fd_ptr(f) ((f)->fdset) +#define rb_fd_max(f) ((f)->maxfd) + +#else + +typedef fd_set rb_fdset_t; +#define rb_fd_zero(f) FD_ZERO(f) +#define rb_fd_set(n, f) FD_SET(n, f) +#define rb_fd_clr(n, f) FD_CLR(n, f) +#define rb_fd_isset(n, f) FD_ISSET(n, f) +#define rb_fd_copy(d, s, n) (*(d) = *(s)) +#define rb_fd_ptr(f) (f) +#define rb_fd_init(f) FD_ZERO(f) +#define rb_fd_term(f) (f) +#define rb_fd_max(f) FD_SETSIZE +#define rb_fd_select(n, rfds, wfds, efds, timeout) select(n, rfds, wfds, efds, timeout) + +#endif + +RUBY_EXTERN struct RNode *ruby_current_node; +void ruby_set_current_source(void); +NORETURN(void rb_exc_raise(VALUE)); +NORETURN(void rb_exc_fatal(VALUE)); +VALUE rb_f_exit(int,VALUE*); +VALUE rb_f_abort(int,VALUE*); +void rb_remove_method(VALUE, const char*); +#define rb_disable_super(klass, name) ((void)0) +#define rb_enable_super(klass, name) ((void)0) +#define HAVE_RB_DEFINE_ALLOC_FUNC 1 +void rb_define_alloc_func(VALUE, VALUE (*)(VALUE)); +void rb_undef_alloc_func(VALUE); +void rb_clear_cache(void); +void rb_clear_cache_by_class(VALUE); +void rb_alias(VALUE, ID, ID); +void rb_attr(VALUE,ID,int,int,int); +int rb_method_boundp(VALUE, ID, int); +void rb_dvar_asgn(ID, VALUE); +void rb_dvar_push(ID, VALUE); +VALUE *rb_svar(int); +VALUE rb_eval_cmd(VALUE, VALUE, int); +int rb_obj_respond_to(VALUE, ID, int); +int rb_respond_to(VALUE, ID); +void rb_interrupt(void); +VALUE rb_apply(VALUE, ID, VALUE); +void rb_backtrace(void); +ID rb_frame_this_func(void); +VALUE rb_obj_instance_eval(int, VALUE*, VALUE); +VALUE rb_mod_module_eval(int, VALUE*, VALUE); +void rb_load(VALUE, int); +void rb_load_protect(VALUE, int, int*); +NORETURN(void rb_jump_tag(int)); +int rb_provided(const char*); +void rb_provide(const char*); +VALUE rb_f_require(VALUE, VALUE); +VALUE rb_require_safe(VALUE, int); +void rb_obj_call_init(VALUE, int, VALUE*); +VALUE rb_class_new_instance(int, VALUE*, VALUE); +VALUE rb_block_proc(void); +VALUE rb_f_lambda(void); +VALUE rb_proc_new(VALUE (*)(ANYARGS/* VALUE yieldarg[, VALUE procarg] */), VALUE); +VALUE rb_proc_call(VALUE, VALUE); +int rb_proc_arity(VALUE); +VALUE rb_binding_new(void); +VALUE rb_obj_method(VALUE, VALUE); +VALUE rb_method_call(int, VALUE*, VALUE); +int rb_mod_method_arity(VALUE, ID); +int rb_obj_method_arity(VALUE, ID); +VALUE rb_protect(VALUE (*)(VALUE), VALUE, int*); +void rb_set_end_proc(void (*)(VALUE), VALUE); +void rb_mark_end_proc(void); +void rb_exec_end_proc(void); +void Init_jump(void); +void ruby_finalize(void); +NORETURN(void ruby_stop(int)); +int ruby_cleanup(int); +int ruby_exec(void); +void rb_gc_mark_threads(void); +void rb_thread_start_timer(void); +void rb_thread_stop_timer(void); +void rb_thread_schedule(void); +void rb_thread_wait_fd(int); +int rb_thread_fd_writable(int); +void rb_thread_fd_close(int); +int rb_thread_alone(void); +void rb_thread_polling(void); +void rb_thread_sleep(int); +void rb_thread_sleep_forever(void); +VALUE rb_thread_stop(void); +VALUE rb_thread_wakeup(VALUE); +VALUE rb_thread_run(VALUE); +VALUE rb_thread_kill(VALUE); +VALUE rb_thread_create(VALUE (*)(ANYARGS), void*); +void rb_thread_trap_eval(VALUE, int, int); +void rb_thread_signal_raise(void *, int); +void rb_thread_signal_exit(void *); +int rb_thread_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +void rb_thread_wait_for(struct timeval); +VALUE rb_thread_current(void); +VALUE rb_thread_main(void); +VALUE rb_thread_local_aref(VALUE, ID); +VALUE rb_thread_local_aset(VALUE, ID, VALUE); +void rb_thread_atfork(void); +VALUE rb_exec_recursive(VALUE(*)(VALUE, VALUE, int),VALUE,VALUE); +/* file.c */ +VALUE rb_file_s_expand_path(int, VALUE *); +VALUE rb_file_expand_path(VALUE, VALUE); +void rb_file_const(const char*, VALUE); +int rb_find_file_ext(VALUE*, const char* const*); +VALUE rb_find_file(VALUE); +char *rb_path_next(const char *); +char *rb_path_skip_prefix(const char *); +char *rb_path_last_separator(const char *); +char *rb_path_end(const char *); +VALUE rb_file_directory_p(VALUE,VALUE); +/* gc.c */ +void ruby_set_stack_size(size_t); +NORETURN(void rb_memerror(void)); +int ruby_stack_check(void); +int ruby_stack_length(VALUE**); +char *rb_source_filename(const char*); +void rb_gc_mark_locations(VALUE*, VALUE*); +void rb_mark_tbl(struct st_table*); +void rb_mark_hash(struct st_table*); +void rb_gc_mark_maybe(VALUE); +void rb_gc_mark(VALUE); +void rb_gc_force_recycle(VALUE); +void rb_gc(void); +void rb_gc_copy_finalizer(VALUE,VALUE); +void rb_gc_finalize_deferred(void); +void rb_gc_call_finalizer_at_exit(void); +VALUE rb_gc_enable(void); +VALUE rb_gc_disable(void); +VALUE rb_gc_start(void); +/* hash.c */ +void st_foreach_safe(struct st_table *, int (*)(ANYARGS), st_data_t); +void rb_hash_foreach(VALUE, int (*)(ANYARGS), VALUE); +VALUE rb_hash(VALUE); +VALUE rb_hash_new(void); +VALUE rb_hash_freeze(VALUE); +VALUE rb_hash_aref(VALUE, VALUE); +VALUE rb_hash_aset(VALUE, VALUE, VALUE); +VALUE rb_hash_delete_if(VALUE); +VALUE rb_hash_delete(VALUE,VALUE); +int rb_path_check(const char*); +int rb_env_path_tainted(void); +/* io.c */ +#define rb_defout rb_stdout +RUBY_EXTERN VALUE rb_fs; +RUBY_EXTERN VALUE rb_output_fs; +RUBY_EXTERN VALUE rb_rs; +RUBY_EXTERN VALUE rb_default_rs; +RUBY_EXTERN VALUE rb_output_rs; +VALUE rb_io_write(VALUE, VALUE); +VALUE rb_io_gets(VALUE); +VALUE rb_io_getc(VALUE); +VALUE rb_io_ungetc(VALUE, VALUE); +VALUE rb_io_close(VALUE); +VALUE rb_io_flush(VALUE); +VALUE rb_io_eof(VALUE); +VALUE rb_io_binmode(VALUE); +VALUE rb_io_addstr(VALUE, VALUE); +VALUE rb_io_printf(int, VALUE*, VALUE); +VALUE rb_io_print(int, VALUE*, VALUE); +VALUE rb_io_puts(int, VALUE*, VALUE); +VALUE rb_file_open(const char*, const char*); +VALUE rb_gets(void); +void rb_write_error(const char*); +void rb_write_error2(const char*, long); +/* marshal.c */ +VALUE rb_marshal_dump(VALUE, VALUE); +VALUE rb_marshal_load(VALUE); +/* numeric.c */ +void rb_num_zerodiv(void); +VALUE rb_num_coerce_bin(VALUE, VALUE); +VALUE rb_num_coerce_cmp(VALUE, VALUE); +VALUE rb_num_coerce_relop(VALUE, VALUE); +VALUE rb_float_new(double); +VALUE rb_num2fix(VALUE); +VALUE rb_fix2str(VALUE, int); +VALUE rb_dbl_cmp(double, double); +/* object.c */ +int rb_eql(VALUE, VALUE); +VALUE rb_any_to_s(VALUE); +VALUE rb_inspect(VALUE); +VALUE rb_obj_is_instance_of(VALUE, VALUE); +VALUE rb_obj_is_kind_of(VALUE, VALUE); +VALUE rb_obj_alloc(VALUE); +VALUE rb_obj_clone(VALUE); +VALUE rb_obj_dup(VALUE); +VALUE rb_obj_init_copy(VALUE,VALUE); +VALUE rb_obj_taint(VALUE); +VALUE rb_obj_tainted(VALUE); +VALUE rb_obj_untaint(VALUE); +VALUE rb_obj_freeze(VALUE); +VALUE rb_obj_id(VALUE); +VALUE rb_obj_class(VALUE); +VALUE rb_class_real(VALUE); +VALUE rb_class_inherited_p(VALUE, VALUE); +VALUE rb_convert_type(VALUE,int,const char*,const char*); +VALUE rb_check_convert_type(VALUE,int,const char*,const char*); +VALUE rb_check_to_integer(VALUE, const char *); +VALUE rb_to_int(VALUE); +VALUE rb_Integer(VALUE); +VALUE rb_Float(VALUE); +VALUE rb_String(VALUE); +VALUE rb_Array(VALUE); +double rb_cstr_to_dbl(const char*, int); +double rb_str_to_dbl(VALUE, int); +/* parse.y */ +RUBY_EXTERN int ruby_sourceline; +RUBY_EXTERN char *ruby_sourcefile; +ID rb_id_attrset(ID); +void rb_gc_mark_parser(void); +int rb_is_const_id(ID); +int rb_is_instance_id(ID); +int rb_is_class_id(ID); +int rb_is_local_id(ID); +int rb_is_junk_id(ID); +int rb_symname_p(const char*); +int rb_sym_interned_p(VALUE); +void rb_gc_mark_symbols(void); +VALUE rb_backref_get(void); +void rb_backref_set(VALUE); +VALUE rb_lastline_get(void); +void rb_lastline_set(VALUE); +VALUE rb_sym_all_symbols(void); +/* process.c */ +void rb_last_status_set(int status, rb_pid_t pid); +VALUE rb_last_status_get(void); +struct rb_exec_arg { + int argc; + VALUE *argv; + const char *prog; +}; +int rb_proc_exec_n(int, VALUE*, const char*); +int rb_proc_exec(const char*); +VALUE rb_check_argv(int, VALUE*); +int rb_exec(const struct rb_exec_arg*); +rb_pid_t rb_fork(int*, int (*)(void*), void*); +VALUE rb_f_exec(int,VALUE*); +rb_pid_t rb_waitpid(rb_pid_t pid, int *status, int flags); +void rb_syswait(rb_pid_t pid); +rb_pid_t rb_spawn(int, VALUE*); +VALUE rb_proc_times(VALUE); +VALUE rb_detach_process(rb_pid_t pid); +/* range.c */ +VALUE rb_range_new(VALUE, VALUE, int); +VALUE rb_range_beg_len(VALUE, long*, long*, long, int); +VALUE rb_length_by_each(VALUE); +/* random.c */ +unsigned long genrand_int32(void); +double genrand_real(void); +/* re.c */ +int rb_memcmp(const void*,const void*,long); +int rb_memcicmp(const void*,const void*,long); +long rb_memsearch(const void*,long,const void*,long); +VALUE rb_reg_nth_defined(int, VALUE); +VALUE rb_reg_nth_match(int, VALUE); +VALUE rb_reg_last_match(VALUE); +VALUE rb_reg_match_pre(VALUE); +VALUE rb_reg_match_post(VALUE); +VALUE rb_reg_match_last(VALUE); +VALUE rb_reg_new(const char*, long, int); +VALUE rb_reg_compile(const char*, long, int); +VALUE rb_reg_match(VALUE, VALUE); +VALUE rb_reg_match2(VALUE); +int rb_reg_options(VALUE); +void rb_set_kcode(const char*); +const char* rb_get_kcode(void); +/* ruby.c */ +RUBY_EXTERN VALUE rb_argv; +RUBY_EXTERN VALUE rb_argv0; +void *rb_load_file(const char*); +void ruby_script(const char*); +void ruby_prog_init(void); +void ruby_set_argv(int, char**); +void ruby_process_options(int, char**); +void ruby_load_script(void); +void ruby_init_loadpath(void); +void ruby_incpush(const char*); +/* signal.c */ +VALUE rb_f_kill(int, VALUE*); +void rb_gc_mark_trap_list(void); +#ifdef POSIX_SIGNAL +#define posix_signal ruby_posix_signal +void posix_signal(int, RETSIGTYPE (*)(int)); +#endif +void rb_trap_exit(void); +void rb_trap_exec(void); +const char *ruby_signal_name(int); +void ruby_default_signal(int); +/* sprintf.c */ +VALUE rb_f_sprintf(int, const VALUE*); +PRINTF_ARGS(VALUE rb_sprintf(const char*, ...), 1, 2); +VALUE rb_vsprintf(const char*, va_list); +VALUE rb_str_format(int, const VALUE *, VALUE); +/* string.c */ +VALUE rb_str_new(const char*, long); +VALUE rb_str_new2(const char*); +VALUE rb_str_new3(VALUE); +VALUE rb_str_new4(VALUE); +VALUE rb_str_new5(VALUE, const char*, long); +VALUE rb_tainted_str_new(const char*, long); +VALUE rb_tainted_str_new2(const char*); +VALUE rb_str_buf_new(long); +VALUE rb_str_buf_new2(const char*); +void rb_str_free(VALUE); +VALUE rb_str_buf_append(VALUE, VALUE); +VALUE rb_str_buf_cat(VALUE, const char*, long); +VALUE rb_str_buf_cat2(VALUE, const char*); +VALUE rb_obj_as_string(VALUE); +VALUE rb_check_string_type(VALUE); +VALUE rb_str_dup(VALUE); +VALUE rb_str_locktmp(VALUE); +VALUE rb_str_unlocktmp(VALUE); +VALUE rb_str_dup_frozen(VALUE); +VALUE rb_str_plus(VALUE, VALUE); +VALUE rb_str_times(VALUE, VALUE); +VALUE rb_str_substr(VALUE, long, long); +void rb_str_modify(VALUE); +VALUE rb_str_freeze(VALUE); +void rb_str_set_len(VALUE, long); +VALUE rb_str_resize(VALUE, long); +VALUE rb_str_cat(VALUE, const char*, long); +VALUE rb_str_cat2(VALUE, const char*); +VALUE rb_str_append(VALUE, VALUE); +VALUE rb_str_concat(VALUE, VALUE); +int rb_memhash(const void *ptr, long len); +int rb_str_hash(VALUE); +int rb_str_cmp(VALUE, VALUE); +VALUE rb_str_upto(VALUE, VALUE, int); +void rb_str_update(VALUE, long, long, VALUE); +VALUE rb_str_inspect(VALUE); +VALUE rb_str_dump(VALUE); +VALUE rb_str_split(VALUE, const char*); +void rb_str_associate(VALUE, VALUE); +VALUE rb_str_associated(VALUE); +void rb_str_setter(VALUE, ID, VALUE*); +VALUE rb_str_intern(VALUE); +VALUE rb_sym_to_s(VALUE); +/* struct.c */ +VALUE rb_struct_new(VALUE, ...); +VALUE rb_struct_define(const char*, ...); +VALUE rb_struct_alloc(VALUE, VALUE); +VALUE rb_struct_aref(VALUE, VALUE); +VALUE rb_struct_aset(VALUE, VALUE, VALUE); +VALUE rb_struct_getmember(VALUE, ID); +VALUE rb_struct_iv_get(VALUE, const char*); +VALUE rb_struct_s_members(VALUE); +VALUE rb_struct_members(VALUE); +/* thread.c */ +typedef struct rb_thread_struct rb_thread_t; +typedef void rb_unblock_function_t(rb_thread_t *); +typedef VALUE rb_blocking_function_t(rb_thread_t *th, void *); +VALUE rb_thread_blocking_region(rb_blocking_function_t *func, void *data, + rb_unblock_function_t *ubf); +#define RB_UBF_DFL ((rb_unblock_function_t *)-1) +VALUE rb_mutex_new(void); +VALUE rb_mutex_locked_p(VALUE mutex); +VALUE rb_mutex_try_lock(VALUE mutex); +VALUE rb_mutex_lock(VALUE mutex); +VALUE rb_mutex_unlock(VALUE mutex); +VALUE rb_mutex_sleep(VALUE self, VALUE timeout); +VALUE rb_mutex_synchronize(VALUE self); +VALUE rb_barrier_new(void); +VALUE rb_barrier_wait(VALUE self); +VALUE rb_barrier_release(VALUE self); +/* time.c */ +VALUE rb_time_new(time_t, time_t); +/* variable.c */ +VALUE rb_mod_name(VALUE); +VALUE rb_class_path(VALUE); +void rb_set_class_path(VALUE, VALUE, const char*); +VALUE rb_path2class(const char*); +void rb_name_class(VALUE, ID); +VALUE rb_class_name(VALUE); +void rb_autoload(VALUE, ID, const char*); +VALUE rb_autoload_load(VALUE, ID); +VALUE rb_autoload_p(VALUE, ID); +void rb_gc_mark_global_tbl(void); +VALUE rb_f_trace_var(int, VALUE*); +VALUE rb_f_untrace_var(int, VALUE*); +VALUE rb_f_global_variables(void); +void rb_alias_variable(ID, ID); +struct st_table* rb_generic_ivar_table(VALUE); +void rb_copy_generic_ivar(VALUE,VALUE); +void rb_mark_generic_ivar(VALUE); +void rb_mark_generic_ivar_tbl(void); +void rb_free_generic_ivar(VALUE); +VALUE rb_ivar_get(VALUE, ID); +VALUE rb_ivar_set(VALUE, ID, VALUE); +VALUE rb_ivar_defined(VALUE, ID); +VALUE rb_iv_set(VALUE, const char*, VALUE); +VALUE rb_iv_get(VALUE, const char*); +VALUE rb_attr_get(VALUE, ID); +VALUE rb_obj_instance_variables(VALUE); +VALUE rb_obj_remove_instance_variable(VALUE, VALUE); +void *rb_mod_const_at(VALUE, void*); +void *rb_mod_const_of(VALUE, void*); +VALUE rb_const_list(void*); +VALUE rb_mod_constants(int, VALUE *, VALUE); +VALUE rb_mod_remove_const(VALUE, VALUE); +int rb_const_defined(VALUE, ID); +int rb_const_defined_at(VALUE, ID); +int rb_const_defined_from(VALUE, ID); +VALUE rb_const_get(VALUE, ID); +VALUE rb_const_get_at(VALUE, ID); +VALUE rb_const_get_from(VALUE, ID); +void rb_const_set(VALUE, ID, VALUE); +VALUE rb_mod_const_missing(VALUE,VALUE); +VALUE rb_cvar_defined(VALUE, ID); +void rb_cvar_set(VALUE, ID, VALUE); +VALUE rb_cvar_get(VALUE, ID); +void rb_cv_set(VALUE, const char*, VALUE); +VALUE rb_cv_get(VALUE, const char*); +void rb_define_class_variable(VALUE, const char*, VALUE); +VALUE rb_mod_class_variables(VALUE); +VALUE rb_mod_remove_cvar(VALUE, VALUE); +/* version.c */ +void ruby_show_version(void); +void ruby_show_copyright(void); + +ID rb_frame_callee(void); +VALUE rb_str_succ(VALUE); +VALUE rb_time_succ(VALUE); +void Init_stack(VALUE*); +void rb_frame_pop(void); +NORETURN(void rb_thread_start_1(void)); + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_INTERN_H */ diff --git a/include/ruby/io.h b/include/ruby/io.h new file mode 100644 index 0000000000..6d22de8df1 --- /dev/null +++ b/include/ruby/io.h @@ -0,0 +1,126 @@ +/********************************************************************** + + rubyio.h - + + $Author$ + $Date$ + created at: Fri Nov 12 16:47:09 JST 1993 + + Copyright (C) 1993-2003 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_IO_H +#define RUBY_IO_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include +#include + +#if defined(HAVE_STDIO_EXT_H) +#include +#endif + +typedef struct rb_io_t { + int fd; /* file descriptor */ + FILE *stdio_file; /* stdio ptr for read/write if available */ + int mode; /* mode flags */ + rb_pid_t pid; /* child's pid (for pipes) */ + int lineno; /* number of lines read */ + char *path; /* pathname for file */ + void (*finalize)(struct rb_io_t*,int); /* finalize proc */ + long refcnt; + char *wbuf; /* wbuf_off + wbuf_len <= wbuf_capa */ + int wbuf_off; + int wbuf_len; + int wbuf_capa; + char *rbuf; /* rbuf_off + rbuf_len <= rbuf_capa */ + int rbuf_off; + int rbuf_len; + int rbuf_capa; +} rb_io_t; + +#define HAVE_RB_IO_T 1 + +#define FMODE_READABLE 1 +#define FMODE_WRITABLE 2 +#define FMODE_READWRITE 3 +#define FMODE_APPEND 64 +#define FMODE_CREATE 128 +#define FMODE_BINMODE 4 +#define FMODE_SYNC 8 +#define FMODE_TTY 16 +#define FMODE_DUPLEX 32 +#define FMODE_WSPLIT 0x200 +#define FMODE_WSPLIT_INITIALIZED 0x400 + +#define GetOpenFile(obj,fp) rb_io_check_closed((fp) = RFILE(rb_io_taint_check(obj))->fptr) + +#define MakeOpenFile(obj, fp) do {\ + if (RFILE(obj)->fptr) {\ + rb_io_close(obj);\ + free(RFILE(obj)->fptr);\ + RFILE(obj)->fptr = 0;\ + }\ + fp = 0;\ + fp = RFILE(obj)->fptr = ALLOC(rb_io_t);\ + fp->fd = -1;\ + fp->stdio_file = NULL;\ + fp->mode = 0;\ + fp->pid = 0;\ + fp->lineno = 0;\ + fp->path = NULL;\ + fp->finalize = 0;\ + fp->refcnt = 1;\ + fp->wbuf = NULL;\ + fp->wbuf_off = 0;\ + fp->wbuf_len = 0;\ + fp->wbuf_capa = 0;\ + fp->rbuf = NULL;\ + fp->rbuf_off = 0;\ + fp->rbuf_len = 0;\ + fp->rbuf_capa = 0;\ +} while (0) + +FILE *rb_io_stdio_file(rb_io_t *fptr); + +FILE *rb_fopen(const char*, const char*); +FILE *rb_fdopen(int, const char*); +int rb_io_mode_flags(const char*); +int rb_io_modenum_flags(int); +void rb_io_check_writable(rb_io_t*); +void rb_io_check_readable(rb_io_t*); +int rb_io_fptr_finalize(rb_io_t*); +void rb_io_synchronized(rb_io_t*); +void rb_io_check_initialized(rb_io_t*); +void rb_io_check_closed(rb_io_t*); +int rb_io_wait_readable(int); +int rb_io_wait_writable(int); +void rb_io_set_nonblock(rb_io_t *fptr); + +VALUE rb_io_taint_check(VALUE); +NORETURN(void rb_eof_error(void)); + +void rb_io_read_check(rb_io_t*); +int rb_io_read_pending(rb_io_t*); +void rb_read_check(FILE*); + +DEPRECATED(int rb_getc(FILE*)); +DEPRECATED(long rb_io_fread(char *, long, FILE *)); +DEPRECATED(long rb_io_fwrite(const char *, long, FILE *)); +DEPRECATED(int rb_read_pending(FILE*)); + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_IO_H */ diff --git a/include/ruby/missing.h b/include/ruby/missing.h new file mode 100644 index 0000000000..007c546617 --- /dev/null +++ b/include/ruby/missing.h @@ -0,0 +1,162 @@ +/************************************************ + + missing.h - prototype for *.c in ./missing, and + for missing timeval struct + + $Author$ + $Date$ + created at: Sat May 11 23:46:03 JST 2002 + +************************************************/ + +#ifndef RUBY_MISSING_H +#define RUBY_MISSING_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#if defined(HAVE_SYS_TIME_H) +# include +#elif !defined(_WIN32) +# define time_t long +struct timeval { + time_t tv_sec; /* seconds */ + time_t tv_usec; /* microseconds */ +}; +#endif +#if defined(HAVE_SYS_TYPES_H) +# include +#endif + +#ifndef HAVE_ACOSH +extern double acosh(double); +extern double asinh(double); +extern double atanh(double); +#endif + +#ifndef HAVE_CRYPT +extern char *crypt(const char *, const char *); +#endif + +#ifndef HAVE_DUP2 +extern int dup2(int, int); +#endif + +#ifndef HAVE_EACCESS +extern int eaccess(const char*, int); +#endif + +#ifndef HAVE_FINITE +extern int finite(double); +#endif + +#ifndef HAVE_FLOCK +extern int flock(int, int); +#endif + +/* +#ifndef HAVE_FREXP +extern double frexp(double, int *); +#endif +*/ + +#ifndef HAVE_HYPOT +extern double hypot(double, double); +#endif + +#ifndef HAVE_ERF +extern double erf(double); +extern double erfc(double); +#endif + +#ifndef isinf +# ifndef HAVE_ISINF +# if defined(HAVE_FINITE) && defined(HAVE_ISNAN) +# define isinf(x) (!finite(x) && !isnan(x)) +# else +extern int isinf(double); +# endif +# endif +#endif + +#ifndef HAVE_ISNAN +extern int isnan(double); +#endif + +/* +#ifndef HAVE_MEMCMP +extern int memcmp(const void *, const void *, size_t); +#endif +*/ + +#ifndef HAVE_MEMMOVE +extern void *memmove(void *, const void *, size_t); +#endif + +/* +#ifndef HAVE_MODF +extern double modf(double, double *); +#endif +*/ + +#ifndef HAVE_STRCASECMP +extern int strcasecmp(const char *, const char *); +#endif + +#ifndef HAVE_STRNCASECMP +extern int strncasecmp(const char *, const char *, size_t); +#endif + +#ifndef HAVE_STRCHR +extern char *strchr(const char *, int); +extern char *strrchr(const char *, int); +#endif + +#ifndef HAVE_STRERROR +extern char *strerror(int); +#endif + +#ifndef HAVE_STRFTIME +extern size_t strftime(char *, size_t, const char *, const struct tm *); +#endif + +#ifndef HAVE_STRSTR +extern char *strstr(const char *, const char *); +#endif + +/* +#ifndef HAVE_STRTOL +extern long strtol(const char *, char **, int); +#endif +*/ + +#ifndef HAVE_STRTOUL +extern unsigned long strtoul(const char *, char **, int); +#endif + +#ifndef HAVE_VSNPRINTF +# include +extern int snprintf(char *, size_t n, char const *, ...); +extern int vsnprintf(char *, size_t n, char const *, va_list); +#endif + +#ifndef HAVE_STRLCPY +extern size_t strlcpy(char *, const char*, size_t); +#endif + +#ifndef HAVE_STRLCAT +extern size_t strlcat(char *, const char*, size_t); +#endif + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_MISSING_H */ diff --git a/include/ruby/node.h b/include/ruby/node.h new file mode 100644 index 0000000000..a477c9d555 --- /dev/null +++ b/include/ruby/node.h @@ -0,0 +1,400 @@ +/********************************************************************** + + node.h - + + $Author$ + $Date$ + created at: Fri May 28 15:14:02 JST 1993 + + Copyright (C) 1993-2003 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_NODE_H +#define RUBY_NODE_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +enum node_type { + NODE_METHOD, + NODE_FBODY, + NODE_CFUNC, + NODE_SCOPE, + NODE_BLOCK, + NODE_IF, + NODE_CASE, + NODE_WHEN, + NODE_OPT_N, + NODE_WHILE, + NODE_UNTIL, + NODE_ITER, + NODE_FOR, + NODE_BREAK, + NODE_NEXT, + NODE_REDO, + NODE_RETRY, + NODE_BEGIN, + NODE_RESCUE, + NODE_RESBODY, + NODE_ENSURE, + NODE_AND, + NODE_OR, + NODE_NOT, + NODE_MASGN, + NODE_LASGN, + NODE_DASGN, + NODE_DASGN_CURR, + NODE_GASGN, + NODE_IASGN, + NODE_IASGN2, + NODE_CDECL, + NODE_CVASGN, + NODE_CVDECL, + NODE_OP_ASGN1, + NODE_OP_ASGN2, + NODE_OP_ASGN_AND, + NODE_OP_ASGN_OR, + NODE_CALL, + NODE_FCALL, + NODE_VCALL, + NODE_SUPER, + NODE_ZSUPER, + NODE_ARRAY, + NODE_ZARRAY, + NODE_VALUES, + NODE_HASH, + NODE_RETURN, + NODE_YIELD, + NODE_LVAR, + NODE_DVAR, + NODE_GVAR, + NODE_IVAR, + NODE_CONST, + NODE_CVAR, + NODE_NTH_REF, + NODE_BACK_REF, + NODE_MATCH, + NODE_MATCH2, + NODE_MATCH3, + NODE_LIT, + NODE_STR, + NODE_DSTR, + NODE_XSTR, + NODE_DXSTR, + NODE_EVSTR, + NODE_DREGX, + NODE_DREGX_ONCE, + NODE_ARGS, + NODE_ARGS_AUX, + NODE_OPT_ARG, + NODE_POSTARG, + NODE_ARGSCAT, + NODE_ARGSPUSH, + NODE_SPLAT, + NODE_TO_ARY, + NODE_BLOCK_ARG, + NODE_BLOCK_PASS, + NODE_DEFN, + NODE_DEFS, + NODE_ALIAS, + NODE_VALIAS, + NODE_UNDEF, + NODE_CLASS, + NODE_MODULE, + NODE_SCLASS, + NODE_COLON2, + NODE_COLON3, + NODE_CREF, + NODE_DOT2, + NODE_DOT3, + NODE_FLIP2, + NODE_FLIP3, + NODE_ATTRSET, + NODE_SELF, + NODE_NIL, + NODE_TRUE, + NODE_FALSE, + NODE_ERRINFO, + NODE_DEFINED, + NODE_POSTEXE, + NODE_ALLOCA, + NODE_BMETHOD, + NODE_MEMO, + NODE_IFUNC, + NODE_DSYM, + NODE_ATTRASGN, + NODE_PRELUDE, + NODE_LAMBDA, + NODE_OPTBLOCK, + NODE_LAST +}; + +typedef struct RNode { + unsigned long flags; + char *nd_file; + union { + struct RNode *node; + ID id; + VALUE value; + VALUE (*cfunc)(ANYARGS); + ID *tbl; + } u1; + union { + struct RNode *node; + ID id; + long argc; + VALUE value; + } u2; + union { + struct RNode *node; + ID id; + long state; + struct global_entry *entry; + long cnt; + VALUE value; + } u3; +} NODE; + +#define RNODE(obj) (R_CAST(RNode)(obj)) + +/* 0..4:T_TYPES, 5:FL_MARK, 6:reserved, 7:NODE_NEWLINE */ +#define NODE_NEWLINE (1<<7) + +#define NODE_TYPESHIFT 8 +#define NODE_TYPEMASK (0x7f<flags & NODE_TYPEMASK)>>NODE_TYPESHIFT)) +#define nd_set_type(n,t) \ + RNODE(n)->flags=((RNODE(n)->flags&~NODE_TYPEMASK)|(((t)<flags>>NODE_LSHIFT)&NODE_LMASK)) +#define nd_set_line(n,l) \ + RNODE(n)->flags=((RNODE(n)->flags&~(-1< + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + */ + +#ifdef __cplusplus +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#define ONIGURUMA +#define ONIGURUMA_VERSION_MAJOR 5 +#define ONIGURUMA_VERSION_MINOR 7 +#define ONIGURUMA_VERSION_TEENY 0 + +#ifdef __cplusplus +# ifndef HAVE_PROTOTYPES +# define HAVE_PROTOTYPES 1 +# endif +# ifndef HAVE_STDARG_PROTOTYPES +# define HAVE_STDARG_PROTOTYPES 1 +# endif +#endif + +/* escape Mac OS X/Xcode 2.4/gcc 4.0.1 problem */ +#if defined(__APPLE__) && defined(__GNUC__) && __GNUC__ >= 4 +# ifndef HAVE_STDARG_PROTOTYPES +# define HAVE_STDARG_PROTOTYPES 1 +# endif +#endif + +#ifndef P_ +#if defined(__STDC__) || defined(_WIN32) +# define P_(args) args +#else +# define P_(args) () +#endif +#endif + +#ifndef PV_ +#ifdef HAVE_STDARG_PROTOTYPES +# define PV_(args) args +#else +# define PV_(args) () +#endif +#endif + +#ifndef ONIG_EXTERN +#if defined(_WIN32) && !defined(__GNUC__) +#if defined(EXPORT) || defined(RUBY_EXPORT) +#define ONIG_EXTERN extern __declspec(dllexport) +#else +#define ONIG_EXTERN extern __declspec(dllimport) +#endif +#endif +#endif + +#ifndef ONIG_EXTERN +#define ONIG_EXTERN extern +#endif + +/* PART: character encoding */ + +#ifndef ONIG_ESCAPE_UCHAR_COLLISION +#define UChar OnigUChar +#endif + +typedef unsigned char OnigUChar; +typedef unsigned long OnigCodePoint; +typedef unsigned int OnigDistance; + +#define ONIG_INFINITE_DISTANCE ~((OnigDistance )0) + +/* case fold flag */ +typedef unsigned int OnigCaseFoldType; + +ONIG_EXTERN OnigCaseFoldType OnigDefaultCaseFoldFlag; + +/* #define ONIGENC_CASE_FOLD_HIRAGANA_KATAKANA (1<<1) */ +/* #define ONIGENC_CASE_FOLD_KATAKANA_WIDTH (1<<2) */ +#define ONIGENC_CASE_FOLD_TURKISH_AZERI (1<<20) +#define INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR (1<<30) + +#define ONIGENC_CASE_FOLD_MIN INTERNAL_ONIGENC_CASE_FOLD_MULTI_CHAR +#define ONIGENC_CASE_FOLD_DEFAULT OnigDefaultCaseFoldFlag + + +#define ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN 3 +#define ONIGENC_GET_CASE_FOLD_CODES_MAX_NUM 13 +/* 13 => Unicode:0x1ffc */ + +/* code range */ +#define ONIGENC_CODE_RANGE_NUM(range) ((int )range[0]) +#define ONIGENC_CODE_RANGE_FROM(range,i) range[((i)*2) + 1] +#define ONIGENC_CODE_RANGE_TO(range,i) range[((i)*2) + 2] + +typedef struct { + int byte_len; /* argument(original) character(s) byte length */ + int code_len; /* number of code */ + OnigCodePoint code[ONIGENC_MAX_COMP_CASE_FOLD_CODE_LEN]; +} OnigCaseFoldCodeItem; + +typedef struct { + OnigCodePoint esc; + OnigCodePoint anychar; + OnigCodePoint anytime; + OnigCodePoint zero_or_one_time; + OnigCodePoint one_or_more_time; + OnigCodePoint anychar_anytime; +} OnigMetaCharTableType; + +typedef int (*OnigApplyAllCaseFoldFunc)(OnigCodePoint from, OnigCodePoint* to, int to_len, void* arg); + +typedef struct OnigEncodingTypeST { + int (*mbc_enc_len)(const OnigUChar* p); + const char* name; + int max_enc_len; + int min_enc_len; + int (*is_mbc_newline)(const OnigUChar* p, const OnigUChar* end); + OnigCodePoint (*mbc_to_code)(const OnigUChar* p, const OnigUChar* end); + int (*code_to_mbclen)(OnigCodePoint code); + int (*code_to_mbc)(OnigCodePoint code, OnigUChar *buf); + int (*mbc_case_fold)(OnigCaseFoldType flag, const OnigUChar** pp, const OnigUChar* end, OnigUChar* to); + int (*apply_all_case_fold)(OnigCaseFoldType flag, OnigApplyAllCaseFoldFunc f, void* arg); + int (*get_case_fold_codes_by_str)(OnigCaseFoldType flag, const OnigUChar* p, const OnigUChar* end, OnigCaseFoldCodeItem acs[]); + int (*property_name_to_ctype)(struct OnigEncodingTypeST* enc, OnigUChar* p, OnigUChar* end); + int (*is_code_ctype)(OnigCodePoint code, unsigned int ctype); + int (*get_ctype_code_range)(int ctype, OnigCodePoint* sb_out, const OnigCodePoint* ranges[]); + OnigUChar* (*left_adjust_char_head)(const OnigUChar* start, const OnigUChar* p); + int (*is_allowed_reverse_match)(const OnigUChar* p, const OnigUChar* end); +} OnigEncodingType; + +typedef OnigEncodingType* OnigEncoding; + +ONIG_EXTERN OnigEncodingType OnigEncodingASCII; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_1; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_2; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_3; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_4; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_5; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_6; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_7; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_8; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_9; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_10; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_11; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_13; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_14; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_15; +ONIG_EXTERN OnigEncodingType OnigEncodingISO_8859_16; +ONIG_EXTERN OnigEncodingType OnigEncodingUTF8; +ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_BE; +ONIG_EXTERN OnigEncodingType OnigEncodingUTF16_LE; +ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_BE; +ONIG_EXTERN OnigEncodingType OnigEncodingUTF32_LE; +ONIG_EXTERN OnigEncodingType OnigEncodingEUC_JP; +ONIG_EXTERN OnigEncodingType OnigEncodingEUC_TW; +ONIG_EXTERN OnigEncodingType OnigEncodingEUC_KR; +ONIG_EXTERN OnigEncodingType OnigEncodingEUC_CN; +ONIG_EXTERN OnigEncodingType OnigEncodingSJIS; +ONIG_EXTERN OnigEncodingType OnigEncodingKOI8; +ONIG_EXTERN OnigEncodingType OnigEncodingKOI8_R; +ONIG_EXTERN OnigEncodingType OnigEncodingCP1251; +ONIG_EXTERN OnigEncodingType OnigEncodingBIG5; +ONIG_EXTERN OnigEncodingType OnigEncodingGB18030; + +#define ONIG_ENCODING_ASCII (&OnigEncodingASCII) +#define ONIG_ENCODING_ISO_8859_1 (&OnigEncodingISO_8859_1) +#define ONIG_ENCODING_ISO_8859_2 (&OnigEncodingISO_8859_2) +#define ONIG_ENCODING_ISO_8859_3 (&OnigEncodingISO_8859_3) +#define ONIG_ENCODING_ISO_8859_4 (&OnigEncodingISO_8859_4) +#define ONIG_ENCODING_ISO_8859_5 (&OnigEncodingISO_8859_5) +#define ONIG_ENCODING_ISO_8859_6 (&OnigEncodingISO_8859_6) +#define ONIG_ENCODING_ISO_8859_7 (&OnigEncodingISO_8859_7) +#define ONIG_ENCODING_ISO_8859_8 (&OnigEncodingISO_8859_8) +#define ONIG_ENCODING_ISO_8859_9 (&OnigEncodingISO_8859_9) +#define ONIG_ENCODING_ISO_8859_10 (&OnigEncodingISO_8859_10) +#define ONIG_ENCODING_ISO_8859_11 (&OnigEncodingISO_8859_11) +#define ONIG_ENCODING_ISO_8859_13 (&OnigEncodingISO_8859_13) +#define ONIG_ENCODING_ISO_8859_14 (&OnigEncodingISO_8859_14) +#define ONIG_ENCODING_ISO_8859_15 (&OnigEncodingISO_8859_15) +#define ONIG_ENCODING_ISO_8859_16 (&OnigEncodingISO_8859_16) +#define ONIG_ENCODING_UTF8 (&OnigEncodingUTF8) +#define ONIG_ENCODING_UTF16_BE (&OnigEncodingUTF16_BE) +#define ONIG_ENCODING_UTF16_LE (&OnigEncodingUTF16_LE) +#define ONIG_ENCODING_UTF32_BE (&OnigEncodingUTF32_BE) +#define ONIG_ENCODING_UTF32_LE (&OnigEncodingUTF32_LE) +#define ONIG_ENCODING_EUC_JP (&OnigEncodingEUC_JP) +#define ONIG_ENCODING_EUC_TW (&OnigEncodingEUC_TW) +#define ONIG_ENCODING_EUC_KR (&OnigEncodingEUC_KR) +#define ONIG_ENCODING_EUC_CN (&OnigEncodingEUC_CN) +#define ONIG_ENCODING_SJIS (&OnigEncodingSJIS) +#define ONIG_ENCODING_KOI8 (&OnigEncodingKOI8) +#define ONIG_ENCODING_KOI8_R (&OnigEncodingKOI8_R) +#define ONIG_ENCODING_CP1251 (&OnigEncodingCP1251) +#define ONIG_ENCODING_BIG5 (&OnigEncodingBIG5) +#define ONIG_ENCODING_GB18030 (&OnigEncodingGB18030) + +#define ONIG_ENCODING_UNDEF ((OnigEncoding )0) + + +/* work size */ +#define ONIGENC_CODE_TO_MBC_MAXLEN 7 +#define ONIGENC_MBC_CASE_FOLD_MAXLEN 18 +/* 18: 6(max-byte) * 3(case-fold chars) */ + +/* character types */ +#define ONIGENC_CTYPE_NEWLINE 0 +#define ONIGENC_CTYPE_ALPHA 1 +#define ONIGENC_CTYPE_BLANK 2 +#define ONIGENC_CTYPE_CNTRL 3 +#define ONIGENC_CTYPE_DIGIT 4 +#define ONIGENC_CTYPE_GRAPH 5 +#define ONIGENC_CTYPE_LOWER 6 +#define ONIGENC_CTYPE_PRINT 7 +#define ONIGENC_CTYPE_PUNCT 8 +#define ONIGENC_CTYPE_SPACE 9 +#define ONIGENC_CTYPE_UPPER 10 +#define ONIGENC_CTYPE_XDIGIT 11 +#define ONIGENC_CTYPE_WORD 12 +#define ONIGENC_CTYPE_ALNUM 13 /* alpha || digit */ +#define ONIGENC_CTYPE_ASCII 14 +#define ONIGENC_MAX_STD_CTYPE ONIGENC_CTYPE_ASCII + + +#define enc_len(enc,p) ONIGENC_MBC_ENC_LEN(enc, p) + +#define ONIGENC_IS_UNDEF(enc) ((enc) == ONIG_ENCODING_UNDEF) +#define ONIGENC_IS_SINGLEBYTE(enc) (ONIGENC_MBC_MAXLEN(enc) == 1) +#define ONIGENC_IS_MBC_HEAD(enc,p) (ONIGENC_MBC_ENC_LEN(enc,p) != 1) +#define ONIGENC_IS_MBC_ASCII(p) (*(p) < 128) +#define ONIGENC_IS_CODE_ASCII(code) ((code) < 128) +#define ONIGENC_IS_MBC_WORD(enc,s,end) \ + ONIGENC_IS_CODE_WORD(enc,ONIGENC_MBC_TO_CODE(enc,s,end)) + + +#define ONIGENC_NAME(enc) ((enc)->name) + +#define ONIGENC_MBC_CASE_FOLD(enc,flag,pp,end,buf) \ + (enc)->mbc_case_fold(flag,(const OnigUChar** )pp,end,buf) +#define ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc,s,end) \ + (enc)->is_allowed_reverse_match(s,end) +#define ONIGENC_LEFT_ADJUST_CHAR_HEAD(enc,start,s) \ + (enc)->left_adjust_char_head(start, s) +#define ONIGENC_APPLY_ALL_CASE_FOLD(enc,case_fold_flag,f,arg) \ + (enc)->apply_all_case_fold(case_fold_flag,f,arg) +#define ONIGENC_GET_CASE_FOLD_CODES_BY_STR(enc,case_fold_flag,p,end,acs) \ + (enc)->get_case_fold_codes_by_str(case_fold_flag,p,end,acs) +#define ONIGENC_STEP_BACK(enc,start,s,n) \ + onigenc_step_back((enc),(start),(s),(n)) + +#define ONIGENC_MBC_ENC_LEN(enc,p) (enc)->mbc_enc_len(p) +#define ONIGENC_MBC_MAXLEN(enc) ((enc)->max_enc_len) +#define ONIGENC_MBC_MAXLEN_DIST(enc) ONIGENC_MBC_MAXLEN(enc) +#define ONIGENC_MBC_MINLEN(enc) ((enc)->min_enc_len) +#define ONIGENC_IS_MBC_NEWLINE(enc,p,end) (enc)->is_mbc_newline((p),(end)) +#define ONIGENC_MBC_TO_CODE(enc,p,end) (enc)->mbc_to_code((p),(end)) +#define ONIGENC_CODE_TO_MBCLEN(enc,code) (enc)->code_to_mbclen(code) +#define ONIGENC_CODE_TO_MBC(enc,code,buf) (enc)->code_to_mbc(code,buf) +#define ONIGENC_PROPERTY_NAME_TO_CTYPE(enc,p,end) \ + (enc)->property_name_to_ctype(enc,p,end) + +#define ONIGENC_IS_CODE_CTYPE(enc,code,ctype) (enc)->is_code_ctype(code,ctype) + +#define ONIGENC_IS_CODE_NEWLINE(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_NEWLINE) +#define ONIGENC_IS_CODE_GRAPH(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_GRAPH) +#define ONIGENC_IS_CODE_PRINT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PRINT) +#define ONIGENC_IS_CODE_ALNUM(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALNUM) +#define ONIGENC_IS_CODE_ALPHA(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_ALPHA) +#define ONIGENC_IS_CODE_LOWER(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_LOWER) +#define ONIGENC_IS_CODE_UPPER(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_UPPER) +#define ONIGENC_IS_CODE_CNTRL(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_CNTRL) +#define ONIGENC_IS_CODE_PUNCT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_PUNCT) +#define ONIGENC_IS_CODE_SPACE(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_SPACE) +#define ONIGENC_IS_CODE_BLANK(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_BLANK) +#define ONIGENC_IS_CODE_DIGIT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_DIGIT) +#define ONIGENC_IS_CODE_XDIGIT(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_XDIGIT) +#define ONIGENC_IS_CODE_WORD(enc,code) \ + ONIGENC_IS_CODE_CTYPE(enc,code,ONIGENC_CTYPE_WORD) + +#define ONIGENC_GET_CTYPE_CODE_RANGE(enc,ctype,sbout,ranges) \ + (enc)->get_ctype_code_range(ctype,sbout,ranges) + +ONIG_EXTERN +OnigUChar* onigenc_step_back P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, int n)); + + +/* encoding API */ +ONIG_EXTERN +int onigenc_init P_((void)); +ONIG_EXTERN +int onigenc_set_default_encoding P_((OnigEncoding enc)); +ONIG_EXTERN +OnigEncoding onigenc_get_default_encoding P_((void)); +ONIG_EXTERN +void onigenc_set_default_caseconv_table P_((const OnigUChar* table)); +ONIG_EXTERN +OnigUChar* onigenc_get_right_adjust_char_head_with_prev P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s, const OnigUChar** prev)); +ONIG_EXTERN +OnigUChar* onigenc_get_prev_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s)); +ONIG_EXTERN +OnigUChar* onigenc_get_left_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s)); +ONIG_EXTERN +OnigUChar* onigenc_get_right_adjust_char_head P_((OnigEncoding enc, const OnigUChar* start, const OnigUChar* s)); +ONIG_EXTERN +int onigenc_strlen P_((OnigEncoding enc, const OnigUChar* p, const OnigUChar* end)); +ONIG_EXTERN +int onigenc_strlen_null P_((OnigEncoding enc, const OnigUChar* p)); +ONIG_EXTERN +int onigenc_str_bytelen_null P_((OnigEncoding enc, const OnigUChar* p)); + + + +/* PART: regular expression */ + +/* config parameters */ +#define ONIG_NREGION 10 +#define ONIG_MAX_BACKREF_NUM 1000 +#define ONIG_MAX_REPEAT_NUM 100000 +#define ONIG_MAX_MULTI_BYTE_RANGES_NUM 10000 +/* constants */ +#define ONIG_MAX_ERROR_MESSAGE_LEN 90 + +typedef unsigned int OnigOptionType; + +#define ONIG_OPTION_DEFAULT ONIG_OPTION_NONE + +/* options */ +#define ONIG_OPTION_NONE 0U +#define ONIG_OPTION_IGNORECASE 1U +#define ONIG_OPTION_EXTEND (ONIG_OPTION_IGNORECASE << 1) +#define ONIG_OPTION_MULTILINE (ONIG_OPTION_EXTEND << 1) +#define ONIG_OPTION_SINGLELINE (ONIG_OPTION_MULTILINE << 1) +#define ONIG_OPTION_FIND_LONGEST (ONIG_OPTION_SINGLELINE << 1) +#define ONIG_OPTION_FIND_NOT_EMPTY (ONIG_OPTION_FIND_LONGEST << 1) +#define ONIG_OPTION_NEGATE_SINGLELINE (ONIG_OPTION_FIND_NOT_EMPTY << 1) +#define ONIG_OPTION_DONT_CAPTURE_GROUP (ONIG_OPTION_NEGATE_SINGLELINE << 1) +#define ONIG_OPTION_CAPTURE_GROUP (ONIG_OPTION_DONT_CAPTURE_GROUP << 1) +/* options (search time) */ +#define ONIG_OPTION_NOTBOL (ONIG_OPTION_CAPTURE_GROUP << 1) +#define ONIG_OPTION_NOTEOL (ONIG_OPTION_NOTBOL << 1) +#define ONIG_OPTION_POSIX_REGION (ONIG_OPTION_NOTEOL << 1) +#define ONIG_OPTION_MAXBIT ONIG_OPTION_POSIX_REGION /* limit */ + +#define ONIG_OPTION_ON(options,regopt) ((options) |= (regopt)) +#define ONIG_OPTION_OFF(options,regopt) ((options) &= ~(regopt)) +#define ONIG_IS_OPTION_ON(options,option) ((options) & (option)) + +/* syntax */ +typedef struct { + unsigned int op; + unsigned int op2; + unsigned int behavior; + OnigOptionType options; /* default option */ + OnigMetaCharTableType meta_char_table; +} OnigSyntaxType; + +ONIG_EXTERN OnigSyntaxType OnigSyntaxASIS; +ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixBasic; +ONIG_EXTERN OnigSyntaxType OnigSyntaxPosixExtended; +ONIG_EXTERN OnigSyntaxType OnigSyntaxEmacs; +ONIG_EXTERN OnigSyntaxType OnigSyntaxGrep; +ONIG_EXTERN OnigSyntaxType OnigSyntaxGnuRegex; +ONIG_EXTERN OnigSyntaxType OnigSyntaxJava; +ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl; +ONIG_EXTERN OnigSyntaxType OnigSyntaxPerl_NG; +ONIG_EXTERN OnigSyntaxType OnigSyntaxRuby; + +/* predefined syntaxes (see regsyntax.c) */ +#define ONIG_SYNTAX_ASIS (&OnigSyntaxASIS) +#define ONIG_SYNTAX_POSIX_BASIC (&OnigSyntaxPosixBasic) +#define ONIG_SYNTAX_POSIX_EXTENDED (&OnigSyntaxPosixExtended) +#define ONIG_SYNTAX_EMACS (&OnigSyntaxEmacs) +#define ONIG_SYNTAX_GREP (&OnigSyntaxGrep) +#define ONIG_SYNTAX_GNU_REGEX (&OnigSyntaxGnuRegex) +#define ONIG_SYNTAX_JAVA (&OnigSyntaxJava) +#define ONIG_SYNTAX_PERL (&OnigSyntaxPerl) +#define ONIG_SYNTAX_PERL_NG (&OnigSyntaxPerl_NG) +#define ONIG_SYNTAX_RUBY (&OnigSyntaxRuby) + +/* default syntax */ +ONIG_EXTERN OnigSyntaxType* OnigDefaultSyntax; +#define ONIG_SYNTAX_DEFAULT OnigDefaultSyntax + +/* syntax (operators) */ +#define ONIG_SYN_OP_VARIABLE_META_CHARACTERS (1U<<0) +#define ONIG_SYN_OP_DOT_ANYCHAR (1U<<1) /* . */ +#define ONIG_SYN_OP_ASTERISK_ZERO_INF (1U<<2) /* * */ +#define ONIG_SYN_OP_ESC_ASTERISK_ZERO_INF (1U<<3) +#define ONIG_SYN_OP_PLUS_ONE_INF (1U<<4) /* + */ +#define ONIG_SYN_OP_ESC_PLUS_ONE_INF (1U<<5) +#define ONIG_SYN_OP_QMARK_ZERO_ONE (1U<<6) /* ? */ +#define ONIG_SYN_OP_ESC_QMARK_ZERO_ONE (1U<<7) +#define ONIG_SYN_OP_BRACE_INTERVAL (1U<<8) /* {lower,upper} */ +#define ONIG_SYN_OP_ESC_BRACE_INTERVAL (1U<<9) /* \{lower,upper\} */ +#define ONIG_SYN_OP_VBAR_ALT (1U<<10) /* | */ +#define ONIG_SYN_OP_ESC_VBAR_ALT (1U<<11) /* \| */ +#define ONIG_SYN_OP_LPAREN_SUBEXP (1U<<12) /* (...) */ +#define ONIG_SYN_OP_ESC_LPAREN_SUBEXP (1U<<13) /* \(...\) */ +#define ONIG_SYN_OP_ESC_AZ_BUF_ANCHOR (1U<<14) /* \A, \Z, \z */ +#define ONIG_SYN_OP_ESC_CAPITAL_G_BEGIN_ANCHOR (1U<<15) /* \G */ +#define ONIG_SYN_OP_DECIMAL_BACKREF (1U<<16) /* \num */ +#define ONIG_SYN_OP_BRACKET_CC (1U<<17) /* [...] */ +#define ONIG_SYN_OP_ESC_W_WORD (1U<<18) /* \w, \W */ +#define ONIG_SYN_OP_ESC_LTGT_WORD_BEGIN_END (1U<<19) /* \<. \> */ +#define ONIG_SYN_OP_ESC_B_WORD_BOUND (1U<<20) /* \b, \B */ +#define ONIG_SYN_OP_ESC_S_WHITE_SPACE (1U<<21) /* \s, \S */ +#define ONIG_SYN_OP_ESC_D_DIGIT (1U<<22) /* \d, \D */ +#define ONIG_SYN_OP_LINE_ANCHOR (1U<<23) /* ^, $ */ +#define ONIG_SYN_OP_POSIX_BRACKET (1U<<24) /* [:xxxx:] */ +#define ONIG_SYN_OP_QMARK_NON_GREEDY (1U<<25) /* ??,*?,+?,{n,m}? */ +#define ONIG_SYN_OP_ESC_CONTROL_CHARS (1U<<26) /* \n,\r,\t,\a ... */ +#define ONIG_SYN_OP_ESC_C_CONTROL (1U<<27) /* \cx */ +#define ONIG_SYN_OP_ESC_OCTAL3 (1U<<28) /* \OOO */ +#define ONIG_SYN_OP_ESC_X_HEX2 (1U<<29) /* \xHH */ +#define ONIG_SYN_OP_ESC_X_BRACE_HEX8 (1U<<30) /* \x{7HHHHHHH} */ + +#define ONIG_SYN_OP2_ESC_CAPITAL_Q_QUOTE (1U<<0) /* \Q...\E */ +#define ONIG_SYN_OP2_QMARK_GROUP_EFFECT (1U<<1) /* (?...) */ +#define ONIG_SYN_OP2_OPTION_PERL (1U<<2) /* (?imsx),(?-imsx) */ +#define ONIG_SYN_OP2_OPTION_RUBY (1U<<3) /* (?imx), (?-imx) */ +#define ONIG_SYN_OP2_PLUS_POSSESSIVE_REPEAT (1U<<4) /* ?+,*+,++ */ +#define ONIG_SYN_OP2_PLUS_POSSESSIVE_INTERVAL (1U<<5) /* {n,m}+ */ +#define ONIG_SYN_OP2_CCLASS_SET_OP (1U<<6) /* [...&&..[..]..] */ +#define ONIG_SYN_OP2_QMARK_LT_NAMED_GROUP (1U<<7) /* (?...) */ +#define ONIG_SYN_OP2_ESC_K_NAMED_BACKREF (1U<<8) /* \k */ +#define ONIG_SYN_OP2_ESC_G_SUBEXP_CALL (1U<<9) /* \g, \g */ +#define ONIG_SYN_OP2_ATMARK_CAPTURE_HISTORY (1U<<10) /* (?@..),(?@..) */ +#define ONIG_SYN_OP2_ESC_CAPITAL_C_BAR_CONTROL (1U<<11) /* \C-x */ +#define ONIG_SYN_OP2_ESC_CAPITAL_M_BAR_META (1U<<12) /* \M-x */ +#define ONIG_SYN_OP2_ESC_V_VTAB (1U<<13) /* \v as VTAB */ +#define ONIG_SYN_OP2_ESC_U_HEX4 (1U<<14) /* \uHHHH */ +#define ONIG_SYN_OP2_ESC_GNU_BUF_ANCHOR (1U<<15) /* \`, \' */ +#define ONIG_SYN_OP2_ESC_P_BRACE_CHAR_PROPERTY (1U<<16) /* \p{...}, \P{...} */ +#define ONIG_SYN_OP2_ESC_P_BRACE_CIRCUMFLEX_NOT (1U<<17) /* \p{^..}, \P{^..} */ +/* #define ONIG_SYN_OP2_CHAR_PROPERTY_PREFIX_IS (1U<<18) */ +#define ONIG_SYN_OP2_ESC_H_XDIGIT (1U<<19) /* \h, \H */ +#define ONIG_SYN_OP2_INEFFECTIVE_ESCAPE (1U<<20) /* \ */ + +/* syntax (behavior) */ +#define ONIG_SYN_CONTEXT_INDEP_ANCHORS (1U<<31) /* not implemented */ +#define ONIG_SYN_CONTEXT_INDEP_REPEAT_OPS (1U<<0) /* ?, *, +, {n,m} */ +#define ONIG_SYN_CONTEXT_INVALID_REPEAT_OPS (1U<<1) /* error or ignore */ +#define ONIG_SYN_ALLOW_UNMATCHED_CLOSE_SUBEXP (1U<<2) /* ...)... */ +#define ONIG_SYN_ALLOW_INVALID_INTERVAL (1U<<3) /* {??? */ +#define ONIG_SYN_ALLOW_INTERVAL_LOW_ABBREV (1U<<4) /* {,n} => {0,n} */ +#define ONIG_SYN_STRICT_CHECK_BACKREF (1U<<5) /* /(\1)/,/\1()/ ..*/ +#define ONIG_SYN_DIFFERENT_LEN_ALT_LOOK_BEHIND (1U<<6) /* (?<=a|bc) */ +#define ONIG_SYN_CAPTURE_ONLY_NAMED_GROUP (1U<<7) /* see doc/RE */ +#define ONIG_SYN_ALLOW_MULTIPLEX_DEFINITION_NAME (1U<<8) /* (?)(?) */ +#define ONIG_SYN_FIXED_INTERVAL_IS_GREEDY_ONLY (1U<<9) /* a{n}?=(?:a{n})? */ + +/* syntax (behavior) in char class [...] */ +#define ONIG_SYN_NOT_NEWLINE_IN_NEGATIVE_CC (1U<<20) /* [^...] */ +#define ONIG_SYN_BACKSLASH_ESCAPE_IN_CC (1U<<21) /* [..\w..] etc.. */ +#define ONIG_SYN_ALLOW_EMPTY_RANGE_IN_CC (1U<<22) +#define ONIG_SYN_ALLOW_DOUBLE_RANGE_OP_IN_CC (1U<<23) /* [0-9-a]=[0-9\-a] */ +/* syntax (behavior) warning */ +#define ONIG_SYN_WARN_CC_OP_NOT_ESCAPED (1U<<24) /* [,-,] */ +#define ONIG_SYN_WARN_REDUNDANT_NESTED_REPEAT (1U<<25) /* (?:a*)+ */ + +/* meta character specifiers (onig_set_meta_char()) */ +#define ONIG_META_CHAR_ESCAPE 0 +#define ONIG_META_CHAR_ANYCHAR 1 +#define ONIG_META_CHAR_ANYTIME 2 +#define ONIG_META_CHAR_ZERO_OR_ONE_TIME 3 +#define ONIG_META_CHAR_ONE_OR_MORE_TIME 4 +#define ONIG_META_CHAR_ANYCHAR_ANYTIME 5 + +#define ONIG_INEFFECTIVE_META_CHAR 0 + +/* error codes */ +#define ONIG_IS_PATTERN_ERROR(ecode) ((ecode) <= -100 && (ecode) > -1000) +/* normal return */ +#define ONIG_NORMAL 0 +#define ONIG_MISMATCH -1 +#define ONIG_NO_SUPPORT_CONFIG -2 + +/* internal error */ +#define ONIGERR_MEMORY -5 +#define ONIGERR_TYPE_BUG -6 +#define ONIGERR_PARSER_BUG -11 +#define ONIGERR_STACK_BUG -12 +#define ONIGERR_UNDEFINED_BYTECODE -13 +#define ONIGERR_UNEXPECTED_BYTECODE -14 +#define ONIGERR_MATCH_STACK_LIMIT_OVER -15 +#define ONIGERR_DEFAULT_ENCODING_IS_NOT_SETTED -21 +#define ONIGERR_SPECIFIED_ENCODING_CANT_CONVERT_TO_WIDE_CHAR -22 +/* general error */ +#define ONIGERR_INVALID_ARGUMENT -30 +/* syntax error */ +#define ONIGERR_END_PATTERN_AT_LEFT_BRACE -100 +#define ONIGERR_END_PATTERN_AT_LEFT_BRACKET -101 +#define ONIGERR_EMPTY_CHAR_CLASS -102 +#define ONIGERR_PREMATURE_END_OF_CHAR_CLASS -103 +#define ONIGERR_END_PATTERN_AT_ESCAPE -104 +#define ONIGERR_END_PATTERN_AT_META -105 +#define ONIGERR_END_PATTERN_AT_CONTROL -106 +#define ONIGERR_META_CODE_SYNTAX -108 +#define ONIGERR_CONTROL_CODE_SYNTAX -109 +#define ONIGERR_CHAR_CLASS_VALUE_AT_END_OF_RANGE -110 +#define ONIGERR_CHAR_CLASS_VALUE_AT_START_OF_RANGE -111 +#define ONIGERR_UNMATCHED_RANGE_SPECIFIER_IN_CHAR_CLASS -112 +#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_NOT_SPECIFIED -113 +#define ONIGERR_TARGET_OF_REPEAT_OPERATOR_INVALID -114 +#define ONIGERR_NESTED_REPEAT_OPERATOR -115 +#define ONIGERR_UNMATCHED_CLOSE_PARENTHESIS -116 +#define ONIGERR_END_PATTERN_WITH_UNMATCHED_PARENTHESIS -117 +#define ONIGERR_END_PATTERN_IN_GROUP -118 +#define ONIGERR_UNDEFINED_GROUP_OPTION -119 +#define ONIGERR_INVALID_POSIX_BRACKET_TYPE -121 +#define ONIGERR_INVALID_LOOK_BEHIND_PATTERN -122 +#define ONIGERR_INVALID_REPEAT_RANGE_PATTERN -123 +/* values error (syntax error) */ +#define ONIGERR_TOO_BIG_NUMBER -200 +#define ONIGERR_TOO_BIG_NUMBER_FOR_REPEAT_RANGE -201 +#define ONIGERR_UPPER_SMALLER_THAN_LOWER_IN_REPEAT_RANGE -202 +#define ONIGERR_EMPTY_RANGE_IN_CHAR_CLASS -203 +#define ONIGERR_MISMATCH_CODE_LENGTH_IN_CLASS_RANGE -204 +#define ONIGERR_TOO_MANY_MULTI_BYTE_RANGES -205 +#define ONIGERR_TOO_SHORT_MULTI_BYTE_STRING -206 +#define ONIGERR_TOO_BIG_BACKREF_NUMBER -207 +#define ONIGERR_INVALID_BACKREF -208 +#define ONIGERR_NUMBERED_BACKREF_OR_CALL_NOT_ALLOWED -209 +#define ONIGERR_TOO_LONG_WIDE_CHAR_VALUE -212 +#define ONIGERR_EMPTY_GROUP_NAME -214 +#define ONIGERR_INVALID_GROUP_NAME -215 +#define ONIGERR_INVALID_CHAR_IN_GROUP_NAME -216 +#define ONIGERR_UNDEFINED_NAME_REFERENCE -217 +#define ONIGERR_UNDEFINED_GROUP_REFERENCE -218 +#define ONIGERR_MULTIPLEX_DEFINED_NAME -219 +#define ONIGERR_MULTIPLEX_DEFINITION_NAME_CALL -220 +#define ONIGERR_NEVER_ENDING_RECURSION -221 +#define ONIGERR_GROUP_NUMBER_OVER_FOR_CAPTURE_HISTORY -222 +#define ONIGERR_INVALID_CHAR_PROPERTY_NAME -223 +#define ONIGERR_INVALID_WIDE_CHAR_VALUE -400 +#define ONIGERR_TOO_BIG_WIDE_CHAR_VALUE -401 +#define ONIGERR_NOT_SUPPORTED_ENCODING_COMBINATION -402 +#define ONIGERR_INVALID_COMBINATION_OF_OPTIONS -403 + +/* errors related to thread */ +#define ONIGERR_OVER_THREAD_PASS_LIMIT_COUNT -1001 + + +/* must be smaller than BIT_STATUS_BITS_NUM (unsigned int * 8) */ +#define ONIG_MAX_CAPTURE_HISTORY_GROUP 31 +#define ONIG_IS_CAPTURE_HISTORY_GROUP(r, i) \ + ((i) <= ONIG_MAX_CAPTURE_HISTORY_GROUP && (r)->list && (r)->list[i]) + +typedef struct OnigCaptureTreeNodeStruct { + int group; /* group number */ + int beg; + int end; + int allocated; + int num_childs; + struct OnigCaptureTreeNodeStruct** childs; +} OnigCaptureTreeNode; + +/* match result region type */ +struct re_registers { + int allocated; + int num_regs; + int* beg; + int* end; + /* extended */ + OnigCaptureTreeNode* history_root; /* capture history tree root */ +}; + +/* capture tree traverse */ +#define ONIG_TRAVERSE_CALLBACK_AT_FIRST 1 +#define ONIG_TRAVERSE_CALLBACK_AT_LAST 2 +#define ONIG_TRAVERSE_CALLBACK_AT_BOTH \ + ( ONIG_TRAVERSE_CALLBACK_AT_FIRST | ONIG_TRAVERSE_CALLBACK_AT_LAST ) + + +#define ONIG_REGION_NOTPOS -1 + +typedef struct re_registers OnigRegion; + +typedef struct { + OnigEncoding enc; + OnigUChar* par; + OnigUChar* par_end; +} OnigErrorInfo; + +typedef struct { + int lower; + int upper; +} OnigRepeatRange; + +typedef void (*OnigWarnFunc) P_((const char* s)); +extern void onig_null_warn P_((const char* s)); +#define ONIG_NULL_WARN onig_null_warn + +#define ONIG_CHAR_TABLE_SIZE 256 + +/* regex_t state */ +#define ONIG_STATE_NORMAL 0 +#define ONIG_STATE_SEARCHING 1 +#define ONIG_STATE_COMPILING -1 +#define ONIG_STATE_MODIFY -2 + +#define ONIG_STATE(reg) \ + ((reg)->state > 0 ? ONIG_STATE_SEARCHING : (reg)->state) + +typedef struct re_pattern_buffer { + /* common members of BBuf(bytes-buffer) */ + unsigned char* p; /* compiled pattern */ + unsigned int used; /* used space for p */ + unsigned int alloc; /* allocated space for p */ + + int state; /* normal, searching, compiling */ + int num_mem; /* used memory(...) num counted from 1 */ + int num_repeat; /* OP_REPEAT/OP_REPEAT_NG id-counter */ + int num_null_check; /* OP_NULL_CHECK_START/END id counter */ + int num_comb_exp_check; /* combination explosion check */ + int num_call; /* number of subexp call */ + unsigned int capture_history; /* (?@...) flag (1-31) */ + unsigned int bt_mem_start; /* need backtrack flag */ + unsigned int bt_mem_end; /* need backtrack flag */ + int stack_pop_level; + int repeat_range_alloc; + OnigRepeatRange* repeat_range; + + OnigEncoding enc; + OnigOptionType options; + OnigSyntaxType* syntax; + OnigCaseFoldType case_fold_flag; + void* name_table; + + /* optimization info (string search, char-map and anchors) */ + int optimize; /* optimize flag */ + int threshold_len; /* search str-length for apply optimize */ + int anchor; /* BEGIN_BUF, BEGIN_POS, (SEMI_)END_BUF */ + OnigDistance anchor_dmin; /* (SEMI_)END_BUF anchor distance */ + OnigDistance anchor_dmax; /* (SEMI_)END_BUF anchor distance */ + int sub_anchor; /* start-anchor for exact or map */ + unsigned char *exact; + unsigned char *exact_end; + unsigned char map[ONIG_CHAR_TABLE_SIZE]; /* used as BM skip or char-map */ + int *int_map; /* BM skip for exact_len > 255 */ + int *int_map_backward; /* BM skip for backward search */ + OnigDistance dmin; /* min-distance of exact or map */ + OnigDistance dmax; /* max-distance of exact or map */ + + /* regex_t link chain */ + struct re_pattern_buffer* chain; /* escape compile-conflict */ +} OnigRegexType; + +typedef OnigRegexType* OnigRegex; + +#ifndef ONIG_ESCAPE_REGEX_T_COLLISION + typedef OnigRegexType regex_t; +#endif + + +typedef struct { + int num_of_elements; + OnigEncoding pattern_enc; + OnigEncoding target_enc; + OnigSyntaxType* syntax; + OnigOptionType option; + OnigCaseFoldType case_fold_flag; +} OnigCompileInfo; + +/* Oniguruma Native API */ +ONIG_EXTERN +int onig_init P_((void)); +ONIG_EXTERN +int onig_error_code_to_str PV_((OnigUChar* s, int err_code, ...)); +ONIG_EXTERN +void onig_set_warn_func P_((OnigWarnFunc f)); +ONIG_EXTERN +void onig_set_verb_warn_func P_((OnigWarnFunc f)); +ONIG_EXTERN +int onig_new P_((OnigRegex*, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo)); +ONIG_EXTERN +int onig_new_deluxe P_((OnigRegex* reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo)); +ONIG_EXTERN +void onig_free P_((OnigRegex)); +ONIG_EXTERN +int onig_recompile P_((OnigRegex, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigOptionType option, OnigEncoding enc, OnigSyntaxType* syntax, OnigErrorInfo* einfo)); +ONIG_EXTERN +int onig_recompile_deluxe P_((OnigRegex reg, const OnigUChar* pattern, const OnigUChar* pattern_end, OnigCompileInfo* ci, OnigErrorInfo* einfo)); +ONIG_EXTERN +int onig_search P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* start, const OnigUChar* range, OnigRegion* region, OnigOptionType option)); +ONIG_EXTERN +int onig_match P_((OnigRegex, const OnigUChar* str, const OnigUChar* end, const OnigUChar* at, OnigRegion* region, OnigOptionType option)); +ONIG_EXTERN +OnigRegion* onig_region_new P_((void)); +ONIG_EXTERN +void onig_region_init P_((OnigRegion* region)); +ONIG_EXTERN +void onig_region_free P_((OnigRegion* region, int free_self)); +ONIG_EXTERN +void onig_region_copy P_((OnigRegion* to, OnigRegion* from)); +ONIG_EXTERN +void onig_region_clear P_((OnigRegion* region)); +ONIG_EXTERN +int onig_region_resize P_((OnigRegion* region, int n)); +ONIG_EXTERN +int onig_region_set P_((OnigRegion* region, int at, int beg, int end)); +ONIG_EXTERN +int onig_name_to_group_numbers P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, int** nums)); +ONIG_EXTERN +int onig_name_to_backref_number P_((OnigRegex reg, const OnigUChar* name, const OnigUChar* name_end, OnigRegion *region)); +ONIG_EXTERN +int onig_foreach_name P_((OnigRegex reg, int (*func)(const OnigUChar*, const OnigUChar*,int,int*,OnigRegex,void*), void* arg)); +ONIG_EXTERN +int onig_number_of_names P_((OnigRegex reg)); +ONIG_EXTERN +int onig_number_of_captures P_((OnigRegex reg)); +ONIG_EXTERN +int onig_number_of_capture_histories P_((OnigRegex reg)); +ONIG_EXTERN +OnigCaptureTreeNode* onig_get_capture_tree P_((OnigRegion* region)); +ONIG_EXTERN +int onig_capture_tree_traverse P_((OnigRegion* region, int at, int(*callback_func)(int,int,int,int,int,void*), void* arg)); +ONIG_EXTERN +int onig_noname_group_capture_is_active P_((OnigRegex reg)); +ONIG_EXTERN +OnigEncoding onig_get_encoding P_((OnigRegex reg)); +ONIG_EXTERN +OnigOptionType onig_get_options P_((OnigRegex reg)); +ONIG_EXTERN +OnigCaseFoldType onig_get_case_fold_flag P_((OnigRegex reg)); +ONIG_EXTERN +OnigSyntaxType* onig_get_syntax P_((OnigRegex reg)); +ONIG_EXTERN +int onig_set_default_syntax P_((OnigSyntaxType* syntax)); +ONIG_EXTERN +void onig_copy_syntax P_((OnigSyntaxType* to, OnigSyntaxType* from)); +ONIG_EXTERN +unsigned int onig_get_syntax_op P_((OnigSyntaxType* syntax)); +ONIG_EXTERN +unsigned int onig_get_syntax_op2 P_((OnigSyntaxType* syntax)); +ONIG_EXTERN +unsigned int onig_get_syntax_behavior P_((OnigSyntaxType* syntax)); +ONIG_EXTERN +OnigOptionType onig_get_syntax_options P_((OnigSyntaxType* syntax)); +ONIG_EXTERN +void onig_set_syntax_op P_((OnigSyntaxType* syntax, unsigned int op)); +ONIG_EXTERN +void onig_set_syntax_op2 P_((OnigSyntaxType* syntax, unsigned int op2)); +ONIG_EXTERN +void onig_set_syntax_behavior P_((OnigSyntaxType* syntax, unsigned int behavior)); +ONIG_EXTERN +void onig_set_syntax_options P_((OnigSyntaxType* syntax, OnigOptionType options)); +ONIG_EXTERN +int onig_set_meta_char P_((OnigSyntaxType* syntax, unsigned int what, OnigCodePoint code)); +ONIG_EXTERN +void onig_copy_encoding P_((OnigEncoding to, OnigEncoding from)); +ONIG_EXTERN +OnigCaseFoldType onig_get_default_case_fold_flag P_((void)); +ONIG_EXTERN +int onig_set_default_case_fold_flag P_((OnigCaseFoldType case_fold_flag)); +ONIG_EXTERN +unsigned int onig_get_match_stack_limit_size P_((void)); +ONIG_EXTERN +int onig_set_match_stack_limit_size P_((unsigned int size)); +ONIG_EXTERN +int onig_end P_((void)); +ONIG_EXTERN +const char* onig_version P_((void)); +ONIG_EXTERN +const char* onig_copyright P_((void)); + +#ifdef __cplusplus +#if 0 +{ /* satisfy cc-mode */ +#endif +} +#endif + +#endif /* ONIGURUMA_H */ diff --git a/include/ruby/re.h b/include/ruby/re.h new file mode 100644 index 0000000000..ae6e0357b6 --- /dev/null +++ b/include/ruby/re.h @@ -0,0 +1,58 @@ +/********************************************************************** + + re.h - + + $Author$ + $Date$ + created at: Thu Sep 30 14:18:32 JST 1993 + + Copyright (C) 1993-2003 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_RE_H +#define RUBY_RE_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include +#include + +#include "ruby/regex.h" + +typedef struct re_pattern_buffer Regexp; + +struct RMatch { + struct RBasic basic; + VALUE str; + struct re_registers *regs; + VALUE regexp; /* RRegexp */ +}; + +#define RMATCH(obj) (R_CAST(RMatch)(obj)) + +VALUE rb_reg_regcomp(VALUE); +long rb_reg_search(VALUE, VALUE, long, long); +VALUE rb_reg_regsub(VALUE, VALUE, struct re_registers *, VALUE); +long rb_reg_adjust_startpos(VALUE, VALUE, long, long); +void rb_match_busy(VALUE); +VALUE rb_reg_quote(VALUE); + +RUBY_EXTERN int ruby_ignorecase; + +int rb_reg_mbclen2(unsigned int, VALUE); +#define mbclen2(c,re) rb_reg_mbclen2((c),(re)) + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_RE_H */ diff --git a/include/ruby/regex.h b/include/ruby/regex.h new file mode 100644 index 0000000000..118c37c480 --- /dev/null +++ b/include/ruby/regex.h @@ -0,0 +1,46 @@ +/********************************************************************** + + regex.h - + + $Author$ + $Date$ + + Copyright (C) 1993-2005 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef ONIGURUMA_REGEX_H +#define ONIGURUMA_REGEX_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#ifdef RUBY +#include "ruby/oniguruma.h" +#else +#include "oniguruma.h" +#endif + +#ifndef ONIG_RUBY_M17N + +ONIG_EXTERN OnigEncoding OnigEncDefaultCharEncoding; + +#undef ismbchar +#define ismbchar(c) (mbclen((c)) != 1) +#define mbclen(c) \ + ONIGENC_MBC_ENC_LEN(OnigEncDefaultCharEncoding, (UChar* )(&c)) + +#endif /* ifndef ONIG_RUBY_M17N */ + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* ONIGURUMA_REGEX_H */ diff --git a/include/ruby/ruby.h b/include/ruby/ruby.h new file mode 100644 index 0000000000..69aadf14c4 --- /dev/null +++ b/include/ruby/ruby.h @@ -0,0 +1,826 @@ +/********************************************************************** + + ruby.h - + + $Author$ + created at: Thu Jun 10 14:26:32 JST 1993 + + Copyright (C) 1993-2003 Yukihiro Matsumoto + Copyright (C) 2000 Network Applied Communication Laboratory, Inc. + Copyright (C) 2000 Information-technology Promotion Agency, Japan + +**********************************************************************/ + +#ifndef RUBY_H +#define RUBY_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include "ruby/config.h" +#ifdef RUBY_EXTCONF_H +#include RUBY_EXTCONF_H +#endif + +#define NORETURN_STYLE_NEW 1 +#ifndef NORETURN +# define NORETURN(x) x +#endif +#ifndef DEPRECATED +# define DEPRECATED(x) x +#endif +#ifndef NOINLINE +# define NOINLINE(x) x +#endif + +#ifdef __GNUC__ +#define PRINTF_ARGS(decl, string_index, first_to_check) \ + decl __attribute__((format(printf, string_index, first_to_check))) +#else +#define PRINTF_ARGS(decl, string_index, first_to_check) decl +#endif + +#ifdef HAVE_STDLIB_H +# include +#endif + +#ifdef HAVE_STRING_H +# include +#else +# include +#endif + +#ifdef HAVE_INTRINSICS_H +# include +#endif + +#include +#include + +#include "defines.h" + +/* need to include to use these macros */ +#ifndef ISPRINT +#define ISASCII(c) isascii((int)(unsigned char)(c)) +#undef ISPRINT +#define ISPRINT(c) (ISASCII(c) && isprint((int)(unsigned char)(c))) +#define ISSPACE(c) (ISASCII(c) && isspace((int)(unsigned char)(c))) +#define ISUPPER(c) (ISASCII(c) && isupper((int)(unsigned char)(c))) +#define ISLOWER(c) (ISASCII(c) && islower((int)(unsigned char)(c))) +#define ISALNUM(c) (ISASCII(c) && isalnum((int)(unsigned char)(c))) +#define ISALPHA(c) (ISASCII(c) && isalpha((int)(unsigned char)(c))) +#define ISDIGIT(c) (ISASCII(c) && isdigit((int)(unsigned char)(c))) +#define ISXDIGIT(c) (ISASCII(c) && isxdigit((int)(unsigned char)(c))) +#endif + +#if defined(HAVE_ALLOCA_H) +#include +#else +# ifdef _AIX +#pragma alloca +# endif +#endif + +#if defined(__VMS) +# pragma builtins +# define alloca __alloca +#endif + +#if SIZEOF_LONG == SIZEOF_VOIDP +typedef unsigned long VALUE; +typedef unsigned long ID; +# define SIGNED_VALUE long +# define SIZEOF_VALUE SIZEOF_LONG +#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP +typedef unsigned LONG_LONG VALUE; +typedef unsigned LONG_LONG ID; +# define SIGNED_VALUE LONG_LONG +# define LONG_LONG_VALUE 1 +# define SIZEOF_VALUE SIZEOF_LONG_LONG +#else +# error ---->> ruby requires sizeof(void*) == sizeof(long) to be compiled. <<---- +#endif + + +#ifdef __STDC__ +# include +#else +# ifndef LONG_MAX +# ifdef HAVE_LIMITS_H +# include +# else + /* assuming 32bit(2's compliment) long */ +# define LONG_MAX 2147483647 +# endif +# endif +# ifndef LONG_MIN +# define LONG_MIN (-LONG_MAX-1) +# endif +# ifndef CHAR_BIT +# define CHAR_BIT 8 +# endif +#endif + +#ifdef HAVE_LONG_LONG +# ifndef LLONG_MAX +# ifdef LONG_LONG_MAX +# define LLONG_MAX LONG_LONG_MAX +# else +# ifdef _I64_MAX +# define LLONG_MAX _I64_MAX +# else + /* assuming 64bit(2's complement) long long */ +# define LLONG_MAX 9223372036854775807LL +# endif +# endif +# endif +# ifndef LLONG_MIN +# ifdef LONG_LONG_MIN +# define LLONG_MIN LONG_LONG_MIN +# else +# ifdef _I64_MIN +# define LLONG_MIN _I64_MIN +# else +# define LLONG_MIN (-LLONG_MAX-1) +# endif +# endif +# endif +#endif + +#ifdef LONG_LONG_VALUE +# define FIXNUM_MAX (LLONG_MAX>>1) +# define FIXNUM_MIN RSHIFT((LONG_LONG)LLONG_MIN,1) +#else +# define FIXNUM_MAX (LONG_MAX>>1) +# define FIXNUM_MIN RSHIFT((long)LONG_MIN,1) +#endif + +#define FIXNUM_FLAG 0x01 +#define INT2FIX(i) ((VALUE)(((SIGNED_VALUE)(i))<<1 | FIXNUM_FLAG)) +#define LONG2FIX(i) INT2FIX(i) +#define rb_fix_new(v) INT2FIX(v) +VALUE rb_int2inum(SIGNED_VALUE); +#define INT2NUM(v) rb_int2inum(v) +#define LONG2NUM(v) INT2NUM(v) +#define rb_int_new(v) rb_int2inum(v) +VALUE rb_uint2inum(VALUE); +#define UINT2NUM(v) rb_uint2inum(v) +#define ULONG2NUM(v) UINT2NUM(v) +#define rb_uint_new(v) rb_uint2inum(v) + +#ifdef HAVE_LONG_LONG +VALUE rb_ll2inum(LONG_LONG); +#define LL2NUM(v) rb_ll2inum(v) +VALUE rb_ull2inum(unsigned LONG_LONG); +#define ULL2NUM(v) rb_ull2inum(v) +#endif + +#if SIZEOF_OFF_T > SIZEOF_LONG && defined(HAVE_LONG_LONG) +# define OFFT2NUM(v) LL2NUM(v) +#elif SIZEOF_OFF_T == SIZEOF_LONG +# define OFFT2NUM(v) LONG2NUM(v) +#else +# define OFFT2NUM(v) INT2NUM(v) +#endif + +#ifndef PIDT2NUM +#define PIDT2NUM(v) LONG2NUM(v) +#endif +#ifndef NUM2PIDT +#define NUM2PIDT(v) NUM2LONG(v) +#endif +#ifndef UIDT2NUM +#define UIDT2NUM(v) LONG2NUM(v) +#endif +#ifndef NUM2UIDT +#define NUM2UIDT(v) NUM2LONG(v) +#endif +#ifndef GIDT2NUM +#define GIDT2NUM(v) LONG2NUM(v) +#endif +#ifndef NUM2GIDT +#define NUM2GIDT(v) NUM2LONG(v) +#endif + +#define FIX2LONG(x) RSHIFT((SIGNED_VALUE)x,1) +#define FIX2ULONG(x) (((VALUE)(x))>>1) +#define FIXNUM_P(f) (((SIGNED_VALUE)(f))&FIXNUM_FLAG) +#define POSFIXABLE(f) ((f) <= FIXNUM_MAX) +#define NEGFIXABLE(f) ((f) >= FIXNUM_MIN) +#define FIXABLE(f) (POSFIXABLE(f) && NEGFIXABLE(f)) + +#define IMMEDIATE_MASK 0x03 +#define IMMEDIATE_P(x) ((VALUE)(x) & IMMEDIATE_MASK) + +#define SYMBOL_FLAG 0x0e +#define SYMBOL_P(x) (((VALUE)(x)&0xff)==SYMBOL_FLAG) +#define ID2SYM(x) ((VALUE)(((long)(x))<<8|SYMBOL_FLAG)) +#define SYM2ID(x) RSHIFT((unsigned long)x,8) + +/* special contants - i.e. non-zero and non-fixnum constants */ +#define Qfalse ((VALUE)0) +#define Qtrue ((VALUE)2) +#define Qnil ((VALUE)4) +#define Qundef ((VALUE)6) /* undefined value for placeholder */ + +#define RTEST(v) (((VALUE)(v) & ~Qnil) != 0) +#define NIL_P(v) ((VALUE)(v) == Qnil) + +#define CLASS_OF(v) rb_class_of((VALUE)(v)) + +#define T_NONE 0x00 + +#define T_NIL 0x01 +#define T_OBJECT 0x02 +#define T_CLASS 0x03 +#define T_ICLASS 0x04 +#define T_MODULE 0x05 +#define T_FLOAT 0x06 +#define T_STRING 0x07 +#define T_REGEXP 0x08 +#define T_ARRAY 0x09 +#define T_FIXNUM 0x0a +#define T_HASH 0x0b +#define T_STRUCT 0x0c +#define T_BIGNUM 0x0d +#define T_FILE 0x0e + +#define T_TRUE 0x10 +#define T_FALSE 0x11 +#define T_DATA 0x12 +#define T_MATCH 0x13 +#define T_SYMBOL 0x14 + +#define T_VALUES 0x1a +#define T_BLOCK 0x1b +#define T_UNDEF 0x1c +#define T_NODE 0x1f + +#define T_MASK 0x1f + +#define BUILTIN_TYPE(x) (((struct RBasic*)(x))->flags & T_MASK) + +#define TYPE(x) rb_type((VALUE)(x)) + +void rb_check_type(VALUE,int); +#define Check_Type(v,t) rb_check_type((VALUE)(v),t) + +VALUE rb_str_to_str(VALUE); +VALUE rb_string_value(volatile VALUE*); +char *rb_string_value_ptr(volatile VALUE*); +char *rb_string_value_cstr(volatile VALUE*); + +#define StringValue(v) rb_string_value(&(v)) +#define StringValuePtr(v) rb_string_value_ptr(&(v)) +#define StringValueCStr(v) rb_string_value_cstr(&(v)) + +void rb_check_safe_obj(VALUE); +void rb_check_safe_str(VALUE); +#define SafeStringValue(v) do {\ + StringValue(v);\ + rb_check_safe_obj(v);\ +} while (0) +/* obsolete macro - use SafeStringValue(v) */ +#define Check_SafeStr(v) rb_check_safe_str((VALUE)(v)) + +VALUE rb_get_path(VALUE); +#define FilePathValue(v) ((v) = rb_get_path(v)) + +void rb_secure(int); +int rb_safe_level(void); +void rb_set_safe_level(int); +void rb_set_safe_level_force(int); +void rb_secure_update(VALUE); + +VALUE rb_errinfo(void); +void rb_set_errinfo(VALUE); + +SIGNED_VALUE rb_num2long(VALUE); +VALUE rb_num2ulong(VALUE); +#define NUM2LONG(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2long((VALUE)x)) +#define NUM2ULONG(x) rb_num2ulong((VALUE)x) +#if SIZEOF_INT < SIZEOF_LONG +long rb_num2int(VALUE); +#define NUM2INT(x) (FIXNUM_P(x)?FIX2INT(x):rb_num2int((VALUE)x)) +long rb_fix2int(VALUE); +#define FIX2INT(x) rb_fix2int((VALUE)x) +unsigned long rb_num2uint(VALUE); +#define NUM2UINT(x) rb_num2uint(x) +unsigned long rb_fix2uint(VALUE); +#define FIX2UINT(x) rb_fix2uint(x) +#else +#define NUM2INT(x) ((int)NUM2LONG(x)) +#define NUM2UINT(x) ((unsigned int)NUM2ULONG(x)) +#define FIX2INT(x) ((int)FIX2LONG(x)) +#define FIX2UINT(x) ((unsigned int)FIX2ULONG(x)) +#endif + +#ifdef HAVE_LONG_LONG +LONG_LONG rb_num2ll(VALUE); +unsigned LONG_LONG rb_num2ull(VALUE); +# define NUM2LL(x) (FIXNUM_P(x)?FIX2LONG(x):rb_num2ll((VALUE)x)) +# define NUM2ULL(x) rb_num2ull((VALUE)x) +#endif + +#if defined(HAVE_LONG_LONG) && SIZEOF_OFF_T > SIZEOF_LONG +# define NUM2OFFT(x) ((off_t)NUM2LL(x)) +#else +# define NUM2OFFT(x) NUM2LONG(x) +#endif + +double rb_num2dbl(VALUE); +#define NUM2DBL(x) rb_num2dbl((VALUE)(x)) + +/* obsolete API - use StringValue() */ +char *rb_str2cstr(VALUE,long*); +/* obsolete API - use StringValuePtr() */ +#define STR2CSTR(x) rb_str2cstr((VALUE)(x),0) + +#define NUM2CHR(x) (((TYPE(x) == T_STRING)&&(RSTRING_LEN(x)>=1))?\ + RSTRING_PTR(x)[0]:(char)(NUM2INT(x)&0xff)) +#define CHR2FIX(x) INT2FIX((long)((x)&0xff)) + +VALUE rb_newobj(void); +#define NEWOBJ(obj,type) type *obj = (type*)rb_newobj() +#define OBJSETUP(obj,c,t) do {\ + RBASIC(obj)->flags = (t);\ + RBASIC(obj)->klass = (c);\ + if (rb_safe_level() >= 3) FL_SET(obj, FL_TAINT);\ +} while (0) +#define CLONESETUP(clone,obj) do {\ + OBJSETUP(clone,rb_singleton_class_clone((VALUE)obj),RBASIC(obj)->flags);\ + rb_singleton_class_attached(RBASIC(clone)->klass, (VALUE)clone);\ + if (FL_TEST(obj, FL_EXIVAR)) rb_copy_generic_ivar((VALUE)clone,(VALUE)obj);\ +} while (0) +#define DUPSETUP(dup,obj) do {\ + OBJSETUP(dup,rb_obj_class(obj),(RBASIC(obj)->flags)&(T_MASK|FL_EXIVAR|FL_TAINT));\ + if (FL_TEST(obj, FL_EXIVAR)) rb_copy_generic_ivar((VALUE)dup,(VALUE)obj);\ +} while (0) + +struct RBasic { + VALUE flags; + VALUE klass; +}; + +struct RObject { + struct RBasic basic; + struct st_table *iv_tbl; +}; + +struct RValues { + struct RBasic basic; + VALUE v1; + VALUE v2; + VALUE v3; +}; + +struct RClass { + struct RBasic basic; + struct st_table *iv_tbl; + struct st_table *m_tbl; + VALUE super; +}; + +struct RFloat { + struct RBasic basic; + double value; +}; + +#define ELTS_SHARED FL_USER2 + +#define RSTRING_EMBED_LEN_MAX ((sizeof(VALUE)*3)/sizeof(char)-1) +struct RString { + struct RBasic basic; + union { + struct { + long len; + char *ptr; + union { + long capa; + VALUE shared; + } aux; + } heap; + char ary[RSTRING_EMBED_LEN_MAX]; + } as; +}; +#define RSTRING_NOEMBED FL_USER1 +#define RSTRING_EMBED_LEN_MASK (FL_USER2|FL_USER3|FL_USER4|FL_USER5|FL_USER6) +#define RSTRING_EMBED_LEN_SHIFT (FL_USHIFT+2) +#define RSTRING_LEN(str) \ + (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ + (long)((RBASIC(str)->flags >> RSTRING_EMBED_LEN_SHIFT) & \ + (RSTRING_EMBED_LEN_MASK >> RSTRING_EMBED_LEN_SHIFT)) : \ + RSTRING(str)->as.heap.len) +#define RSTRING_PTR(str) \ + (!(RBASIC(str)->flags & RSTRING_NOEMBED) ? \ + RSTRING(str)->as.ary : \ + RSTRING(str)->as.heap.ptr) + +struct RArray { + struct RBasic basic; + long len; + union { + long capa; + VALUE shared; + } aux; + VALUE *ptr; +}; +#define RARRAY_LEN(a) RARRAY(a)->len +#define RARRAY_PTR(a) RARRAY(a)->ptr + +struct RRegexp { + struct RBasic basic; + struct re_pattern_buffer *ptr; + long len; + char *str; +}; + +struct RHash { + struct RBasic basic; + struct st_table *tbl; + int iter_lev; + VALUE ifnone; +}; + +struct RFile { + struct RBasic basic; + struct rb_io_t *fptr; +}; + +struct RData { + struct RBasic basic; + void (*dmark)(void*); + void (*dfree)(void*); + void *data; +}; + +#define DATA_PTR(dta) (RDATA(dta)->data) + +/* +#define RUBY_DATA_FUNC(func) ((void (*)(void*))func) +*/ +typedef void (*RUBY_DATA_FUNC)(void*); + +VALUE rb_data_object_alloc(VALUE,void*,RUBY_DATA_FUNC,RUBY_DATA_FUNC); + +#define Data_Wrap_Struct(klass,mark,free,sval)\ + rb_data_object_alloc(klass,sval,(RUBY_DATA_FUNC)mark,(RUBY_DATA_FUNC)free) + +#define Data_Make_Struct(klass,type,mark,free,sval) (\ + sval = ALLOC(type),\ + memset(sval, 0, sizeof(type)),\ + Data_Wrap_Struct(klass,mark,free,sval)\ +) + +#define Data_Get_Struct(obj,type,sval) do {\ + Check_Type(obj, T_DATA); \ + sval = (type*)DATA_PTR(obj);\ +} while (0) + +#define RSTRUCT_EMBED_LEN_MAX 3 +struct RStruct { + struct RBasic basic; + union { + struct { + long len; + VALUE *ptr; + } heap; + VALUE ary[RSTRUCT_EMBED_LEN_MAX]; + } as; +}; +#define RSTRUCT_EMBED_LEN_MASK (FL_USER2|FL_USER1) +#define RSTRUCT_EMBED_LEN_SHIFT (FL_USHIFT+1) +#define RSTRUCT_LEN(st) \ + ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ + (long)((RBASIC(st)->flags >> RSTRUCT_EMBED_LEN_SHIFT) & \ + (RSTRUCT_EMBED_LEN_MASK >> RSTRUCT_EMBED_LEN_SHIFT)) : \ + RSTRUCT(st)->as.heap.len) +#define RSTRUCT_PTR(st) \ + ((RBASIC(st)->flags & RSTRUCT_EMBED_LEN_MASK) ? \ + RSTRUCT(st)->as.ary : \ + RSTRUCT(st)->as.heap.ptr) + +struct RBignum { + struct RBasic basic; + char sign; + long len; + void *digits; +}; + +#define R_CAST(st) (struct st*) +#define RBASIC(obj) (R_CAST(RBasic)(obj)) +#define ROBJECT(obj) (R_CAST(RObject)(obj)) +#define RCLASS(obj) (R_CAST(RClass)(obj)) +#define RMODULE(obj) RCLASS(obj) +#define RFLOAT(obj) (R_CAST(RFloat)(obj)) +#define RSTRING(obj) (R_CAST(RString)(obj)) +#define RREGEXP(obj) (R_CAST(RRegexp)(obj)) +#define RARRAY(obj) (R_CAST(RArray)(obj)) +#define RHASH(obj) (R_CAST(RHash)(obj)) +#define RDATA(obj) (R_CAST(RData)(obj)) +#define RSTRUCT(obj) (R_CAST(RStruct)(obj)) +#define RBIGNUM(obj) (R_CAST(RBignum)(obj)) +#define RFILE(obj) (R_CAST(RFile)(obj)) +#define RVALUES(obj) (R_CAST(RValues)(obj)) + +#define FL_SINGLETON FL_USER0 +#define FL_MARK (1<<5) +#define FL_RESERVED (1<<6) /* will be used in the future GC */ +#define FL_FINALIZE (1<<7) +#define FL_TAINT (1<<8) +#define FL_EXIVAR (1<<9) +#define FL_FREEZE (1<<10) + +#define FL_USHIFT 11 + +#define FL_USER0 (1<<(FL_USHIFT+0)) +#define FL_USER1 (1<<(FL_USHIFT+1)) +#define FL_USER2 (1<<(FL_USHIFT+2)) +#define FL_USER3 (1<<(FL_USHIFT+3)) +#define FL_USER4 (1<<(FL_USHIFT+4)) +#define FL_USER5 (1<<(FL_USHIFT+5)) +#define FL_USER6 (1<<(FL_USHIFT+6)) +#define FL_USER7 (1<<(FL_USHIFT+7)) + +#define SPECIAL_CONST_P(x) (IMMEDIATE_P(x) || !RTEST(x)) + +#define FL_ABLE(x) (!SPECIAL_CONST_P(x) && BUILTIN_TYPE(x) != T_NODE) +#define FL_TEST(x,f) (FL_ABLE(x)?(RBASIC(x)->flags&(f)):0) +#define FL_ANY(x,f) FL_TEST(x,f) +#define FL_ALL(x,f) (FL_TEST(x,f) == (f)) +#define FL_SET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags |= (f);} while (0) +#define FL_UNSET(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags &= ~(f);} while (0) +#define FL_REVERSE(x,f) do {if (FL_ABLE(x)) RBASIC(x)->flags ^= (f);} while (0) + +#define OBJ_TAINTED(x) FL_TEST((x), FL_TAINT) +#define OBJ_TAINT(x) FL_SET((x), FL_TAINT) +#define OBJ_INFECT(x,s) do {if (FL_ABLE(x) && FL_ABLE(s)) RBASIC(x)->flags |= RBASIC(s)->flags & FL_TAINT;} while (0) + +#define OBJ_FROZEN(x) FL_TEST((x), FL_FREEZE) +#define OBJ_FREEZE(x) FL_SET((x), FL_FREEZE) + +#define ALLOC_N(type,n) (type*)xmalloc2((n),sizeof(type)) +#define ALLOC(type) (type*)xmalloc(sizeof(type)) +#define REALLOC_N(var,type,n) (var)=(type*)xrealloc2((char*)(var),(n),sizeof(type)) + +#define ALLOCA_N(type,n) (type*)alloca(sizeof(type)*(n)) + +#define MEMZERO(p,type,n) memset((p), 0, sizeof(type)*(n)) +#define MEMCPY(p1,p2,type,n) memcpy((p1), (p2), sizeof(type)*(n)) +#define MEMMOVE(p1,p2,type,n) memmove((p1), (p2), sizeof(type)*(n)) +#define MEMCMP(p1,p2,type,n) memcmp((p1), (p2), sizeof(type)*(n)) + +void rb_obj_infect(VALUE,VALUE); + +typedef int ruby_glob_func(const char*,VALUE); +void rb_glob(const char*,void(*)(const char*,VALUE),VALUE); +int ruby_glob(const char*,int,ruby_glob_func*,VALUE); +int ruby_brace_expand(const char*,int,ruby_glob_func*,VALUE); +int ruby_brace_glob(const char*,int,ruby_glob_func*,VALUE); + +VALUE rb_define_class(const char*,VALUE); +VALUE rb_define_module(const char*); +VALUE rb_define_class_under(VALUE, const char*, VALUE); +VALUE rb_define_module_under(VALUE, const char*); + +void rb_include_module(VALUE,VALUE); +void rb_extend_object(VALUE,VALUE); + +void rb_define_variable(const char*,VALUE*); +void rb_define_virtual_variable(const char*,VALUE(*)(ANYARGS),void(*)(ANYARGS)); +void rb_define_hooked_variable(const char*,VALUE*,VALUE(*)(ANYARGS),void(*)(ANYARGS)); +void rb_define_readonly_variable(const char*,VALUE*); +void rb_define_const(VALUE,const char*,VALUE); +void rb_define_global_const(const char*,VALUE); + +#define RUBY_METHOD_FUNC(func) ((VALUE (*)(ANYARGS))func) +void rb_define_method(VALUE,const char*,VALUE(*)(ANYARGS),int); +void rb_define_module_function(VALUE,const char*,VALUE(*)(ANYARGS),int); +void rb_define_global_function(const char*,VALUE(*)(ANYARGS),int); + +void rb_undef_method(VALUE,const char*); +void rb_define_alias(VALUE,const char*,const char*); +void rb_define_attr(VALUE,const char*,int,int); + +void rb_global_variable(VALUE*); +void rb_register_mark_object(VALUE); +void rb_gc_register_address(VALUE*); +void rb_gc_unregister_address(VALUE*); + +ID rb_intern(const char*); +ID rb_intern2(const char*, long); +const char *rb_id2name(ID); +ID rb_to_id(VALUE); +VALUE rb_id2str(ID); + +char *rb_class2name(VALUE); +char *rb_obj_classname(VALUE); + +void rb_p(VALUE); + +VALUE rb_eval_string(const char*); +VALUE rb_eval_string_protect(const char*, int*); +VALUE rb_eval_string_wrap(const char*, int*); +VALUE rb_funcall(VALUE, ID, int, ...); +VALUE rb_funcall2(VALUE, ID, int, const VALUE*); +VALUE rb_funcall3(VALUE, ID, int, const VALUE*); +int rb_scan_args(int, const VALUE*, const char*, ...); +VALUE rb_call_super(int, const VALUE*); + +VALUE rb_gv_set(const char*, VALUE); +VALUE rb_gv_get(const char*); +VALUE rb_iv_get(VALUE, const char*); +VALUE rb_iv_set(VALUE, const char*, VALUE); + +VALUE rb_equal(VALUE,VALUE); + +RUBY_EXTERN VALUE ruby_verbose, ruby_debug; + +PRINTF_ARGS(NORETURN(void rb_raise(VALUE, const char*, ...)), 2, 3); +PRINTF_ARGS(NORETURN(void rb_fatal(const char*, ...)), 1, 2); +PRINTF_ARGS(NORETURN(void rb_bug(const char*, ...)), 1, 2); +NORETURN(void rb_sys_fail(const char*)); +NORETURN(void rb_iter_break(void)); +NORETURN(void rb_exit(int)); +NORETURN(void rb_notimplement(void)); + +/* reports if `-w' specified */ +PRINTF_ARGS(void rb_warning(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_compile_warning(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_sys_warning(const char*, ...), 1, 2); +/* reports always */ +PRINTF_ARGS(void rb_warn(const char*, ...), 1, 2); +PRINTF_ARGS(void rb_compile_warn(const char*, ...), 1, 2); + +VALUE rb_each(VALUE); +VALUE rb_yield(VALUE); +VALUE rb_yield_values(int n, ...); +VALUE rb_yield_splat(VALUE); +int rb_block_given_p(void); +void rb_need_block(void); +VALUE rb_iterate(VALUE(*)(VALUE),VALUE,VALUE(*)(ANYARGS),VALUE); +VALUE rb_block_call(VALUE,ID,int,VALUE*,VALUE(*)(ANYARGS),VALUE); +VALUE rb_rescue(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE); +VALUE rb_rescue2(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE,...); +VALUE rb_ensure(VALUE(*)(ANYARGS),VALUE,VALUE(*)(ANYARGS),VALUE); +VALUE rb_catch(const char*,VALUE(*)(ANYARGS),VALUE); +NORETURN(void rb_throw(const char*,VALUE)); + +VALUE rb_require(const char*); + +#ifdef __ia64 +void ruby_init_stack(VALUE*, void*); +#define RUBY_INIT_STACK \ + VALUE variable_in_this_stack_frame; \ + ruby_init_stack(&variable_in_this_stack_frame, rb_ia64_bsp()); +#else +void ruby_init_stack(VALUE*); +#define RUBY_INIT_STACK \ + VALUE variable_in_this_stack_frame; \ + ruby_init_stack(&variable_in_this_stack_frame); +#endif +void ruby_init(void); +void ruby_options(int, char**); +NORETURN(void ruby_run(void)); + +RUBY_EXTERN VALUE rb_mKernel; +RUBY_EXTERN VALUE rb_mComparable; +RUBY_EXTERN VALUE rb_mEnumerable; +RUBY_EXTERN VALUE rb_mPrecision; +RUBY_EXTERN VALUE rb_mErrno; +RUBY_EXTERN VALUE rb_mFileTest; +RUBY_EXTERN VALUE rb_mGC; +RUBY_EXTERN VALUE rb_mMath; +RUBY_EXTERN VALUE rb_mProcess; + +RUBY_EXTERN VALUE rb_cBasicObject; +RUBY_EXTERN VALUE rb_cObject; +RUBY_EXTERN VALUE rb_cArray; +RUBY_EXTERN VALUE rb_cBignum; +RUBY_EXTERN VALUE rb_cBinding; +RUBY_EXTERN VALUE rb_cClass; +RUBY_EXTERN VALUE rb_cCont; +RUBY_EXTERN VALUE rb_cDir; +RUBY_EXTERN VALUE rb_cData; +RUBY_EXTERN VALUE rb_cFalseClass; +RUBY_EXTERN VALUE rb_cFile; +RUBY_EXTERN VALUE rb_cFixnum; +RUBY_EXTERN VALUE rb_cFloat; +RUBY_EXTERN VALUE rb_cHash; +RUBY_EXTERN VALUE rb_cInteger; +RUBY_EXTERN VALUE rb_cIO; +RUBY_EXTERN VALUE rb_cMatch; +RUBY_EXTERN VALUE rb_cMethod; +RUBY_EXTERN VALUE rb_cModule; +RUBY_EXTERN VALUE rb_cNameErrorMesg; +RUBY_EXTERN VALUE rb_cNilClass; +RUBY_EXTERN VALUE rb_cNumeric; +RUBY_EXTERN VALUE rb_cProc; +RUBY_EXTERN VALUE rb_cRange; +RUBY_EXTERN VALUE rb_cRegexp; +RUBY_EXTERN VALUE rb_cStat; +RUBY_EXTERN VALUE rb_cString; +RUBY_EXTERN VALUE rb_cStruct; +RUBY_EXTERN VALUE rb_cSymbol; +RUBY_EXTERN VALUE rb_cThread; +RUBY_EXTERN VALUE rb_cTime; +RUBY_EXTERN VALUE rb_cTrueClass; +RUBY_EXTERN VALUE rb_cUnboundMethod; +RUBY_EXTERN VALUE rb_cISeq; +RUBY_EXTERN VALUE rb_cVM; +RUBY_EXTERN VALUE rb_cEnv; + +RUBY_EXTERN VALUE rb_eException; +RUBY_EXTERN VALUE rb_eStandardError; +RUBY_EXTERN VALUE rb_eSystemExit; +RUBY_EXTERN VALUE rb_eInterrupt; +RUBY_EXTERN VALUE rb_eSignal; +RUBY_EXTERN VALUE rb_eFatal; +RUBY_EXTERN VALUE rb_eArgError; +RUBY_EXTERN VALUE rb_eEOFError; +RUBY_EXTERN VALUE rb_eIndexError; +RUBY_EXTERN VALUE rb_eKeyError; +RUBY_EXTERN VALUE rb_eRangeError; +RUBY_EXTERN VALUE rb_eIOError; +RUBY_EXTERN VALUE rb_eRuntimeError; +RUBY_EXTERN VALUE rb_eSecurityError; +RUBY_EXTERN VALUE rb_eSystemCallError; +RUBY_EXTERN VALUE rb_eThreadError; +RUBY_EXTERN VALUE rb_eTypeError; +RUBY_EXTERN VALUE rb_eZeroDivError; +RUBY_EXTERN VALUE rb_eNotImpError; +RUBY_EXTERN VALUE rb_eNoMemError; +RUBY_EXTERN VALUE rb_eNoMethodError; +RUBY_EXTERN VALUE rb_eFloatDomainError; +RUBY_EXTERN VALUE rb_eLocalJumpError; +RUBY_EXTERN VALUE rb_eSysStackError; +RUBY_EXTERN VALUE rb_eRegexpError; + +RUBY_EXTERN VALUE rb_eScriptError; +RUBY_EXTERN VALUE rb_eNameError; +RUBY_EXTERN VALUE rb_eSyntaxError; +RUBY_EXTERN VALUE rb_eLoadError; + +RUBY_EXTERN VALUE rb_stdin, rb_stdout, rb_stderr; + +static inline VALUE +rb_class_of(VALUE obj) +{ + if (IMMEDIATE_P(obj)) { + if (FIXNUM_P(obj)) return rb_cFixnum; + if (obj == Qtrue) return rb_cTrueClass; + if (SYMBOL_P(obj)) return rb_cSymbol; + } + else if (!RTEST(obj)) { + if (obj == Qnil) return rb_cNilClass; + if (obj == Qfalse) return rb_cFalseClass; + } + return RBASIC(obj)->klass; +} + +static inline int +rb_type(VALUE obj) +{ + if (IMMEDIATE_P(obj)) { + if (FIXNUM_P(obj)) return T_FIXNUM; + if (obj == Qtrue) return T_TRUE; + if (SYMBOL_P(obj)) return T_SYMBOL; + if (obj == Qundef) return T_UNDEF; + } + else if (!RTEST(obj)) { + if (obj == Qnil) return T_NIL; + if (obj == Qfalse) return T_FALSE; + } + return BUILTIN_TYPE(obj); +} + +static inline int +rb_special_const_p(VALUE obj) +{ + if (SPECIAL_CONST_P(obj)) return Qtrue; + return Qfalse; +} + +#include "ruby/missing.h" +#include "ruby/intern.h" + +#if defined(EXTLIB) && defined(USE_DLN_A_OUT) +/* hook for external modules */ +static char *dln_libs_to_be_linked[] = { EXTLIB, 0 }; +#endif + +#define RUBY_VM 1 /* YARV */ +#define HAVE_NATIVETHREAD + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_H */ diff --git a/include/ruby/signal.h b/include/ruby/signal.h new file mode 100644 index 0000000000..29ffcd9f11 --- /dev/null +++ b/include/ruby/signal.h @@ -0,0 +1,93 @@ +/********************************************************************** + + rubysig.h - + + $Author$ + $Date$ + created at: Wed Aug 16 01:15:38 JST 1995 + + Copyright (C) 1993-2003 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBYSIG_H +#define RUBYSIG_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#include + +#ifdef _WIN32 +typedef LONG rb_atomic_t; + +# define ATOMIC_TEST(var) InterlockedExchange(&(var), 0) +# define ATOMIC_SET(var, val) InterlockedExchange(&(var), (val)) +# define ATOMIC_INC(var) InterlockedIncrement(&(var)) +# define ATOMIC_DEC(var) InterlockedDecrement(&(var)) + +/* Windows doesn't allow interrupt while system calls */ +# define TRAP_BEG do {\ + rb_atomic_t trap_immediate = ATOMIC_SET(rb_trap_immediate, 1) + +# define TRAP_END\ + ATOMIC_SET(rb_trap_immediate, trap_immediate);\ +} while (0) + +# define RUBY_CRITICAL(statements) do {\ + rb_atomic_t trap_immediate = ATOMIC_SET(rb_trap_immediate, 0);\ + statements;\ + ATOMIC_SET(rb_trap_immediate, trap_immediate);\ +} while (0) +#else +typedef int rb_atomic_t; + +# define ATOMIC_TEST(var) ((var) ? ((var) = 0, 1) : 0) +# define ATOMIC_SET(var, val) ((var) = (val)) +# define ATOMIC_INC(var) (++(var)) +# define ATOMIC_DEC(var) (--(var)) + +# define TRAP_BEG do {\ + int trap_immediate = rb_trap_immediate;\ + rb_trap_immediate = 1 + +# define TRAP_END \ + rb_trap_immediate = trap_immediate;\ +} while (0) + +# define RUBY_CRITICAL(statements) do {\ + int trap_immediate = rb_trap_immediate;\ + rb_trap_immediate = 0;\ + statements;\ + rb_trap_immediate = trap_immediate;\ +} while (0) +#endif +RUBY_EXTERN rb_atomic_t rb_trap_immediate; + +RUBY_EXTERN int rb_prohibit_interrupt; +#define DEFER_INTS (rb_prohibit_interrupt++) +#define ALLOW_INTS do {\ + rb_prohibit_interrupt--;\ +} while (0) +#define ENABLE_INTS (rb_prohibit_interrupt--) + +VALUE rb_with_disable_interrupt(VALUE(*)(ANYARGS),VALUE); + +RUBY_EXTERN rb_atomic_t rb_trap_pending; +void rb_trap_restore_mask(void); + +RUBY_EXTERN int rb_thread_critical; +void rb_thread_schedule(void); + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBYSIG_H */ diff --git a/include/ruby/st.h b/include/ruby/st.h new file mode 100644 index 0000000000..d6d4479b3e --- /dev/null +++ b/include/ruby/st.h @@ -0,0 +1,79 @@ +/* This is a public domain general purpose hash table package written by Peter Moore @ UCB. */ + +/* @(#) st.h 5.1 89/12/14 */ + +#ifndef RUBY_ST_H +#define RUBY_ST_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#if SIZEOF_LONG == SIZEOF_VOIDP +typedef unsigned long st_data_t; +#elif SIZEOF_LONG_LONG == SIZEOF_VOIDP +typedef unsigned LONG_LONG st_data_t; +#else +# error ---->> st.c requires sizeof(void*) == sizeof(long) to be compiled. <<--- +- +#endif +#define ST_DATA_T_DEFINED + +typedef struct st_table st_table; + +struct st_hash_type { + int (*compare)(); + int (*hash)(); +}; + +struct st_table { + struct st_hash_type *type; + int num_bins; + int num_entries; + struct st_table_entry **bins; +}; + +#define st_is_member(table,key) st_lookup(table,key,(st_data_t *)0) + +enum st_retval {ST_CONTINUE, ST_STOP, ST_DELETE, ST_CHECK}; + +#ifndef _ +# define _(args) args +#endif +#ifndef ANYARGS +# ifdef __cplusplus +# define ANYARGS ... +# else +# define ANYARGS +# endif +#endif + +st_table *st_init_table(struct st_hash_type *); +st_table *st_init_table_with_size(struct st_hash_type *, int); +st_table *st_init_numtable(void); +st_table *st_init_numtable_with_size(int); +st_table *st_init_strtable(void); +st_table *st_init_strtable_with_size(int); +int st_delete(st_table *, st_data_t *, st_data_t *); +int st_delete_safe(st_table *, st_data_t *, st_data_t *, st_data_t); +int st_insert(st_table *, st_data_t, st_data_t); +int st_lookup(st_table *, st_data_t, st_data_t *); +int st_foreach(st_table *, int (*)(ANYARGS), st_data_t); +void st_add_direct(st_table *, st_data_t, st_data_t); +void st_free_table(st_table *); +void st_cleanup_safe(st_table *, st_data_t); +st_table *st_copy(st_table *); +int st_numcmp(long, long); +int st_numhash(long); + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_ST_H */ diff --git a/include/ruby/util.h b/include/ruby/util.h new file mode 100644 index 0000000000..8437872479 --- /dev/null +++ b/include/ruby/util.h @@ -0,0 +1,81 @@ +/********************************************************************** + + util.h - + + $Author$ + $Date$ + created at: Thu Mar 9 11:55:53 JST 1995 + + Copyright (C) 1993-2003 Yukihiro Matsumoto + +**********************************************************************/ + +#ifndef RUBY_UTIL_H +#define RUBY_UTIL_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +#ifndef _ +#ifdef __cplusplus +# ifndef HAVE_PROTOTYPES +# define HAVE_PROTOTYPES 1 +# endif +# ifndef HAVE_STDARG_PROTOTYPES +# define HAVE_STDARG_PROTOTYPES 1 +# endif +#endif +#ifdef HAVE_PROTOTYPES +# define _(args) args +#else +# define _(args) () +#endif +#ifdef HAVE_STDARG_PROTOTYPES +# define __(args) args +#else +# define __(args) () +#endif +#endif + +#define scan_oct ruby_scan_oct +unsigned long ruby_scan_oct(const char *, int, int *); +#define scan_hex ruby_scan_hex +unsigned long ruby_scan_hex(const char *, int, int *); + +#if defined(MSDOS) || defined(__CYGWIN32__) || defined(_WIN32) +void ruby_add_suffix(VALUE str, const char *suffix); +#endif + +void ruby_qsort(void *, const int, const int, + int (*)(const void *, const void *, void *), void *); + +void ruby_setenv(const char *, const char *); +void ruby_unsetenv(const char *); +#undef setenv +#undef unsetenv +#define setenv(name,val) ruby_setenv(name,val) +#define unsetenv(name,val) ruby_unsetenv(name); + +char *ruby_strdup(const char *); +#undef strdup +#define strdup(s) ruby_strdup(s) + +char *ruby_getcwd(void); +#define my_getcwd() ruby_getcwd() + +double ruby_strtod(const char *, char **); +#undef strtod +#define strtod(s,e) ruby_strtod(s,e) + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_UTIL_H */ diff --git a/include/ruby/win32.h b/include/ruby/win32.h new file mode 100644 index 0000000000..450cb32853 --- /dev/null +++ b/include/ruby/win32.h @@ -0,0 +1,544 @@ +#ifndef RUBY_WIN32_H +#define RUBY_WIN32_H 1 + +#if defined(__cplusplus) +extern "C" { +#if 0 +} /* satisfy cc-mode */ +#endif +#endif + +/* + * Copyright (c) 1993, Intergraph Corporation + * + * You may distribute under the terms of either the GNU General Public + * License or the Artistic License, as specified in the perl README file. + * + */ + +// +// Definitions for NT port of Perl +// + + +// +// Ok now we can include the normal include files. +// + +// #include conflict with varargs.h? +#if !defined(WSAAPI) +#include +#endif + +#define NT 1 /* deprecated */ + +#ifdef _WIN32_WCE +#undef CharNext +#define CharNext CharNextA +#endif + +// +// We're not using Microsoft's "extensions" to C for +// Structured Exception Handling (SEH) so we can nuke these +// +#undef try +#undef except +#undef finally +#undef leave + +#if defined(__cplusplus) +extern "C++" { +#endif + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#ifdef HAVE_SYS_UTIME_H +# include +#else +# include +#endif +#include +#include + +#if defined(__cplusplus) +} +#endif + +#ifdef _M_IX86 +# define WIN95 1 +#else +# undef WIN95 +#endif + +#ifdef WIN95 +extern DWORD rb_w32_osid(void); +#define rb_w32_iswinnt() (rb_w32_osid() == VER_PLATFORM_WIN32_NT) +#define rb_w32_iswin95() (rb_w32_osid() == VER_PLATFORM_WIN32_WINDOWS) +#else +#define rb_w32_iswinnt() TRUE +#define rb_w32_iswin95() FALSE +#endif + +#define WNOHANG -1 + +#undef getc +#undef putc +#undef fgetc +#undef fputc +#undef getchar +#undef putchar +#undef fgetchar +#undef fputchar +#undef utime +#undef lseek +#undef fstat +#define getc(_stream) rb_w32_getc(_stream) +#define getchar() rb_w32_getc(stdin) +#define putc(_c, _stream) rb_w32_putc(_c, _stream) +#define putchar(_c) rb_w32_putc(_c, stdout) +#ifdef RUBY_EXPORT +#define fgetc(_stream) getc(_stream) +#define fputc(_c, _stream) putc(_c, _stream) +#define fgetchar() getchar() +#define fputchar(_c) putchar(_c) +#define utime(_p, _t) rb_w32_utime(_p, _t) +#define lseek(_f, _o, _w) _lseeki64(_f, _o, _w) + +#define pipe(p) _pipe(p, 2048L, O_BINARY) +#define close(h) rb_w32_close(h) +#define fclose(f) rb_w32_fclose(f) +#define read(f, b, s) rb_w32_read(f, b, s) +#define write(f, b, s) rb_w32_write(f, b, s) +#define getpid() rb_w32_getpid() +#define sleep(x) rb_w32_Sleep((x)*1000) +#define Sleep(msec) (void)rb_w32_Sleep(msec) +#define fstat(fd,st) _fstati64(fd,st) +#ifdef __BORLANDC__ +#define creat(p, m) _creat(p, m) +#define eof() _eof() +#define filelength(h) _filelength(h) +#define mktemp(t) _mktemp(t) +#define tell(h) _tell(h) +#define _open _sopen +#define sopen _sopen +#define _fstati64(fd,st) rb_w32_fstati64(fd,st) +#undef fopen +#define fopen(p, m) rb_w32_fopen(p, m) +#undef fdopen +#define fdopen(h, m) rb_w32_fdopen(h, m) +#undef fsopen +#define fsopen(p, m, sh) rb_w32_fsopen(p, m, sh) +#endif + +#undef execv +#define execv(path,argv) rb_w32_aspawn(P_OVERLAY,path,argv) +#if !defined(__BORLANDC__) && !defined(_WIN32_WCE) +#undef isatty +#define isatty(h) rb_w32_isatty(h) +#endif + +#undef mkdir +#define mkdir(p, m) rb_w32_mkdir(p, m) +#undef rmdir +#define rmdir(p) rb_w32_rmdir(p) +#undef unlink +#define unlink(p) rb_w32_unlink(p) +#endif + +#if SIZEOF_OFF_T == 8 +#define off_t __int64 +#define stat stati64 +#if defined(__BORLANDC__) +#define stati64(path, st) rb_w32_stati64(path, st) +#elif !defined(_MSC_VER) || _MSC_VER < 1400 +#define stati64 _stati64 +#define _stati64(path, st) rb_w32_stati64(path, st) +#else +#define stati64 _stat64 +#define _stat64(path, st) rb_w32_stati64(path, st) +#endif +#else +#define stat(path,st) rb_w32_stat(path,st) +#define fstat(fd,st) rb_w32_fstat(fd,st) +extern int rb_w32_stat(const char *, struct stat *); +extern int rb_w32_fstat(int, struct stat *); +#endif + +#define strcasecmp(s1, s2) stricmp(s1, s2) +#define strncasecmp(s1, s2, n) strnicmp(s1, s2, n) +#define fsync(h) _commit(h) + +#ifdef __MINGW32__ +struct timezone { + int tz_minuteswest; + int tz_dsttime; +}; +#undef isascii +#define isascii __isascii +#endif +extern void NtInitialize(int *, char ***); +extern int rb_w32_cmdvector(const char *, char ***); +extern rb_pid_t rb_w32_pipe_exec(const char *, const char *, int, int *); +extern int flock(int fd, int oper); +extern int rb_w32_is_socket(int); +extern int WSAAPI rb_w32_accept(int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_bind(int, const struct sockaddr *, int); +extern int WSAAPI rb_w32_connect(int, const struct sockaddr *, int); +extern void rb_w32_fdset(int, fd_set*); +extern void rb_w32_fdclr(int, fd_set*); +extern int rb_w32_fdisset(int, fd_set*); +extern int WSAAPI rb_w32_select(int, fd_set *, fd_set *, fd_set *, struct timeval *); +extern int WSAAPI rb_w32_getpeername(int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_getsockname(int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_getsockopt(int, int, int, char *, int *); +extern int WSAAPI rb_w32_ioctlsocket(int, long, u_long *); +extern int WSAAPI rb_w32_listen(int, int); +extern int WSAAPI rb_w32_recv(int, char *, int, int); +extern int WSAAPI rb_w32_recvfrom(int, char *, int, int, struct sockaddr *, int *); +extern int WSAAPI rb_w32_send(int, const char *, int, int); +extern int WSAAPI rb_w32_sendto(int, const char *, int, int, const struct sockaddr *, int); +extern int WSAAPI rb_w32_setsockopt(int, int, int, const char *, int); +extern int WSAAPI rb_w32_shutdown(int, int); +extern int WSAAPI rb_w32_socket(int, int, int); +extern SOCKET rb_w32_get_osfhandle(int); +extern struct hostent *WSAAPI rb_w32_gethostbyaddr(const char *, int, int); +extern struct hostent *WSAAPI rb_w32_gethostbyname(const char *); +extern int WSAAPI rb_w32_gethostname(char *, int); +extern struct protoent *WSAAPI rb_w32_getprotobyname(const char *); +extern struct protoent *WSAAPI rb_w32_getprotobynumber(int); +extern struct servent *WSAAPI rb_w32_getservbyname(const char *, const char *); +extern struct servent *WSAAPI rb_w32_getservbyport(int, const char *); +extern int rb_w32_socketpair(int, int, int, int *); +extern char * rb_w32_getenv(const char *); +extern int rb_w32_rename(const char *, const char *); +extern char **rb_w32_get_environ(void); +extern void rb_w32_free_environ(char **); + +#define vsnprintf(s,n,f,l) rb_w32_vsnprintf(s,n,f,l) +#define snprintf rb_w32_snprintf +extern int rb_w32_vsnprintf(char *, size_t, const char *, va_list); +extern int rb_w32_snprintf(char *, size_t, const char *, ...); + +extern int chown(const char *, int, int); +extern int link(const char *, const char *); +extern int gettimeofday(struct timeval *, struct timezone *); +extern rb_pid_t waitpid (rb_pid_t, int *, int); +extern int rb_w32_argv_size(char *const *); +extern char *rb_w32_join_argv(char *, char *const *); +extern rb_pid_t rb_w32_spawn(int, const char *, const char*); +extern rb_pid_t rb_w32_aspawn(int, const char *, char *const *); +extern int kill(int, int); +extern int fcntl(int, int, ...); +extern rb_pid_t rb_w32_getpid(void); +#if !defined(__BORLANDC__) && !defined(_WIN32_WCE) +extern int rb_w32_isatty(int); +#endif +extern int rb_w32_mkdir(const char *, int); +extern int rb_w32_rmdir(const char *); +extern int rb_w32_unlink(const char *); +extern int rb_w32_stati64(const char *, struct stati64 *); + +#ifdef __BORLANDC__ +extern int rb_w32_fstati64(int, struct stati64 *); +extern off_t _lseeki64(int, off_t, int); +extern FILE *rb_w32_fopen(const char *, const char *); +extern FILE *rb_w32_fdopen(int, const char *); +extern FILE *rb_w32_fsopen(const char *, const char *, int); +#endif + +#include +#if !defined __MINGW32__ || defined __NO_ISOCEXT +#ifndef isnan +#define isnan(x) _isnan(x) +#endif +#ifndef finite +#define finite(x) _finite(x) +#endif +#ifndef copysign +#define copysign(a, b) _copysign(a, b) +#endif +#ifndef scalb +#define scalb(a, b) _scalb(a, b) +#endif +#endif + +#if !defined S_IFIFO && defined _S_IFIFO +#define S_IFIFO _S_IFIFO +#endif + +#if 0 && defined __BORLANDC__ +#undef S_ISDIR +#undef S_ISFIFO +#undef S_ISBLK +#undef S_ISCHR +#undef S_ISREG +#define S_ISDIR(m) (((unsigned short)(m) & S_IFMT) == S_IFDIR) +#define S_ISFIFO(m) (((unsigned short)(m) & S_IFMT) == S_IFIFO) +#define S_ISBLK(m) (((unsigned short)(m) & S_IFMT) == S_IFBLK) +#define S_ISCHR(m) (((unsigned short)(m) & S_IFMT) == S_IFCHR) +#define S_ISREG(m) (((unsigned short)(m) & S_IFMT) == S_IFREG) +#endif + +#if !defined S_IRUSR && !defined __MINGW32__ +#define S_IRUSR 0400 +#endif +#ifndef S_IRGRP +#define S_IRGRP 0040 +#endif +#ifndef S_IROTH +#define S_IROTH 0004 +#endif + +#if !defined S_IWUSR && !defined __MINGW32__ +#define S_IWUSR 0200 +#endif +#ifndef S_IWGRP +#define S_IWGRP 0020 +#endif +#ifndef S_IWOTH +#define S_IWOTH 0002 +#endif + +#if !defined S_IXUSR && !defined __MINGW32__ +#define S_IXUSR 0100 +#endif +#ifndef S_IXGRP +#define S_IXGRP 0010 +#endif +#ifndef S_IXOTH +#define S_IXOTH 0001 +#endif + +// +// define this so we can do inplace editing +// + +#define SUFFIX +extern int truncate(const char *path, off_t length); +extern int ftruncate(int fd, off_t length); +extern int fseeko(FILE *stream, off_t offset, int whence); +extern off_t ftello(FILE *stream); + +// +// stubs +// +extern int ioctl (int, int, ...); +extern rb_uid_t getuid (void); +extern rb_uid_t geteuid (void); +extern rb_gid_t getgid (void); +extern rb_gid_t getegid (void); +extern int setuid (rb_uid_t); +extern int setgid (rb_gid_t); + +extern char *rb_w32_strerror(int); + +#ifdef RUBY_EXPORT +#define strerror(e) rb_w32_strerror(e) +#endif + +#define PIPE_BUF 1024 + +#define LOCK_SH 1 +#define LOCK_EX 2 +#define LOCK_NB 4 +#define LOCK_UN 8 + + +#ifndef SIGINT +#define SIGINT 2 +#endif +#ifndef SIGKILL +#define SIGKILL 9 +#endif + + +/* #undef va_start */ +/* #undef va_end */ + +/* winsock error map */ +#define EWOULDBLOCK WSAEWOULDBLOCK +#define EINPROGRESS WSAEINPROGRESS +#define EALREADY WSAEALREADY +#define ENOTSOCK WSAENOTSOCK +#define EDESTADDRREQ WSAEDESTADDRREQ +#define EMSGSIZE WSAEMSGSIZE +#define EPROTOTYPE WSAEPROTOTYPE +#define ENOPROTOOPT WSAENOPROTOOPT +#define EPROTONOSUPPORT WSAEPROTONOSUPPORT +#define ESOCKTNOSUPPORT WSAESOCKTNOSUPPORT +#define EOPNOTSUPP WSAEOPNOTSUPP +#define EPFNOSUPPORT WSAEPFNOSUPPORT +#define EAFNOSUPPORT WSAEAFNOSUPPORT +#define EADDRINUSE WSAEADDRINUSE +#define EADDRNOTAVAIL WSAEADDRNOTAVAIL +#define ENETDOWN WSAENETDOWN +#define ENETUNREACH WSAENETUNREACH +#define ENETRESET WSAENETRESET +#define ECONNABORTED WSAECONNABORTED +#define ECONNRESET WSAECONNRESET +#define ENOBUFS WSAENOBUFS +#define EISCONN WSAEISCONN +#define ENOTCONN WSAENOTCONN +#define ESHUTDOWN WSAESHUTDOWN +#define ETOOMANYREFS WSAETOOMANYREFS +#define ETIMEDOUT WSAETIMEDOUT +#define ECONNREFUSED WSAECONNREFUSED +#define ELOOP WSAELOOP +/*#define ENAMETOOLONG WSAENAMETOOLONG*/ +#define EHOSTDOWN WSAEHOSTDOWN +#define EHOSTUNREACH WSAEHOSTUNREACH +/*#define ENOTEMPTY WSAENOTEMPTY*/ +#define EPROCLIM WSAEPROCLIM +#define EUSERS WSAEUSERS +#define EDQUOT WSAEDQUOT +#define ESTALE WSAESTALE +#define EREMOTE WSAEREMOTE + +#define F_SETFL 1 +#define O_NONBLOCK 1 + +#undef FD_SET +#define FD_SET(f, s) rb_w32_fdset(f, s) + +#undef FD_CLR +#define FD_CLR(f, s) rb_w32_fdclr(f, s) + +#undef FD_ISSET +#define FD_ISSET(f, s) rb_w32_fdisset(f, s) + +#ifdef RUBY_EXPORT +#undef accept +#define accept(s, a, l) rb_w32_accept(s, a, l) + +#undef bind +#define bind(s, a, l) rb_w32_bind(s, a, l) + +#undef connect +#define connect(s, a, l) rb_w32_connect(s, a, l) + +#undef select +#define select(n, r, w, e, t) rb_w32_select(n, r, w, e, t) + +#undef getpeername +#define getpeername(s, a, l) rb_w32_getpeername(s, a, l) + +#undef getsockname +#define getsockname(s, a, l) rb_w32_getsockname(s, a, l) + +#undef getsockopt +#define getsockopt(s, v, n, o, l) rb_w32_getsockopt(s, v, n, o, l) + +#undef ioctlsocket +#define ioctlsocket(s, c, a) rb_w32_ioctlsocket(s, c, a) + +#undef listen +#define listen(s, b) rb_w32_listen(s, b) + +#undef recv +#define recv(s, b, l, f) rb_w32_recv(s, b, l, f) + +#undef recvfrom +#define recvfrom(s, b, l, f, fr, frl) rb_w32_recvfrom(s, b, l, f, fr, frl) + +#undef send +#define send(s, b, l, f) rb_w32_send(s, b, l, f) + +#undef sendto +#define sendto(s, b, l, f, t, tl) rb_w32_sendto(s, b, l, f, t, tl) + +#undef setsockopt +#define setsockopt(s, v, n, o, l) rb_w32_setsockopt(s, v, n, o, l) + +#undef shutdown +#define shutdown(s, h) rb_w32_shutdown(s, h) + +#undef socket +#define socket(s, t, p) rb_w32_socket(s, t, p) + +#undef gethostbyaddr +#define gethostbyaddr(a, l, t) rb_w32_gethostbyaddr(a, l, t) + +#undef gethostbyname +#define gethostbyname(n) rb_w32_gethostbyname(n) + +#undef gethostname +#define gethostname(n, l) rb_w32_gethostname(n, l) + +#undef getprotobyname +#define getprotobyname(n) rb_w32_getprotobyname(n) + +#undef getprotobynumber +#define getprotobynumber(n) rb_w32_getprotobynumber(n) + +#undef getservbyname +#define getservbyname(n, p) rb_w32_getservbyname(n, p) + +#undef getservbyport +#define getservbyport(p, pr) rb_w32_getservbyport(p, pr) + +#undef socketpair +#define socketpair(a, t, p, s) rb_w32_socketpair(a, t, p, s) + +#undef get_osfhandle +#define get_osfhandle(h) rb_w32_get_osfhandle(h) + +#undef getcwd +#define getcwd(b, s) rb_w32_getcwd(b, s) + +#undef getenv +#define getenv(n) rb_w32_getenv(n) + +#undef rename +#define rename(o, n) rb_w32_rename(o, n) + +#undef times +#define times(t) rb_w32_times(t) +#endif + +struct tms { + long tms_utime; + long tms_stime; + long tms_cutime; + long tms_cstime; +}; + +int rb_w32_times(struct tms *); + +/* thread stuff */ +HANDLE GetCurrentThreadHandle(void); +int rb_w32_sleep(unsigned long msec); +int rb_w32_putc(int, FILE*); +int rb_w32_getc(FILE*); +int rb_w32_close(int); +int rb_w32_fclose(FILE*); +size_t rb_w32_read(int, void *, size_t); +size_t rb_w32_write(int, const void *, size_t); +int rb_w32_utime(const char *, const struct utimbuf *); +int WINAPI rb_w32_Sleep(unsigned long msec); + +/* +== ***CAUTION*** +Since this function is very dangerous, ((*NEVER*)) +* lock any HANDLEs(i.e. Mutex, Semaphore, CriticalSection and so on) or, +* use anything like TRAP_BEG...TRAP_END block structure, +in asynchronous_func_t. +*/ +typedef DWORD (*asynchronous_func_t)(DWORD self, int argc, DWORD* argv); +DWORD rb_w32_asynchronize(asynchronous_func_t func, DWORD self, int argc, DWORD* argv, DWORD intrval); + +#if defined(__cplusplus) +#if 0 +{ /* satisfy cc-mode */ +#endif +} /* extern "C" { */ +#endif + +#endif /* RUBY_WIN32_H */ diff --git a/include/rubyio.h b/include/rubyio.h new file mode 100644 index 0000000000..f385058c44 --- /dev/null +++ b/include/rubyio.h @@ -0,0 +1 @@ +#include diff --git a/include/rubysig.h b/include/rubysig.h new file mode 100644 index 0000000000..cc8cdb2f6d --- /dev/null +++ b/include/rubysig.h @@ -0,0 +1 @@ +#include -- cgit v1.2.3