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

Function load_xref

internal/cbm/pdf/pdf_obj.c:1866–1975  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1864}
1865
1866static bool load_xref(pdf_doc_t *d) {
1867 const unsigned char *s = d->data;
1868 size_t len = d->len;
1869 /* the last "startxref" */
1870 size_t i = len < 9 ? 0 : len - 9 + 1;
1871 bool found = false;
1872 while (i-- > 0) {
1873 if (s[i] == 's' && memcmp(s + i, "startxref", 9) == 0) {
1874 found = true;
1875 break;
1876 }
1877 }
1878 if (!found) {
1879 return false;
1880 }
1881 size_t p = i + 9;
1882 pdf_tok_t t;
1883 pdf_lex(d, s, len, &p, &t);
1884 if (t.kind != PT_NUM) {
1885 return false;
1886 }
1887 pdf_map_t seen = {0};
1888 /* /XRefStm targets already merged: a later (older) section naming one again
1889 * adds nothing, since every number it holds is in d->xref already */
1890 pdf_map_t stm_seen = {0};
1891 kv_list_t trail = {0};
1892 bool first = true;
1893 bool ok = true;
1894 pdf_val_t *offv = new_val(d, PV_NUM);
1895 if (!offv) {
1896 return false;
1897 }
1898 offv->is_int = t.is_int;
1899 offv->inum = t.inum;
1900 pdf_val_t *off = offv;
1901 while (off && off->kind == PV_NUM && off->is_int &&
1902 pdf_map_get(&seen, (uint64_t)off->inum) < 0 && seen.n < PDF_MAX_PREV) {
1903 if (!pdf_map_put(&seen, (uint64_t)off->inum, 1)) {
1904 d->nomem = true;
1905 ok = false;
1906 break;
1907 }
1908 size_t at;
1909 if (!find_xref_at(d, off->inum, &at)) {
1910 ok = false;
1911 break;
1912 }
1913 pdf_xref_t sec = {0};
1914 pdf_val_t *tr = NULL;
1915 if (starts_with(d, at, "xref")) {
1916 if (!xref_table(d, at + 4, &sec, &tr)) {
1917 xref_free(&sec);
1918 ok = false;
1919 break;
1920 }
1921 pdf_val_t *xs = pdf_dget_raw(tr, "XRefStm");
1922 if (xs && xs->kind == PV_NUM && xs->is_int &&
1923 pdf_map_get(&stm_seen, (uint64_t)xs->inum) < 0) {

Callers 1

pdf_doc_openFunction · 0.85

Calls 15

pdf_lexFunction · 0.85
new_valFunction · 0.85
pdf_map_getFunction · 0.85
pdf_map_putFunction · 0.85
find_xref_atFunction · 0.85
xref_tableFunction · 0.85
xref_freeFunction · 0.85
pdf_dget_rawFunction · 0.85
xref_stream_atFunction · 0.85
xref_slotFunction · 0.85
trailer_key_structuralFunction · 0.85
kl_pushFunction · 0.85

Tested by

no test coverage detected