MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / xref_table

Function xref_table

internal/cbm/pdf/pdf_obj.c:1633–1685  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1631}
1632
1633static bool xref_table(pdf_doc_t *d, size_t p, pdf_xref_t *sec, pdf_val_t **tr) {
1634 const unsigned char *s = d->data;
1635 size_t len = d->len;
1636 for (;;) {
1637 pdf_tok_t t;
1638 size_t p2 = p;
1639 pdf_lex(d, s, len, &p2, &t);
1640 if (pdf_kw_is(&t, "trailer")) {
1641 pdf_tok_t t2;
1642 pdf_lex(d, s, len, &p2, &t2);
1643 pdf_val_t *v = pdf_parse_value(d, s, len, &p2, &t2, 0);
1644 if (!v) {
1645 return false;
1646 }
1647 *tr = v->kind == PV_DICT ? v : NULL;
1648 return true;
1649 }
1650 if (t.kind != PT_NUM) {
1651 return false;
1652 }
1653 pdf_tok_t tc;
1654 pdf_lex(d, s, len, &p2, &tc);
1655 if (tc.kind != PT_NUM || !tc.is_int) {
1656 return false;
1657 }
1658 int64_t start = t.is_int ? t.inum : pdf_d2i(t.num);
1659 bool use = t.is_int || t.num == (double)start;
1660 p = p2;
1661 for (int64_t i = 0; i < tc.inum; i++) {
1662 int64_t off;
1663 int64_t gen;
1664 char kind;
1665 size_t end;
1666 if (!match_xref_entry(d, p, &off, &gen, &kind, &end)) {
1667 return false;
1668 }
1669 p = end;
1670 if (!use) {
1671 continue;
1672 }
1673 bool fresh;
1674 pdf_xent_t *e = xref_slot(d, sec, pdf_sat_add(start, i), &fresh);
1675 if (!e) {
1676 return false;
1677 }
1678 if (fresh && kind == 'n') {
1679 e->type = 1;
1680 e->a = off;
1681 e->b = gen;
1682 }
1683 }
1684 }
1685}
1686
1687static int64_t be_field(const unsigned char *p, int w) {
1688 uint64_t v = 0;

Callers 1

load_xrefFunction · 0.85

Calls 7

pdf_lexFunction · 0.85
pdf_kw_isFunction · 0.85
pdf_parse_valueFunction · 0.85
pdf_d2iFunction · 0.85
match_xref_entryFunction · 0.85
xref_slotFunction · 0.85
pdf_sat_addFunction · 0.85

Tested by

no test coverage detected