Finds help entry for key: returns filled-in hentry and TRUE, on success FALSE, on failure Assumes that lines of idx file have the following form key\tnode\turl\tchksum\n (chksum ma be empty, then it is set to -1) and that lines are sorted alpahbetically w.r.t. index entries
| 386 | // key\tnode\turl\tchksum\n (chksum ma be empty, then it is set to -1) |
| 387 | // and that lines are sorted alpahbetically w.r.t. index entries |
| 388 | static BOOLEAN heKey2Entry(char* filename, char* key, heEntry hentry) |
| 389 | { |
| 390 | FILE* fd; |
| 391 | int c, k; |
| 392 | int kl, i; |
| 393 | *(hentry->key) = '\0'; |
| 394 | *(hentry->url) = '\0'; |
| 395 | *(hentry->node) = '\0'; |
| 396 | hentry->chksum = 0; |
| 397 | if (filename == NULL || key == NULL) return FALSE; |
| 398 | fd = fopen(filename, "r"); |
| 399 | if (fd == NULL) return FALSE; |
| 400 | kl = strlen(key); |
| 401 | |
| 402 | k = key[0]; |
| 403 | i = 0; |
| 404 | while ((c = getc(fd)) != EOF) |
| 405 | { |
| 406 | if (c < k) |
| 407 | { |
| 408 | /* Skip line */ |
| 409 | while (getc(fd) != '\n') {}; |
| 410 | if (i) |
| 411 | { |
| 412 | i=0; |
| 413 | k=key[0]; |
| 414 | } |
| 415 | } |
| 416 | else if (c == k) |
| 417 | { |
| 418 | i++; |
| 419 | if (i == kl) |
| 420 | { |
| 421 | // \t must follow, otherwise only substring match |
| 422 | if (getc(fd) != '\t') goto Failure; |
| 423 | |
| 424 | // Now we found an exact match |
| 425 | if (hentry->key != key) strcpy(hentry->key, key); |
| 426 | // get node |
| 427 | i = 0; |
| 428 | while ((c = getc(fd)) != '\t' && c != EOF) |
| 429 | { |
| 430 | hentry->node[i] = c; |
| 431 | i++; |
| 432 | } |
| 433 | if (c == EOF) goto Failure; |
| 434 | if (hentry->node[0]=='\0') |
| 435 | strcpy(hentry->node,hentry->key); |
| 436 | |
| 437 | // get url |
| 438 | //hentry->node[i] = '\0'; |
| 439 | i = 0; |
| 440 | while ((c = getc(fd)) != '\t' && c != EOF) |
| 441 | { |
| 442 | hentry->url[i] = c; |
| 443 | i++; |
| 444 | } |
| 445 | if (c == EOF) goto Failure; |
no test coverage detected