csope/src/refsfound.c

79 lines
1.7 KiB
C
Raw Normal View History

2023-08-08 06:47:02 -04:00
#include "global.h"
/* Possibly rename */
struct FILE;
/* Page cursor stack */
2023-08-13 05:21:52 -04:00
static FILE **hto_page = &refsfound;
2023-08-08 06:47:02 -04:00
#define PCS_MAXPAGE 16
2023-08-10 15:06:17 -04:00
static size_t PCS_pos[PCS_MAXPAGE] = {0};
2023-08-13 05:21:52 -04:00
static size_t PCS_top = 0;
2023-08-08 06:47:02 -04:00
2023-08-13 05:21:52 -04:00
long seekpage(const size_t i) {
if(i > PCS_MAXPAGE - 1) { return -1; }
2023-08-08 06:47:02 -04:00
2023-08-13 05:21:52 -04:00
if(i < PCS_top) {
2023-08-11 17:31:25 -04:00
fseek(*hto_page, PCS_pos[i], SEEK_SET);
return PCS_pos[i];
}
2023-08-08 06:47:02 -04:00
fseek(*hto_page, PCS_pos[PCS_top], SEEK_SET);
size_t lc = 0;
2023-08-13 05:21:52 -04:00
while(PCS_top < i) {
2023-08-08 06:47:02 -04:00
const char c = getc(*hto_page);
2023-08-13 05:21:52 -04:00
if(c == '\n') { ++lc; }
if(c == EOF) { return -1; }
if(lc == mdisprefs) { PCS_pos[++PCS_top] = ftell(*hto_page); }
2023-08-08 06:47:02 -04:00
}
return PCS_pos[PCS_top];
}
2023-08-13 05:21:52 -04:00
long seekrelline(unsigned i) {
2023-08-08 06:47:02 -04:00
seekpage(current_page);
size_t lc = 0;
2023-08-13 05:21:52 -04:00
while(lc < i) {
2023-08-08 06:47:02 -04:00
const char c = getc(*hto_page);
2023-08-10 15:06:17 -04:00
assert("seekrelline() tried to read past the reference file" && !(c == EOF));
2023-08-13 05:21:52 -04:00
if(c == '\n') { ++lc; }
2023-08-08 06:47:02 -04:00
}
return ftell(*hto_page);
}
2023-08-13 05:21:52 -04:00
void PCS_reset(void) {
2023-08-08 06:47:02 -04:00
PCS_top = 0;
}
///* position references found file at specified line */
2023-08-13 05:21:52 -04:00
// void
// seekline(unsigned int line)
2023-08-08 06:47:02 -04:00
//{
2023-08-13 05:21:52 -04:00
// /* verify that there is a references found file */
// if (refsfound == NULL) {
// return;
// }
// /* go to the beginning of the file */
// rewind(refsfound);
2023-08-08 06:47:02 -04:00
// /**/
// seekrelline(line);
2023-08-13 05:21:52 -04:00
// }
2023-08-08 06:47:02 -04:00
//
///* XXX: this is just dodging the problem */
2023-08-13 05:21:52 -04:00
// void
// seekrelline(unsigned int line){
// int c;
2023-08-08 06:47:02 -04:00
//
2023-08-13 05:21:52 -04:00
// /* verify that there is a references found file */
// if (refsfound == NULL) {
// return;
// }
2023-08-08 06:47:02 -04:00
//
2023-08-13 05:21:52 -04:00
// /* find the requested line */
// nextline = 1;
// while (nextline < line && (c = getc(refsfound)) != EOF) {
// if (c == '\n') {
// nextline++;
// }
// }
// }