Newer
Older
scim-wnn / scim-wnn / src / wnnconversion.cpp
@tamra tamra on 20 Nov 2004 3 KB 変換の仮実装。
/***************************************************************************
 *   Copyright (C) 2004 by TAM(Teppei Tamra)                               *
 *   tam-t@par.odn.ne.jp                                                   *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
 ***************************************************************************/
#include "wnnconversion.h"

#ifdef HAVE_CONFIG_H
  #include <config.h>
#endif

#ifdef HAVE_GETTEXT
  #include <libintl.h>
  #define _(String) dgettext(GETTEXT_PACKAGE,String)
  #define N_(String) (String)
#else
  #define _(String) (String)
  #define N_(String) (String)
  #define bindtextdomain(Package,Directory)
  #define textdomain(domain)
  #define bind_textdomain_codeset(domain,codeset)
#endif

WnnConversion::WnnConversion()
{
    // とりあえず決めうちでいきます。
    wnn = jl_open_lang("test","localhost","jp_JP","/usr/lib/wnn7/ja_JP/wnnenvrc",wnn_error,wnn_message,10);
    m_iconv.set_encoding ("EUC-JP");
}


WnnConversion::~WnnConversion()
{
}


    /* w_charからEUCに変換するアレ */
void WnnConversion::wstostr(unsigned char *e,w_char *u) {
    w_char x;
    for(;*u;) {
        x = *u ++;
        if (x & 0x8000) {
            *e ++ = x >> 8;
            *e ++ = x;
        } else
            *e++ = x;
    }
    *e ++ = 0;
}

    /* EUCからw_charに変換するナニ */
void WnnConversion::strtows(w_char *u,unsigned char *e) {
    w_char  x;
    for(;*e;) {
        x = *e ++;
        if(x & 0x80)
        x = ((x << 8) & 0xff00)  | *e ++;
        *u ++ = x;
    }
    *u = 0;
}



/*!
    \fn WnnConversion::isConnected()
 */
bool WnnConversion::isConnected()
{
    if (wnn) return(true);
    else (false);
}




/*!
    \fn WnnConversion::wnn_message (char *s)
 */
int WnnConversion::wnn_message (char *s)
{

    SCIM_DEBUG_IMENGINE(1) << s << "\n";
}

/*!
    \fn WnnConversion::wnn_error (char *s)
 */
int WnnConversion::wnn_error (char *s)
{

    SCIM_DEBUG_IMENGINE(1) << s << "\n";
}




/*!
    \fn WnnConversion::reset()
 */
void WnnConversion::reset()
{
    yomiText.clear();
    text.clear();
}


/*!
    \fn WnnConversion::setYomiText(WideString yomi)
 */
void WnnConversion::setYomiText(WideString yomi)
{
    yomiText = yomi;
}


/*!
    \fn WnnConversion::ren_conversion()
 */
int WnnConversion::ren_conversion()
{
    convList.clear();
    w_char ws[1024];
    char c[2048];
    String y;
    m_iconv.convert(y,yomiText);
    strtows(ws,(unsigned char*)y.data());
    int b = jl_ren_conv(wnn,ws,0,-1,WNN_USE_ZENGO);

    wnn_get_area(wnn,0,-1,ws,1);
    wstostr((unsigned char*)c,ws);
    m_iconv.convert(text,c,strlen(c) + 1);

}


/*!
    \fn WnnConversion::getText()
 */
WideString WnnConversion::getText()
{
    return(text);
}