Deleted Added
full compact
ch.c (173683) ch.c (191930)
1/*
1/*
2 * Copyright (C) 1984-2007 Mark Nudelman
2 * Copyright (C) 1984-2008 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 about less, or for information on how to
8 * contact the author, see the README file.
9 */
10

--- 21 unchanged lines hidden (view full) ---

32public int ignore_eoi;
33
34/*
35 * Pool of buffers holding the most recently used blocks of the input file.
36 * The buffer pool is kept as a doubly-linked circular list,
37 * in order from most- to least-recently used.
38 * The circular list is anchored by the file state "thisfile".
39 */
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 about less, or for information on how to
8 * contact the author, see the README file.
9 */
10

--- 21 unchanged lines hidden (view full) ---

32public int ignore_eoi;
33
34/*
35 * Pool of buffers holding the most recently used blocks of the input file.
36 * The buffer pool is kept as a doubly-linked circular list,
37 * in order from most- to least-recently used.
38 * The circular list is anchored by the file state "thisfile".
39 */
40struct bufnode {
41 struct bufnode *next, *prev;
42 struct bufnode *hnext, *hprev;
43};
44
40#define LBUFSIZE 8192
41struct buf {
45#define LBUFSIZE 8192
46struct buf {
42 struct buf *next, *prev;
43 struct buf *hnext, *hprev;
47 struct bufnode node;
44 BLOCKNUM block;
45 unsigned int datasize;
46 unsigned char data[LBUFSIZE];
47};
48 BLOCKNUM block;
49 unsigned int datasize;
50 unsigned char data[LBUFSIZE];
51};
52#define bufnode_buf(bn) ((struct buf *) bn)
48
53
49struct buflist {
50 /* -- Following members must match struct buf */
51 struct buf *buf_next, *buf_prev;
52 struct buf *buf_hnext, *buf_hprev;
53};
54
55/*
56 * The file state is maintained in a filestate structure.
57 * A pointer to the filestate is kept in the ifile structure.
58 */
59#define BUFHASH_SIZE 64
60struct filestate {
54/*
55 * The file state is maintained in a filestate structure.
56 * A pointer to the filestate is kept in the ifile structure.
57 */
58#define BUFHASH_SIZE 64
59struct filestate {
61 struct buf *buf_next, *buf_prev;
62 struct buflist hashtbl[BUFHASH_SIZE];
60 struct bufnode buflist;
61 struct bufnode hashtbl[BUFHASH_SIZE];
63 int file;
64 int flags;
65 POSITION fpos;
66 int nbufs;
67 BLOCKNUM block;
68 unsigned int offset;
69 POSITION fsize;
70};
71
62 int file;
63 int flags;
64 POSITION fpos;
65 int nbufs;
66 BLOCKNUM block;
67 unsigned int offset;
68 POSITION fsize;
69};
70
72#define ch_bufhead thisfile->buf_next
73#define ch_buftail thisfile->buf_prev
71#define ch_bufhead thisfile->buflist.next
72#define ch_buftail thisfile->buflist.prev
74#define ch_nbufs thisfile->nbufs
75#define ch_block thisfile->block
76#define ch_offset thisfile->offset
77#define ch_fpos thisfile->fpos
78#define ch_fsize thisfile->fsize
79#define ch_flags thisfile->flags
80#define ch_file thisfile->file
81
73#define ch_nbufs thisfile->nbufs
74#define ch_block thisfile->block
75#define ch_offset thisfile->offset
76#define ch_fpos thisfile->fpos
77#define ch_fsize thisfile->fsize
78#define ch_flags thisfile->flags
79#define ch_file thisfile->file
80
82#define END_OF_CHAIN ((struct buf *)&thisfile->buf_next)
83#define END_OF_HCHAIN(h) ((struct buf *)&thisfile->hashtbl[h])
81#define END_OF_CHAIN (&thisfile->buflist)
82#define END_OF_HCHAIN(h) (&thisfile->hashtbl[h])
84#define BUFHASH(blk) ((blk) & (BUFHASH_SIZE-1))
85
83#define BUFHASH(blk) ((blk) & (BUFHASH_SIZE-1))
84
86#define FOR_BUFS_IN_CHAIN(h,bp) \
87 for (bp = thisfile->hashtbl[h].buf_hnext; \
88 bp != END_OF_HCHAIN(h); bp = bp->hnext)
85/*
86 * Macros to manipulate the list of buffers in thisfile->buflist.
87 */
88#define FOR_BUFS(bn) \
89 for (bn = ch_bufhead; bn != END_OF_CHAIN; bn = bn->next)
89
90
90#define HASH_RM(bp) \
91 (bp)->hnext->hprev = (bp)->hprev; \
92 (bp)->hprev->hnext = (bp)->hnext;
91#define BUF_RM(bn) \
92 (bn)->next->prev = (bn)->prev; \
93 (bn)->prev->next = (bn)->next;
93
94
94#define HASH_INS(bp,h) \
95 (bp)->hnext = thisfile->hashtbl[h].buf_hnext; \
96 (bp)->hprev = END_OF_HCHAIN(h); \
97 thisfile->hashtbl[h].buf_hnext->hprev = (bp); \
98 thisfile->hashtbl[h].buf_hnext = (bp);
95#define BUF_INS_HEAD(bn) \
96 (bn)->next = ch_bufhead; \
97 (bn)->prev = END_OF_CHAIN; \
98 ch_bufhead->prev = (bn); \
99 ch_bufhead = (bn);
99
100
101#define BUF_INS_TAIL(bn) \
102 (bn)->next = END_OF_CHAIN; \
103 (bn)->prev = ch_buftail; \
104 ch_buftail->next = (bn); \
105 ch_buftail = (bn);
106
107/*
108 * Macros to manipulate the list of buffers in thisfile->hashtbl[n].
109 */
110#define FOR_BUFS_IN_CHAIN(h,bn) \
111 for (bn = thisfile->hashtbl[h].hnext; \
112 bn != END_OF_HCHAIN(h); bn = bn->hnext)
113
114#define BUF_HASH_RM(bn) \
115 (bn)->hnext->hprev = (bn)->hprev; \
116 (bn)->hprev->hnext = (bn)->hnext;
117
118#define BUF_HASH_INS(bn,h) \
119 (bn)->hnext = thisfile->hashtbl[h].hnext; \
120 (bn)->hprev = END_OF_HCHAIN(h); \
121 thisfile->hashtbl[h].hnext->hprev = (bn); \
122 thisfile->hashtbl[h].hnext = (bn);
123
100static struct filestate *thisfile;
101static int ch_ungotchar = -1;
102static int maxbufs = -1;
103
104extern int autobuf;
105extern int sigs;
106extern int secure;
107extern int screen_trashed;

--- 6 unchanged lines hidden (view full) ---

114extern char *namelogfile;
115#endif
116
117static int ch_addbuf();
118
119
120/*
121 * Get the character pointed to by the read pointer.
124static struct filestate *thisfile;
125static int ch_ungotchar = -1;
126static int maxbufs = -1;
127
128extern int autobuf;
129extern int sigs;
130extern int secure;
131extern int screen_trashed;

--- 6 unchanged lines hidden (view full) ---

138extern char *namelogfile;
139#endif
140
141static int ch_addbuf();
142
143
144/*
145 * Get the character pointed to by the read pointer.
122 * ch_get() is a macro which is more efficient to call
123 * than fch_get (the function), in the usual case
124 * that the block desired is at the head of the chain.
125 */
146 */
126#define ch_get() ((ch_block == ch_bufhead->block && \
127 ch_offset < ch_bufhead->datasize) ? \
128 ch_bufhead->data[ch_offset] : fch_get())
129 int
147 int
130fch_get()
148ch_get()
131{
132 register struct buf *bp;
149{
150 register struct buf *bp;
151 register struct bufnode *bn;
133 register int n;
134 register int slept;
135 register int h;
136 POSITION pos;
137 POSITION len;
138
139 if (thisfile == NULL)
140 return (EOI);
141
152 register int n;
153 register int slept;
154 register int h;
155 POSITION pos;
156 POSITION len;
157
158 if (thisfile == NULL)
159 return (EOI);
160
161 /*
162 * Quick check for the common case where
163 * the desired char is in the head buffer.
164 */
165 if (ch_bufhead != END_OF_CHAIN)
166 {
167 bp = bufnode_buf(ch_bufhead);
168 if (ch_block == bp->block && ch_offset < bp->datasize)
169 return bp->data[ch_offset];
170 }
171
142 slept = FALSE;
143
144 /*
145 * Look for a buffer holding the desired block.
146 */
147 h = BUFHASH(ch_block);
172 slept = FALSE;
173
174 /*
175 * Look for a buffer holding the desired block.
176 */
177 h = BUFHASH(ch_block);
148 FOR_BUFS_IN_CHAIN(h, bp)
178 FOR_BUFS_IN_CHAIN(h, bn)
149 {
179 {
180 bp = bufnode_buf(bn);
150 if (bp->block == ch_block)
151 {
152 if (ch_offset >= bp->datasize)
153 /*
154 * Need more data in this buffer.
155 */
181 if (bp->block == ch_block)
182 {
183 if (ch_offset >= bp->datasize)
184 /*
185 * Need more data in this buffer.
186 */
156 goto read_more;
187 break;
157 goto found;
158 }
159 }
188 goto found;
189 }
190 }
160 /*
161 * Block is not in a buffer.
162 * Take the least recently used buffer
163 * and read the desired block into it.
164 * If the LRU buffer has data in it,
165 * then maybe allocate a new buffer.
166 */
167 if (ch_buftail == END_OF_CHAIN || ch_buftail->block != -1)
191 if (bn == END_OF_HCHAIN(h))
168 {
169 /*
192 {
193 /*
170 * There is no empty buffer to use.
171 * Allocate a new buffer if:
172 * 1. We can't seek on this file and -b is not in effect; or
173 * 2. We haven't allocated the max buffers for this file yet.
194 * Block is not in a buffer.
195 * Take the least recently used buffer
196 * and read the desired block into it.
197 * If the LRU buffer has data in it,
198 * then maybe allocate a new buffer.
174 */
199 */
175 if ((autobuf && !(ch_flags & CH_CANSEEK)) ||
176 (maxbufs < 0 || ch_nbufs < maxbufs))
177 if (ch_addbuf())
178 /*
179 * Allocation failed: turn off autobuf.
180 */
181 autobuf = OPT_OFF;
200 if (ch_buftail == END_OF_CHAIN ||
201 bufnode_buf(ch_buftail)->block != -1)
202 {
203 /*
204 * There is no empty buffer to use.
205 * Allocate a new buffer if:
206 * 1. We can't seek on this file and -b is not in effect; or
207 * 2. We haven't allocated the max buffers for this file yet.
208 */
209 if ((autobuf && !(ch_flags & CH_CANSEEK)) ||
210 (maxbufs < 0 || ch_nbufs < maxbufs))
211 if (ch_addbuf())
212 /*
213 * Allocation failed: turn off autobuf.
214 */
215 autobuf = OPT_OFF;
216 }
217 bn = ch_buftail;
218 bp = bufnode_buf(bn);
219 BUF_HASH_RM(bn); /* Remove from old hash chain. */
220 bp->block = ch_block;
221 bp->datasize = 0;
222 BUF_HASH_INS(bn, h); /* Insert into new hash chain. */
182 }
223 }
183 bp = ch_buftail;
184 HASH_RM(bp); /* Remove from old hash chain. */
185 bp->block = ch_block;
186 bp->datasize = 0;
187 HASH_INS(bp, h); /* Insert into new hash chain. */
188
189 read_more:
190 pos = (ch_block * LBUFSIZE) + bp->datasize;
191 if ((len = ch_length()) != NULL_POSITION && pos >= len)
192 /*
193 * At end of file.
194 */
195 return (EOI);

--- 108 unchanged lines hidden (view full) ---

304 }
305#endif
306 }
307 if (sigs)
308 return (EOI);
309 }
310
311 found:
224
225 read_more:
226 pos = (ch_block * LBUFSIZE) + bp->datasize;
227 if ((len = ch_length()) != NULL_POSITION && pos >= len)
228 /*
229 * At end of file.
230 */
231 return (EOI);

--- 108 unchanged lines hidden (view full) ---

340 }
341#endif
342 }
343 if (sigs)
344 return (EOI);
345 }
346
347 found:
312 if (ch_bufhead != bp)
348 if (ch_bufhead != bn)
313 {
314 /*
315 * Move the buffer to the head of the buffer chain.
316 * This orders the buffer chain, most- to least-recently used.
317 */
349 {
350 /*
351 * Move the buffer to the head of the buffer chain.
352 * This orders the buffer chain, most- to least-recently used.
353 */
318 bp->next->prev = bp->prev;
319 bp->prev->next = bp->next;
320 bp->next = ch_bufhead;
321 bp->prev = END_OF_CHAIN;
322 ch_bufhead->prev = bp;
323 ch_bufhead = bp;
354 BUF_RM(bn);
355 BUF_INS_HEAD(bn);
324
325 /*
326 * Move to head of hash chain too.
327 */
356
357 /*
358 * Move to head of hash chain too.
359 */
328 HASH_RM(bp);
329 HASH_INS(bp, h);
360 BUF_HASH_RM(bn);
361 BUF_HASH_INS(bn, h);
330 }
331
332 if (ch_offset >= bp->datasize)
333 /*
334 * After all that, we still don't have enough data.
335 * Go back and try again.
336 */
337 goto read_more;

--- 43 unchanged lines hidden (view full) ---

381 * Start a log file AFTER less has already been running.
382 * Invoked from the - command; see toggle_option().
383 * Write all the existing buffered data to the log file.
384 */
385 public void
386sync_logfile()
387{
388 register struct buf *bp;
362 }
363
364 if (ch_offset >= bp->datasize)
365 /*
366 * After all that, we still don't have enough data.
367 * Go back and try again.
368 */
369 goto read_more;

--- 43 unchanged lines hidden (view full) ---

413 * Start a log file AFTER less has already been running.
414 * Invoked from the - command; see toggle_option().
415 * Write all the existing buffered data to the log file.
416 */
417 public void
418sync_logfile()
419{
420 register struct buf *bp;
421 register struct bufnode *bn;
389 int warned = FALSE;
390 BLOCKNUM block;
391 BLOCKNUM nblocks;
392
393 nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE;
394 for (block = 0; block < nblocks; block++)
395 {
422 int warned = FALSE;
423 BLOCKNUM block;
424 BLOCKNUM nblocks;
425
426 nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE;
427 for (block = 0; block < nblocks; block++)
428 {
396 for (bp = ch_bufhead; ; bp = bp->next)
429 int wrote = FALSE;
430 FOR_BUFS(bn)
397 {
431 {
398 if (bp == END_OF_CHAIN)
399 {
400 if (!warned)
401 {
402 error("Warning: log file is incomplete",
403 NULL_PARG);
404 warned = TRUE;
405 }
406 break;
407 }
432 bp = bufnode_buf(bn);
408 if (bp->block == block)
409 {
410 write(logfile, (char *) bp->data, bp->datasize);
433 if (bp->block == block)
434 {
435 write(logfile, (char *) bp->data, bp->datasize);
436 wrote = TRUE;
411 break;
412 }
413 }
437 break;
438 }
439 }
440 if (!wrote && !warned)
441 {
442 error("Warning: log file is incomplete",
443 NULL_PARG);
444 warned = TRUE;
445 }
414 }
415}
416
417#endif
418
419/*
420 * Determine if a specific block is currently in one of the buffers.
421 */
422 static int
423buffered(block)
424 BLOCKNUM block;
425{
426 register struct buf *bp;
446 }
447}
448
449#endif
450
451/*
452 * Determine if a specific block is currently in one of the buffers.
453 */
454 static int
455buffered(block)
456 BLOCKNUM block;
457{
458 register struct buf *bp;
459 register struct bufnode *bn;
427 register int h;
428
429 h = BUFHASH(block);
460 register int h;
461
462 h = BUFHASH(block);
430 FOR_BUFS_IN_CHAIN(h, bp)
463 FOR_BUFS_IN_CHAIN(h, bn)
431 {
464 {
465 bp = bufnode_buf(bn);
432 if (bp->block == block)
433 return (TRUE);
434 }
435 return (FALSE);
436}
437
438/*
439 * Seek to a specified position in the file.

--- 65 unchanged lines hidden (view full) ---

505/*
506 * Seek to the beginning of the file, or as close to it as we can get.
507 * We may not be able to seek there if input is a pipe and the
508 * beginning of the pipe is no longer buffered.
509 */
510 public int
511ch_beg_seek()
512{
466 if (bp->block == block)
467 return (TRUE);
468 }
469 return (FALSE);
470}
471
472/*
473 * Seek to a specified position in the file.

--- 65 unchanged lines hidden (view full) ---

539/*
540 * Seek to the beginning of the file, or as close to it as we can get.
541 * We may not be able to seek there if input is a pipe and the
542 * beginning of the pipe is no longer buffered.
543 */
544 public int
545ch_beg_seek()
546{
513 register struct buf *bp, *firstbp;
547 register struct bufnode *bn;
548 register struct bufnode *firstbn;
514
515 /*
516 * Try a plain ch_seek first.
517 */
518 if (ch_seek(ch_zero()) == 0)
519 return (0);
520
521 /*
522 * Can't get to position 0.
523 * Look thru the buffers for the one closest to position 0.
524 */
549
550 /*
551 * Try a plain ch_seek first.
552 */
553 if (ch_seek(ch_zero()) == 0)
554 return (0);
555
556 /*
557 * Can't get to position 0.
558 * Look thru the buffers for the one closest to position 0.
559 */
525 firstbp = bp = ch_bufhead;
526 if (bp == END_OF_CHAIN)
560 firstbn = ch_bufhead;
561 if (firstbn == END_OF_CHAIN)
527 return (1);
562 return (1);
528 while ((bp = bp->next) != END_OF_CHAIN)
529 if (bp->block < firstbp->block)
530 firstbp = bp;
531 ch_block = firstbp->block;
563 FOR_BUFS(bn)
564 {
565 if (bufnode_buf(bn)->block < bufnode_buf(firstbn)->block)
566 firstbn = bn;
567 }
568 ch_block = bufnode_buf(firstbn)->block;
532 ch_offset = 0;
533 return (0);
534}
535
536/*
537 * Return the length of the file, if known.
538 */
539 public POSITION

--- 83 unchanged lines hidden (view full) ---

623}
624
625/*
626 * Flush (discard) any saved file state, including buffer contents.
627 */
628 public void
629ch_flush()
630{
569 ch_offset = 0;
570 return (0);
571}
572
573/*
574 * Return the length of the file, if known.
575 */
576 public POSITION

--- 83 unchanged lines hidden (view full) ---

660}
661
662/*
663 * Flush (discard) any saved file state, including buffer contents.
664 */
665 public void
666ch_flush()
667{
631 register struct buf *bp;
668 register struct bufnode *bn;
632
633 if (thisfile == NULL)
634 return;
635
636 if (!(ch_flags & CH_CANSEEK))
637 {
638 /*
639 * If input is a pipe, we don't flush buffer contents,
640 * since the contents can't be recovered.
641 */
642 ch_fsize = NULL_POSITION;
643 return;
644 }
645
646 /*
647 * Initialize all the buffers.
648 */
669
670 if (thisfile == NULL)
671 return;
672
673 if (!(ch_flags & CH_CANSEEK))
674 {
675 /*
676 * If input is a pipe, we don't flush buffer contents,
677 * since the contents can't be recovered.
678 */
679 ch_fsize = NULL_POSITION;
680 return;
681 }
682
683 /*
684 * Initialize all the buffers.
685 */
649 for (bp = ch_bufhead; bp != END_OF_CHAIN; bp = bp->next)
650 bp->block = -1;
686 FOR_BUFS(bn)
687 {
688 bufnode_buf(bn)->block = -1;
689 }
651
652 /*
653 * Figure out the size of the file, if we can.
654 */
655 ch_fsize = filesize(ch_file);
656
657 /*
658 * Seek to a known position: the beginning of the file.

--- 30 unchanged lines hidden (view full) ---

689/*
690 * Allocate a new buffer.
691 * The buffer is added to the tail of the buffer chain.
692 */
693 static int
694ch_addbuf()
695{
696 register struct buf *bp;
690
691 /*
692 * Figure out the size of the file, if we can.
693 */
694 ch_fsize = filesize(ch_file);
695
696 /*
697 * Seek to a known position: the beginning of the file.

--- 30 unchanged lines hidden (view full) ---

728/*
729 * Allocate a new buffer.
730 * The buffer is added to the tail of the buffer chain.
731 */
732 static int
733ch_addbuf()
734{
735 register struct buf *bp;
736 register struct bufnode *bn;
697
698 /*
699 * Allocate and initialize a new buffer and link it
700 * onto the tail of the buffer list.
701 */
702 bp = (struct buf *) calloc(1, sizeof(struct buf));
703 if (bp == NULL)
704 return (1);
705 ch_nbufs++;
706 bp->block = -1;
737
738 /*
739 * Allocate and initialize a new buffer and link it
740 * onto the tail of the buffer list.
741 */
742 bp = (struct buf *) calloc(1, sizeof(struct buf));
743 if (bp == NULL)
744 return (1);
745 ch_nbufs++;
746 bp->block = -1;
707 bp->next = END_OF_CHAIN;
708 bp->prev = ch_buftail;
709 ch_buftail->next = bp;
710 ch_buftail = bp;
711 HASH_INS(bp, 0);
747 bn = &bp->node;
748
749 BUF_INS_TAIL(bn);
750 BUF_HASH_INS(bn, 0);
712 return (0);
713}
714
715/*
716 *
717 */
718 static void
719init_hashtbl()
720{
721 register int h;
722
723 for (h = 0; h < BUFHASH_SIZE; h++)
724 {
751 return (0);
752}
753
754/*
755 *
756 */
757 static void
758init_hashtbl()
759{
760 register int h;
761
762 for (h = 0; h < BUFHASH_SIZE; h++)
763 {
725 thisfile->hashtbl[h].buf_hnext = END_OF_HCHAIN(h);
726 thisfile->hashtbl[h].buf_hprev = END_OF_HCHAIN(h);
764 thisfile->hashtbl[h].hnext = END_OF_HCHAIN(h);
765 thisfile->hashtbl[h].hprev = END_OF_HCHAIN(h);
727 }
728}
729
730/*
731 * Delete all buffers for this file.
732 */
733 static void
734ch_delbufs()
735{
766 }
767}
768
769/*
770 * Delete all buffers for this file.
771 */
772 static void
773ch_delbufs()
774{
736 register struct buf *bp;
775 register struct bufnode *bn;
737
738 while (ch_bufhead != END_OF_CHAIN)
739 {
776
777 while (ch_bufhead != END_OF_CHAIN)
778 {
740 bp = ch_bufhead;
741 bp->next->prev = bp->prev;
742 bp->prev->next = bp->next;
743 free(bp);
779 bn = ch_bufhead;
780 BUF_RM(bn);
781 free(bufnode_buf(bn));
744 }
745 ch_nbufs = 0;
746 init_hashtbl();
747}
748
749/*
750 * Is it possible to seek on a file descriptor?
751 */

--- 29 unchanged lines hidden (view full) ---

781 thisfile = (struct filestate *) get_filestate(curr_ifile);
782 if (thisfile == NULL)
783 {
784 /*
785 * Allocate and initialize a new filestate.
786 */
787 thisfile = (struct filestate *)
788 calloc(1, sizeof(struct filestate));
782 }
783 ch_nbufs = 0;
784 init_hashtbl();
785}
786
787/*
788 * Is it possible to seek on a file descriptor?
789 */

--- 29 unchanged lines hidden (view full) ---

819 thisfile = (struct filestate *) get_filestate(curr_ifile);
820 if (thisfile == NULL)
821 {
822 /*
823 * Allocate and initialize a new filestate.
824 */
825 thisfile = (struct filestate *)
826 calloc(1, sizeof(struct filestate));
789 thisfile->buf_next = thisfile->buf_prev = END_OF_CHAIN;
827 thisfile->buflist.next = thisfile->buflist.prev = END_OF_CHAIN;
790 thisfile->nbufs = 0;
791 thisfile->flags = 0;
792 thisfile->fpos = 0;
793 thisfile->block = 0;
794 thisfile->offset = 0;
795 thisfile->file = -1;
796 thisfile->fsize = NULL_POSITION;
797 ch_flags = flags;

--- 64 unchanged lines hidden (view full) ---

862 return (ch_flags);
863}
864
865#if 0
866 public void
867ch_dump(struct filestate *fs)
868{
869 struct buf *bp;
828 thisfile->nbufs = 0;
829 thisfile->flags = 0;
830 thisfile->fpos = 0;
831 thisfile->block = 0;
832 thisfile->offset = 0;
833 thisfile->file = -1;
834 thisfile->fsize = NULL_POSITION;
835 ch_flags = flags;

--- 64 unchanged lines hidden (view full) ---

900 return (ch_flags);
901}
902
903#if 0
904 public void
905ch_dump(struct filestate *fs)
906{
907 struct buf *bp;
908 struct bufnode *bn;
870 unsigned char *s;
871
872 if (fs == NULL)
873 {
874 printf(" --no filestate\n");
875 return;
876 }
877 printf(" file %d, flags %x, fpos %x, fsize %x, blk/off %x/%x\n",
878 fs->file, fs->flags, fs->fpos,
879 fs->fsize, fs->block, fs->offset);
880 printf(" %d bufs:\n", fs->nbufs);
909 unsigned char *s;
910
911 if (fs == NULL)
912 {
913 printf(" --no filestate\n");
914 return;
915 }
916 printf(" file %d, flags %x, fpos %x, fsize %x, blk/off %x/%x\n",
917 fs->file, fs->flags, fs->fpos,
918 fs->fsize, fs->block, fs->offset);
919 printf(" %d bufs:\n", fs->nbufs);
881 for (bp = fs->buf_next; bp != (struct buf *)fs; bp = bp->next)
920 for (bn = fs->next; bn != &fs->buflist; bn = bn->next)
882 {
921 {
922 bp = bufnode_buf(bn);
883 printf("%x: blk %x, size %x \"",
884 bp, bp->block, bp->datasize);
885 for (s = bp->data; s < bp->data + 30; s++)
886 if (*s >= ' ' && *s < 0x7F)
887 printf("%c", *s);
888 else
889 printf(".");
890 printf("\"\n");
891 }
892}
893#endif
923 printf("%x: blk %x, size %x \"",
924 bp, bp->block, bp->datasize);
925 for (s = bp->data; s < bp->data + 30; s++)
926 if (*s >= ' ' && *s < 0x7F)
927 printf("%c", *s);
928 else
929 printf(".");
930 printf("\"\n");
931 }
932}
933#endif