=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/less/position.c,v retrieving revision 1.7 retrieving revision 1.8 diff -c -r1.7 -r1.8 *** src/usr.bin/less/position.c 2014/04/25 13:38:21 1.7 --- src/usr.bin/less/position.c 2015/11/05 22:08:44 1.8 *************** *** 6,27 **** * * For more information, see the README file. */ - /* * Routines dealing with the "position" table. * This is a table which tells the position (in the input file) of the * first char on each currently displayed line. * * {{ The position table is scrolled by moving all the entries. ! * Would be better to have a circular table ! * and just change a couple of pointers. }} */ #include "less.h" #include "position.h" ! static POSITION *table = NULL; /* The position table */ static int table_size; extern int sc_width, sc_height; --- 6,30 ---- * * For more information, see the README file. */ + /* + * Modified for use with illumos. + * Copyright 2014 Garrett D'Amore + */ /* * Routines dealing with the "position" table. * This is a table which tells the position (in the input file) of the * first char on each currently displayed line. * * {{ The position table is scrolled by moving all the entries. ! * Would be better to have a circular table ! * and just change a couple of pointers. }} */ #include "less.h" #include "position.h" ! static off_t *table = NULL; /* The position table */ static int table_size; extern int sc_width, sc_height; *************** *** 35,46 **** * the bottom line on the screen * the line after the bottom line on the screen */ ! public POSITION ! position(where) ! int where; { ! switch (where) ! { case BOTTOM: where = sc_height - 2; break; --- 38,47 ---- * the bottom line on the screen * the line after the bottom line on the screen */ ! off_t ! position(int where) { ! switch (where) { case BOTTOM: where = sc_height - 2; break; *************** *** 56,66 **** /* * Add a new file position to the bottom of the position table. */ ! public void ! add_forw_pos(pos) ! POSITION pos; { ! register int i; /* * Scroll the position table up. --- 57,66 ---- /* * Add a new file position to the bottom of the position table. */ ! void ! add_forw_pos(off_t pos) { ! int i; /* * Scroll the position table up. *************** *** 73,83 **** /* * Add a new file position to the top of the position table. */ ! public void ! add_back_pos(pos) ! POSITION pos; { ! register int i; /* * Scroll the position table down. --- 73,82 ---- /* * Add a new file position to the top of the position table. */ ! void ! add_back_pos(off_t pos) { ! int i; /* * Scroll the position table down. *************** *** 90,109 **** /* * Initialize the position table, done whenever we clear the screen. */ ! public void ! pos_clear() { ! register int i; for (i = 0; i < sc_height; i++) ! table[i] = NULL_POSITION; } /* * Allocate or reallocate the position table. */ ! public void ! pos_init() { struct scrpos scrpos; --- 89,108 ---- /* * Initialize the position table, done whenever we clear the screen. */ ! void ! pos_clear(void) { ! int i; for (i = 0; i < sc_height; i++) ! table[i] = -1; } /* * Allocate or reallocate the position table. */ ! void ! pos_init(void) { struct scrpos scrpos; *************** *** 113,128 **** * If we already have a table, remember the first line in it * before we free it, so we can copy that line to the new table. */ ! if (table != NULL) ! { get_scrpos(&scrpos); ! free((char*)table); ! } else ! scrpos.pos = NULL_POSITION; ! table = (POSITION *) ecalloc(sc_height, sizeof(POSITION)); table_size = sc_height; pos_clear(); ! if (scrpos.pos != NULL_POSITION) table[scrpos.ln-1] = scrpos.pos; } --- 112,127 ---- * If we already have a table, remember the first line in it * before we free it, so we can copy that line to the new table. */ ! if (table != NULL) { get_scrpos(&scrpos); ! free(table); ! } else { ! scrpos.pos = -1; ! } ! table = ecalloc(sc_height, sizeof (off_t)); table_size = sc_height; pos_clear(); ! if (scrpos.pos != -1) table[scrpos.ln-1] = scrpos.pos; } *************** *** 131,139 **** * Check the position table to see if the position falls within its range. * Return the position table entry if found, -1 if not. */ ! public int ! onscreen(pos) ! POSITION pos; { register int i; --- 130,137 ---- * Check the position table to see if the position falls within its range. * Return the position table entry if found, -1 if not. */ ! int ! onscreen(off_t pos) { register int i; *************** *** 148,168 **** /* * See if the entire screen is empty. */ ! public int ! empty_screen() { return (empty_lines(0, sc_height-1)); } ! public int ! empty_lines(s, e) ! int s; ! int e; { ! register int i; for (i = s; i <= e; i++) ! if (table[i] != NULL_POSITION && table[i] != 0) return (0); return (1); } --- 146,164 ---- /* * See if the entire screen is empty. */ ! int ! empty_screen(void) { return (empty_lines(0, sc_height-1)); } ! int ! empty_lines(int s, int e) { ! int i; for (i = s; i <= e; i++) ! if (table[i] != -1 && table[i] != 0) return (0); return (1); } *************** *** 175,193 **** * such that the top few lines are empty, we may have to set * the screen line to a number > 0. */ ! public void ! get_scrpos(scrpos) ! struct scrpos *scrpos; { ! register int i; /* * Find the first line on the screen which has something on it, * and return the screen line number and the file position. */ for (i = 0; i < sc_height; i++) ! if (table[i] != NULL_POSITION) ! { scrpos->ln = i+1; scrpos->pos = table[i]; return; --- 171,187 ---- * such that the top few lines are empty, we may have to set * the screen line to a number > 0. */ ! void ! get_scrpos(struct scrpos *scrpos) { ! int i; /* * Find the first line on the screen which has something on it, * and return the screen line number and the file position. */ for (i = 0; i < sc_height; i++) ! if (table[i] != -1) { scrpos->ln = i+1; scrpos->pos = table[i]; return; *************** *** 195,201 **** /* * The screen is empty. */ ! scrpos->pos = NULL_POSITION; } /* --- 189,195 ---- /* * The screen is empty. */ ! scrpos->pos = -1; } /* *************** *** 207,215 **** * or it may be in { -1 .. -(sc_height-1) } to refer to lines * relative to the bottom of the screen. */ ! public int ! adjsline(sline) ! int sline; { /* * Negative screen line number means --- 201,208 ---- * or it may be in { -1 .. -(sc_height-1) } to refer to lines * relative to the bottom of the screen. */ ! int ! adjsline(int sline) { /* * Negative screen line number means