MCPcopy Create free account
hub / github.com/Singular/Singular / heKey2Entry

Function heKey2Entry

Singular/fehelp.cc:388–474  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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
388static 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;

Callers 2

feHelpFunction · 0.85
heReKey2EntryFunction · 0.85

Calls 1

si_fscanfFunction · 0.85

Tested by

no test coverage detected