1/* Copyright 1992 NEC Corporation, Tokyo, Japan.
2 *
3 * Permission to use, copy, modify, distribute and sell this software
4 * and its documentation for any purpose is hereby granted without
5 * fee, provided that the above copyright notice appear in all copies
6 * and that both that copyright notice and this permission notice
7 * appear in supporting documentation, and that the name of NEC
8 * Corporation not be used in advertising or publicity pertaining to
9 * distribution of the software without specific, written prior
10 * permission.  NEC Corporation makes no representations about the
11 * suitability of this software for any purpose.  It is provided "as
12 * is" without express or implied warranty.
13 *
14 * NEC CORPORATION DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
15 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN
16 * NO EVENT SHALL NEC CORPORATION BE LIABLE FOR ANY SPECIAL, INDIRECT OR
17 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
18 * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
19 * OTHER TORTUOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
20 * PERFORMANCE OF THIS SOFTWARE.
21 */
22
23/************************************************************************/
24/* THIS SOURCE CODE IS MODIFIED FOR TKO BY T.MURAI 1997
25/************************************************************************/
26
27
28#if !defined(lint) && !defined(__CODECENTER__)
29static char rcs_id[] = "@(#) 102.1 $Id: bunsetsu.c 10525 2004-12-23 21:23:50Z korli $";
30#endif	/* lint */
31
32#include <errno.h>
33#include "canna.h"
34#include "RK.h"
35#include "RKintern.h"
36
37extern int BunsetsuKugiri;
38
39static char *e_message[] = {
40#ifdef WIN
41  /* 0*/"\312\270\300\341\244\316\260\334\306\260\244\313\274\272\307\324\244\267\244\336\244\267\244\277",
42  /* 1*/"\264\301\273\372\244\316\306\311\244\337\244\362\274\350\244\352\275\320\244\273\244\336\244\273\244\363\244\307\244\267\244\277",
43  /* 2*/"\312\270\300\341\244\316\260\334\306\260\244\313\274\272\307\324\244\267\244\336\244\267\244\277",
44  /* 3*/"\264\301\273\372\244\316\306\311\244\337\244\362\274\350\244\352\275\320\244\273\244\336\244\273\244\363\244\307\244\267\244\277",
45  /* 4*/"\244\253\244\312\264\301\273\372\312\321\264\271\244\313\274\272\307\324\244\267\244\336\244\267\244\277",
46#else
47  /* 0*/"������������������������������������������������",
48  /* 1*/"����������������������������������������������������������������",
49  /* 2*/"������������������������������������������������",
50  /* 3*/"����������������������������������������������������������������",
51  /* 4*/"����������������������������������������������������",
52#endif
53};
54
55int
56enterAdjustMode(uiContext d, yomiContext yc)
57{
58  extern KanjiModeRec bunsetsu_mode;
59  int i, n = 0;
60  RkStat rst;
61
62  for (i = 0 ; i < yc->curbun ; i++) {
63    if (RkwGoTo(yc->context, i) == -1) {
64      return makeRkError(d, e_message[0]);
65    }
66    if (RkwGetStat(yc->context, &rst) == -1) {
67      return makeRkError(d, e_message[1]);
68    }
69    n += rst.ylen;
70  }
71  yc->kanjilen = n;
72  /* �������������������������������������������������������������������� */
73  if (RkwGoTo(yc->context, yc->curbun) == -1) {
74    return makeRkError(d, e_message[2]);
75  }
76  if (RkwGetStat(yc->context, &rst) == -1) {
77    return makeRkError(d, e_message[3]);
78  }
79  yc->bunlen = rst.ylen;
80
81  yc->tanMode = yc->curMode;
82  yc->tanMinorMode = yc->minorMode;
83  yc->minorMode = CANNA_MODE_AdjustBunsetsuMode;
84  d->current_mode = yc->curMode = &bunsetsu_mode;
85  return 0;
86}
87
88int
89leaveAdjustMode(uiContext d, yomiContext yc)
90{
91  extern KanjiModeRec bunsetsu_mode;
92
93  yc->bunlen = yc->kanjilen = 0;
94  yc->minorMode = yc->tanMinorMode;
95  d->current_mode = yc->curMode = yc->tanMode;
96  return 0;
97}
98
99
100static int
101BunFullExtend(uiContext d)
102{
103  yomiContext yc = (yomiContext)d->modec;
104
105  yc->bunlen = yc->kEndp - yc->kanjilen;
106  makeKanjiStatusReturn(d, yc);
107  return 0;
108}
109
110static int
111BunFullShrink(uiContext d)
112{
113  yomiContext yc = (yomiContext)d->modec;
114
115  yc->bunlen = 1;
116  makeKanjiStatusReturn(d, yc);
117  return 0;
118}
119
120static int
121BunExtend(uiContext d)
122{
123  yomiContext yc = (yomiContext)d->modec;
124
125  if (yc->kanjilen + yc->bunlen < yc->kEndp) {
126    /* ������������������������ */
127
128    yc->bunlen++;
129    makeKanjiStatusReturn(d, yc);
130    return 0;
131  }
132  else if (cannaconf.CursorWrap) {
133    return BunFullShrink(d);
134  }
135  (void)NothingChangedWithBeep(d);
136  return 0;
137}
138
139static int
140BunShrink(uiContext d)
141{
142  yomiContext yc = (yomiContext)d->modec;
143
144  if (yc->bunlen > 0) {
145    /* �������������������� */
146    int newlen = yc->bunlen;
147
148    newlen--;
149    if (newlen > 0) {
150      yc->bunlen = newlen;
151      makeKanjiStatusReturn(d, yc);
152      return 0;
153    }
154    else if (cannaconf.CursorWrap) {
155      return BunFullExtend(d);
156    }
157  }
158  (void)NothingChangedWithBeep(d);
159  return 0;
160}
161
162static int
163BunHenkan(uiContext d)
164{
165  yomiContext yc = (yomiContext)d->modec;
166
167  yc->nbunsetsu = RkwResize(yc->context, yc->bunlen);
168  leaveAdjustMode(d, yc);
169  if (yc->nbunsetsu < 0) {
170    makeRkError(d, e_message[4]);
171    yc->nbunsetsu = 1/* dummy */;
172    return TanMuhenkan(d);
173  }
174  makeKanjiStatusReturn(d, yc);
175  currentModeInfo(d);
176  return 0;
177}
178
179static int
180BunQuit(uiContext d)
181{
182  yomiContext yc = (yomiContext)d->modec;
183
184  leaveAdjustMode(d, yc);
185  makeKanjiStatusReturn(d, yc);
186  currentModeInfo(d);
187  return 0;
188}
189
190static int
191BunSelfInsert(uiContext d)
192{
193  d->nbytes = BunQuit(d);
194  d->more.todo = 1;
195  d->more.ch = d->ch;
196  d->more.fnum = CANNA_FN_FunctionalInsert;
197  return d->nbytes;
198}
199
200static int
201BunQuotedInsert(uiContext d)
202{
203  d->nbytes = BunQuit(d);
204  d->more.todo = 1;
205  d->more.ch = d->ch;
206  d->more.fnum = CANNA_FN_QuotedInsert;
207  return d->nbytes;
208}
209
210static int
211BunKillToEOL(uiContext d)
212{
213  d->nbytes = BunQuit(d);
214  d->more.todo = 1;
215  d->more.ch = d->ch;
216  d->more.fnum = CANNA_FN_KillToEndOfLine;
217  return d->nbytes;
218}
219
220#include "bunmap.h"
221
222/* ��������������������������������
223
224 ����������������������������������������������������������������
225 */
226