1 /*
2 * Copyright (c) 1994 Sony Corporation
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files (the
6 * "Software"), to deal in the Software without restriction, including
7 * without limitation the rights to use, copy, modify, merge, publish,
8 * distribute, sublicense, and/or sell copies of the Software, and to
9 * permit persons to whom the Software is furnished to do so, subject to
10 * the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL SONY CORPORATION BE LIABLE FOR ANY CLAIM,
19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
21 * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 *
23 * Except as contained in this notice, the name of Sony Corporation
24 * shall not be used in advertising or otherwise to promote the sale, use
25 * or other dealings in this Software without prior written authorization
26 * from Sony Corporation.
27 *
28 */
29
30 /*
31 * $SonyRCSfile: etc.c,v $
32 * $SonyRevision: 1.1 $
33 * $SonyDate: 1994/06/03 08:03:15 $
34 */
35
36
37
38 #include <stdlib.h>
39 #include <string.h>
40 #include "common.h"
41 #include "key.h"
42
43 #include "sj3.h"
44
45 static char rehname[SHORTLENGTH * 2];
46 static int dcflag = 0;
47
48 int
exec_etc(int key)49 exec_etc(int key)
50 {
51 u_short row, col;
52 int inc;
53 int chbun;
54 int edited;
55 int etckey;
56 Conversion *cv;
57
58 cv = GetConversion ();
59
60 edited = 0;
61 chbun = 0;
62 StartGuide (&row, &col);
63 if (key == KEY_ETC) {
64 printR (WCGEtc);
65 if (cv->column >= MINCOL)
66 spaceR (WCGetc);
67 Clear_EOL ();
68 EndGuide (row, col);
69 SaveConversion ();
70 inc = inkey ();
71 if (AnotherConversion ())
72 return(KEY_NORMAL);
73 cv = GetConversion ();
74 etckey = etc_map (keyvalue);
75 }
76 else {
77 EndGuide (row, col);
78 etckey = key;
79 }
80
81 switch (etckey) {
82 case KEY_NORMAL:
83 normal:
84 switch (inc) {
85 case 'h':
86 helplevel ();
87 break;
88 case 't':
89 if (!IsCflag ())
90 chbun = exec_toroku ();
91 break;
92 case 's':
93 if (!IsCflag ())
94 chbun = exec_syoukyo ();
95 break;
96 case 'v':
97 case 'd':
98 disp_version (inc);
99 break;
100 case 'w':
101 change_weight ();
102 break;
103 default:
104 break;
105 }
106 break;
107 case KEY_HELP:
108 helplevel ();
109 break;
110 case KEY_TOROKU:
111 if (!IsCflag ())
112 chbun = exec_toroku ();
113 break;
114 case KEY_SYOUKYO:
115 if (!IsCflag ())
116 chbun = exec_syoukyo ();
117 break;
118 case KEY_SJRC:
119 if (IsCflag ())
120 exec_sjrc ();
121 break;
122 case KEY_EDIT:
123 if (IsHenkan ()) {
124 if (cv->CurBun < 0) {
125 cv->CurBun = 0;
126 Bdisp (1);
127 }
128 edited = exec_edit ();
129 }
130 break;
131 case KEY_RECONNECT:
132 if (reconnect() && IsHenkan()) {
133 EndGuide (row, col);
134 Clear_EOL();
135 Ccheck();
136 Cclear(1);
137 ResetHenkan();
138 vprintU(cv->out_buf, 1);
139 cv->Kanji = 0;
140 return(KEY_NORMAL);
141 }
142 break;
143 case KEY_ETC:
144 break;
145 default:
146 if ((inc = write_pseq (2)) != 0)
147 goto normal;
148 return(etckey);
149 break;
150 }
151
152 EndGuide (row, col);
153 if (edited) {
154 if (!Sdouon (3))
155 Rdisp ();
156 }
157 if (chbun)
158 Ssbun(1);
159 return(KEY_NORMAL);
160 }
161
162 void
Ssbun(int flag)163 Ssbun(int flag)
164 {
165 Conversion *cv;
166 static short ScurBun, SpreBun;
167
168 cv = GetConversion();
169 if (flag) {
170 if (cv->CurBun != ScurBun || cv->PreBun != SpreBun) {
171 cv->CurBun = ScurBun;
172 cv->PreBun = SpreBun;
173 Bdisp(1);
174 }
175 } else {
176 ScurBun = cv->CurBun;
177 SpreBun = cv->PreBun;
178 }
179 }
180
181 int
etc_map(int key)182 etc_map(int key)
183 {
184 int i;
185 int val;
186
187 for (i = 0 ; i < u_etckeys ; i ++) {
188 if (key == Uetckey[i])
189 return (Uetcval[i]);
190 }
191
192 switch (key) {
193 case KEY_HENKAN:
194 val = KEY_TOROKU;
195 break;
196 case KEY_MUHENKAN:
197 val = KEY_SYOUKYO;
198 break;
199 case KEY_ETC:
200 val = KEY_HELP;
201 break;
202 case KEY_KETTEI:
203 val = KEY_SJRC;
204 break;
205 case KEY_CODE:
206 val = KEY_EDIT;
207 break;
208 case KEY_HALPHA:
209 val = KEY_RECONNECT;
210 break;
211 default:
212 val = KEY_NORMAL;
213 break;
214 }
215 return (val);
216 }
217
218 void
helplevel()219 helplevel()
220 {
221 wchar16_t wtmp[BUFFLENGTH];
222 u_char mtmp[BUFFLENGTH];
223 u_char tmp[BUFFLENGTH];
224 Conversion *cv;
225
226 cv = GetConversion ();
227
228 if (Hlevel == 1 && cv->column >= MINCOL) {
229 HHlevel = 2;
230 Hlevel = 2;
231 (void) wcstombs((char *)mtmp, WCMHelp, BUFFLENGTH);
232 snprintf((char *)tmp, sizeof(tmp), (char *)mtmp, "on");
233 (void) mbstowcs(wtmp, (char *)tmp, BUFFLENGTH);
234 }
235 else {
236 HHlevel = 1;
237 Hlevel = 1;
238 (void) wcstombs((char *)mtmp, WCMHelp, BUFFLENGTH);
239 snprintf((char *)tmp, sizeof(tmp), (char *)mtmp, "off");
240 (void) mbstowcs(wtmp, (char *)tmp, BUFFLENGTH);
241 }
242 guide_print_pause (WCGHelp, wtmp);
243 }
244
245 void
disp_version(int c)246 disp_version(int c)
247 {
248 char tmp[BUFFLENGTH];
249
250 wchar16_t wtmp[BUFFLENGTH];
251
252 if (c == 'v')
253 snprintf(tmp, sizeof(tmp), "%s, %s ", Version, Copyright);
254 else if (c == 'd')
255 snprintf (tmp, sizeof(tmp), "%s ", Date);
256 else
257 return;
258 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
259 guide_print_pause (0, wtmp);
260 }
261
262 void
exec_sjrc()263 exec_sjrc()
264 {
265 char tmp[BUFFLENGTH];
266 u_char SUCCorFAIL[BUFFLENGTH];
267 wchar16_t wtmp[BUFFLENGTH];
268
269
270 if (*RCfile == (char)NULL) {
271 getsjrc();
272 if (*RCfile == (char)NULL)
273 {
274 (void) wcstombs((char *)SUCCorFAIL, WCNOTHsjrc, BUFFLENGTH);
275 snprintf((char *)tmp, sizeof(tmp), (char *)SUCCorFAIL);
276 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
277 }
278 else
279 {
280 (void) wcstombs((char *)SUCCorFAIL, WCSUCCsjrc, BUFFLENGTH);
281 snprintf(tmp, sizeof(tmp), "%s %s ", RCfile, SUCCorFAIL);
282 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
283 }
284 } else {
285 if (setrc (RCfile) == TRUE)
286 {
287 (void) wcstombs((char *)SUCCorFAIL, WCSUCCsjrc, BUFFLENGTH);
288 } else {
289 (void) wcstombs((char *)SUCCorFAIL, WCFAILsjrc, BUFFLENGTH);
290 }
291 snprintf(tmp, sizeof(tmp), "%s %s ", RCfile, SUCCorFAIL);
292 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
293 }
294 guide_print_pause (0, wtmp);
295 }
296
297 static int weight = 3;
298 static int seed = 100000;
299
300 void
change_weight()301 change_weight()
302 {
303 int c;
304 char s[2];
305 char tmp[BUFFLENGTH];
306 u_char mtmp[BUFFLENGTH];
307 wchar16_t wtmp[BUFFLENGTH];
308
309 (void) wcstombs((char *)mtmp, WCWeight_mes, BUFFLENGTH);
310 snprintf(tmp, sizeof(tmp), (char *)mtmp, weight);
311 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
312 c = guide_print_pause (0, wtmp);
313
314 if (isdigit (c) && (c != '0')) {
315 s[0] = c;
316 s[1] = '\0';
317 weight = atoi (s);
318 }
319 }
320
321 int
UsecWeight(int sw)322 UsecWeight(int sw)
323 {
324
325
326 if (sw)
327 return (seed);
328 else
329 return (seed * weight);
330 }
331
332 int
dconnect(int aflag)333 dconnect(int aflag)
334 {
335 int err;
336 char tmp[BUFFLENGTH];
337 wchar16_t wtmp[BUFFLENGTH];
338 u_char dtmp[BUFFLENGTH];
339
340 if (!dcflag) {
341 (void) wcstombs((char *)dtmp, WCDiscon, BUFFLENGTH);
342 snprintf(tmp, sizeof(tmp), (char *)dtmp, cur_serv);
343 beep();
344 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
345 guide_print_pause (0, wtmp);
346
347
348 if (aflag && keyvalue == KEY_HENKAN) {
349 if ((err = sj3_autocon()) == 0) {
350 (void) wcstombs((char *)dtmp, WCRserv_OK, BUFFLENGTH);
351 snprintf(tmp, sizeof(tmp), (char *)dtmp, cur_serv);
352 (void) mbstowcs(wtmp, (char *)tmp, BUFFLENGTH);
353 guide_print_pause(0, wtmp);
354 } else {
355 guide_print_pause(WCSpace, WCNconnect);
356 dcflag = 1;
357 }
358 } else
359 dcflag = 1;
360 disp_mode();
361 }
362 return(dcflag);
363 }
364
set_dcflag(flag)365 set_dcflag(flag)
366 int flag;
367 {
368 dcflag = flag;
369 }
370
371 int
IsDcflag()372 IsDcflag()
373 {
374 return(dcflag);
375 }
376
377 int
reconnect()378 reconnect()
379 {
380 int inc, err;
381 char tmp[BUFFLENGTH], *hp;
382 char newserv[SHORTLENGTH * 2], *nsp;
383 wchar16_t wtmp[BUFFLENGTH];
384 u_char rtmp[BUFFLENGTH];
385
386 strncpy(newserv, cur_serv, SHORTLENGTH * 2 - 1);
387 newserv[SHORTLENGTH * 2 - 1] = '\0';
388 while(1) {
389 SaveConversion();
390 TopGuide();
391 printR(WCGrcon);
392 (void) wcstombs((char *)rtmp, WCRserv, BUFFLENGTH);
393 snprintf(tmp, sizeof(tmp), (char *)rtmp, newserv);
394 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
395 SJ_print (wtmp);
396 Clear_EOL();
397 Flush();
398 nsp = newserv;
399 while ((inc = inkey()) != EOF) {
400 if (AnotherConversion()) {
401 unget_key(inc);
402 return(0);
403 }
404 if (keyvalue != KEY_NORMAL && keyvalue != KEY_FLUSH)
405 return(0);
406 if (inc == '\n' || inc == '\r' || IsESC(inc))
407 break;
408 if (is_bs (inc) && nsp > newserv) {
409 nsp--;
410 *nsp = '\0';
411 backspace(1);
412 Flush();
413 } else if (isgraph(inc) &&
414 nsp < &newserv[SHORTLENGTH * 2 - 1]) {
415 *nsp++ = inc;
416 printf("%c", inc);
417 Flush();
418 } else
419 beep();
420 }
421 if (nsp > newserv) {
422 *nsp = '\0';
423 strlcpy(rehname, newserv, sizeof(rehname));
424 cur_serv = rehname;
425 } else if (newserv[0] == '\0') {
426 strlcpy(newserv, cur_serv, sizeof(newserv));
427 }
428 if ((err = SJ2_reconnect()) == 0) {
429 TopGuide();
430 printR(WCGrcon);
431 (void) wcstombs((char *)rtmp, WCRserv_OK, BUFFLENGTH);
432 snprintf(tmp, sizeof(tmp), (char *)rtmp, newserv);
433 (void) mbstowcs(wtmp, tmp, BUFFLENGTH);
434 SJ_print(wtmp);
435 Clear_EOL();
436 Flush();
437 set_dcflag(0);
438 inc = inkey();
439 if (AnotherConversion ())
440 unget_key(inc);
441 break;
442 } else {
443 TopGuide();
444 printR(WCGrcon);
445 SJ_print(WCSpace);
446 sj_check_error(err);
447 SJ_print(WCContinue);
448 Clear_EOL();
449 Backspace();
450 Flush();
451 inc = inkey();
452 if (AnotherConversion()) {
453 unget_key(inc);
454 set_dcflag(1);
455 break;
456 }
457 if (inc == 'n' || inc == 'N' || inc == EOF) {
458 set_dcflag(1);
459 break;
460 }
461 }
462 }
463 return(1);
464 }
465
466 int
guide_print_pause(wchar16_t * s1,wchar16_t * s2)467 guide_print_pause(wchar16_t *s1, wchar16_t *s2)
468 {
469 int c;
470
471 guide_print(s1, s2);
472 SaveConversion();
473 c = inkey();
474 if (AnotherConversion()) {
475 unget_key(c);
476 return (EOF);
477 }
478 return (c);
479 }
480
481
482