if (*(--page) != '\n') {	/* '--page' here */ /* Something's wrong... */ endwin (); fprintf (stderr, "\nInternal error in back_lines().\n"); exit (-1); } } /* Go back 'n' lines */ for (i = 0; i < n; i++) do { if (page == buf) { if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer in back_lines().\n"); exit (-1); } if (fpos > bytes_read) { /* Really possible to move backward BUF_SIZE/2 bytes? */ if (fpos < BUF_SIZE / 2 + bytes_read) { /* No, move less then */ if (lseek (fd, 0, SEEK_SET) == -1) { endwin (); fprintf (stderr, "\nError moving file pointer " "in back_lines().\n"); exit (-1); 
/* Go back 'n' lines */ for (i = 0; i < n; i++) do { if (page == buf) { if ((fpos = lseek(fd, 0, SEEK_CUR)) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer in back_lines().\n"); exit(-1); } if (fpos > bytes_read) { /* Really possible to move backward BUF_SIZE/2 bytes? */ if (fpos < BUF_SIZE / 2 + bytes_read) { /* No, move less then */ if (lseek(fd, 0, SEEK_SET) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer " "in back_lines().\n"); exit(-1); } page = buf + fpos - bytes_read; } else {	/* Move backward BUF_SIZE/2 bytes */ if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR) == -1) { endwin(); fprintf(stderr, "\nError moving file pointer" " in back_lines().\n"); exit(-1); } page = buf + BUF_SIZE / 2; } if ((bytes_read = read(fd, buf, BUF_SIZE)) == -1) { endwin(); fprintf(stderr, "\nError reading file in " "back_lines().\n"); exit(-1); } buf[bytes_read] = '\0'; } else {	/* Beginning of file reached */ begin_reached = 1; return; } 
back_lines (int n){    int i, fpos;    begin_reached = 0;    /* We have to distinguish between end_reached and !end_reached       since at end of file, the line is not ended by a '\n'.       The code inside 'if' basically does a '--page' to move one       character backward so as to skip '\n' of the previous line */    if (!end_reached) {	/* Either beginning of buffer or beginning of file reached? */	if (page == buf) {	    if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {		endwin ();		fprintf (stderr, "\nError moving file pointer in "			 "back_lines().\n");		exit (-1);	    }	    if (fpos > bytes_read) {	/* Not beginning of file yet */		/* We've reached beginning of buffer, but not beginning of		   file yet, so read previous part of file into buffer.		   Note that we only move backward for BUF_SIZE/2 bytes,		   but not BUF_SIZE bytes to avoid re-reading again in		   print_page() later */		/* Really possible to move backward BUF_SIZE/2 bytes? */		if (fpos < BUF_SIZE / 2 + bytes_read) {		    /* No, move less then */		    if (lseek (fd, 0, SEEK_SET) == -1) {			endwin ();			fprintf (stderr, "\nError moving file pointer in "				 "back_lines().\n");			exit (-1);		    }		    page = buf + fpos - bytes_read;		} else {	/* Move backward BUF_SIZE/2 bytes */		    if (lseek (fd, -(BUF_SIZE / 2 + bytes_read), SEEK_CUR)			== -1) {			endwin ();			fprintf (stderr, "\nError moving file pointer "				 "in back_lines().\n");			exit (-1);		    }		    page = buf + BUF_SIZE / 2;		}		if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {		    endwin ();		    fprintf (stderr, "\nError reading file in back_lines().\n");		    exit (-1);		}		buf[bytes_read] = '\0';	    } else {		/* Beginning of file reached */		begin_reached = 1;		return;	    }	}	if (*(--page) != '\n') {	/* '--page' here */	    /* Something's wrong... */	    endwin ();	    fprintf (stderr, "\nInternal error in back_lines().\n");	    exit (-1);	}    }    /* Go back 'n' lines */    for (i = 0; i < n; i++)	do {	    if (page == buf) {		if ((fpos = lseek (fd, 0, SEEK_CUR)) == -1) {		    endwin ();		    fprintf (stderr,			  "\nError moving file pointer in back_lines().\n");		    exit (-1);		}		if (fpos > bytes_read) {		    /* Really possible to move backward BUF_SIZE/2 bytes? */		    if (fpos < BUF_SIZE / 2 + bytes_read) {			/* No, move less then */			if (lseek (fd, 0, SEEK_SET) == -1) {			    endwin ();			    fprintf (stderr, "\nError moving file pointer "				     "in back_lines().\n");			    exit (-1);			}			page = buf + fpos - bytes_read;		    } else {	/* Move backward BUF_SIZE/2 bytes */			if (lseek (fd, -(BUF_SIZE / 2 + bytes_read),				   SEEK_CUR) == -1) {			    endwin ();			    fprintf (stderr, "\nError moving file pointer"				     " in back_lines().\n");			    exit (-1);			}			page = buf + BUF_SIZE / 2;		    }		    if ((bytes_read = read (fd, buf, BUF_SIZE)) == -1) {			endwin ();			fprintf (stderr, "\nError reading file in "				 "back_lines().\n");			exit (-1);		    }		    buf[bytes_read] = '\0';		} else {	/* Beginning of file reached */		    begin_reached = 1;		    return;		}	    }	} while (*(--page) != '\n');    page++;}
4520	/local/tlutelli/issta_data/temp/c/2005_temp/2005/4520/b1c5f1c635f4a821f834ed51ccd8a2a1515fffd2/textbox.c/buggy/scripts/lxdialog/textbox.c