1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501
|
#include "config.h"
#include <stdio.h>
#include <signal.h>
#include <fcntl.h>
#include "fep.h"
#include <sys/types.h>
#include <sys/wait.h>
#if defined TERMIOS || defined TERMIO
#if !defined(VDISABLE)
# ifdef _POSIX_VDISABLE
# define VDISABLE _POSIX_VDISABLE
# else
# define VDISABLE 0377
# endif
#endif
#ifdef TERMIOS
#define GET_TTY(tty,ioval) tcgetattr(tty,ioval)
#define SET_TTY(tty,ioval) tcsetattr(tty,TCSANOW,ioval)
#else /* not TERMIOS */
#define GET_TTY(tty,ioval) ioctl(tty, TCGETA, ioval)
#define SET_TTY(tty,ioval) ioctl(tty, TCSETA, ioval)
#endif /* TERMIOS */
#else /* not TERMIOS nor TERMIO */
#define GET_TTY(tty,ioval) tiocget(tty, ioval)
#define SET_TTY(tty,ioval) tiocset(tty, ioval)
#endif
#ifndef NO_SUSPEND
SignalFunc suspend();
#endif
TERMPARAM d_ioval;
int tty;
#ifdef TIOCSWINSZ
struct winsize d_winsize;
#endif /* TIOCSWINSZ */
extern
int ShellPID;
extern
FILE *Shellout;
#if !defined(TERMIOS) && !defined(TERMIO)
static int
tiocget(fd, ioval)
int fd;
TERMPARAM *ioval;
{
int er;
er = ioctl(fd, TIOCGETP, &(ioval->m_ttyb));
if ( er == -1 ) return er;
er = ioctl(fd, TIOCGETC, &(ioval->m_tchars));
if ( er == -1 ) return er;
#ifdef TIOCLGET
er = ioctl(fd, TIOCLGET, &(ioval->m_lmode));
if ( er == -1 ) return er;
#endif /* TIOCLGET */
#ifdef TIOCGETD
er = ioctl(fd, TIOCGETD, &(ioval->m_ldisc));
if ( er == -1 ) return er;
#endif /* TIOCGETD */
#ifdef TIOCGLTC
er = ioctl(fd, TIOCGLTC, &(ioval->m_ltchars));
if ( er == -1 ) return er;
#endif /* TIOCGLTC */
#ifdef sony_news
# ifdef TIOCKGET
er = ioctl(fd, TIOCKGET, &(ioval->km_con));
if ( er == -1 ) return er;
# endif /* TIOCKGET */
# ifdef TIOCKGETC
er = ioctl(fd, TIOCKGETC, &(ioval->km_jtchars));
if ( er == -1 ) return er;
# endif /* TIOCKGETC */
#endif /* sony_news */
return er;
}
static int
tiocset(fd, ioval)
int fd;
TERMPARAM *ioval;
{
int er;
er = ioctl(fd, TIOCSETP, &(ioval->m_ttyb));
if ( er == -1 ) return er;
er = ioctl(fd, TIOCSETC, &(ioval->m_tchars));
#ifdef TIOCLSET
er = ioctl(fd, TIOCLSET, &(ioval->m_lmode));
if ( er == -1 ) return er;
#endif /* TIOCLSET */
#ifdef TIOCGETD
er = ioctl(fd, TIOCSETD, &(ioval->m_ldisc));
if ( er == -1 ) return er;
#endif /* TIOCGETD */
#ifdef TIOCGLTC
er = ioctl(fd, TIOCSLTC, &(ioval->m_ltchars));
if ( er == -1 ) return er;
#endif /* TIOCGLTC */
#ifdef sony_news
# ifdef TIOCKGET
er = ioctl(fd, TIOCKSET, &(ioval->km_con));
if ( er == -1 ) return er;
# endif /* TIOCKGET */
# ifdef TIOCKGETC
er = ioctl(fd, TIOCKSETC, &(ioval->km_jtchars));
if ( er == -1 ) return er;
# endif /* TIOCKGETC */
#endif /* sony_news */
return er;
}
#endif /* not TERMIOS */
set_winsize(tty)
int tty;
{
#ifdef TIOCSWINSZ
int er;
struct winsize s_winsize;
s_winsize = d_winsize;
if (msgLine() == (int)UseBottomLine) {
s_winsize.ws_row--;
}
er = ioctl(tty, TIOCSWINSZ, &s_winsize);
if (er == -1) {
printf("Error occured\n");
}
#endif /* TIOCSWINSZ */
}
get_winsize()
{
#ifdef TIOCSWINSZ
extern int lines, columns;
ioctl(tty, TIOCGWINSZ, &d_winsize);
if (d_winsize.ws_col == 0) {
d_winsize.ws_col = columns;
} else {
columns = d_winsize.ws_col;
}
if (d_winsize.ws_row == 0) {
d_winsize.ws_row = lines;
} else {
lines = d_winsize.ws_row;
}
ioctl(tty, TIOCSWINSZ, &d_winsize);
#endif /* TIOCSWINSZ */
}
set_tty()
{ int er;
TERMPARAM ioval;
GET_TTY(tty, &d_ioval);
ioval = d_ioval;
#if defined TERMIOS || defined TERMIO
ioval.c_iflag &= ~(INLCR|IGNCR|ICRNL|IXON|IXOFF);
# ifdef ISTRIP
ioval.c_iflag &= ~ISTRIP; /* 8bit through */
# endif
ioval.c_lflag &= ~(ISIG|ICANON|ECHO);
ioval.c_oflag &= ~(OPOST);
ioval.c_cc[VMIN] = 1;
ioval.c_cc[VTIME] = 0;
/* invalidate special control characters */
ioval.c_cc[VINTR] = VDISABLE;
ioval.c_cc[VSTART] = VDISABLE;
ioval.c_cc[VSTOP] = VDISABLE;
ioval.c_cc[VQUIT] = VDISABLE;
# ifdef VDISCARD
ioval.c_cc[VDISCARD]= VDISABLE;
# endif
# ifdef VLNEXT
ioval.c_cc[VLNEXT] = VDISABLE;
# endif
# ifdef VSUSP
ioval.c_cc[VSUSP] = VDISABLE;
# endif
# ifdef VDSUSP
ioval.c_cc[VDSUSP] = VDISABLE;
# endif
#else
ioval.m_ttyb.sg_flags = RAW;
#endif
er = SET_TTY(tty, &ioval);
initFep();
if (er == -1) {
printf("Error occured\n");
reset_tty();
Exit(-1);
}
}
reset_tty()
{
reset_tty_without_close();
close(tty);
}
reset_tty_without_close()
{
termFep();
SET_TTY(tty, &d_ioval);
}
set_tty_sane(tty)
int tty;
{ int er;
TERMPARAM ioval;
ioval = d_ioval;
#if defined TERMIOS || defined TERMIO
#ifndef ECHOKE
# define ECHOKE 0
#endif
ioval.c_lflag |= ISIG | ICANON | ECHO | ECHOE | ECHOK | ECHOKE;
ioval.c_iflag |= BRKINT | IGNPAR | ICRNL;
# ifdef ISTRIP
ioval.c_iflag &= ~ISTRIP; /* 8bit through */
# endif
ioval.c_oflag |= OPOST | ONLCR;
#else /* if not TERMIOS */
#ifdef BSD42
ioval.m_ttyb.sg_flags |= ECHO | CRMOD | ANYP | CRTERA | CRTKIL;
#else
ioval.m_ttyb.sg_flags |= ECHO | CRMOD | ANYP | CRTERA | CRTKIL | PASS8;
#endif /* BSD42 */
# ifdef TIOCLGET
# ifdef LPASS8
ioval.m_lmode |= LPASS8;
# endif
# ifdef LPASS8OUT
ioval.m_lmode |= LPASS8OUT;
# endif
# ifdef LEUCBKSP
ioval.m_lmode |= LEUCBKSP;
# endif
# endif
#endif /* not TERMIOS */
er = SET_TTY(tty, &ioval);
if (er == -1) {
printf("Error occured\n");
}
}
tty_ready()
{ char *ttyname();
tty = open(ttyname(0),O_RDWR);
}
SignalFunc
reset_exit()
{
reset_tty();
signal(SIGCHLD,SIG_DFL);
Exit(-1);
}
#ifndef LINUX
SignalFunc
bus_exit()
{
reset_tty();
fprintf(stderr,"BUS ERROR\n");
Abort();
}
#endif
SignalFunc
segv_exit()
{
reset_tty();
fprintf(stderr,"SEGMENTATION VIOLATION\n");
Abort();
}
#ifdef APOLLO
SignalFunc
chld_exit()
{
reset_tty();
Exit(0);
}
#endif
#ifdef HPUX
#define IF_STOPPED(x) WIFSTOPPED((x).w_stopval)
#else /* not HPUX */
#define IF_STOPPED(x) WIFSTOPPED(x)
#endif /* not HPUX */
SignalFunc
chld_changed()
{
int cpid;
#if defined(_AIX) || defined(SVR4)
int statusp;
#else
union wait statusp;
#endif
#ifndef NO_SUSPEND
while ((cpid = wait((int *)&statusp)) != -1 && cpid != ShellPID)
;
#else
do {
#ifdef SVR4
cpid = waitpid(-1, &statusp, WUNTRACED|WNOHANG);
#else
cpid = wait3((int *) &statusp, WUNTRACED|WNOHANG, (struct rusage *) 0);
#endif
} while (cpid != 0 && cpid != -1 && cpid != ShellPID);
if (cpid != ShellPID)
return; /* ignore */
if (IF_STOPPED(statusp)) { /* suspend */
suspend();
}
else
#endif /* NO_SUSPEND */
{
reset_tty();
Exit(0);
}
}
SignalFunc
iot_exit()
{
reset_tty();
fprintf(stderr,"Abort.\n");
Abort();
}
SignalFunc
hup_exit()
{
reset_tty();
fprintf(stderr,"Hungup\n");
Exit(-1);
}
SignalFunc
int_exit()
{
reset_tty();
fprintf(stderr,"Interrupt\n");
Exit(-1);
}
SignalFunc
pipe_exit()
{
reset_tty();
fprintf(stderr,"Pipe down\n");
Exit(-1);
}
SignalFunc
term_exit()
{
reset_tty();
fprintf(stderr,"Terminate\n");
Exit(-1);
}
#ifndef NO_SUSPEND
SignalFunc
suspend()
{
reset_tty_without_close();
signal(SIGTSTP,SIG_DFL);
kill(0,SIGTSTP);
/* process stopped */
signal(SIGTSTP,suspend);
set_tty();
#ifdef HAVE_KILLPG
killpg(ShellPID,SIGCONT); /* 4.0 - 4.3BSD */
#else
kill(-ShellPID,SIGCONT); /* 4.3BSD Reno - , SysV */
#endif
}
#endif
#ifdef SIGWINCH
SignalFunc
winchange()
{
int tty;
signal(SIGWINCH,SIG_IGN);
tty = fileno(Shellout);
get_winsize();
set_winsize(tty);
initFep();
showcurmode();
signal(SIGWINCH,winchange);
}
#endif
SignalFunc
sig_usr1()
{
signal(SIGUSR1,SIG_IGN);
initFep();
toggleEscape(ViEsc);
signal(SIGUSR1,sig_usr1);
}
SignalFunc
sig_usr2()
{
signal(SIGUSR2,SIG_IGN);
initFep();
toggleEscape(EmacsEsc);
signal(SIGUSR2,sig_usr2);
}
SignalFunc
sig_int()
{
signal(SIGHUP,SIG_IGN);
initFep();
toggleEscape(NoEsc);
signal(SIGHUP,sig_int);
}
set_int()
{
signal(SIGHUP ,hup_exit);
signal(SIGINT ,sig_int);
/* signal(SIGQUIT,iot_exit); */
signal(SIGILL ,reset_exit);
signal(SIGIOT ,iot_exit);
signal(SIGFPE ,reset_exit);
#ifndef LINUX
signal(SIGBUS ,bus_exit);
#endif
signal(SIGSEGV,segv_exit);
signal(SIGPIPE,pipe_exit);
signal(SIGTERM,term_exit);
#ifndef NO_SUSPEND
signal(SIGTSTP,suspend);
#endif
#ifdef SIGWINCH
signal(SIGWINCH,winchange);
#endif
signal(SIGUSR1,sig_usr1);
signal(SIGUSR2,sig_usr2);
}
saveJisyo()
{
#ifdef USE_SERVER
if ((NetLearnMode != LearnTemporal) && (UserDic != NULL)) {
printf("Saving JISYO...\n");
closeSKK(UserDic,UserDicName);
}
#else
if (UserDic != NULL) {
printf("Saving JISYO...\n");
closeSKK(UserDic,UserDicName);
}
#endif
}
Exit(v)
int v;
{
freeDevice();
saveJisyo();
exit(v);
}
Abort()
{
freeDevice();
saveJisyo();
signal(SIGQUIT,SIG_DFL);
signal(SIGIOT, SIG_DFL);
abort();
}
|