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
|
/*
*
* libnamazu.c - Namazu library api
*
* $Id: libnamazu.c,v 1.35.8.11 2008-03-06 15:38:09 opengl2772 Exp $
*
* Copyright (C) 1997-1999 Satoru Takabayashi All rights reserved.
* Copyright (C) 2000-2008 Namazu Project All rights reserved.
* Copyright (C) 1999 NOKUBI Takatsugu All rights reserved.
* This is free software with ABSOLUTELY NO WARRANTY.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA
*
*
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#ifdef HAVE_SUPPORT_H
# include "support.h"
#endif
#include <stdio.h>
#ifdef HAVE_STDLIB_H
# include <stdlib.h>
#endif
#include <sys/types.h>
#include <fcntl.h>
#include <ctype.h>
#include <sys/stat.h>
#include <signal.h>
#include <stdarg.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#else
# ifdef _WIN32
# include <io.h>
# endif
#endif
#ifdef HAVE_STRING_H
# include <string.h>
#else
# include <strings.h>
#endif
#include "libnamazu.h"
#include "util.h"
#include "codeconv.h"
#include "search.h"
#include "hlist.h"
#include "field.h"
#include "i18n.h"
#include "regex.h"
#include "var.h"
#include "alias.h"
#include "replace.h"
#include "idxname.h"
static enum nmz_sortmethod sortmethod = SORT_BY_SCORE;
static enum nmz_sortorder sortorder = DESCENDING;
static int maxhit = 10000; /* Ignore if pages matched more than this. */
static int maxmatch = 1000; /* Ignore if words matched more than this. */
static int debugmode = 0;
static int loggingmode = 1; /* do logging with NMZ.slog */
static int regex_searchmode = 1; /* enable regex search */
static char dyingmsg[BUFSIZE] = "";
static int output_warn_to_file = 0; /* output warning to file or stderr */
/*
*
* Public functions
*
*/
/*
* Free all internal data.
*/
void
nmz_free_internal(void)
{
nmz_free_idxnames();
nmz_free_aliases();
nmz_free_replaces();
nmz_free_field_cache();
}
void
nmz_set_sortmethod(enum nmz_sortmethod method)
{
sortmethod = method;
}
enum nmz_sortmethod
nmz_get_sortmethod(void)
{
return sortmethod;
}
void
nmz_set_sortorder(enum nmz_sortorder order)
{
sortorder = order;
}
enum nmz_sortorder
nmz_get_sortorder(void)
{
return sortorder;
}
void
nmz_set_maxhit(int max)
{
maxhit = max;
}
int
nmz_get_maxhit(void)
{
return maxhit;
}
void
nmz_set_maxmatch(int max)
{
maxmatch = max;
}
int
nmz_get_maxmatch(void)
{
return maxmatch;
}
void
nmz_set_debugmode(int mode)
{
debugmode = mode;
}
int
nmz_is_debugmode(void)
{
return debugmode;
}
void
nmz_set_loggingmode(int mode)
{
loggingmode = mode;
}
int
nmz_is_loggingmode(void)
{
return loggingmode;
}
void
nmz_set_output_warn_to_file(int mode)
{
output_warn_to_file = mode;
}
int
nmz_is_output_warn_to_file(void)
{
return output_warn_to_file;
}
void
nmz_set_regex_searchmode(int mode)
{
regex_searchmode = mode;
}
int
nmz_is_regex_searchmode(void)
{
return regex_searchmode;
}
/*
* This function is used for formating a string with printf
* notation and store the string in the static variable
* `msg'. and return its pointer. So, thhe string can only
* be used until the next call to the function.
*
* NOTE: Mainly used with nmz_set_dyingmsg() macro.
*/
char *
nmz_msg(const char *fmt, ...)
{
static char msg[BUFSIZE] = "";
va_list args;
va_start(args, fmt);
vsnprintf(msg, BUFSIZE - 1, fmt, args);
va_end(args);
return msg;
}
/*
* This function is not used directly but used only through
* nmz_set_dyingmsg() macro. That's for getting __FILE__ and
* __LINE__ information and including them in the
* dyingmsg in debug mode. It makes debug easy.
*/
char *
nmz_set_dyingmsg_sub(const char *fmt, ...)
{
va_list args;
va_start(args, fmt);
vsnprintf(dyingmsg, BUFSIZE - 1, fmt, args);
va_end(args);
return dyingmsg;
}
char *
nmz_get_dyingmsg(void)
{
return dyingmsg;
}
|