00001 /* 00002 * libfid - Full-text Index Data structure library 00003 * Copyright (C) 2007 Robert Homann 00004 * 00005 * This library is free software; you can redistribute it and/or 00006 * modify it under the terms of the GNU Lesser General Public 00007 * License as published by the Free Software Foundation; either 00008 * version 2.1 of the License, or (at your option) any later version. 00009 * 00010 * This library is distributed in the hope that it will be useful, 00011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 * Lesser General Public License for more details. 00014 * 00015 * You should have received a copy of the GNU Lesser General Public 00016 * License along with this library; if not, write to the Free Software 00017 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, 00018 * MA 02110-1301 USA 00019 */ 00020 00021 #ifdef HAVE_CONFIG_H 00022 #include "config.h" 00023 #endif /* HAVE_CONFIG_H */ 00024 00025 #include <string.h> 00026 #include <stdlib.h> 00027 00028 #include "libdefs.h" 00029 #include "options.h" 00030 00031 int fid_options_prefetch=1; 00032 int fid_options_smart_prefetch=1; 00033 00034 /*! 00035 * \brief Parse environment variable for library configuration. 00036 * 00037 * This function is called automatically by functions that can be influenced 00038 * by an environment variable whose name is defined by #FID_OPTIONS_VARNAME, 00039 * and is usually not called directly from client code. The function parses the 00040 * content of the environment variable once only. 00041 * 00042 * The environment variable is expected to contain a colon separated list of 00043 * option names. Currently, the following options are recognized (unknown 00044 * options are silently ignored). 00045 * - \c NOPREFETCH Usually every file opened for reading is prefetched 00046 * automatically to fill the file cache in order to prevent excessive time 00047 * consumption for searching within files. Setting this option disables 00048 * automatic prefetching entirely. 00049 * - \c FORCEPREFETCH If prefetching is not disabled, then the default 00050 * behavior is to prefetch a file only if it is very small, or if the 00051 * kernel reports that it, or large parts thereof, are not present in file 00052 * cache already. Setting this option causes the library to always read the 00053 * whole file (still quite fast when cached already, but much slower than 00054 * asking the kernel beforehand and relying on these information). 00055 * 00056 * \note Global variables #fid_options_prefetch and #fid_options_smart_prefetch 00057 * are set by this function according to the content of environment variable 00058 * #FID_OPTIONS_VARNAME. <em>Do not set these variables manually.</em> 00059 */ 00060 void fid_options_parse(void) 00061 { 00062 static int initialized; 00063 char *string, *saveptr, *token; 00064 00065 if(initialized) 00066 { 00067 return; 00068 } 00069 00070 initialized=1; 00071 00072 if((string=getenv(FID_OPTIONS_VARNAME)) == NULL) 00073 { 00074 return; 00075 } 00076 00077 token=strtok_r(string,":",&saveptr); 00078 while(token != NULL) 00079 { 00080 if(strcmp(token,"NOPREFETCH") == 0) 00081 { 00082 fid_options_prefetch=0; 00083 } 00084 else if(strcmp(token,"FORCEPREFETCH") == 0) 00085 { 00086 fid_options_smart_prefetch=0; 00087 } 00088 token=strtok_r(NULL,":",&saveptr); 00089 } 00090 } 00091