1 /*
2  * Copyright (C) 2002 Laird Breyer
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License as published by
6  * the Free Software Foundation; either version 3 of the License, or
7  * (at your option) any later version.
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
17  *
18  * Author:   Laird Breyer <laird@lbreyer.com>
19  */
20 
21 #ifndef UTIL_H
22 #define UTIL_H
23 
24 #include <stdio.h>
25 #include "dbacl.h"
26 
27 /* external commands */
28 #define CMD_QUITNOW                     1
29 #define CMD_RELOAD_CATS                 2
30 
31 /* in gcc, most calls to extern inline functions are inlined */
32 
33 #if defined JENKINS4
34 
35 #define JENKINS_HASH_VALUE unsigned long int
36 /* string hash function in jenkins.c */
37 unsigned long int hash( unsigned char *k,
38 			unsigned long int length,
39 			unsigned long int initval);
40 #elif defined JENKINS8
41 
42 #define JENKINS_HASH_VALUE unsigned long long
43 unsigned long long hash( unsigned char *k,
44 			 unsigned long long length,
45 			 unsigned long long initval);
46 #endif
47 
48 /* this should make them as fast as a macro */
49 hash_value_t hash_full_token(const char *tok);
50 hash_value_t hash_partial_token(const char *tok, int len,
51 				const char *extra);
52 
53 /* this should make them as fast as a macro */
54 digitized_weight_t digitize_a_weight(weight_t w, token_order_t o);
55 weight_t undigitize_a_weight(digitized_weight_t d, token_order_t o);
56 
57 double nats2bits(double score);
58 
59 double chi2_cdf(double df, double x);
60 double gamma_tail(double a, double b, double x);
61 double normal_cdf(double x);
62 
63 extern double igamc(double, double);
64 extern double ndtr(double);
65 
66 typedef struct {
67   const char *tempfile;
68 } signal_cleanup_t;
69 
70 void init_signal_handling();
71 void process_pending_signal(FILE *input);
72 void cleanup_signal_handling();
73 
74 void init_buffers();
75 void cleanup_buffers();
76 void cleanup_tempfiles();
77 void set_iobuf_mode(FILE *input);
78 
79 bool_t fill_textbuf(FILE *input, int *extra_lines);
80 #if defined HAVE_MBRTOWC
81 bool_t fill_wc_textbuf(char *pptextbuf, mbstate_t *shiftstate);
82 #endif
83 
84 #define E_ERROR 0
85 #define E_WARNING 1
86 #define E_FATAL 2
87 void errormsg(int type, const char *fmt, ...)
88 #ifdef __GNUC__
89 __attribute__((format (printf, 2, 3)))
90 #endif
91 ;
92 void print_token(FILE *out, const char *tok);
93 
94 /* Solaris needs this */
95 #if !defined isinf
96 #define isinf(x) (!finite(x) && (x)==(x))
97 #endif
98 
99 /* Solaris needs this */
100 #if !defined isblank
101 #define isblank(c) (((c) == ' ') || ((c) == '\t'))
102 #endif
103 
104 #endif
105