MCPcopy Create free account
hub / github.com/coreutils/coreutils / find_line

Function find_line

src/csplit.c:562–593  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

560 Return a pointer to the line, or NULL if it is not found in the file. */
561
562static struct cstring *
563find_line (intmax_t linenum)
564{
565 if (head == NULL && !load_buffer ())
566 return NULL;
567
568 if (linenum < head->start_line)
569 return NULL;
570
571 for (struct buffer_record *b = head;;)
572 {
573 if (linenum < b->start_line + b->num_lines)
574 {
575 /* The line is in this buffer. */
576 struct line *l;
577 idx_t offset; /* How far into the buffer the line is. */
578
579 l = b->line_start;
580 offset = linenum - b->start_line;
581 /* Find the control record. */
582 while (offset >= CTRL_SIZE)
583 {
584 l = l->next;
585 offset -= CTRL_SIZE;
586 }
587 return &l->starts[offset];
588 }
589 if (b->next == NULL && !load_buffer ())
590 return NULL;
591 b = b->next; /* Try the next data block. */
592 }
593}
594
595/* Return true if at least one more line is available for input. */
596

Callers 2

no_more_linesFunction · 0.85
process_regexpFunction · 0.85

Calls 1

load_bufferFunction · 0.85

Tested by

no test coverage detected