comparison src/cache.c @ 734:e6ebae313d46

Fix up some types, make some signed vs unsigned warnings quiet.
author zas_
date Thu, 22 May 2008 11:27:43 +0000
parents a1dcef8cd1ae
children 4fe8f9656107
comparison
equal deleted inserted replaced
733:57f759d012c7 734:e6ebae313d46
183 *------------------------------------------------------------------- 183 *-------------------------------------------------------------------
184 * sim cache read 184 * sim cache read
185 *------------------------------------------------------------------- 185 *-------------------------------------------------------------------
186 */ 186 */
187 187
188 static gint cache_sim_read_skipline(FILE *f, int s) 188 static gint cache_sim_read_skipline(FILE *f, gint s)
189 { 189 {
190 if (!f) return FALSE; 190 if (!f) return FALSE;
191 191
192 if (fseek(f, 0 - s, SEEK_CUR) == 0) 192 if (fseek(f, 0 - s, SEEK_CUR) == 0)
193 { 193 {
194 char b; 194 gchar b;
195 while (fread(&b, sizeof(b), 1, f) == 1) 195 while (fread(&b, sizeof(b), 1, f) == 1)
196 { 196 {
197 if (b == '\n') return TRUE; 197 if (b == '\n') return TRUE;
198 } 198 }
199 return TRUE; 199 return TRUE;
200 } 200 }
201 201
202 return FALSE; 202 return FALSE;
203 } 203 }
204 204
205 static gint cache_sim_read_comment(FILE *f, char *buf, int s, CacheData *cd) 205 static gint cache_sim_read_comment(FILE *f, gchar *buf, gint s, CacheData *cd)
206 { 206 {
207 if (!f || !buf || !cd) return FALSE; 207 if (!f || !buf || !cd) return FALSE;
208 208
209 if (s < 1 || buf[0] != '#') return FALSE; 209 if (s < 1 || buf[0] != '#') return FALSE;
210 210
211 return cache_sim_read_skipline(f, s - 1); 211 return cache_sim_read_skipline(f, s - 1);
212 } 212 }
213 213
214 static gint cache_sim_read_dimensions(FILE *f, char *buf, int s, CacheData *cd) 214 static gint cache_sim_read_dimensions(FILE *f, gchar *buf, gint s, CacheData *cd)
215 { 215 {
216 if (!f || !buf || !cd) return FALSE; 216 if (!f || !buf || !cd) return FALSE;
217 217
218 if (s < 10 || strncmp("Dimensions", buf, 10) != 0) return FALSE; 218 if (s < 10 || strncmp("Dimensions", buf, 10) != 0) return FALSE;
219 219
220 if (fseek(f, - s, SEEK_CUR) == 0) 220 if (fseek(f, - s, SEEK_CUR) == 0)
221 { 221 {
222 char b; 222 gchar b;
223 char buf[1024]; 223 gchar buf[1024];
224 gint p = 0; 224 gsize p = 0;
225 gint w, h; 225 gint w, h;
226 226
227 b = 'X'; 227 b = 'X';
228 while (b != '[') 228 while (b != '[')
229 { 229 {
252 } 252 }
253 253
254 return FALSE; 254 return FALSE;
255 } 255 }
256 256
257 static gint cache_sim_read_date(FILE *f, char *buf, int s, CacheData *cd) 257 static gint cache_sim_read_date(FILE *f, gchar *buf, gint s, CacheData *cd)
258 { 258 {
259 if (!f || !buf || !cd) return FALSE; 259 if (!f || !buf || !cd) return FALSE;
260 260
261 if (s < 4 || strncmp("Date", buf, 4) != 0) return FALSE; 261 if (s < 4 || strncmp("Date", buf, 4) != 0) return FALSE;
262 262
263 if (fseek(f, - s, SEEK_CUR) == 0) 263 if (fseek(f, - s, SEEK_CUR) == 0)
264 { 264 {
265 char b; 265 gchar b;
266 char buf[1024]; 266 gchar buf[1024];
267 gint p = 0; 267 gsize p = 0;
268 268
269 b = 'X'; 269 b = 'X';
270 while (b != '[') 270 while (b != '[')
271 { 271 {
272 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE; 272 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
292 } 292 }
293 293
294 return FALSE; 294 return FALSE;
295 } 295 }
296 296
297 static gint cache_sim_read_checksum(FILE *f, char *buf, int s, CacheData *cd) 297 static gint cache_sim_read_checksum(FILE *f, gchar *buf, gint s, CacheData *cd)
298 { 298 {
299 if (!f || !buf || !cd) return FALSE; 299 if (!f || !buf || !cd) return FALSE;
300 300
301 if (s < 8 || strncmp("Checksum", buf, 8) != 0) return FALSE; 301 if (s < 8 || strncmp("Checksum", buf, 8) != 0) return FALSE;
302 302
303 if (fseek(f, - s, SEEK_CUR) == 0) 303 if (fseek(f, - s, SEEK_CUR) == 0)
304 { 304 {
305 char b; 305 gchar b;
306 char buf[1024]; 306 gchar buf[1024];
307 gint p = 0; 307 gsize p = 0;
308 308
309 b = 'X'; 309 b = 'X';
310 while (b != '[') 310 while (b != '[')
311 { 311 {
312 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE; 312 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
332 } 332 }
333 333
334 return FALSE; 334 return FALSE;
335 } 335 }
336 336
337 static gint cache_sim_read_md5sum(FILE *f, char *buf, int s, CacheData *cd) 337 static gint cache_sim_read_md5sum(FILE *f, gchar *buf, gint s, CacheData *cd)
338 { 338 {
339 if (!f || !buf || !cd) return FALSE; 339 if (!f || !buf || !cd) return FALSE;
340 340
341 if (s < 8 || strncmp("MD5sum", buf, 6) != 0) return FALSE; 341 if (s < 8 || strncmp("MD5sum", buf, 6) != 0) return FALSE;
342 342
343 if (fseek(f, - s, SEEK_CUR) == 0) 343 if (fseek(f, - s, SEEK_CUR) == 0)
344 { 344 {
345 char b; 345 gchar b;
346 char buf[64]; 346 gchar buf[64];
347 gint p = 0; 347 gsize p = 0;
348 348
349 b = 'X'; 349 b = 'X';
350 while (b != '[') 350 while (b != '[')
351 { 351 {
352 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE; 352 if (fread(&b, sizeof(b), 1, f) != 1) return FALSE;
369 } 369 }
370 370
371 return FALSE; 371 return FALSE;
372 } 372 }
373 373
374 static gint cache_sim_read_similarity(FILE *f, char *buf, int s, CacheData *cd) 374 static gint cache_sim_read_similarity(FILE *f, gchar *buf, gint s, CacheData *cd)
375 { 375 {
376 if (!f || !buf || !cd) return FALSE; 376 if (!f || !buf || !cd) return FALSE;
377 377
378 if (s < 11 || strncmp("Similarity", buf, 10) != 0) return FALSE; 378 if (s < 11 || strncmp("Similarity", buf, 10) != 0) return FALSE;
379 379
380 if (strncmp("Grid[32 x 32]", buf + 10, 13) != 0) return FALSE; 380 if (strncmp("Grid[32 x 32]", buf + 10, 13) != 0) return FALSE;
381 381
382 if (fseek(f, - s, SEEK_CUR) == 0) 382 if (fseek(f, - s, SEEK_CUR) == 0)
383 { 383 {
384 char b; 384 gchar b;
385 guint8 pixel_buf[3]; 385 guint8 pixel_buf[3];
386 ImageSimilarityData *sd; 386 ImageSimilarityData *sd;
387 gint x, y; 387 gint x, y;
388 388
389 b = 'X'; 389 b = 'X';
439 439
440 CacheData *cache_sim_data_load(const gchar *path) 440 CacheData *cache_sim_data_load(const gchar *path)
441 { 441 {
442 FILE *f; 442 FILE *f;
443 CacheData *cd = NULL; 443 CacheData *cd = NULL;
444 char buf[32]; 444 gchar buf[32];
445 gint success = CACHE_LOAD_LINE_NOISE; 445 gint success = CACHE_LOAD_LINE_NOISE;
446 gchar *pathl; 446 gchar *pathl;
447 447
448 if (!path) return NULL; 448 if (!path) return NULL;
449 449
454 if (!f) return NULL; 454 if (!f) return NULL;
455 455
456 cd = cache_sim_data_new(); 456 cd = cache_sim_data_new();
457 cd->path = g_strdup(path); 457 cd->path = g_strdup(path);
458 458
459 if (fread(&buf, sizeof(char), 9, f) != 9 || 459 if (fread(&buf, sizeof(gchar), 9, f) != 9 ||
460 strncmp(buf, "SIMcache", 8) != 0) 460 strncmp(buf, "SIMcache", 8) != 0)
461 { 461 {
462 DEBUG_1("%s is not a cache file", cd->path); 462 DEBUG_1("%s is not a cache file", cd->path);
463 success = 0; 463 success = 0;
464 } 464 }
465 465
466 while (success > 0) 466 while (success > 0)
467 { 467 {
468 int s; 468 gint s;
469 s = fread(&buf, sizeof(char), sizeof(buf), f); 469 s = fread(&buf, sizeof(gchar), sizeof(buf), f);
470 470
471 if (s < 1) 471 if (s < 1)
472 { 472 {
473 success = 0; 473 success = 0;
474 } 474 }