File misc.c changed (mode: 100644) (index 0b7c060..6105584) |
... |
... |
static int editdistance(const char *s, const char *t, int cutoff){ |
109 |
109 |
} |
} |
110 |
110 |
|
|
111 |
111 |
int *v[3]; |
int *v[3]; |
112 |
|
for(int i = 0; i != 3; i++) { |
|
|
112 |
|
int i; |
|
113 |
|
for(i = 0; i != 3; i++) { |
113 |
114 |
v[i] = malloc(sizeof(int) * (size_t)(b+1)); |
v[i] = malloc(sizeof(int) * (size_t)(b+1)); |
114 |
115 |
} |
} |
115 |
116 |
|
|
116 |
|
for(int i = 0; i != b+1; i++){ |
|
|
117 |
|
for(i = 0; i != b+1; i++){ |
117 |
118 |
v[0][i] = i; |
v[0][i] = i; |
118 |
119 |
} |
} |
119 |
120 |
|
|
120 |
121 |
int pcur; |
int pcur; |
121 |
122 |
int ppcur; |
int ppcur; |
122 |
123 |
int cur = 1; |
int cur = 1; |
123 |
|
for(int i = 0; i != a; i++){ |
|
|
124 |
|
for(i = 0; i != a; i++){ |
124 |
125 |
cur = (cur+1) % 3; |
cur = (cur+1) % 3; |
125 |
126 |
pcur = cur -1; |
pcur = cur -1; |
126 |
127 |
if(pcur < 0) pcur += 3; |
if(pcur < 0) pcur += 3; |
|
... |
... |
static int editdistance(const char *s, const char *t, int cutoff){ |
153 |
154 |
pcur = cur -1; |
pcur = cur -1; |
154 |
155 |
if(pcur < 0) pcur += 3; |
if(pcur < 0) pcur += 3; |
155 |
156 |
int d = v[pcur][b]; |
int d = v[pcur][b]; |
156 |
|
for(int i = 0; i != 3; i++) |
|
|
157 |
|
for(i = 0; i != 3; i++) |
157 |
158 |
free(v[i]); |
free(v[i]); |
158 |
159 |
return d; |
return d; |
159 |
160 |
} |
} |
|
... |
... |
void getsuggestions(const char *name, char *buff, size_t buffsize, int nTables, |
167 |
168 |
int count = 0; |
int count = 0; |
168 |
169 |
|
|
169 |
170 |
struct {int distance; const char *name;} suggestions[3]; |
struct {int distance; const char *name;} suggestions[3]; |
170 |
|
for(int i = 0; i != 3; i++){ |
|
|
171 |
|
int i; |
|
172 |
|
for(i = 0; i != 3; i++){ |
171 |
173 |
suggestions[i].distance = INT_MAX; |
suggestions[i].distance = INT_MAX; |
172 |
174 |
suggestions[i].name = NULL; |
suggestions[i].name = NULL; |
173 |
175 |
} |
} |
174 |
176 |
|
|
175 |
177 |
va_start(ap, nTables); |
va_start(ap, nTables); |
176 |
178 |
|
|
177 |
|
for(int i = 0; i != nTables; i++){ |
|
|
179 |
|
|
|
180 |
|
for(i = 0; i != nTables; i++){ |
178 |
181 |
struct hashtable *ht = va_arg(ap, struct hashtable*); |
struct hashtable *ht = va_arg(ap, struct hashtable*); |
179 |
|
|
|
180 |
|
for(size_t x = 0; x != ht->size; x++){ |
|
|
182 |
|
|
|
183 |
|
size_t x; |
|
184 |
|
for(x = 0; x != ht->size; x++){ |
181 |
185 |
if(ht->bucket[x].name){ |
if(ht->bucket[x].name){ |
182 |
186 |
const struct typeandname *tan = ht->bucket[x].val; |
const struct typeandname *tan = ht->bucket[x].val; |
183 |
187 |
if(typeeq(tan->ty, gAny)){ |
if(typeeq(tan->ty, gAny)){ |
|
... |
... |
void getsuggestions(const char *name, char *buff, size_t buffsize, int nTables, |
187 |
191 |
int dist = editdistance(ht->bucket[x].name, name, cutoff); |
int dist = editdistance(ht->bucket[x].name, name, cutoff); |
188 |
192 |
if(dist <= cutoff){ |
if(dist <= cutoff){ |
189 |
193 |
count++; |
count++; |
190 |
|
for(int j = 0; j != 3; j++){ |
|
|
194 |
|
int j; |
|
195 |
|
for(j = 0; j != 3; j++){ |
191 |
196 |
if(suggestions[j].distance > dist){ |
if(suggestions[j].distance > dist){ |
192 |
197 |
if(i == 0){ |
if(i == 0){ |
193 |
198 |
suggestions[2] = suggestions[1]; |
suggestions[2] = suggestions[1]; |
|
... |
... |
int updateflag(int cur, char *txt, struct hashtable *flags){ |
469 |
474 |
} |
} |
470 |
475 |
|
|
471 |
476 |
int updateannotation(int cur, char *txt, struct hashtable *flags){ |
int updateannotation(int cur, char *txt, struct hashtable *flags){ |
472 |
|
char sep[] = " \t\n"; |
|
|
477 |
|
char sep[] = " \t\r\n"; |
473 |
478 |
memset(txt, ' ', strlen("//#")); |
memset(txt, ' ', strlen("//#")); |
474 |
|
for(char *ann = strtok(txt, sep); ann; ann = strtok(NULL, sep)){ |
|
|
479 |
|
char *ann; |
|
480 |
|
for(ann = strtok(txt, sep); ann; ann = strtok(NULL, sep)){ |
475 |
481 |
cur = updateflag(cur, ann, flags); |
cur = updateflag(cur, ann, flags); |
476 |
482 |
} |
} |
477 |
483 |
return cur; |
return cur; |
File typeandname.c changed (mode: 100644) (index 6cb071e..b00c032) |
3 |
3 |
|
|
4 |
4 |
#include "typeandname.h" |
#include "typeandname.h" |
5 |
5 |
|
|
|
6 |
|
#if !(defined __CYGWIN__ || defined linux) |
|
7 |
|
extern void * _aligned_malloc(size_t size, size_t alignment); |
|
8 |
|
#endif |
|
9 |
|
|
6 |
10 |
struct typeandname *newtypeandname(const struct typenode *ty, const char *name) |
struct typeandname *newtypeandname(const struct typenode *ty, const char *name) |
7 |
11 |
{ |
{ |
8 |
12 |
struct typeandname *tan = calloc(sizeof(struct typeandname), 1); |
struct typeandname *tan = calloc(sizeof(struct typeandname), 1); |
|
... |
... |
struct typeandname *newtypeandname(const struct typenode *ty, const char *name) |
15 |
19 |
struct typenode *newtypenode(const char *typename, const struct typenode *superclass) |
struct typenode *newtypenode(const char *typename, const struct typenode *superclass) |
16 |
20 |
{ |
{ |
17 |
21 |
struct typenode *result; |
struct typenode *result; |
18 |
|
result = aligned_alloc(8, sizeof(struct typenode)); |
|
|
22 |
|
#if (defined __CYGWIN__ || defined linux) |
|
23 |
|
result = memalign(8, sizeof(struct typenode)); |
|
24 |
|
#else |
|
25 |
|
result = _aligned_malloc(8, sizeof(struct typenode)); |
|
26 |
|
#endif |
19 |
27 |
result->typename = strdup(typename); |
result->typename = strdup(typename); |
20 |
28 |
result->superclass = superclass; |
result->superclass = superclass; |
21 |
29 |
return result; |
return result; |