ch.c (367516) | ch.c (369759) |
---|---|
1/* | 1/* |
2 * Copyright (C) 1984-2020 Mark Nudelman | 2 * Copyright (C) 1984-2021 Mark Nudelman |
3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information, see the README file. 8 */ 9 10 --- 25 unchanged lines hidden (view full) --- 36 * in order from most- to least-recently used. 37 * The circular list is anchored by the file state "thisfile". 38 */ 39struct bufnode { 40 struct bufnode *next, *prev; 41 struct bufnode *hnext, *hprev; 42}; 43 | 3 * 4 * You may distribute under the terms of either the GNU General Public 5 * License or the Less License, as specified in the README file. 6 * 7 * For more information, see the README file. 8 */ 9 10 --- 25 unchanged lines hidden (view full) --- 36 * in order from most- to least-recently used. 37 * The circular list is anchored by the file state "thisfile". 38 */ 39struct bufnode { 40 struct bufnode *next, *prev; 41 struct bufnode *hnext, *hprev; 42}; 43 |
44#define LBUFSIZE 8192 | 44#define LBUFSIZE 8192 |
45struct buf { 46 struct bufnode node; 47 BLOCKNUM block; 48 unsigned int datasize; 49 unsigned char data[LBUFSIZE]; 50}; 51#define bufnode_buf(bn) ((struct buf *) bn) 52 53/* 54 * The file state is maintained in a filestate structure. 55 * A pointer to the filestate is kept in the ifile structure. 56 */ | 45struct buf { 46 struct bufnode node; 47 BLOCKNUM block; 48 unsigned int datasize; 49 unsigned char data[LBUFSIZE]; 50}; 51#define bufnode_buf(bn) ((struct buf *) bn) 52 53/* 54 * The file state is maintained in a filestate structure. 55 * A pointer to the filestate is kept in the ifile structure. 56 */ |
57#define BUFHASH_SIZE 1024 | 57#define BUFHASH_SIZE 1024 |
58struct filestate { 59 struct bufnode buflist; 60 struct bufnode hashtbl[BUFHASH_SIZE]; 61 int file; 62 int flags; 63 POSITION fpos; 64 int nbufs; 65 BLOCKNUM block; 66 unsigned int offset; 67 POSITION fsize; 68}; 69 | 58struct filestate { 59 struct bufnode buflist; 60 struct bufnode hashtbl[BUFHASH_SIZE]; 61 int file; 62 int flags; 63 POSITION fpos; 64 int nbufs; 65 BLOCKNUM block; 66 unsigned int offset; 67 POSITION fsize; 68}; 69 |
70#define ch_bufhead thisfile->buflist.next 71#define ch_buftail thisfile->buflist.prev 72#define ch_nbufs thisfile->nbufs 73#define ch_block thisfile->block 74#define ch_offset thisfile->offset 75#define ch_fpos thisfile->fpos 76#define ch_fsize thisfile->fsize 77#define ch_flags thisfile->flags 78#define ch_file thisfile->file | 70#define ch_bufhead thisfile->buflist.next 71#define ch_buftail thisfile->buflist.prev 72#define ch_nbufs thisfile->nbufs 73#define ch_block thisfile->block 74#define ch_offset thisfile->offset 75#define ch_fpos thisfile->fpos 76#define ch_fsize thisfile->fsize 77#define ch_flags thisfile->flags 78#define ch_file thisfile->file |
79 | 79 |
80#define END_OF_CHAIN (&thisfile->buflist) 81#define END_OF_HCHAIN(h) (&thisfile->hashtbl[h]) 82#define BUFHASH(blk) ((blk) & (BUFHASH_SIZE-1)) | 80#define END_OF_CHAIN (&thisfile->buflist) 81#define END_OF_HCHAIN(h) (&thisfile->hashtbl[h]) 82#define BUFHASH(blk) ((blk) & (BUFHASH_SIZE-1)) |
83 84/* 85 * Macros to manipulate the list of buffers in thisfile->buflist. 86 */ | 83 84/* 85 * Macros to manipulate the list of buffers in thisfile->buflist. 86 */ |
87#define FOR_BUFS(bn) \ | 87#define FOR_BUFS(bn) \ |
88 for (bn = ch_bufhead; bn != END_OF_CHAIN; bn = bn->next) 89 90#define BUF_RM(bn) \ 91 (bn)->next->prev = (bn)->prev; \ 92 (bn)->prev->next = (bn)->next; 93 94#define BUF_INS_HEAD(bn) \ 95 (bn)->next = ch_bufhead; \ --- 5 unchanged lines hidden (view full) --- 101 (bn)->next = END_OF_CHAIN; \ 102 (bn)->prev = ch_buftail; \ 103 ch_buftail->next = (bn); \ 104 ch_buftail = (bn); 105 106/* 107 * Macros to manipulate the list of buffers in thisfile->hashtbl[n]. 108 */ | 88 for (bn = ch_bufhead; bn != END_OF_CHAIN; bn = bn->next) 89 90#define BUF_RM(bn) \ 91 (bn)->next->prev = (bn)->prev; \ 92 (bn)->prev->next = (bn)->next; 93 94#define BUF_INS_HEAD(bn) \ 95 (bn)->next = ch_bufhead; \ --- 5 unchanged lines hidden (view full) --- 101 (bn)->next = END_OF_CHAIN; \ 102 (bn)->prev = ch_buftail; \ 103 ch_buftail->next = (bn); \ 104 ch_buftail = (bn); 105 106/* 107 * Macros to manipulate the list of buffers in thisfile->hashtbl[n]. 108 */ |
109#define FOR_BUFS_IN_CHAIN(h,bn) \ | 109#define FOR_BUFS_IN_CHAIN(h,bn) \ |
110 for (bn = thisfile->hashtbl[h].hnext; \ 111 bn != END_OF_HCHAIN(h); bn = bn->hnext) 112 | 110 for (bn = thisfile->hashtbl[h].hnext; \ 111 bn != END_OF_HCHAIN(h); bn = bn->hnext) 112 |
113#define BUF_HASH_RM(bn) \ | 113#define BUF_HASH_RM(bn) \ |
114 (bn)->hnext->hprev = (bn)->hprev; \ 115 (bn)->hprev->hnext = (bn)->hnext; 116 | 114 (bn)->hnext->hprev = (bn)->hprev; \ 115 (bn)->hprev->hnext = (bn)->hnext; 116 |
117#define BUF_HASH_INS(bn,h) \ | 117#define BUF_HASH_INS(bn,h) \ |
118 (bn)->hnext = thisfile->hashtbl[h].hnext; \ 119 (bn)->hprev = END_OF_HCHAIN(h); \ 120 thisfile->hashtbl[h].hnext->hprev = (bn); \ 121 thisfile->hashtbl[h].hnext = (bn); 122 123static struct filestate *thisfile; 124static int ch_ungotchar = -1; 125static int maxbufs = -1; --- 109 unchanged lines hidden (view full) --- 235 * Not at the correct position: must seek. 236 * If input is a pipe, we're in trouble (can't seek on a pipe). 237 * Some data has been lost: just return "?". 238 */ 239 if (!(ch_flags & CH_CANSEEK)) 240 return ('?'); 241 if (lseek(ch_file, (off_t)pos, SEEK_SET) == BAD_LSEEK) 242 { | 118 (bn)->hnext = thisfile->hashtbl[h].hnext; \ 119 (bn)->hprev = END_OF_HCHAIN(h); \ 120 thisfile->hashtbl[h].hnext->hprev = (bn); \ 121 thisfile->hashtbl[h].hnext = (bn); 122 123static struct filestate *thisfile; 124static int ch_ungotchar = -1; 125static int maxbufs = -1; --- 109 unchanged lines hidden (view full) --- 235 * Not at the correct position: must seek. 236 * If input is a pipe, we're in trouble (can't seek on a pipe). 237 * Some data has been lost: just return "?". 238 */ 239 if (!(ch_flags & CH_CANSEEK)) 240 return ('?'); 241 if (lseek(ch_file, (off_t)pos, SEEK_SET) == BAD_LSEEK) 242 { |
243 error("seek error", NULL_PARG); | 243 error("seek error", NULL_PARG); |
244 clear_eol(); 245 return (EOI); | 244 clear_eol(); 245 return (EOI); |
246 } 247 ch_fpos = pos; 248 } | 246 } 247 ch_fpos = pos; 248 } |
249 250 /* 251 * Read the block. 252 * If we read less than a full block, that's ok. 253 * We use partial block and pick up the rest next time. 254 */ 255 if (ch_ungotchar != -1) 256 { --- 49 unchanged lines hidden (view full) --- 306 * Wait a while, then try again. 307 */ 308 if (!slept) 309 { 310 PARG parg; 311 parg.p_string = wait_message(); 312 ierror("%s", &parg); 313 } | 249 250 /* 251 * Read the block. 252 * If we read less than a full block, that's ok. 253 * We use partial block and pick up the rest next time. 254 */ 255 if (ch_ungotchar != -1) 256 { --- 49 unchanged lines hidden (view full) --- 306 * Wait a while, then try again. 307 */ 308 if (!slept) 309 { 310 PARG parg; 311 parg.p_string = wait_message(); 312 ierror("%s", &parg); 313 } |
314#if !MSDOS_COMPILER 315 sleep(1); 316#else 317#if MSDOS_COMPILER==WIN32C 318 Sleep(1000); 319#endif 320#endif | 314 sleep_ms(2); /* Reduce system load */ |
321 slept = TRUE; 322 323#if HAVE_STAT_INO 324 if (follow_mode == FOLLOW_NAME) 325 { 326 /* See whether the file's i-number has changed, 327 * or the file has shrunk. 328 * If so, force the file to be closed and --- 647 unchanged lines hidden --- | 315 slept = TRUE; 316 317#if HAVE_STAT_INO 318 if (follow_mode == FOLLOW_NAME) 319 { 320 /* See whether the file's i-number has changed, 321 * or the file has shrunk. 322 * If so, force the file to be closed and --- 647 unchanged lines hidden --- |