1 /* 2 * wnn_os.h,v 1.12 2002/06/22 13:24:31 hiroo Exp 3 * Canna: $Id: wnn_os.h,v 1.5 2003/01/06 01:41:28 aida_s Exp $ 4 */ 5 6 /* 7 * FreeWnn is a network-extensible Kana-to-Kanji conversion system. 8 * This file is part of FreeWnn. 9 * 10 * Copyright Kyoto University Research Institute for Mathematical Sciences 11 * 1987, 1988, 1989, 1990, 1991, 1992 12 * Copyright OMRON Corporation. 1987, 1988, 1989, 1990, 1991, 1992, 1999 13 * Copyright ASTEC, Inc. 1987, 1988, 1989, 1990, 1991, 1992 14 * Copyright FreeWnn Project 1999, 2000, 2002 15 * 16 * Maintainer: FreeWnn Project <freewnn@tomo.gr.jp> 17 * 18 * This program is free software; you can redistribute it and/or modify 19 * it under the terms of the GNU General Public License as published by 20 * the Free Software Foundation; either version 2 of the License, or 21 * (at your option) any later version. 22 * 23 * This program is distributed in the hope that it will be useful, 24 * but WITHOUT ANY WARRANTY; without even the implied warranty of 25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 26 * GNU General Public License for more details. 27 * 28 * You should have received a copy of the GNU General Public License 29 * along with this program; if not, write to the Free Software 30 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 31 */ 32 33 #ifndef WNN_OS_H 34 #define WNN_OS_H 35 36 #ifdef HAVE_CONFIG_H 37 # include <config.h> 38 #endif 39 40 /* system headers needed for system dependent configuration */ 41 #include <signal.h> 42 #if STDC_HEADERS 43 # include <stdlib.h> 44 # include <limits.h> 45 #endif /* STDC_HEADERS */ 46 47 #include <sys/types.h> 48 #include <sys/file.h> 49 #if HAVE_SYS_PARAM_H 50 # include <sys/param.h> 51 #endif 52 53 /* ncurses' term.h defines them to either 0 or 1! */ 54 #ifndef HAVE_TERMIOS_H 55 # define DONT_HAVE_TERMIOS_H 56 #endif 57 #ifndef HAVE_TERMIO_H 58 # define DONT_HAVE_TERMIO_H 59 #endif 60 #ifndef HAVE_SYS_TERMIO_H 61 # define DONT_HAVE_SYS_TERMIO_H 62 #endif 63 #ifndef HAVE_SGTTY_H 64 # define DONT_HAVE_SGTTY_H 65 #endif 66 67 #ifdef CONFIG_TERMINFO 68 # if defined(HAVE_TERMINFO) 69 # if defined(HAVE_CURSES_H) 70 # include <curses.h> 71 # elif defined(HAVE_NCURSES_H) 72 # include <ncurses.h> 73 # else 74 # error "no terminfo header" 75 # endif 76 # ifdef HAVE_TERM_H 77 # include <term.h> 78 # endif 79 # else /* !HAVE_TERMINFO */ 80 # if defined(HAVE_TERMCAP_H) 81 # include <termcap.h> 82 # endif 83 # endif 84 #endif 85 86 #ifndef CONFIG_TERMINFO 87 #ifdef TERMINFO 88 #include <curses.h> 89 #include <term.h> 90 #endif 91 #endif 92 93 #ifdef DONT_HAVE_TERMIOS_H 94 # undef HAVE_TERMIOS_H 95 # undef DONT_HAVE_TERMIOS_H 96 #endif 97 #ifdef DONT_HAVE_TERMIO_H 98 # undef HAVE_TERMIO_H 99 # undef DONT_HAVE_TERMIO_H 100 #endif 101 #ifdef DONT_HAVE_SYS_TERMIO_H 102 # undef HAVE_SYS_TERMIO_H 103 # undef DONT_HAVE_SYS_TERMIO_H 104 #endif 105 #ifdef DONT_HAVE_SGTTY_H 106 # undef HAVE_SGTTY_H 107 # undef DONT_HAVE_SGTTY_H 108 #endif 109 110 /* strchr vs. index, etc. */ 111 #if (HAVE_MEMSET) && !(HAVE_BZERO) 112 # define bzero(adr,n) memset((adr),0,(n)) 113 #endif 114 #if !(HAVE_STRCHR) && (HAVE_INDEX) 115 # define strchr index 116 #endif 117 #if !(HAVE_STRRCHR) && (HAVE_RINDEX) 118 # define strrchr rindex 119 #endif 120 121 /* SIGNAL */ 122 123 #ifdef SYSVR2 124 #ifndef re_signal 125 # define re_signal(x, y) signal((x), (y)) 126 #endif 127 #else 128 # define re_signal(x, y) 129 #endif 130 131 #if !defined (SIGCHLD) && defined (SIGCLD) 132 # define SIGCHLD SIGCLD 133 #endif 134 135 typedef RETSIGTYPE (*intfnptr) (); 136 137 /* Temporally place the number of filedescripters hack here. */ 138 #if HAVE_GETDTABLESIZE 139 # define WNN_NFD getdtablesize() 140 #elif defined (OPEN_MAX) 141 # define WNN_NFD OPEN_MAX 142 #elif defined (NOFILE) 143 # define WNN_NFD NOFILE 144 #endif /* HAVE_GETDTABLESIZE */ 145 146 /* pseudo ramdom number */ 147 #if !defined (RAND_MAX) 148 # if defined (INT_MAX) 149 # define RAND_MAX INT_MAX 150 # else 151 # define RAND_MAX 0x7fffffff 152 # endif /* INT_MAX */ 153 #endif /* RAND_MAX*/ 154 155 #if HAVE_DRAND48 156 # define DRAND() drand48 () 157 # define SDRAND(x) srand48 (x) 158 #elif HAVE_RAMDOM 159 # define DRAND() ((double) random() / (double) RAND_MAX) 160 # define SDRAND(x) srandom (x) 161 #else 162 # define DRAND() ((double) rand() / (double) RAND_MAX) 163 # define SDRAND(x) srand (x) 164 #endif /* HAVE_DRAND48 */ 165 166 #if HAVE_RANDOM 167 # define RAND() random () 168 # define SRAND(x) srandom (x) 169 #else 170 # define RAND() rand () 171 # define SRAND(x) srand (x) 172 #endif /* HAVE_RANDOM */ 173 174 #if !defined(HAVE_FD_SET) && !defined(FD_SET) && defined(HAVE_UNISTD_H) 175 #include <unistd.h> /* to define FD_SET */ 176 #endif 177 #if defined(HAVE_FD_SET) || defined(FD_SET) 178 typedef fd_set wnn_fd_set; 179 #define WNN_FD_SET FD_SET 180 #define WNN_FD_CLEAR FD_CLEAR 181 #define WNN_FD_ISSET FD_ISSET 182 #define WNN_FD_ZERO FD_ZERO 183 #else 184 typedef unsigned long wnn_fd_mask; 185 #define BINTSIZE (sizeof(unsigend long) *8) 186 #define WNN_FD_SETSIZE WNN_NFD 187 #define WNN_FD_SET_WIDTH ((WNN_FD_SETSIZE) + (BINTSIZE - 1U) / (BINTSIZE)) 188 typedef struct wnn_fd_set { 189 wnn_fd_mask fds_bits[WNN_FD_SET_WIDTH]; 190 } 191 #define WNN_FD_SET(pos,array) (array[pos/BINTSIZE] |= (1<<(pos%BINTSIZE))) 192 #define WNN_FD_CLR(pos,array) (array[pos/BINTSIZE] &= ~(1<<(pos%BINTSIZE))) 193 #define WNN_FD_ISSET(pos,array) (array[pos/BINTSIZE] & (1<<(pos%BINTSIZE))) 194 #define WNN_FD_ZERO(array) (bzero (array, WNN_FD_SET_WIDTH)) 195 #endif /* !(HAVE_FD_ZERO || defined (FD_ZERO)) */ 196 197 #ifdef HAVE_KILLPG 198 # define KILLPG(pgrp, sig) killpg(pgrp, sig) 199 #else 200 # define KILLPG(pgrp, sig) kill(-(pgrp), sig) 201 #endif /* HAVE_KILLPG */ 202 203 #if defined(HAVE_GETPGID) /* SVR4 and most modern systems */ 204 # define GETPGID(pid) getpgid(pid) 205 #elif defined(HAVE_GETPGRP) && !defined(GETPGRP_VOID) /* 4.3BSD */ 206 # define GETPGID(pid) getpgrp(pid) 207 #elif defined(uniosu) 208 # define GETPGID(pid) ngetpgrp(pid) 209 #else 210 /* no way to get process group id */ 211 #endif /* GETPGID */ 212 213 #if defined(HAVE_GETPGRP) && defined(GETPGRP_VOID) /* POSIX, SysV */ 214 # define GETMYPGRP() getpgrp() 215 #elif defined(GETPGID) 216 # define GETMYPGRP() GETPGID(getpid()) 217 #else 218 /* probably some build error occured */ 219 # error "don't know how to get my process group id" 220 #endif /* GETMYPGRP */ 221 222 /* function prototypes (temporal use. need reconstruction) */ 223 unsigned int create_cswidth (char *s); /* xutoj.c */ 224 int euksc_to_ksc (unsigned char *ksc, 225 unsigned char *euksc, 226 int eusiz); /* xutoj.c */ 227 int get_short (short *sp, FILE *ifpter); /* bdic.c */ 228 229 #endif /* WNN_OS_H */ 230