/* vi:set sw=4:

    rbwcharbuf.c

    Copyright (c) 2000 Minero Aoki <aamine@dp.u-netsurf.ne.jp>

    This program is free software.
    You can distribute/modify this program under the terms of
    the GNU Lesser General Public License version 2 or later.

*/


#include <stdio.h>
#ifdef __STDC__
# include <stdlib.h>
#endif

#include "ruby.h"
#include "re.h"


#include "sftextbuf.h"

VALUE WCharBuffer;
VALUE WCharBufferMark;


/* buffer dependent definitions */

#define IS_WCHAR_BUFFER

#include "sftextbuf.c"


/* ruby interface */

#define BUFFER_CLASS WcharBuffer
#define MARK_CLASS WcharBufferMark

#define GET_BUF(v,var) Data_Get_Struct(v, struct sf_wcharbuf, var)
#define GET_MARK(v, var) Data_Get_Struct(v, struct sf_wcharbufmark, var)
#define GET_MARK_CHK(v, var) GET_MARK(v, var); alive_check(var)

#define WRAP_BUF(p, c) Data_Wrap_Struct(c, buffer_mark, buffer_free, p)
#define WRAP_MARK(p, c) Data_Wrap_Struct(c, bufmark_mark, bufmark_free, p)

#include "rbbufcommon.c"


/*
========================================================================
                                init
========================================================================
*/

void
Init_wchar_buffer()
{
    WCharBuffer = rb_define_class("WCharBuffer", rb_cData);
    rb_define_singleton_method(WCharBuffer, "new", buffer_s_new, 0);
    rb_define_method(WCharBuffer, "new_mark",     buffer_new_mark,     -1);
    rb_define_method(WCharBuffer, "head",         buffer_head,          0);
    rb_define_method(WCharBuffer, "tail",         buffer_tail,          0);
    rb_define_method(WCharBuffer, "size",         buffer_size,          0);
    rb_define_method(WCharBuffer, "length",       buffer_size,          0);
    rb_define_method(WCharBuffer, "byte_size",    buffer_size,          0);
    rb_define_method(WCharBuffer, "byte_length",  buffer_size,          0);
    rb_define_method(WCharBuffer, "empty?",       buffer_empty_p,       0);
    rb_define_method(WCharBuffer, "substr",       strbuf_substr,        2);
    rb_define_method(WCharBuffer, "[]",           strbuf_substr,        2);
    rb_define_method(WCharBuffer, "each",         buffer_each_line,     0);
    rb_define_method(WCharBuffer, "each_line",    buffer_each_line,     0);
    rb_define_method(WCharBuffer, "reverse_each", buffer_rev_each_line, 0);
    rb_define_method(WCharBuffer, "string",       buffer_string,        0);
    rb_define_method(WCharBuffer, "to_s",         buffer_string,        0);
    rb_define_method(WCharBuffer, "concat",       buffer_concat,        1);
    rb_define_method(WCharBuffer, "clear",        buffer_clear,         0);
    rb_define_method(WCharBuffer, "<<",           buffer_concat,        1);
    rb_define_method(WCharBuffer, "index",        strbuf_index,        -1);
    rb_define_method(WCharBuffer, "rindex",       strbuf_rindex,       -1);
    rb_define_method(WCharBuffer, "match_to",     strbuf_match_to,     -1);
    rb_define_method(WCharBuffer, "=~",           strbuf_match_to,     -1);
    rb_define_method(WCharBuffer, "inspect",      strbuf_inspect,       0);

    WCharBufferMark = rb_define_class("WCharBufferMark", rb_cData);
    rb_define_method(WCharBufferMark, "buffer",       bufmark_buffer,    0);
    rb_define_method(WCharBufferMark, "dup",          bufmark_dup,       0);
    rb_define_method(WCharBufferMark, "clone",        bufmark_clone,     0);
    rb_define_method(WCharBufferMark, "alive?",       bufmark_alive_p,   0);
    rb_define_method(WCharBufferMark, "discard",      bufmark_discard,   0);
    rb_define_method(WCharBufferMark, "insert",       bufmark_insert,    1);
/*rb_define_method(WCharBufferMark, "copy_of",      bufmark_copyof,    2);*/
    rb_define_method(WCharBufferMark, "delete",       sbufmark_delete,   1);
    rb_define_method(WCharBufferMark, "[]",           sbufmark_substr,   1);
    rb_define_method(WCharBufferMark, "substr",       sbufmark_substr,   1);
    rb_define_method(WCharBufferMark, "substr_ro",    sbufmark_rosubstr, 1);
    rb_define_method(WCharBufferMark, "each_line_ro", bufmark_roeach,    0);
    rb_define_method(WCharBufferMark, "index",        bufmark_index,     0);
    rb_define_method(WCharBufferMark, "byte_index",   bufmark_index,     0);
    rb_define_method(WCharBufferMark, "to_i",         bufmark_index,     0);
    rb_define_method(WCharBufferMark, "index=",       bufmark_setidx,    1);
    rb_define_method(WCharBufferMark, "move_to",      bufmark_setidx,    1);
    rb_define_method(WCharBufferMark, "move",         bufmark_fwd,       1);
    rb_define_method(WCharBufferMark, "forward",      bufmark_fwd,       1);
    rb_define_method(WCharBufferMark, "back",         bufmark_back,      1);
    rb_define_method(WCharBufferMark, "head",         bufmark_go_beg,    0);
    rb_define_method(WCharBufferMark, "tail",         bufmark_go_end,    0);
    rb_define_method(WCharBufferMark, "+",            bufmark_plus,      1);
    rb_define_method(WCharBufferMark, "-",            bufmark_minus,     1);
    rb_define_method(WCharBufferMark, "inspect",      sbufmark_inspect,  0);


    rb_define_method(WCharBuffer, "debug_on", debugon, 0);
    rb_define_method(WCharBuffer, "debug_off", debugoff, 0);
}
