2020#include < vector>
2121#include < sstream>
2222#include < iostream>
23- #include < fstream>
2423#include < string>
2524#include < algorithm>
25+ #include < filesystem>
2626
2727// Xapian includes
2828#include < xapian.h>
2929
3030#include " version.h"
3131
32- #ifdef _WIN32
33- #include < windows.h>
34- #else
35- #include < sys/stat.h>
36- #endif
37-
38- #define FIELD_TYPE 1
39- #define FIELD_NAME 2
40- #define FIELD_ARGS 3
41- #define FIELD_TAG 4
42- #define FIELD_URL 5
43- #define FIELD_KEYW 6
44- #define FIELD_DOC 7
4532
46- #define HEX2DEC (x ) (((x)>=' 0' && (x)<=' 9' )?((x)-' 0' ):\
47- ((x)>=' a' && (x)<=' f' )?((x)-' a' +10 ):\
48- ((x)>=' A' && (x)<=' F' )?((x)-' A' +10 ):-1 )
33+ constexpr Xapian::valueno FIELD_TYPE{ 1 };
34+ constexpr Xapian::valueno FIELD_NAME{ 2 };
35+ constexpr Xapian::valueno FIELD_ARGS{ 3 };
36+ constexpr Xapian::valueno FIELD_TAG{ 4 };
37+ constexpr Xapian::valueno FIELD_URL{ 5 };
38+ constexpr Xapian::valueno FIELD_KEYW{ 6 };
39+ constexpr Xapian::valueno FIELD_DOC{ 7 };
4940
50-
51- bool dirExists (const std::string& dirName)
41+ constexpr int hex2dec (unsigned char c)
5242{
53- #ifdef _WIN32
54- DWORD ftyp = GetFileAttributesA (dirName.c_str ());
55- if (ftyp == INVALID_FILE_ATTRIBUTES)
56- return false ; // something is wrong with your path!
57-
58- if (ftyp & FILE_ATTRIBUTE_DIRECTORY)
59- return true ; // this is a directory!
60- #else
61- struct stat sb;
43+ if (c >= ' 0' && c <= ' 9' ) return c - ' 0' ;
44+ if (c >= ' a' && c <= ' f' ) return c - ' a' + 10 ;
45+ if (c >= ' A' && c <= ' F' ) return c - ' A' + 10 ;
46+ return -1 ;
47+ }
6248
63- if (stat (dirName.c_str (), &sb)==0 && S_ISDIR (sb.st_mode ))
64- {
65- return true ;
66- }
67- #endif
6849
69- return false ;
50+ bool dirExists (const std::string &dirname)
51+ {
52+ std::error_code ec;
53+ return std::filesystem::is_directory (dirname, ec);
7054}
7155
7256
@@ -90,11 +74,10 @@ static std::string uriDecode(const std::string & sSrc)
9074 {
9175 if (*pSrc == ' %' ) // replace %2A with corresponding ASCII character
9276 {
93- char dec1, dec2;
77+ int dec1, dec2;
9478 unsigned char c1=*(pSrc+1 );
9579 unsigned char c2=*(pSrc+2 );
96- if (-1 != (dec1 = HEX2DEC (c1))
97- && -1 != (dec2 = HEX2DEC (c2)))
80+ if (-1 != (dec1 = hex2dec (c1)) && -1 != (dec2 = hex2dec (c2)))
9881 {
9982 *pEnd++ = (dec1 << 4 ) + dec2;
10083 pSrc += 3 ;
@@ -359,7 +342,7 @@ int main(int argc,char **argv)
359342 std::cout << " Content-Type:application/javascript;charset=utf-8\r\n\n " ;
360343 // parse query string
361344 std::vector<std::string> parts = split (queryString,' &' );
362- std::string searchFor,callback ;
345+ std::string searchFor;
363346 int num=1 ,page=0 ;
364347 for (std::vector<std::string>::const_iterator it=parts.begin ();it!=parts.end ();++it)
365348 {
0 commit comments