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__)
24 static char rcs_id[] = "@(#) 102.1 $Id: ulmount.c,v 1.3 2003/09/17 08:50:53 aida_s Exp $";
25 #endif
26 
27 #ifndef NO_EXTEND_MENU
28 #include	<errno.h>
29 #include 	"canna.h"
30 
31 #ifdef luna88k
32 extern int errno;
33 #endif
34 
35 /*********************************************************************
36  *                      wchar_t replace begin                        *
37  *********************************************************************/
38 #ifdef wchar_t
39 # error "wchar_t is already defined"
40 #endif
41 #define wchar_t cannawc
42 
43 /* cfunc mountContext
44  *
45  * mountContext
46  *
47  */
48 static mountContext
newMountContext()49 newMountContext()
50 {
51   mountContext mcxt;
52 
53   if ((mcxt = (mountContext)calloc(1, sizeof(mountContextRec)))
54                                            == (mountContext)NULL) {
55 #ifndef CODED_MESSAGE
56     jrKanjiError = "malloc (newMountContext) �Ǥ��ޤ���Ǥ���";
57 #else
58     jrKanjiError = "malloc (newMountContext) \244\307\244\255\244\336\244\273"
59 	"\244\363\244\307\244\267\244\277";
60 #endif
61     return (mountContext)NULL;
62   }
63   mcxt->id = MOUNT_CONTEXT;
64 
65   return mcxt;
66 }
67 
68 static void
freeMountContext(mc)69 freeMountContext(mc)
70 mountContext mc;
71 {
72   if (mc) {
73     if (mc->mountList) {
74       if (*(mc->mountList)) {
75 	free(*(mc->mountList));
76       }
77       free(mc->mountList);
78     }
79     if (mc->mountOldStatus) {
80       free(mc->mountOldStatus);
81     }
82     if (mc->mountNewStatus) {
83       free(mc->mountNewStatus);
84     }
85     free(mc);
86   }
87 }
88 
89 /*
90  * ��������Ԥ���
91  */
getMountContext(d)92 getMountContext(d)
93 uiContext d;
94 {
95   mountContext mc;
96   int retval = 0;
97 
98   if (pushCallback(d, d->modec,
99                    NO_CALLBACK, NO_CALLBACK,
100                    NO_CALLBACK, NO_CALLBACK) == 0) {
101 #ifndef CODED_MESSAGE
102     jrKanjiError = "malloc (pushCallback) �Ǥ��ޤ���Ǥ���";
103 #else
104     jrKanjiError = "malloc (pushCallback) \244\307\244\255\244\336\244\273"
105 	"\244\363\244\307\244\267\244\277";
106 #endif
107     return(NG);
108   }
109 
110   if((mc = newMountContext()) == (mountContext)NULL) {
111     popCallback(d);
112     return(NG);
113   }
114   mc->majorMode = d->majorMode;
115   mc->next = d->modec;
116   d->modec = (mode_context)mc;
117 
118   mc->prevMode = d->current_mode;
119 
120   return(retval);
121 }
122 
123 void
popMountMode(d)124 popMountMode(d)
125 uiContext d;
126 {
127   mountContext mc = (mountContext)d->modec;
128 
129   d->modec = mc->next;
130   d->current_mode = mc->prevMode;
131   freeMountContext(mc);
132 }
133 
134 static struct dicname *
findDic(s)135 findDic(s)
136 char *s;
137 {
138   extern struct dicname *kanjidicnames;
139   struct dicname *dp;
140 
141   for (dp = kanjidicnames ; dp ; dp = dp->next) {
142     if (!strcmp(s, dp->name)) {
143       return dp;
144     }
145   }
146   return (struct dicname *)0;
147 }
148 
149 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
150  * ����Υޥ���ȡ�����ޥ����                                              *
151  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
152 
153 static
uuMountExitCatch(d,retval,env)154 uuMountExitCatch(d, retval, env)
155 uiContext d;
156 int retval;
157 mode_context env;
158 /* ARGSUSED */
159 {
160   mountContext mc;
161   int i, nmount = 0;
162   extern defaultContext;
163   struct dicname *dp;
164 
165   killmenu(d);
166   popCallback(d); /* OnOff ��ݥå� */
167 
168   if(defaultContext == -1) {
169     if((KanjiInit() != 0) || (defaultContext == -1)) {
170 #ifdef STANDALONE
171 #ifndef CODED_MESSAGE
172       jrKanjiError = "���ʴ����Ѵ��Ǥ��ޤ���";
173 #else
174       jrKanjiError = "\244\253\244\312\264\301\273\372\312\321\264\271\244\307\244\255\244\336\244\273\244\363";
175 #endif
176 #else
177 #ifndef CODED_MESSAGE
178       jrKanjiError = "���ʴ����Ѵ������Ф��̿��Ǥ��ޤ���";
179 #else
180       jrKanjiError = "\244\253\244\312\264\301\273\372\312\321\264\271\245\265"
181 	"\241\274\245\320\244\310\304\314\277\256\244\307\244\255\244\336"
182 	"\244\273\244\363";
183 #endif
184 #endif
185       popMountMode(d);
186       popCallback(d);
187       return(GLineNGReturn(d));
188     }
189   }
190 
191   mc = (mountContext)d->modec;
192   for(i=0; mc->mountList[i]; i++) {
193     if(mc->mountOldStatus[i] != mc->mountNewStatus[i]) {
194       if(mc->mountNewStatus[i]) {
195 	/* �ޥ���Ȥ��� */
196 	nmount++;
197 	if((retval = RkwMountDic(defaultContext, (char *)mc->mountList[i],
198 			    cannaconf.kojin ? PL_ALLOW : PL_INHIBIT)) == NG) {
199 	  if (errno == EPIPE) {
200 	    jrKanjiPipeError();
201 	  }
202 	  MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\336\245\246"
203 		"\245\363\245\310\244\313\274\272\307\324\244\267\244\336"
204 		"\244\267\244\277", 512);
205                        /* ����Υޥ���Ȥ˼��Ԥ��ޤ��� */
206 	}
207 	else if(d->contextCache != -1 &&
208 	  (retval = RkwMountDic(d->contextCache, (char *)mc->mountList[i],
209 			    cannaconf.kojin ? PL_ALLOW : PL_INHIBIT)) == NG) {
210 	  if (errno == EPIPE) {
211 	    jrKanjiPipeError();
212 	  }
213 	  MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\336\245\246"
214 		"\245\363\245\310\244\313\274\272\307\324\244\267\244\336"
215 		"\244\267\244\277", 512);
216                               /* ����Υޥ���Ȥ˼��Ԥ��ޤ��� */
217 	}
218 	else { /* ���� */
219 	  dp = findDic((char *)mc->mountList[i]);
220 	  if (!dp) {
221 	    dp = (struct dicname *)malloc(sizeof(struct dicname));
222 	    if (dp) {
223 	      dp->name = malloc(strlen((char *)mc->mountList[i]) + 1);
224 	      if (dp->name) {
225 		/* �ޥ���Ȥ�����Ĥϥꥹ�ȤˤĤʤ� */
226 		strcpy(dp->name, (char *)mc->mountList[i]);
227 		dp->dictype = DIC_PLAIN;
228 		/* dp->dicflag = DIC_NOT_MOUNTED; will be rewritten below */
229 		dp->next = kanjidicnames;
230 		kanjidicnames = dp;
231 	      }
232 	      else { /* malloc failed */
233 		free((char *)dp);
234 		dp = (struct dicname *)0;
235 	      }
236 	    }
237 	  }
238 	  if (dp) {
239 	    dp->dicflag = DIC_MOUNTED;
240 	  }
241 	}
242       } else {
243 	/* ����ޥ���Ȥ��� */
244 	nmount++;
245 	if((retval = RkwUnmountDic(defaultContext, (char *)mc->mountList[i]))
246 	   == NG) {
247 	  if (errno == EPIPE) {
248 	    jrKanjiPipeError();
249 	  }
250 	  MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\242\245\363"
251 		"\245\336\245\246\245\363\245\310\244\313\274\272\307\324"
252 		"\244\267\244\336\244\267\244\277", 512);
253                              /* ����Υ���ޥ���Ȥ˼��Ԥ��ޤ��� */
254 	}
255 	else if(d->contextCache != -1 &&
256 	  (retval = RkwUnmountDic(d->contextCache, (char *)mc->mountList[i]))
257 		== NG) {
258 	  if (errno == EPIPE) {
259 	    jrKanjiPipeError();
260 	  }
261 	  MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\242\245\363"
262 		"\245\336\245\246\245\363\245\310\244\313\274\272\307\324"
263 		"\244\267\244\336\244\267\244\277", 512);
264                              /* ����Υ���ޥ���Ȥ˼��Ԥ��ޤ��� */
265 	}
266 	else {
267 	  dp = findDic((char *)mc->mountList[i]);
268 	  if (dp) { /* ���ʤ餺�ʲ����̤�Ϥ� */
269 	    dp->dicflag = DIC_NOT_MOUNTED;
270 	  }
271 	}
272       }
273     }
274   }
275 
276   if(nmount)
277     makeAllContextToBeClosed(1);
278 
279   if(retval != NG)
280     MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\336\245\246\245\363"
281 	"\245\310\241\277\245\242\245\363\245\336\245\246\245\363\245\310"
282 	"\244\362\271\324\244\244\244\336\244\267\244\277", 512);
283            /* ����Υޥ���ȡ�����ޥ���Ȥ�Ԥ��ޤ��� */
284   else
285     MBstowcs(d->genbuf, "\274\255\275\361\244\316\245\336\245\246\245\363"
286 	"\245\310\241\277\245\242\245\363\245\336\245\246\245\363\245\310"
287 	"\244\313\274\272\307\324\244\267\244\336\244\267\244\277", 512);
288            /* ����Υޥ���ȡ�����ޥ���Ȥ˼��Ԥ��ޤ��� */
289   makeGLineMessage(d, d->genbuf, WStrlen(d->genbuf));
290 
291   popMountMode(d);
292   popCallback(d);
293   currentModeInfo(d);
294 
295   return(0);
296 }
297 
298 static
uuMountQuitCatch(d,retval,env)299 uuMountQuitCatch(d, retval, env)
300 uiContext d;
301 int retval;
302 mode_context env;
303 /* ARGSUSED */
304 {
305   popCallback(d); /* OnOff ��ݥå� */
306 
307   popMountMode(d);
308   popCallback(d);
309   currentModeInfo(d);
310 
311   return prevMenuIfExist(d);
312 }
313 
314 /*
315  * dicLbuf                dicLp       soldp   snewp
316  * ���������������������� ����������  ������  ������
317  * ��iroha\@fuzokugo\@k�� ��*iroha��  ��1 ��  ��1 ��
318  * ��atakana\@satoko\@s�� ��*fuzo ��  ��1 ��  ��1 ��
319  * ��oft\@\@...        �� ��*kata ��  ��0 ��  ��0 ��
320  * ��                  �� ��  :   ��  ��: ��  ��: ��
321  * ���������������������� ����������  ������  ������
322  * dicMbuf                dicMp
323  * ���������������������� ����������
324  * ��iroha\@fuzokugo\@s�� ��*iroha��
325  * ��atoko\@\@...      �� ��*fuzo ��
326  * ��                  �� ��*sato ��
327  * ��                  �� ��  :   ��
328  * ���������������������� ����������
329  */
330 static
getDicList(d)331 getDicList(d)
332 uiContext d;
333 {
334   mountContext mc = (mountContext)d->modec;
335   char *dicLbuf, dicMbuf[ROMEBUFSIZE];
336   char **dicLp, *dicMp[ROMEBUFSIZE/2];
337   char *wptr, **Lp, **Mp;
338   BYTE *sop, *snp, *soldp, *snewp;
339   int dicLc, dicMc, i;
340   extern defaultContext;
341 
342   if((dicLbuf = malloc(ROMEBUFSIZE)) == (char *)NULL) {
343 #ifndef CODED_MESSAGE
344     jrKanjiError = "malloc (getDicList) �Ǥ��ޤ���Ǥ���";
345 #else
346     jrKanjiError = "malloc (getDicList) \244\307\244\255\244\336\244\273";
347 #endif
348     return(NG);
349   }
350   if(defaultContext == -1) {
351     if((KanjiInit() != 0) || (defaultContext == -1)) {
352 #ifdef STANDALONE
353 #ifndef CODED_MESSAGE
354       jrKanjiError = "���ʴ����Ѵ��Ǥ��ޤ���";
355 #else
356       jrKanjiError = "\244\253\244\312\264\301\273\372\312\321\264\271\244\307\244\255\244\336\244\273\244\363";
357 #endif
358 #else
359 #ifndef CODED_MESSAGE
360       jrKanjiError = "���ʴ����Ѵ������Ф��̿��Ǥ��ޤ���";
361 #else
362       jrKanjiError = "\244\253\244\312\264\301\273\372\312\321\264\271"
363 	"\245\265\241\274\245\320\244\310\304\314\277\256\244\307\244\255"
364 	"\244\336\244\273\244\363";
365 #endif
366 #endif
367       free(dicLbuf);
368       return(NG);
369     }
370   }
371   if((dicLc = RkwGetDicList(defaultContext, (char *)dicLbuf, ROMEBUFSIZE))
372      < 0) {
373     if(errno == EPIPE)
374       jrKanjiPipeError();
375     jrKanjiError = "\245\336\245\246\245\363\245\310\262\304\307\275\244\312"
376 	"\274\255\275\361\244\316\274\350\244\352\275\320\244\267\244\313"
377 	"\274\272\307\324\244\267\244\336\244\267\244\277";
378                    /* �ޥ���Ȳ�ǽ�ʼ���μ��Ф��˼��Ԥ��ޤ��� */
379     free(dicLbuf);
380     return(NG);
381   }
382   if (dicLc == 0) {
383     jrKanjiError = "\245\336\245\246\245\363\245\310\262\304\307\275\244\312"
384 	"\274\255\275\361\244\254\302\270\272\337\244\267\244\336\244\273"
385 	"\244\363";
386                    /* �ޥ���Ȳ�ǽ�ʼ���¸�ߤ��ޤ��� */
387     free(dicLbuf);
388     return NG;
389   }
390   if((dicLp = (char **)calloc(dicLc + 1, sizeof(char *))) == (char **)NULL) {
391 #ifndef CODED_MESSAGE
392     jrKanjiError = "malloc (getDicList) �Ǥ��ޤ���Ǥ���";
393 #else
394     jrKanjiError = "malloc (getDicList) \244\307\244\255\244\336\244\273"
395 	"\244\363\244\307\244\267\244\277";
396 #endif
397     free(dicLbuf);
398     return(NG);
399   }
400   if((soldp = (BYTE *)malloc(dicLc + 1)) == (BYTE *)NULL) {
401 #ifndef CODED_MESSAGE
402     jrKanjiError = "malloc (getDicList) �Ǥ��ޤ���Ǥ���";
403 #else
404     jrKanjiError = "malloc (getDicList) \244\307\244\255\244\336\244\273"
405 	"\244\363\244\307\244\267\244\277";
406 #endif
407     free(dicLbuf);
408     free(dicLp);
409     return(NG);
410   }
411   if((snewp = (BYTE *)malloc(dicLc + 1)) == (BYTE *)NULL) {
412 #ifndef CODED_MESSAGE
413     jrKanjiError = "malloc (getDicList) �Ǥ��ޤ���Ǥ���";
414 #else
415     jrKanjiError = "malloc (getDicList) \244\307\244\255\244\336\244\273"
416 	"\244\363\244\307\244\267\244\277";
417 #endif
418     free(dicLbuf);
419     free(dicLp);
420     free((char *)soldp);
421     return(NG);
422   }
423   for(i = 0, wptr = dicLbuf; i < dicLc; i++) { /* buf ���� */
424     dicLp[i] = wptr;
425     while(*wptr++)
426       /* EMPTY */
427       ; /* NULL �ޤǥ����åפ���NULL �μ��ޤǥݥ�����ʤ�� */
428   }
429   dicLp[i] = (char *)NULL;
430 
431   if(defaultContext == -1) {
432     if((KanjiInit() != 0) || (defaultContext == -1)) {
433 #ifdef STANDALONE
434 #ifndef CODED_MESSAGE
435       jrKanjiError = "���ʴ����Ѵ��Ǥ��ޤ���";
436 #else
437       jrKanjiError = "\244\253\244\312\264\301\273\372\312\321\264\271\244\307\244\255\244\336\244\273\244\363";
438 #endif
439 #else
440 #ifndef CODED_MESSAGE
441       jrKanjiError = "���ʴ����Ѵ������Ф��̿��Ǥ��ޤ���";
442 #else
443       jrKanjiError = "\244\253\244\312\264\301\273\372\312\321\264\271"
444 	"\245\265\241\274\245\320\244\310\304\314\277\256\244\307\244\255"
445 	"\244\336\244\273\244\363";
446 #endif
447 #endif
448       free(dicLbuf);
449       free(dicLp);
450       free((char *)soldp);
451       return(NG);
452     }
453   }
454   if((dicMc = RkwGetMountList(defaultContext, (char *)dicMbuf, ROMEBUFSIZE)) <
455      0) {
456     if(errno == EPIPE)
457       jrKanjiPipeError();
458     jrKanjiError = "\245\336\245\246\245\363\245\310\244\267\244\306\244\244"
459 	"\244\353\274\255\275\361\244\316\274\350\244\352\275\320\244\267"
460 	"\244\313\274\272\307\324\244\267\244\336\244\267\244\277";
461                    /* �ޥ���Ȥ��Ƥ��뼭��μ��Ф��˼��Ԥ��ޤ��� */
462     free(dicLbuf);
463     free(dicLp);
464     free((char *)soldp);
465     free((char *)snewp);
466     return(NG);
467   }
468 
469   for(i = 0, wptr = dicMbuf ; i < dicMc ; i++) { /* buf ���� */
470     dicMp[i] = wptr;
471     while (*wptr++)
472       /* EMPTY */
473       ; /* NULL �ޤǥ����åפ���NULL �μ��ޤǥݥ�����ʤ�� */
474   }
475   dicMp[i] = (char *)NULL;
476 
477   for(i=0, sop=soldp, snp=snewp; i<dicLc; i++, sop++, snp++) {
478     *sop = 0;
479     *snp = 0;
480   }
481   for(Lp=dicLp, sop=soldp, snp=snewp; *Lp; Lp++, sop++, snp++) {
482     for(Mp=dicMp; *Mp; Mp++) {
483       if(!strcmp((char *)*Lp, (char *)*Mp)) {
484 	*sop = *snp = 1;
485 	break;
486       }
487     }
488   }
489   mc->mountList = dicLp;
490   mc->mountOldStatus = soldp;
491   mc->mountNewStatus = snewp;
492 
493   return(dicLc);
494 }
495 
dicMount(d)496 dicMount(d)
497 uiContext d;
498 {
499   ichiranContext oc;
500   mountContext mc;
501   int retval = 0, currentkouho = 0, nelem;
502   wchar_t *xxxx[100];
503   yomiContext yc = (yomiContext)d->modec;
504 
505   if (yc->generalFlags & CANNA_YOMI_CHGMODE_INHIBITTED) {
506     return NothingChangedWithBeep(d);
507   }
508   d->status = 0;
509 
510   if((retval = getMountContext(d)) == NG) {
511     killmenu(d);
512     return(GLineNGReturn(d));
513   }
514 
515   /* ����ꥹ�Ȥȥޥ���ȡ�����ޥ���Ȥξ��֤� montContext �ˤȤäƤ��� */
516   if((nelem = getDicList(d)) == NG) {
517     popMountMode(d);
518     popCallback(d);
519     killmenu(d);
520     return(GLineNGReturn(d));
521   }
522 
523   mc = (mountContext)d->modec;
524 #if defined(DEBUG)
525   if(iroha_debug) {
526     int i;
527 
528     printf("<��mount>\n");
529     for(i= 0; mc->mountList[i]; i++)
530       printf("[%s][%x][%x]\n", mc->mountList[i],
531 	     mc->mountOldStatus[i], mc->mountNewStatus[i]);
532     printf("\n");
533   }
534 #endif
535 
536   /* selectOnOff ��Ƥ֤���ν��� */
537   mc->curIkouho = currentkouho = 0;
538 
539   retval = setWStrings(xxxx, mc->mountList, 0);
540   if (retval == NG) {
541     popMountMode(d);
542     popCallback(d);
543     killmenu(d);
544     return GLineNGReturn(d);
545   }
546   if((retval = selectOnOff(d, xxxx, &mc->curIkouho, nelem,
547 		 BANGOMAX, currentkouho, mc->mountOldStatus,
548 		 NO_CALLBACK, uuMountExitCatch,
549 		 uuMountQuitCatch, uiUtilIchiranTooSmall)) == NG) {
550     popMountMode(d);
551     popCallback(d);
552     killmenu(d);
553     return GLineNGReturn(d);
554   }
555 
556   oc = (ichiranContext)d->modec;
557   oc->majorMode = CANNA_MODE_ExtendMode;
558   oc->minorMode = CANNA_MODE_MountDicMode;
559   currentModeInfo(d);
560 
561   /* ��������Ԥ������Ƹ���������Ф��ʤ� */
562   if(oc->tooSmall) {
563     wchar_t p[512];
564 
565     ichiranFin(d);
566     popCallback(d); /* OnOff ��ݥå� */
567     popMountMode(d);
568     popCallback(d);
569     currentModeInfo(d);
570     MBstowcs(p ,"\274\255\275\361\260\354\315\367\315\321\244\316\311\375"
571 		"\244\254\266\271\244\244\244\316\244\307\274\255\275\361"
572 		"\245\336\245\246\245\363\245\310\241\277\245\242\245\363"
573 		"\245\336\245\246\245\363\245\310\244\307\244\255\244\336"
574 		"\244\273\244\363",64);
575          /* ��������Ѥ����������ΤǼ���ޥ���ȡ�����ޥ���ȤǤ��ޤ��� */
576     makeGLineMessage(d, p, WStrlen(p));
577     killmenu(d);
578     return(0);
579   }
580 
581   makeGlineStatus(d);
582   /* d->status = ICHIRAN_EVERYTIME; */
583 
584   return(retval);
585 }
586 
587 #ifndef wchar_t
588 # error "wchar_t is already undefined"
589 #endif
590 #undef wchar_t
591 /*********************************************************************
592  *                       wchar_t replace end                         *
593  *********************************************************************/
594 
595 #endif /* NO_EXTEND_MENU */
596