1 /*
2  *  $Id: wnn_os.h,v 1.16 2005/06/12 17:14:23 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, 2005
14  *
15  * Maintainer:  FreeWnn Project   <freewnn@tomo.gr.jp>
16  *
17  * This library is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU Lesser General Public
19  * License as published by the Free Software Foundation; either
20  * version 2 of the License, or (at your option) any later version.
21  *
22  * This library 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 GNU
25  * Lesser General Public License for more details.
26  *
27  * You should have received a copy of the GNU Lesser General Public
28  * License along with this library; if not, write to the
29  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
30  * 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 #ifdef TERMINFO
54 #include <curses.h>
55 #include <term.h>
56 #endif
57 
58 /* strchr vs. index, etc. */
59 #if (HAVE_MEMSET) && !(HAVE_BZERO)
60 #  define bzero(adr,n)  memset((adr),0,(n))
61 #endif
62 #if !(HAVE_STRCHR) && (HAVE_INDEX)
63 #  define strchr  index
64 #endif
65 #if !(HAVE_STRRCHR) && (HAVE_RINDEX)
66 #  define strrchr rindex
67 #endif
68 
69 /* SIGNAL */
70 
71 #ifdef SYSVR2
72 #ifndef re_signal
73 # define re_signal(x, y) signal((x), (y))
74 #endif
75 #else
76 # define re_signal(x, y)
77 #endif
78 
79 #if !defined (SIGCHLD) && defined (SIGCLD)
80 #  define SIGCHLD SIGCLD
81 #endif
82 
83 typedef RETSIGTYPE (*intfnptr) ();
84 
85 /* Temporally place the number of filedescripters hack here. */
86 #if HAVE_GETDTABLESIZE
87 #  define WNN_NFD getdtablesize()
88 #elif defined (OPEN_MAX)
89 #  define WNN_NFD OPEN_MAX
90 #elif defined (NOFILE)
91 #  define WNN_NFD NOFILE
92 #endif /* HAVE_GETDTABLESIZE */
93 
94 /* pseudo ramdom number */
95 #if !defined (RAND_MAX)
96 #  if defined (INT_MAX)
97 #    define RAND_MAX INT_MAX
98 #  else
99 #    define RAND_MAX 0x7fffffff
100 #  endif /* INT_MAX */
101 #endif /* RAND_MAX*/
102 
103 #if HAVE_DRAND48
104 #  define DRAND()  drand48 ()
105 #  define SDRAND(x)  srand48 (x)
106 #elif HAVE_RAMDOM
107 #  define DRAND()  ((double) random() / (double) RAND_MAX)
108 #  define SDRAND(x)  srandom (x)
109 #else
110 #  define DRAND()  ((double) rand() / (double) RAND_MAX)
111 #  define SDRAND(x)  srand (x)
112 #endif /* HAVE_DRAND48 */
113 
114 #if HAVE_RANDOM
115 #  define RAND()  random ()
116 #  define SRAND(x)  srandom (x)
117 #else
118 #  define RAND()  rand ()
119 #  define SRAND(x)  srand (x)
120 #endif /* HAVE_RANDOM */
121 
122 /*
123  * It may be needless and had better be removed, however,
124  * Wnn4 did not take it for granted that the system provided
125  * FD_SET and other feature that SUS v.2 determines.
126  * So I left Wnn4's own definition with a little modification
127  * in case the system did not provide the feature.
128  * I took a look into the FreeBSD definition of FD_* family.
129  * A small change comes from Canna 3.6p3.
130  */
131 #if !defined(HAVE_FD_SET) && !defined(FD_SET) && defined(HAVE_UNISTD_H)
132 #  include <unistd.h> /* to define FD_SET */
133 #endif
134 #if !defined(HAVE_FD_SET) && !defined(FD_SET)
135 typedef unsigned long fd_mask;
136 #define BINTSIZE               (sizeof(unsigend long) *8)
137 #define SETSIZE         WNN_NFD
138 #define SET_WIDTH       ((SETSIZE) + (BINTSIZE - 1U) / (BINTSIZE))
139 typedef struct wnn_fd_set {
140   wnn_fd_mask fds_bits[SET_WIDTH];
141 }
142 #define FD_SET(pos,array)  (array[pos/BINTSIZE] |= (1<<(pos%BINTSIZE)))
143 #define FD_CLR(pos,array)  (array[pos/BINTSIZE] &= ~(1<<(pos%BINTSIZE)))
144 #define FD_ISSET(pos,array)        (array[pos/BINTSIZE] &  (1<<(pos%BINTSIZ
145 E)))
146 #define FD_ZERO(array)     (bzero (array, FD_SET_WIDTH))
147 #endif /* !HAVE_FD_SET */
148 
149 
150 /* function prototypes (temporal use. need reconstruction) */
151 char *get_server_env (char *lang);	/* server_env.c */
152 unsigned int create_cswidth (char *s);	/* xutoj.c */
153 int euksc_to_ksc (unsigned char *ksc,
154 		  unsigned char *euksc,
155 		  int eusiz);		/* xutoj.c */
156 
157 #include "fake-rfc2553.h"
158 #endif  /* WNN_OS_H */
159