forked from s3team/Squirrel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.cpp
More file actions
157 lines (126 loc) · 3.6 KB
/
Copy pathutils.cpp
File metadata and controls
157 lines (126 loc) · 3.6 KB
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
#include "../include/utils.h"
#include <dirent.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
void trim_string(string &res){
int count = 0;
int idx = 0;
bool expect_space = false;
for(int i = 0; i < res.size(); i++){
if(res[i] == ';' && i != res.size() - 1){
res[i+1] = '\n';
}
if(res[i] == ' '){
if(expect_space == false){
continue;
}else{
expect_space = false;
res[idx++] = res[i];
count ++;
}
}else{
expect_space = true;
res[idx++] = res[i];
count ++;
}
}
res.resize(count);
}
string gen_string(){
return string("x");
}
double gen_float(){
return 1.2;
}
long gen_long(){
return 1;
}
int gen_int(){
return 1;
}
typedef unsigned long uint64_t;
Program * parser(string sql){
yyscan_t scanner;
YY_BUFFER_STATE state;
Program * p = new Program();
if (ff_lex_init(&scanner)) {
return NULL;
}
state = ff__scan_string(sql.c_str(), scanner);
int ret = ff_parse(p, scanner);
ff__delete_buffer(state, scanner);
ff_lex_destroy(scanner);
if(ret != 0){
p->deep_delete();
return NULL;
}
return p;
}
uint64_t fucking_hash ( const void * key, int len )
{
const uint64_t m = 0xc6a4a7935bd1e995;
const int r = 47;
uint64_t h = 0xdeadbeefdeadbeef ^ (len * m);
const uint64_t * data = (const uint64_t *)key;
const uint64_t * end = data + (len/8);
while(data != end)
{
uint64_t k = *data++;
k *= m;
k ^= k >> r;
k *= m;
h ^= k;
h *= m;
}
const unsigned char * data2 = (const unsigned char*)data;
switch(len & 7)
{
case 7: h ^= uint64_t(data2[6]) << 48;
case 6: h ^= uint64_t(data2[5]) << 40;
case 5: h ^= uint64_t(data2[4]) << 32;
case 4: h ^= uint64_t(data2[3]) << 24;
case 3: h ^= uint64_t(data2[2]) << 16;
case 2: h ^= uint64_t(data2[1]) << 8;
case 1: h ^= uint64_t(data2[0]);
h *= m;
};
h ^= h >> r;
h *= m;
h ^= h >> r;
return h;
}
vector<string> get_all_files_in_dir( const char * dir_name )
{
vector<string> file_list;
if( NULL == dir_name )
{
cout<<" dir_name is null ! "<<endl;
return file_list;
}
struct stat s;
lstat( dir_name , &s );
if( ! S_ISDIR( s.st_mode ) )
{
cout<<"dir_name is not a valid directory !"<<endl;
return file_list;
}
struct dirent * filename; // return value for readdir()
DIR * dir; // return value for opendir()
dir = opendir( dir_name );
if( NULL == dir )
{
cout<<"Can not open dir "<<dir_name<<endl;
return file_list;
}
cout<<"Successfully opened the dir !"<<endl;
while( ( filename = readdir(dir) ) != NULL )
{
if( strcmp( filename->d_name , "." ) == 0 ||
strcmp( filename->d_name , ".." ) == 0 )
continue;
cout<<filename->d_name <<endl;
file_list.push_back(string(filename->d_name));
}
return file_list;
}