comparison Wnn/uum/termio.c @ 0:bbc77ca4def5

initial import
author Yoshiki Yazawa <yaz@cc.rim.or.jp>
date Thu, 13 Dec 2007 04:30:14 +0900
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:bbc77ca4def5
1 /*
2 * $Id: termio.c,v 1.7 2006/09/04 17:21:29 aonoto Exp $
3 */
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 FreeWnn Project 1999, 2000, 2002, 2006
14 *
15 * Maintainer: FreeWnn Project
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 of the License, or
20 * (at your option) 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 this program; if not, write to the Free Software
29 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30 */
31 #ifdef HAVE_CONFIG_H
32 # include <config.h>
33 #endif
34
35 #include <stdio.h>
36 #if STDC_HEADERS
37 # include <stdlib.h>
38 # include <string.h>
39 #else
40 # if defined (HAVE_STRINGS_H)
41 # include <strings.h>
42 # endif /* HAVE_STRINGS_H */
43 #endif /* STDC_HEADERS */
44
45 #include "commonhd.h"
46 #include "sdefine.h"
47 #include "sheader.h"
48
49 /*
50 * tparm() macro for fixed argument prototype systems:
51 * It may not harm on systems that tparm() has variable argument prototype
52 * (or no prototype for compatibility).
53 */
54 #define TPARM_3ARGS(func, p1, p2) tparm((func), (p1), (p2), 0,0,0,0,0,0,0)
55
56 #ifdef HAVE_TERMINFO
57 #include <stdio.h>
58 #include <curses.h>
59 #include <term.h>
60 #ifdef putchar
61 #undef putchar
62 #endif
63 extern int putchar ();
64
65 extern char Term_Name[];
66 extern char *Term_UnderScoreStart;
67 extern char *Term_UnderScoreEnd;
68 extern char *Term_ClrScreen;
69 extern char *Term_ClrEofLine;
70 extern char *Term_ThrowCursor;
71 extern char *Term_StandOutStart;
72 extern char *Term_StandOutEnd;
73 extern char *Term_BoldOutStart;
74 extern char *Term_BoldOutEnd;
75 static int bold_mode_fun = 0;
76
77 int
78 openTermData ()
79 {
80 char *cp, *get_kbd_env ();
81 int status;
82 /* int k; */
83 char lcode[10];
84 char termchar[20];
85 char errprefix[1024] = "error";
86
87 /* for convert_key --- added by Nide 10/3 */
88 if (NULL == (cp = get_kbd_env ()) || 0 != convert_getterm (cp, (0 != verbose_option)))
89 {
90 fprintf (stderr, "Cannot get keyboard information.\n");
91 return (-1);
92 }
93
94 if ((cp = getenv ("TERM")) == NULL)
95 {
96 fprintf (stderr, "Cannot get terminal name.");
97 return (-1);
98 }
99 strcpy (Term_Name, cp);
100
101 if ((strlen (Term_Name) > 2) && (strcmp (Term_Name + (strlen (Term_Name) - 2), "-j") == 0))
102 {
103 fprintf (stderr, MSG_GET (4));
104 /*
105 fprintf(stderr,"Uum:uumからuumはおこせません。\n");
106 */
107 return (-1);
108 }
109 setupterm (0, 1, &status);
110 reset_shell_mode ();
111 if (status != 1)
112 {
113 return (-1);
114 }
115 #if defined(uniosu)
116 if (jterm < 2)
117 { /* kanji terminal */
118 fprintf (stderr, "Not kanji terminal. Goodbye !\n");
119 return (-1);
120 }
121 #endif /* defined(uniosu) */
122 if (save_cursor == (char *) NULL || *save_cursor == NULL || restore_cursor == (char *) NULL || *restore_cursor == NULL || change_scroll_region == (char *) NULL || *change_scroll_region == NULL)
123 {
124 fprintf (stderr, "Your terminal is not strong enough. Goodbye !\n");
125 return (-1);
126 }
127 /*
128 * setenv TERM "${TERM}-j" to prevent starting uum over
129 * uum-controled terminal (disabled for now ...)
130 */
131 termchar[0] = 0;
132 strcat (termchar, cp);
133 /* strcat (termchar, "-j"); */
134 if (setenv ("TERM", termchar, 1) != 0)
135 {
136 #if HAVE_SNPRINTF
137 snprintf (errprefix, sizeof (errprefix),
138 "error at %s (%d)", __FILE__, __LINE__);
139 #endif /* HAVE_SNPRINTF */
140 perror (errprefix);
141 exit (1);
142 }
143
144 sprintf (lcode, "%d", lines - conv_lines);
145 if (setenv ("LINES", lcode, 1) != 0)
146 {
147 #if HAVE_SNPRINTF
148 snprintf (errprefix, sizeof (errprefix),
149 "error at %s (%d)", __FILE__, __LINE__);
150 #endif /* HAVE_SNPRINTF */
151 perror (errprefix);
152 exit (1);
153 }
154
155 if (cursor_normal && cursor_invisible)
156 {
157 cursor_invisible_fun = 1;
158 }
159 else
160 {
161 cursor_invisible_fun = 0;
162 }
163 if (keypad_xmit && *keypad_xmit && keypad_local && *keypad_local)
164 {
165 keypad_fun = 1;
166 }
167 else
168 {
169 keypad_fun = 0;
170 }
171 Term_UnderScoreEnd = exit_underline_mode;
172 Term_UnderScoreStart = enter_underline_mode;
173 Term_StandOutEnd = exit_standout_mode;
174 Term_StandOutStart = enter_standout_mode;
175 if (enter_bold_mode && exit_attribute_mode)
176 bold_mode_fun = 1;
177 else
178 bold_mode_fun = 0;
179
180 Term_BoldOutStart = enter_bold_mode;
181 Term_BoldOutEnd = exit_attribute_mode;
182 return (0);
183 }
184
185
186 void
187 closeTermData ()
188 {
189 resetterm ();
190 reset_shell_mode ();
191 }
192
193 void
194 set_keypad_on ()
195 {
196 tputs (keypad_xmit, 1, putchar);
197 }
198
199 void
200 set_keypad_off ()
201 {
202 tputs (keypad_local, 1, putchar);
203 }
204
205 void
206 set_scroll_region (start, end)
207 int start, end;
208 {
209 tputs (TPARM_3ARGS (change_scroll_region, start, end), 1, putchar);
210 }
211
212 void
213 clr_end_screen ()
214 {
215 tputs (clr_eos, 1, putchar);
216 }
217
218
219 void
220 clr_screen ()
221 {
222 tputs (clear_screen, lines, putchar);
223 Term_ClrScreen = clear_screen;
224 }
225
226 void
227 clr_line1 ()
228 {
229 tputs (clr_eol, 1, putchar);
230 Term_ClrEofLine = clr_eol;
231 }
232
233 void
234 throw_cur_raw (col, row)
235 int col, row;
236 {
237 tputs (TPARM_3ARGS (cursor_address, row, col), 1, putchar);
238 }
239
240 void
241 h_r_on_raw ()
242 {
243 tputs (enter_standout_mode, 1, putchar);
244 }
245
246 void
247 h_r_off_raw ()
248 {
249 tputs (exit_standout_mode, 1, putchar);
250 }
251
252 void
253 u_s_on_raw ()
254 {
255 tputs (enter_underline_mode, 1, putchar);
256 }
257
258 void
259 u_s_off_raw ()
260 {
261 tputs (exit_underline_mode, 1, putchar);
262 }
263
264 void
265 b_s_on_raw ()
266 {
267 if (bold_mode_fun)
268 tputs (enter_bold_mode, 1, putchar);
269 else
270 tputs (enter_underline_mode, 1, putchar);
271 }
272
273 void
274 b_s_off_raw ()
275 {
276 if (bold_mode_fun)
277 tputs (exit_attribute_mode, 1, putchar);
278 else
279 tputs (exit_underline_mode, 1, putchar);
280 }
281
282 void
283 ring_bell ()
284 {
285 tputs (bell, 1, putchar);
286 flush ();
287 }
288
289 void
290 save_cursor_raw ()
291 {
292 tputs (save_cursor, 1, putchar);
293 }
294
295 void
296 restore_cursor_raw ()
297 {
298 tputs (restore_cursor, 1, putchar);
299 }
300
301 void
302 cursor_invisible_raw ()
303 {
304 tputs (cursor_invisible, 1, putchar);
305 }
306
307 void
308 cursor_normal_raw ()
309 {
310 tputs (cursor_normal, 1, putchar);
311 }
312
313 #endif /* HAVE_TERMINFO */