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 #ifndef lint
24 static char rcs[] = "@(#) 112.1 $Id: can.c,v 1.4 2003/02/01 19:34:20 aida_s Exp $";
25 #endif
26 
27 #ifdef ENGINE_SWITCH
28 #include "RKrename.h"
29 #endif
30 #include "cannaconf.h"
31 #define CANNA_NEW_WCHAR_AWARE
32 
33 #include <stdio.h>
34 #include <signal.h>
35 #include <canna/RK.h>
36 #include <ctype.h>
37 #include <pwd.h>
38 #include <sys/types.h>
39 #include <grp.h>
40 #include "ccompat.h"
41 #ifdef __EMX__
42 #include <netdb.h>
43 #endif
44 
45 #if defined(__STDC__) || defined(SVR4)
46 #include <locale.h>
47 #endif
48 
49 #ifdef SVR4
50 extern  char *gettxt();
51 #else
52 #define	gettxt(x,y)  (y)
53 #endif
54 
55 #define TRUE 1
56 #define FALSE 0
57 #define RECSZ 256
58 #define ERR_VALUE 1
59 #define BUFLEN   1024
60 #define	STRCMP(d, s)	strcmp((char *)(d), (char *)(s))
61 #define NOT_OVER_WRITE 0
62 #define OVER_WRITE 1
63 
64 #ifdef SIGNALRETURNSINT
65 #define SIGVAL int
66 #else
67 #define SIGVAL void
68 #endif
69 
70 #ifdef USE_VARARGS
71 #ifdef __STDC__
72 extern  void Message(char *,...);
73 #else
74 extern  void Message();
75 #endif
76 #else
77 extern  void Message();
78 #endif
79 
80 
81 extern	RkDeleteLine();
82 extern	RkDefineLine();
83 extern	rmDitionary();
84 
85 char            init[RECSZ], *Progname;
86 unsigned char	*r_dic;
87 unsigned char   rm_dic[RECSZ];
88 int	cx_num, is_display, mode ,mode2;
89 unsigned char dicname[RECSZ];
90 static char *r_file;
91 unsigned  char dicname1[RECSZ], dicname2[RECSZ];
92 static int  majv, minv, protover;
93 static char     *hinshi ;
94 static char     msg_abnls[80], msg_abnl[80] , msg_sfq[80] ,msg_l[80];
95 
96 #define canna_protocol_version(ma, mi) ((ma) * 1024 + (mi))
97 #define canna_major_version(ver) ((ver) / 1024)
98 #define canna_minor_version(ver) ((ver) % 1024)
99 
100 static   int opt_cs ;
101 static   int opt_l  ;
102 static   int opt_r  ;
103 static   int opt_h  ;
104 static   int opt_i  ;
105 static   int opt_u  ;
106 static   int opt_s  ;
107 static   int opt_fq ;
108 static   int opt_std;
109 static   int opt_myg , opt_g , opt_rw , opt_v , opt_a ;
110 
111 static   char *opt_dic1 ;
112 static   char *opt_dic2 ;
113 static   char *opt_lfile ;
114 static   char *opt_user , *opt_grp ;
115 
116 /*-------------------------------------------------------------*/
117 
118 static int      cmd_code ;
119 #define    ADD    1
120 #define    CAT    2
121 #define    CP     3
122 #define    DEL    4
123 #define    LS     5
124 #define    MK     6
125 #define    MV     7
126 #define    RM     8
127 #define    CHMOD  9
128 #define    SY     10
129 #define    KILL   11
130 
131 /**************************************************************/
132 /*                         ���̴ؿ�                           */
133 /**************************************************************/
134 
135 void
usage()136 usage()
137 {
138 
139     switch ( cmd_code ) {
140 
141        case ADD :
142 
143     (void) fprintf(stderr, gettxt("cannacmd:53",
144 			  "Usage: %s [options]  remote-dic\n"),Progname);
145     (void) fprintf(stderr, gettxt("cannacmd:54", " options include:\n"));
146     (void) fprintf(stderr, gettxt("cannacmd:55",
147 			  "\t{-cs | -cannaserver} canna-server\n"));
148     (void) fprintf(stderr, gettxt("cannacmd:56", "\t-l local-file\n"));
149     break ;
150 
151        case    CAT :
152 
153     (void)fprintf(stderr,gettxt("cannacmd:71",
154    			"Usage: %s [options]  remote-dic\n"), Progname);
155     (void)fprintf(stderr,gettxt("cannacmd:72", " options:\n"));
156     (void)fprintf(stderr,gettxt("cannacmd:73",
157 			"        {-cs | -cannaserver} canna-server\n"));
158     (void)fprintf(stderr,gettxt("cannacmd:74", "        -i | -u user-name\n"));
159     (void)fprintf(stderr,gettxt("cannacmd:75", "        -l local-file\n"));
160     (void)fprintf(stderr,gettxt("cannacmd:234","        -G \n"));
161     (void)fprintf(stderr,gettxt("cannacmd:235","        -g group-name\n"));
162     break ;
163 
164        case    CP :
165 
166     (void)fprintf(stderr,gettxt("cannacmd:85",
167 			"Usage: %s [options]  from-dic to-dic\n"), Progname);
168     (void)fprintf(stderr,gettxt("cannacmd:86", " options:\n"));
169     (void)fprintf(stderr,gettxt("cannacmd:87",
170 			"        {-cs | -cannaserver} canna-server\n"));
171     (void)fprintf(stderr,gettxt("cannacmd:88", "        -s\n"));
172     (void)fprintf(stderr,gettxt("cannacmd:89", "        -i | -u user-name\n"));
173     (void)fprintf(stderr,gettxt("cannacmd:236","        -G \n"));
174     (void)fprintf(stderr,gettxt("cannacmd:237","        -g group-name\n"));
175     break ;
176 
177        case    DEL :
178 
179     (void) fprintf(stderr, gettxt("cannacmd:102",
180 			  "Usage: %s [options]  remote-dic\n"),Progname);
181     (void) fprintf(stderr, gettxt("cannacmd:103", " options:\n"));
182     (void) fprintf(stderr, gettxt("cannacmd:104",
183 			  "\t{-cs | -cannaserver} canna-server\n"));
184     (void) fprintf(stderr, gettxt("cannacmd:105", "\t-l local-file\n"));
185     break ;
186 
187        case    LS :
188 
189     (void)fprintf(stderr,gettxt("cannacmd:121",
190 			"Usage: %s [options]\n"), Progname);
191     (void)fprintf(stderr,gettxt("cannacmd:122", " options:\n"));
192     (void)fprintf(stderr,gettxt("cannacmd:123",
193 			"        {-cs | -cannaserver} canna-server\n"));
194     (void)fprintf(stderr,gettxt("cannacmd:124", "        -i\n"));
195     (void)fprintf(stderr,gettxt("cannacmd:125", "        -u user-name\n"));
196     (void)fprintf(stderr,gettxt("cannacmd:238", "        -G \n"));
197     (void)fprintf(stderr,gettxt("cannacmd:239", "        -g group-name\n"));
198     (void)fprintf(stderr,gettxt("cannacmd:240", "        -a \n"));
199     (void)fprintf(stderr,gettxt("cannacmd:241", "        -l \n"));
200     break ;
201 
202        case     MK :
203 
204     (void) fprintf(stderr, gettxt("cannacmd:134",
205 			  "Usage: %s [options]  remote-dic\n"),Progname);
206     (void) fprintf(stderr, gettxt("cannacmd:135", " options:\n"));
207     (void) fprintf(stderr, gettxt("cannacmd:136",
208 			  "\t{-cs | -cannaserver} canna-server\n"));
209     (void) fprintf(stderr, gettxt("cannacmd:137", "\t-s\n"));
210     (void) fprintf(stderr, gettxt("cannacmd:138", "\t{- | -l local-file}\n"));
211     (void) fprintf(stderr, gettxt("cannacmd:139", "\t-fq\n"));
212     (void) fprintf(stderr, gettxt("cannacmd:242", "\t-G  \n"));
213     break ;
214 
215        case     MV :
216 
217     (void)fprintf(stderr,gettxt("cannacmd:155",
218 			"Usage: %s [options]  from-dic to-dic\n"), Progname);
219     (void)fprintf(stderr,gettxt("cannacmd:156", " options:\n"));
220     (void)fprintf(stderr,gettxt("cannacmd:157",
221 			"        {-cs | -cannaserver} canna-server\n"));
222     (void)fprintf(stderr,gettxt("cannacmd:243", "        -G \n"));
223     (void)fflush(stderr);
224     break ;
225 
226        case     RM :
227 
228     (void)fprintf(stderr,gettxt("cannacmd:177",
229 		"Usage: %s [options]  dicname1 [dicname2...]\n"), Progname);
230     (void)fprintf(stderr,gettxt("cannacmd:178", " options:\n"));
231     (void)fprintf(stderr,gettxt("cannacmd:179",
232 			"        {-cs | -cannaserver} canna-server\n"));
233     (void)fprintf(stderr,gettxt("cannacmd:180", "         -fq \n"));
234     (void)fprintf(stderr,gettxt("cannacmd:244", "         -G \n"));
235     break ;
236 
237        case     CHMOD :
238 
239     (void)fprintf(stderr,gettxt("cannacmd:245",
240 		"Usage: %s [options]  dicname \n"), Progname);
241     (void)fprintf(stderr,gettxt("cannacmd:246", " options:\n"));
242     (void)fprintf(stderr,gettxt("cannacmd:247",
243 			"        {-cs | -cannaserver} canna-server\n"));
244     (void)fprintf(stderr,gettxt("cannacmd:248",
245                         "        {+|-}{r|w|rw|wr}... \n"));
246     (void)fprintf(stderr,gettxt("cannacmd:249", "        -G \n"));
247     break ;
248 
249        case     SY :
250 
251     (void)fprintf(stderr,gettxt("cannacmd:999",
252 		"Usage: %s [options]   \n"),Progname);
253     (void)fprintf(stderr,gettxt("cannacmd:999", " options:\n"));
254     (void)fprintf(stderr,gettxt("cannacmd:999",
255 			"        {-cs | -cannaserver} canna-server\n"));
256     break ;
257 
258        case     KILL :
259     (void)fprintf(stderr,gettxt("cannacmd:257","Usage: %s    \n"),Progname);
260     break ;
261 
262     }
263     (void)fflush(stderr);
264     exit(ERR_VALUE);
265 
266 }
267 
268 static SIGVAL
StopAll(sig)269 StopAll(sig)
270 int sig;
271 /* ARGSUSED */
272 {
273 #ifdef DEBUG
274     Message("StopAll: Caught signal, Quit addwords and do nothing");
275 #endif
276     (void) signal(SIGINT,  SIG_IGN);
277     (void) signal(SIGQUIT, SIG_IGN);
278     (void) signal(SIGTERM, SIG_IGN);
279     /*
280      * Shutting down and close connection with server.
281      */
282     (void) RkFinalize();
283     fprintf(stderr,"\n");
284     Message(gettxt("cannacmd:232", "Process was intrrupted."));
285     exit(ERR_VALUE);
286 }
287 
288 static SIGVAL
RefreshAll(sig)289 RefreshAll(sig)
290 int sig;
291 /* ARGSUSED */
292 {
293 #ifdef DEBUG
294     Message("RefreshAll: Caught signal, Shutting down addwords.");
295 #endif
296     (void) signal(SIGINT,  SIG_IGN);
297     (void) signal(SIGQUIT, SIG_IGN);
298     (void) signal(SIGTERM, SIG_IGN);
299 
300     if (cmd_code == CAT ) {
301 	if (STRCMP(r_file,"")) {
302 	    unlink(r_file);
303 	}
304     }
305     /*
306      * Shutting down and close old connection with server.
307      */
308     (void) RkUnmountDic(cx_num, (char *)r_dic);
309     (void) RkFinalize();
310 
311     /*
312      * Restart new connection with server and add dic.
313      */
314     cx_num = RkInitialize(init);
315     if (cx_num == 0) {
316 	if (cmd_code == CP || cmd_code == MK) {
317 	    if (mode & KYOUSEI) {
318 		(void) RkCreateDic(cx_num, r_dic, mode);
319 	    } else {
320 		(void) rmDictionary(cx_num, r_dic , mode );
321 	    }
322 	}
323 	(void) RkFinalize();
324     }
325 
326     Message(gettxt("cannacmd:232", "Process was intrrupted."));
327     exit(ERR_VALUE);
328 }
329 
330 
331 int
rk_init()332 rk_init()
333 {
334     if ((cx_num = RkInitialize(init)) < 0 ) {
335 	if (init[0] != '/') {
336 	    (void)fprintf(stderr,gettxt("cannacmd:67",
337 		"Cannot connect with cannaserver \"%s\".\n"), init);
338 	}
339 	else {
340 	    (void)fprintf(stderr, gettxt("cannacmd:68",
341 		 "Cannot connect with cannaserver.\n"));
342 	}
343 	exit(ERR_VALUE);
344     }
345     return(0);
346 }
347 
348 int
nwcheck()349 nwcheck()
350 {
351     int   bak ;
352     RkwGetProtocolVersion(&majv, &minv);
353     protover = canna_protocol_version(majv, minv);
354     bak = RkwGetServerVersion(&majv, &minv);
355     if ( bak < 0 ) { /* �����Фξ��֤��۾� */
356 	if (init[0] != '/') {
357 	    (void)fprintf(stderr,gettxt("cannacmd:80",
358 		   "Cannaserver \"%s\" is in an abnormal state.\n"), init);
359 	}
360 	else {
361 	    (void)fprintf(stderr,
362 	      gettxt("cannacmd:81", "Cannaserver is in an abnormal state.\n"));
363 	}
364 	RkFinalize();
365 	exit(ERR_VALUE);
366     }
367     if ( majv < 2 && minv < 2 ) { /* irohaserver && R7.1����� */
368 	    if (init[0] != '/') {
369 		(void)fprintf(stderr, gettxt("cannacmd:82",
370 	     "Cannaserver \"%s\" does not support dictionary maintenance.\n")
371 		      , init);
372 	    }
373 	    else {
374 	    (void)fprintf(stderr, gettxt("cannacmd:83",
375 	   "Cannaserver does not support dictionary maintenance.\n"));
376 	    }
377 	    RkFinalize();
378 	    exit(ERR_VALUE);
379     }
380     return(0);
381 }
382 
383 static int
ParseFile(fp)384 ParseFile(fp)
385   FILE	*fp;
386 {
387     char line[BUFLEN], *whinp ;
388     int ret = -1 ;
389     int werr , i , hflg , hlen , lineno ;
390 
391     hflg = 0 ;
392     werr = 0 ;
393     lineno = 0 ;
394     if (is_display != TRUE) {
395 	(void) fprintf(stderr, "\n");
396     }
397     if ( hinshi != NULL ) {
398       hflg = 1 ;
399       hlen = strlen(hinshi);
400     }
401     while (fgets((char *)line, sizeof(line), fp)) {
402         if (line[strlen(line) - 1] == '\n')
403 	  line[strlen(line)-1] = '\0';
404 	lineno++ ;
405 	if ( hflg ) {     /* 92.12.21 */
406 	    whinp = index(line,'#') ;
407 	    if (whinp == NULL) continue ;
408 	    if (strncmp(whinp,hinshi,hlen) != 0 ||
409 	        (whinp[hlen] != ' ' && whinp[hlen] != '\t' &&
410 		 whinp[hlen] != '*' ) ) continue ;
411 	}
412 
413 	if (strlen(line) == (BUFLEN-1) ) {
414 	    werr = 1;
415 	}
416 	else {
417 	  if (cmd_code == DEL) {
418 	    i = RkDeleteLine(cx_num, r_dic, line) ;
419 	  }
420 	  else {
421 	    i = RkDefineLine(cx_num, r_dic, line) ;
422 	  }
423 	  if (i == -1) {
424 	    Message(gettxt("cannacmd:59", "write error \"%s\""), line);
425 	  }
426 	  else if (i == -2) {
427 	    Message(gettxt("cannacmd:60",
428 		   "Nomination length is too long. \"%s\""),line);
429 	  }
430 	  else if (i == -3) {
431 	    Message(gettxt("cannacmd:61",
432 		   "Reading or nomination length is too long.\"%s\""), line);
433 	  }
434 	  if ((is_display == TRUE) &&
435 	     ((++ret & 0x0f) == 0)) {
436 	     (void) fputs(".", stderr);
437 	  }
438         }
439     }
440     Message("");
441     if (werr == 1) {
442 	Message(gettxt("cannacmd:233", "too long line at %d"),lineno);
443     }                                  /* message add  93.03.18 */
444     RkSync(cx_num, (char *)r_dic);
445     return (0);
446 }
447 
448 void
dicname_chk(dic)449 dicname_chk(dic)
450 char  *dic ;
451 {
452     if ((unsigned char *)index(dic, '-' )) {
453 	Message(gettxt("cannacmd:64",
454 	       "Cannot use character \"-\" for dictionary name."));
455 	exit(ERR_VALUE);
456     }
457     if ((int)strlen((char *)dic) >= RECSZ) {
458 	Message(gettxt("cannacmd:65",
459 	       "Dictionary name \"%s\" is too long."), dic);
460 	exit(ERR_VALUE);
461     }
462 }
463 
464 /*  ���롼��̾ ����   */
465 char *
searchgroup()466 searchgroup()
467 {
468     char *groupname = NULL ;
469 
470     struct passwd *pass = getpwuid( getuid() );
471     if ( pass ) {
472 	struct group *grp = getgrgid(pass -> pw_gid);
473 	if ( grp ) {
474 	    groupname = grp -> gr_name;
475 	}
476     }
477     if (groupname == NULL) {
478 	(void)fprintf(stderr,gettxt("cannacmd:250","invalid group name\n"));
479 	exit(ERR_VALUE);
480     }
481     return(groupname);
482 }
483 
484 
485 /*
486  * �桼��̾���� ������=̾���ؤΥݥ���
487  */
488 static char *
searchuname()489 searchuname()
490 {
491     char *username = NULL, *getenv(), *getlogin() ;
492 
493     struct passwd *pass = getpwuid( getuid() ) ;
494     if ( pass ) username = pass->pw_name ;
495 
496     if ( username == NULL ) {
497 	if( (username = getlogin()) == NULL ) {
498 	    if( (username = getenv( "LOGNAME" )) == NULL ) {
499 		  username = getenv( "USER" ) ;
500 	    }
501 	}
502     }
503     if ( username == NULL ) {
504 	(void)fprintf(stderr,gettxt("cannacmd:251","invalid user name\n"));
505 	exit(ERR_VALUE);
506     }
507     return( username ) ;
508 }
509 
510 
511 /* addwords delwords �Ǽ���� write�������뤫������å����� */
512 static void
write_chk()513 write_chk()
514 {
515     int mode ,ret;
516     mode = 0 ;
517  grp:
518     ret = RkChmodDic(cx_num,opt_dic1,mode) ;
519     if (ret < 0) {
520 	switch (ret) {
521           case NOENT:
522 	            /* �桼������ˤʤ���Х��롼�׼�����Ƥߤ�*/
523 	    if (mode == 0) {
524 		mode = RK_GRP_DIC ;
525 		goto grp ;
526 	    }
527 	    fprintf(stderr,gettxt("cannacmd:169",
528 		  "Dictionary \"%s\" does not exist.\n"), opt_dic1);
529 	    break;
530           case BADCONT:
531 	    fprintf(stderr,gettxt(
532 		  "cannacmd:176","Illegal context value was used.\n"));
533 	    break;
534           case ACCES:
535 	    fprintf(stderr,gettxt(
536 		  "cannacmd:171", "Cannot access to dictionary.\n"));
537 	    break;
538           case NOTALC:
539 	    fprintf(stderr, gettxt("cannacmd:168", "No more memory.\n"));
540 	    break;
541           case -1:
542 	    return;   /* �쥵���Фϥ����å�����OK */
543           default:
544 	    fprintf(stderr, gettxt("cannacmd:252",
545 		   "Invalid return code RkChmoddic  code=%d \n"),ret);
546 	    break;
547 	}
548 	RkFinalize();
549 	exit(ERR_VALUE);
550     }
551     if (( ret & RK_ENABLE_WRITE)  == RK_ENABLE_WRITE ) {
552 	return;
553     }
554     fprintf(stderr,gettxt(
555 		  "cannacmd:171", "Cannot access to dictionary.\n"));
556     RkFinalize();
557     exit(ERR_VALUE);
558 }
559 
560 /* mkdic mvdic  �ǥ����Х饤�Ȥ���� write�������뤫������å����� */
ovwrite_chk(dicname,mode)561 ovwrite_chk(dicname,mode)
562 char *dicname;
563 int mode;
564 {
565     int ret;
566     ret = RkChmodDic(cx_num,dicname,mode) ;
567     if (ret < 0) {
568 	switch (ret) {
569           case NOENT:
570 	            /* �����ʤ��ʤ�OK */
571 	    return(0);
572           case BADCONT:
573 	    fprintf(stderr,gettxt(
574 		  "cannacmd:176","Illegal context value was used.\n"));
575 	    break;
576           case ACCES:
577 	    fprintf(stderr,gettxt(
578 		  "cannacmd:171", "Cannot access to dictionary.\n"));
579 	    break;
580           case NOTALC:
581 	    fprintf(stderr, gettxt("cannacmd:168", "No more memory.\n"));
582 	    break;
583           case -1:
584 	    return(0);   /* �쥵���Фϥ����å�����OK */
585           default:
586 	    fprintf(stderr, gettxt("cannacmd:252",
587 		   "Invalid return code RkChmoddic  code=%d \n"),ret);
588 	    break;
589 	}
590 	return(ERR_VALUE);
591     }
592     if (( ret & RK_ENABLE_WRITE)  == RK_ENABLE_WRITE ) {
593 	return(0);
594     }
595     fprintf(stderr,gettxt(
596 		  "cannacmd:256", "Cannot access to dictionary.\n"));
597     return(ERR_VALUE);
598 }
599 
600 /**************************************************************/
601 /*                        addwords                            */
602 /**************************************************************/
603 
604 static int
Addwords(fp)605 Addwords(fp)
606   FILE	*fp;
607 {
608     int  ret ;
609     if (RkMountDic(cx_num, (char *)r_dic, 0) < 0 ) {
610 	(void) Message(gettxt("cannacmd:63",
611 		      "Cannot mount dictionary \"%s\"."), r_dic);
612 	return (-1);
613     }
614     ret = ParseFile(fp);
615     RkUnmountDic(cx_num, (char *)r_dic);
616     return (ret);
617 }
618 
add_main(argc,argv)619 add_main (argc,argv)
620 int   argc  ;
621 char  **argv;
622 {
623     FILE	*fp;
624     char	*l_file = NULL;
625 
626     mode = Rk_MWD;
627     is_display = FALSE;
628     hinshi = NULL ;
629 
630     scan_opt(argc,argv,&argv);
631 
632     if (opt_i || opt_u || opt_s || opt_fq||opt_std||opt_myg||opt_g) usage();
633     if (opt_dic2 != NULL) usage();
634 
635     if (opt_l)  l_file = opt_lfile ;
636     r_dic = (unsigned char *)opt_dic1 ;
637 
638     if (isatty(fileno(stdout)) == 0) {
639       is_display = TRUE;
640     }
641     if (!l_file) {
642 	fp = stdin;
643     } else {
644         is_display = TRUE ;
645 	fp = (FILE *)fopen(l_file, "r");
646 	if (!fp) {
647 	    Message(gettxt("cannacmd:66",
648 		   "%s: cannot open \"%s\""), Progname, l_file);
649 	    exit(ERR_VALUE);
650 	}
651     }
652 
653     rk_init() ;
654     write_chk();
655 
656     if (Addwords(fp) == -1) {
657 	if (l_file)
658 	    (void) fclose(fp);
659 	(void) RkFinalize();
660 	exit(ERR_VALUE);
661     }
662     (void) RkFinalize();
663     Message(gettxt("cannacmd:69", "Addwords has done on \"%s\"."), r_dic);
664     exit (0);
665 }
666 
667 
668 /**************************************************************/
669 /*                        catdic                              */
670 /**************************************************************/
671 
cat_main(argc,argv)672 cat_main(argc,argv)
673 int   argc  ;
674 char  **argv;
675 {
676     FILE *fopen(), *fp = stdout;
677     unsigned char dirname[RECSZ*2];  /* �桼��̾�ޤ���"iroha"�ޤ���NULL*/
678     unsigned char filename[RECSZ*2]; /* �ե�����̾�ޤ���NULL */
679     static int  i , errflg ;
680     unsigned char buf[BUFLEN],dicname_bk[RECSZ];  /* 92.12.15 */
681     unsigned char *dirnamep;
682     int dirname_offset = 0;
683 
684     hinshi = NULL ;
685     if (argc < 2) usage();
686 
687     (void)strcpy((char *)dirname, "");
688     (void)strcpy((char *)dicname, "");
689     (void)strcpy((char *)filename, "");
690 
691     scan_opt(argc,argv,&argc);
692 
693     if ( opt_s || opt_fq || opt_std ) usage();
694 
695     if (opt_u)  {
696       if (opt_i|opt_g|opt_myg) usage();
697       (void)strcpy((char *)dirname, ":user/");
698       dirname_offset = strlen((char *)dirname);
699       (void)strcpy((char *)dirname + dirname_offset, opt_user);
700     }
701     if ( opt_g ) {
702 	if (opt_i|opt_u|opt_myg) usage();
703 	(void)strcpy((char *)dirname, ":group/");
704 	(void)strcat((char *)dirname, opt_grp);
705     }
706     if ( opt_myg ) {
707 	if (opt_i|opt_u|opt_g) usage();
708 	(void)strcpy((char *)dirname, ":group/");
709 	(void)strcat((char *)dirname, searchgroup());
710     }
711     if (opt_l) (void)strcpy((char *)filename,opt_lfile);
712     (void)strcpy((char *)dicname,opt_dic1);
713     r_dic = (unsigned char *)opt_dic1 ;     /* 93.03.01 */
714     r_file = (char *)filename;
715 
716     /* �ޤ�Initialize���� */
717     rk_init() ;
718 
719     /*  server  new/old check  */
720     nwcheck() ;
721 
722     if ( opt_i ) {
723 	if ( majv == 1 ) {
724 	    (void)strcpy((char *)dirname,"iroha");
725 	}
726 	else {
727 	    if (protover > canna_protocol_version(3, 1)) {
728 		(void)strcpy((char *)dirname,":canna");
729 	    }
730 	    else {
731 		(void)strcpy((char *)dirname,"canna");
732 	    }
733 	}
734 	dirname_offset = 0;
735     }
736     if (protover > canna_protocol_version(3, 1)) {
737       /* ����: �¤� protocol version 3.1 �Ϸ��� */
738       dirname_offset = 0;
739       if ( dirname[0] == '\0' ) {   /* ���ץ����ʤ��Ǥ�dir�����ꤹ�� */
740 	  (void)strcpy((char *)dirname,":user/");
741 	  (void)strcat((char *)dirname,searchuname());
742       }
743     }
744     else {
745 	if (opt_g || opt_myg ) {
746 	    fprintf(stderr, gettxt("cannacmd:253",
747 	   "This options or command are not supported by canna-server\n"));
748 	    exit(ERR_VALUE);
749 	}
750     }
751     dirnamep = dirname + dirname_offset;
752 
753     /* 92.12.15 */
754     if( filename[0] != '\0' ) { /* �ե�����̾�����ꤵ��ʤ����ɸ����� */
755 	for ( i = 1; i < argc ; i++) {
756 	    strncpy((char *)dicname,(char *)argv[i],RECSZ-1);
757 	    strcpy((char *)dicname_bk, (char *)dicname);
758 	    if (RkGetWordTextDic(cx_num,dirnamep,dicname_bk,buf,BUFLEN) >= 0) {
759 		if((fp = fopen((char *)filename,"w")) == NULL) {
760 		    (void)fprintf(stderr,gettxt("cannacmd:77",
761 			"Specified file \"%s\" cannot open.\n"),filename);
762 		    exit(ERR_VALUE);
763 		}
764 		else {
765 		    break  ;
766 		}
767 	    }
768 	}
769     }
770 
771     (void) signal(SIGTERM, RefreshAll);
772     (void) signal(SIGINT, RefreshAll);
773 
774 
775     errflg = 0 ;
776     for ( i = 1 ; i < argc ; i++) {
777 	strncpy((char *)dicname,(char *)argv[i],RECSZ-1);
778 	/* ����˽��� */
779 	if(DownLoadDic(fp, dirnamep) < 0) {
780 	    errflg = 1 ;
781 	}
782     }
783     (void)fclose(fp);
784     RkFinalize();
785     if (errflg == 1) {
786 	exit(ERR_VALUE);
787     }
788     exit(0);
789 }
790 
DownLoadDic(fp,dirname)791 DownLoadDic(fp, dirname)
792 FILE          *fp;
793 unsigned char *dirname;
794 {
795     int           ret , hlen , hflg , blen ;
796     unsigned char buf[BUFLEN] ;
797     unsigned char dicname_bk[RECSZ];
798     char *whinp ;
799 
800     hflg = 0 ;
801     strcpy((char *)dicname_bk, (char *)dicname);
802 
803     if ( hinshi != NULL ) {
804       hflg = 1 ;
805       hlen = strlen(hinshi);
806     }
807     do {
808 	if ((ret = RkGetWordTextDic(cx_num,dirname,dicname_bk,buf,
809 				BUFLEN)) >= 0) {
810 	    dicname_bk[0] = '\0' ;
811 	    if (!ret) {
812 		break;
813 	    }
814 	    if ( hflg ) {
815 		whinp = index((char *)buf,'#') ;
816 		if (whinp == NULL) continue ;
817 		if (strncmp(whinp,hinshi,hlen) != 0  ||
818 		    (whinp[hlen] != ' ' && whinp[hlen] != '\t'  &&
819 	             whinp[hlen] != '*' ))  continue ;
820 	    }
821 	    blen = strlen((char *)buf) ;
822 	    buf[blen+1] = '\0' ;
823 	    buf[blen  ] = '\n' ;
824 	    if (!fwrite(buf,1,blen+1,fp)) {
825 		(void)fprintf(stderr, gettxt("cannacmd:84",
826 			   "write error \n"));
827 		return -1;
828 	    }
829 	} else {
830 	    PrintMessage(ret, dicname);
831 	    return -1;
832 	}
833     } while(ret >= 0);
834     return (0);
835 }
836 
837 
838 /**************************************************************/
839 /*                        cpdic                               */
840 /**************************************************************/
841 
cp_main(argc,argv)842 cp_main(argc,argv)
843 int   argc  ;
844 char  **argv;
845 {
846   unsigned char dirname[RECSZ*2];      /* �桼��̾�ޤ���"iroha"�ޤ���NULL*/
847   int  dirname_offset = 0 , mode_cp  , ret ;
848   unsigned char *dirnamep;
849   char ans[20];
850 
851   mode = Rk_MWD;              /* ����μ��� */
852   mode_cp = 0 ;
853 
854   if(argc < 3 || argc > 8) usage();
855 
856   (void)strcpy((char *)dirname, "");
857   (void)strcpy((char *)dicname1, "");
858   (void)strcpy((char *)dicname2, "");
859 
860   scan_opt(argc,argv,&argc);
861   if ( opt_l || opt_r || opt_fq || opt_std ) usage();
862   if ( opt_dic2 == NULL ) usage();
863   if ( argc >= 4 ) usage();  /* �������İʾ夢�� */
864 
865   if ( opt_u ) {
866       if (opt_i) usage();
867       (void)strcpy((char *)dirname,"user/");
868       dirname_offset = strlen((char *)dirname);
869       (void)strcat((char *)dirname,opt_user);
870   }
871   if ( opt_s ) mode = Rk_SWD;
872 
873   if ( opt_g ) {
874       if ( opt_i || opt_u ) usage();
875       (void)strcpy((char *)dirname,"group/");
876       (void)strcat((char *)dirname,opt_grp);
877   }
878   if ( opt_myg ) {
879       mode_cp |= RK_GRP_DIC ;
880   }
881 
882   (void)strcpy((char *)dicname1,opt_dic1);
883   (void)strcpy((char *)dicname2,opt_dic2);
884   r_dic = (unsigned char *)opt_dic2 ;     /* 93.03.01 */
885 
886   /* �ޤ�Initialize���� */
887   rk_init() ;
888 
889   /*  server  new/old check  */
890   nwcheck() ;
891 
892 
893   if ( opt_i == 1 ) {
894       if ( majv == 1 ) {         /* old server */
895 	(void)strcpy((char *)dirname,"iroha");
896       }
897       else {
898 	(void)strcpy((char *)dirname,"canna");
899       }
900       dirname_offset = 0;
901   }
902 
903   dirnamep = dirname + dirname_offset;
904 
905   if (protover > canna_protocol_version(3, 1)) {
906 
907       if ( dirname[0] == '\0' ) {
908 	  (void)strcpy((char *)dirname,"user/");
909 	  (void)strcat((char *)dirname,searchuname());
910       }
911       dirname_offset = 0;
912       dirnamep = dirname + dirname_offset;
913       ret = RkCopyDic(cx_num,dirnamep,dicname1,dicname2,mode_cp);
914       if (ret == EXIST ) {     /* ���ԡ���˼������� */
915 	  if (isatty(fileno(stdin)) != 0) {
916 	      (void)fprintf(stderr,gettxt("cannacmd:205",
917     "Specified dictionary \"%s\" already exists. Do you overwrite it ? (y/n)"),
918 		      dicname2);
919 	      ans[0]=getchar();
920 	  } else {
921 	      (void)fprintf(stderr,gettxt("cannacmd:206",
922 	    "Specified dictionary \"%s\" already exists."),dicname);
923 	      (void)strcpy(ans,"n");
924 	  }
925 	  if ( ans[0] == 'y' ) {     /* ������� */
926 	      ret = RkRemoveDic(cx_num,dicname2,mode_cp);
927 	      if ( ret == 0) {
928 		  mode_cp |= KYOUSEI;
929 		  ret = RkCopyDic(cx_num,dirnamep,dicname1,dicname2,mode_cp);
930  		  if ( ret == 0) {
931 		      (void)fprintf(stderr, gettxt("cannacmd:201",
932 		       "Dictionary \"%s\" is overwritten."), dicname2);
933 		  }
934 	      }
935 	      if (ret <0) {
936 		  PrintMessage(ret,dicname1);
937 		  RkFinalize();
938 		  exit(1);
939 	      }
940 	  } else {                    /* ������ʤ� */
941 	      (void)fprintf(stderr, gettxt("cannacmd:207",
942 	     "Dictionary \"%s\" is not created.\n"), dicname2);
943 	      RkFinalize();
944 	      exit(1);
945 	  }
946       }
947       else {                          /* ���ԡ���˼����ʤ� */
948 	  if (ret <0) {
949 	      if (ret == TXTBSY ) {
950 		  PrintMessage(ret,dicname2);
951 	      }
952 	      else {
953 		  PrintMessage(ret,dicname1);
954 	      }
955 	      RkFinalize();
956 	      exit(1);
957 	  }
958 	  (void)fprintf(stderr, gettxt("cannacmd:199",
959 	       "New dictionary \"%s\" is created.\n"), dicname2);
960 	  (void)fprintf(stderr, gettxt("cannacmd:200",
961 	       "Please change customize file."));
962       }
963   }
964   else {                 /* �Ť� canna �ν��� */
965       if ( opt_g || opt_myg ) {
966 	    fprintf(stderr, gettxt("cannacmd:253",
967 	   "This options or command are not supported by canna-server\n"));
968 	    exit(ERR_VALUE);
969 	}
970 
971       /* ������� */
972       (void) signal(SIGINT, StopAll);
973       (void) signal(SIGQUIT, StopAll);
974       (void) signal(SIGTERM, StopAll);
975 
976       if (makeDictionary(cx_num, dicname2, mode) < 0) {
977 	  RkFinalize();
978 	  exit(ERR_VALUE);
979       }
980 
981       (void) signal(SIGINT,  RefreshAll);
982       (void) signal(SIGQUIT, RefreshAll);
983       (void) signal(SIGTERM, RefreshAll);
984 
985       if(CopyDic(cx_num, dirnamep, dicname1, dicname2, mode)) {
986 	  RkFinalize();
987 	  exit(ERR_VALUE);
988       }
989   }
990 
991   /* finalize���� */
992   RkFinalize();
993   (void)fprintf(stderr,	gettxt("cannacmd:101",
994 	       "\n\"%s\" was copied to \"%s\".\n"), dicname1, dicname2);
995   exit(0);
996 }
997 
998 
999 /**************************************************************/
1000 /*                        delwords                            */
1001 /**************************************************************/
1002 
del_main(argc,argv)1003 del_main (argc,argv)
1004 int   argc  ;
1005 char  **argv;
1006 {
1007     FILE	*fp;
1008     char	*l_file = NULL;
1009 
1010     mode = Rk_MWD;
1011     is_display = FALSE;
1012     hinshi = NULL ;
1013 
1014     scan_opt(argc,argv,&argc);
1015     if ( opt_i || opt_u || opt_s ||opt_fq||opt_std||opt_myg||opt_g) usage();
1016     if ( opt_dic2 != NULL ) usage();
1017 
1018     if ( opt_l ) l_file = opt_lfile ;
1019     r_dic = (unsigned char *)opt_dic1 ;
1020 
1021     if (!l_file) {
1022 	fp = stdin;
1023 	if (isatty(fileno(stdin)) == 0) {
1024 	    is_display = TRUE;
1025 	}
1026     } else {
1027 	is_display = TRUE;
1028 	fp = (FILE *)fopen(l_file, "r");
1029 	if (!fp) {
1030 	    Message(gettxt("cannacmd:115",
1031 		   "%s: cannot open \"%s\""), Progname, l_file);
1032 	    exit(ERR_VALUE);
1033 	}
1034     }
1035 
1036     /* �ޤ�Initialize���� */
1037     rk_init() ;
1038     write_chk();
1039 
1040     if (Addwords(fp) == -1) {
1041 	if (!l_file)
1042 	    (void) fclose(fp);
1043 	(void) RkFinalize();
1044 	exit(ERR_VALUE);
1045     }
1046     (void) RkFinalize();
1047     Message(gettxt("cannacmd:118", "Delwords has done on \"%s\"."), r_dic);
1048     exit (0);
1049 }
1050 
1051 
1052 /**************************************************************/
1053 /*                        lsdic                               */
1054 /**************************************************************/
1055 
1056 /* ����ꥹ�Ȥ�������ޤ��� */
ls_main(argc,argv)1057 ls_main(argc,argv)
1058 int   argc  ;
1059 char  **argv;
1060 {
1061     unsigned char *p;
1062     int i, arg, j;
1063     int bufcnt , ret;
1064     char  user[RECSZ*2] ;
1065     unsigned char  buf[BUFLEN];
1066     int user_offset = 0;
1067     static char *accsbuf[] ={"-r-","-w-","-rw-","--"};
1068 
1069     strcpy(msg_abnls,gettxt("cannacmd:119",
1070 	    "Cannaserver \"%s\" is in an abnormal state.\n"));
1071     strcpy(msg_abnl, gettxt("cannacmd:120",
1072 	    "Cannaserver is in an abnormal state.\n"));
1073 
1074     /*
1075      * �桼��̾�����ꤵ��Ƥ��ʤ�����
1076      * ��ʬ��̾����õ���Ƥ���̾����RK��ƤӤޤ���
1077      */
1078 
1079     user[0] = '\0';
1080     mode = 0 ;
1081 
1082     scan_opt(argc,argv,&argc);
1083     if (opt_u) {
1084       strcpy(user, ":user/");
1085       user_offset = strlen(user);
1086       strcpy(user + user_offset, opt_user);
1087     }
1088     if ( opt_r || opt_s || opt_fq || opt_std) usage();
1089     if (opt_dic1 != NULL) usage();
1090 
1091     /* �����ǥ桼�������ꤵ��ʤ���м�ʬ�μ����ץ��ȥ����Ȥ��ޤ� */
1092     if ((*user == '\0') && (opt_i == 0) && (opt_g == 0) && (opt_myg == 0)) {
1093       if (opt_u) { /* �桼��̾��NULL���ϤäƤ����饨�顼 */
1094 	usage();
1095       }
1096       (void)strcpy(user, ":user/");
1097       user_offset = strlen(user);
1098       (void)strcpy(user + user_offset, searchuname());
1099     }
1100 
1101     if (opt_l) {
1102 	if (opt_i || opt_u || opt_g || opt_a ) usage();
1103     }
1104     if (opt_a) {
1105 	if (opt_i || opt_g || opt_myg || opt_u || opt_l ) usage();
1106 	opt_i = 1 ;
1107 	opt_myg = 1 ;
1108     }
1109     /* ����ꥹ�Ⱥ��� */
1110 
1111     /* �ޤ�Initialize���� */
1112     rk_init() ;
1113 
1114     /*  server  new/old check  */
1115     nwcheck() ;
1116 
1117      if ( opt_i == 1 ) {
1118 	    if ( majv == 1 ) {    /* old server */
1119 	      if(*user == '\0') {
1120 		  (void)strcpy(user, "iroha");
1121 		  user_offset = 0;
1122 	      } else {
1123 		  (void)strcat(user, ":iroha");
1124 	      }
1125 	    }
1126 	    else {
1127 	      if(*user == '\0') {
1128 		  user_offset = 0;
1129 		  if (protover > canna_protocol_version(3, 1)) {
1130 		      (void)strcpy(user, ":canna");
1131 		  }
1132 		  else {
1133 		      (void)strcpy(user, "canna");
1134 		  }
1135 	      } else {
1136 		  (void)strcat(user, ":canna");
1137 	      }
1138 	    }
1139      }
1140     if (protover > canna_protocol_version(3, 1)) {
1141       /* ����: �¤� protocol version 3.1 �Ϸ��� */
1142       user_offset = 0;
1143     }
1144     else {
1145 	if ( opt_l || opt_g || opt_myg ) {
1146 	    fprintf(stderr, gettxt("cannacmd:253",
1147 	   "This options or command are not supported by canna-server\n"));
1148 	    RkFinalize();
1149 	    exit(ERR_VALUE);
1150 	}
1151     }
1152     if ( opt_g ) {
1153 	if ( *user == '\0' ) {
1154 	    (void)strcpy(user,":group/");
1155 	    (void)strcat(user,opt_grp);
1156 	}
1157 	else {
1158 	    (void)strcat(user,":group/");
1159 	    (void)strcat(user,opt_grp);
1160 	}
1161     }
1162     if ( opt_myg ) {
1163 	mode = RK_GRP_DIC  ;
1164 	if ( *user == '\0' ) {
1165 	    (void)strcpy(user,":group/");
1166 	    (void)strcat(user,searchgroup());
1167 	}
1168 	else {
1169 	    (void)strcat(user,":group/");
1170 	    (void)strcat(user,searchgroup());
1171 	}
1172     }
1173     (void) signal(SIGINT, StopAll);
1174     (void) signal(SIGQUIT, StopAll);
1175     (void) signal(SIGTERM, StopAll);
1176     bufcnt = RkListDic(cx_num, user + user_offset, buf, BUFLEN );
1177 
1178 
1179     /*
1180      *    ���������ץ��ȥ����Ȥ��ƽ����Ǥ���
1181      */
1182 
1183     if (bufcnt >= 0) {
1184       for (p = buf, i = 0 ; i < bufcnt && *p ; i++) {
1185 	if ( opt_l ) {
1186 	    ret = RkChmodDic(cx_num,p,mode);
1187 	    if (ret < 0 ) {
1188 		(void)fprintf(stderr,gettxt("cannacmd:252",
1189 		      "invalid return code rkchmoddic code=%d \n"),ret);
1190 		RkFinalize();
1191 		exit(1);
1192 	    }
1193 	    switch (ret) {
1194 	      case RK_ENABLE_READ | RK_DISABLE_WRITE :
1195 		j = 0;
1196 		break ;
1197 	      case RK_ENABLE_WRITE | RK_DISABLE_READ :
1198 		j = 1 ;
1199 		break ;
1200 	      case RK_ENABLE_WRITE | RK_ENABLE_READ :
1201 		j = 2 ;
1202 		break ;
1203 	      default :
1204 		j = 3 ;
1205 		break ;
1206 	    }
1207 	    (void)fprintf(stdout, "%s  %s\n", p,accsbuf[j]);
1208 	}
1209 	else {
1210 	    (void)fprintf(stdout, "%s\n", p);
1211 	}
1212         p += strlen((char *)p) + 1;
1213       }
1214       if ( i != bufcnt ) {
1215 	(void)fprintf(stderr,gettxt("cannacmd:255",
1216 	      "Too many dictionary  \n"));
1217 	RkFinalize();
1218 	exit(1);
1219       }
1220       RkFinalize();
1221       exit(0);
1222     }
1223     RkFinalize();
1224     switch ( bufcnt ) {
1225       case NOTALC :
1226 	(void)fprintf(stderr, gettxt("cannacmd:130",
1227 	     "Cannot get memory.\n"));
1228 	break;
1229       case BADCONT :
1230 	(void)fprintf(stderr,gettxt("cannacmd:131",
1231 	    "Illegal context value was used.\n"));
1232 	break;
1233       case ACCES  :
1234 	(void)fprintf(stderr,gettxt("cannacmd:171",
1235 	    "Cannot access to dictionary.\n"));
1236 	break;
1237       default:
1238 	if (init[0] == '/') {
1239 	    (void)fprintf(stderr,msg_abnl);
1240 	} else {
1241 	    (void)fprintf(stderr,msg_abnls,init);
1242 	}
1243 	break;
1244     }
1245     exit(ERR_VALUE);
1246 }
1247 
1248 
1249 /**************************************************************/
1250 /*                        mkdic                               */
1251 /**************************************************************/
1252 
1253 static int
Upload(fp,flag)1254 Upload(fp, flag)
1255   FILE	*fp;
1256   int   flag;
1257 {
1258     int ret=0 ;
1259     (void) signal(SIGINT,  StopAll);
1260     (void) signal(SIGQUIT, StopAll);
1261     (void) signal(SIGTERM, StopAll);
1262     if (makeDictionary(cx_num, (unsigned char *)r_dic, mode) != 0) {
1263 	return (-1);
1264     }
1265     (void) signal(SIGINT,  RefreshAll);
1266     (void) signal(SIGQUIT, RefreshAll);
1267     (void) signal(SIGTERM, RefreshAll);
1268     if (flag) {
1269 	ret = Addwords(fp);
1270     }
1271     return (ret);
1272 }
1273 
mk_main(argc,argv)1274 mk_main (argc,argv)
1275 int   argc  ;
1276 char  **argv;
1277 {
1278     FILE	*fp;
1279     char	*l_file = NULL;
1280     char        upld = '\0';
1281     int         i , errflg = 0;
1282 
1283     strcpy(msg_sfq,gettxt("cannacmd:132",
1284 	  "Option  -s and -fq are specified at once. \n")) ;
1285     strcpy(msg_l,  gettxt("cannacmd:133",
1286 	  "Option - or -l cannot be specified.\n")) ;
1287 
1288     mode = Rk_MWD;
1289     mode2 = PL_ALLOW ;
1290     is_display = FALSE;
1291     hinshi = NULL ;
1292 
1293     scan_opt(argc,argv,&argc);
1294     if ( opt_i || opt_u || opt_g ) usage();
1295     if ( opt_l && opt_std ) usage();
1296     if ( (opt_l || opt_std) && opt_dic2 != NULL ) usage();
1297 
1298     if ( opt_fq ) {
1299       if ( opt_s ) {
1300         (void) fprintf(stderr,msg_sfq);
1301         exit(ERR_VALUE) ;
1302       }
1303       if ( opt_l || opt_std ) {
1304         (void) fprintf(stderr,msg_l);
1305         exit(ERR_VALUE) ;
1306       }
1307       mode = mode | PL_DIC ;
1308       mode2 = PL_ALLOW ;
1309     }
1310     if ( opt_s ) mode = Rk_SWD;
1311     if ( opt_l || opt_std ) {
1312       upld++ ;
1313       l_file = opt_lfile ;
1314     }
1315     if ( opt_myg ) { mode = mode | RK_GRP_DIC ;
1316     }
1317     if (upld) {
1318       if (isatty(fileno(stdout)) == 0) {
1319 	  is_display = TRUE;
1320       }
1321       if (!l_file) {
1322 	fp = stdin;
1323       } else {
1324 	is_display = TRUE ;
1325 	fp = (FILE *)fopen(l_file, "r");
1326 	if (!fp) {
1327 	  Message(gettxt("cannacmd:149",
1328 			 "%s: cannot open \"%s\""), Progname, l_file);
1329 	  exit(ERR_VALUE);
1330 	}
1331       }
1332     }
1333 
1334     /* �ޤ�Initialize���� */
1335     rk_init() ;
1336     for ( i = 1 ; i < argc ; i++) {
1337 	r_dic = (unsigned char *)argv[i];
1338 	opt_dic1 = argv[i] ;
1339 	if (ovwrite_chk(opt_dic1,mode) == 0 ) {
1340 	    if (Upload(fp, (int)upld) == -1) {
1341 		errflg = 1 ;
1342 	    }
1343 	    else {
1344 		if (!upld) {
1345 		    Message("");
1346 		}
1347 	    }
1348 	}
1349 	else {
1350 	    errflg = 1 ;
1351 	}
1352     }
1353     (void) RkFinalize();
1354     if (upld && l_file)
1355       (void)fclose(fp);
1356     if (errflg == 1) {
1357 	exit(ERR_VALUE);
1358     }
1359     exit (0);
1360 }
1361 
1362 
1363 /**************************************************************/
1364 /*                        mvdic                               */
1365 /**************************************************************/
1366 
mv_main(argc,argv)1367 mv_main(argc,argv)
1368 int   argc  ;
1369 char  **argv;
1370 {
1371   int  ret ,mode;
1372   char *dicname1;
1373   char *dicname2;
1374   char dic1[RECSZ];
1375   char dic2[RECSZ];
1376   ret = 0;
1377 
1378   (void)strcpy(msg_abnl,gettxt("cannacmd:153",
1379        "Cannaserver is in an abnormal state.\n"));
1380   (void)strcpy(msg_abnls,gettxt("cannacmd:154",
1381        "Cannaserver \"%s\" is in an abnormal state.\n"));
1382 
1383   mode = NOT_OVER_WRITE;
1384   scan_opt(argc,argv,&argc);
1385   if (opt_l || opt_r || opt_i ||opt_u||opt_s||opt_fq||opt_std||opt_g) usage();
1386   if (opt_dic2 == NULL) usage();
1387   if ( opt_myg ) mode = mode | RK_GRP_DIC ;
1388 
1389 
1390   dicname1 = opt_dic1 ;
1391   dicname2 = opt_dic2 ;
1392 
1393   strncpy(dic1, dicname1, RECSZ - 1);
1394   strncpy(dic2, dicname2, RECSZ - 1);
1395 
1396   /* ����̾��Ʊ���ʤ饨�顼 */
1397   if(!strcmp(dic1,dic2)) {
1398     fprintf(stderr, gettxt("cannacmd:161",
1399 	   "%s: %s, Dictionary name is same.\n"),Progname, dic1);
1400     exit(ERR_VALUE);
1401   }
1402 
1403   (void) signal(SIGINT, StopAll);
1404   (void) signal(SIGQUIT, StopAll);
1405   (void) signal(SIGTERM, StopAll);
1406 
1407 
1408   /* �ޤ�Initialize���� */
1409   rk_init() ;
1410 
1411   if (ovwrite_chk(dic2,mode) == 0 ){
1412       ret = renameDictionary(cx_num, dic1, dic2, mode);
1413   }
1414   else {
1415       ret = ERR_VALUE ;
1416   }
1417   RkFinalize();
1418   exit(ret);
1419 }
1420 
renameDictionary(cn,dicname1,dicname2,force)1421 renameDictionary(cn, dicname1, dicname2, force)
1422 int cn;
1423 char *dicname1;
1424 char *dicname2;
1425 int force;
1426 {
1427   char ans[20];
1428   int ret = 0;
1429 
1430 
1431   nwcheck() ;
1432 
1433   switch ( RkRenameDic( cn, dicname1, dicname2, force) ) {
1434   case 0 :
1435     fprintf(stderr,gettxt("cannacmd:166",
1436 	  "Change dictionary \"%s\" to \"%s\".\n"),dicname1, dicname2);
1437     ret = 0;
1438     break;
1439   case 1 :
1440     fprintf(stderr,gettxt("cannacmd:167",
1441 	  "Overwrite dictionary \"%s\" to \"%s\".\n"),dicname1, dicname2);
1442     ret = 0;
1443     break;
1444   case NOTALC :
1445     (void)fprintf(stderr, gettxt("cannacmd:168", "No more memory.\n"));
1446     break;
1447   case NOENT :
1448     fprintf(stderr,gettxt("cannacmd:169",
1449 	  "Dictionary \"%s\" does not exist.\n"), dicname1);
1450     ret = 1;
1451     break;
1452   case BADF :
1453     fprintf(stderr,gettxt("cannacmd:170",
1454 	   "\"%s\" or \"%s\" is binary dictionary.\n"), dicname1,dicname2);
1455     ret = 1;
1456     break;
1457   case ACCES :
1458     fprintf(stderr,gettxt("cannacmd:171", "Cannot access to dictionary.\n"));
1459     ret = 1;
1460     break;
1461   case BADDR :
1462     (void)fprintf(stderr,gettxt("cannacmd:172",
1463 	"dics.dir is abnormal. Cannot create dictionary file.\n"));
1464     ret = -1;
1465     break;
1466   case MOUNT :
1467   case EXIST :
1468     fprintf(stderr,gettxt("cannacmd:173",
1469 "Specified dictionary \"%s\" already exists. Do you overwrite it ? (y/n)"),
1470 	    dicname2);
1471     ans[0]=getchar();          /* 92.10.28 */
1472     if(ans[0] == 'y') {
1473       force = force | OVER_WRITE  ;
1474       ret = renameDictionary(cn, dicname1, dicname2, force);
1475     }
1476     else {
1477       fprintf(stderr, gettxt("cannacmd:174",
1478 	     "Specified dictionary \"%s\" does not overwite.\n"),dicname2);
1479       ret = 1;
1480     }
1481     break;
1482   case TXTBSY :
1483     fprintf(stderr,gettxt("cannacmd:175",
1484 	  "Dictionary \"%s\" or \"%s\" is in use. Cannot overwrite it.\n"),
1485 	    dicname1, dicname2);
1486     ret = 1;
1487     break;
1488   case BADCONT :
1489     fprintf(stderr,gettxt("cannacmd:176","Illegal context value was used.\n"));
1490     ret = 1;
1491     break;
1492   default:
1493     if(init[0] == '/') {
1494       fprintf(stderr,msg_abnl );
1495     }
1496     else {
1497       fprintf(stderr,msg_abnls,init);
1498     }
1499     ret = 1;
1500     break;
1501   }
1502   return ret;
1503 }
1504 
1505 
1506 /**************************************************************/
1507 /*                        rmdic                               */
1508 /**************************************************************/
1509 
rm_main(argc,argv)1510 rm_main(argc,argv)
1511 int   argc  ;
1512 char  **argv;
1513 {
1514   int  i, j , ret , undel ;
1515   int isflag = 0;
1516   int rmdone = 0; /* rm ���ޤ��ʤ���Ƥ��ʤ� */
1517 
1518 
1519   mode = 0  ;
1520   if(argc < 2) usage();
1521 
1522   scan_opt(argc,argv,&argc);
1523   if ( opt_l || opt_r || opt_i ||opt_u||opt_s||opt_std||opt_g) usage();
1524 
1525   if ( opt_fq ) mode = PL_DIC ;
1526   if ( opt_myg ) mode = mode | RK_GRP_DIC ;
1527 
1528   /* �ޤ�Initialize���� */
1529   rk_init() ;
1530 
1531   (void) signal(SIGINT, StopAll);
1532   (void) signal(SIGQUIT, StopAll);
1533   (void) signal(SIGTERM, StopAll);
1534 
1535   /* ������ */
1536   undel = 0 ;
1537   for(j = 1; j < argc; j++) {
1538 
1539       strncpy((char *)rm_dic, (char *)argv[j], RECSZ - 1);
1540       rm_dic[RECSZ - 1] = (unsigned char)0;
1541 
1542       ret = rmDictionary(cx_num, rm_dic, mode) ;
1543       if (  ret == -1 ) {
1544 	RkFinalize();
1545 	exit(ERR_VALUE);
1546       }
1547       if (  ret == -2 ) {  /* �����ä��ʤ��ä� */
1548 	  undel = 1 ;
1549       }
1550       rmdone = 1; /* �ºݤ� rm ���Ԥ�줿 */
1551     }
1552 
1553   RkFinalize();
1554   if (rmdone == 0) { /* ���� rm ���ʤ���ʤ��ä��ʤ�� */
1555     (void)fprintf(stderr, gettxt("cannacmd:185",
1556 	 "Dictionary is not specified.\n"));
1557   }
1558   if (undel == 0 ) {
1559       exit(0) ;
1560   }
1561   else {
1562       exit(2) ;
1563   }
1564 }
1565 
1566 /************************************************************************/
1567 /*                    chmoddic                                          */
1568 /************************************************************************/
1569 
ch_main(argc,argv)1570 ch_main(argc,argv)
1571 int   argc  ;
1572 char  **argv;
1573 {
1574     int  ret ,mode ;
1575     scan_opt(argc,argv,&argc);
1576     if (opt_l||opt_r||opt_s||opt_fq||opt_std||opt_g||opt_u||opt_a) usage();
1577     mode = opt_rw ;
1578     if ( mode == 0 ) usage();
1579     if ( opt_dic2 != NULL ) usage();
1580     if ( opt_myg ) mode = mode | RK_GRP_DIC;
1581     rk_init();
1582 
1583     (void) signal(SIGINT, StopAll);
1584     (void) signal(SIGQUIT, StopAll);
1585     (void) signal(SIGTERM, StopAll);
1586 
1587     ret = RkChmodDic(cx_num,opt_dic1,mode);
1588     if (ret < 0) {
1589 	switch (ret) {
1590           case NOENT:
1591 	    fprintf(stderr,gettxt("cannacmd:169",
1592 		  "Dictionary \"%s\" does not exist.\n"), opt_dic1);
1593 	    break;
1594           case BADCONT:
1595 	    fprintf(stderr,gettxt(
1596 		  "cannacmd:176","Illegal context value was used.\n"));
1597 	    break;
1598           case ACCES:
1599 	    fprintf(stderr,gettxt(
1600 		  "cannacmd:171", "Cannot access to dictionary.\n"));
1601 	    break;
1602           case NOTALC:
1603 	    fprintf(stderr, gettxt("cannacmd:168", "No more memory.\n"));
1604 	    break;
1605           case -1:
1606 	    fprintf(stderr, gettxt("cannacmd:253",
1607   	   "This options or command are not supported by canna-server\n"));
1608 	    break;
1609           default:
1610 	    fprintf(stderr, gettxt("cannacmd:252",
1611 		   "Invalid return code RkChmoddic  code=%d \n"),ret);
1612 	    break;
1613 	}
1614 	RkFinalize();
1615 	exit(ERR_VALUE);
1616     }
1617     RkFinalize();
1618     exit(0);
1619 }
1620 /************************************************************************/
1621 /*                    syncdic                                           */
1622 /************************************************************************/
1623 
sy_main(argc,argv)1624 sy_main(argc,argv)
1625 int   argc  ;
1626 char  **argv;
1627 {
1628     int  ret ,mode ;
1629     scan_opt(argc,argv,&argc);
1630     if (opt_l||opt_r||opt_s||opt_fq||opt_std||opt_g||opt_u||opt_a||opt_myg)
1631       usage();
1632 
1633     rk_init();
1634     nwcheck();
1635 
1636     if (protover < canna_protocol_version(3,1)) {
1637 	fprintf(stderr, gettxt("cannacmd:253",
1638   	   "This options or command are not supported by canna-server\n"));
1639 	exit(ERR_VALUE);
1640     }
1641 
1642     (void) signal(SIGINT, StopAll);
1643     (void) signal(SIGQUIT, StopAll);
1644     (void) signal(SIGTERM, StopAll);
1645 
1646     ret = RkSync(cx_num,NULL);
1647     if (ret < 0) {
1648 	fprintf(stderr,
1649 	   "invalid return code rksync  code=%d \n",ret);
1650 	RkFinalize();
1651 	exit(ERR_VALUE);
1652     }
1653     RkFinalize();
1654     exit(0);
1655 }
1656 
1657 /************************************************************************/
1658 /*                    cannakill              94.08.11                   */
1659 /************************************************************************/
1660 
kill_main(argc,argv)1661 kill_main(argc,argv)
1662 int   argc  ;
1663 char  **argv;
1664 {
1665 
1666     int  ret ;
1667     char *p ;
1668 
1669 #ifndef __EMX__
1670     if ( argc > 2 ) {
1671 	usage();
1672     }
1673     if ( argc == 2 ) {
1674 	p = argv[1];
1675 	for ( ; *p != '\0' ; p++ ) {
1676 	    if ( strchr("0123456789",*p) == NULL ) {
1677 		usage();
1678 	    }
1679 	}
1680 #ifdef USE_UNIX_SOCKET
1681 	(void)strcpy(init,"unix:");
1682 #else
1683 	(void)strcpy(init,"localhost:");
1684 #endif
1685 	(void)strcat(init,argv[1]);
1686     }
1687     else {
1688 #ifdef USE_UNIX_SOCKET
1689 	(void)strcpy(init,"unix");
1690 #else
1691 	(void)strcpy(init,"localhost");
1692 #endif
1693     }
1694 #else
1695     if ( argc > 1 ) {
1696 	usage();
1697     }
1698     else {
1699 	memset ((void *)init, 0, RECSZ);
1700 	gethostname(init, RECSZ);
1701     }
1702 #endif
1703     rk_init();
1704 
1705     (void) signal(SIGINT, StopAll);
1706     (void) signal(SIGQUIT, StopAll);
1707     (void) signal(SIGTERM, StopAll);
1708 
1709     ret = RkKillServer();
1710     if (ret < 0) {
1711 	switch (ret) {
1712           case OLDSRV:
1713 	    fprintf(stderr,gettxt("cannacmd:258",
1714 		"Cannot kill server,because server version is old.\n"));
1715 	    break;
1716           case NOTUXSRV:
1717 	    fprintf(stderr,gettxt("cannacmd:259",
1718 		"Cannot kill server,because server is run by another machine.\n"));
1719 	    break;
1720           case NOTOWNSRV:
1721 	    fprintf(stderr,gettxt("cannacmd:260",
1722 		"Cannot kill server,because server is not run by you.\n"));
1723 	    break;
1724           default:
1725 	    fprintf(stderr, gettxt("cannacmd:261",
1726 		   "Invalid return code RkKillserver  code=%d \n"),ret);
1727 	    break;
1728 	}
1729 	RkFinalize();
1730 	exit(ERR_VALUE);
1731     }
1732     exit(0);
1733 }
1734 
can_ver()1735 can_ver()
1736 {
1737     rk_init();
1738     nwcheck();
1739 /*    printf(gettxt("cannacmd:254","canna version is %d.%d \n",
1740 	   protover/1024 , protover % 1024 ));*/
1741     printf("canna version is %d.%d \n",
1742 	   protover/1024 , protover % 1024 );
1743     RkFinalize();
1744     exit(0) ;
1745 }
1746 
1747 /************************************************************************/
1748 /*                    main                                              */
1749 /************************************************************************/
1750 static struct  command {
1751 	char *name ;
1752 	int  (*func) pro((int, char **));
1753 	int  cmd_code ;
1754 }	commands[] = {
1755 	{"addwords",add_main,1},
1756 	{"catdic"  ,cat_main,2},
1757 	{"cpdic"   ,cp_main,3 },
1758 	{"delwords",del_main,4},
1759 	{"lsdic"   ,ls_main,5 },
1760 	{"mkdic"   ,mk_main,6 },
1761 	{"mvdic"   ,mv_main,7 },
1762 	{"rmdic"   ,rm_main,8 },
1763 	{"downloaddic" ,cat_main,2 },
1764 	{"cpuserdic"   ,cp_main,3 },
1765 	{"lsuserdic"   ,ls_main,5 },
1766 	{"mkuserdic"   ,mk_main,6 },
1767 	{"uploaddic"   ,mk_main,6 },
1768 	{"mvuserdic"   ,mv_main,7 },
1769 	{"rmuserdic"   ,rm_main,8 },
1770 	{"chmoddic"    ,ch_main,9 },
1771 	{"syncdic"     ,sy_main,10},
1772 	{"cannakill"   ,kill_main,11}
1773 };
1774 #define  NCOMMANDS    (sizeof(commands) / sizeof(struct command))
1775 
main(argc,argv)1776 main(argc,argv)
1777 int argc ;
1778 char **argv ;
1779 {
1780     int     i ;
1781     char *p ;
1782 
1783 #if defined(__STDC__) || defined(SVR4)
1784     (void)setlocale(LC_ALL,"");
1785 #endif
1786 
1787 #ifdef __EMX__
1788      Progname = _getname (argv[0]);
1789      _remext (Progname);
1790 #else
1791      p = rindex(argv[0],'/');
1792      if ( p == NULL ) {
1793 	 Progname = argv[0];
1794      }
1795      else {
1796 	 Progname = p + 1 ;
1797      }
1798 #endif
1799 
1800      (void)strcpy(init, "/usr/lib/canna/dic");  /* �����������Ǥ�̵��̣ */
1801      for ( i = 0; i < NCOMMANDS ; i++) {
1802 	 if (strcmp(Progname,commands[i].name) == 0) {
1803 	     cmd_code = commands[i].cmd_code ;
1804 	     (*commands[i].func)(argc,argv);
1805 	     break ;
1806          }
1807      }
1808      return (0);
1809 }
1810 
1811 /*  ���ץ����Υ����å�
1812     ����̾�ʳ��Υ��ץ����ϥ����å��� argv ���������   */
scan_opt(argc,argv,argcp)1813 scan_opt(argc,argv,argcp)
1814 int  argc ,*argcp;
1815 char **argv ;
1816 {
1817 /* ���δؿ��ǥ����å�������
1818        ���ץ����ν�ʣ���꤬�ʤ���
1819        ��������ꤹ�륪�ץ����ΰ��������뤫
1820        �������ꤵ��Ƥ��뤫(lsdic�����)
1821        ���İʾ弭���ʤ���(rmdic�����)
1822 */
1823 
1824 static  char *options[]={"-cs","-cannaserver","-l","-hi","-h","-i","-u","-s",
1825   "-fq","-","-G","-g","+w","-w","+r","-r","+wr","+rw","-wr","-rw","-v","-a"};
1826 #define NOPTIONS sizeof(options) / sizeof(char *)
1827 #define OPT_CS   0
1828 #define OPT_CANNASAVER  1
1829 #define OPT_L   2
1830 #define OPT_R   3
1831 #define OPT_H   4
1832 #define OPT_I   5
1833 #define OPT_U   6
1834 #define OPT_S   7
1835 #define OPT_FQ  8
1836 #define OPT_STD 9
1837 #define OPT_MYG 10
1838 #define OPT_G   11
1839 #define OPT_WADD 12
1840 #define OPT_WDEL 13
1841 #define OPT_RADD 14
1842 #define OPT_RDEL 15
1843 #define OPT_WRADD 16
1844 #define OPT_RWADD 17
1845 #define OPT_WRDEL 18
1846 #define OPT_RWDEL 19
1847 #define OPT_V   20
1848 #define OPT_A   21
1849 
1850 int 	opt_code , i ;
1851 char    **p ;
1852 
1853     opt_cs = opt_l = opt_r = opt_h = opt_i = opt_u = opt_s = opt_fq = 0 ;
1854     opt_std = opt_myg = opt_g = opt_v = opt_a = 0 ;
1855     opt_rw  = 0 ;
1856     opt_lfile = opt_dic1 = opt_dic2 = opt_user = opt_grp = NULL ;
1857 
1858     p = argv + 1 ;   /* ���ޥ����ʬ����� */
1859     while( *p != NULL ) {
1860 /*    printf(" argc= %d opt= %s\n",argc,*p);*/
1861       for (opt_code = 0 ; opt_code  < NOPTIONS ; opt_code++ ){
1862 	if (strcmp( *p ,options[opt_code]) == 0 )  break ;
1863       }
1864       switch(opt_code) {
1865         case OPT_CS :
1866         case OPT_CANNASAVER :
1867 	  if (opt_cs)  usage();			/* ��ʣ�����å� */
1868 	  if ( *(p + 1) == NULL ) usage();
1869 	  opt_cs = 1 ;
1870 	  (void) strcpy(init,*(p+1));
1871 	  shrink_opt(argc,p,2);
1872 	  argc -= 2 ;
1873 	  break ;
1874         case OPT_FQ :
1875 	  if (opt_fq) usage();
1876 	  opt_fq = 1 ;
1877 	  shrink_opt(argc,p,1);
1878 	  argc-- ;
1879 	  break  ;
1880         case OPT_S :
1881 	  if (opt_s) usage();
1882 	  opt_s = 1 ;
1883 	  shrink_opt(argc,p,1);
1884 	  argc-- ;
1885 	  break  ;
1886         case OPT_L :
1887 	  if (opt_l) usage();
1888 	  opt_l = 1 ;
1889 	  if (cmd_code == LS ) {
1890 	      shrink_opt(argc,p,1);
1891 	      argc-- ;
1892 	  }
1893 	  else {
1894 	      if ( *(p + 1) == NULL ) usage();
1895 	      opt_lfile = *(p+1);
1896 	      shrink_opt(argc,p,2);
1897 	      argc -= 2 ;
1898 	  }
1899 	  break ;
1900         case OPT_H :
1901 	  usage();
1902         case OPT_R :
1903 	  if (opt_r) usage();
1904 	  if ( *(p + 1) == NULL ) usage();
1905 	  hinshi = *(p+1);
1906 	  shrink_opt(argc,p,2);
1907 	  argc -= 2 ;
1908 	  break ;
1909         case OPT_I :
1910 	  if (opt_i) usage();
1911 	  opt_i = 1 ;
1912 	  shrink_opt(argc,p,1);
1913 	  argc-- ;
1914 	  break  ;
1915         case OPT_U :
1916 	  if (opt_u) usage();
1917 	  if ( *(p + 1) == NULL ) usage();
1918 	  opt_u = 1 ;
1919 	  opt_user = *(p+1);
1920 	  shrink_opt(argc,p,2);
1921 	  argc -= 2 ;
1922 	  break ;
1923         case OPT_STD :
1924 	  if (opt_std) usage();
1925 	  opt_std = 1 ;
1926 	  opt_lfile = NULL;
1927 	  shrink_opt(argc,p,1);
1928 	  argc-- ;
1929 	  break  ;
1930         case OPT_MYG :    /* -G */
1931 	  if ( opt_myg ) usage();
1932 	  opt_myg = 1 ;
1933 	  shrink_opt(argc,p,1);
1934 	  argc-- ;
1935 	  break ;
1936         case OPT_G :      /* -g */
1937 	  if ( opt_g ) usage();
1938 	  if ( *(p+1) == NULL ) usage();
1939 	  opt_g = 1 ;
1940 	  opt_grp = *(p+1);
1941 	  shrink_opt(argc,p,2);
1942 	  argc-=2 ;
1943 	  break ;
1944         case OPT_WADD :      /* +w */
1945 	  if ((opt_rw & RK_DISABLE_WRITE) == RK_DISABLE_WRITE ) usage();
1946 	  opt_rw = opt_rw | RK_ENABLE_WRITE ;
1947 	  shrink_opt(argc,p,1);
1948 	  argc-- ;
1949 	  break ;
1950         case OPT_WDEL :      /* -w */
1951 	  if ((opt_rw & RK_ENABLE_WRITE) == RK_ENABLE_WRITE ) usage();
1952 	  opt_rw = opt_rw | RK_DISABLE_WRITE ;
1953 	  shrink_opt(argc,p,1);
1954 	  argc-- ;
1955 	  break ;
1956         case OPT_RADD :      /* +r */
1957 	  if ((opt_rw & RK_DISABLE_READ) == RK_DISABLE_READ ) usage();
1958 	  opt_rw = opt_rw | RK_ENABLE_READ ;
1959 	  shrink_opt(argc,p,1);
1960 	  argc-- ;
1961 	  break ;
1962         case OPT_RDEL :      /* -r */
1963 	  if ((opt_rw & RK_ENABLE_READ) == RK_ENABLE_READ ) usage();
1964 	  opt_rw = opt_rw | RK_DISABLE_READ ;
1965 	  shrink_opt(argc,p,1);
1966 	  argc-- ;
1967 	  break ;
1968         case OPT_WRADD :     /* +wr */
1969         case OPT_RWADD :     /* +rw */
1970 	  if ((opt_rw & RK_DISABLE_READ) == RK_DISABLE_READ ) usage();
1971 	  if ((opt_rw & RK_DISABLE_WRITE) == RK_DISABLE_WRITE ) usage();
1972 	  opt_rw = opt_rw | RK_ENABLE_WRITE | RK_ENABLE_READ ;
1973 	  shrink_opt(argc,p,1);
1974 	  argc-- ;
1975 	  break ;
1976         case OPT_WRDEL :     /* -wr */
1977         case OPT_RWDEL :     /* -rw */
1978 	  if ((opt_rw & RK_ENABLE_READ) == RK_ENABLE_READ ) usage();
1979 	  if ((opt_rw & RK_ENABLE_WRITE) == RK_ENABLE_WRITE ) usage();
1980 	  opt_rw = opt_rw | RK_DISABLE_WRITE | RK_DISABLE_READ ;
1981 	  shrink_opt(argc,p,1);
1982 	  argc-- ;
1983 	  break ;
1984         case OPT_V :
1985 	  can_ver() ;
1986         case OPT_A :
1987 	  opt_a = 1;
1988 	  shrink_opt(argc,p,1);
1989 	  argc-- ;
1990 	  break ;
1991         default :
1992 	  dicname_chk(*p);
1993 	  if ( opt_dic1 == NULL ) {
1994 	    opt_dic1 = *p ;
1995 	  }
1996 	  else {
1997 	    opt_dic2 = *p ;
1998 	  }
1999 	  p++ ;
2000       }       /* case end */
2001     }         /* for  end */
2002     if (cmd_code == LS || cmd_code == SY){
2003 	if ( opt_dic1 != NULL ) usage();
2004     }
2005     else {
2006 	if ( opt_dic1 == NULL)  usage();
2007     }
2008 
2009     if (cmd_code != CHMOD && opt_rw != 0) usage();
2010 
2011     *argcp = argc ;
2012     return(0);
2013 }
2014 
2015 /*  argv �Υ��ץ����� n ��ʬ���˵ͤ�� */
shrink_opt(argc,argv,n)2016 shrink_opt(argc,argv,n)
2017 int  argc, n ;
2018 char  *argv[] ;
2019 {
2020     int  i ;
2021     for ( i = n ; i < argc ; i++ ) {
2022       argv[i-n] = argv[i];
2023     }
2024 }
2025