MCPcopy Create free account
hub / github.com/OpenPrinting/cups / helpSaveIndex

Function helpSaveIndex

cgi-bin/help-index.c:427–495  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

425 */
426
427int /* O - 0 on success, -1 on error */
428helpSaveIndex(help_index_t *hi, /* I - Index */
429 const char *hifile) /* I - Index filename */
430{
431 cups_file_t *fp; /* Index file */
432 help_node_t *node; /* Current node */
433 help_word_t *word; /* Current word */
434
435
436 /*
437 * Try creating a new index file...
438 */
439
440 if ((fp = cupsFileOpen(hifile, "w9")) == NULL)
441 return (-1);
442
443 /*
444 * Lock the file while we write it...
445 */
446
447 cupsFileLock(fp, 1);
448
449 cupsFilePuts(fp, "HELPV2\n");
450
451 for (node = (help_node_t *)cupsArrayFirst(hi->nodes);
452 node;
453 node = (help_node_t *)cupsArrayNext(hi->nodes))
454 {
455 /*
456 * Write the current node with/without the anchor...
457 */
458
459 if (node->anchor)
460 {
461 if (cupsFilePrintf(fp, "%s#%s " CUPS_LLFMT " " CUPS_LLFMT " \"%s\"\n",
462 node->filename, node->anchor,
463 CUPS_LLCAST node->offset, CUPS_LLCAST node->length,
464 node->text) < 0)
465 break;
466 }
467 else
468 {
469 if (cupsFilePrintf(fp, "%s %d " CUPS_LLFMT " " CUPS_LLFMT " \"%s\" \"%s\"\n",
470 node->filename, (int)node->mtime,
471 CUPS_LLCAST node->offset, CUPS_LLCAST node->length,
472 node->section ? node->section : "", node->text) < 0)
473 break;
474 }
475
476 /*
477 * Then write the words associated with the node...
478 */
479
480 for (word = (help_word_t *)cupsArrayFirst(node->words);
481 word;
482 word = (help_word_t *)cupsArrayNext(node->words))
483 if (cupsFilePrintf(fp, " %d %s\n", word->count, word->text) < 0)
484 break;

Callers 1

helpLoadIndexFunction · 0.85

Calls 8

cupsFileOpenFunction · 0.85
cupsFileLockFunction · 0.85
cupsFilePutsFunction · 0.85
cupsArrayFirstFunction · 0.85
cupsArrayNextFunction · 0.85
cupsFilePrintfFunction · 0.85
cupsFileFlushFunction · 0.85
cupsFileCloseFunction · 0.85

Tested by

no test coverage detected