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#if !defined(lint) && !defined(__CODECENTER__)
24static char rcs_id[] = "@(#) 102.1 $Id: ulserver.c 14875 2005-11-12 21:25:31Z bonefish $";
25#endif
26
27#ifndef NO_EXTEND_MENU
28#include	<errno.h>
29#include "canna.h"
30
31#ifdef luna88k
32extern int errno;
33#endif
34
35static int uuServerChangeEveryTimeCatch(uiContext d, int retval, mode_context env);
36static int uuServerChangeExitCatch(uiContext d, int retval, mode_context env);
37static int uuServerChangeQuitCatch(uiContext d, int retval, mode_context env);
38static int serverChangeDo(uiContext d, int len);
39
40static int serverChangeDo();
41
42/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
43 * ¥µ¡¼¥Ð¤ÎÀÚ¤êÎ¥¤·                                                          *
44 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
45
46int serverFin(uiContext d)
47{
48  int retval = 0;
49  yomiContext yc = (yomiContext)d->modec;
50
51#ifndef STANDALONE
52  if (yc->generalFlags & CANNA_YOMI_CHGMODE_INHIBITTED) {
53    return NothingChangedWithBeep(d);
54  }
55  d->status = 0;
56  killmenu(d);
57
58  jrKanjiPipeError();
59
60  makeGLineMessageFromString(d, "\244\253\244\312\264\301\273\372\312\321\264\271\245\265\241\274\245\320\244\310\244\316\300\334\302\263\244\362\300\332\244\352\244\336\244\267\244\277");
61            /* ¤«¤Ê´Á»úÊÑ´¹¥µ¡¼¥Ð¤È¤ÎÀܳ¤òÀÚ¤ê¤Þ¤·¤¿ */
62  currentModeInfo(d);
63#endif /* STANDALONE */
64
65  return(retval);
66}
67
68/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
69 * ¥µ¡¼¥Ð¤ÎÀڤ괹¤¨                                                          *
70 * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
71
72#ifndef STANDALONE
73
74static
75uuServerChangeEveryTimeCatch(uiContext d, int retval, mode_context env)
76/* ARGSUSED */
77{
78  int len, echoLen, revPos;
79  static int lmachinename;
80  static WCHAR_T *wmachinename;
81
82  if (!wmachinename) {
83    WCHAR_T xxx[30]; /* 30 ¤Ã¤Æ¤Î¤Ï "¥Þ¥·¥ó̾?[" ¤è¤ê¤ÏŤ¤¤Ù¤È¤¤¤¦¤³¤È */
84    lmachinename = MBstowcs(xxx, "\245\336\245\267\245\363\314\276?[", 30);
85                              /* ¥Þ¥·¥ó̾ */
86    wmachinename = (WCHAR_T *)malloc((lmachinename + 1)* sizeof(WCHAR_T));
87    if (!wmachinename) {
88      return -1;
89    }
90    WStrcpy(wmachinename, xxx);
91  }
92
93  if((echoLen = d->kanji_status_return->length) < 0)
94    return(retval);
95
96  if (echoLen == 0) {
97    d->kanji_status_return->revPos = 0;
98    d->kanji_status_return->revLen = 0;
99  }
100
101  WStrncpy(d->genbuf + lmachinename,
102	   d->kanji_status_return->echoStr, echoLen);
103  /* echoStr == d->genbuf ¤À¤È¤Þ¤º¤¤¤Î¤ÇÀè¤ËÆ°¤«¤¹ */
104  WStrncpy(d->genbuf, wmachinename, lmachinename);
105  revPos = len = lmachinename;
106  len += echoLen;
107  d->genbuf[len++] = (WCHAR_T)']';
108
109  d->kanji_status_return->gline.line = d->genbuf;
110  d->kanji_status_return->gline.length = len;
111  if (d->kanji_status_return->revLen) {
112    d->kanji_status_return->gline.revPos =
113      d->kanji_status_return->revPos + revPos;
114    d->kanji_status_return->gline.revLen = d->kanji_status_return->revLen;
115  }
116  else { /* ȿžÎΰ褬¤Ê¤¤¾ì¹ç */
117    d->kanji_status_return->gline.revPos = len - 1;
118    d->kanji_status_return->gline.revLen = 1;
119  }
120  d->kanji_status_return->info &= ~(KanjiThroughInfo | KanjiEmptyInfo);
121  d->kanji_status_return->info |= KanjiGLineInfo;
122  echostrClear(d);
123  checkGLineLen(d);
124
125  return retval;
126}
127
128static
129uuServerChangeExitCatch(uiContext d, int retval, mode_context env)
130/* ARGSUSED */
131{
132  popCallback(d); /* Æɤߤò pop */
133
134  return(serverChangeDo(d, retval));
135}
136
137static
138uuServerChangeQuitCatch(uiContext d, int retval, mode_context env)
139/* ARGSUSED */
140{
141  popCallback(d); /* Æɤߤò pop */
142
143  return prevMenuIfExist(d);
144}
145
146extern exp(char *) RkwGetServerName();
147#endif /* STANDALONE */
148
149int serverChange(uiContext d)
150{
151  int retval = 0;
152  WCHAR_T *w;
153  extern KanjiModeRec yomi_mode;
154  extern int defaultContext;
155  yomiContext yc = (yomiContext)d->modec;
156
157#ifndef STANDALONE
158  if (yc->generalFlags & CANNA_YOMI_CHGMODE_INHIBITTED) {
159    return NothingChangedWithBeep(d);
160  }
161  d->status = 0;
162
163  if ((yc = GetKanjiString(d, (WCHAR_T *)NULL, 0,
164		     CANNA_ONLY_ASCII,
165		     (int)CANNA_YOMI_CHGMODE_INHIBITTED,
166		     (int)CANNA_YOMI_END_IF_KAKUTEI,
167		     CANNA_YOMI_INHIBIT_ALL,
168		     uuServerChangeEveryTimeCatch, uuServerChangeExitCatch,
169		     uuServerChangeQuitCatch))
170      == (yomiContext)0) {
171    killmenu(d);
172    return NoMoreMemory();
173  }
174  yc->minorMode = CANNA_MODE_ChangingServerMode;
175  if(defaultContext != -1) {
176    char *servname;
177    servname = RkwGetServerName();
178    if (servname && (w = WString(servname)) != (WCHAR_T *)0) {
179      RomajiStoreYomi(d, w, (WCHAR_T *)0);
180      WSfree(w);
181      yc->kRStartp = yc->kCurs = 0;
182      yc->rStartp = yc->rCurs = 0;
183      d->current_mode = &yomi_mode;
184      makeYomiReturnStruct(d);
185    }
186  }
187  currentModeInfo(d);
188#endif /* STANDALONE */
189
190  return(retval);
191}
192
193#ifndef STANDALONE
194static
195serverChangeDo(uiContext d, int len)
196{
197/* WCHAR_T ¤ÇÎɤ¤¤«¡© 256 ¤ÇÎɤ¤¤«¡© */
198  WCHAR_T newServerName[256];
199  WCHAR_T w1[512];
200  char tmpServName[256];
201  extern defaultContext;
202  char *p;
203
204  d->status = 0;
205
206  if(!len)
207    return(serverChange(d));
208
209  WStrncpy(newServerName, d->buffer_return, len);
210  newServerName[len] = 0;
211#if defined(DEBUG) && !defined(WIN)
212  if(iroha_debug)
213    printf("iroha_server_name = [%s]\n", newServerName);
214#endif
215
216  jrKanjiPipeError();
217  WCstombs(tmpServName, newServerName, 256);
218  if (RkSetServerName(tmpServName) && (p = index((char *)tmpServName, '@'))) {
219#ifdef WIN
220    char xxxx[512];
221#else
222    char xxxx[1024];
223#endif
224    *p = '\0';
225    sprintf(xxxx, "\244\253\244\312\264\301\273\372\312\321\264\271\245\250\245\363\245\270\245\363 %s \244\317\315\370\315\321\244\307\244\255\244\336\244\273\244\363\n",
226	    tmpServName);
227          /* ¤«¤Ê´Á»úÊÑ´¹¥¨¥ó¥¸¥ó %s ¤ÏÍøÍѤǤ­¤Þ¤»¤ó */
228    makeGLineMessageFromString(d, xxxx);
229
230    RkSetServerName((char *)0);
231    currentModeInfo(d);
232    killmenu(d);
233    return 0;
234  }
235
236  if(defaultContext == -1) {
237    if((KanjiInit() != 0) || (defaultContext == -1)) {
238      jrKanjiError = "\244\253\244\312\264\301\273\372\312\321\264\271\245\265\241\274\245\320\244\310\304\314\277\256\244\307\244\255\244\336\244\273\244\363";
239                   /* ¤«¤Ê´Á»úÊÑ´¹¥µ¡¼¥Ð¤ÈÄÌ¿®¤Ç¤­¤Þ¤»¤ó */
240      killmenu(d);
241      return(GLineNGReturn(d));
242    }
243    d->contextCache = -1;
244  }
245
246  p = RkwGetServerName();
247  if (p) { /* ÀäÂÐÀ®¸ù¤¹¤ë¤ó¤À¤±¤É¤Í */
248    if ((int)strlen(p) < 256) {
249      MBstowcs(newServerName, p, 256);
250    }
251  }
252
253  MBstowcs(w1, " \244\316\244\253\244\312\264\301\273\372\312\321\264\271\245\265\241\274\245\320\244\313\300\334\302\263\244\267\244\336\244\267\244\277", 512);
254              /* ¤Î¤«¤Ê´Á»úÊÑ´¹¥µ¡¼¥Ð¤ËÀܳ¤·¤Þ¤·¤¿ */
255  WStrcpy((WCHAR_T *)d->genbuf, (WCHAR_T *)newServerName);
256  WStrcat((WCHAR_T *)d->genbuf, (WCHAR_T *)w1);
257
258  makeGLineMessage(d, d->genbuf, WStrlen(d->genbuf));
259  killmenu(d);
260  currentModeInfo(d);
261
262  return(0);
263}
264
265#endif /* STANDALONE */
266#endif /* NO_EXTEND_MENU */
267