1 #ifndef lint
2 static char rcs_id[] = "$Id: jhlp.c,v 1.2 2001/06/14 18:16:12 ura Exp $";
3 #endif /* lint */
4
5 /*
6 * FreeWnn is a network-extensible Kana-to-Kanji conversion system.
7 * This file is part of FreeWnn.
8 *
9 * Copyright Kyoto University Research Institute for Mathematical Sciences
10 * 1987, 1988, 1989, 1990, 1991, 1992
11 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999
12 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992
13 * Copyright 1991, 1992 by Massachusetts Institute of Technology
14 *
15 * Author: OMRON SOFTWARE Co., Ltd. <freewnn@rd.kyoto.omronsoft.co.jp>
16 *
17 * This program is free software; you can redistribute it and/or modify
18 * it under the terms of the GNU General Public License as published by
19 * the Free Software Foundation; either version 2, or (at your option)
20 * any later version.
21 *
22 * This program is distributed in the hope that it will be useful,
23 * but WITHOUT ANY WARRANTY; without even the implied warranty of
24 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 * GNU General Public License for more details.
26 *
27 * You should have received a copy of the GNU General Public License
28 * along with GNU Emacs; see the file COPYING. If not, write to the
29 * Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
30 *
31 * Commentary:
32 *
33 * Change log:
34 *
35 * Last modified date: 8,Feb.1999
36 *
37 * Code:
38 *
39 */
40 /* Version 4.0
41 */
42 #include <stdio.h>
43 #include <signal.h>
44 #include <pwd.h>
45 #include "commonhd.h"
46 #include "sdefine.h"
47 #include <X11/Xos.h>
48 #include "xjutil.h"
49 #include "sxheader.h"
50 #include "config.h"
51 #include "xext.h"
52
53 struct passwd *getpwuid ();
54
55 #ifdef BSD42
56 #include <sgtty.h>
57 #endif /* BSD42 */
58 #ifdef SYSVR2
59 #include <termio.h>
60 #endif /* SYSVR2 */
61
62 extern char *optarg;
63 extern int optind;
64
65 static void
do_end()66 do_end ()
67 {
68 xw_end ();
69 disconnect_server ();
70 exit (0);
71 }
72
73 void
terminate_handler()74 terminate_handler ()
75 {
76 do_end ();
77 }
78
79 static void
do_main()80 do_main ()
81 {
82 int buf[2];
83
84 for (;;)
85 {
86 xw_read (buf);
87 }
88 }
89
90 static int
keyin0()91 keyin0 ()
92 {
93 static int buf[BUFSIZ];
94 static int *bufend = buf;
95 static int *bufstart = buf;
96 int n;
97
98 if (bufstart < bufend)
99 {
100 return (*bufstart++);
101 }
102 for (;;)
103 {
104 if ((n = xw_read (buf)) > 0)
105 {
106 bufstart = buf;
107 bufend = buf + n;
108 return (*bufstart++);
109 }
110 }
111 }
112
113 static int
conv_keyin()114 conv_keyin ()
115 {
116 int keyin0 ();
117
118 return (keyin0 ());
119 }
120
121 int
keyin()122 keyin ()
123 {
124 return (conv_keyin ());
125 }
126
127
128 /*
129 signal settings
130 */
131
132 static void
save_signals()133 save_signals ()
134 {
135 signal (SIGPIPE, SIG_IGN);
136 signal (SIGHUP, SIG_IGN);
137 signal (SIGQUIT, SIG_IGN);
138 signal (SIGTERM, terminate_handler);
139 signal (SIGCHLD, SIG_IGN);
140 }
141
142 void
main(argc,argv)143 main (argc, argv)
144 int argc;
145 char **argv;
146 {
147 extern char xjutil_name[];
148 extern int counter;
149 prgname = argv[0];
150
151 #ifdef DEBUG
152 fprintf (stderr, "%s, %s, %s, %d\n", argv[0], argv[1], argv[2], argv[3][0]);
153 #endif /* DEBUG */
154 display_name = (char *) alloc_and_copy (argv[1]);
155 strcpy (xjutil_name, argv[2]);
156 counter = (int) argv[3][0];
157
158 save_signals ();
159
160 maxchg = MAXCHG;
161 maxlength = MAXCHG * 2;
162 maxbunsetsu = MAXBUNSETSU;
163
164 if (alloc_all_buf () == -1)
165 exit (1);
166
167 if (create_xjutil () == -1)
168 {
169 exit (-1);
170 }
171 if (init_xcvtkey () == -1)
172 {
173 return_error ();
174 exit (-1);
175 }
176
177 switch (init_wnn ())
178 {
179 case -1:
180 terminate_handler ();
181 break;
182 case -2:
183 disconnect_server ();
184 do_end ();
185 break;
186 }
187 connect_server ();
188
189 do_main ();
190 }
191