You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
948B

  1. #include "global.h"
  2. /* Possibly rename */
  3. struct FILE;
  4. /* Page cursor stack */
  5. static FILE **hto_page = &refsfound;
  6. #define PCS_MAXPAGE 16
  7. static size_t PCS_pos[PCS_MAXPAGE] = {0};
  8. static size_t PCS_top = 0;
  9. long seekpage(const size_t i) {
  10. if(i > PCS_MAXPAGE - 1) { return -1; }
  11. if(i < PCS_top) {
  12. fseek(*hto_page, PCS_pos[i], SEEK_SET);
  13. return PCS_pos[i];
  14. }
  15. fseek(*hto_page, PCS_pos[PCS_top], SEEK_SET);
  16. size_t lc = 0;
  17. while(PCS_top < i) {
  18. const char c = getc(*hto_page);
  19. if(c == '\n') { ++lc; }
  20. if(c == EOF) { return -1; }
  21. if(lc == mdisprefs) { PCS_pos[++PCS_top] = ftell(*hto_page); }
  22. }
  23. return PCS_pos[PCS_top];
  24. }
  25. long seekrelline(unsigned i) {
  26. seekpage(current_page);
  27. size_t lc = 0;
  28. while(lc < i) {
  29. const char c = getc(*hto_page);
  30. assert("seekrelline() tried to read past the reference file" && !(c == EOF));
  31. if(c == '\n') { ++lc; }
  32. }
  33. return ftell(*hto_page);
  34. }
  35. void PCS_reset(void) {
  36. PCS_top = 0;
  37. }