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: sjrc.c,v $
32  * $SonyRevision: 1.4 $
33  * $SonyDate: 1997/01/23 11:20:54 $
34  */
35 
36 
37 #include <stdlib.h>
38 #include <string.h>
39 #include "wchar16.h"
40 #include "kctype.h"
41 #if defined(__sony_news) && defined(SVR4)
42 #include <jcode.h>
43 #endif
44 #include "common.h"
45 #include "key.h"
46 #include <locale.h>
47 #include "Paths.h"
48 
49 #include "sj3.h"
50 
51 int		vflag = 1;
52 
53 char		RCfile[LONGLENGTH];
54 
55 wchar16_t	guide_sj2[GUIDELEN];
56 wchar16_t	guide_buffer[GUIDELEN];
57 wchar16_t	guide_unbuffer[GUIDELEN];
58 wchar16_t	guide_hira[GUIDELEN];
59 wchar16_t	guide_zkata[GUIDELEN];
60 wchar16_t	guide_hkata[GUIDELEN];
61 wchar16_t	guide_halpha[GUIDELEN];
62 wchar16_t	guide_zalpha[GUIDELEN];
63 wchar16_t	guide_shift[GUIDELEN];
64 wchar16_t	guide_jis[GUIDELEN];
65 wchar16_t	guide_kuten[GUIDELEN];
66 wchar16_t	guide_etc[GUIDELEN];
67 wchar16_t	guide_etcfunc[GUIDELEN];
68 wchar16_t	guide_function[GUIDELEN];
69 
70 wchar16_t guide_euc[GUIDELEN];
71 wchar16_t guide_euc2[GUIDELEN];
72 wchar16_t guide_jis2[GUIDELEN];
73 wchar16_t guide_kuten2[GUIDELEN];
74 static char	*rcfile = ".sjrc";
75 static char	*rkfile = ".sjrk";
76 
77 static int	intr_code = 0x03;
78 static char	goto_code[LONGLENGTH];
79 static int	goto_num = 0;
80 static char	trap_code[LONGLENGTH];
81 static int	trap_num = 0;
82 static int	def_muhenkan	= KEY_HALPHA;
83 static int	def_muedit	= KEY_ZHIRA;
84 static int	muhenkan_toggle = 1;
85 static int	bstudy = 1;
86 
87 char **dict_list = NULL;
88 int  dict_num = 0;
89 
90 #define SJ3_NO		-1
91 #define SJ3_SJIS	0
92 #define SJ3_EUC		1
93 
94 
95 static int user_euc = 0;
96 static int file_code = SJ3_NO;
97 static int locale_code = SJ3_SJIS;
98 
99 #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
100 
101 void
sjset_code()102 sjset_code()
103 {
104 	char *loc;
105 
106         if (current_locale == LC_CTYPE_EUC) {
107 		locale_code = SJ3_EUC;
108 		user_euc = 1;
109 		file_code = SJ3_NO;
110 	} else
111 		user_euc = 0;
112 }
113 
114 void
sjrc_init()115 sjrc_init()
116 {
117 	clear_del ();
118 	clear_key ();
119 	intr_code = 0x03;
120 	goto_num = 0;
121 	trap_num = 0;
122 	def_muhenkan = KEY_HALPHA;
123 	def_muedit = KEY_ZHIRA;
124 	muhenkan_toggle = 1;
125 	bstudy = 1;
126 	flush_conversion = 0;
127 	if (dict_list) {
128 		if (dict_list[0]) free(dict_list[0]);
129 		free(dict_list);
130 		dict_list = NULL;
131 	}
132 	dict_num = 0;
133 }
134 
135 
136 
137 void
getsjrc()138 getsjrc()
139 {
140 	char *p;
141 
142 	sjset_code();
143 	mk_cvtkey(term_name);
144 	RCfile[0] = '\0';
145 	if ((p = getenv("SJRC")) != NULL && *p != '\0') {
146 		if (*p != '/')
147 			snprintf(RCfile, sizeof(RCfile), "%s/", home);
148 		else
149 			snprintf(RCfile, sizeof(RCfile), "%s", home);
150 		if (setrc(RCfile) == TRUE)
151 			return;
152 	}
153 	if (home[0] != '\0') {
154 		snprintf(RCfile, sizeof(RCfile), "%s/%s", home, rcfile);
155 		if (setrc(RCfile) == TRUE)
156 			return;
157 	}
158         strlcpy(RCfile, DEFRCFILE, sizeof(RCfile));
159         if (setrc(RCfile) == TRUE)
160                 return;
161 
162 	RCfile[0] = '\0';
163 }
164 
165 
166 
167 int
setrc(char * file)168 setrc(char *file)
169 {
170 	wchar16_t	*p;
171 	char		line[MAXLINE];
172 	struct wordent	word[WORDN];
173 	struct functbl *functp;
174 	FILE *fd, *fopen();
175 
176 	if (vflag > 1)
177 		aprintf ("sjrc file is %s\n", file);
178 
179 	if ((fd = fopen(RCfile, "r")) == NULL)
180 		return(FALSE);
181 	sjrc_init ();
182 	while (fgets (line, MAXLINE, fd) != NULL) {
183 		if (getword(line, word) <= 0)
184 			continue;
185 		functp = funcs;
186 		p = word[0].word_str;
187 		while (functp->keyword != NULL) {
188 			if (match(p, functp->keyword)) {
189 				(*(functp->func))(word);
190 				break;;
191 			}
192 			functp++;
193 		}
194 	}
195 	fclose(fd);
196 	return(TRUE);
197 }
198 
199 
200 
201 void
getsjrk(int erase)202 getsjrk(int erase)
203 {
204 	char *p;
205 	int i;
206 	char *getenv();
207 	char RKfile[LONGLENGTH];
208 
209 	RKfile[0] = '\0';
210 	sj3_rkcode(1);
211 	if ((p = getenv("SJRK")) != NULL && *p != '\0') {
212 		if (*p != '/')
213 			snprintf(RKfile, sizeof(RKfile), "%s/%s", home,p);
214 		else
215 			snprintf(RKfile, sizeof(RKfile), "%s%s", home, p);
216 		if ((i = sj3_rkinit2(RKfile, erase)) == TRUE) {
217 			if (!oasys)
218 				mkkigou();
219 			return;
220 		}
221 		if (i == FALSE)
222 			done3();
223 	}
224 	if (home[0] != '\0') {
225 		snprintf(RKfile, sizeof(RKfile), "%s/%s", home, rkfile);
226 		if ((i = sj3_rkinit2(RKfile, erase)) == TRUE) {
227 			if (!oasys)
228 				mkkigou();
229 			return;
230 		}
231 		if (i == FALSE)
232 			done3();
233 	}
234 	sj3_rkcode(0);
235 	if ((i = sj3_rkinit2(DEFRKFILE, erase)) != TRUE) {
236 		if (i == 1) {
237 			fprintf(stderr, "Warning cannot open rule file %s\n\r",
238 				DEFRKFILE);
239 			(void)sj3_rkinit2("/dev/null", erase);
240 		} else
241 			done3();
242 	}
243 	if (!oasys)
244 		mkkigou();
245 }
246 
247 
248 
249 int
match(wchar16_t * s1,wchar16_t * s2)250 match(wchar16_t *s1, wchar16_t *s2)
251 {
252 	wchar16_t c1, c2;
253 
254 	if (s1 == NULL)
255 		return(0);
256 	while (*s2 != '\0') {
257 		c1 = *s1++;
258 		c2 = *s2++;
259 		if (TOLOWER(WcLowByte(c1)) != TOLOWER(WcLowByte(c2)))
260 			return(0);
261 	}
262 	return(1);
263 }
264 
265 
266 int
getword(u_char * s,struct wordent word[])267 getword(u_char *s, struct wordent word[])
268 {
269 	u_char	c;
270 	wchar16_t *w;
271 	wchar16_t wcbuf[MAXLINE*2];
272 	wchar16_t ttmp[MAXLINE];
273 	u_char  buf[MAXLINE*2];
274 	u_char *p;
275 	int	i, wcount;
276 	u_short cc;
277 
278 	if (IsDelimitor(*s)) {
279 		s++;
280 	} else {
281 		p = s;
282 		while(!IsDelimitor(*s)) {
283 			if (IsTerminator(*s) || isTerminator(*s))
284 				break;
285 			s++;
286 		}
287 		*s++ = '\0';
288                 if (file_code == locale_code) {
289 			(void) mbstowcs(wcbuf, (char *)p, MAXLINE*2);
290 		} else {
291 			if (file_code == SJ3_SJIS) {
292 				(void) sjistoeuc(buf, MAXLINE*2, (u_char *)p, MAXLINE);
293 			} else if (file_code == SJ3_EUC) {
294 				(void) euctosjis(buf, MAXLINE*2, (u_char *)p, MAXLINE);
295 			} else {
296 				strlcpy(buf, p, sizeof(buf));
297 			}
298 			(void) mbstowcs(wcbuf, (char *)buf, MAXLINE*2);
299 		}
300                 (void) mbstowcs(ttmp, term_name, MAXLINE);
301 		if (match(wcbuf, ttmp) == 0)
302 			return(0);
303 	}
304 	i = wcount = 0;
305 	w = word[wcount].word_str;
306 	while (*s != '\0') {
307 		c = *s++;
308 		if (file_code == SJ3_SJIS) {
309 			if (issjis1(c) && issjis2(*s)) {
310 				if (i < MAXWORD - 1) {
311 					cc = (c << 8) + *s;
312 					*w++ = sjis2euc(cc);
313 					i ++ ;
314 				}
315 				s++;
316 				continue;
317 			}
318 		} else if (file_code == SJ3_EUC) {
319 			if (iseuc(c) && iseuc(*s)) {
320 				if (i < MAXWORD - 1) {
321 					*w++ = (c << 8) + (*s & 0xff);
322 					i ++;
323 				}
324 				s++;
325 				continue;
326 			}
327 			if (iseuckana(c) && iskana2(*s))
328 				c = *s++;
329                         if (IsEUCHojo(c) && iseuc(*s) && iseuc(s[1])) {
330                                 cc = WcSetX0212(*s, s[1]);
331 				*w++ = cc;
332                                 s += 2;
333 				continue;
334 			}
335 		} else {
336 			if (issjis1(c) && issjis2(*s)) {
337 				file_code = SJ3_SJIS;
338 				s--;
339 				continue;
340 			}
341 			if ((iseuc(c) && iseuc(*s)) ||
342 				(iseuckana(c) && iskana2(*s)) ||
343 			        (IsEUCHojo(c) && iseuc(*s) && iseuc(s[1]))) {
344 				file_code = SJ3_EUC;
345 				s--;
346 				continue;
347 			}
348 		}
349 		if (isTerminator(c))
350 			break;
351 		if (IsDelimitor(c)) {
352 			if (i > 0) {
353 				if (++wcount >= WORDN - 1)
354 					break;
355 				*w = '\0';
356 				i = 0;
357 				w = word[wcount].word_str;
358 			}
359 			continue;
360 		}
361 		if (IsEscape(c))
362 			c = *s++;
363 		if (IsTerminator(c))
364 			break;
365 		if (i < MAXWORD - 1) {
366 			*w++ = c;
367 			i++;
368 		}
369 	}
370 	*w = '\0';
371 	if (word[wcount].word_str[0] != '\0')
372 		word[++wcount].word_str[0] = '\0';
373 	return(wcount);
374 }
375 
376 int
IsTerminator(u_char c)377 IsTerminator(u_char c)
378 {
379 	if (c == '\n')
380 		return (1);
381 	else
382 		return (0);
383 }
384 
385 int
isTerminator(u_char c)386 isTerminator(u_char c)
387 {
388 	if (c == '#')
389 		return (1);
390 	else
391 		return (0);
392 }
393 
394 int
IsEscape(u_char c)395 IsEscape(u_char c)
396 {
397 	if (c == '\\')
398 		return (1);
399 	else
400 		return (0);
401 }
402 
403 int
IsDelimitor(u_char c)404 IsDelimitor(u_char c)
405 {
406 	if (c == ' ' || c == '\t' || c == '.')
407 		return (1);
408 	else
409 		return (0);
410 }
411 
412 int
set_forkshell(struct wordent word[])413 set_forkshell(struct wordent word[])
414 {
415 	if (word[1].word_str[0] != '\0' && shellprog[0] == '\0') {
416 /*
417  * Remove warning.
418  * Patched by Hidekazu Kuroki(hidekazu@cs.titech.ac.jp)		1996/8/10
419  */
420 		strlcpy(shellprog, (char *)word[1].word_str, sizeof(shellprog));
421 		shell_flag++;
422 	}
423 	return 0;
424 }
425 
426 int
set_intr(struct wordent word[])427 set_intr(struct wordent word[])
428 {
429 	int	c;
430 
431 	if (word[1].word_str[0] != '\0')
432 		if ((c = eval_key (word[1].word_str)) != -1)
433 			intr_code = c;
434 	return 0;
435 }
436 
437 int
set_delkey(struct wordent word[])438 set_delkey(struct wordent word[])
439 {
440 	int	c;
441 
442 	if (word[1].word_str[0] != '\0')
443 		if ((c = eval_key (word[1].word_str)) != -1)
444 			set_del (c);
445 	return 0;
446 }
447 
448 int
isintr(u_char c)449 isintr(u_char c)
450 {
451 	if (c == intr_code)
452 		return (1);
453 	else
454 		return (0);
455 }
456 
457 int
set_goto(struct wordent word[])458 set_goto(struct wordent word[])
459 {
460 	int	c;
461 
462 	if (word[1].word_str[0] != '\0')
463 		if ((c = eval_key (word[1].word_str)) != -1)
464 			goto_code[goto_num ++] = c;
465 	return 0;
466 }
467 
468 int
IsGoto(u_char c)469 IsGoto(u_char c)
470 {
471 	int	i;
472 
473 	for (i = 0 ; i < goto_num ; i ++) {
474 		if (c == goto_code[i])
475 			return (1);
476 	}
477 	return (0);
478 }
479 
480 int
set_trap(struct wordent word[])481 set_trap(struct wordent word[])
482 {
483 	int	c;
484 
485 	if (word[1].word_str[0] != '\0')
486 		if ((c = eval_key (word[1].word_str)) != -1)
487 			trap_code[trap_num ++] = c;
488 	return 0;
489 }
490 
491 int
IsTrap(u_char c)492 IsTrap(u_char c)
493 {
494 	int	i;
495 
496 	for (i = 0 ; i < trap_num ; i ++) {
497 		if (c == trap_code[i])
498 			return (1);
499 	}
500 	return (0);
501 }
502 
503 int
mode_key(int mode)504 mode_key(int mode)
505 {
506 	switch (mode) {
507 	case MODE_HALPHA:
508 		return (KEY_HALPHA);
509 		break;
510 	case MODE_ZALPHA:
511 		return (KEY_ZALPHA);
512 		break;
513 	case MODE_HKATA:
514 		return (KEY_HKATA);
515 		break;
516 	case MODE_ZKATA:
517 		return (KEY_ZKATA);
518 		break;
519 	case MODE_ZHIRA:
520 	default:
521 		return (KEY_ZHIRA);
522 		break;
523 	}
524 }
525 
526 int	Direct = 0;
527 
528 int
set_init_mode(struct wordent word[])529 set_init_mode(struct wordent word[])
530 {
531 	Conversion	*cv;
532 	int	i, j;
533 	wchar16_t	*p;
534 
535 	cv = GetConversion ();
536 	j = 1;
537 	p = word[j].word_str;
538 	while (*p != '\0') {
539 		if (match (p, WCBuff))
540 			cv->BuffMode = BUFF;
541 		else if (match (p, WCUnbuff))
542 			cv->BuffMode = UNBUFF;
543 		else if (match (p, WCDirect))
544 			Direct = 1;
545 		else {
546 			for (i = 0 ; i < 5 ; i ++) {
547 				if (match (p, mode_val[i].keyword)) {
548 					cv->Imode = mode_val[i].ivalue;
549 					break;
550 				}
551 			}
552 		}
553 		p = word[++j].word_str;
554 	}
555 	return 0;
556 }
557 
558 int
set_helpmenu(struct wordent word[])559 set_helpmenu(struct wordent word[])
560 {
561 	if (match (word[1].word_str, WCOff))
562 		HHlevel = Hlevel = 1;
563 	else if (match (word[1].word_str, WCOn))
564 		HHlevel = Hlevel = 2;
565 	return 0;
566 }
567 
568 int
set_defcode(struct wordent word[])569 set_defcode(struct wordent word[])
570 {
571 	wchar16_t *p;
572 	int i;
573 
574 	p = word[1].word_str;
575 	for (i = 0; i < 5; i++) {
576 		if (match(p, code_val[i].keyword)) {
577 			SetCode(code_val[i].ivalue);
578 			break;
579 		}
580 	}
581 	return 0;
582 }
583 
584 int
set_muhenkan(struct wordent word[])585 set_muhenkan(struct wordent word[])
586 {
587 	int	i;
588 	wchar16_t	*p;
589 
590 	p = word[1].word_str;
591 	for (i = 0 ; i < 5 ; i ++) {
592 		if (match (p, mode_val[i].keyword)) {
593 			def_muhenkan = mode_key (mode_val[i].ivalue);
594 			break;
595 		}
596 	}
597 }
598 
599 int
set_muedit(struct wordent word[])600 set_muedit(struct wordent word[])
601 {
602 	int	i;
603 	wchar16_t	*p;
604 
605 	p = word[1].word_str;
606 	for (i = 0 ; i < 5 ; i ++) {
607 		if (match (p, mode_val[i].keyword)) {
608 			def_muedit = mode_key (mode_val[i].ivalue);
609 			break;
610 		}
611 	}
612 	return 0;
613 }
614 
615 int
set_m_toggle(struct wordent word[])616 set_m_toggle(struct wordent word[])
617 {
618 	if (match (word[1].word_str, WCOn))
619 		muhenkan_toggle = 1;
620 	if (match (word[1].word_str, WCOff))
621 		muhenkan_toggle = 0;
622 	return 0;
623 }
624 
625 int
set_silent(struct wordent word[])626 set_silent(struct wordent word[])
627 {
628 	vflag = 0;
629 	return 0;
630 }
631 
632 int
set_bstudy(struct wordent word[])633 set_bstudy(struct wordent word[])
634 {
635 	if (match (word[1].word_str, WCOn))
636 		bstudy = 1;
637 	if (match (word[1].word_str, WCOff))
638 		bstudy = 0;
639 	return 0;
640 }
641 
642 int
is_bstudy()643 is_bstudy()
644 {
645 	return (bstudy);
646 }
647 
648 int
eval_muhenkan()649 eval_muhenkan()
650 {
651 	Conversion	*cv;
652 
653 	cv = GetConversion ();
654 	if (muhenkan_toggle && (KEY_ZHIRA != mode_key (cv->Imode)))
655 		return (KEY_ZHIRA);
656 	else
657 		return (def_muhenkan);
658 }
659 
660 int
value_muhenkan()661 value_muhenkan()
662 {
663 	return (def_muedit);
664 }
665 
666 int
set_guide(struct wordent word[])667 set_guide(struct wordent word[])
668 {
669 	int	i;
670 
671 	if (*word[2].word_str == '\0') {
672 		return;
673 	}
674 	else if (match (word[1].word_str, WCSj2)) {
675 		wscpy (guide_sj2, word[2].word_str);
676 		WCSJrun = guide_sj2;
677 	}
678 	else if (match (word[1].word_str, WCBuffer)) {
679 		wscpy (guide_buffer, word[2].word_str);
680 		WCMode_buff = guide_buffer;
681 	}
682 	else if (match (word[1].word_str, WCUnbuffer)) {
683 		wscpy (guide_unbuffer, word[2].word_str);
684 		WCMode_unbuff = guide_unbuffer;
685 	}
686 	else if (match (word[1].word_str, WCHira)) {
687 		wscpy (guide_hira, word[2].word_str);
688 		WCMode_Zhira = guide_hira;
689 	}
690 	else if (match (word[1].word_str, WCZkata)) {
691 		wscpy (guide_zkata, word[2].word_str);
692 		WCMode_Zkata = guide_zkata;
693 	}
694 	else if (match (word[1].word_str, WCHkata)) {
695 		wscpy (guide_hkata, word[2].word_str);
696 		WCMode_Hkata = guide_hkata;
697 	}
698 	else if (match (word[1].word_str, WCHalpha)) {
699 		wscpy (guide_halpha, word[2].word_str);
700 		WCMode_Halpha = guide_halpha;
701 	}
702 	else if (match (word[1].word_str, WCZalpha)) {
703 		wscpy (guide_zalpha, word[2].word_str);
704 		WCMode_Zalpha = guide_zalpha;
705 	}
706 	else if (match (word[1].word_str, WCShift)) {
707 		wscpy (guide_shift, word[2].word_str);
708 		WCGCshift = guide_shift;
709 	}
710 	else if (match (word[1].word_str, WCJis)) {
711 		wscpy (guide_jis, word[2].word_str);
712 		WCGCjis = guide_jis;
713 	}
714 	else if (match (word[1].word_str, WCJis2)) {
715 		wscpy (guide_jis2, word[2].word_str);
716 		WCGCjis2 = guide_jis2;
717 	}
718 	else if (match (word[1].word_str, WCKuten)) {
719 		wscpy (guide_kuten, word[2].word_str);
720 		WCGCkuten = guide_kuten;
721 	}
722 	else if (match (word[1].word_str, WCKuten2)) {
723 		wscpy (guide_kuten2, word[2].word_str);
724 		WCGCkuten2 = guide_kuten2;
725 	}
726 	else if (match (word[1].word_str, WCEuc)) {
727 		wscpy (guide_euc, word[2].word_str);
728 		WCGCeuc = guide_euc;
729 	}
730 	else if (match (word[1].word_str, WCEuc2)) {
731 		wscpy (guide_euc2, word[2].word_str);
732 		WCGCeuc2 = guide_euc2;
733 	}
734 	else if (match (word[1].word_str, WCEtc)) {
735 		wscpy (guide_etc, word[2].word_str);
736 		WCGEtc = guide_etc;
737 	}
738 	else if (match (word[1].word_str, WCFuncetc)) {
739 		i = 2;
740 		*guide_etcfunc = '\0';
741 		while (*word[i].word_str != '\0') {
742 			if (i == 2)
743 				wscat (guide_etcfunc, WCSpace2);
744 			else
745 				wscat (guide_etcfunc, WCSpace);
746 			wscat (guide_etcfunc, word[i].word_str);
747 			i ++;
748 		}
749 		WCGetc = guide_etcfunc;
750 	}
751 	else if (match (word[1].word_str, WCFunction)) {
752 		i = 2;
753 		*guide_function = '\0';
754 		while (*word[i].word_str != '\0') {
755 			if (i == 2)
756 				wscat (guide_function, WCSpace2);
757 			else
758 				wscat (guide_function, WCSpace);
759 			wscat (guide_function, word[i].word_str);
760 			i ++;
761 		}
762 		WCGmode = guide_function;
763 	}
764 	return 0;
765 }
766 
767 int
set_flush_conversion(struct wordent word[])768 set_flush_conversion(struct wordent word[])
769 {
770 	if (match (word[1].word_str, WCOn))
771 		flush_conversion = 1;
772 	if (match (word[1].word_str, WCOff))
773 		flush_conversion = 0;
774 	return 0;
775 }
776 
777 int
set_server(struct wordent word[])778 set_server(struct wordent word[])
779 {
780 	int i, j, size;
781 	char *p;
782         char *sbuf;
783 	char host[LONGLENGTH];
784 
785         if (cur_serv != NULL && *cur_serv != '\0')
786                 return;
787         size = 0;
788         i = 0;
789         while (word[i + 1].word_str[0] != '\0') {
790                 if (i >= MAXSERVER)
791                         break;
792                 size += wslen(word[++i].word_str);
793                 size++;
794         }
795         if ((sbuf = malloc(size)) == NULL) {
796                 fprintf (stderr, "set_server: can't alloc memory\n\r");
797                 done3();
798         }
799         p = sbuf;
800         for (j = 0; j < i; j++) {
801                 serv_list[j] = p;
802 		(void) wcstombs(host, word[j+1].word_str, LONGLENGTH);
803                 strlcpy(p, host, strlen(p));
804                 size = strlen(p) + 1;
805                 p += size;
806         }
807         cur_serv = serv_list[0];
808 	return 0;
809 }
810 
811 #define DICT_SUFFIX ".dic"
812 
813 int
set_dict(struct wordent word[])814 set_dict(struct wordent word[])
815 {
816 	int i, j, size, suffix_len;
817 	char *p;
818         char *sbuf;
819 	char dict[LONGLENGTH];
820 	int rest;
821 
822 	suffix_len = strlen(DICT_SUFFIX);
823         size = 0;
824         i = 0;
825         while (word[i + 1].word_str[0] != '\0') {
826                 size += wslen(word[++i].word_str) + suffix_len;
827                 size++;
828         }
829         if ((sbuf = malloc(size)) == NULL) {
830                 fprintf (stderr, "set_dict: can't alloc memory\n\r");
831                 done3();
832         }
833 	if ((dict_list = (char **)malloc(sizeof(char *) * i)) == NULL) {
834 		free(sbuf);
835                 fprintf (stderr, "set_dict: can't alloc memory\n\r");
836                 done3();
837         }
838 	dict_num = i;
839         p = sbuf;
840 	rest = size;
841         for (j = 0; j < i; j++) {
842                 dict_list[j] = p;
843 		(void) wcstombs(dict, word[j+1].word_str, LONGLENGTH);
844 		snprintf(p, rest, "%s%s", dict, DICT_SUFFIX);
845                 size = strlen(p) + 1;
846 		rest -= size;
847                 p += size;
848         }
849 	return 0;
850 }
851